From f74999af5711b6d874ed6128b713bbf15d551fc3 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 1 Jul 2014 18:58:25 +0300 Subject: [PATCH] zwischenstopp --- lib/ast/basic_expressions.rb | 4 +--- lib/virtual/frame.rb | 14 ++++++++++---- lib/virtual/machine.rb | 14 ++++++++------ lib/virtual/mystery.rb | 8 +++++--- test/virtual/test_basic.rb | 22 ---------------------- test/virtual/virtual_helper.rb | 2 +- 6 files changed, 25 insertions(+), 39 deletions(-) diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 969ddf42..56c1f6fa 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -28,11 +28,9 @@ module Ast class NameExpression < Expression # attr_reader :name - # compiling a variable resolves it. if it wasn't defined, raise an exception + # compiling a variable resolves it. If it's not defined look call it as a menthod (which may raise NoMethodFound) def compile frame - # either a variable or needs to be called. frame.get(name) -# frame.send name end end diff --git a/lib/virtual/frame.rb b/lib/virtual/frame.rb index 6b77e3f4..83bfcc15 100644 --- a/lib/virtual/frame.rb +++ b/lib/virtual/frame.rb @@ -10,11 +10,17 @@ module Virtual # - next exception instruction # - self (me) # - argument mappings - # - local variable mapping + # - local variable mapping, together with last called binding class Frame - def initialize - + def initialize normal , exceptional , me + @next_normal = normal + @next_exception = exceptional + @me = me + # a binding represents the local variables at a point in the program. + # The amount of local variables is assumed to be relatively small, and so the + # storage is a linked list. Has the same api as a ha + @binding = List.new end - attr_reader :next_normal, :next_exception, :me, :argument_names + attr_reader :next_normal, :next_exception, :me, :binding end end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index a51ce1b0..f82d6802 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -37,13 +37,11 @@ module Virtual end def initialize - # a binding represents the local variables at a point in the program. - # The amount of local variables is assumed to be relatively small, and so the - # storage is a linked list. Has the same api as a ha - @bindings = List.new + the_end = HaltInstruction.new + @frame = Frame.new(the_end , the_end , :Object) end - attr_reader :bindings - + attr_reader :frame + # run the instruction stream given. Instructions are a graph and executing means traversing it. # If there is no next instruction the machine stops def run instruction @@ -53,6 +51,10 @@ module Virtual instruction = next_instruction end end + #return an anonymous new function (the top level) into which code is compiled + def anonymous + + end end end diff --git a/lib/virtual/mystery.rb b/lib/virtual/mystery.rb index a1ffb650..363709b7 100644 --- a/lib/virtual/mystery.rb +++ b/lib/virtual/mystery.rb @@ -9,10 +9,12 @@ module Virtual end - class TrueValue < Value + class Singleton < Value end - class FalseValue < Value + class TrueValue < Singleton end - class NilValue < Value + class FalseValue < Singleton + end + class NilValue < Singleton end end diff --git a/test/virtual/test_basic.rb b/test/virtual/test_basic.rb index 5a54eec9..0b65020c 100644 --- a/test/virtual/test_basic.rb +++ b/test/virtual/test_basic.rb @@ -32,19 +32,6 @@ class TestBasic < MiniTest::Test check end - def test_name_underscode_start - @string_input = '_bar ' - @output = Ast::NameExpression.new('_bar') - check - end - - def test_name_underscode_middle - @string_input = 'foo_bar ' - @parse_output = {:name => 'foo_bar'} - @output = Ast::NameExpression.new('foo_bar') - check - end - def test_instance_variable @string_input = '@foo_bar ' @parse_output = {:instance_variable=>{:name=>"foo_bar"}} @@ -74,13 +61,4 @@ class TestBasic < MiniTest::Test check end - def test_string_escapes - out = 'hello \nyou' - @string_input = '"' + out + '"' - @parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}, - {:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]} - @output = Ast::StringExpression.new(out) - check - end - end \ No newline at end of file diff --git a/test/virtual/virtual_helper.rb b/test/virtual/virtual_helper.rb index f81b8755..b1947c81 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -12,7 +12,7 @@ module VirtualHelper syntax = parser.parse_with_debug(@string_input) parts = Parser::Transform.new.apply(syntax) machine = Virtual::Machine.new - expressions = parts.compile(machine.bindings) + expressions = parts.compile(machine.frame , machine.anonymous) assert_equal @output , expressions end