fix name expression and test
plus various cleaning and rename off call_site
This commit is contained in:
parent
2fde50c27a
commit
6f2affaf36
@ -1,12 +1,12 @@
|
|||||||
module Compiler
|
module Compiler
|
||||||
|
|
||||||
def self.compile expression , method
|
def self.compile expression , method
|
||||||
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
|
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
|
||||||
#puts "Expression #{exp_name}"
|
#puts "Expression #{exp_name}"
|
||||||
begin
|
begin
|
||||||
self.send "compile_#{exp_name}".to_sym , expression, method
|
self.send "compile_#{exp_name}".to_sym , expression, method
|
||||||
rescue NoMethodError => e
|
rescue NoMethodError => e
|
||||||
puts exp_name
|
puts "no compile method foudn for " + exp_name
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -14,7 +14,7 @@ module Compiler
|
|||||||
end
|
end
|
||||||
|
|
||||||
require_relative "compiler/basic_expressions"
|
require_relative "compiler/basic_expressions"
|
||||||
require_relative "compiler/call_site_expression"
|
require_relative "compiler/callsite_expression"
|
||||||
require_relative "compiler/compound_expressions"
|
require_relative "compiler/compound_expressions"
|
||||||
require_relative "compiler/if_expression"
|
require_relative "compiler/if_expression"
|
||||||
require_relative "compiler/function_expression"
|
require_relative "compiler/function_expression"
|
||||||
|
@ -11,28 +11,28 @@ module Compiler
|
|||||||
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
||||||
|
|
||||||
# attr_reader :value
|
# attr_reader :value
|
||||||
def self.compile_integer expession , method
|
def self.compile_integer expression , method
|
||||||
int = Virtual::IntegerConstant.new(expession.value)
|
int = Virtual::IntegerConstant.new(expression.value)
|
||||||
to = Virtual::Return.new(Virtual::Integer , int)
|
to = Virtual::Return.new(Virtual::Integer , int)
|
||||||
method.add_code Virtual::Set.new( to , int)
|
method.add_code Virtual::Set.new( to , int)
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compile_true expession , method
|
def self.compile_true expression , method
|
||||||
value = Virtual::TrueConstant.new
|
value = Virtual::TrueConstant.new
|
||||||
to = Virtual::Return.new(Virtual::Reference , value)
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
method.add_code Virtual::Set.new( to , value )
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compile_false expession , method
|
def self.compile_false expression , method
|
||||||
value = Virtual::FalseConstant.new
|
value = Virtual::FalseConstant.new
|
||||||
to = Virtual::Return.new(Virtual::Reference , value)
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
method.add_code Virtual::Set.new( to , value )
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compile_nil expession , method
|
def self.compile_nil expression , method
|
||||||
value = Virtual::NilConstant.new
|
value = Virtual::NilConstant.new
|
||||||
to = Virtual::Return.new(Virtual::Reference , value)
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
method.add_code Virtual::Set.new( to , value )
|
method.add_code Virtual::Set.new( to , value )
|
||||||
@ -41,20 +41,20 @@ module Compiler
|
|||||||
|
|
||||||
# attr_reader :name
|
# attr_reader :name
|
||||||
# compiling name needs to check if it's a variable and if so resolve it
|
# compiling name needs to check if it's a variable and if so resolve it
|
||||||
# otherwise it's a method without args and a send is usued.
|
# otherwise it's a method without args and a send is issued.
|
||||||
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
||||||
def self.compile_name expession , method
|
def self.compile_name expression , method
|
||||||
return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self
|
return Virtual::Self.new( Virtual::Mystery ) if expression.name == :self
|
||||||
if method.has_var(expession.name)
|
if method.has_var(expression.name)
|
||||||
message.compile_get(method , expession.name )
|
message.compile_get(method , expression.name )
|
||||||
else
|
else
|
||||||
raise "TODO unimplemented branch #{expession.class}(#{expession})"
|
call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit
|
||||||
message.compile_send( method , expession.name , Virtual::Self.new( Virtual::Mystery ) )
|
Compiler.compile(call, method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.compile_module expession , method
|
def self.compile_module expression , method
|
||||||
clazz = Virtual::BootSpace.space.get_or_create_class name
|
clazz = Virtual::BootSpace.space.get_or_create_class name
|
||||||
raise "uups #{clazz}.#{name}" unless clazz
|
raise "uups #{clazz}.#{name}" unless clazz
|
||||||
to = Virtual::Return.new(Virtual::Reference , clazz )
|
to = Virtual::Return.new(Virtual::Reference , clazz )
|
||||||
@ -63,8 +63,8 @@ module Compiler
|
|||||||
end
|
end
|
||||||
|
|
||||||
# attr_reader :string
|
# attr_reader :string
|
||||||
def self.compile_string expession , method
|
def self.compile_string expression , method
|
||||||
value = Virtual::StringConstant.new(expession.string)
|
value = Virtual::StringConstant.new(expression.string)
|
||||||
to = Virtual::Return.new(Virtual::Reference , value)
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
Virtual::BootSpace.space.add_object value
|
Virtual::BootSpace.space.add_object value
|
||||||
method.add_code Virtual::Set.new( to , value )
|
method.add_code Virtual::Set.new( to , value )
|
||||||
@ -72,22 +72,22 @@ module Compiler
|
|||||||
end
|
end
|
||||||
|
|
||||||
#attr_reader :left, :right
|
#attr_reader :left, :right
|
||||||
def self.compile_assignment expession , method
|
def self.compile_assignment expression , method
|
||||||
raise "must assign to NameExpression , not #{expession.left}" unless expession.left.instance_of? Ast::NameExpression
|
raise "must assign to NameExpression , not #{expression.left}" unless expression.left.instance_of? Ast::NameExpression
|
||||||
r = Compiler.compile(expession.right , method )
|
r = Compiler.compile(expression.right , method )
|
||||||
raise "oh noo, nil from where #{expession.right.inspect}" unless r
|
raise "oh noo, nil from where #{expression.right.inspect}" unless r
|
||||||
index = method.has_arg(name)
|
index = method.has_arg(name)
|
||||||
if index
|
if index
|
||||||
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::MessageSlot.new(index , r,type , r ))
|
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::MessageSlot.new(index , r,type , r ))
|
||||||
else
|
else
|
||||||
index = method.ensure_local(expession.left.name)
|
index = method.ensure_local(expression.left.name)
|
||||||
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::FrameSlot.new(index , r.type , r ))
|
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::FrameSlot.new(index , r.type , r ))
|
||||||
end
|
end
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compile_variable expession, method
|
def self.compile_variable expression, method
|
||||||
method.add_code Virtual::InstanceGet.new(expession.name)
|
method.add_code Virtual::InstanceGet.new(expression.name)
|
||||||
Virtual::Return.new( Virtual::Mystery )
|
Virtual::Return.new( Virtual::Mystery )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "meta_class"
|
require_relative "meta_class"
|
||||||
|
|
||||||
module Virtual
|
module Virtual
|
||||||
|
|
||||||
# class is mainly a list of methods with a name (for now)
|
# class is mainly a list of methods with a name (for now)
|
||||||
# layout of object is seperated into Layout
|
# layout of object is seperated into Layout
|
||||||
class BootClass < Virtual::ObjectConstant
|
class BootClass < Virtual::ObjectConstant
|
||||||
@ -22,8 +22,7 @@ module Virtual
|
|||||||
|
|
||||||
def get_instance_method fname
|
def get_instance_method fname
|
||||||
fname = fname.to_sym
|
fname = fname.to_sym
|
||||||
f = @instance_methods.detect{ |f| f.name == fname }
|
@instance_methods.detect{ |fun| fun.name == fname }
|
||||||
f
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# get the method and if not found, try superclasses. raise error if not found
|
# get the method and if not found, try superclasses. raise error if not found
|
||||||
@ -52,4 +51,4 @@ module Virtual
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -25,10 +25,9 @@ class TestBasic < MiniTest::Test
|
|||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_name
|
def test_name
|
||||||
#TODO
|
|
||||||
@string_input = 'foo '
|
@string_input = 'foo '
|
||||||
@output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER"
|
@output = "-Virtual::Return(:index => 5, :type => Virtual::Mystery)"
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user