create rubyx dir and move previous vool_compiler there
This commit is contained in:
parent
63dd6d9039
commit
c8451d0048
@ -23,10 +23,10 @@ guard :minitest , all_on_start: false do # with Minitest::Unit
|
|||||||
watch(%r{^lib/parfait/type.rb}) { Dir["test/parfait/type/test_*.rb"] }
|
watch(%r{^lib/parfait/type.rb}) { Dir["test/parfait/type/test_*.rb"] }
|
||||||
|
|
||||||
# ruby compiler tests have a whole directory
|
# ruby compiler tests have a whole directory
|
||||||
watch(%r{^lib/vool/ruby_compiler.rb}) { Dir["test/vool/ruby_compiler/test_*.rb"] }
|
watch(%r{^lib/rubyx/ruby_compiler.rb}) { Dir["test/rubyx/ruby_compiler/test_*.rb"] }
|
||||||
|
|
||||||
# Vool to_mom compile process + # Ruby to vool compile process
|
# Vool to_mom compile process + # Ruby to vool compile process
|
||||||
watch(%r{^lib/vool/statements/(.+)_statement.rb}) { |m|
|
watch(%r{^lib/vool/(.+)_statement.rb}) { |m|
|
||||||
[ Dir["test/vool/to_mom/test_#{m[1]}*.rb"] , "test/vool/statements/test_#{m[1]}.rb"] }
|
[ Dir["test/vool/to_mom/test_#{m[1]}*.rb"] , "test/vool/statements/test_#{m[1]}.rb"] }
|
||||||
watch(%r{^lib/vool/statements/send_statement.rb}) {
|
watch(%r{^lib/vool/statements/send_statement.rb}) {
|
||||||
[ Dir["test/vool/to_mom/send/test_*.rb"] , "test/vool/statements/test_send_statement.rb"] }
|
[ Dir["test/vool/to_mom/send/test_*.rb"] , "test/vool/statements/test_send_statement.rb"] }
|
||||||
|
@ -14,5 +14,6 @@ require_relative "elf/object_writer"
|
|||||||
require_relative "risc"
|
require_relative "risc"
|
||||||
require_relative "arm/arm_machine"
|
require_relative "arm/arm_machine"
|
||||||
require_relative "arm/arm_platform"
|
require_relative "arm/arm_platform"
|
||||||
require_relative "vool/vool_compiler"
|
require_relative "vool/statement"
|
||||||
|
require_relative "rubyx/rubyx_compiler"
|
||||||
require_relative "mom/mom"
|
require_relative "mom/mom"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
require_relative "statement"
|
|
||||||
|
|
||||||
module Vool
|
module RubyX
|
||||||
# This RubyCompiler compiles incoming ruby (string) into vools internal representation
|
# This RubyCompiler compiles incoming ruby (string) into vools internal representation
|
||||||
# with the help of the parser gem. The parser outputs an abstract ast (nodes)
|
# with the help of the parser gem. The parser outputs an abstract ast (nodes)
|
||||||
# that get transformed into concrete, specific classes.
|
# that get transformed into concrete, specific classes.
|
||||||
@ -24,13 +23,13 @@ module Vool
|
|||||||
|
|
||||||
def on_class( statement )
|
def on_class( statement )
|
||||||
name , sup , body = *statement
|
name , sup , body = *statement
|
||||||
ClassStatement.new( get_name(name) , get_name(sup) , process(body) )
|
Vool::ClassStatement.new( get_name(name) , get_name(sup) , process(body) )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_def( statement )
|
def on_def( statement )
|
||||||
name , args , body = *statement
|
name , args , body = *statement
|
||||||
arg_array = process_all( args )
|
arg_array = process_all( args )
|
||||||
MethodStatement.new( name , arg_array , process(body) )
|
Vool::MethodStatement.new( name , arg_array , process(body) )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_arg( arg )
|
def on_arg( arg )
|
||||||
@ -41,13 +40,13 @@ module Vool
|
|||||||
sendd = process(block_node.children[0])
|
sendd = process(block_node.children[0])
|
||||||
args = process(block_node.children[1])
|
args = process(block_node.children[1])
|
||||||
body = process(block_node.children[2])
|
body = process(block_node.children[2])
|
||||||
sendd.add_block BlockStatement.new(args , body)
|
sendd.add_block Vool::BlockStatement.new(args , body)
|
||||||
sendd
|
sendd
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_yield(node)
|
def on_yield(node)
|
||||||
args = process_all(node.children)
|
args = process_all(node.children)
|
||||||
YieldStatement.new(args)
|
Vool::YieldStatement.new(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_args(args)
|
def on_args(args)
|
||||||
@ -56,31 +55,31 @@ module Vool
|
|||||||
|
|
||||||
#basic Values
|
#basic Values
|
||||||
def on_self exp
|
def on_self exp
|
||||||
SelfExpression.new
|
Vool::SelfExpression.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_nil expression
|
def on_nil expression
|
||||||
NilConstant.new
|
Vool::NilConstant.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_int expression
|
def on_int expression
|
||||||
IntegerConstant.new(expression.children.first)
|
Vool::IntegerConstant.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_float expression
|
def on_float expression
|
||||||
FloatConstant.new(expression.children.first)
|
Vool::FloatConstant.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_true expression
|
def on_true expression
|
||||||
TrueConstant.new
|
Vool::TrueConstant.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_false expression
|
def on_false expression
|
||||||
FalseConstant.new
|
Vool::FalseConstant.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_str expression
|
def on_str expression
|
||||||
StringConstant.new(expression.children.first)
|
Vool::StringConstant.new(expression.children.first)
|
||||||
end
|
end
|
||||||
alias :on_string :on_str
|
alias :on_string :on_str
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ module Vool
|
|||||||
alias :on_xstr :on_dstr
|
alias :on_xstr :on_dstr
|
||||||
|
|
||||||
def on_sym expression
|
def on_sym expression
|
||||||
SymbolConstant.new(expression.children.first)
|
Vool::SymbolConstant.new(expression.children.first)
|
||||||
end
|
end
|
||||||
alias :on_string :on_str
|
alias :on_string :on_str
|
||||||
|
|
||||||
@ -98,17 +97,17 @@ module Vool
|
|||||||
raise "Not implemented dynamix symbols (with interpolation)"
|
raise "Not implemented dynamix symbols (with interpolation)"
|
||||||
end
|
end
|
||||||
def on_kwbegin statement
|
def on_kwbegin statement
|
||||||
ScopeStatement.new process_all( statement.children )
|
Vool::ScopeStatement.new process_all( statement.children )
|
||||||
end
|
end
|
||||||
alias :on_begin :on_kwbegin
|
alias :on_begin :on_kwbegin
|
||||||
|
|
||||||
# Array + Hashes
|
# Array + Hashes
|
||||||
def on_array expression
|
def on_array expression
|
||||||
ArrayStatement.new expression.children.collect{ |elem| process(elem) }
|
Vool::ArrayStatement.new expression.children.collect{ |elem| process(elem) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_hash expression
|
def on_hash expression
|
||||||
hash = HashStatement.new
|
hash = Vool::HashStatement.new
|
||||||
expression.children.each do |elem|
|
expression.children.each do |elem|
|
||||||
raise "Hash error, hash contains non pair: #{elem.type}" if elem.type != :pair
|
raise "Hash error, hash contains non pair: #{elem.type}" if elem.type != :pair
|
||||||
hash.add( process(elem.children[0]) , process(elem.children[1]) )
|
hash.add( process(elem.children[0]) , process(elem.children[1]) )
|
||||||
@ -118,15 +117,15 @@ module Vool
|
|||||||
|
|
||||||
#Variables
|
#Variables
|
||||||
def on_lvar expression
|
def on_lvar expression
|
||||||
LocalVariable.new(expression.children.first)
|
Vool::LocalVariable.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_ivar expression
|
def on_ivar expression
|
||||||
InstanceVariable.new(instance_name(expression.children.first))
|
Vool::InstanceVariable.new(instance_name(expression.children.first))
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_cvar expression
|
def on_cvar expression
|
||||||
ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym)
|
Vool::ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_const expression
|
def on_const expression
|
||||||
@ -134,20 +133,20 @@ module Vool
|
|||||||
if scope
|
if scope
|
||||||
raise "Only unscoped Names implemented #{scope}" unless scope.type == :cbase
|
raise "Only unscoped Names implemented #{scope}" unless scope.type == :cbase
|
||||||
end
|
end
|
||||||
ModuleName.new(expression.children[1])
|
Vool::ModuleName.new(expression.children[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Assignements
|
# Assignements
|
||||||
def on_lvasgn expression
|
def on_lvasgn expression
|
||||||
name = expression.children[0]
|
name = expression.children[0]
|
||||||
value = process(expression.children[1])
|
value = process(expression.children[1])
|
||||||
LocalAssignment.new(name,value)
|
Vool::LocalAssignment.new(name,value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_ivasgn expression
|
def on_ivasgn expression
|
||||||
name = expression.children[0]
|
name = expression.children[0]
|
||||||
value = process(expression.children[1])
|
value = process(expression.children[1])
|
||||||
IvarAssignment.new(instance_name(name),value)
|
Vool::IvarAssignment.new(instance_name(name),value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_op_asgn(expression)
|
def on_op_asgn(expression)
|
||||||
@ -162,52 +161,52 @@ module Vool
|
|||||||
|
|
||||||
def on_return statement
|
def on_return statement
|
||||||
return_value = process(statement.children.first)
|
return_value = process(statement.children.first)
|
||||||
ReturnStatement.new( return_value )
|
Vool::ReturnStatement.new( return_value )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_while statement
|
def on_while statement
|
||||||
condition , statements = *statement
|
condition , statements = *statement
|
||||||
WhileStatement.new( process(condition) , process(statements))
|
Vool::WhileStatement.new( process(condition) , process(statements))
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_if statement
|
def on_if statement
|
||||||
condition , if_true , if_false = *statement
|
condition , if_true , if_false = *statement
|
||||||
if_true = process(if_true)
|
if_true = process(if_true)
|
||||||
if_false = process(if_false)
|
if_false = process(if_false)
|
||||||
IfStatement.new( process(condition) , if_true , if_false )
|
Vool::IfStatement.new( process(condition) , if_true , if_false )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_send statement
|
def on_send statement
|
||||||
kids = statement.children.dup
|
kids = statement.children.dup
|
||||||
receiver = process(kids.shift) || SelfExpression.new
|
receiver = process(kids.shift) || Vool::SelfExpression.new
|
||||||
name = kids.shift
|
name = kids.shift
|
||||||
arguments = process_all(kids)
|
arguments = process_all(kids)
|
||||||
SendStatement.new( name , receiver , arguments )
|
Vool::SendStatement.new( name , receiver , arguments )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_and expression
|
def on_and expression
|
||||||
name = expression.type
|
name = expression.type
|
||||||
left = process(expression.children[0])
|
left = process(expression.children[0])
|
||||||
right = process( expression.children[1] )
|
right = process( expression.children[1] )
|
||||||
LogicalStatement.new( name , left , right)
|
Vool::LogicalStatement.new( name , left , right)
|
||||||
end
|
end
|
||||||
alias :on_or :on_and
|
alias :on_or :on_and
|
||||||
|
|
||||||
# this is a call to super without args (z = zero arity)
|
# this is a call to super without args (z = zero arity)
|
||||||
def on_zsuper exp
|
def on_zsuper exp
|
||||||
SendStatement.new( nil , SuperExpression.new , nil)
|
Vool::SendStatement.new( nil , Vool::SuperExpression.new , nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# this is a call to super with args and
|
# this is a call to super with args and
|
||||||
# same name as current method, which is set later
|
# same name as current method, which is set later
|
||||||
def on_super( statement )
|
def on_super( statement )
|
||||||
arguments = process_all(statement.children)
|
arguments = process_all(statement.children)
|
||||||
SendStatement.new( nil , SuperExpression.new , arguments)
|
Vool::SendStatement.new( nil , Vool::SuperExpression.new , arguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_assignment statement
|
def on_assignment statement
|
||||||
name , value = *statement
|
name , value = *statement
|
||||||
w = Assignment.new()
|
w = Vool::Assignment.new()
|
||||||
w.name = process name
|
w.name = process name
|
||||||
w.value = process(value)
|
w.value = process(value)
|
||||||
w
|
w
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "ruby_compiler"
|
require_relative "ruby_compiler"
|
||||||
|
|
||||||
module Vool
|
module RubyX
|
||||||
class VoolCompiler
|
class RubyXCompiler
|
||||||
|
|
||||||
def self.ruby_to_vool( ruby_source )
|
def self.ruby_to_vool( ruby_source )
|
||||||
vool = RubyCompiler.compile( ruby_source )
|
vool = RubyCompiler.compile( ruby_source )
|
||||||
@ -12,7 +12,7 @@ module Vool
|
|||||||
def self.ruby_to_binary(source , platform = :arm)
|
def self.ruby_to_binary(source , platform = :arm)
|
||||||
machine = Risc.machine.boot
|
machine = Risc.machine.boot
|
||||||
vool = self.ruby_to_vool(source)
|
vool = self.ruby_to_vool(source)
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil).class
|
||||||
machine.translate(platform)
|
machine.translate(platform)
|
||||||
machine.position_all
|
machine.position_all
|
||||||
machine.create_binary
|
machine.create_binary
|
93
lib/vool/basic_values.rb
Normal file
93
lib/vool/basic_values.rb
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
module Vool
|
||||||
|
class Constant < Expression
|
||||||
|
#gobble it up
|
||||||
|
def each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class IntegerConstant < Constant
|
||||||
|
attr_reader :value
|
||||||
|
def initialize(value)
|
||||||
|
@value = value
|
||||||
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
||||||
|
end
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||||
|
end
|
||||||
|
def to_s
|
||||||
|
value.to_s
|
||||||
|
end
|
||||||
|
def each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class FloatConstant < Constant
|
||||||
|
attr_reader :value
|
||||||
|
def initialize(value)
|
||||||
|
@value = value
|
||||||
|
end
|
||||||
|
def ct_type
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class TrueConstant < Constant
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||||
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class FalseConstant < Constant
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||||
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class NilConstant < Constant
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||||
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class SelfExpression < Expression
|
||||||
|
attr_reader :my_type
|
||||||
|
def initialize(type = nil)
|
||||||
|
@my_type = type
|
||||||
|
end
|
||||||
|
def slot_definition(in_method)
|
||||||
|
@my_type = in_method.for_type
|
||||||
|
Mom::SlotDefinition.new(:message , [:receiver])
|
||||||
|
end
|
||||||
|
def ct_type
|
||||||
|
@my_type
|
||||||
|
end
|
||||||
|
def to_s
|
||||||
|
"self"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class SuperExpression < Statement
|
||||||
|
end
|
||||||
|
class StringConstant < Constant
|
||||||
|
attr_reader :value
|
||||||
|
def initialize(value)
|
||||||
|
@value = value
|
||||||
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
||||||
|
end
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class SymbolConstant < StringConstant
|
||||||
|
def ct_type
|
||||||
|
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
17
lib/vool/local_assignment.rb
Normal file
17
lib/vool/local_assignment.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module Vool
|
||||||
|
|
||||||
|
class LocalAssignment < Assignment
|
||||||
|
|
||||||
|
def to_mom( method )
|
||||||
|
if method.arguments_type.variable_index(@name)
|
||||||
|
type = :arguments
|
||||||
|
else
|
||||||
|
type = :frame
|
||||||
|
end
|
||||||
|
to = Mom::SlotDefinition.new(:message ,[ type , @name])
|
||||||
|
from = @value.slot_definition(method)
|
||||||
|
return chain_assign( Mom::SlotLoad.new(to,from) , method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
22
lib/vool/normalizer.rb
Normal file
22
lib/vool/normalizer.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module Vool
|
||||||
|
module Normalizer
|
||||||
|
# given a something, determine if it is a Name
|
||||||
|
#
|
||||||
|
# Return a Name, and a possible rest that has a hoisted part of the statement
|
||||||
|
#
|
||||||
|
# eg if( @var % 5) is not normalized
|
||||||
|
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
|
||||||
|
#
|
||||||
|
# also constants count, though they may not be so useful in ifs, but returns
|
||||||
|
def normalize_name( condition )
|
||||||
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||||
|
condition = condition.first
|
||||||
|
end
|
||||||
|
return [condition] if condition.is_a?(Named) or condition.is_a?(Constant)
|
||||||
|
condition = condition.normalize
|
||||||
|
local = "tmp_#{object_id}".to_sym
|
||||||
|
assign = Statements.new [LocalAssignment.new( local , condition)]
|
||||||
|
[LocalVariable.new(local) , assign]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
41
lib/vool/variables.rb
Normal file
41
lib/vool/variables.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
module Vool
|
||||||
|
module Named
|
||||||
|
attr_reader :name
|
||||||
|
def initialize name
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
def each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class LocalVariable < Expression
|
||||||
|
include Named
|
||||||
|
def slot_definition(method)
|
||||||
|
if method.arguments_type.variable_index(@name)
|
||||||
|
type = :arguments
|
||||||
|
else
|
||||||
|
type = :frame
|
||||||
|
end
|
||||||
|
Mom::SlotDefinition.new(:message , [type , @name])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class InstanceVariable < Expression
|
||||||
|
include Named
|
||||||
|
def slot_definition(method)
|
||||||
|
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
|
||||||
|
end
|
||||||
|
# used to collect type information
|
||||||
|
def add_ivar( array )
|
||||||
|
array << @name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ClassVariable < Expression
|
||||||
|
include Named
|
||||||
|
end
|
||||||
|
|
||||||
|
class ModuleName < Expression
|
||||||
|
include Named
|
||||||
|
end
|
||||||
|
end
|
@ -18,7 +18,7 @@ module Elf
|
|||||||
in_space("def main(arg);#{input};end")
|
in_space("def main(arg);#{input};end")
|
||||||
end
|
end
|
||||||
def check(input, file)
|
def check(input, file)
|
||||||
Vool::VoolCompiler.ruby_to_binary( input )
|
Vool::RubyXCompiler.ruby_to_binary( input )
|
||||||
writer = Elf::ObjectWriter.new(Risc.machine)
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
writer.save "test/#{file}.o"
|
writer.save "test/#{file}.o"
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ module Mains
|
|||||||
def compile(input , file , scp)
|
def compile(input , file , scp)
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
puts "Compiling test/#{file}.o" if DEBUG
|
puts "Compiling test/#{file}.o" if DEBUG
|
||||||
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
|
Vool::RubyXCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
|
||||||
writer = Elf::ObjectWriter.new(Risc.machine)
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
writer.save "test/#{file}.o"
|
writer.save "test/#{file}.o"
|
||||||
object_file = "/tmp/#{file}.o"
|
object_file = "/tmp/#{file}.o"
|
||||||
|
@ -28,7 +28,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def produce_instructions
|
def produce_instructions
|
||||||
assert @expect , "No output given"
|
assert @expect , "No output given"
|
||||||
Vool::VoolCompiler.ruby_to_binary as_test_main , :interpreter
|
Vool::RubyXCompiler.ruby_to_binary as_test_main , :interpreter
|
||||||
test = Parfait.object_space.get_class_by_name :Test
|
test = Parfait.object_space.get_class_by_name :Test
|
||||||
test.instance_type.get_method(:main).cpu_instructions
|
test.instance_type.get_method(:main).cpu_instructions
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_method
|
def create_method
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
test.get_method(:meth)
|
test.get_method(:meth)
|
||||||
@ -37,24 +37,24 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_method_statement_in_class
|
def test_creates_method_statement_in_class
|
||||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal MethodStatement , clazz.body.class
|
assert_equal MethodStatement , clazz.body.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_statement_has_class
|
def test_method_statement_has_class
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
clazz = vool.to_mom(nil)
|
clazz = vool.to_mom(nil)
|
||||||
assert vool.body.clazz
|
assert vool.body.clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parfait_class_creation
|
def test_parfait_class_creation
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
clazz = vool.to_mom(nil)
|
clazz = vool.to_mom(nil)
|
||||||
assert_equal Parfait::Class , vool.body.clazz.class
|
assert_equal Parfait::Class , vool.body.clazz.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_typed_method_instance_type
|
def test_typed_method_instance_type
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5; @ibar = 4;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5; @ibar = 4;end")
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
method = test.instance_type.get_method(:meth)
|
method = test.instance_type.get_method(:meth)
|
||||||
@ -63,7 +63,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_vool_method_has_one_local
|
def test_vool_method_has_one_local
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
method = test.get_method(:meth)
|
method = test.get_method(:meth)
|
||||||
@ -73,7 +73,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_typed_method_has_one_local
|
def test_typed_method_has_one_local
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
vool = RubyXCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
method = test.instance_type.get_method(:meth)
|
method = test.instance_type.get_method(:meth)
|
||||||
|
9
test/rubyx/ruby_compiler/helper.rb
Normal file
9
test/rubyx/ruby_compiler/helper.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
require_relative "../../helper"
|
||||||
|
|
||||||
|
module Vool
|
||||||
|
module RubyTests
|
||||||
|
def compile(input)
|
||||||
|
RubyX::RubyCompiler.compile(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,17 +2,18 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestArray < MiniTest::Test
|
class TestArray < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_empty
|
def test_empty
|
||||||
lst = RubyCompiler.compile( "[]")
|
lst = compile( "[]")
|
||||||
assert_equal ArrayStatement , lst.class
|
assert_equal ArrayStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_one
|
def test_one
|
||||||
lst = RubyCompiler.compile( "[1]")
|
lst = compile( "[1]")
|
||||||
assert_equal ArrayStatement , lst.class
|
assert_equal ArrayStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_two
|
def test_two
|
||||||
lst = RubyCompiler.compile( "[1,2]")
|
lst = compile( "[1,2]")
|
||||||
assert_equal ArrayStatement , lst.class
|
assert_equal ArrayStatement , lst.class
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,76 +2,79 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestBasicValues < MiniTest::Test
|
class TestBasicValues < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_self
|
def test_self
|
||||||
lst = RubyCompiler.compile( "self")
|
lst = compile( "self")
|
||||||
assert_equal SelfExpression , lst.class
|
assert_equal SelfExpression , lst.class
|
||||||
end
|
end
|
||||||
def test_nil
|
def test_nil
|
||||||
lst = RubyCompiler.compile( "nil")
|
lst = compile( "nil")
|
||||||
assert_equal NilConstant , lst.class
|
assert_equal NilConstant , lst.class
|
||||||
end
|
end
|
||||||
def test_false
|
def test_false
|
||||||
lst = RubyCompiler.compile( "false")
|
lst = compile( "false")
|
||||||
assert_equal FalseConstant , lst.class
|
assert_equal FalseConstant , lst.class
|
||||||
end
|
end
|
||||||
def test_true
|
def test_true
|
||||||
lst = RubyCompiler.compile( "true")
|
lst = compile( "true")
|
||||||
assert_equal TrueConstant , lst.class
|
assert_equal TrueConstant , lst.class
|
||||||
end
|
end
|
||||||
def test_integer
|
def test_integer
|
||||||
lst = RubyCompiler.compile( "123")
|
lst = compile( "123")
|
||||||
assert_equal IntegerConstant , lst.class
|
assert_equal IntegerConstant , lst.class
|
||||||
end
|
end
|
||||||
def test_string
|
def test_string
|
||||||
lst = RubyCompiler.compile( "'string'")
|
lst = compile( "'string'")
|
||||||
assert_equal StringConstant , lst.class , lst.inspect
|
assert_equal StringConstant , lst.class , lst.inspect
|
||||||
end
|
end
|
||||||
def test_sym
|
def test_sym
|
||||||
lst = RubyCompiler.compile( ":symbol")
|
lst = compile( ":symbol")
|
||||||
assert_equal SymbolConstant , lst.class , lst.inspect
|
assert_equal SymbolConstant , lst.class , lst.inspect
|
||||||
end
|
end
|
||||||
def test_dstr
|
def test_dstr
|
||||||
assert_raises RuntimeError do
|
assert_raises RuntimeError do
|
||||||
RubyCompiler.compile( '"dstr#{self}"')
|
compile( '"dstr#{self}"')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scope
|
def test_scope
|
||||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
lst = compile( "begin ; 1 ; end")
|
||||||
assert_equal ScopeStatement , lst.class , lst.inspect
|
assert_equal ScopeStatement , lst.class , lst.inspect
|
||||||
end
|
end
|
||||||
def test_scope_contents
|
def test_scope_contents
|
||||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
lst = compile( "begin ; 1 ; end")
|
||||||
assert_equal 1 , lst.statements.first.value
|
assert_equal 1 , lst.statements.first.value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBasicTypes < MiniTest::Test
|
class TestBasicTypes < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
end
|
end
|
||||||
def compile( input )
|
def compile_ct( input )
|
||||||
lst = RubyCompiler.compile( input )
|
lst = compile( input )
|
||||||
lst.ct_type
|
lst.ct_type
|
||||||
end
|
end
|
||||||
def test_integer
|
def test_integer
|
||||||
assert_equal "Integer_Type" , compile( "123").name
|
assert_equal "Integer_Type" , compile_ct( "123").name
|
||||||
end
|
end
|
||||||
def test_string
|
def test_string
|
||||||
assert_equal "Word_Type" , compile( "'string'").name
|
assert_equal "Word_Type" , compile_ct( "'string'").name
|
||||||
end
|
end
|
||||||
def test_sym
|
def test_sym
|
||||||
assert_equal "Word_Type" , compile( ":symbol").name
|
assert_equal "Word_Type" , compile_ct( ":symbol").name
|
||||||
end
|
end
|
||||||
# classes fot these are not implemented in parfait yet
|
# classes fot these are not implemented in parfait yet
|
||||||
def pest_nil
|
def pest_nil
|
||||||
assert_equal "Nil_Type" , compile( "nil").name
|
assert_equal "Nil_Type" , compile_ct( "nil").name
|
||||||
end
|
end
|
||||||
def pest_false
|
def pest_false
|
||||||
assert_equal "False_Type" , compile( "false").name
|
assert_equal "False_Type" , compile_ct( "false").name
|
||||||
end
|
end
|
||||||
def pest_true
|
def pest_true
|
||||||
assert_equal "True_Type" , compile( "true").name
|
assert_equal "True_Type" , compile_ct( "true").name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,10 +2,11 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestBlockStatement < MiniTest::Test
|
class TestBlockStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def setup()
|
def setup()
|
||||||
input = "plus_one{|arg1| arg1 + 1 } "
|
input = "plus_one{|arg1| arg1 + 1 } "
|
||||||
@lst = RubyCompiler.compile( input )
|
@lst = compile( input )
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal SendStatement , @lst.class
|
assert_equal SendStatement , @lst.class
|
@ -2,10 +2,11 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestEmptyClassStatement < MiniTest::Test
|
class TestEmptyClassStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
input = "class Tryout < Base;end"
|
input = "class Tryout < Base;end"
|
||||||
@lst = RubyCompiler.compile( input )
|
@lst = compile( input )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compile_class
|
def test_compile_class
|
||||||
@ -27,13 +28,14 @@ module Vool
|
|||||||
end
|
end
|
||||||
class TestBasicClassStatement < MiniTest::Test
|
class TestBasicClassStatement < MiniTest::Test
|
||||||
include CompilerHelper
|
include CompilerHelper
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_compile_one_method
|
def test_compile_one_method
|
||||||
lst = RubyCompiler.compile( in_Test("@ivar = 4") )
|
lst = compile( in_Test("@ivar = 4") )
|
||||||
assert_equal IvarAssignment , lst.body.class
|
assert_equal IvarAssignment , lst.body.class
|
||||||
end
|
end
|
||||||
def test_compile_two_methods
|
def test_compile_two_methods
|
||||||
lst = RubyCompiler.compile( in_Test("false; true;") )
|
lst = compile( in_Test("false; true;") )
|
||||||
assert_equal ScopeStatement , lst.body.class
|
assert_equal ScopeStatement , lst.body.class
|
||||||
assert_equal TrueConstant , lst.body.statements[1].class
|
assert_equal TrueConstant , lst.body.statements[1].class
|
||||||
end
|
end
|
@ -2,33 +2,34 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class HashArray < MiniTest::Test
|
class HashArray < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_empty
|
def test_empty
|
||||||
lst = RubyCompiler.compile( "{}")
|
lst = compile( "{}")
|
||||||
assert_equal HashStatement , lst.class
|
assert_equal HashStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_empty_length
|
def test_empty_length
|
||||||
lst = RubyCompiler.compile( "{}")
|
lst = compile( "{}")
|
||||||
assert_equal 0 , lst.length
|
assert_equal 0 , lst.length
|
||||||
end
|
end
|
||||||
def test_one
|
def test_one
|
||||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
lst = compile( "{ 1 => 2}")
|
||||||
assert_equal HashStatement , lst.class
|
assert_equal HashStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_one_length
|
def test_one_length
|
||||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
lst = compile( "{ 1 => 2}")
|
||||||
assert_equal 1 , lst.length
|
assert_equal 1 , lst.length
|
||||||
end
|
end
|
||||||
def test_one_pair
|
def test_one_pair
|
||||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
lst = compile( "{ 1 => 2}")
|
||||||
assert_equal 1 , lst.hash.keys.first.value
|
assert_equal 1 , lst.hash.keys.first.value
|
||||||
end
|
end
|
||||||
def test_two_length
|
def test_two_length
|
||||||
lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}")
|
lst = compile( "{ sym: :works , 'string_too' => 2}")
|
||||||
assert_equal 2 , lst.length
|
assert_equal 2 , lst.length
|
||||||
end
|
end
|
||||||
def test_two_key_one
|
def test_two_key_one
|
||||||
lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}")
|
lst = compile( "{ sym: :works , 'string_too' => 2}")
|
||||||
assert_equal :sym , lst.hash.keys.first.value
|
assert_equal :sym , lst.hash.keys.first.value
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,20 +2,21 @@ require_relative 'helper'
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestIfStatement < MiniTest::Test
|
class TestIfStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def basic_if
|
def basic_if
|
||||||
"if(10 < 12) ; true ; end"
|
"if(10 < 12) ; true ; end"
|
||||||
end
|
end
|
||||||
def test_if_basic
|
def test_if_basic
|
||||||
lst = RubyCompiler.compile( basic_if )
|
lst = compile( basic_if )
|
||||||
assert_equal IfStatement , lst.class
|
assert_equal IfStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_if_basic_cond
|
def test_if_basic_cond
|
||||||
lst = RubyCompiler.compile( basic_if )
|
lst = compile( basic_if )
|
||||||
assert_equal ScopeStatement , lst.condition.class
|
assert_equal ScopeStatement , lst.condition.class
|
||||||
end
|
end
|
||||||
def test_if_basic_branches
|
def test_if_basic_branches
|
||||||
lst = RubyCompiler.compile( basic_if )
|
lst = compile( basic_if )
|
||||||
assert_equal TrueConstant , lst.if_true.class
|
assert_equal TrueConstant , lst.if_true.class
|
||||||
assert_nil lst.if_false
|
assert_nil lst.if_false
|
||||||
end
|
end
|
||||||
@ -24,15 +25,15 @@ module Vool
|
|||||||
"if(false) ; true ; else ; false; end"
|
"if(false) ; true ; else ; false; end"
|
||||||
end
|
end
|
||||||
def test_if_double
|
def test_if_double
|
||||||
lst = RubyCompiler.compile( double_if )
|
lst = compile( double_if )
|
||||||
assert_equal IfStatement , lst.class
|
assert_equal IfStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_if_double_cond
|
def test_if_double_cond
|
||||||
lst = RubyCompiler.compile( double_if )
|
lst = compile( double_if )
|
||||||
assert_equal ScopeStatement , lst.condition.class
|
assert_equal ScopeStatement , lst.condition.class
|
||||||
end
|
end
|
||||||
def test_if_double_branches
|
def test_if_double_branches
|
||||||
lst = RubyCompiler.compile( double_if )
|
lst = compile( double_if )
|
||||||
assert_equal TrueConstant , lst.if_true.class
|
assert_equal TrueConstant , lst.if_true.class
|
||||||
assert_equal FalseConstant, lst.if_false.class
|
assert_equal FalseConstant, lst.if_false.class
|
||||||
end
|
end
|
||||||
@ -41,15 +42,15 @@ module Vool
|
|||||||
"true if(false)"
|
"true if(false)"
|
||||||
end
|
end
|
||||||
def test_if_reverse
|
def test_if_reverse
|
||||||
lst = RubyCompiler.compile( reverse_if )
|
lst = compile( reverse_if )
|
||||||
assert_equal IfStatement , lst.class
|
assert_equal IfStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_if_reverse_cond
|
def test_if_reverse_cond
|
||||||
lst = RubyCompiler.compile( reverse_if )
|
lst = compile( reverse_if )
|
||||||
assert_equal FalseConstant , lst.condition.class
|
assert_equal FalseConstant , lst.condition.class
|
||||||
end
|
end
|
||||||
def test_if_reverse_branches
|
def test_if_reverse_branches
|
||||||
lst = RubyCompiler.compile( reverse_if )
|
lst = compile( reverse_if )
|
||||||
assert_equal TrueConstant , lst.if_true.class
|
assert_equal TrueConstant , lst.if_true.class
|
||||||
assert_nil lst.if_false
|
assert_nil lst.if_false
|
||||||
end
|
end
|
||||||
@ -58,15 +59,15 @@ module Vool
|
|||||||
"true unless(false)"
|
"true unless(false)"
|
||||||
end
|
end
|
||||||
def test_if_reverse
|
def test_if_reverse
|
||||||
lst = RubyCompiler.compile( reverse_unless )
|
lst = compile( reverse_unless )
|
||||||
assert_equal IfStatement , lst.class
|
assert_equal IfStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_if_reverse_cond
|
def test_if_reverse_cond
|
||||||
lst = RubyCompiler.compile( reverse_unless )
|
lst = compile( reverse_unless )
|
||||||
assert_equal ScopeStatement , lst.condition.class
|
assert_equal ScopeStatement , lst.condition.class
|
||||||
end
|
end
|
||||||
def test_if_reverse_branches
|
def test_if_reverse_branches
|
||||||
lst = RubyCompiler.compile( reverse_unless )
|
lst = compile( reverse_unless )
|
||||||
assert_nil lst.if_true
|
assert_nil lst.if_true
|
||||||
assert_equal TrueConstant ,lst.if_false.class
|
assert_equal TrueConstant ,lst.if_false.class
|
||||||
end
|
end
|
||||||
@ -75,15 +76,15 @@ module Vool
|
|||||||
"false ? true : false"
|
"false ? true : false"
|
||||||
end
|
end
|
||||||
def test_if_ternary
|
def test_if_ternary
|
||||||
lst = RubyCompiler.compile( ternary )
|
lst = compile( ternary )
|
||||||
assert_equal IfStatement , lst.class
|
assert_equal IfStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_if_ternary_cond
|
def test_if_ternary_cond
|
||||||
lst = RubyCompiler.compile( ternary )
|
lst = compile( ternary )
|
||||||
assert_equal FalseConstant , lst.condition.class
|
assert_equal FalseConstant , lst.condition.class
|
||||||
end
|
end
|
||||||
def test_if_ternary_branches
|
def test_if_ternary_branches
|
||||||
lst = RubyCompiler.compile( ternary )
|
lst = compile( ternary )
|
||||||
assert_equal TrueConstant , lst.if_true.class
|
assert_equal TrueConstant , lst.if_true.class
|
||||||
assert_equal FalseConstant, lst.if_false.class
|
assert_equal FalseConstant, lst.if_false.class
|
||||||
end
|
end
|
@ -2,27 +2,28 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestIvarAssignment < MiniTest::Test
|
class TestIvarAssignment < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_local
|
def test_local
|
||||||
lst = RubyCompiler.compile( "foo = bar")
|
lst = compile( "foo = bar")
|
||||||
assert_equal LocalAssignment , lst.class
|
assert_equal LocalAssignment , lst.class
|
||||||
end
|
end
|
||||||
def test_local_name
|
def test_local_name
|
||||||
lst = RubyCompiler.compile( "foo = bar")
|
lst = compile( "foo = bar")
|
||||||
assert_equal :foo , lst.name
|
assert_equal :foo , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance
|
def test_instance
|
||||||
lst = RubyCompiler.compile( "@foo = bar")
|
lst = compile( "@foo = bar")
|
||||||
assert_equal IvarAssignment , lst.class
|
assert_equal IvarAssignment , lst.class
|
||||||
end
|
end
|
||||||
def test_instance_name
|
def test_instance_name
|
||||||
lst = RubyCompiler.compile( "@foo = bar")
|
lst = compile( "@foo = bar")
|
||||||
assert_equal :foo , lst.name
|
assert_equal :foo , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_const
|
def test_const
|
||||||
lst = RubyCompiler.compile( "@foo = 5")
|
lst = compile( "@foo = 5")
|
||||||
assert_equal IvarAssignment , lst.class
|
assert_equal IvarAssignment , lst.class
|
||||||
end
|
end
|
||||||
|
|
@ -2,21 +2,22 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestLocalAssignment < MiniTest::Test
|
class TestLocalAssignment < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_local
|
def test_local
|
||||||
lst = RubyCompiler.compile( "foo = bar")
|
lst = compile( "foo = bar")
|
||||||
assert_equal LocalAssignment , lst.class
|
assert_equal LocalAssignment , lst.class
|
||||||
end
|
end
|
||||||
def test_local_name
|
def test_local_name
|
||||||
lst = RubyCompiler.compile( "foo = bar")
|
lst = compile( "foo = bar")
|
||||||
assert_equal :foo , lst.name
|
assert_equal :foo , lst.name
|
||||||
end
|
end
|
||||||
def test_local_const
|
def test_local_const
|
||||||
lst = RubyCompiler.compile( "foo = 5")
|
lst = compile( "foo = 5")
|
||||||
assert_equal LocalAssignment , lst.class
|
assert_equal LocalAssignment , lst.class
|
||||||
end
|
end
|
||||||
def test_local_ivar
|
def test_local_ivar
|
||||||
lst = RubyCompiler.compile( "foo = @iv")
|
lst = compile( "foo = @iv")
|
||||||
assert_equal LocalAssignment , lst.class
|
assert_equal LocalAssignment , lst.class
|
||||||
assert_equal InstanceVariable , lst.value.class
|
assert_equal InstanceVariable , lst.value.class
|
||||||
end
|
end
|
@ -1,10 +1,11 @@
|
|||||||
require_relative "../helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestLogical < MiniTest::Test
|
class TestLogical < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def simple
|
def simple
|
||||||
RubyCompiler.compile( "@a and @b")
|
compile( "@a and @b")
|
||||||
end
|
end
|
||||||
def test_simple
|
def test_simple
|
||||||
lst = simple
|
lst = simple
|
||||||
@ -24,16 +25,16 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_or
|
def test_or
|
||||||
lst = RubyCompiler.compile( "@a or @b")
|
lst = compile( "@a or @b")
|
||||||
assert_equal :or , lst.name
|
assert_equal :or , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_or2
|
def test_or2
|
||||||
lst = RubyCompiler.compile( "@a || @b")
|
lst = compile( "@a || @b")
|
||||||
assert_equal :or , lst.name
|
assert_equal :or , lst.name
|
||||||
end
|
end
|
||||||
def test_and2
|
def test_and2
|
||||||
lst = RubyCompiler.compile( "@a && @b")
|
lst = compile( "@a && @b")
|
||||||
assert_equal :and , lst.name
|
assert_equal :and , lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,10 +2,11 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestMethodStatement < MiniTest::Test
|
class TestMethodStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def basic_setup()
|
def basic_setup()
|
||||||
input = "def tryout(arg1, arg2) ; true ; false ; end "
|
input = "def tryout(arg1, arg2) ; true ; false ; end "
|
||||||
@lst = RubyCompiler.compile( input )
|
@lst = compile( input )
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
basic_setup
|
basic_setup
|
||||||
@ -28,12 +29,12 @@ module Vool
|
|||||||
end
|
end
|
||||||
def test_body_is_scope_one_statement
|
def test_body_is_scope_one_statement
|
||||||
input = "def tryout(arg1, arg2) ; a = true ; end "
|
input = "def tryout(arg1, arg2) ; a = true ; end "
|
||||||
lst = RubyCompiler.compile( input )
|
lst = compile( input )
|
||||||
assert_equal LocalAssignment , lst.body.class
|
assert_equal LocalAssignment , lst.body.class
|
||||||
end
|
end
|
||||||
def test_body_is_scope_zero_statement
|
def test_body_is_scope_zero_statement
|
||||||
input = "def tryout(arg1, arg2) ; arg1 = arg2 ; end "
|
input = "def tryout(arg1, arg2) ; arg1 = arg2 ; end "
|
||||||
lst = RubyCompiler.compile( input )
|
lst = compile( input )
|
||||||
assert_equal LocalAssignment , lst.body.class
|
assert_equal LocalAssignment , lst.body.class
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -20,8 +20,9 @@ module Vool
|
|||||||
end
|
end
|
||||||
class TestLocalOpAssign < MiniTest::Test
|
class TestLocalOpAssign < MiniTest::Test
|
||||||
include OpAss
|
include OpAss
|
||||||
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = RubyCompiler.compile( "foo += 5")
|
@lst = compile( "foo += 5")
|
||||||
end
|
end
|
||||||
def test_local_ass
|
def test_local_ass
|
||||||
assert_equal LocalAssignment , @lst.class
|
assert_equal LocalAssignment , @lst.class
|
||||||
@ -29,8 +30,9 @@ module Vool
|
|||||||
end
|
end
|
||||||
class TestIvarOpAssign < MiniTest::Test
|
class TestIvarOpAssign < MiniTest::Test
|
||||||
include OpAss
|
include OpAss
|
||||||
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = RubyCompiler.compile( "@foo += 5")
|
@lst = compile( "@foo += 5")
|
||||||
end
|
end
|
||||||
def test_ivar_ass
|
def test_ivar_ass
|
||||||
assert_equal IvarAssignment , @lst.class
|
assert_equal IvarAssignment , @lst.class
|
@ -2,19 +2,20 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestReturnStatement < MiniTest::Test
|
class TestReturnStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_return_const
|
def test_return_const
|
||||||
lst = RubyCompiler.compile( "return 1" )
|
lst = compile( "return 1" )
|
||||||
assert_equal ReturnStatement , lst.class
|
assert_equal ReturnStatement , lst.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_value
|
def test_return_value
|
||||||
lst = RubyCompiler.compile( "return 1" )
|
lst = compile( "return 1" )
|
||||||
assert_equal 1 , lst.return_value.value
|
assert_equal 1 , lst.return_value.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_send
|
def test_return_send
|
||||||
lst = RubyCompiler.compile( "return foo" )
|
lst = compile( "return foo" )
|
||||||
assert_equal SendStatement , lst.return_value.class
|
assert_equal SendStatement , lst.return_value.class
|
||||||
assert_equal :foo , lst.return_value.name
|
assert_equal :foo , lst.return_value.name
|
||||||
end
|
end
|
@ -1,61 +1,62 @@
|
|||||||
require_relative "../helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestSend < MiniTest::Test
|
class TestSend < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def test_simple
|
def test_simple
|
||||||
lst = RubyCompiler.compile( "foo")
|
lst = compile( "foo")
|
||||||
assert_equal SendStatement , lst.class
|
assert_equal SendStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_simple_name
|
def test_simple_name
|
||||||
lst = RubyCompiler.compile( "foo")
|
lst = compile( "foo")
|
||||||
assert_equal :foo , lst.name
|
assert_equal :foo , lst.name
|
||||||
end
|
end
|
||||||
def test_simple_receiver
|
def test_simple_receiver
|
||||||
lst = RubyCompiler.compile( "foo")
|
lst = compile( "foo")
|
||||||
assert_equal SelfExpression , lst.receiver.class
|
assert_equal SelfExpression , lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_simple_args
|
def test_simple_args
|
||||||
lst = RubyCompiler.compile( "foo")
|
lst = compile( "foo")
|
||||||
assert_equal [] , lst.arguments
|
assert_equal [] , lst.arguments
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_one_arg
|
def test_one_arg
|
||||||
lst = RubyCompiler.compile( "bar(1)")
|
lst = compile( "bar(1)")
|
||||||
assert_equal SendStatement , lst.class
|
assert_equal SendStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_one_arg_name
|
def test_one_arg_name
|
||||||
lst = RubyCompiler.compile( "bar(1)")
|
lst = compile( "bar(1)")
|
||||||
assert_equal :bar , lst.name
|
assert_equal :bar , lst.name
|
||||||
end
|
end
|
||||||
def test_one_arg_receiver
|
def test_one_arg_receiver
|
||||||
lst = RubyCompiler.compile( "bar(1)")
|
lst = compile( "bar(1)")
|
||||||
assert_equal SelfExpression , lst.receiver.class
|
assert_equal SelfExpression , lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_one_arg_args
|
def test_one_arg_args
|
||||||
lst = RubyCompiler.compile( "bar(1)")
|
lst = compile( "bar(1)")
|
||||||
assert_equal 1 , lst.arguments.first.value
|
assert_equal 1 , lst.arguments.first.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_super0_receiver
|
def test_super0_receiver
|
||||||
lst = RubyCompiler.compile( "super")
|
lst = compile( "super")
|
||||||
assert_equal SuperExpression , lst.receiver.class
|
assert_equal SuperExpression , lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_super0
|
def test_super0
|
||||||
lst = RubyCompiler.compile( "super")
|
lst = compile( "super")
|
||||||
assert_equal SendStatement , lst.class
|
assert_equal SendStatement , lst.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_super_receiver
|
def test_super_receiver
|
||||||
lst = RubyCompiler.compile( "super(1)")
|
lst = compile( "super(1)")
|
||||||
assert_equal SuperExpression , lst.receiver.class
|
assert_equal SuperExpression , lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_super_args
|
def test_super_args
|
||||||
lst = RubyCompiler.compile( "super(1)")
|
lst = compile( "super(1)")
|
||||||
assert_equal 1 , lst.arguments.first.value
|
assert_equal 1 , lst.arguments.first.value
|
||||||
end
|
end
|
||||||
def test_super_name #is nil
|
def test_super_name #is nil
|
||||||
lst = RubyCompiler.compile( "super(1)")
|
lst = compile( "super(1)")
|
||||||
assert_nil lst.name
|
assert_nil lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -66,12 +67,12 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_int_receiver
|
def test_int_receiver
|
||||||
sent = RubyCompiler.compile( "5.div4")
|
sent = compile( "5.div4")
|
||||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||||
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
||||||
end
|
end
|
||||||
def test_string_receiver
|
def test_string_receiver
|
||||||
sent = RubyCompiler.compile( "'5'.putstring")
|
sent = compile( "'5'.putstring")
|
||||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||||
assert_equal "Word_Type" , sent.receiver.ct_type.name
|
assert_equal "Word_Type" , sent.receiver.ct_type.name
|
||||||
end
|
end
|
@ -2,56 +2,57 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestVariables < MiniTest::Test
|
class TestVariables < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
# "free standing" local can not be tested as it will result in send
|
# "free standing" local can not be tested as it will result in send
|
||||||
# in other words ther is no way of knowing if a name is variable or method
|
# in other words ther is no way of knowing if a name is variable or method
|
||||||
# one needs an assignemnt first, to "tell" the parser it's a local
|
# one needs an assignemnt first, to "tell" the parser it's a local
|
||||||
def test_local_basic
|
def test_local_basic
|
||||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
lst = compile( "foo = 1 ; foo")
|
||||||
assert_equal ScopeStatement , lst.class
|
assert_equal ScopeStatement , lst.class
|
||||||
assert_equal LocalVariable , lst.statements[1].class
|
assert_equal LocalVariable , lst.statements[1].class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_local_nane
|
def test_local_nane
|
||||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
lst = compile( "foo = 1 ; foo")
|
||||||
assert_equal LocalVariable , lst.statements[1].class
|
assert_equal LocalVariable , lst.statements[1].class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_basic
|
def test_instance_basic
|
||||||
lst = RubyCompiler.compile( "@var" )
|
lst = compile( "@var" )
|
||||||
assert_equal InstanceVariable , lst.class
|
assert_equal InstanceVariable , lst.class
|
||||||
assert_equal :var , lst.name
|
assert_equal :var , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_return
|
def test_instance_return
|
||||||
lst = RubyCompiler.compile( "return @var" )
|
lst = compile( "return @var" )
|
||||||
assert_equal InstanceVariable , lst.return_value.class
|
assert_equal InstanceVariable , lst.return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_basic
|
def test_class_basic
|
||||||
lst = RubyCompiler.compile( "@@var" )
|
lst = compile( "@@var" )
|
||||||
assert_equal ClassVariable , lst.class
|
assert_equal ClassVariable , lst.class
|
||||||
assert_equal :var , lst.name
|
assert_equal :var , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_return
|
def test_class_return
|
||||||
lst = RubyCompiler.compile( "return @@var" )
|
lst = compile( "return @@var" )
|
||||||
assert_equal ClassVariable , lst.return_value.class
|
assert_equal ClassVariable , lst.return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_module_basic
|
def test_module_basic
|
||||||
lst = RubyCompiler.compile( "Module" )
|
lst = compile( "Module" )
|
||||||
assert_equal ModuleName , lst.class
|
assert_equal ModuleName , lst.class
|
||||||
assert_equal :Module , lst.name
|
assert_equal :Module , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_module_base_scoped
|
def test_module_base_scoped
|
||||||
lst = RubyCompiler.compile( "::Module" )
|
lst = compile( "::Module" )
|
||||||
assert_equal ModuleName , lst.class
|
assert_equal ModuleName , lst.class
|
||||||
assert_equal :Module , lst.name
|
assert_equal :Module , lst.name
|
||||||
end
|
end
|
||||||
def test_module_module_scoped
|
def test_module_module_scoped
|
||||||
assert_raises {RubyCompiler.compile( "M::Module" ) }
|
assert_raises {compile( "M::Module" ) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,6 +1,6 @@
|
|||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
module Vool
|
module RubyX
|
||||||
class TestWhileStatement < MiniTest::Test
|
class TestWhileStatement < MiniTest::Test
|
||||||
|
|
||||||
def basic_while
|
def basic_while
|
@ -2,10 +2,11 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestYieldStatement < MiniTest::Test
|
class TestYieldStatement < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
|
||||||
def setup()
|
def setup()
|
||||||
input = "def plus_one; yield(0) ; end "
|
input = "def plus_one; yield(0) ; end "
|
||||||
@lst = RubyCompiler.compile( input )
|
@lst = compile( input )
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal MethodStatement , @lst.class
|
assert_equal MethodStatement , @lst.class
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Vool
|
module RubyX
|
||||||
class TestClassCompiler < MiniTest::Test
|
class TestClassCompiler < MiniTest::Test
|
||||||
include CompilerHelper
|
include CompilerHelper
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compile_in_test input
|
def compile_in_test input
|
||||||
vool = VoolCompiler.ruby_to_vool in_Test(input)
|
vool = RubyXCompiler.ruby_to_vool in_Test(input)
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
itest = Parfait.object_space.get_class_by_name(:Test)
|
itest = Parfait.object_space.get_class_by_name(:Test)
|
||||||
assert itest
|
assert itest
|
||||||
@ -28,26 +28,33 @@ module Vool
|
|||||||
|
|
||||||
def test_doesnt_create_existing_clas
|
def test_doesnt_create_existing_clas
|
||||||
space_class = Parfait.object_space.get_class_by_name(:Space)
|
space_class = Parfait.object_space.get_class_by_name(:Space)
|
||||||
VoolCompiler.ruby_to_vool "class Space ; end"
|
RubyXCompiler.ruby_to_vool "class Space ; end"
|
||||||
clazz = Parfait.object_space.get_class_by_name(:Space)
|
clazz = Parfait.object_space.get_class_by_name(:Space)
|
||||||
assert_equal clazz , space_class
|
assert_equal clazz , space_class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_body_is_scope
|
def test_class_body_is_scope
|
||||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal MethodStatement , clazz.body.class
|
assert_equal MethodStatement , clazz.body.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_class_without_deriviation
|
def test_creates_class_without_deriviation
|
||||||
vool = VoolCompiler.ruby_to_vool "class Testing ; end"
|
vool = RubyXCompiler.ruby_to_vool "class Testing ; end"
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
||||||
assert clazz , "No classes created"
|
assert clazz , "No classes created"
|
||||||
assert_equal :Object , clazz.super_class_name
|
assert_equal :Object , clazz.super_class_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_creates_class_deriviation
|
||||||
|
vool = RubyXCompiler.ruby_to_vool "class Testing ; end"
|
||||||
|
mom = vool.to_mom(nil)
|
||||||
|
assert_equal ClassStatement , vool.class
|
||||||
|
assert mom , "No classes created"
|
||||||
|
end
|
||||||
|
|
||||||
def test_creates_class_with_deriviation
|
def test_creates_class_with_deriviation
|
||||||
vool = VoolCompiler.ruby_to_vool "class Test2 < List ;end"
|
vool = RubyXCompiler.ruby_to_vool "class Test2 < List ;end"
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
||||||
assert clazz, "No classes created"
|
assert clazz, "No classes created"
|
||||||
@ -56,14 +63,14 @@ module Vool
|
|||||||
|
|
||||||
def test_space_is_unchanged_by_compile
|
def test_space_is_unchanged_by_compile
|
||||||
space1 = Parfait.object_space.get_class_by_name(:Space)
|
space1 = Parfait.object_space.get_class_by_name(:Space)
|
||||||
VoolCompiler.ruby_to_vool "class Space ;end"
|
RubyXCompiler.ruby_to_vool "class Space ;end"
|
||||||
space2 = Parfait.object_space.get_class_by_name(:Space)
|
space2 = Parfait.object_space.get_class_by_name(:Space)
|
||||||
assert_equal space1 , space2
|
assert_equal space1 , space2
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_space_type_is_unchanged_by_compile
|
def test_space_type_is_unchanged_by_compile
|
||||||
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||||
VoolCompiler.ruby_to_vool "class Space ;end"
|
RubyXCompiler.ruby_to_vool "class Space ;end"
|
||||||
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||||
assert_equal space1 , space2
|
assert_equal space1 , space2
|
||||||
end
|
end
|
@ -8,7 +8,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
Vool::VoolCompiler.ruby_to_binary( @string_input , :interpreter)
|
Vool::RubyXCompiler.ruby_to_binary( @string_input , :interpreter)
|
||||||
@interpreter = Interpreter.new
|
@interpreter = Interpreter.new
|
||||||
@interpreter.start_machine
|
@interpreter.start_machine
|
||||||
end
|
end
|
||||||
|
@ -1 +0,0 @@
|
|||||||
require_relative "../helper"
|
|
Loading…
x
Reference in New Issue
Block a user