Skip to content

Commit

Permalink
Revert "Repaired pyv8 code"
Browse files Browse the repository at this point in the history
This reverts commit 201eb94b5ae455b453f03fba44e7470d07602d1e.

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@681 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
lkcl committed Jun 24, 2009
1 parent f0d2259 commit 976f8d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 124 deletions.
42 changes: 3 additions & 39 deletions library/platform/pyjslibPyV8.py
@@ -1,5 +1,5 @@
# pyv8_print_fn is actually in pyv8run.py and is added to the Globals
def printFunc(objs, newline):
def printFunc(objs):
JS("""
var s = "";
for(var i=0; i < objs.length; i++) {
Expand All @@ -11,41 +11,5 @@ def printFunc(objs, newline):
""")

# pyv8_import_module is actually in pyv8run.py and has been added to Globals.
def import_module(syspath, parent_name, module_name, dynamic_load, async, init):
JS("""
module = $pyjs.modules_hash[module_name];
if (typeof module == 'function' && module.__was_initialized__ == true) {
return null;
}
if (module_name == 'sys' || module_name == 'pyjslib') {
module();
return null;
}
""")
names = module_name.split(".")
importName = ''
# Import all modules in the chain (import a.b.c)
for name in names:
importName += name
JS("""module = $pyjs.modules_hash[importName];""")
if not isUndefined(module):
# Not initialized, but present. Must be pyjs module.
if JS("module.__was_initialized__ != true"):
# Module wasn't initialized
module()
else:
# Get a pytjon module from PyV8
initialized = False
try:
JS("initialized = (module.__was_initialized__ != true)")
except:
pass
if not initialized:
# Module wasn't initialized
module = pyv8_import_module(parent_name, module_name)
module.__was_initialized__ = True
JS("""$pyjs.modules_hash[importName] = module""")
importName += '.'
name = names[0]
JS("""$pyjs.modules[name] = $pyjs.modules_hash[module];""")
return None
def import_module(syspath, parent_name, module_name, dynamic_load, async):
pyv8_import_module(parent_name, module_name)
112 changes: 27 additions & 85 deletions pyv8/pyv8run.py
Expand Up @@ -7,10 +7,6 @@
from os.path import join, dirname, basename, abspath
from optparse import OptionParser

usage = """
usage: %prog [options] <application module name or path>
"""

currentdir = abspath(dirname(dirname(__file__)))
builddir = abspath("..")
sys.path.append(join(builddir, "pyjs"))
Expand All @@ -25,107 +21,53 @@
join(builddir, "addons")]


# Create a python class to be used in the context
class Global(PyV8.JSClass):
class Global:
def pyv8_print_fn(self, arg):
print arg
def pyv8_import_module(self, parent_name, module_name):
exec "import " + module_name
return locals()[module_name]
pass

def main():

parser = OptionParser(usage = usage)
pyjs.add_compile_options(parser)
parser.add_option("-o", "--output",
dest="output",
help="File to which the generated javascript should be written")

parser.add_option("-i", "--input",
dest="input",
help="File from which the generated javascript should be read")

parser.set_defaults(\
output = None,
input = None,
)
(options, args) = parser.parse_args()

file_name = args[0]
if len(args) > 1:
module_name = args[1]
file_name = sys.argv[1]
if len(sys.argv) > 2:
module_name = sys.argv[2]
else:
module_name = None

debug = 0

if options.input:
txt = open(options.input, 'r').read()
else:
parser = pyjs.PlatformParser("platform", verbose=False)
parser.setPlatform("PyV8")

if file_name[-3:] == ".py":
file_name = file_name[:-3]

app_translator = pyjs.AppTranslator(
app_library_dirs, parser,
verbose = False,
debug = options.debug,
print_statements = options.print_statements,
function_argument_checking = options.function_argument_checking,
attribute_checking = options.attribute_checking,
source_tracking = options.source_tracking,
line_tracking = options.line_tracking,
store_source = options.store_source,
)
app_libs, txt = app_translator.translate(file_name, debug=debug,
library_modules=['_pyjs.js', 'sys', 'pyjslib'])

template = """
var $pyjs = new Object();
$pyjs.modules = {};
$pyjs.modules_hash = {};
var pyjs_options = new Object();
pyjs_options.set_all = function (v) {
pyjs_options.arg_ignore = v;
pyjs_options.arg_count = v;
pyjs_options.arg_is_instance = v;
pyjs_options.arg_instance_type = v;
pyjs_options.arg_kwarg_dup = v;
pyjs_options.arg_kwarg_unexpected_keyword = v;
pyjs_options.arg_kwarg_multiple_values = v;
}
pyjs_options.set_all(true);
var trackstack = [];
var track = {module:'__main__', lineno: 1};
trackstack.push(track);
parser = pyjs.PlatformParser("platform", verbose=False)
parser.setPlatform("PyV8")

if file_name[-3:] == ".py":
file_name = file_name[:-3]

app_translator = pyjs.AppTranslator(app_library_dirs, parser, verbose=False)
app_libs, txt = app_translator.translate(file_name, debug=debug,
library_modules=['_pyjs.js', 'sys', 'pyjslib'])

#txt = pyjs.translate(file_name, module_name)

PyV8.debugger.enabled = True

e = PyV8.JSEngine(Global())

template = """
%(app_libs)s
%(module)s
"""

txt = template % {'app_libs': app_libs, 'module_name': file_name,
'module': txt}

#for mod_name in app_translator.library_modules:
for mod_name in ['sys', 'pyjslib', file_name]:
txt += "%s();\n" % mod_name
txt = template % {'app_libs': app_libs, 'module_name': file_name,
'module': txt}

if options.output:
fp = open(options.output, 'w')
fp.write(txt)
fp.close()
for mod_name in app_translator.library_modules:
txt += "%s();\n" % mod_name

PyV8.debugger.enabled = True
# create a context with an explicit global
ctxt = PyV8.JSContext(Global())
# enter the context
ctxt.enter()

x = ctxt.eval(txt)
x = e.eval(txt)

if __name__ == '__main__':
main()

0 comments on commit 976f8d1

Please sign in to comment.