From 99132a92b6d3095b9a85d4052f892205da65bffb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 9 Dec 2016 14:17:01 +0200 Subject: [PATCH] modulize operator_expression --- lib/typed/compiler.rb | 4 ++-- .../compiler/{operator_value.rb => operator_expression.rb} | 7 ++----- lib/typed/tree/operator_expression.rb | 6 ++++-- lib/typed/tree/to_code.rb | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) rename lib/typed/compiler/{operator_value.rb => operator_expression.rb} (76%) diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index e6186fbd..40ffebb9 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -4,7 +4,8 @@ module Typed CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , "class_statement" , "collections" , "field_def" , "field_access", - "function_statement" , "if_statement" , "name_expression"] + "function_statement" , "if_statement" , "name_expression" , + "operator_expression"] CompilerModules.each do |mod| require_relative "compiler/" + mod @@ -190,7 +191,6 @@ module Typed end end -require_relative "compiler/operator_value" require_relative "compiler/return_statement" require_relative "compiler/statement_list" require_relative "compiler/while_statement" diff --git a/lib/typed/compiler/operator_value.rb b/lib/typed/compiler/operator_expression.rb similarity index 76% rename from lib/typed/compiler/operator_value.rb rename to lib/typed/compiler/operator_expression.rb index b3773394..f2a7fa91 100644 --- a/lib/typed/compiler/operator_value.rb +++ b/lib/typed/compiler/operator_expression.rb @@ -1,16 +1,13 @@ module Typed - Compiler.class_eval do + module OperatorExpression def on_OperatorExpression statement - #puts "operator #{statement.inspect}" -# operator , left_e , right_e = *statement + # operator , left_e , right_e = *statement # left and right must be expressions. Expressions return a register when compiled left_reg = process(statement.left_expression) right_reg = process(statement.right_expression) raise "Not register #{left_reg}" unless left_reg.is_a?(Register::RegisterValue) raise "Not register #{right_reg}" unless right_reg.is_a?(Register::RegisterValue) - #puts "left #{left_reg}" - #puts "right #{right_reg}" add_code Register::OperatorInstruction.new(statement,statement.operator,left_reg,right_reg) return left_reg # though this has wrong value attached end diff --git a/lib/typed/tree/operator_expression.rb b/lib/typed/tree/operator_expression.rb index 4df8bbb9..2d17c52f 100644 --- a/lib/typed/tree/operator_expression.rb +++ b/lib/typed/tree/operator_expression.rb @@ -1,5 +1,7 @@ module Typed - class OperatorExpression < Expression - attr_accessor :operator , :left_expression , :right_expression + module Tree + class OperatorExpression < Expression + attr_accessor :operator , :left_expression , :right_expression + end end end diff --git a/lib/typed/tree/to_code.rb b/lib/typed/tree/to_code.rb index dfb787c5..c8af3dfe 100644 --- a/lib/typed/tree/to_code.rb +++ b/lib/typed/tree/to_code.rb @@ -96,7 +96,7 @@ module Typed def on_operator_value statement operator , left_e , right_e = *statement - w = OperatorExpression.new() + w = Tree::OperatorExpression.new() w.operator = operator w.left_expression = process(left_e) w.right_expression = process(right_e)