Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
191ca2c7
Commit
191ca2c7
authored
Feb 23, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bulk of initial work.
parent
528b70e8
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
669 additions
and
0 deletions
+669
-0
Makefile
Makefile
+50
-0
README.md
README.md
+24
-0
index.html
index.html
+41
-0
main.cpp
main.cpp
+554
-0
No files found.
Makefile
0 → 100644
View file @
191ca2c7
PYVERSION
=
3.5.2
PYMINOR
=
$(
basename
$(PYVERSION)
)
CPYTHON_EMSCRIPTEN_ROOT
=
../cpython-emscripten
CC
=
emcc
CXX
=
em++
OPTFLAGS
=
-O2
CXXFLAGS
=
-std
=
c++14
$(OPTFLAGS)
-g
-I
$(CPYTHON_EMSCRIPTEN_ROOT)
/installs/python-
$(PYVERSION)
/include/python
$(PYMINOR)
/
-Wno-warn-absolute-paths
LDFLAGS
=
$(OPTFLAGS)
$(CPYTHON_EMSCRIPTEN_ROOT)
/installs/python-
$(PYVERSION)
/lib/libpython
$(PYMINOR)
.a
\
-s
TOTAL_MEMORY
=
268435456
\
-s
ASSERTIONS
=
2
\
-s
EMULATE_FUNCTION_POINTER_CASTS
=
1
\
-s
EXPORTED_FUNCTIONS
=
'["_main"]'
\
--memory-init-file
0
all
:
python.asm.js
python.asm.js
:
main.bc root
$(CC)
--bind
-o
$@
$(
filter
%.bc,
$^
)
$(LDFLAGS)
\
$(
foreach
d,
$(
wildcard
root/
*
)
,--preload-file
$d
@/
$(
notdir
$d
))
serve
:
python.asm.js
@
echo
"Serving on port 8062"
python
-m
SimpleHTTPServer 8062
clean
:
-
rm
-fr
root
-
rm
python.asm.js python.asm.data python.asm.wasm
-
rm
*
.bc
%.bc
:
%.cpp $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/python$(PYMINOR)
$(CXX)
-o
$@
$<
$(CXXFLAGS)
root
:
$(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/python$(PYMINOR)
mkdir
-p
root/lib
cp
-a
$(CPYTHON_EMSCRIPTEN_ROOT)
/installs/python-
$(PYVERSION)
/lib/python
$(PYMINOR)
/ root/lib
(
\
cd
root/lib/python
$(PYMINOR)
;
\
rm
-fr
test
distutils ensurepip idlelib __pycache__ tkinter
;
\
)
$(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/python$(PYMINOR)
:
make
-C
$(CPYTHON_EMSCRIPTEN_ROOT)
/
$(PYVERSION)
README.md
0 → 100644
View file @
191ca2c7
# Calling Python from Javascript with value conversion
# Building
These instructions were tested on Linux. OSX should be substantively the same.
1.
Build emscripten according to
[
these
instructions
](
https://developer.mozilla.org/en-US/docs/WebAssembly/C_to_wasm
)
.
2.
Enable the emscripten environment (
`source emsdk_env.sh`
)
3.
Build
[
cpython-emscripten
](
https://github.com/dgym/cpython-emscripten
)
:
1.
Clone the git repository
2.
cd into
`3.5.2`
, and type
`make`
.
4.
Build this project.
[It assumes that
`cpython-emscripten`
was checked out and built in a
directory alongside this project. TODO: Provide a way to specify the
cpython-emscripten location]
Type
`make`
.
index.html
0 → 100644
View file @
191ca2c7
<!DOCTYPE html>
<html>
<!-- Quick and dirty tests... Not useful for anything else. -->
<head>
<meta
charset=
"utf-8"
/>
</head>
<body>
<script
src=
'python.asm.js'
></script>
<script>
/* window.pyexec = Module.cwrap('PyRun_SimpleString', 'number', ['string']);*/
var
doTest
=
function
(
code
)
{
var
x
=
Module
.
runPython
(
code
);
console
.
log
(
"
------
"
)
console
.
log
(
code
)
console
.
log
(
"
Return type
"
+
typeof
x
)
console
.
log
(
JSON
.
stringify
(
x
))
console
.
log
()
}
var
onReady
=
function
()
{
doTest
(
"
42
"
);
doTest
(
"
42.0
"
);
doTest
(
"
[0, 1, 32.0]
"
)
doTest
(
"
{'foo': 42}
"
)
doTest
(
"
'This is a string'
"
)
doTest
(
"
def foo():
\n
return 42
\n\n
foo()
"
)
doTest
(
"
import sys
\n
sys.platform
"
)
};
// Wait for the module to be ready before calling any functions.
var
interval
=
setInterval
(
function
()
{
if
(
Module
.
calledRun
)
{
window
.
clearInterval
(
interval
);
onReady
();
}
},
100
);
</script>
</body>
</html>
main.cpp
0 → 100644
View file @
191ca2c7
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment