def static_eval(txt): stream, result, parse = sexp_parser.SExpGrammer().parse(txt) if not result or stream.position != len(txt): print " " * (stream.position + 2) + "^" print "Parse error at position: %i" % stream.position return try: module = sexp_to_cps.convert_parse_to_cps(parse, False) except Exception as e: print "Could not interpret syntax: " + str(e) return try: prog = expression_tree.Prog(module) instrs, jumps = prog.compile() except Exception as e: print "Compile error: " + str(e) return try: print "Program output: " + str(vm.run_program(instrs, jumps)) except vm.RuntimeException as e: print "Runtime error: " + str(e) return
def convert_def(parse, module): new_module = copy(module) main_already_present = "main" in new_module new_module.update(sexp_to_cps.convert_parse_to_cps(parse)) if "main" in new_module and not main_already_present: new_module[INTERACTIVE_MAIN] = expression_tree.Func(["ret"], expression_tree.Call("main", [expression_tree.Finish()])) return new_module
def static_eval(txt): stream, result, parse = sexp_parser.SExpGrammer().parse(txt) if not result or stream.position != len(txt): print " " * (stream.position + 2) + "^" print "Parse error at position: %i" % stream.position return try: module = sexp_to_cps.convert_parse_to_cps(parse, False) except Exception as e: print "Could not interpret syntax: " + str(e) return try: prog = expression_tree.Prog(module) instrs, jumps = prog.compile() except Exception as e: print "Compile error: " + str(e) return try: print "Program output: " + str(vm.run_program(instrs, jumps)) except vm.RuntimeException as e: print "Runtime error: " + str(e) return
def convert_def(parse, module): new_module = copy(module) main_already_present = "main" in new_module new_module.update(sexp_to_cps.convert_parse_to_cps(parse)) if "main" in new_module and not main_already_present: new_module[INTERACTIVE_MAIN] = expression_tree.Func( ["ret"], expression_tree.Call("main", [expression_tree.Finish()])) return new_module