zwischenstopp

This commit is contained in:
Torsten Ruger 2014-07-01 18:58:25 +03:00
parent 7045a4b256
commit f74999af57
6 changed files with 25 additions and 39 deletions

View File

@ -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

View File

@ -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

View File

@ -37,12 +37,10 @@ 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
@ -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

View File

@ -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

View File

@ -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

View File

@ -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