implement ivar assignment
This commit is contained in:
@ -1,7 +1,15 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Register
|
||||
module SpaceHack
|
||||
# test hack to in place change object type
|
||||
def add_space_field(name,type)
|
||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
end
|
||||
module ExpressionHelper
|
||||
include SpaceHack
|
||||
|
||||
def check
|
||||
Register.machine.boot unless Register.machine.booted
|
||||
@ -14,17 +22,13 @@ module Register
|
||||
produced
|
||||
end
|
||||
|
||||
# test hack to in place change object type
|
||||
def add_space_field(name,type)
|
||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
end
|
||||
|
||||
module Statements
|
||||
include AST::Sexp
|
||||
include Compiling
|
||||
|
||||
include SpaceHack
|
||||
|
||||
def setup
|
||||
Register.machine.boot # force boot to reset main
|
||||
end
|
||||
|
@ -14,9 +14,16 @@ module Register
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def test_assign_local
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input =s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)))
|
||||
def test_assign_ivar_notpresent
|
||||
@input =s(:statements, s(:i_assignment, s(:name, :r), s(:int, 5)))
|
||||
@expect = []
|
||||
assert_raises{ check_nil }
|
||||
end
|
||||
|
||||
def test_assign_ivar
|
||||
add_space_field(:r , :Integer)
|
||||
|
||||
@input =s(:statements, s(:i_assignment, s(:name, :r), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
||||
RegToSlot, Label, FunctionReturn]
|
||||
|
Reference in New Issue
Block a user