def _one_call_stack_info(self, cp, pc, args=None): (module_name, func_name, arity) = cp.find_func_def(pc) line_number = cp.find_current_line(pc) if args: arg_part = args else: arg_part = W_IntObject(arity) return W_TupleObject([ global_atom_table.get_obj_from_str(module_name), global_atom_table.get_obj_from_str(func_name), arg_part, W_ListObject( W_TupleObject([ global_atom_table.get_obj_from_str('file'), #FIXME: it actually should be a string type, # and it also influent the error_message function eterm_operators.build_strlist_object( [W_IntObject(ord(c)) for c in cp.file_name]) ]), W_ListObject( W_TupleObject([ global_atom_table.get_obj_from_str('line'), W_IntObject(line_number) ]))) ])
def get_basic_value(self, cp, pair): (tag, value) = pair if tag == opcodes.TAG_XREG or tag == opcodes.TAG_YREG: return self.fetch_basereg(pair) elif tag == opcodes.TAG_INTEGER: return cp.const_table[value] elif tag == opcodes.TAG_ATOM: if value == 0: return constant.CONST_NIL else: return global_atom_table.get_obj_at(value) elif tag == opcodes.TAGX_LITERAL: return cp.lit_table[value] elif tag == opcodes.TAGX_FLOATREG: return self.x_reg.get_float(value) else: # TODO: take more care for else branch return W_IntObject(value)
def test_str(self): x = 12345 obj1 = W_IntObject(x) result = obj1.str() assert result == str(x)
def _to_value(self): return eterm_operators.build_strlist_object([W_IntObject(val) for val in self.vals])
def _to_value(self): return W_IntObject(self.val)
def build_strlist_object_from_string(s): return build_strlist_object([W_IntObject(ord(c)) for c in s])
def buildInstrs(self, beam): pc = 0 instrs = [] const_table = [] atoms = beam.getAtomTable() #current_label = 0 while (pc < len(self.code)): pc, instr = self.parseInstr(pc) arity = opcodes.arity[instr] args = [] lst_field = None for i in range(0, arity): pc, first = self.parseOne(pc) pc, tag = self._parseTag(pc, first) if self.isBaseTag(tag): pc, val = self._parseInt(pc, first) if tag == opcodes.TAG_INTEGER: val = self._check_const_table(const_table, val) elif tag == opcodes.TAG_ATOM and not val == 0: val = global_atom_table.search_index(atoms[val - 1]) args.append((tag, val)) elif tag == opcodes.TAGX_FLOATLIT: pc, val = self._parse_floatreg(pc) args.append((tag, val)) elif tag == opcodes.TAGX_SELECTLIST: pc, lst_field = self._parse_selectlist(pc) for i in range(len(lst_field)): ((tag, val), label) = lst_field[i] if tag == opcodes.TAG_INTEGER: val = self._check_const_table(const_table, val) elif tag == opcodes.TAG_ATOM and not val == 0: val = global_atom_table.search_index(atoms[val - 1]) lst_field[i] = ((tag, val), label) elif tag == opcodes.TAGX_FLOATREG: pc, val = self._parse_floatreg(pc) args.append((tag, val)) elif tag == opcodes.TAGX_ALLOCLIST: pc, lst_field = self._parse_alloclist(pc) elif tag == opcodes.TAGX_LITERAL: pc, val = self._parse_literal(pc) args.append((tag, val)) else: pretty_print.print_hex(self.code) raise Exception("Unknown TAG: %d at position:%d" % (tag, pc - 1)) if instr in opcodes.loop_instrs: instrs.append(LoopInstruction(instr, args[:])) elif lst_field: #if lst_field: instrs.append(ListInstruction(instr, args[:], lst_field)) #if instr in opcodes.possible_pattern_matches and (not self.check_error_label(current_label, args)): #instrs.append(PatternMatchingListInstruction(instr, args[:], lst_field)) #else: #instrs.append(ListInstruction(instr, args[:], lst_field)) else: instrs.append(Instruction(instr, args[:])) #if instr in opcodes.possible_pattern_matches and (not self.check_error_label(current_label, args)): #instrs.append(PatternMatchingInstruction(instr, args[:])) #else: #if instr == opcodes.LABEL: #current_label = args[0][1] #instrs.append(Instruction(instr, args[:])) return self.mark_pattern_instrs(instrs), [ W_IntObject(v) for v in const_table ]
from pyrlang.interpreter.datatypes.number import W_IntObject from pyrlang.interpreter.datatypes.list import W_NilObject CONST_0 = W_IntObject(0) CONST_NIL = W_NilObject() # the process terminated normally STATE_TERMINATE = 0 # the process run out of its reduction steps # and thus should be suspended and inserted # to run able queue again STATE_SWITH = 1 # the process didn't match any message in its # message and thus should be suspended and # removed out of the runable queue STATE_HANG_UP = 2 PRIORITY_MAXIMUM = 0 PRIORITY_HIGH = 1 PRIORITY_NORMAL = 2 PRIORITY_LOW = 4 # how many times we skip a low priority process # before we execute it. LOW_PRIORITY_PROCESS_SKIP_TIMES = 5 # use it to represent an undefined register tuple of (address, tag) INVALID_REG = (0, 0) # used for jit.loop_unrolling_heuristic hint UNROLLING_CUTOFF = 5