def _prepare_runtime(exportable=False): if exportable: for name, value in FIXED_VALUES_EXPORTABLE.items(): yield _assignment_code(name, value) else: for name, value in FIXED_VALUES.items(): yield _assignment_code(name, value) for name, func in BUILTIN_FUNCTIONS.items(): yield _assignment_code(name, BuiltinFunction(func, name)) _, ast = parser.parse(LIBRARY_CODE, source_name='_system_library') yield ast
def test(string): # print('=========================================') # print(' ', string) # print('=========================================') tokens, ast = parse(string) # print(json.dumps(ast, indent = 4)) # bytes = bytecode.build({'#': 'program', 'items': [ast]}) builder = bytecode.CodeBuilder() interpreter_bytes = runtime.wrap_with_runtime(builder, ast) # for index, byte in enumerate(bytes): # print('{:3d} - {}'.format(index, byte)) vm = Interpereter(interpreter_bytes, builder=builder, trace=True) return vm.run(tick_limit=10000, error_if_exhausted=True)
def main(): if len(sys.argv) == 1: interactive_terminal() return # Some options, gotta run file try: args = parse_arguments() filename = proc_filename(args.filename) code = open(filename).read() tokens, ast = parser.parse(code, source_name = filename) btc = prepare_runtime(bytecode.CodeBuilder(), ast, exportable = args.compile) if args.compile: print(btc.dump()) return interpereter = Interpereter(btc, trace = args.trace) result = interpereter.run() print(result) except parser.ParseFailed as e: print(format_error_place(code, e.position))