def test_basic_interpreter_behavior(self, test_class, test_selector, expected_result, result_type):
     u = Universe()
     u.setup_classpath("Smalltalk:TestSuite/BasicInterpreterTests")
     
     actual_result = u.execute_method(test_class, test_selector)
     
     self._assertEqualsSOMValue(expected_result, actual_result, result_type)
    def test_basic_interpreter_behavior(self, test_class, test_selector,
                                        expected_result, result_type):
        u = Universe()
        u.setup_classpath("Smalltalk:TestSuite/BasicInterpreterTests")

        actual_result = u.execute_method(test_class, test_selector)

        self._assertEqualsSOMValue(expected_result, actual_result, result_type)
Exemple #3
0
 def print_stack_trace(self, nilObject):
     # Print a stack trace starting in this frame
     from som.vm.universe import Universe
     Universe.std_print(self.get_method().get_holder().get_name().get_string())
     Universe.std_print(self.get_bytecode_index() + "@"
                        + self.get_method().get_signature().get_string())
     
     if self.has_previous_frame(nilObject):
         self.get_previous_frame().print_stack_trace(nilObject)
Exemple #4
0
    def print_stack_trace(self, nilObject):
        # Print a stack trace starting in this frame
        from som.vm.universe import Universe
        Universe.std_print(
            self.get_method().get_holder().get_name().get_string())
        Universe.std_print(self.get_bytecode_index() + "@" +
                           self.get_method().get_signature().get_string())

        if self.has_previous_frame(nilObject):
            self.get_previous_frame().print_stack_trace(nilObject)
Exemple #5
0
    def dump(cls, clazz):
        for i in range(0, clazz.get_number_of_instance_invokables()):
            inv = clazz.get_instance_invokable(i)

            # output header and skip if the Invokable is a Primitive
            Universe.error_print(str(clazz.get_name()) + ">>" +
                                 str(inv.get_signature()) + " = ")

            if inv.is_primitive():
                Universe.error_println("<primitive>")
                continue
      
            # output actual method
            cls.dump_method(inv, "\t")
    def test_basic_interpreter_behavior(self, test_class, test_selector,
                                        expected_result, result_type):
        u = Universe()
        u.setup_classpath("Smalltalk:TestSuite/BasicInterpreterTests")

        try:
            actual_result = u.execute_method(test_class, test_selector)

            self._assert_equals_SOM_value(expected_result, actual_result,
                                          result_type)
        except ParseError as e:
            # if we expect a ParseError, then all is fine, otherwise re-raise it
            if result_type is not ParseError:
                raise e
Exemple #7
0
    def dump(cls, clazz):
        for i in range(0, clazz.get_number_of_instance_invokables()):
            inv = clazz.get_instance_invokable(i)

            # output header and skip if the Invokable is a Primitive
            Universe.error_print(
                str(clazz.get_name()) + ">>" + str(inv.get_signature()) +
                " = ")

            if inv.is_primitive():
                Universe.error_println("<primitive>")
                continue

            # output actual method
            cls.dump_method(inv, "\t")
Exemple #8
0
 def setUp(self):
     # Universe definition
     self.universe = Universe()
     # Array definition, 5 strings "bar"
     self.array = Array(Object(None), 5)
     for i in range(4):
         self.array.set_indexable_field(i, "bar")
     # Extended array definition, 5 strings "bar" followed by a string "foo"
     self.extended_array = Array(Object(None), 6)
     for i in range(4):
         self.extended_array.set_indexable_field(i, "bar")
     self.extended_array.set_indexable_field(5, "foo")
Exemple #9
0
    def test_som_test(self, test_name):
        args = ["-cp", "Smalltalk", "TestSuite/TestHarness.som", test_name]
        u = Universe(True)
        u.interpret(args)

        self.assertEquals(0, u.last_exit_code())
Exemple #10
0
    def dump_method(cls, m, indent):
        Universe.error_println("(")

        # output stack information
        Universe.error_println("%s<%d locals, %d stack, %d bc_count>" % (indent,
                               m.get_number_of_locals().get_embedded_integer(),
                               m.get_maximum_number_of_stack_elements().get_embedded_integer(),
                               m.get_number_of_bytecodes()))

        # output bytecodes
        b = 0
        while b < m.get_number_of_bytecodes():
            Universe.error_print(indent)
            
            # bytecode index
            if b < 10:  Universe.error_print(" ")
            if b < 100: Universe.error_print(" ")
            Universe.error_print(" %d:" % b)

            # mnemonic
            bytecode = m.get_bytecode(b)
            Universe.error_print(Bytecodes.as_str(bytecode) + "  ")

            # parameters (if any)
            if Bytecodes.get_bytecode_length(bytecode) == 1:
                Universe.error_println()
                b += 1
                continue
      
            if bytecode == Bytecodes.push_local:
                Universe.error_println("local: " + str(m.get_bytecode(b + 1)) +
                                       ", context: " + str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.push_argument:
                Universe.error_println("argument: " + str(m.get_bytecode(b + 1)) +
                                       ", context " + str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.push_field:
                Universe.error_println("(index: " + str(m.get_bytecode(b + 1)) +
                                       ") field: " + str(m.get_holder().get_instance_field_name(m.get_bytecode(b + 1))))
            elif bytecode == Bytecodes.push_block:
                Universe.error_print("block: (index: " + str(m.get_bytecode(b + 1)) + ") ")
                cls.dump_method(m.get_constant(b), indent + "\t")
            elif bytecode == Bytecodes.push_constant:
                constant = m.get_constant(b)
                Universe.error_println("(index: " + str(m.get_bytecode(b + 1)) +
                                       ") value: (" + 
                                       str(constant.get_class().get_name()) +
                                       ") " + str(constant))
            elif bytecode == Bytecodes.push_global:
                Universe.error_println("(index: " + str(m.get_bytecode(b + 1)) +
                                       ") value: " + str(m.get_constant(b)))
            elif bytecode == Bytecodes.pop_local:
                Universe.error_println("local: "     + str(m.get_bytecode(b + 1)) +
                                       ", context: " + str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.pop_argument:
                Universe.error_println("argument: "  + str(m.get_bytecode(b + 1)) +
                                       ", context: " + str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.pop_field:
                Universe.error_println("(index: "  + str(m.get_bytecode(b + 1)) +
                                       ") field: " + str(m.get_holder().get_instance_field_name(m.get_bytecode(b + 1))))
            elif bytecode == Bytecodes.send:
                Universe.error_println("(index: "      + str(m.get_bytecode(b + 1)) +
                                       ") signature: " + str(m.get_constant(b)))
            elif bytecode == Bytecodes.super_send:
                Universe.error_println("(index: "      + str(m.get_bytecode(b + 1)) +
                                       ") signature: " + str(m.get_constant(b)))
            else:
                Universe.error_println("<incorrect bytecode>")
      
            b += Bytecodes.get_bytecode_length(m.get_bytecode(b))
    
        Universe.error_println(indent + ")")
Exemple #11
0
    def dump_method(cls, m, indent):
        Universe.error_println("(")

        # output stack information
        Universe.error_println(
            "%s<%d locals, %d stack, %d bc_count>" %
            (indent, m.get_number_of_locals().get_embedded_integer(),
             m.get_maximum_number_of_stack_elements().get_embedded_integer(),
             m.get_number_of_bytecodes()))

        # output bytecodes
        b = 0
        while b < m.get_number_of_bytecodes():
            Universe.error_print(indent)

            # bytecode index
            if b < 10: Universe.error_print(" ")
            if b < 100: Universe.error_print(" ")
            Universe.error_print(" %d:" % b)

            # mnemonic
            bytecode = m.get_bytecode(b)
            Universe.error_print(Bytecodes.as_str(bytecode) + "  ")

            # parameters (if any)
            if Bytecodes.get_bytecode_length(bytecode) == 1:
                Universe.error_println()
                b += 1
                continue

            if bytecode == Bytecodes.push_local:
                Universe.error_println("local: " + str(m.get_bytecode(b + 1)) +
                                       ", context: " +
                                       str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.push_argument:
                Universe.error_println("argument: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ", context " +
                                       str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.push_field:
                Universe.error_println(
                    "(index: " + str(m.get_bytecode(b + 1)) + ") field: " +
                    str(m.get_holder().get_instance_field_name(
                        m.get_bytecode(b + 1))))
            elif bytecode == Bytecodes.push_block:
                Universe.error_print("block: (index: " +
                                     str(m.get_bytecode(b + 1)) + ") ")
                cls.dump_method(m.get_constant(b), indent + "\t")
            elif bytecode == Bytecodes.push_constant:
                constant = m.get_constant(b)
                Universe.error_println("(index: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ") value: (" +
                                       str(constant.get_class().get_name()) +
                                       ") " + str(constant))
            elif bytecode == Bytecodes.push_global:
                Universe.error_println("(index: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ") value: " + str(m.get_constant(b)))
            elif bytecode == Bytecodes.pop_local:
                Universe.error_println("local: " + str(m.get_bytecode(b + 1)) +
                                       ", context: " +
                                       str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.pop_argument:
                Universe.error_println("argument: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ", context: " +
                                       str(m.get_bytecode(b + 2)))
            elif bytecode == Bytecodes.pop_field:
                Universe.error_println(
                    "(index: " + str(m.get_bytecode(b + 1)) + ") field: " +
                    str(m.get_holder().get_instance_field_name(
                        m.get_bytecode(b + 1))))
            elif bytecode == Bytecodes.send:
                Universe.error_println("(index: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ") signature: " +
                                       str(m.get_constant(b)))
            elif bytecode == Bytecodes.super_send:
                Universe.error_println("(index: " +
                                       str(m.get_bytecode(b + 1)) +
                                       ") signature: " +
                                       str(m.get_constant(b)))
            else:
                Universe.error_println("<incorrect bytecode>")

            b += Bytecodes.get_bytecode_length(m.get_bytecode(b))

        Universe.error_println(indent + ")")
Exemple #12
0
 def test_som_test(self, test_name):
     args = ["-cp", "Smalltalk", "TestSuite/TestHarness.som", test_name]
     u = Universe(True)
     u.interpret(args)
     
     self.assertEquals(0, u.last_exit_code())