Esempio n. 1
0
def test_retlast_undefined_addition():
    jscode = JsCode()
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes, ['LOAD_UNDEFINED'])

    jscode = JsCode()
    jscode.emit('LOAD_INTCONSTANT', 1)
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes, ['LOAD_INTCONSTANT 1', 'LOAD_UNDEFINED'])
Esempio n. 2
0
def test_retlast_undefined_addition():
    jscode = JsCode()
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes, ['LOAD_UNDEFINED'])

    jscode = JsCode()
    jscode.emit('LOAD_INTCONSTANT', 1)
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes,
                             ['LOAD_INTCONSTANT 1', 'LOAD_UNDEFINED'])
Esempio n. 3
0
def test_retlast_pop_removal():
    jscode = JsCode()
    jscode.emit('POP')
    jsfunc = jscode.make_js_function()
    assert not jsfunc.opcodes

    jscode = JsCode()
    jscode.emit('POP')
    jscode.emit('LABEL', 0)
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes, ['POP', 'LOAD_UNDEFINED'])
Esempio n. 4
0
def test_retlast_pop_removal():
    jscode = JsCode()
    jscode.emit('POP')
    jsfunc = jscode.make_js_function()
    assert not jsfunc.opcodes

    jscode = JsCode()
    jscode.emit('POP')
    jscode.emit('LABEL', 0)
    jsfunc = jscode.make_js_function()
    assert_bytecode_list_eql(jsfunc.opcodes, ['POP', 'LOAD_UNDEFINED'])
Esempio n. 5
0
 def emit(self, bytecode):
     code = JsCode()
     if self.body is not None:
         self.body.emit(code)
     funcobj = code.make_js_function(self.name, self.params)
     bytecode.emit('DECLARE_FUNCTION', funcobj)
     if self.name is None:
         bytecode.emit('LOAD_FUNCTION', funcobj)
Esempio n. 6
0
def test_simple():
    bytecode = JsCode()
    bytecode.emit('LOAD_FLOATCONSTANT', 2)
    bytecode.emit('LOAD_FLOATCONSTANT', 4)
    bytecode.emit('ADD')
    bytecode.emit('POP')
    func = bytecode.make_js_function()
    res = func.run(ExecutionContext([W_Object()]), check_stack=False)
    assert res.ToNumber(None) == 6.0
Esempio n. 7
0
 def emit(self, bytecode):
     # a bit naive operator for now
     trycode = JsCode()
     self.tryblock.emit(trycode)
     tryfunc = trycode.make_js_function()
     if self.catchblock:
         catchcode = JsCode()
         self.catchblock.emit(catchcode)
         catchfunc = catchcode.make_js_function()
     else:
         catchfunc = None
     if self.finallyblock:
         finallycode = JsCode()
         self.finallyblock.emit(finallycode)
         finallyfunc = finallycode.make_js_function()
     else:
         finallyfunc = None
     bytecode.emit('TRYCATCHBLOCK', tryfunc, self.catchparam.get_literal(), catchfunc, finallyfunc)
Esempio n. 8
0
def assertv(code, value):
    jsint = interpreter.Interpreter()
    ctx = jsint.w_Global
    try:
        bytecode = JsCode()
        interpreter.load_source(code, '').emit(bytecode)
        func = bytecode.make_js_function()
        code_val = func.run(ExecutionContext([ctx]))
    except ThrowException, excpt:
        code_val = excpt.exception
Esempio n. 9
0
 def run(self, script, interactive=False):
     """run the interpreter"""
     bytecode = JsCode()
     script.emit(bytecode)
     if not we_are_translated():
         # debugging
         self._code = bytecode
     func = bytecode.make_js_function()
     if interactive:
         return func.run(self.global_context)
     else:
         func.run(self.global_context)
Esempio n. 10
0
 def Call(self, ctx, args=[], this=None):
     tam = len(args)
     if tam >= 1:
         fbody  = args[tam-1].ToString(ctx)
         argslist = []
         for i in range(tam-1):
             argslist.append(args[i].ToString(ctx))
         fargs = ','.join(argslist)
         functioncode = "function (%s) {%s}"%(fargs, fbody)
     else:
         functioncode = "function () {}"
     #remove program and sourcelements node
     funcnode = parse(functioncode).children[0].children[0]
     ast = ASTBUILDER.dispatch(funcnode)
     bytecode = JsCode()
     ast.emit(bytecode)
     func = bytecode.make_js_function()
     return func.run(ctx)
Esempio n. 11
0
    def test_append(self):
        code = """
        function f() {
            for(i = 0; i < 100; i++){
            }
        }
        f();
        """
        jsint = interpreter.Interpreter()
        ctx = jsint.w_Global
        bytecode = JsCode()
        interpreter.load_source(code, '').emit(bytecode)
        func = bytecode.make_js_function()

        def interp_w(c):
            jitdriver.set_param("inlining", True)
            code_val = func.run(ExecutionContext([ctx]))
        interp_w(1)
        self.meta_interp(interp_w, [6], listcomp=True, backendopt=True, listops=True)