def main(argv): config.default.open_file_handle() try: filename = argv[1] except (IndexError, ValueError): print 'usage: %s [file-name]' % argv[0] return 1 try: if argv[2] == '--stacksize': stacksize = int(argv[3]) assert stacksize >= 0 config.default.vm_stacksize = stacksize except (IndexError, ValueError): pass # w_global = make_module() exprlist_w = load_file(filename) if len(exprlist_w) == 1: if exprlist_w[0].car_w().to_string() == 'BYTECODE-FUNCTION': run_bytecode(exprlist_w[0], w_global) else: run_source(list_to_pair(exprlist_w), w_global) else: run_source(list_to_pair(exprlist_w), w_global) # leave_program() return 0
def call(self, args_w): if len(args_w) == 0: # from stdin XXX use current-input-port stdin = config.default.stdin content = stdin.readall() return list_to_pair(read_string(content)[:]) # XXX different else: assert len(args_w) == 1 # from given file w_file, = args_w assert isinstance(w_file, W_File) return list_to_pair(read_string(w_file.w_readall().content())[:])
def dump_bytecode_function(w_func): assert isinstance(w_func, W_BytecodeFunction) fields_w = [None] * 9 fields_w[0] = symbol('BYTECODE-FUNCTION') fields_w[1] = list_to_pair([symbol('NAME'), symbol(w_func.name)]) # code_w = [None] * len(w_func.code) for i in xrange(len(code_w)): code_w[i] = W_Integer(ord(w_func.code[i])) w_code = list_to_pair(code_w) fields_w[2] = list_to_pair([symbol('CODE'), w_code]) fields_w[3] = list_to_pair([ symbol('NB-ARGS'), W_Integer(w_func.nb_args), w_boolean(w_func.has_vararg) ]) fields_w[4] = list_to_pair( [symbol('NB-LOCALS'), W_Integer(w_func.nb_locals)]) upval_descrs_w = [None] * (len(w_func.upval_descrs) >> 1) i = 0 while i < len(w_func.upval_descrs): c0, c1 = w_func.upval_descrs[i], w_func.upval_descrs[i + 1] upval_descrs_w[i >> 1] = list_to_pair( [W_Integer(ord(c0)), W_Integer(ord(c1))]) i += 2 # w_upval_descrs = list_to_pair(upval_descrs_w[:]) fields_w[5] = list_to_pair([symbol('UPVAL-DESCRS'), w_upval_descrs]) w_consts = list_to_pair(w_func.consts_w[:]) fields_w[6] = list_to_pair([symbol('CONSTS'), w_consts]) w_names = list_to_pair(w_func.names_w[:]) fields_w[7] = list_to_pair([symbol('NAMES'), w_names]) functions_w = [ dump_bytecode_function(w_function) for w_function in w_func.functions_w ] w_functions = list_to_pair(functions_w[:]) fields_w[8] = list_to_pair([symbol('FUNCTIONS'), w_functions]) return list_to_pair(fields_w)
def dump_bytecode_function(w_func): assert isinstance(w_func, W_BytecodeFunction) fields_w = [None] * 9 fields_w[0] = symbol('BYTECODE-FUNCTION') fields_w[1] = list_to_pair([symbol('NAME'), symbol(w_func.name)]) # code_w = [None] * len(w_func.code) for i in xrange(len(code_w)): code_w[i] = W_Integer(ord(w_func.code[i])) w_code = list_to_pair(code_w) fields_w[2] = list_to_pair([symbol('CODE'), w_code]) fields_w[3] = list_to_pair([symbol('NB-ARGS'), W_Integer(w_func.nb_args), w_boolean(w_func.has_vararg)]) fields_w[4] = list_to_pair([symbol('NB-LOCALS'), W_Integer(w_func.nb_locals)]) upval_descrs_w = [None] * (len(w_func.upval_descrs) >> 1) i = 0 while i < len(w_func.upval_descrs): c0, c1 = w_func.upval_descrs[i], w_func.upval_descrs[i + 1] upval_descrs_w[i >> 1] = list_to_pair([W_Integer(ord(c0)), W_Integer(ord(c1))]) i += 2 # w_upval_descrs = list_to_pair(upval_descrs_w[:]) fields_w[5] = list_to_pair([symbol('UPVAL-DESCRS'), w_upval_descrs]) w_consts = list_to_pair(w_func.consts_w[:]) fields_w[6] = list_to_pair([symbol('CONSTS'), w_consts]) w_names = list_to_pair(w_func.names_w[:]) fields_w[7] = list_to_pair([symbol('NAMES'), w_names]) functions_w = [dump_bytecode_function(w_function) for w_function in w_func.functions_w] w_functions = list_to_pair(functions_w[:]) fields_w[8] = list_to_pair([symbol('FUNCTIONS'), w_functions]) return list_to_pair(fields_w)