move common statements into its only use in vool
This commit is contained in:
parent
79bf416e58
commit
ad4690d719
@ -9,7 +9,6 @@ module Common
|
|||||||
@next = nekst
|
@next = nekst
|
||||||
nekst
|
nekst
|
||||||
end
|
end
|
||||||
alias :<< :set_next
|
|
||||||
|
|
||||||
# during translation we replace one by one
|
# during translation we replace one by one
|
||||||
def replace_next( nekst )
|
def replace_next( nekst )
|
||||||
@ -44,6 +43,7 @@ module Common
|
|||||||
def append( code )
|
def append( code )
|
||||||
last.set_next code
|
last.set_next code
|
||||||
end
|
end
|
||||||
|
alias :<< :append
|
||||||
|
|
||||||
def length( labels = [] )
|
def length( labels = [] )
|
||||||
ret = 1
|
ret = 1
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
module Common
|
|
||||||
#extracted to resuse
|
|
||||||
module Statements
|
|
||||||
attr_reader :statements
|
|
||||||
def initialize(statements)
|
|
||||||
@statements = statements
|
|
||||||
end
|
|
||||||
|
|
||||||
def empty?
|
|
||||||
@statements.empty?
|
|
||||||
end
|
|
||||||
def single?
|
|
||||||
@statements.length == 1
|
|
||||||
end
|
|
||||||
def first
|
|
||||||
@statements.first
|
|
||||||
end
|
|
||||||
def last
|
|
||||||
@statements.last
|
|
||||||
end
|
|
||||||
def length
|
|
||||||
@statements.length
|
|
||||||
end
|
|
||||||
def [](i)
|
|
||||||
@statements[i]
|
|
||||||
end
|
|
||||||
def <<(o)
|
|
||||||
@statements << o
|
|
||||||
self
|
|
||||||
end
|
|
||||||
def add_array(a)
|
|
||||||
@statements += a
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -15,6 +15,5 @@ require_relative "risc"
|
|||||||
require_relative "arm/arm_machine"
|
require_relative "arm/arm_machine"
|
||||||
require_relative "arm/translator"
|
require_relative "arm/translator"
|
||||||
require_relative "common/list"
|
require_relative "common/list"
|
||||||
require_relative "common/statements"
|
|
||||||
require_relative "vool/vool_compiler"
|
require_relative "vool/vool_compiler"
|
||||||
require_relative "mom/mom"
|
require_relative "mom/mom"
|
||||||
|
@ -51,10 +51,10 @@ module Vool
|
|||||||
head
|
head
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect(arr)
|
def each(&block)
|
||||||
@if_true.collect(arr)
|
block.call(condition)
|
||||||
@if_false.collect(arr) if @if_false
|
@if_true.each(&block)
|
||||||
super
|
@if_false.each(&block) if @if_false
|
||||||
end
|
end
|
||||||
|
|
||||||
def simplify_condition
|
def simplify_condition
|
||||||
|
@ -60,7 +60,7 @@ module Vool
|
|||||||
type = @receiver.ct_type
|
type = @receiver.ct_type
|
||||||
called_method = type.resolve_method(@name)
|
called_method = type.resolve_method(@name)
|
||||||
raise "No method #{@name} for #{type}" unless called_method
|
raise "No method #{@name} for #{type}" unless called_method
|
||||||
Mom::Statements.new( message_setup(in_method) << Mom::SimpleCall.new( called_method) )
|
message_setup(in_method) << Mom::SimpleCall.new( called_method)
|
||||||
end
|
end
|
||||||
|
|
||||||
# this breaks cleanly into two parts:
|
# this breaks cleanly into two parts:
|
||||||
|
@ -1,6 +1,35 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class Statements < Statement
|
class Statements < Statement
|
||||||
include Common::Statements
|
attr_reader :statements
|
||||||
|
def initialize(statements)
|
||||||
|
@statements = statements
|
||||||
|
end
|
||||||
|
|
||||||
|
def empty?
|
||||||
|
@statements.empty?
|
||||||
|
end
|
||||||
|
def single?
|
||||||
|
@statements.length == 1
|
||||||
|
end
|
||||||
|
def first
|
||||||
|
@statements.first
|
||||||
|
end
|
||||||
|
def last
|
||||||
|
@statements.last
|
||||||
|
end
|
||||||
|
def length
|
||||||
|
@statements.length
|
||||||
|
end
|
||||||
|
def [](i)
|
||||||
|
@statements[i]
|
||||||
|
end
|
||||||
|
def <<(o)
|
||||||
|
@statements << o
|
||||||
|
self
|
||||||
|
end
|
||||||
|
def add_array(a)
|
||||||
|
@statements += a
|
||||||
|
end
|
||||||
|
|
||||||
# create machine instructions
|
# create machine instructions
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
@ -18,7 +47,7 @@ module Vool
|
|||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
block.call(self)
|
block.call(self)
|
||||||
@statements.each{|a| a.each(block)}
|
@statements.each{|a| a.each(&block)}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user