move that test to core (cant be done in compiled code) and focus on string addition instead
This commit is contained in:
parent
cdfc1ac891
commit
5756e0b325
@ -26,7 +26,8 @@ module Ast
|
||||
locals[arg] = arg_value
|
||||
args << arg_value
|
||||
end
|
||||
function = Vm::Function.new(name , args )
|
||||
class_name = context.current_class.name
|
||||
function = Vm::Function.new("#{class_name}::#{name}" , args )
|
||||
context.current_class.add_function function
|
||||
|
||||
parent_locals = context.locals
|
||||
|
@ -20,7 +20,7 @@ module Ast
|
||||
|
||||
return_reg = Vm::Integer.new(7)
|
||||
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::StringConstant)
|
||||
return_reg.load into , expression_value if expression_value.register != return_reg.register
|
||||
return_reg.load into , expression_value
|
||||
else
|
||||
return_reg.move( into, expression_value ) if expression_value.register != return_reg.register
|
||||
end
|
||||
|
23
lib/core/base_object.rb
Normal file
23
lib/core/base_object.rb
Normal file
@ -0,0 +1,23 @@
|
||||
module Core
|
||||
class BaseObject
|
||||
|
||||
def _set_instance_variable(name , value)
|
||||
return name
|
||||
end
|
||||
|
||||
def _get_instance_variable( name )
|
||||
return name
|
||||
end
|
||||
|
||||
def _get_singleton_method(name )
|
||||
return name
|
||||
end
|
||||
def _add_singleton_method(method)
|
||||
return 4
|
||||
end
|
||||
def initialize()
|
||||
return 4
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -29,7 +29,7 @@ module Vm
|
||||
|
||||
def initialize(name , args = [] , return_type = nil)
|
||||
super()
|
||||
@name = name
|
||||
@name = name.to_sym
|
||||
@args = Array.new(args.length)
|
||||
args.each_with_index do |arg , i|
|
||||
if arg.is_a?(Value)
|
||||
|
@ -3,32 +3,32 @@ require_relative 'helper'
|
||||
class TestClass < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
def test_base_class
|
||||
def test_class
|
||||
@string_input = <<HERE
|
||||
class BaseObject
|
||||
def _set_instance_variable(name , value)
|
||||
4
|
||||
class String
|
||||
def plus( str)
|
||||
my_length = self.length()
|
||||
str_len = str.length()
|
||||
new_string = String.new(my_length + str_len)
|
||||
i = 0
|
||||
while( i < my_length)
|
||||
char = self.get(i)
|
||||
new_string.set(i , char)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
def _get_instance_variable( name )
|
||||
4
|
||||
i = 0
|
||||
while( i < str_len)
|
||||
char = str.get(i)
|
||||
new_string.set( i + my_length , char)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
def _get_singleton_method(name )
|
||||
4
|
||||
end
|
||||
def _add_singleton_method(method)
|
||||
4
|
||||
end
|
||||
def initialize()
|
||||
4
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@should = [0x0,0xb0,0xa0,0xe3,0x2a,0x10,0xa0,0xe3,0x13,0x0,0x0,0xeb,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x40,0x2d,0xe9,0xa,0x30,0x42,0xe2,0x22,0x21,0x42,0xe0,0x22,0x22,0x82,0xe0,0x22,0x24,0x82,0xe0,0x22,0x28,0x82,0xe0,0xa2,0x21,0xa0,0xe1,0x2,0x41,0x82,0xe0,0x84,0x30,0x53,0xe0,0x1,0x20,0x82,0x52,0xa,0x30,0x83,0x42,0x30,0x30,0x83,0xe2,0x0,0x30,0xc1,0xe5,0x1,0x10,0x41,0xe2,0x0,0x0,0x52,0xe3,0xef,0xff,0xff,0x1b,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x20,0x10,0x8f,0xe2,0x9,0x10,0x81,0xe2,0xe9,0xff,0xff,0xeb,0x14,0x10,0x8f,0xe2,0xc,0x20,0xa0,0xe3,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20]
|
||||
@output = " 42 "
|
||||
parse
|
||||
write "putint"
|
||||
write "class"
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user