modulize field_access and field_def

This commit is contained in:
Torsten Ruger
2016-12-09 14:04:06 +02:00
parent 4da13c3867
commit 059fb38f08
5 changed files with 12 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
module Typed
Compiler.class_eval do
module Collections
# attr_reader :values
def on_array statement, context
end

View File

@@ -1,15 +1,12 @@
module Typed
Compiler.class_eval do
module FieldAccess
def on_FieldAccess statement
# receiver_ast , field_ast = *statement
receiver = process(statement.receiver)
clazz = Register.machine.space.get_class_by_name receiver.type
field_name = statement.field.name
index = clazz.instance_type.variable_index(field_name)
raise "field access, but no such field:#{field_name} for class #{clazz.name}" unless index
value = use_reg(clazz.instance_type.type_at(index))

View File

@@ -1,11 +1,11 @@
module Typed
Compiler.class_eval do
module FieldDef
include AST::Sexp
def on_FieldDef statement
# type , name , value = *statement
reset_regs # field_def is a statement, no return and all regs
#puts statement.inspect
# type , name , value = *statement
name_s = no_space( statement.name.value )
@method.ensure_local( name_s, statement.type ) unless( @method.has_arg(name_s))
# if there is a value assigned, process it as am assignemnt statement (kind of call on_assign)