more test working
operator wip
This commit is contained in:
@ -1,8 +1,5 @@
|
||||
module Bosl
|
||||
Compiler.class_eval do
|
||||
# operators are really function calls
|
||||
|
||||
# call_site - attr_reader :name, :args , :receiver
|
||||
|
||||
def on_call expression
|
||||
name , arguments , receiver = *expression
|
||||
|
@ -6,7 +6,7 @@ module Bosl
|
||||
end
|
||||
|
||||
def on_class expression
|
||||
puts expression.inspect
|
||||
#puts expression.inspect
|
||||
name , derives , expressions = *expression
|
||||
clazz = Parfait::Space.object_space.get_class_by_name! name
|
||||
#puts "Compiling class #{clazz.name.inspect}"
|
||||
|
@ -3,15 +3,13 @@ module Bosl
|
||||
# operator attr_reader :operator, :left, :right
|
||||
def on_operator expression
|
||||
operator , left , right = *expression
|
||||
nil
|
||||
Virtual::Return.new()
|
||||
end
|
||||
|
||||
def on_assign expression
|
||||
puts "assign"
|
||||
puts expression.inspect
|
||||
name , value = *expression
|
||||
name = name.to_a.first
|
||||
v = process(value )
|
||||
v = process(value)
|
||||
index = method.ensure_local( name )
|
||||
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index ) , v )
|
||||
end
|
||||
|
@ -1,25 +1,25 @@
|
||||
module Bosl
|
||||
Compiler.class_eval do
|
||||
|
||||
# while- attr_reader :condition, :body
|
||||
def on_while expression
|
||||
puts expression.inspect
|
||||
condition , expressions = *expression
|
||||
condition = condition.first
|
||||
|
||||
# this is where the while ends and both branches meet
|
||||
merge = method.source.new_block("while merge")
|
||||
# this comes after the current and beofre the merge
|
||||
start = method.source.new_block("while_start" )
|
||||
method.source.current start
|
||||
|
||||
cond = process(expression.condition)
|
||||
cond = process(condition)
|
||||
|
||||
method.source.add_code IsTrueBranch.new(merge)
|
||||
method.source.add_code Virtual::IsTrueBranch.new(merge)
|
||||
|
||||
last = process_all(expressions).last
|
||||
|
||||
last = cond
|
||||
expression.body.each do |part|
|
||||
last = process(part)
|
||||
raise part.inspect if last.nil?
|
||||
end
|
||||
# unconditionally branch to the start
|
||||
method.source.add_code UnconditionalBranch.new(start)
|
||||
method.source.add_code Virtual::UnconditionalBranch.new(start)
|
||||
|
||||
# continue execution / compiling at the merge block
|
||||
method.source.current merge
|
||||
|
@ -6,7 +6,7 @@ module Virtual
|
||||
# from may be a Constant (Object,Integer,String,Class)
|
||||
class Set < Instruction
|
||||
def initialize from , to
|
||||
raise "no to slot #{to}" unless to.is_a? Slot
|
||||
raise "no to slot #{to.inspect}" unless to.is_a? Slot
|
||||
@from = from
|
||||
@to = to
|
||||
end
|
||||
|
Reference in New Issue
Block a user