예제 #1
0
 def find_func_def(self, pc):
     while pc != 0:
         instr = self.instrs[0]
         if instr.opcode == opcodes.FUNC_INFO:
             (module_index, func_name_index, arity) = instr.arg_values()
             return (global_atom_table.get_str_at(module_index),
                     global_atom_table.get_str_at(func_name_index), arity)
         else:
             pc -= 1
     raise Exception("cannot find function definition from address %d" %
                     (pc))
예제 #2
0
 def search_exports(self, func_name, arity, header):
     for i in range(0, len(header)):
         entry = header[i]
         if global_atom_table.get_str_at(
                 entry[0]) == func_name and arity == entry[1]:
             return i
     else:
         raise Exception("Cannot found public function %s/%d" %
                         (func_name, arity))
예제 #3
0
 def import_BIF_and_module(self):
     mfl = ModFileLoader()
     import_mods = []
     import_header = self._import_header[:]
     func_list = []
     func_dict = {}
     mod_dict = {}
     for i in range(0, len(import_header)):
         entry = import_header[i]
         module_atom_index = entry[0]
         func_atom_index = entry[1]
         arity = entry[2]
         moduleName = global_atom_table.get_str_at(module_atom_index)
         funcName = global_atom_table.get_str_at(func_atom_index)
         #print "prepare importing function: %s:%s/%d..." % (moduleName, funcName, arity)
         # BIF
         if moduleName in ModuleDict.module_dict and ModuleDict.is_bif_from_tuple(
                 self.get_name_entry(entry)):
             # we use function_arity to emulate function overload
             moduleEntity = ModuleDict.module_dict[moduleName]()
             bif_name = ModuleDict.get_bif_name(funcName, arity)
             import_header[i] = (entry[0], len(func_list), entry[2])
             func_dict[func_atom_index] = len(func_list)
             func_list.append(moduleEntity.searchFunc(bif_name)())
         elif not moduleName == self.get_self_module_name():
             if module_atom_index not in mod_dict:
                 #print "searching module [%s] by %s"%(moduleName, self.get_self_module_name())
                 b = mfl.find(moduleName)
                 mod_dict[module_atom_index] = len(import_mods)
                 import_mods.append(CodeParser(b, moduleName + ".erl",
                                               self))
             mod_cp = import_mods[mod_dict[module_atom_index]]
             func_index = self.search_exports(funcName, arity,
                                              mod_cp.export_header)
             import_header[i] = (mod_dict[module_atom_index], func_index,
                                 arity)
     return func_list[:], func_dict.copy(
     ), import_header[:], import_mods[:], mod_dict.copy()
예제 #4
0
def rand_to_str(cp, rand):
    (tag, val) = rand
    if tag == opcodes.TAGX_LITERAL:
        return value_str(cp.lit_table[val])
    elif tag == opcodes.TAG_LITERAL:
        return str(val)
    elif tag == opcodes.TAG_INTEGER:
        return "#%d" % (cp.const_table[val].toint())
    elif tag == opcodes.TAG_ATOM:
        return global_atom_table.get_str_at(val)
    elif tag == opcodes.TAG_XREG:
        return "x(%d)" % val
    elif tag == opcodes.TAG_YREG:
        return "y(%d)" % val
    elif tag == opcodes.TAG_LABEL:
        return "L%d" % val
    elif tag == opcodes.TAGX_FLOATREG:
        return "f(%d)" % val
    else:
        return str(val)
예제 #5
0
파일: atom.py 프로젝트: tzwenn/pyrlang
 def get_str(self):
     from pyrlang.interpreter.atom_table import global_atom_table
     return global_atom_table.get_str_at(self.index)
예제 #6
0
 def get_name_entry(self, entry):
     return (global_atom_table.get_str_at(entry[0]),
             global_atom_table.get_str_at(entry[1]), entry[2])