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)
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
def compile(self, ctx): body = self.body body = compile_ast(body, self.scope, self.identifier) ctx.emit('DECLARE_FUNCTION', self.identifier, body)
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
def ast_to_bytecode(ast): """ Compile the AST into a bytecode """ bc = compile_ast(ast, ast.scope) return bc
def interpret(source): bc = compile_ast(parse(source)) frame = Frame(bc) execute(frame, bc) return frame # for tests and later introspection