new field access code and test. wip as field def broken
This commit is contained in:
parent
c4f89441e2
commit
b99b392481
28
lib/bosl/compiler/field_access.rb
Normal file
28
lib/bosl/compiler/field_access.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
module Bosl
|
||||||
|
Compiler.class_eval do
|
||||||
|
|
||||||
|
def on_field_access expression
|
||||||
|
puts expression.inspect
|
||||||
|
receiver_ast , field_ast = *expression
|
||||||
|
receiver = receiver_ast.first_from(:name)
|
||||||
|
field_name = field_ast.first_from(:name)
|
||||||
|
|
||||||
|
case receiver
|
||||||
|
when :self
|
||||||
|
for_class = self.method.for_class
|
||||||
|
index = for_class.object_layout.variable_index(field_name)
|
||||||
|
raise "field access, but no such field:#{field_name} for class #{for_class.name}"
|
||||||
|
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(:int,index ) , ret)
|
||||||
|
|
||||||
|
when :message
|
||||||
|
#message Slot
|
||||||
|
raise "message not yet"
|
||||||
|
else
|
||||||
|
#arg / frame Slot
|
||||||
|
raise "frame not implemented"
|
||||||
|
end
|
||||||
|
|
||||||
|
Virtual::Return.new( value )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
22
test/compiler/test_field_access.rb
Normal file
22
test/compiler/test_field_access.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require_relative "compiler_helper"
|
||||||
|
require_relative "code_checker"
|
||||||
|
|
||||||
|
module Virtual
|
||||||
|
class TestFoo < MiniTest::Test
|
||||||
|
include CodeChecker
|
||||||
|
|
||||||
|
def test_foo2
|
||||||
|
@string_input = <<HERE
|
||||||
|
int a
|
||||||
|
int foo(int x)
|
||||||
|
int b = self.a
|
||||||
|
return b +x
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@expect = [ Virtual::Return ]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user