Beispiel #1
0
    def compile(self, ctx):
        body = self.body
        if body is None:
            body = Return(None)
        body = compile_ast(body, self.scope)

        method = CodeFunction(self.identifier, body)

        ctx.emit('DECLARE_FUNCTION', self.identifier, method)
Beispiel #2
0
    def _bytecode(self, filename):
        filename = os.path.abspath(self.root + filename)

        # bytecode cache based on the filename
        try:
            return self.cached_files[filename]
        except KeyError:
            data = self._read_file(filename)
            if data is None:
                return None

            ast = source_to_ast(data)
            bc = compile_ast(ast, ast.scope, unicode(filename))

            self.cached_files[filename] = bc

        return bc
Beispiel #3
0
    def compile(self, ctx):
        body = self.body
        body = compile_ast(body, self.scope, self.identifier)

        ctx.emit('DECLARE_FUNCTION', self.identifier, body)
Beispiel #4
0
def ast_to_bytecode(ast, filename):
    """ Compile the AST into a bytecode
    """
    filename = unicode(os.path.abspath(filename))
    bc = compile_ast(ast, ast.scope, filename)
    return bc
Beispiel #5
0
def ast_to_bytecode(ast):
    """ Compile the AST into a bytecode
    """
    bc = compile_ast(ast, ast.scope)
    return bc
Beispiel #6
0
def ast_to_bytecode(ast, filename):
    """ Compile the AST into a bytecode
    """
    filename = unicode(os.path.abspath(filename))
    bc = compile_ast(ast, ast.scope, filename)
    return bc
Beispiel #7
0
def interpret(source):
    bc = compile_ast(parse(source))
    frame = Frame(bc)
    execute(frame, bc)
    return frame  # for tests and later introspection
Beispiel #8
0
    def compile(self, ctx):
        body = self.body
        body = compile_ast(body, self.scope, self.identifier)

        ctx.emit('DECLARE_FUNCTION', self.identifier, body)
Beispiel #9
0
def interpret(source):
    bc = compile_ast(parse(source))
    frame = Frame(bc)
    execute(frame, bc)
    return frame  # for tests and later introspection