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

@ -3,7 +3,8 @@ require_relative "tree"
module Typed module Typed
CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , 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| CompilerModules.each do |mod|
require_relative "compiler/" + mod require_relative "compiler/" + mod
@ -189,9 +190,6 @@ module Typed
end end
end end
require_relative "compiler/collections"
require_relative "compiler/field_def"
require_relative "compiler/field_access"
require_relative "compiler/function_definition" require_relative "compiler/function_definition"
require_relative "compiler/operator_value" require_relative "compiler/operator_value"
require_relative "compiler/return_statement" require_relative "compiler/return_statement"

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
module Typed module Typed
class FieldAccess < Expression module Tree
attr_accessor :receiver , :field class FieldAccess < Expression
attr_accessor :receiver , :field
end
end end
end end