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"] }
|
||||
|
||||
# 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
|
||||
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"] }
|
||||
watch(%r{^lib/vool/statements/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 "arm/arm_machine"
|
||||
require_relative "arm/arm_platform"
|
||||
require_relative "vool/vool_compiler"
|
||||
require_relative "vool/statement"
|
||||
require_relative "rubyx/rubyx_compiler"
|
||||
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
|
||||
# with the help of the parser gem. The parser outputs an abstract ast (nodes)
|
||||
# that get transformed into concrete, specific classes.
|
||||
@ -24,13 +23,13 @@ module Vool
|
||||
|
||||
def on_class( 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
|
||||
|
||||
def on_def( statement )
|
||||
name , args , body = *statement
|
||||
arg_array = process_all( args )
|
||||
MethodStatement.new( name , arg_array , process(body) )
|
||||
Vool::MethodStatement.new( name , arg_array , process(body) )
|
||||
end
|
||||
|
||||
def on_arg( arg )
|
||||
@ -41,13 +40,13 @@ module Vool
|
||||
sendd = process(block_node.children[0])
|
||||
args = process(block_node.children[1])
|
||||
body = process(block_node.children[2])
|
||||
sendd.add_block BlockStatement.new(args , body)
|
||||
sendd.add_block Vool::BlockStatement.new(args , body)
|
||||
sendd
|
||||
end
|
||||
|
||||
def on_yield(node)
|
||||
args = process_all(node.children)
|
||||
YieldStatement.new(args)
|
||||
Vool::YieldStatement.new(args)
|
||||
end
|
||||
|
||||
def on_args(args)
|
||||
@ -56,31 +55,31 @@ module Vool
|
||||
|
||||
#basic Values
|
||||
def on_self exp
|
||||
SelfExpression.new
|
||||
Vool::SelfExpression.new
|
||||
end
|
||||
|
||||
def on_nil expression
|
||||
NilConstant.new
|
||||
Vool::NilConstant.new
|
||||
end
|
||||
|
||||
def on_int expression
|
||||
IntegerConstant.new(expression.children.first)
|
||||
Vool::IntegerConstant.new(expression.children.first)
|
||||
end
|
||||
|
||||
def on_float expression
|
||||
FloatConstant.new(expression.children.first)
|
||||
Vool::FloatConstant.new(expression.children.first)
|
||||
end
|
||||
|
||||
def on_true expression
|
||||
TrueConstant.new
|
||||
Vool::TrueConstant.new
|
||||
end
|
||||
|
||||
def on_false expression
|
||||
FalseConstant.new
|
||||
Vool::FalseConstant.new
|
||||
end
|
||||
|
||||
def on_str expression
|
||||
StringConstant.new(expression.children.first)
|
||||
Vool::StringConstant.new(expression.children.first)
|
||||
end
|
||||
alias :on_string :on_str
|
||||
|
||||
@ -90,7 +89,7 @@ module Vool
|
||||
alias :on_xstr :on_dstr
|
||||
|
||||
def on_sym expression
|
||||
SymbolConstant.new(expression.children.first)
|
||||
Vool::SymbolConstant.new(expression.children.first)
|
||||
end
|
||||
alias :on_string :on_str
|
||||
|
||||
@ -98,17 +97,17 @@ module Vool
|
||||
raise "Not implemented dynamix symbols (with interpolation)"
|
||||
end
|
||||
def on_kwbegin statement
|
||||
ScopeStatement.new process_all( statement.children )
|
||||
Vool::ScopeStatement.new process_all( statement.children )
|
||||
end
|
||||
alias :on_begin :on_kwbegin
|
||||
|
||||
# Array + Hashes
|
||||
def on_array expression
|
||||
ArrayStatement.new expression.children.collect{ |elem| process(elem) }
|
||||
Vool::ArrayStatement.new expression.children.collect{ |elem| process(elem) }
|
||||
end
|
||||
|
||||
def on_hash expression
|
||||
hash = HashStatement.new
|
||||
hash = Vool::HashStatement.new
|
||||
expression.children.each do |elem|
|
||||
raise "Hash error, hash contains non pair: #{elem.type}" if elem.type != :pair
|
||||
hash.add( process(elem.children[0]) , process(elem.children[1]) )
|
||||
@ -118,15 +117,15 @@ module Vool
|
||||
|
||||
#Variables
|
||||
def on_lvar expression
|
||||
LocalVariable.new(expression.children.first)
|
||||
Vool::LocalVariable.new(expression.children.first)
|
||||
end
|
||||
|
||||
def on_ivar expression
|
||||
InstanceVariable.new(instance_name(expression.children.first))
|
||||
Vool::InstanceVariable.new(instance_name(expression.children.first))
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def on_const expression
|
||||
@ -134,20 +133,20 @@ module Vool
|
||||
if scope
|
||||
raise "Only unscoped Names implemented #{scope}" unless scope.type == :cbase
|
||||
end
|
||||
ModuleName.new(expression.children[1])
|
||||
Vool::ModuleName.new(expression.children[1])
|
||||
end
|
||||
|
||||
# Assignements
|
||||
def on_lvasgn expression
|
||||
name = expression.children[0]
|
||||
value = process(expression.children[1])
|
||||
LocalAssignment.new(name,value)
|
||||
Vool::LocalAssignment.new(name,value)
|
||||
end
|
||||
|
||||
def on_ivasgn expression
|
||||
name = expression.children[0]
|
||||
value = process(expression.children[1])
|
||||
IvarAssignment.new(instance_name(name),value)
|
||||
Vool::IvarAssignment.new(instance_name(name),value)
|
||||
end
|
||||
|
||||
def on_op_asgn(expression)
|
||||
@ -162,52 +161,52 @@ module Vool
|
||||
|
||||
def on_return statement
|
||||
return_value = process(statement.children.first)
|
||||
ReturnStatement.new( return_value )
|
||||
Vool::ReturnStatement.new( return_value )
|
||||
end
|
||||
|
||||
def on_while statement
|
||||
condition , statements = *statement
|
||||
WhileStatement.new( process(condition) , process(statements))
|
||||
Vool::WhileStatement.new( process(condition) , process(statements))
|
||||
end
|
||||
|
||||
def on_if statement
|
||||
condition , if_true , if_false = *statement
|
||||
if_true = process(if_true)
|
||||
if_false = process(if_false)
|
||||
IfStatement.new( process(condition) , if_true , if_false )
|
||||
Vool::IfStatement.new( process(condition) , if_true , if_false )
|
||||
end
|
||||
|
||||
def on_send statement
|
||||
kids = statement.children.dup
|
||||
receiver = process(kids.shift) || SelfExpression.new
|
||||
receiver = process(kids.shift) || Vool::SelfExpression.new
|
||||
name = kids.shift
|
||||
arguments = process_all(kids)
|
||||
SendStatement.new( name , receiver , arguments )
|
||||
Vool::SendStatement.new( name , receiver , arguments )
|
||||
end
|
||||
|
||||
def on_and expression
|
||||
name = expression.type
|
||||
left = process(expression.children[0])
|
||||
right = process( expression.children[1] )
|
||||
LogicalStatement.new( name , left , right)
|
||||
Vool::LogicalStatement.new( name , left , right)
|
||||
end
|
||||
alias :on_or :on_and
|
||||
|
||||
# this is a call to super without args (z = zero arity)
|
||||
def on_zsuper exp
|
||||
SendStatement.new( nil , SuperExpression.new , nil)
|
||||
Vool::SendStatement.new( nil , Vool::SuperExpression.new , nil)
|
||||
end
|
||||
|
||||
# this is a call to super with args and
|
||||
# same name as current method, which is set later
|
||||
def on_super( statement )
|
||||
arguments = process_all(statement.children)
|
||||
SendStatement.new( nil , SuperExpression.new , arguments)
|
||||
Vool::SendStatement.new( nil , Vool::SuperExpression.new , arguments)
|
||||
end
|
||||
|
||||
def on_assignment statement
|
||||
name , value = *statement
|
||||
w = Assignment.new()
|
||||
w = Vool::Assignment.new()
|
||||
w.name = process name
|
||||
w.value = process(value)
|
||||
w
|
@ -1,7 +1,7 @@
|
||||
require_relative "ruby_compiler"
|
||||
|
||||
module Vool
|
||||
class VoolCompiler
|
||||
module RubyX
|
||||
class RubyXCompiler
|
||||
|
||||
def self.ruby_to_vool( ruby_source )
|
||||
vool = RubyCompiler.compile( ruby_source )
|
||||
@ -12,7 +12,7 @@ module Vool
|
||||
def self.ruby_to_binary(source , platform = :arm)
|
||||
machine = Risc.machine.boot
|
||||
vool = self.ruby_to_vool(source)
|
||||
vool.to_mom(nil)
|
||||
vool.to_mom(nil).class
|
||||
machine.translate(platform)
|
||||
machine.position_all
|
||||
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")
|
||||
end
|
||||
def check(input, file)
|
||||
Vool::VoolCompiler.ruby_to_binary( input )
|
||||
Vool::RubyXCompiler.ruby_to_binary( input )
|
||||
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||
writer.save "test/#{file}.o"
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ module Mains
|
||||
def compile(input , file , scp)
|
||||
Risc.machine.boot
|
||||
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.save "test/#{file}.o"
|
||||
object_file = "/tmp/#{file}.o"
|
||||
|
@ -28,7 +28,7 @@ module Risc
|
||||
end
|
||||
def produce_instructions
|
||||
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.instance_type.get_method(:main).cpu_instructions
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module Vool
|
||||
end
|
||||
|
||||
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)
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
test.get_method(:meth)
|
||||
@ -37,24 +37,24 @@ module Vool
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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)
|
||||
assert vool.body.clazz
|
||||
end
|
||||
|
||||
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)
|
||||
assert_equal Parfait::Class , vool.body.clazz.class
|
||||
end
|
||||
|
||||
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)
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
method = test.instance_type.get_method(:meth)
|
||||
@ -63,7 +63,7 @@ module Vool
|
||||
end
|
||||
|
||||
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)
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
method = test.get_method(:meth)
|
||||
@ -73,7 +73,7 @@ module Vool
|
||||
end
|
||||
|
||||
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)
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
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
|
||||
class TestArray < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_empty
|
||||
lst = RubyCompiler.compile( "[]")
|
||||
lst = compile( "[]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
def test_one
|
||||
lst = RubyCompiler.compile( "[1]")
|
||||
lst = compile( "[1]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
def test_two
|
||||
lst = RubyCompiler.compile( "[1,2]")
|
||||
lst = compile( "[1,2]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
end
|
@ -2,76 +2,79 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestBasicValues < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_self
|
||||
lst = RubyCompiler.compile( "self")
|
||||
lst = compile( "self")
|
||||
assert_equal SelfExpression , lst.class
|
||||
end
|
||||
def test_nil
|
||||
lst = RubyCompiler.compile( "nil")
|
||||
lst = compile( "nil")
|
||||
assert_equal NilConstant , lst.class
|
||||
end
|
||||
def test_false
|
||||
lst = RubyCompiler.compile( "false")
|
||||
lst = compile( "false")
|
||||
assert_equal FalseConstant , lst.class
|
||||
end
|
||||
def test_true
|
||||
lst = RubyCompiler.compile( "true")
|
||||
lst = compile( "true")
|
||||
assert_equal TrueConstant , lst.class
|
||||
end
|
||||
def test_integer
|
||||
lst = RubyCompiler.compile( "123")
|
||||
lst = compile( "123")
|
||||
assert_equal IntegerConstant , lst.class
|
||||
end
|
||||
def test_string
|
||||
lst = RubyCompiler.compile( "'string'")
|
||||
lst = compile( "'string'")
|
||||
assert_equal StringConstant , lst.class , lst.inspect
|
||||
end
|
||||
def test_sym
|
||||
lst = RubyCompiler.compile( ":symbol")
|
||||
lst = compile( ":symbol")
|
||||
assert_equal SymbolConstant , lst.class , lst.inspect
|
||||
end
|
||||
def test_dstr
|
||||
assert_raises RuntimeError do
|
||||
RubyCompiler.compile( '"dstr#{self}"')
|
||||
compile( '"dstr#{self}"')
|
||||
end
|
||||
end
|
||||
|
||||
def test_scope
|
||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
||||
lst = compile( "begin ; 1 ; end")
|
||||
assert_equal ScopeStatement , lst.class , lst.inspect
|
||||
end
|
||||
def test_scope_contents
|
||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
||||
lst = compile( "begin ; 1 ; end")
|
||||
assert_equal 1 , lst.statements.first.value
|
||||
end
|
||||
end
|
||||
class TestBasicTypes < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
end
|
||||
def compile( input )
|
||||
lst = RubyCompiler.compile( input )
|
||||
def compile_ct( input )
|
||||
lst = compile( input )
|
||||
lst.ct_type
|
||||
end
|
||||
def test_integer
|
||||
assert_equal "Integer_Type" , compile( "123").name
|
||||
assert_equal "Integer_Type" , compile_ct( "123").name
|
||||
end
|
||||
def test_string
|
||||
assert_equal "Word_Type" , compile( "'string'").name
|
||||
assert_equal "Word_Type" , compile_ct( "'string'").name
|
||||
end
|
||||
def test_sym
|
||||
assert_equal "Word_Type" , compile( ":symbol").name
|
||||
assert_equal "Word_Type" , compile_ct( ":symbol").name
|
||||
end
|
||||
# classes fot these are not implemented in parfait yet
|
||||
def pest_nil
|
||||
assert_equal "Nil_Type" , compile( "nil").name
|
||||
assert_equal "Nil_Type" , compile_ct( "nil").name
|
||||
end
|
||||
def pest_false
|
||||
assert_equal "False_Type" , compile( "false").name
|
||||
assert_equal "False_Type" , compile_ct( "false").name
|
||||
end
|
||||
def pest_true
|
||||
assert_equal "True_Type" , compile( "true").name
|
||||
assert_equal "True_Type" , compile_ct( "true").name
|
||||
end
|
||||
end
|
||||
end
|
@ -2,10 +2,11 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestBlockStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def setup()
|
||||
input = "plus_one{|arg1| arg1 + 1 } "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
@lst = compile( input )
|
||||
end
|
||||
def test_method
|
||||
assert_equal SendStatement , @lst.class
|
@ -2,10 +2,11 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestEmptyClassStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def setup
|
||||
input = "class Tryout < Base;end"
|
||||
@lst = RubyCompiler.compile( input )
|
||||
@lst = compile( input )
|
||||
end
|
||||
|
||||
def test_compile_class
|
||||
@ -27,13 +28,14 @@ module Vool
|
||||
end
|
||||
class TestBasicClassStatement < MiniTest::Test
|
||||
include CompilerHelper
|
||||
include RubyTests
|
||||
|
||||
def test_compile_one_method
|
||||
lst = RubyCompiler.compile( in_Test("@ivar = 4") )
|
||||
lst = compile( in_Test("@ivar = 4") )
|
||||
assert_equal IvarAssignment , lst.body.class
|
||||
end
|
||||
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 TrueConstant , lst.body.statements[1].class
|
||||
end
|
@ -2,33 +2,34 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class HashArray < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_empty
|
||||
lst = RubyCompiler.compile( "{}")
|
||||
lst = compile( "{}")
|
||||
assert_equal HashStatement , lst.class
|
||||
end
|
||||
def test_empty_length
|
||||
lst = RubyCompiler.compile( "{}")
|
||||
lst = compile( "{}")
|
||||
assert_equal 0 , lst.length
|
||||
end
|
||||
def test_one
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
lst = compile( "{ 1 => 2}")
|
||||
assert_equal HashStatement , lst.class
|
||||
end
|
||||
def test_one_length
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
lst = compile( "{ 1 => 2}")
|
||||
assert_equal 1 , lst.length
|
||||
end
|
||||
def test_one_pair
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
lst = compile( "{ 1 => 2}")
|
||||
assert_equal 1 , lst.hash.keys.first.value
|
||||
end
|
||||
def test_two_length
|
||||
lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}")
|
||||
lst = compile( "{ sym: :works , 'string_too' => 2}")
|
||||
assert_equal 2 , lst.length
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
@ -2,20 +2,21 @@ require_relative 'helper'
|
||||
|
||||
module Vool
|
||||
class TestIfStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def basic_if
|
||||
"if(10 < 12) ; true ; end"
|
||||
end
|
||||
def test_if_basic
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
lst = compile( basic_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_basic_cond
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
lst = compile( basic_if )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_basic_branches
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
lst = compile( basic_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_nil lst.if_false
|
||||
end
|
||||
@ -24,15 +25,15 @@ module Vool
|
||||
"if(false) ; true ; else ; false; end"
|
||||
end
|
||||
def test_if_double
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
lst = compile( double_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_double_cond
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
lst = compile( double_if )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_double_branches
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
lst = compile( double_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_equal FalseConstant, lst.if_false.class
|
||||
end
|
||||
@ -41,15 +42,15 @@ module Vool
|
||||
"true if(false)"
|
||||
end
|
||||
def test_if_reverse
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
lst = compile( reverse_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_reverse_cond
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
lst = compile( reverse_if )
|
||||
assert_equal FalseConstant , lst.condition.class
|
||||
end
|
||||
def test_if_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
lst = compile( reverse_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_nil lst.if_false
|
||||
end
|
||||
@ -58,15 +59,15 @@ module Vool
|
||||
"true unless(false)"
|
||||
end
|
||||
def test_if_reverse
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
lst = compile( reverse_unless )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_reverse_cond
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
lst = compile( reverse_unless )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
lst = compile( reverse_unless )
|
||||
assert_nil lst.if_true
|
||||
assert_equal TrueConstant ,lst.if_false.class
|
||||
end
|
||||
@ -75,15 +76,15 @@ module Vool
|
||||
"false ? true : false"
|
||||
end
|
||||
def test_if_ternary
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
lst = compile( ternary )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_ternary_cond
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
lst = compile( ternary )
|
||||
assert_equal FalseConstant , lst.condition.class
|
||||
end
|
||||
def test_if_ternary_branches
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
lst = compile( ternary )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_equal FalseConstant, lst.if_false.class
|
||||
end
|
@ -2,27 +2,28 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestIvarAssignment < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_local
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_name
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
|
||||
def test_instance
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
||||
lst = compile( "@foo = bar")
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
def test_instance_name
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
||||
lst = compile( "@foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
|
||||
def test_const
|
||||
lst = RubyCompiler.compile( "@foo = 5")
|
||||
lst = compile( "@foo = 5")
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
|
@ -2,21 +2,22 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestLocalAssignment < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_local
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_name
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
def test_local_const
|
||||
lst = RubyCompiler.compile( "foo = 5")
|
||||
lst = compile( "foo = 5")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_ivar
|
||||
lst = RubyCompiler.compile( "foo = @iv")
|
||||
lst = compile( "foo = @iv")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
assert_equal InstanceVariable , lst.value.class
|
||||
end
|
@ -1,10 +1,11 @@
|
||||
require_relative "../helper"
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestLogical < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def simple
|
||||
RubyCompiler.compile( "@a and @b")
|
||||
compile( "@a and @b")
|
||||
end
|
||||
def test_simple
|
||||
lst = simple
|
||||
@ -24,16 +25,16 @@ module Vool
|
||||
end
|
||||
|
||||
def test_or
|
||||
lst = RubyCompiler.compile( "@a or @b")
|
||||
lst = compile( "@a or @b")
|
||||
assert_equal :or , lst.name
|
||||
end
|
||||
|
||||
def test_or2
|
||||
lst = RubyCompiler.compile( "@a || @b")
|
||||
lst = compile( "@a || @b")
|
||||
assert_equal :or , lst.name
|
||||
end
|
||||
def test_and2
|
||||
lst = RubyCompiler.compile( "@a && @b")
|
||||
lst = compile( "@a && @b")
|
||||
assert_equal :and , lst.name
|
||||
end
|
||||
end
|
@ -2,10 +2,11 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestMethodStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def basic_setup()
|
||||
input = "def tryout(arg1, arg2) ; true ; false ; end "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
@lst = compile( input )
|
||||
end
|
||||
def test_method
|
||||
basic_setup
|
||||
@ -28,12 +29,12 @@ module Vool
|
||||
end
|
||||
def test_body_is_scope_one_statement
|
||||
input = "def tryout(arg1, arg2) ; a = true ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
lst = compile( input )
|
||||
assert_equal LocalAssignment , lst.body.class
|
||||
end
|
||||
def test_body_is_scope_zero_statement
|
||||
input = "def tryout(arg1, arg2) ; arg1 = arg2 ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
lst = compile( input )
|
||||
assert_equal LocalAssignment , lst.body.class
|
||||
end
|
||||
end
|
@ -20,8 +20,9 @@ module Vool
|
||||
end
|
||||
class TestLocalOpAssign < MiniTest::Test
|
||||
include OpAss
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = RubyCompiler.compile( "foo += 5")
|
||||
@lst = compile( "foo += 5")
|
||||
end
|
||||
def test_local_ass
|
||||
assert_equal LocalAssignment , @lst.class
|
||||
@ -29,8 +30,9 @@ module Vool
|
||||
end
|
||||
class TestIvarOpAssign < MiniTest::Test
|
||||
include OpAss
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = RubyCompiler.compile( "@foo += 5")
|
||||
@lst = compile( "@foo += 5")
|
||||
end
|
||||
def test_ivar_ass
|
||||
assert_equal IvarAssignment , @lst.class
|
@ -2,19 +2,20 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestReturnStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_return_const
|
||||
lst = RubyCompiler.compile( "return 1" )
|
||||
lst = compile( "return 1" )
|
||||
assert_equal ReturnStatement , lst.class
|
||||
end
|
||||
|
||||
def test_return_value
|
||||
lst = RubyCompiler.compile( "return 1" )
|
||||
lst = compile( "return 1" )
|
||||
assert_equal 1 , lst.return_value.value
|
||||
end
|
||||
|
||||
def test_return_send
|
||||
lst = RubyCompiler.compile( "return foo" )
|
||||
lst = compile( "return foo" )
|
||||
assert_equal SendStatement , lst.return_value.class
|
||||
assert_equal :foo , lst.return_value.name
|
||||
end
|
@ -1,61 +1,62 @@
|
||||
require_relative "../helper"
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestSend < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_simple
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
lst = compile( "foo")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_simple_name
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
lst = compile( "foo")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
def test_simple_receiver
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
lst = compile( "foo")
|
||||
assert_equal SelfExpression , lst.receiver.class
|
||||
end
|
||||
def test_simple_args
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
lst = compile( "foo")
|
||||
assert_equal [] , lst.arguments
|
||||
end
|
||||
|
||||
def test_one_arg
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
lst = compile( "bar(1)")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_one_arg_name
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
lst = compile( "bar(1)")
|
||||
assert_equal :bar , lst.name
|
||||
end
|
||||
def test_one_arg_receiver
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
lst = compile( "bar(1)")
|
||||
assert_equal SelfExpression , lst.receiver.class
|
||||
end
|
||||
def test_one_arg_args
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
lst = compile( "bar(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
|
||||
def test_super0_receiver
|
||||
lst = RubyCompiler.compile( "super")
|
||||
lst = compile( "super")
|
||||
assert_equal SuperExpression , lst.receiver.class
|
||||
end
|
||||
def test_super0
|
||||
lst = RubyCompiler.compile( "super")
|
||||
lst = compile( "super")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
|
||||
def test_super_receiver
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
lst = compile( "super(1)")
|
||||
assert_equal SuperExpression , lst.receiver.class
|
||||
end
|
||||
def test_super_args
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
lst = compile( "super(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
def test_super_name #is nil
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
lst = compile( "super(1)")
|
||||
assert_nil lst.name
|
||||
end
|
||||
end
|
||||
@ -66,12 +67,12 @@ module Vool
|
||||
end
|
||||
|
||||
def test_int_receiver
|
||||
sent = RubyCompiler.compile( "5.div4")
|
||||
sent = compile( "5.div4")
|
||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
||||
end
|
||||
def test_string_receiver
|
||||
sent = RubyCompiler.compile( "'5'.putstring")
|
||||
sent = compile( "'5'.putstring")
|
||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||
assert_equal "Word_Type" , sent.receiver.ct_type.name
|
||||
end
|
@ -2,56 +2,57 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestVariables < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
# "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
|
||||
# one needs an assignemnt first, to "tell" the parser it's a local
|
||||
def test_local_basic
|
||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
||||
lst = compile( "foo = 1 ; foo")
|
||||
assert_equal ScopeStatement , lst.class
|
||||
assert_equal LocalVariable , lst.statements[1].class
|
||||
end
|
||||
|
||||
def test_local_nane
|
||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
||||
lst = compile( "foo = 1 ; foo")
|
||||
assert_equal LocalVariable , lst.statements[1].class
|
||||
end
|
||||
|
||||
def test_instance_basic
|
||||
lst = RubyCompiler.compile( "@var" )
|
||||
lst = compile( "@var" )
|
||||
assert_equal InstanceVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_instance_return
|
||||
lst = RubyCompiler.compile( "return @var" )
|
||||
lst = compile( "return @var" )
|
||||
assert_equal InstanceVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_class_basic
|
||||
lst = RubyCompiler.compile( "@@var" )
|
||||
lst = compile( "@@var" )
|
||||
assert_equal ClassVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_class_return
|
||||
lst = RubyCompiler.compile( "return @@var" )
|
||||
lst = compile( "return @@var" )
|
||||
assert_equal ClassVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_module_basic
|
||||
lst = RubyCompiler.compile( "Module" )
|
||||
lst = compile( "Module" )
|
||||
assert_equal ModuleName , lst.class
|
||||
assert_equal :Module , lst.name
|
||||
end
|
||||
|
||||
def test_module_base_scoped
|
||||
lst = RubyCompiler.compile( "::Module" )
|
||||
lst = compile( "::Module" )
|
||||
assert_equal ModuleName , lst.class
|
||||
assert_equal :Module , lst.name
|
||||
end
|
||||
def test_module_module_scoped
|
||||
assert_raises {RubyCompiler.compile( "M::Module" ) }
|
||||
assert_raises {compile( "M::Module" ) }
|
||||
end
|
||||
end
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Vool
|
||||
module RubyX
|
||||
class TestWhileStatement < MiniTest::Test
|
||||
|
||||
def basic_while
|
@ -2,10 +2,11 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestYieldStatement < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def setup()
|
||||
input = "def plus_one; yield(0) ; end "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
@lst = compile( input )
|
||||
end
|
||||
def test_method
|
||||
assert_equal MethodStatement , @lst.class
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
module RubyX
|
||||
class TestClassCompiler < MiniTest::Test
|
||||
include CompilerHelper
|
||||
|
||||
@ -9,7 +9,7 @@ module Vool
|
||||
end
|
||||
|
||||
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)
|
||||
itest = Parfait.object_space.get_class_by_name(:Test)
|
||||
assert itest
|
||||
@ -28,26 +28,33 @@ module Vool
|
||||
|
||||
def test_doesnt_create_existing_clas
|
||||
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)
|
||||
assert_equal clazz , space_class
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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)
|
||||
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
||||
assert clazz , "No classes created"
|
||||
assert_equal :Object , clazz.super_class_name
|
||||
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
|
||||
vool = VoolCompiler.ruby_to_vool "class Test2 < List ;end"
|
||||
vool = RubyXCompiler.ruby_to_vool "class Test2 < List ;end"
|
||||
vool.to_mom(nil)
|
||||
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
||||
assert clazz, "No classes created"
|
||||
@ -56,14 +63,14 @@ module Vool
|
||||
|
||||
def test_space_is_unchanged_by_compile
|
||||
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)
|
||||
assert_equal space1 , space2
|
||||
end
|
||||
|
||||
def test_space_type_is_unchanged_by_compile
|
||||
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
|
||||
assert_equal space1 , space2
|
||||
end
|
@ -8,7 +8,7 @@ module Risc
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
Vool::VoolCompiler.ruby_to_binary( @string_input , :interpreter)
|
||||
Vool::RubyXCompiler.ruby_to_binary( @string_input , :interpreter)
|
||||
@interpreter = Interpreter.new
|
||||
@interpreter.start_machine
|
||||
end
|
||||
|
@ -1 +0,0 @@
|
||||
require_relative "../helper"
|
Loading…
x
Reference in New Issue
Block a user