first tests comping through after ast/compile change
This commit is contained in:
parent
ff22c17784
commit
e4c799ecb6
@ -2,7 +2,7 @@ require_relative "instruction"
|
||||
|
||||
module Arm
|
||||
|
||||
# A Machines main responsibility in the framework is to instantiate Instruction
|
||||
# A Machines main responsibility in the framework is to instantiate Instructions
|
||||
|
||||
# Value functions are mapped to machines by concatenating the values class name + the methd name
|
||||
# Example: IntegerValue.plus( value ) -> Machine.signed_plus (value )
|
||||
@ -53,7 +53,6 @@ module Arm
|
||||
end
|
||||
|
||||
def self.class_for clazz
|
||||
c_name = clazz.name
|
||||
my_module = self.class.name.split("::").first
|
||||
clazz_name = clazz.name.split("::").last
|
||||
if(my_module != Register )
|
||||
|
@ -1,9 +1,9 @@
|
||||
module Compiler
|
||||
|
||||
def self.compile expression , method , message
|
||||
exp_name = expression.class.split("::").last.sub("Expression","").downcase
|
||||
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
|
||||
puts "Expression #{exp_name}"
|
||||
self.send exp_name.to_sym , method , message
|
||||
self.send "compile_#{exp_name}".to_sym , expression, method , message
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -11,28 +11,28 @@ module Compiler
|
||||
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
||||
|
||||
# attr_reader :value
|
||||
def compile_integer expession , method , message
|
||||
def self.compile_integer expession , method , message
|
||||
int = Virtual::IntegerConstant.new(value)
|
||||
to = Virtual::NewReturn.new(Virtual::Integer , int)
|
||||
method.add_code Virtual::Set.new( to , int)
|
||||
to
|
||||
end
|
||||
|
||||
def compile_true expession , method , message
|
||||
def self.compile_true expession , method , message
|
||||
value = Virtual::TrueConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def compile_false expession , method , message
|
||||
def self.compile_false expession , method , message
|
||||
value = Virtual::FalseConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def compile_nil expession , method , message
|
||||
def self.compile_nil expession , method , message
|
||||
value = Virtual::NilConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
@ -43,7 +43,7 @@ module Compiler
|
||||
# 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 ussued.
|
||||
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
||||
def compile_name expession , method , message
|
||||
def self.compile_name expession , method , message
|
||||
return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self
|
||||
if method.has_var(expession.name)
|
||||
message.compile_get(method , expession.name )
|
||||
@ -54,7 +54,7 @@ module Compiler
|
||||
end
|
||||
|
||||
|
||||
def compile_module expession , method , message
|
||||
def self.compile_module expession , method , message
|
||||
clazz = Virtual::BootSpace.space.get_or_create_class name
|
||||
raise "uups #{clazz}.#{name}" unless clazz
|
||||
to = Virtual::Return.new(Virtual::Reference , clazz )
|
||||
@ -63,7 +63,7 @@ module Compiler
|
||||
end
|
||||
|
||||
# attr_reader :string
|
||||
def compile_string expession , method , message
|
||||
def self.compile_string expession , method , message
|
||||
value = Virtual::StringConstant.new(expession.string)
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
Virtual::BootSpace.space.add_object value
|
||||
@ -72,14 +72,14 @@ module Compiler
|
||||
end
|
||||
|
||||
#attr_reader :left, :right
|
||||
def compile_assignment expession , method , message
|
||||
def self.compile_assignment expession , method , message
|
||||
raise "must assign to NameExpression , not #{expession.left}" unless expession.left.instance_of? NameExpression
|
||||
r = right.compile(method,message)
|
||||
raise "oh noo, nil from where #{expession.right.inspect}" unless r
|
||||
message.compile_set( method , expession.left.name , r )
|
||||
end
|
||||
|
||||
def compile_variable expession, method , message
|
||||
def self.compile_variable expession, method , message
|
||||
method.add_code Virtual::InstanceGet.new(expession.name)
|
||||
Virtual::NewReturn.new( Virtual::Mystery )
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ module Compiler
|
||||
|
||||
# call_site - attr_reader :name, :args , :receiver
|
||||
|
||||
def compile_call_site expession , method , message
|
||||
def self.compile_call_site expession , method , message
|
||||
me = expession.receiver.compile( method, message )
|
||||
method.add_code Virtual::NewMessage.new
|
||||
method.add_code Virtual::Set.new(Virtual::NewSelf.new(me.type), me)
|
||||
|
@ -1,14 +1,14 @@
|
||||
module Compiler
|
||||
|
||||
# attr_reader :values
|
||||
def compile_array expession, context
|
||||
def self.compile_array expession, context
|
||||
to.do
|
||||
end
|
||||
# attr_reader :key , :value
|
||||
def compile_association context
|
||||
def self.compile_association context
|
||||
to.do
|
||||
end
|
||||
def compile_hash context
|
||||
def self.compile_hash context
|
||||
to.do
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
module Compiler
|
||||
# list - attr_reader :expressions
|
||||
def compile_list expession , method , message
|
||||
expession.expressions.collect { |part| part.compile( method, message ) }
|
||||
def self.compile_list expession , method , message
|
||||
expession.expressions.collect do |part|
|
||||
Compiler.compile( part , method, message )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Compiler
|
||||
# function attr_reader :name, :params, :body , :receiver
|
||||
def compile_function expression, method , message
|
||||
def self.compile_function expression, method , message
|
||||
args = expession.params.collect do |p|
|
||||
raise "error, argument must be a identifier, not #{p}" unless p.is_a? NameExpression
|
||||
p.name
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Compiler
|
||||
# if - attr_reader :cond, :if_true, :if_false
|
||||
|
||||
def compile_if expression , method , message
|
||||
def self.compile_if expression , method , message
|
||||
# to execute the logic as the if states it, the blocks are the other way around
|
||||
# so we can the jump over the else if true ,and the else joins unconditionally after the true_block
|
||||
merge_block = method.new_block "if_merge" # last one, created first
|
||||
|
@ -1,10 +1,10 @@
|
||||
module Compiler
|
||||
# module attr_reader :name ,:expressions
|
||||
def compile_module expression , context
|
||||
def self.compile_module expression , context
|
||||
return clazz
|
||||
end
|
||||
|
||||
def compile_class expression , method , message
|
||||
def self.compile_class expression , method , message
|
||||
clazz = ::Virtual::BootSpace.space.get_or_create_class name
|
||||
puts "Created class #{clazz.name.inspect}"
|
||||
expression.expressions.each do |expr|
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Compiler
|
||||
# operator attr_reader :operator, :left, :right
|
||||
def compile_operator expression, method , message
|
||||
def self.compile_operator expression, method , message
|
||||
call = CallSiteExpression.new( operator , [right] , left )
|
||||
call.compile(method,message)
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Compiler
|
||||
|
||||
# return attr_reader :expression
|
||||
def compile_return expression, scope ,method
|
||||
def self.compile_return expression, scope ,method
|
||||
Virtual::Reference.new
|
||||
end
|
||||
def old
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Compiler
|
||||
|
||||
# while- attr_reader :condition, :body
|
||||
def compile_while expression, method , message
|
||||
def self.compile_while expression, method , message
|
||||
start = Virtual::Label.new("while_start")
|
||||
method.add_code start
|
||||
is = expression.condition.compile(method,message)
|
||||
|
@ -24,7 +24,7 @@ module Builtin
|
||||
# The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
|
||||
def _get_instance_variable context , name = Virtual::Integer
|
||||
get_function = Virtual::CompiledMethod.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery )
|
||||
# return get_function
|
||||
return get_function
|
||||
me = get_function.receiver
|
||||
var_name = get_function.args.first
|
||||
return_to = get_function.return_type
|
||||
|
@ -63,7 +63,7 @@ module Virtual
|
||||
def locals_at l_block
|
||||
used =[]
|
||||
# call assigns the return register, but as it is in l_block, it is not asked.
|
||||
assigned = [ RegisterReference.new(Register::RegisterMachine.instance.return_register) ]
|
||||
assigned = [ RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ]
|
||||
l_block.reachable.each do |b|
|
||||
b.uses.each {|u|
|
||||
(used << u) unless assigned.include?(u)
|
||||
@ -158,11 +158,11 @@ module Virtual
|
||||
# mov( r1 , r2 )
|
||||
# add( r1 , r2 , 4)
|
||||
# end
|
||||
# mov and add will be called on Machine and generate Inststuction that are then added
|
||||
# mov and add will be called on Machine and generate Instructions that are then added
|
||||
# to the current block
|
||||
# also symbols are supported and wrapped as register usages (for bare metal programming)
|
||||
def method_missing(meth, *arg_names, &block)
|
||||
add_code ::Register::RegisterMachine.instance.send(meth , *arg_names)
|
||||
add_code ::Arm::ArmMachine.send(meth , *arg_names)
|
||||
end
|
||||
|
||||
def mem_length
|
||||
|
@ -50,7 +50,8 @@ module Virtual
|
||||
# read all the files needed for a minimal system at compile
|
||||
classes = ["object"]
|
||||
classes.each do |clazz|
|
||||
bytes = File.read(File.join( File.dirname( __FILE__ ) , ".." , "parfait" , "#{clazz}.rb") )
|
||||
bytes = File.read(File.join( File.dirname( __FILE__ ) , ".." , "parfait" , "#{clazz}.rb") )
|
||||
bytes = 0 #shuts up my atom linter
|
||||
# expression = compile_main(bytes)
|
||||
end
|
||||
end
|
||||
@ -59,7 +60,7 @@ module Virtual
|
||||
syntax = @parser.parse_with_debug(bytes)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
main = Virtual::CompiledMethod.main
|
||||
parts.compile( main , self.message )
|
||||
Compiler.compile( parts , main , self.message )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -30,12 +30,12 @@ HERE
|
||||
# a hand coded version of the fibonachi numbers (moved to kernel to be able to call it)
|
||||
# not my hand off course, found in the net from a basic introduction
|
||||
def test_kernel_fibo
|
||||
int = Register::Integer.new(Register::RegisterMachine.instance.receiver_register)
|
||||
int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
|
||||
fibo = @object_space.get_or_create_class(:Object).resolve_method(:fibo)
|
||||
main = @object_space.main
|
||||
main.mov int , 10
|
||||
main.call( fibo )
|
||||
main.mov( Register::RegisterMachine.instance.receiver_register , Register::RegisterMachine.instance.return_register )
|
||||
main.mov( Virtual::RegisterMachine.instance.receiver_register , Virtual::RegisterMachine.instance.return_register )
|
||||
putint = @object_space.get_or_create_class(:Object).resolve_method(:putint)
|
||||
main.call( putint )
|
||||
@should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0x52,0xe3,0x2,0x0,0xa0,0xd1,0x7,0x0,0x0,0xda,0x1,0x30,0xa0,0xe3,0x0,0x40,0xa0,0xe3,0x4,0x30,0x83,0xe0,0x4,0x40,0x43,0xe0,0x1,0x20,0x42,0xe2,0x1,0x0,0x52,0xe3,0xfa,0xff,0xff,0x1a,0x3,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
|
||||
|
Loading…
Reference in New Issue
Block a user