From 9ebe28450bcb9053df53c96bb59aceba31bbe4f8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 7 Nov 2015 12:19:04 +0200 Subject: [PATCH] add global variable space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit could in the long run move spaces functionality to the class and since the class is global anyway, wouldn’t need this --- lib/soml/compiler.rb | 7 +++++++ lib/soml/compiler/assignment.rb | 2 +- lib/soml/compiler/field_def.rb | 3 ++- lib/soml/compiler/name_expression.rb | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/soml/compiler.rb b/lib/soml/compiler.rb index d94944df..19ca9fe5 100644 --- a/lib/soml/compiler.rb +++ b/lib/soml/compiler.rb @@ -136,6 +136,13 @@ module Soml def reset_regs @regs.clear end + + # ensure the name given is not space and raise exception otherwise + # return the name for chaining + def no_space name + raise "space is a reserved name" if name == :space + name + end end end diff --git a/lib/soml/compiler/assignment.rb b/lib/soml/compiler/assignment.rb index 24dbef03..34afb1bb 100644 --- a/lib/soml/compiler/assignment.rb +++ b/lib/soml/compiler/assignment.rb @@ -5,7 +5,7 @@ module Soml reset_regs # statements reset registers, ie have all at their disposal #puts statement.inspect name , value = *statement - name = name.to_a.first + name = no_space name.to_a.first v = process(value) raise "Not register #{v}" unless v.is_a?(Register::RegisterValue) code = nil diff --git a/lib/soml/compiler/field_def.rb b/lib/soml/compiler/field_def.rb index 410074ea..eb79958a 100644 --- a/lib/soml/compiler/field_def.rb +++ b/lib/soml/compiler/field_def.rb @@ -6,7 +6,8 @@ module Soml reset_regs # field_def is a statement, no return and all regs #puts statement.inspect type , name , value = *statement - @method.ensure_local( name.first, type ) unless( @method.has_arg(name.first)) + name_s = no_space( name.first ) + @method.ensure_local( name_s, type ) unless( @method.has_arg(name_s)) # if there is a value assigned, process it as am assignemnt statement (kind of call on_assign) process( s(:assignment , name , value ) ) if value return nil diff --git a/lib/soml/compiler/name_expression.rb b/lib/soml/compiler/name_expression.rb index 14a6c7a6..ba834362 100644 --- a/lib/soml/compiler/name_expression.rb +++ b/lib/soml/compiler/name_expression.rb @@ -12,6 +12,12 @@ module Soml add_code Register.get_slot(statement , :message , :receiver , ret ) return ret end + if(name == :space) + space = Parfait::Space.object_space + reg = use_reg :Space , space + add_code Register::LoadConstant.new( statement, space , reg ) + return reg + end # either an argument, so it's stored in message if( index = @method.has_arg(name)) ret = use_reg @method.arguments[index].type