2019-04-11 00:02:14 +00:00
|
|
|
import pyjsparser
|
2019-05-12 04:23:46 +00:00
|
|
|
from .space import Space
|
|
|
|
from . import fill_space
|
|
|
|
from .byte_trans import ByteCodeGenerator
|
|
|
|
from .code import Code
|
|
|
|
from .simplex import *
|
2019-04-11 00:02:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
pyjsparser.parser.ENABLE_JS2PY_ERRORS = lambda msg: MakeError(u'SyntaxError', unicode(msg))
|
|
|
|
|
|
|
|
def get_js_bytecode(js):
|
|
|
|
a = ByteCodeGenerator(Code())
|
|
|
|
d = pyjsparser.parse(js)
|
|
|
|
a.emit(d)
|
|
|
|
return a.exe.tape
|
|
|
|
|
2019-05-12 04:23:46 +00:00
|
|
|
def eval_js_vm(js, debug=False):
|
|
|
|
a = ByteCodeGenerator(Code(debug_mode=debug))
|
2019-04-11 00:02:14 +00:00
|
|
|
s = Space()
|
|
|
|
a.exe.space = s
|
|
|
|
s.exe = a.exe
|
|
|
|
|
|
|
|
d = pyjsparser.parse(js)
|
|
|
|
|
|
|
|
a.emit(d)
|
|
|
|
fill_space.fill_space(s, a)
|
2019-05-12 04:23:46 +00:00
|
|
|
if debug:
|
|
|
|
from pprint import pprint
|
|
|
|
pprint(a.exe.tape)
|
|
|
|
print()
|
2019-04-11 00:02:14 +00:00
|
|
|
a.exe.compile()
|
|
|
|
|
|
|
|
return a.exe.run(a.exe.space.GlobalObj)
|