Exemplo n.º 1
0
 def RET0(self, args, space):
     """
     A: rbase, D: lit
     Return without value
     """
     debug_print("RET0 called")
     return [W_Num(0)]
Exemplo n.º 2
0
 def RET0(self, args, space): 
     """
     A: rbase, D: lit
     Return without value
     """
     debug_print("RET0 called")
     return [W_Num(0)]
Exemplo n.º 3
0
 def KSHORT(self, args, space):
     """
     A: dst, D: lits
     Set A to 16 bit signed integer D
     """
     val = self.decode_lits(args[1])
     debug_print("KSHORT: set R %d to %d" % (args[0], val))
     self.registers[args[0]] = W_Num(val)
Exemplo n.º 4
0
 def ADDVN(self, args, space):
     """
     A: dst, B: var, C: num
     """
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_constant(args[2])
     debug_print("ADDVN: Reg[%s] = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1 + v2)
Exemplo n.º 5
0
    def run(self):
        returnvalue = None
        space = ObjectSpace()

        returnvalue = self.root_frame.execute_frame(space)

        debug_print("Finished intepreting")
        return returnvalue[0]
Exemplo n.º 6
0
 def GGET(self, args, space):
    """
    A: dst, D: str
    get global
    """
    key = self.get_str_constant(args[1]).s_val
    debug_print("GGET: get %s in R %s" % (key, args[0]))
    self.registers[args[0]] = space.globals[key]
Exemplo n.º 7
0
 def KSHORT(self, args, space): 
     """
     A: dst, D: lits
     Set A to 16 bit signed integer D
     """
     val = self.decode_lits(args[1])
     debug_print("KSHORT: set R %d to %d" %(args[0], val))
     self.registers[args[0]] = W_Num(val)
Exemplo n.º 8
0
 def ADDVN(self, args, space):
     """
     A: dst, B: var, C: num
     """
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_constant(args[2])
     debug_print("ADDVN: Reg[%s] = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1+v2)
Exemplo n.º 9
0
 def GGET(self, args, space):
     """
    A: dst, D: str
    get global
    """
     key = self.get_str_constant(args[1]).s_val
     debug_print("GGET: get %s in R %s" % (key, args[0]))
     self.registers[args[0]] = space.globals[key]
Exemplo n.º 10
0
 def GSET(self, args, space):
     """
     A: dst, D: str
     Set Global
     """
     key = self.get_str_constant(args[1]).s_val
     val = self.registers[args[0]]
     debug_print('GSET: set global %s to %s' % (key, val))
     self.space.globals[key] = val
Exemplo n.º 11
0
 def ADDVV(self, args, space):
     """
     A: dst, B: var, C: var
     Sets A to B + C
     """
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_register(args[2])
     debug_print("ADDVV: Reg %d = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1 + v2)
Exemplo n.º 12
0
 def GSET(self, args, space):
     """
     A: dst, D: str
     Set Global
     """
     key = self.get_str_constant(args[1]).s_val
     val = self.registers[args[0]]
     debug_print('GSET: set global %s to %s' %(key, val))
     self.space.globals[key] = val
Exemplo n.º 13
0
 def ADDVV(self, args, space):
     """
     A: dst, B: var, C: var
     Sets A to B + C
     """
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_register(args[2])
     debug_print("ADDVV: Reg %d = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1 + v2)
Exemplo n.º 14
0
 def RET1(self, args, space):
     """
     A: rbase, D: lit
     Return with exactly one value, R(A) holds the value
     """
     # TODO only numbers at the moment
     w_v = self.registers[args[0]]
     debug_print('RET1: return %s' % w_v.to_str())
     # TODO results are wrapped in a list, because it makes returning multiple arguments
     # easier, improve if possible
     return [w_v]
Exemplo n.º 15
0
    def parse_frame(self):
        flags = self.byte()
        num_params = self.byte()
        frame_size = self.byte()
        num_uv = self.byte()
        num_kgc = self.uleb()
        num_kn = self.uleb()
        num_bc = self.uleb()

        instructions = []
        debug_print("found " + str(num_bc) + " bc instructions")
        for i in xrange(0, num_bc):
            instructions.append(self.decode_opcode(self.word()))

        debug_print("num uv " + str(num_uv))
        uv_data = []
        for i in xrange(0, num_uv):
            uv = self.h()
            uv_data.append((uv & 0x8000, uv & 0x4000, uv & 0x3fff))

        constants = [None] * (num_kgc + num_kn)

        childc = len(self.frames)
        #TODO imlement constant parsing
        for i in xrange(0, num_kgc):
            u = self.uleb()
            # CHILD
            if u == 0:
                childc -= 1
                constants[num_kn + i] = self.frames[childc]
            elif u == 1:
                len_array = self.uleb()
                len_hash = self.uleb()
                w_table = W_Table()
                self.parse_array(w_table, len_array)
                self.parse_hash(w_table, len_hash)
                constants[num_kn + i] = w_table
            else:  # string and all other things
                constants[num_kn + i] = self.const_str(u)
            """
            for t in UNROLLED_KGC_TYPES:
                if t == kgc_type:
                    meth = getattr(self, t)
            """

        for i in xrange(0, num_kn):
            debug_print("read knum")
            constants[i] = self.read_knum()

        debug_print(str(constants))
        for (ind, args) in instructions:
            debug_print(str(OP_DESC[ind].name) + " " + str(args))

        return LuaBytecodeFrame(flags, constants, uv_data, instructions)
Exemplo n.º 16
0
 def RET1(self, args, space):
     """
     A: rbase, D: lit
     Return with exactly one value, R(A) holds the value
     """
     # TODO only numbers at the moment
     w_v = self.registers[args[0]]
     debug_print('RET1: return %s' % w_v.to_str())
     # TODO results are wrapped in a list, because it makes returning multiple arguments
     # easier, improve if possible
     return [w_v]
Exemplo n.º 17
0
    def parse_frame(self):
        flags = self.byte()
        num_params = self.byte()
        frame_size = self.byte()
        num_uv = self.byte()
        num_kgc = self.uleb()
        num_kn = self.uleb()
        num_bc = self.uleb()

        instructions = []
        debug_print("found "+str(num_bc)+" bc instructions")
        for i in xrange(0, num_bc):
            instructions.append(self.decode_opcode(self.word()))

        debug_print("num uv "+str(num_uv))
        uv_data = []
        for i in xrange(0, num_uv):
            uv = self.h()
            uv_data.append((uv & 0x8000, uv & 0x4000, uv & 0x3fff))

        constants = [None] * (num_kgc+num_kn)

        childc = len(self.frames)
        #TODO imlement constant parsing
        for i in xrange(0, num_kgc):
            u = self.uleb()
            # CHILD
            if u == 0:
                childc -= 1
                constants[num_kn+i] = self.frames[childc]
            elif u == 1:
                len_array = self.uleb()
                len_hash = self.uleb()
                w_table = W_Table()
                self.parse_array(w_table, len_array)
                self.parse_hash(w_table, len_hash)
                constants[num_kn+i] = w_table
            else:  # string and all other things
                constants[num_kn+i] = self.const_str(u)
            """
            for t in UNROLLED_KGC_TYPES:
                if t == kgc_type:
                    meth = getattr(self, t)
            """

        for i in xrange(0, num_kn):
            debug_print("read knum")
            constants[i] = self.read_knum()

        debug_print(str(constants))
        for (ind, args) in instructions:
            debug_print(str(OP_DESC[ind].name)+" "+str(args))

        return LuaBytecodeFrame(flags, constants, uv_data, instructions)
Exemplo n.º 18
0
 def SUBVV(self, args, space):
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_register(args[2])
     debug_print("ADDVV: Reg %d = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1-v2)
Exemplo n.º 19
0
 def SUBVV(self, args, space):
     v1 = self.get_num_register(args[1])
     v2 = self.get_num_register(args[2])
     debug_print("ADDVV: Reg %d = %s + %s" % (args[0], v1, v2))
     self.registers[args[0]] = W_Num(v1 - v2)