From 059fb38f08d578593a4989ea580a92f4108a3416 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 9 Dec 2016 14:04:06 +0200 Subject: [PATCH] modulize field_access and field_def --- lib/typed/compiler.rb | 6 ++---- lib/typed/compiler/collections.rb | 3 ++- lib/typed/compiler/field_access.rb | 5 +---- lib/typed/compiler/field_def.rb | 6 +++--- lib/typed/tree/field_access.rb | 6 ++++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index 77771ef5..c52792df 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -3,7 +3,8 @@ require_relative "tree" module Typed CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , - "class_statement" , "if_statement" , "name_expression"] + "class_statement" , "collections" , "field_def" , "field_access", + "if_statement" , "name_expression"] CompilerModules.each do |mod| require_relative "compiler/" + mod @@ -189,9 +190,6 @@ module Typed end end -require_relative "compiler/collections" -require_relative "compiler/field_def" -require_relative "compiler/field_access" require_relative "compiler/function_definition" require_relative "compiler/operator_value" require_relative "compiler/return_statement" diff --git a/lib/typed/compiler/collections.rb b/lib/typed/compiler/collections.rb index 3ceb3f8c..7cb40d3b 100644 --- a/lib/typed/compiler/collections.rb +++ b/lib/typed/compiler/collections.rb @@ -1,6 +1,7 @@ module Typed - Compiler.class_eval do + module Collections + # attr_reader :values def on_array statement, context end diff --git a/lib/typed/compiler/field_access.rb b/lib/typed/compiler/field_access.rb index e83da282..15b3976f 100644 --- a/lib/typed/compiler/field_access.rb +++ b/lib/typed/compiler/field_access.rb @@ -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)) diff --git a/lib/typed/compiler/field_def.rb b/lib/typed/compiler/field_def.rb index 8bd373ce..6d5b0342 100644 --- a/lib/typed/compiler/field_def.rb +++ b/lib/typed/compiler/field_def.rb @@ -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) diff --git a/lib/typed/tree/field_access.rb b/lib/typed/tree/field_access.rb index 8c520c03..ae91cecc 100644 --- a/lib/typed/tree/field_access.rb +++ b/lib/typed/tree/field_access.rb @@ -1,5 +1,7 @@ module Typed - class FieldAccess < Expression - attr_accessor :receiver , :field + module Tree + class FieldAccess < Expression + attr_accessor :receiver , :field + end end end