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
|
locals[arg] = arg_value
|
||||||
args << arg_value
|
args << arg_value
|
||||||
end
|
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
|
context.current_class.add_function function
|
||||||
|
|
||||||
parent_locals = context.locals
|
parent_locals = context.locals
|
||||||
|
@ -20,7 +20,7 @@ module Ast
|
|||||||
|
|
||||||
return_reg = Vm::Integer.new(7)
|
return_reg = Vm::Integer.new(7)
|
||||||
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::StringConstant)
|
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
|
else
|
||||||
return_reg.move( into, expression_value ) if expression_value.register != return_reg.register
|
return_reg.move( into, expression_value ) if expression_value.register != return_reg.register
|
||||||
end
|
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)
|
def initialize(name , args = [] , return_type = nil)
|
||||||
super()
|
super()
|
||||||
@name = name
|
@name = name.to_sym
|
||||||
@args = Array.new(args.length)
|
@args = Array.new(args.length)
|
||||||
args.each_with_index do |arg , i|
|
args.each_with_index do |arg , i|
|
||||||
if arg.is_a?(Value)
|
if arg.is_a?(Value)
|
||||||
|
@ -3,32 +3,32 @@ require_relative 'helper'
|
|||||||
class TestClass < MiniTest::Test
|
class TestClass < MiniTest::Test
|
||||||
include Fragments
|
include Fragments
|
||||||
|
|
||||||
def test_base_class
|
def test_class
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class BaseObject
|
class String
|
||||||
def _set_instance_variable(name , value)
|
def plus( str)
|
||||||
4
|
my_length = self.length()
|
||||||
end
|
str_len = str.length()
|
||||||
|
new_string = String.new(my_length + str_len)
|
||||||
def _get_instance_variable( name )
|
i = 0
|
||||||
4
|
while( i < my_length)
|
||||||
end
|
char = self.get(i)
|
||||||
|
new_string.set(i , char)
|
||||||
def _get_singleton_method(name )
|
i = i + 1
|
||||||
4
|
end
|
||||||
end
|
i = 0
|
||||||
def _add_singleton_method(method)
|
while( i < str_len)
|
||||||
4
|
char = str.get(i)
|
||||||
end
|
new_string.set( i + my_length , char)
|
||||||
def initialize()
|
i = i + 1
|
||||||
4
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
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]
|
@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 "
|
@output = " 42 "
|
||||||
parse
|
parse
|
||||||
write "putint"
|
write "class"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user