Rename Vool to Sol
Simple is really the descriptive name for the layer Sure, it is "virtual" but that is not as important as the fact that it is simple (or simplified) Also objct (based really) is better, since orientated implies it is a little like that, but only orientated, not really it. Sol only has objects, nothing else Just cause i was renaming anyway
This commit is contained in:
parent
aa9fc8bc81
commit
d1f8733623
@ -26,8 +26,8 @@ guard :minitest , all_on_start: false do # with Minitest::Unit
|
|||||||
# ruby compiler tests have a whole directory
|
# ruby compiler tests have a whole directory
|
||||||
watch(%r{^lib/ruby/ruby_compiler.rb}) { Dir["test/ruby/test_*.rb"] }
|
watch(%r{^lib/ruby/ruby_compiler.rb}) { Dir["test/ruby/test_*.rb"] }
|
||||||
|
|
||||||
watch(%r{^lib/vool/statements/send_statement.rb}) {
|
watch(%r{^lib/sol/statements/send_statement.rb}) {
|
||||||
[ Dir["test/vool/send/test_*.rb"] ] }
|
[ Dir["test/sol/send/test_*.rb"] ] }
|
||||||
|
|
||||||
# message setup
|
# message setup
|
||||||
watch(%r{^lib/slot_machine/instruction/message_setup.rb}) { Dir["test/slot_machine/send/test_setup*.rb"] }
|
watch(%r{^lib/slot_machine/instruction/message_setup.rb}) { Dir["test/slot_machine/send/test_setup*.rb"] }
|
||||||
|
17
README.md
17
README.md
@ -12,7 +12,7 @@ X can be read as X times faster, or a decade away, depending on mindset.
|
|||||||
The last rewrite clarified the roles of the different layers
|
The last rewrite clarified the roles of the different layers
|
||||||
of the system, see below. The overhaul is done and rubyx produces working binaries.
|
of the system, see below. The overhaul is done and rubyx produces working binaries.
|
||||||
|
|
||||||
Processing goes through layers: Ruby --> Vool --> SlotMachine --> Risc --> Arm --> binary .
|
Processing goes through layers: Ruby --> Sol --> SlotMachine --> Risc --> Arm --> binary .
|
||||||
|
|
||||||
Currently most basic constructs work to some (usable) degree, ie if, while,
|
Currently most basic constructs work to some (usable) degree, ie if, while,
|
||||||
assignment, ivars, calling and dynamic dispatch all work. Simple blocks, those
|
assignment, ivars, calling and dynamic dispatch all work. Simple blocks, those
|
||||||
@ -27,14 +27,15 @@ anything, even counting to a million.
|
|||||||
|
|
||||||
Ruby is input layer, we use whitequarks parser to parse ruby. The untyped ast is then
|
Ruby is input layer, we use whitequarks parser to parse ruby. The untyped ast is then
|
||||||
transformed into a typed version. The classes and fields follow the ast output pretty
|
transformed into a typed version. The classes and fields follow the ast output pretty
|
||||||
much one to one. The we transform to Vool, removing much of ruby's "fluff".
|
much one to one. The we transform to Sol, removing much of ruby's "fluff".
|
||||||
|
|
||||||
### Vool
|
### Sol
|
||||||
|
|
||||||
Vool is a Virtual Object Oriented Language. Virtual in that is has no own syntax. But
|
Sol is a Simple Object Language. Simple as in much simpler than ruby. Object (more
|
||||||
it has semantics, and those are substantially simpler than ruby.
|
based than oriented) as everything is an object. Everything the language "sees".
|
||||||
|
(Dataprocessing is done at a lower level, partly Slot, partly risc)
|
||||||
|
|
||||||
Vool is Ruby without the fluff. No unless, no reverse if/while, no splats. Just simple
|
Sol is Ruby without the fluff. No unless, no reverse if/while, no splats. Just simple
|
||||||
oo. (Without this level the step down to the next layer was just too big)
|
oo. (Without this level the step down to the next layer was just too big)
|
||||||
|
|
||||||
|
|
||||||
@ -47,13 +48,13 @@ SlotMachine has no concept of memory yet, only objects. Data is transferred dire
|
|||||||
to object with one of SlotMachine's main instructions, the SlotLoad.
|
to object with one of SlotMachine's main instructions, the SlotLoad.
|
||||||
|
|
||||||
Mainly SlotMachine is an easy to understand step on the way down. A mix of oo and machine. In
|
Mainly SlotMachine is an easy to understand step on the way down. A mix of oo and machine. In
|
||||||
practise it means that the amount of instructions that need to be generated in vool
|
practise it means that the amount of instructions that need to be generated in sol
|
||||||
is much smaller (easier to understand) and the mapping down to risc is quite straightforward.
|
is much smaller (easier to understand) and the mapping down to risc is quite straightforward.
|
||||||
|
|
||||||
### Risc
|
### Risc
|
||||||
|
|
||||||
The risc cpu architecture approach was a simplification of the cpu instruction set to a
|
The risc cpu architecture approach was a simplification of the cpu instruction set to a
|
||||||
minimum. Arm, our main target, is a risc architecture, and much like Vool uncrinkles
|
minimum. Arm, our main target, is a risc architecture, and much like Sol uncrinkles
|
||||||
Ruby, the Risc layer simplifies ARM.
|
Ruby, the Risc layer simplifies ARM.
|
||||||
|
|
||||||
The Risc layer here abstracts the Arm in a minimal and independent way. It does not model
|
The Risc layer here abstracts the Arm in a minimal and independent way. It does not model
|
||||||
|
@ -16,7 +16,7 @@ require_relative "parfait/binary_code"
|
|||||||
require_relative "parfait/callable"
|
require_relative "parfait/callable"
|
||||||
require_relative "parfait/block"
|
require_relative "parfait/block"
|
||||||
require_relative "parfait/callable_method"
|
require_relative "parfait/callable_method"
|
||||||
require_relative "parfait/vool_method"
|
require_relative "parfait/sol_method"
|
||||||
require_relative "parfait/dictionary"
|
require_relative "parfait/dictionary"
|
||||||
require_relative "parfait/type"
|
require_relative "parfait/type"
|
||||||
require_relative "parfait/cache_entry"
|
require_relative "parfait/cache_entry"
|
||||||
|
@ -42,7 +42,7 @@ module Parfait
|
|||||||
|
|
||||||
def create_instance_method_for(name , type , frame , body )
|
def create_instance_method_for(name , type , frame , body )
|
||||||
raise "Method exists #{name}" if get_instance_method(name)
|
raise "Method exists #{name}" if get_instance_method(name)
|
||||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
method = Parfait::SolMethod.new(name , type , frame , body )
|
||||||
add_instance_method( method )
|
add_instance_method( method )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ module Parfait
|
|||||||
# A CallableMethod is static object that primarily holds the executable code.
|
# A CallableMethod is static object that primarily holds the executable code.
|
||||||
# It is callable through it's binary code
|
# It is callable through it's binary code
|
||||||
#
|
#
|
||||||
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
|
# It's relation to the method a ruby programmer knows (called SolMethod) is many to one,
|
||||||
# meaning one VoolMethod (untyped) has many CallableMethod implementations.
|
# meaning one SolMethod (untyped) has many CallableMethod implementations.
|
||||||
# The VoolMethod only holds vool code, no binary.
|
# The SolMethod only holds sol code, no binary.
|
||||||
#
|
#
|
||||||
# CallableMethods are bound to a known type (self_type) and have known argument
|
# CallableMethods are bound to a known type (self_type) and have known argument
|
||||||
# and local variables. All variable resolution inside the method is exact (static),
|
# and local variables. All variable resolution inside the method is exact (static),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Class is mainly a list of methods with a name.
|
# Class is mainly a list of methods with a name.
|
||||||
# The methods are untyped, sis VoolMethod.
|
# The methods are untyped, sis SolMethod.
|
||||||
|
|
||||||
# The memory layout of an object is determined by the Type (see there).
|
# The memory layout of an object is determined by the Type (see there).
|
||||||
# The class carries the "current" type, ie the type an object would be if you
|
# The class carries the "current" type, ie the type an object would be if you
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
# An Object carries the data for the instance variables it has.
|
# An Object carries the data for the instance variables it has.
|
||||||
# The Type lists the names of the instance variables
|
# The Type lists the names of the instance variables
|
||||||
# The Class keeps a list of instance methods, these have a name and (vool) code
|
# The Class keeps a list of instance methods, these have a name and (sol) code
|
||||||
# Each type in turn has a list of CallableMethods that hold binary code
|
# Each type in turn has a list of CallableMethods that hold binary code
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
|
|
||||||
# This represents the method at source code level (sis vool)
|
# This represents the method at source code level (sis sol)
|
||||||
#
|
#
|
||||||
# Type objects are already created for args and locals, but the main attribute
|
# Type objects are already created for args and locals, but the main attribute
|
||||||
# is the source, which is a Vool::Statement
|
# is the source, which is a Sol::Statement
|
||||||
#
|
#
|
||||||
# Classes store VoolMethods, while Types store Risc::CallableMethod
|
# Classes store SolMethods, while Types store Risc::CallableMethod
|
||||||
# A Type referes to a Class , but a Class (interface) is implemented by many types
|
# A Type referes to a Class , but a Class (interface) is implemented by many types
|
||||||
# as it changes during the course of it's life. Types do not change. Objects have
|
# as it changes during the course of it's life. Types do not change. Objects have
|
||||||
# type, and so only indirectly a class.
|
# type, and so only indirectly a class.
|
||||||
#
|
#
|
||||||
class VoolMethod < Object
|
class SolMethod < Object
|
||||||
|
|
||||||
attr_reader :name , :args_type , :frame_type
|
attr_reader :name , :args_type , :frame_type
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
@ -24,8 +24,8 @@ module Parfait
|
|||||||
raise "Name must be symbol" unless name.is_a?(Symbol)
|
raise "Name must be symbol" unless name.is_a?(Symbol)
|
||||||
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
||||||
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
|
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
|
||||||
raise "source must be vool not#{source.class}" unless source.is_a?(Vool::Statement)
|
raise "source must be sol not#{source.class}" unless source.is_a?(Sol::Statement)
|
||||||
raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?)
|
raise "Empty bod" if(@source.is_a?(Sol::Statements) and @source.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_callable_method_for( type )
|
def create_callable_method_for( type )
|
@ -111,7 +111,7 @@ module Parfait
|
|||||||
# The superclass must be known when the class is created, or it raises an error.
|
# The superclass must be known when the class is created, or it raises an error.
|
||||||
# The class is initiated with the type of the superclass (hence above)
|
# The class is initiated with the type of the superclass (hence above)
|
||||||
#
|
#
|
||||||
# Only Vool::ClassExpression really ever creates classes and "grows" the type
|
# Only Sol::ClassExpression really ever creates classes and "grows" the type
|
||||||
# according to the instances it finds, see there
|
# according to the instances it finds, see there
|
||||||
#
|
#
|
||||||
def create_class( name , superclass = nil )
|
def create_class( name , superclass = nil )
|
||||||
|
@ -13,7 +13,7 @@ module Risc
|
|||||||
class OperatorInstruction < Instruction
|
class OperatorInstruction < Instruction
|
||||||
def initialize( source , operator , left , right )
|
def initialize( source , operator , left , right )
|
||||||
super(source)
|
super(source)
|
||||||
operator = operator.value if operator.is_a?(Vool::Constant)
|
operator = operator.value if operator.is_a?(Sol::Constant)
|
||||||
@operator = operator
|
@operator = operator
|
||||||
raise "unsuported operator :#{operator}:#{operator.class}:" unless Risc.operators.include?(operator)
|
raise "unsuported operator :#{operator}:#{operator.class}:" unless Risc.operators.include?(operator)
|
||||||
@left = left
|
@left = left
|
||||||
|
@ -141,7 +141,7 @@ module Parfait
|
|||||||
Type: {names: :List , types: :List ,
|
Type: {names: :List , types: :List ,
|
||||||
object_class: :Class, methods: :CallableMethod ,
|
object_class: :Class, methods: :CallableMethod ,
|
||||||
is_single: :Object} ,
|
is_single: :Object} ,
|
||||||
VoolMethod: { name: :Word , args_type: :Type , frame_type: :Type } ,
|
SolMethod: { name: :Word , args_type: :Type , frame_type: :Type } ,
|
||||||
Word: {char_length: :Integer , next_word: :Word} ,
|
Word: {char_length: :Integer , next_word: :Word} ,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -17,9 +17,9 @@ what we may loosely call type here, ie the kind of statement.
|
|||||||
The ruby layer is really all about defining classes for every kind of statement,
|
The ruby layer is really all about defining classes for every kind of statement,
|
||||||
thus "typing" the syntax tree, and making it concrete.
|
thus "typing" the syntax tree, and making it concrete.
|
||||||
|
|
||||||
## to Vool
|
## to Sol
|
||||||
|
|
||||||
In our nice layers, we are on the way down to Vool, a simplified version of oo.
|
In our nice layers, we are on the way down to Sol, a simplified version of oo.
|
||||||
|
|
||||||
It has proven handy to have this layer, so the code for transforming each object
|
It has proven handy to have this layer, so the code for transforming each object
|
||||||
is in the class representing that object. (As one does in oo, again imho).
|
is in the class representing that object. (As one does in oo, again imho).
|
||||||
@ -35,4 +35,4 @@ will surely follow.
|
|||||||
|
|
||||||
The compilation process ends up creating (parfait) objects to represent
|
The compilation process ends up creating (parfait) objects to represent
|
||||||
things like classes, types and constants. This is not done here yet, but in
|
things like classes, types and constants. This is not done here yet, but in
|
||||||
the vool layer.
|
the sol layer.
|
||||||
|
@ -6,11 +6,11 @@ module Ruby
|
|||||||
@name , @value = name , value
|
@name , @value = name , value
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool()
|
def to_sol()
|
||||||
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
||||||
case value
|
case value
|
||||||
when Variable , Constant
|
when Variable , Constant
|
||||||
return self.vool_brother.new(name,@value.to_vool)
|
return self.sol_brother.new(name,@value.to_sol)
|
||||||
when SendStatement , YieldStatement , RubyBlockStatement
|
when SendStatement , YieldStatement , RubyBlockStatement
|
||||||
return normalize_send
|
return normalize_send
|
||||||
else
|
else
|
||||||
@ -18,12 +18,12 @@ module Ruby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# sends may have complex args that get hoisted in vool:ing them
|
# sends may have complex args that get hoisted in sol:ing them
|
||||||
# in which case we have to assign the simplified, otherwise the
|
# in which case we have to assign the simplified, otherwise the
|
||||||
# plain send
|
# plain send
|
||||||
def normalize_send
|
def normalize_send
|
||||||
statements = value.to_vool
|
statements = value.to_sol
|
||||||
return assignment( statements ) if statements.is_a?(Vool::CallStatement)
|
return assignment( statements ) if statements.is_a?(Sol::CallStatement)
|
||||||
# send has hoisted assigns, so we make an assign out of the "pure" send
|
# send has hoisted assigns, so we make an assign out of the "pure" send
|
||||||
statements << assignment(statements.statements.pop)
|
statements << assignment(statements.statements.pop)
|
||||||
statements
|
statements
|
||||||
@ -32,7 +32,7 @@ module Ruby
|
|||||||
# create same type assignment with the value (a send)
|
# create same type assignment with the value (a send)
|
||||||
def assignment(value)
|
def assignment(value)
|
||||||
value ||= @value
|
value ||= @value
|
||||||
self.vool_brother.new(name,value)
|
self.sol_brother.new(name,value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Ruby
|
module Ruby
|
||||||
class Constant < Statement
|
class Constant < Statement
|
||||||
def to_vool
|
def to_sol
|
||||||
vool_brother.new
|
sol_brother.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class ValueConstant < Constant
|
class ValueConstant < Constant
|
||||||
@ -9,8 +9,8 @@ module Ruby
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def to_vool
|
def to_sol
|
||||||
vool_brother.new(@value)
|
sol_brother.new(@value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class IntegerConstant < ValueConstant
|
class IntegerConstant < ValueConstant
|
||||||
|
@ -5,8 +5,8 @@ module Ruby
|
|||||||
#
|
#
|
||||||
# A CallStatement has a name, receiver and arguments
|
# A CallStatement has a name, receiver and arguments
|
||||||
#
|
#
|
||||||
# Using the "vool_brother" we can create the right Vool class for it.
|
# Using the "sol_brother" we can create the right Sol class for it.
|
||||||
# Arguments in vool must be simple, so any complex expressions get
|
# Arguments in sol must be simple, so any complex expressions get
|
||||||
# hoisted and assigned to temporary variables.
|
# hoisted and assigned to temporary variables.
|
||||||
#
|
#
|
||||||
class CallStatement < Statement
|
class CallStatement < Statement
|
||||||
@ -18,17 +18,17 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
# we "normalize" or flatten any complex argument expressions into a list
|
# we "normalize" or flatten any complex argument expressions into a list
|
||||||
def to_vool
|
def to_sol
|
||||||
statements = Vool::Statements.new([])
|
statements = Sol::Statements.new([])
|
||||||
receiver = normalize_arg(@receiver , statements)
|
receiver = normalize_arg(@receiver , statements)
|
||||||
arguments = []
|
arguments = []
|
||||||
@arguments.each_with_index do |arg , index |
|
@arguments.each_with_index do |arg , index |
|
||||||
arguments << normalize_arg(arg , statements)
|
arguments << normalize_arg(arg , statements)
|
||||||
end
|
end
|
||||||
if statements.empty?
|
if statements.empty?
|
||||||
return vool_brother.new(@name, receiver , arguments)
|
return sol_brother.new(@name, receiver , arguments)
|
||||||
else
|
else
|
||||||
statements << vool_brother.new(@name, receiver , arguments)
|
statements << sol_brother.new(@name, receiver , arguments)
|
||||||
return statements
|
return statements
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,17 +38,17 @@ module Ruby
|
|||||||
# the effect is of walking the call tree now,
|
# the effect is of walking the call tree now,
|
||||||
# rather than using a stack to do that at runtime
|
# rather than using a stack to do that at runtime
|
||||||
def normalize_arg(arg , statements)
|
def normalize_arg(arg , statements)
|
||||||
vool_arg = arg.to_vool
|
sol_arg = arg.to_sol
|
||||||
return vool_arg if vool_arg.is_a?(Vool::Expression)
|
return sol_arg if sol_arg.is_a?(Sol::Expression)
|
||||||
if( vool_arg.is_a?(Vool::Statements))
|
if( sol_arg.is_a?(Sol::Statements))
|
||||||
while(vool_arg.length > 1)
|
while(sol_arg.length > 1)
|
||||||
statements << vool_arg.shift
|
statements << sol_arg.shift
|
||||||
end
|
end
|
||||||
vool_arg = vool_arg.shift
|
sol_arg = sol_arg.shift
|
||||||
end
|
end
|
||||||
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, vool_arg)
|
assign = Sol::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, sol_arg)
|
||||||
statements << assign
|
statements << assign
|
||||||
return Vool::LocalVariable.new(assign.name)
|
return Sol::LocalVariable.new(assign.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Ruby
|
module Ruby
|
||||||
class ClassMethodStatement < MethodStatement
|
class ClassMethodStatement < MethodStatement
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
body = normalized_body
|
body = normalized_body
|
||||||
Vool::ClassMethodExpression.new( @name , @args.dup , body.to_vool)
|
Sol::ClassMethodExpression.new( @name , @args.dup , body.to_sol)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -3,7 +3,7 @@ module Ruby
|
|||||||
attr_reader :name, :super_class_name , :body
|
attr_reader :name, :super_class_name , :body
|
||||||
|
|
||||||
# init with the class name, super class name and statement body
|
# init with the class name, super class name and statement body
|
||||||
# body must be Method or Send (See to_vool) or empty/nil (possibly not handled right)
|
# body must be Method or Send (See to_sol) or empty/nil (possibly not handled right)
|
||||||
def initialize( name , supe , body)
|
def initialize( name , supe , body)
|
||||||
@name , @super_class_name = name , supe
|
@name , @super_class_name = name , supe
|
||||||
case body
|
case body
|
||||||
@ -18,23 +18,23 @@ module Ruby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create equivalent vool objects. Mostly for method statements
|
# Create equivalent sol objects. Mostly for method statements
|
||||||
# For calls, call transform_statement, see there
|
# For calls, call transform_statement, see there
|
||||||
def to_vool
|
def to_sol
|
||||||
meths = []
|
meths = []
|
||||||
body.statements.each do |meth|
|
body.statements.each do |meth|
|
||||||
if( meth.is_a?(MethodStatement))
|
if( meth.is_a?(MethodStatement))
|
||||||
meths << meth.to_vool
|
meths << meth.to_sol
|
||||||
else
|
else
|
||||||
meths += transform_statement(meth)
|
meths += transform_statement(meth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Vool::ClassExpression.new(@name , @super_class_name, Vool::Statements.new(meths) )
|
Sol::ClassExpression.new(@name , @super_class_name, Sol::Statements.new(meths) )
|
||||||
end
|
end
|
||||||
|
|
||||||
# We rewrite certain send statements (so raise error for all else)
|
# We rewrite certain send statements (so raise error for all else)
|
||||||
# Currently only attributes (ie attr :name) supported, for which the standard getter
|
# Currently only attributes (ie attr :name) supported, for which the standard getter
|
||||||
# and setter is created and returned as vool
|
# and setter is created and returned as sol
|
||||||
def transform_statement( class_send )
|
def transform_statement( class_send )
|
||||||
unless class_send.is_a?(SendStatement)
|
unless class_send.is_a?(SendStatement)
|
||||||
raise "Other than methods, only class methods allowed, not #{class_send.class}"
|
raise "Other than methods, only class methods allowed, not #{class_send.class}"
|
||||||
@ -53,21 +53,21 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
# creates a getter method for the given instance name (sym)
|
# creates a getter method for the given instance name (sym)
|
||||||
# The Method is created in Ruby, and to_vool is called to transform to Vool
|
# The Method is created in Ruby, and to_sol is called to transform to Sol
|
||||||
# The standard getter obviously only returns the ivar
|
# The standard getter obviously only returns the ivar
|
||||||
def getter_for(instance_name)
|
def getter_for(instance_name)
|
||||||
return_statement = ReturnStatement.new(InstanceVariable.new(instance_name))
|
return_statement = ReturnStatement.new(InstanceVariable.new(instance_name))
|
||||||
MethodStatement.new(instance_name , [] , return_statement).to_vool
|
MethodStatement.new(instance_name , [] , return_statement).to_sol
|
||||||
end
|
end
|
||||||
|
|
||||||
# creates a setter method (name=) for the given instance name (sym)
|
# creates a setter method (name=) for the given instance name (sym)
|
||||||
# The Method is created in Ruby, and to_vool is called to transform to Vool
|
# The Method is created in Ruby, and to_sol is called to transform to Sol
|
||||||
# The setter method assigns the incoming value and returns the ivar
|
# The setter method assigns the incoming value and returns the ivar
|
||||||
def setter_for(instance_name)
|
def setter_for(instance_name)
|
||||||
assign = IvarAssignment.new(instance_name , LocalVariable.new(:val))
|
assign = IvarAssignment.new(instance_name , LocalVariable.new(:val))
|
||||||
return_statement = ReturnStatement.new(InstanceVariable.new(instance_name))
|
return_statement = ReturnStatement.new(InstanceVariable.new(instance_name))
|
||||||
statements = Statements.new([assign, return_statement])
|
statements = Statements.new([assign, return_statement])
|
||||||
MethodStatement.new("#{instance_name}=".to_sym , [:val] , statements).to_vool
|
MethodStatement.new("#{instance_name}=".to_sym , [:val] , statements).to_sol
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -3,11 +3,11 @@ require_relative "normalizer"
|
|||||||
module Ruby
|
module Ruby
|
||||||
# The if must have condition and a true branch, the false is optional
|
# The if must have condition and a true branch, the false is optional
|
||||||
#
|
#
|
||||||
# It maps pretty much one to one to a Vool, except for "hoisting"
|
# It maps pretty much one to one to a Sol, except for "hoisting"
|
||||||
#
|
#
|
||||||
# Ruby may have super complex expressions as the condition, whereas
|
# Ruby may have super complex expressions as the condition, whereas
|
||||||
# Vool may not. Ie of a Statement list all but the last are hoisted to before
|
# Sol may not. Ie of a Statement list all but the last are hoisted to before
|
||||||
# the vool if. This is equivalent, just easier to compile later
|
# the sol if. This is equivalent, just easier to compile later
|
||||||
#
|
#
|
||||||
# The hoisintg code is in Normalizer, as it is also useed in return and while
|
# The hoisintg code is in Normalizer, as it is also useed in return and while
|
||||||
class IfStatement < Statement
|
class IfStatement < Statement
|
||||||
@ -21,11 +21,11 @@ module Ruby
|
|||||||
@if_false = if_false
|
@if_false = if_false
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
cond , hoisted = *normalized_vool(@condition)
|
cond , hoisted = *normalized_sol(@condition)
|
||||||
me = Vool::IfStatement.new(cond , @if_true&.to_vool, @if_false&.to_vool)
|
me = Sol::IfStatement.new(cond , @if_true&.to_sol, @if_false&.to_sol)
|
||||||
return me unless hoisted
|
return me unless hoisted
|
||||||
Vool::Statements.new( hoisted ) << me
|
Sol::Statements.new( hoisted ) << me
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_false?
|
def has_false?
|
||||||
|
@ -7,7 +7,7 @@ module Ruby
|
|||||||
# ie: false && non_existant_method
|
# ie: false && non_existant_method
|
||||||
# will never call the non_existant_method , but instead evaluate to false
|
# will never call the non_existant_method , but instead evaluate to false
|
||||||
#
|
#
|
||||||
# Vool has no concept of this, so the Statement is expanded into the if
|
# Sol has no concept of this, so the Statement is expanded into the if
|
||||||
# that it really is
|
# that it really is
|
||||||
class LogicalStatement < Statement
|
class LogicalStatement < Statement
|
||||||
attr_reader :name , :left , :right
|
attr_reader :name , :left , :right
|
||||||
|
@ -15,9 +15,9 @@ module Ruby
|
|||||||
body << replace_return( body.pop )
|
body << replace_return( body.pop )
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
body = normalized_body
|
body = normalized_body
|
||||||
Vool::MethodExpression.new( @name , @args.dup , body.to_vool)
|
Sol::MethodExpression.new( @name , @args.dup , body.to_sol)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_return(statement)
|
def replace_return(statement)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Ruby
|
module Ruby
|
||||||
module Normalizer
|
module Normalizer
|
||||||
# Normalize ruby to vool by "flattening" structure
|
# Normalize ruby to sol by "flattening" structure
|
||||||
#
|
#
|
||||||
# This is a common issue for return, if and while , which all need to operate on the
|
# This is a common issue for return, if and while , which all need to operate on the
|
||||||
# last value. In ruby the last value is always implicit, in vool not.
|
# last value. In ruby the last value is always implicit, in sol not.
|
||||||
#
|
#
|
||||||
# A "normalized" structure is first of all not recursive, a list not a tree,
|
# A "normalized" structure is first of all not recursive, a list not a tree,
|
||||||
# The last expression of the list may be one of three things
|
# The last expression of the list may be one of three things
|
||||||
@ -13,11 +13,11 @@ module Ruby
|
|||||||
#
|
#
|
||||||
# We return the last expression, the one that is returned or tested on, seperately
|
# We return the last expression, the one that is returned or tested on, seperately
|
||||||
#
|
#
|
||||||
def normalized_vool( condition )
|
def normalized_sol( condition )
|
||||||
vool_condition = condition.to_vool
|
sol_condition = condition.to_sol
|
||||||
return vool_condition unless( vool_condition.is_a?(Vool::Statements) )
|
return sol_condition unless( sol_condition.is_a?(Sol::Statements) )
|
||||||
return vool_condition.first if( vool_condition.single?)
|
return sol_condition.first if( sol_condition.single?)
|
||||||
return [vool_condition.pop , vool_condition ]
|
return [sol_condition.pop , sol_condition ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,11 +8,11 @@ module Ruby
|
|||||||
@return_value = value || NilConstant.new
|
@return_value = value || NilConstant.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
val , hoisted = *normalized_vool(@return_value)
|
val , hoisted = *normalized_sol(@return_value)
|
||||||
me = Vool::ReturnStatement.new(val)
|
me = Sol::ReturnStatement.new(val)
|
||||||
return me unless hoisted
|
return me unless hoisted
|
||||||
Vool::Statements.new( hoisted ) << me
|
Sol::Statements.new( hoisted ) << me
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -13,16 +13,16 @@ module Ruby
|
|||||||
raise "no bod" unless @body
|
raise "no bod" unless @body
|
||||||
end
|
end
|
||||||
|
|
||||||
# This resolves to a Vool SendStatement, in fact that is mostly what it is.
|
# This resolves to a Sol SendStatement, in fact that is mostly what it is.
|
||||||
#
|
#
|
||||||
# The implicitly passed block (in ruby) gets converted to the constant it is, and
|
# The implicitly passed block (in ruby) gets converted to the constant it is, and
|
||||||
# is passed as the last argument.
|
# is passed as the last argument.
|
||||||
#
|
#
|
||||||
def to_vool
|
def to_sol
|
||||||
#block_name = "implicit_block_#{object_id}".to_sym
|
#block_name = "implicit_block_#{object_id}".to_sym
|
||||||
lambda = Vool::LambdaExpression.new( @args.dup , @body.to_vool)
|
lambda = Sol::LambdaExpression.new( @args.dup , @body.to_sol)
|
||||||
ret = @send.to_vool
|
ret = @send.to_sol
|
||||||
sendd = ret.is_a?(Vool::Statements) ? ret.last : ret
|
sendd = ret.is_a?(Sol::Statements) ? ret.last : ret
|
||||||
sendd.arguments << lambda
|
sendd.arguments << lambda
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,7 @@ module Ruby
|
|||||||
#
|
#
|
||||||
# As a second step, it extracts classes, methods, ivars and locals.
|
# As a second step, it extracts classes, methods, ivars and locals.
|
||||||
#
|
#
|
||||||
# The next step is then to go to the vool level, which is
|
# The next step is then to go to the sol level, which is
|
||||||
# simpler, and then finally to compile
|
# simpler, and then finally to compile
|
||||||
# to the next level down, SlotMachine (Minimal Object Machine)
|
# to the next level down, SlotMachine (Minimal Object Machine)
|
||||||
class RubyCompiler < AST::Processor
|
class RubyCompiler < AST::Processor
|
||||||
|
@ -5,10 +5,10 @@ module Ruby
|
|||||||
#
|
#
|
||||||
class SendStatement < CallStatement
|
class SendStatement < CallStatement
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
if @receiver.is_a?(ModuleName) and @receiver.name == :X
|
if @receiver.is_a?(ModuleName) and @receiver.name == :X
|
||||||
args = @arguments.collect { |arg| arg.to_vool }
|
args = @arguments.collect { |arg| arg.to_sol }
|
||||||
return Vool::MacroExpression.new(name , args)
|
return Sol::MacroExpression.new(name , args)
|
||||||
end
|
end
|
||||||
return require_file if( @name == :require_relative )
|
return require_file if( @name == :require_relative )
|
||||||
return super
|
return super
|
||||||
@ -25,7 +25,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
path = File.expand_path( "../../../#{file}" , __FILE__)
|
path = File.expand_path( "../../../#{file}" , __FILE__)
|
||||||
source = File.read(path)
|
source = File.read(path)
|
||||||
RubyCompiler.compile( source ).to_vool
|
RubyCompiler.compile( source ).to_sol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SuperStatement < SendStatement
|
class SuperStatement < SendStatement
|
||||||
|
@ -7,16 +7,16 @@ module Ruby
|
|||||||
#
|
#
|
||||||
class Statement
|
class Statement
|
||||||
|
|
||||||
# Many statements exist in the vool layer in quite a similar arrangement
|
# Many statements exist in the sol layer in quite a similar arrangement
|
||||||
# Especially for different types of assignment we can abstract the creation
|
# Especially for different types of assignment we can abstract the creation
|
||||||
# of the vool, by using the right class to instantiate, the "vool_brother"
|
# of the sol, by using the right class to instantiate, the "sol_brother"
|
||||||
# Ie same class_name, but in the Vool module
|
# Ie same class_name, but in the Sol module
|
||||||
def vool_brother
|
def sol_brother
|
||||||
eval "Vool::#{class_name}"
|
eval "Sol::#{class_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# return the class name without the module
|
# return the class name without the module
|
||||||
# used to evaluate the vool_brother
|
# used to evaluate the sol_brother
|
||||||
def class_name
|
def class_name
|
||||||
self.class.name.split("::").last
|
self.class.name.split("::").last
|
||||||
end
|
end
|
||||||
|
@ -35,11 +35,11 @@ module Ruby
|
|||||||
@statements << o
|
@statements << o
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
def to_vool
|
def to_sol
|
||||||
return first.to_vool if( single? )
|
return first.to_sol if( single? )
|
||||||
brother = vool_brother.new(nil)
|
brother = sol_brother.new(nil)
|
||||||
@statements.each do |s|
|
@statements.each do |s|
|
||||||
brother << s.to_vool
|
brother << s.to_sol
|
||||||
end
|
end
|
||||||
brother
|
brother
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,8 @@ module Ruby
|
|||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
vool_brother.new(@name)
|
sol_brother.new(@name)
|
||||||
end
|
end
|
||||||
def to_s(depth=0)
|
def to_s(depth=0)
|
||||||
name.to_s
|
name.to_s
|
||||||
|
@ -11,9 +11,9 @@ module Ruby
|
|||||||
@body = body
|
@body = body
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_vool
|
def to_sol
|
||||||
cond , hoisted = *normalized_vool(@condition)
|
cond , hoisted = *normalized_sol(@condition)
|
||||||
Vool::WhileStatement.new(cond , @body.to_vool , hoisted)
|
Sol::WhileStatement.new(cond , @body.to_sol , hoisted)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -6,7 +6,7 @@ require_relative "risc"
|
|||||||
require_relative "slot_machine/slot_machine"
|
require_relative "slot_machine/slot_machine"
|
||||||
require_relative "arm/arm_machine"
|
require_relative "arm/arm_machine"
|
||||||
require_relative "arm/arm_platform"
|
require_relative "arm/arm_platform"
|
||||||
require_relative "vool/statement"
|
require_relative "sol/statement"
|
||||||
require_relative "vool/builtin"
|
require_relative "sol/builtin"
|
||||||
require_relative "ruby"
|
require_relative "ruby"
|
||||||
require_relative "rubyx/rubyx_compiler"
|
require_relative "rubyx/rubyx_compiler"
|
||||||
|
@ -3,7 +3,7 @@ module RubyX
|
|||||||
# give helper functions to create any intermediate layer.
|
# give helper functions to create any intermediate layer.
|
||||||
# Layers are:
|
# Layers are:
|
||||||
# - ruby , always needed as input, string
|
# - ruby , always needed as input, string
|
||||||
# - vool - intermediate language layer
|
# - sol - intermediate language layer
|
||||||
# - slot_machine - intermediate machine layer
|
# - slot_machine - intermediate machine layer
|
||||||
# - risc - "last" intermediate machine layer
|
# - risc - "last" intermediate machine layer
|
||||||
# - target - arm or interpreter binary code
|
# - target - arm or interpreter binary code
|
||||||
@ -13,19 +13,19 @@ module RubyX
|
|||||||
# There are methods to go from ruby to any of the layers in the system
|
# There are methods to go from ruby to any of the layers in the system
|
||||||
# (mainly for testing). ruby_to_binary creates actual binary code
|
# (mainly for testing). ruby_to_binary creates actual binary code
|
||||||
# for a given platform.
|
# for a given platform.
|
||||||
# The compiler keeps the vool source as an instance.
|
# The compiler keeps the sol source as an instance.
|
||||||
# To compile several sources, more vool can be added, ie ruby_to_vool
|
# To compile several sources, more sol can be added, ie ruby_to_sol
|
||||||
# can be called several times.
|
# can be called several times.
|
||||||
#
|
#
|
||||||
# All other methods come in pairs, one takes ruby source (those are for testing)
|
# All other methods come in pairs, one takes ruby source (those are for testing)
|
||||||
# and the other uses the stored vool source for further processing.
|
# and the other uses the stored sol source for further processing.
|
||||||
#
|
#
|
||||||
# Only builtin is loaded, so no runtime , but the compiler
|
# Only builtin is loaded, so no runtime , but the compiler
|
||||||
# can be used to read the runtime and then any other code
|
# can be used to read the runtime and then any other code
|
||||||
#
|
#
|
||||||
class RubyXCompiler
|
class RubyXCompiler
|
||||||
|
|
||||||
attr_reader :vool , :options
|
attr_reader :sol , :options
|
||||||
|
|
||||||
# initialize boots Parfait and Risc (ie load Builin)
|
# initialize boots Parfait and Risc (ie load Builin)
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@ -35,7 +35,7 @@ module RubyX
|
|||||||
end
|
end
|
||||||
|
|
||||||
# The highest level function creates binary code for the given ruby code
|
# The highest level function creates binary code for the given ruby code
|
||||||
# for the given platform (see Platform). Binary code means that vool/slot_machine/risc
|
# for the given platform (see Platform). Binary code means that sol/slot_machine/risc
|
||||||
# are created and then assembled into BinaryCode objects.
|
# are created and then assembled into BinaryCode objects.
|
||||||
# (no executable is generated, only the binary code and objects needed for a binary)
|
# (no executable is generated, only the binary code and objects needed for a binary)
|
||||||
#
|
#
|
||||||
@ -43,38 +43,38 @@ module RubyX
|
|||||||
#
|
#
|
||||||
# The compiling is done by to_binary
|
# The compiling is done by to_binary
|
||||||
def ruby_to_binary(ruby , platform)
|
def ruby_to_binary(ruby , platform)
|
||||||
ruby_to_vool(ruby)
|
ruby_to_sol(ruby)
|
||||||
to_binary(platform)
|
to_binary(platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
# ruby_to_target creates Target instructions (but does not link)
|
# ruby_to_target creates Target instructions (but does not link)
|
||||||
#
|
#
|
||||||
# After creating vool, we call to_target
|
# After creating sol, we call to_target
|
||||||
# Return a Linker
|
# Return a Linker
|
||||||
def ruby_to_target(ruby , platform)
|
def ruby_to_target(ruby , platform)
|
||||||
ruby_to_vool(ruby)
|
ruby_to_sol(ruby)
|
||||||
to_target( platform )
|
to_target( platform )
|
||||||
end
|
end
|
||||||
|
|
||||||
# ruby_to_risc creates Risc instructions
|
# ruby_to_risc creates Risc instructions
|
||||||
#
|
#
|
||||||
# After creating vool, we call to_risc
|
# After creating sol, we call to_risc
|
||||||
# Return a RiscCollection
|
# Return a RiscCollection
|
||||||
def ruby_to_risc(ruby)
|
def ruby_to_risc(ruby)
|
||||||
ruby_to_vool(ruby)
|
ruby_to_sol(ruby)
|
||||||
to_risc()
|
to_risc()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transform the incoming ruby source (string) to slot
|
# Transform the incoming ruby source (string) to slot
|
||||||
#
|
#
|
||||||
# The vool is stored using ruby_to_vool,the to_slot is called
|
# The sol is stored using ruby_to_sol,the to_slot is called
|
||||||
# Return SlotMachine Statement
|
# Return SlotMachine Statement
|
||||||
def ruby_to_slot(ruby)
|
def ruby_to_slot(ruby)
|
||||||
ruby_to_vool(ruby)
|
ruby_to_sol(ruby)
|
||||||
to_slot
|
to_slot
|
||||||
end
|
end
|
||||||
|
|
||||||
# Process previously stored vool source to binary.
|
# Process previously stored sol source to binary.
|
||||||
# Binary code is generated by calling to_risc, then positioning and calling
|
# Binary code is generated by calling to_risc, then positioning and calling
|
||||||
# create_binary on the linker. The linker may then be used to creat a binary file.
|
# create_binary on the linker. The linker may then be used to creat a binary file.
|
||||||
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
||||||
@ -86,7 +86,7 @@ module RubyX
|
|||||||
linker
|
linker
|
||||||
end
|
end
|
||||||
|
|
||||||
# transform stored vool to target code
|
# transform stored sol to target code
|
||||||
# return a linker
|
# return a linker
|
||||||
def to_target(platform)
|
def to_target(platform)
|
||||||
raise "No platform given" unless platform
|
raise "No platform given" unless platform
|
||||||
@ -94,46 +94,46 @@ module RubyX
|
|||||||
collection.translate(platform)
|
collection.translate(platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Process previously stored vool source to risc.
|
# Process previously stored sol source to risc.
|
||||||
# return a Risc::RiscCollection , a collection of MethodCompilers
|
# return a Risc::RiscCollection , a collection of MethodCompilers
|
||||||
def to_risc()
|
def to_risc()
|
||||||
slot = to_slot
|
slot = to_slot
|
||||||
slot.to_risc()
|
slot.to_risc()
|
||||||
end
|
end
|
||||||
|
|
||||||
# return slot_machine for the previously stored vool source.
|
# return slot_machine for the previously stored sol source.
|
||||||
def to_slot
|
def to_slot
|
||||||
@vool.to_parfait
|
@sol.to_parfait
|
||||||
@vool.to_slot(nil)
|
@sol.to_slot(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# ruby_to_vool compiles the ruby to ast, and then to vool
|
# ruby_to_sol compiles the ruby to ast, and then to sol
|
||||||
def ruby_to_vool(ruby_source)
|
def ruby_to_sol(ruby_source)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( ruby_source )
|
ruby_tree = Ruby::RubyCompiler.compile( ruby_source )
|
||||||
unless(@vool)
|
unless(@sol)
|
||||||
@vool = ruby_tree.to_vool
|
@sol = ruby_tree.to_sol
|
||||||
return @vool
|
return @sol
|
||||||
end
|
end
|
||||||
# TODO: should check if this works with reopening classes
|
# TODO: should check if this works with reopening classes
|
||||||
# or whether we need to unify the vool for a class
|
# or whether we need to unify the sol for a class
|
||||||
unless(@vool.is_a?(Vool::ScopeStatement))
|
unless(@sol.is_a?(Sol::ScopeStatement))
|
||||||
@vool = Vool::ScopeStatement.new([@vool])
|
@sol = Sol::ScopeStatement.new([@sol])
|
||||||
end
|
end
|
||||||
@vool << ruby_tree.to_vool
|
@sol << ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_parfait
|
def load_parfait
|
||||||
parfait = ["object"]
|
parfait = ["object"]
|
||||||
parfait.each do |file|
|
parfait.each do |file|
|
||||||
path = File.expand_path("../../parfait/#{file}.rb",__FILE__)
|
path = File.expand_path("../../parfait/#{file}.rb",__FILE__)
|
||||||
ruby_to_vool(File.read(path))
|
ruby_to_sol(File.read(path))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ruby_to_binary( ruby , options)
|
def self.ruby_to_binary( ruby , options)
|
||||||
compiler = RubyXCompiler.new(options)
|
compiler = RubyXCompiler.new(options)
|
||||||
compiler.load_parfait if options[:load_parfait]
|
compiler.load_parfait if options[:load_parfait]
|
||||||
compiler.ruby_to_vool(ruby)
|
compiler.ruby_to_sol(ruby)
|
||||||
compiler.to_binary(options[:platform])
|
compiler.to_binary(options[:platform])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ class RubyXC < Thor
|
|||||||
return {parfait: opt }
|
return {parfait: opt }
|
||||||
end
|
end
|
||||||
def get_preload
|
def get_preload
|
||||||
options[:preload] ? Vool::Builtin.builtin_code : ""
|
options[:preload] ? Sol::Builtin.builtin_code : ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# SlotMachine
|
# SlotMachine
|
||||||
|
|
||||||
This layer sits between the language layer (vool) and the risc machine layer.
|
This layer sits between the language layer (sol) and the risc machine layer.
|
||||||
It is meant to make the transition (between vool and risc) easier to understand.
|
It is meant to make the transition (between sol and risc) easier to understand.
|
||||||
|
|
||||||
Previous efforts were doing the transition without an intermediate layer. But while
|
Previous efforts were doing the transition without an intermediate layer. But while
|
||||||
this was possible, it was more difficult than need be, and so we go to the old saying
|
this was possible, it was more difficult than need be, and so we go to the old saying
|
||||||
@ -13,17 +13,17 @@ A little recap of why the transition was too steep will naturally reveal the des
|
|||||||
|
|
||||||
### Structure
|
### Structure
|
||||||
|
|
||||||
Vool has a tree structure. Risc is a linked list, so essentially flat.
|
Sol has a tree structure. Risc is a linked list, so essentially flat.
|
||||||
|
|
||||||
### Memory model
|
### Memory model
|
||||||
|
|
||||||
Vool has no memory, it has objects and they just are. Risc on the other hand has only registers
|
Sol has no memory, it has objects and they just are. Risc on the other hand has only registers
|
||||||
and memory. Data can only move to/from/between registers, ie not from memory to memory.
|
and memory. Data can only move to/from/between registers, ie not from memory to memory.
|
||||||
While Risc knows about objects, it deals in machine words.
|
While Risc knows about objects, it deals in machine words.
|
||||||
|
|
||||||
### Execution model
|
### Execution model
|
||||||
|
|
||||||
Vool's implicit execution model would be interpretation, ie tree traversal. Vool has high level
|
Sol's implicit execution model would be interpretation, ie tree traversal. Sol has high level
|
||||||
control structures, including send, and no goto, it is a language after all.
|
control structures, including send, and no goto, it is a language after all.
|
||||||
|
|
||||||
Risc is close to a cpu, it has a current instruction (pc), registers (8) and a register based
|
Risc is close to a cpu, it has a current instruction (pc), registers (8) and a register based
|
||||||
@ -32,7 +32,7 @@ used (stacks are messy, not oo)
|
|||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
The *essential* step from vool to risc, is the one from a language to a machine. From statements
|
The *essential* step from sol to risc, is the one from a language to a machine. From statements
|
||||||
that hang in the air, to an instruction set.
|
that hang in the air, to an instruction set.
|
||||||
So to put a layer in the middle of those two, SlotMachine will be:
|
So to put a layer in the middle of those two, SlotMachine will be:
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ module SlotMachine
|
|||||||
# Base class for SlotMachine instructions
|
# Base class for SlotMachine instructions
|
||||||
# At the base class level instructions are a linked list.
|
# At the base class level instructions are a linked list.
|
||||||
#
|
#
|
||||||
# SlotMachine::Instructions are created by the Vool level as an intermediate step
|
# SlotMachine::Instructions are created by the Sol level as an intermediate step
|
||||||
# towards the next level down, the Risc level.
|
# towards the next level down, the Risc level.
|
||||||
# SlotMachine and Risc are both abstract machines (ie have instructions), so both
|
# SlotMachine and Risc are both abstract machines (ie have instructions), so both
|
||||||
# share the linked list functionality (In Util::List)
|
# share the linked list functionality (In Util::List)
|
||||||
@ -18,7 +18,7 @@ module SlotMachine
|
|||||||
@next = nekst
|
@next = nekst
|
||||||
return unless source
|
return unless source
|
||||||
unless source.is_a?(String) or
|
unless source.is_a?(String) or
|
||||||
source.is_a?(Vool::Statement)
|
source.is_a?(Sol::Statement)
|
||||||
raise "Source must be string or Instruction, not #{source.class}"
|
raise "Source must be string or Instruction, not #{source.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
# just name scoping the same stuff to slot
|
# just name scoping the same stuff to slot
|
||||||
# so we know we are on the way down, keeping our layers seperated
|
# so we know we are on the way down, keeping our layers seperated
|
||||||
# and we can put constant adding into the to_risc methods (instead of on vool classes)
|
# and we can put constant adding into the to_risc methods (instead of on sol classes)
|
||||||
class Constant
|
class Constant
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ module SlotMachine
|
|||||||
class BlockYield < Instruction
|
class BlockYield < Instruction
|
||||||
attr :arg_index
|
attr :arg_index
|
||||||
|
|
||||||
# pass in the source (vool statement) and the index.
|
# pass in the source (sol statement) and the index.
|
||||||
# The index is the argument index of the block that we call
|
# The index is the argument index of the block that we call
|
||||||
def initialize(source , index)
|
def initialize(source , index)
|
||||||
super(source)
|
super(source)
|
||||||
|
@ -9,7 +9,7 @@ module SlotMachine
|
|||||||
#
|
#
|
||||||
# Setting up the method is not part of this instructions scope. That setup
|
# Setting up the method is not part of this instructions scope. That setup
|
||||||
# includes the type check and any necccessay method resolution.
|
# includes the type check and any necccessay method resolution.
|
||||||
# See vool send statement
|
# See sol send statement
|
||||||
#
|
#
|
||||||
class DynamicCall < Instruction
|
class DynamicCall < Instruction
|
||||||
attr :cache_entry
|
attr :cache_entry
|
||||||
|
@ -15,7 +15,7 @@ module SlotMachine
|
|||||||
class ResolveMethod < Instruction
|
class ResolveMethod < Instruction
|
||||||
attr :cache_entry , :name
|
attr :cache_entry , :name
|
||||||
|
|
||||||
# pass in source (VoolStatement)
|
# pass in source (SolStatement)
|
||||||
# name of the method (don't knwow the actaual method)
|
# name of the method (don't knwow the actaual method)
|
||||||
# and the cache_entry
|
# and the cache_entry
|
||||||
def initialize(source , name , cache_entry)
|
def initialize(source , name , cache_entry)
|
||||||
|
@ -9,7 +9,7 @@ module SlotMachine
|
|||||||
|
|
||||||
attr_reader :return_label
|
attr_reader :return_label
|
||||||
|
|
||||||
# pass in the source_name (string/vool_instruction) for accounting purposes
|
# pass in the source_name (string/sol_instruction) for accounting purposes
|
||||||
# and the return_label, where we actually jump to. This is set up by the
|
# and the return_label, where we actually jump to. This is set up by the
|
||||||
# method_compiler, so it is easy to find (see return_label in compiler)
|
# method_compiler, so it is easy to find (see return_label in compiler)
|
||||||
def initialize( source , label )
|
def initialize( source , label )
|
||||||
|
@ -4,7 +4,7 @@ module SlotMachine
|
|||||||
|
|
||||||
def initialize( source , name )
|
def initialize( source , name )
|
||||||
super(source)
|
super(source)
|
||||||
name = name.value if name.is_a?(Vool::SymbolConstant)
|
name = name.value if name.is_a?(Sol::SymbolConstant)
|
||||||
raise "No reg #{name.class}" unless name.class == Symbol
|
raise "No reg #{name.class}" unless name.class == Symbol
|
||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,8 @@ module SlotMachine
|
|||||||
# The Compiler/Collection for the SlotMachine level is a collection of SlotMachine level Method
|
# The Compiler/Collection for the SlotMachine level is a collection of SlotMachine level Method
|
||||||
# compilers These will transform to Risc MethodCompilers on the way down.
|
# compilers These will transform to Risc MethodCompilers on the way down.
|
||||||
#
|
#
|
||||||
# As RubyCompiler pools source at the vool level, when several classes are compiled
|
# As RubyCompiler pools source at the sol level, when several classes are compiled
|
||||||
# from vool to slot, several SlotMachineCompilers get instantiated. They must be merged before
|
# from sol to slot, several SlotMachineCompilers get instantiated. They must be merged before
|
||||||
# proceeding with translate. Thus we have a append method.
|
# proceeding with translate. Thus we have a append method.
|
||||||
#
|
#
|
||||||
class SlotCollection
|
class SlotCollection
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# The *essential* step from vool to risc, is the one from a language to a machine.
|
# The *essential* step from sol to risc, is the one from a language to a machine.
|
||||||
# From vools statements that hang in the air, to an instruction set.
|
# From sols statements that hang in the air, to an instruction set.
|
||||||
#
|
#
|
||||||
# ### List based: Bit like Risc, just no registers
|
# ### List based: Bit like Risc, just no registers
|
||||||
#
|
#
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# VOOL
|
# SOL
|
||||||
|
|
||||||
Virtual Object Oriented Language
|
Simple Object Language
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
in other words, ruby without the fluff.
|
in other words, ruby without the fluff.
|
||||||
@ -9,10 +9,10 @@ Possibly later other languages can compile to this level and use rx-file as code
|
|||||||
|
|
||||||
## Syntax tree
|
## Syntax tree
|
||||||
|
|
||||||
Vool is a layer with concrete syntax tree, just like the ruby layer above.
|
Sol is a layer with concrete syntax tree, just like the ruby layer above.
|
||||||
Vool is just simplified, without fluff, see below.
|
Sol is just simplified, without fluff, see below.
|
||||||
|
|
||||||
The next layer down is the SlotMachine, Minimal object Machine, which uses an instruction list.
|
The next layer down is the SlotMachine, which uses an instruction list.
|
||||||
|
|
||||||
The nodes of the syntax tree are all the things one would expect from a language,
|
The nodes of the syntax tree are all the things one would expect from a language,
|
||||||
if statements and the like. There is no context yet, and actual objects,
|
if statements and the like. There is no context yet, and actual objects,
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
# Base class for assignments (local/ivar), works just as you'd expect
|
# Base class for assignments (local/ivar), works just as you'd expect
|
||||||
# Only "quirk" maybe, that arguments are like locals
|
# Only "quirk" maybe, that arguments are like locals
|
@ -1,9 +1,9 @@
|
|||||||
module Vool
|
module Sol
|
||||||
#Marker class for different constants
|
#Marker class for different constants
|
||||||
class Constant < Expression
|
class Constant < Expression
|
||||||
end
|
end
|
||||||
|
|
||||||
# An integer at the vool level
|
# An integer at the sol level
|
||||||
class IntegerConstant < Constant
|
class IntegerConstant < Constant
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@ -19,7 +19,7 @@ module Vool
|
|||||||
value.to_s
|
value.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# An float at the vool level
|
# An float at the sol level
|
||||||
class FloatConstant < Constant
|
class FloatConstant < Constant
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@ -32,7 +32,7 @@ module Vool
|
|||||||
value.to_s
|
value.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# True at the vool level
|
# True at the sol level
|
||||||
class TrueConstant < Constant
|
class TrueConstant < Constant
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:True)
|
Parfait.object_space.get_type_by_class_name(:True)
|
||||||
@ -44,7 +44,7 @@ module Vool
|
|||||||
"true"
|
"true"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# False at the vool level
|
# False at the sol level
|
||||||
class FalseConstant < Constant
|
class FalseConstant < Constant
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:False)
|
Parfait.object_space.get_type_by_class_name(:False)
|
||||||
@ -56,7 +56,7 @@ module Vool
|
|||||||
"false"
|
"false"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Nil at the vool level
|
# Nil at the sol level
|
||||||
class NilConstant < Constant
|
class NilConstant < Constant
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
Parfait.object_space.get_type_by_class_name(:Nil)
|
||||||
@ -69,7 +69,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Self at the vool level
|
# Self at the sol level
|
||||||
class SelfExpression < Expression
|
class SelfExpression < Expression
|
||||||
attr_reader :my_type
|
attr_reader :my_type
|
||||||
def initialize(type = nil)
|
def initialize(type = nil)
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
module Builtin
|
module Builtin
|
||||||
def self.boot_methods(options)
|
def self.boot_methods(options)
|
||||||
return if options[:boot_methods] == false
|
return if options[:boot_methods] == false
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
class CallStatement < Statement
|
class CallStatement < Statement
|
||||||
attr_reader :name , :receiver , :arguments
|
attr_reader :name , :receiver , :arguments
|
@ -1,5 +1,5 @@
|
|||||||
module Vool
|
module Sol
|
||||||
# This represents a class at the vool level. Vool is a syntax tree,
|
# This represents a class at the sol level. Sol is a syntax tree,
|
||||||
# so here the only child (or children) is a body.
|
# so here the only child (or children) is a body.
|
||||||
# Body may either be a MethodStatement, or Statements (either empty or
|
# Body may either be a MethodStatement, or Statements (either empty or
|
||||||
# containing MethodStatement)
|
# containing MethodStatement)
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class ClassMethodExpression < Expression
|
class ClassMethodExpression < Expression
|
||||||
attr_reader :name, :args , :body
|
attr_reader :name, :args , :body
|
||||||
|
|
||||||
@ -7,14 +7,14 @@ module Vool
|
|||||||
raise "no bod" unless @body
|
raise "no bod" unless @body
|
||||||
end
|
end
|
||||||
|
|
||||||
# create the parfait VoolMethod to hold the code for this method
|
# create the parfait SolMethod to hold the code for this method
|
||||||
#
|
#
|
||||||
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
||||||
def to_parfait( clazz = nil )
|
def to_parfait( clazz = nil )
|
||||||
raise "No class given to class method #{name}" unless clazz
|
raise "No class given to class method #{name}" unless clazz
|
||||||
vool_m = clazz.single_class.create_instance_method_for(name , make_arg_type , make_frame , body )
|
sol_m = clazz.single_class.create_instance_method_for(name , make_arg_type , make_frame , body )
|
||||||
vool_m.create_callable_method_for(clazz.single_class.instance_type)
|
sol_m.create_callable_method_for(clazz.single_class.instance_type)
|
||||||
vool_m
|
sol_m
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_slot(clazz)
|
def to_slot(clazz)
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class IfStatement < Statement
|
class IfStatement < Statement
|
||||||
|
|
||||||
attr_reader :condition , :if_true , :if_false
|
attr_reader :condition , :if_true , :if_false
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
class IvarAssignment < Assignment
|
class IvarAssignment < Assignment
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class LambdaExpression < Expression
|
class LambdaExpression < Expression
|
||||||
attr_reader :args , :body , :clazz
|
attr_reader :args , :body , :clazz
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
# Local assignment really only differs in where the variable is actually stored,
|
# Local assignment really only differs in where the variable is actually stored,
|
||||||
# slot_position defines that
|
# slot_position defines that
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
class MacroExpression < CallStatement
|
class MacroExpression < CallStatement
|
||||||
|
|
@ -1,14 +1,14 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class MethodExpression < Expression
|
class MethodExpression < Expression
|
||||||
attr_reader :name, :args , :body
|
attr_reader :name, :args , :body
|
||||||
|
|
||||||
def initialize( name , args , body )
|
def initialize( name , args , body )
|
||||||
@name , @args , @body = name , args , body
|
@name , @args , @body = name , args , body
|
||||||
raise "no bod" unless @body
|
raise "no bod" unless @body
|
||||||
raise "Not Vool #{@body}" unless @body.is_a?(Statement)
|
raise "Not Sol #{@body}" unless @body.is_a?(Statement)
|
||||||
end
|
end
|
||||||
|
|
||||||
# create the parfait VoolMethod to hold the code for this method
|
# create the parfait SolMethod to hold the code for this method
|
||||||
#
|
#
|
||||||
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
||||||
def to_parfait( clazz = nil )
|
def to_parfait( clazz = nil )
|
||||||
@ -17,9 +17,9 @@ module Vool
|
|||||||
#FIXME , should check arg_type, and if the same, clear method and ok
|
#FIXME , should check arg_type, and if the same, clear method and ok
|
||||||
raise "Redefining #{clazz.name}.#{name} not supported #{method}"
|
raise "Redefining #{clazz.name}.#{name} not supported #{method}"
|
||||||
end
|
end
|
||||||
vool_m = clazz.create_instance_method_for(name , make_arg_type , make_frame , body )
|
sol_m = clazz.create_instance_method_for(name , make_arg_type , make_frame , body )
|
||||||
vool_m.create_callable_method_for(clazz.instance_type)
|
sol_m.create_callable_method_for(clazz.instance_type)
|
||||||
vool_m
|
sol_m
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates the SlotMachine::MethodCompiler that will do the next step
|
# Creates the SlotMachine::MethodCompiler that will do the next step
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class ReturnStatement < Statement
|
class ReturnStatement < Statement
|
||||||
|
|
||||||
attr_reader :return_value
|
attr_reader :return_value
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
# Sending in a dynamic language is off course not as simple as just calling.
|
# Sending in a dynamic language is off course not as simple as just calling.
|
||||||
# The function that needs to be called depends after all on the receiver,
|
# The function that needs to be called depends after all on the receiver,
|
||||||
# and no guarantees can be made on what that is.
|
# and no guarantees can be made on what that is.
|
||||||
@ -37,8 +37,8 @@ module Vool
|
|||||||
#
|
#
|
||||||
# A slight complication occurs for methods defined in superclasses. Since we are
|
# A slight complication occurs for methods defined in superclasses. Since we are
|
||||||
# type, not class, based, these are not part of our type.
|
# type, not class, based, these are not part of our type.
|
||||||
# So we check, and if find, add the source (vool_method) to the class and start
|
# So we check, and if find, add the source (sol_method) to the class and start
|
||||||
# compiling the vool for the receiver_type
|
# compiling the sol for the receiver_type
|
||||||
#
|
#
|
||||||
def to_slot( compiler )
|
def to_slot( compiler )
|
||||||
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
||||||
@ -53,14 +53,14 @@ module Vool
|
|||||||
|
|
||||||
# If a method is found in the class (not the type)
|
# If a method is found in the class (not the type)
|
||||||
# we add it to the class that the receiver type represents, and create a compiler
|
# we add it to the class that the receiver type represents, and create a compiler
|
||||||
# to compile the vool for the specific type (the receiver)
|
# to compile the sol for the specific type (the receiver)
|
||||||
def create_method_from_source(compiler)
|
def create_method_from_source(compiler)
|
||||||
vool_method = @receiver.ct_type.object_class.resolve_method!(@name)
|
sol_method = @receiver.ct_type.object_class.resolve_method!(@name)
|
||||||
return nil unless vool_method
|
return nil unless sol_method
|
||||||
#puts "#{vool_method.name} , adding to #{@receiver.ct_type.object_class.name}"
|
#puts "#{sol_method.name} , adding to #{@receiver.ct_type.object_class.name}"
|
||||||
@receiver.ct_type.object_class.add_instance_method(vool_method)
|
@receiver.ct_type.object_class.add_instance_method(sol_method)
|
||||||
vool_method.create_callable_method_for(@receiver.ct_type)
|
sol_method.create_callable_method_for(@receiver.ct_type)
|
||||||
new_compiler = vool_method.compiler_for(@receiver.ct_type)
|
new_compiler = sol_method.compiler_for(@receiver.ct_type)
|
||||||
compiler.add_method_compiler(new_compiler)
|
compiler.add_method_compiler(new_compiler)
|
||||||
new_compiler.callable
|
new_compiler.callable
|
||||||
end
|
end
|
@ -1,17 +1,16 @@
|
|||||||
# Virtual
|
|
||||||
# Object Oriented
|
|
||||||
# Language
|
|
||||||
#
|
#
|
||||||
# VOOL is the abstraction of ruby: ruby minus the fluff
|
# SOL -- Simple Object Language
|
||||||
|
#
|
||||||
|
# SOL is the abstraction of ruby: ruby minus the fluff
|
||||||
# fluff is generally what makes ruby nice to use, like 3 ways to achieve the same thing
|
# fluff is generally what makes ruby nice to use, like 3 ways to achieve the same thing
|
||||||
# if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles,
|
# if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles,
|
||||||
# implicit blocks, splats and multiple assigns etc
|
# implicit blocks, splats and multiple assigns etc
|
||||||
#
|
#
|
||||||
# Vool has expression and statements, revealing that age old dichotomy of code and
|
# Sol has expression and statements, revealing that age old dichotomy of code and
|
||||||
# data. Statements represent code whereas Expressions resolve to data.
|
# data. Statements represent code whereas Expressions resolve to data.
|
||||||
# (in ruby there are no pure statements, everthing resolves to data)
|
# (in ruby there are no pure statements, everthing resolves to data)
|
||||||
#
|
#
|
||||||
# Vool resolves to SlotMachine in the next step down. But it also the place where we create
|
# Sol resolves to SlotMachine in the next step down. But it also the place where we create
|
||||||
# Parfait representations for the main oo players, ie classes and methods.
|
# Parfait representations for the main oo players, ie classes and methods.
|
||||||
# The protocol is thus two stage:
|
# The protocol is thus two stage:
|
||||||
# - first to_parfait with implicit side-effects of creating parfait objects that
|
# - first to_parfait with implicit side-effects of creating parfait objects that
|
||||||
@ -19,13 +18,13 @@
|
|||||||
# - second to_slot , which will return a slot version of the statement. This may be code
|
# - second to_slot , which will return a slot version of the statement. This may be code
|
||||||
# or a compiler (for methods), or compiler collection (for classes)
|
# or a compiler (for methods), or compiler collection (for classes)
|
||||||
#
|
#
|
||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
# Base class for all statements in the tree. Derived classes correspond to known language
|
# Base class for all statements in the tree. Derived classes correspond to known language
|
||||||
# constructs
|
# constructs
|
||||||
#
|
#
|
||||||
# Basically Statements represent code, generally speaking code "does things".
|
# Basically Statements represent code, generally speaking code "does things".
|
||||||
# But Vool distinguishes Expressions (see below), that represent data, and as such
|
# But Sol distinguishes Expressions (see below), that represent data, and as such
|
||||||
# don't do things themselves, rather passively participate in being pushed around
|
# don't do things themselves, rather passively participate in being pushed around
|
||||||
class Statement
|
class Statement
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class Statements < Statement
|
class Statements < Statement
|
||||||
attr_reader :statements
|
attr_reader :statements
|
||||||
def initialize(statements)
|
def initialize(statements)
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
class SuperStatement < SendStatement
|
class SuperStatement < SendStatement
|
||||||
|
|
||||||
end
|
end
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
module Named
|
module Named
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
def initialize name
|
def initialize name
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class WhileStatement < Statement
|
class WhileStatement < Statement
|
||||||
attr_reader :condition , :body , :hoisted
|
attr_reader :condition , :body , :hoisted
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Vool
|
module Sol
|
||||||
|
|
||||||
# A Yield is a lot like a Send, which is why they share the base class CallStatement
|
# A Yield is a lot like a Send, which is why they share the base class CallStatement
|
||||||
# That means it has a receiver (self), arguments and an (implicitly assigned) name
|
# That means it has a receiver (self), arguments and an (implicitly assigned) name
|
@ -1,13 +1,13 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestVoolMethod < MiniTest::Test
|
class TestSolMethod < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") )
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") )
|
||||||
@clazz = ruby_tree.to_vool
|
@clazz = ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
def method
|
def method
|
||||||
@clazz.body.first
|
@clazz.body.first
|
||||||
@ -22,7 +22,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
clazz = @clazz.to_parfait
|
clazz = @clazz.to_parfait
|
||||||
assert_equal Parfait::VoolMethod , clazz.get_instance_method(:main).class
|
assert_equal Parfait::SolMethod , clazz.get_instance_method(:main).class
|
||||||
end
|
end
|
||||||
def test_type_method
|
def test_type_method
|
||||||
clazz = @clazz.to_parfait
|
clazz = @clazz.to_parfait
|
@ -7,7 +7,7 @@ module Parfait
|
|||||||
[:Behaviour ,:BinaryCode,:Block,:CacheEntry,:Callable,:CallableMethod,:Class,
|
[:Behaviour ,:BinaryCode,:Block,:CacheEntry,:Callable,:CallableMethod,:Class,
|
||||||
:DataObject,:Data4,:Data8,:Data16,:Data32,:Dictionary,:Factory, :Integer,:FalseClass,
|
:DataObject,:Data4,:Data8,:Data16,:Data32,:Dictionary,:Factory, :Integer,:FalseClass,
|
||||||
:List,:Message, :SingletonClass,:NilClass,:Object,:ReturnAddress,
|
:List,:Message, :SingletonClass,:NilClass,:Object,:ReturnAddress,
|
||||||
:Space,:TrueClass,:Type,:VoolMethod,:Word]
|
:Space,:TrueClass,:Type,:SolMethod,:Word]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_space_length
|
def test_space_length
|
||||||
|
@ -12,9 +12,9 @@ module Ruby
|
|||||||
def compile_main(input)
|
def compile_main(input)
|
||||||
RubyCompiler.compile(as_main(input))
|
RubyCompiler.compile(as_main(input))
|
||||||
end
|
end
|
||||||
def compile_main_vool(input)
|
def compile_main_sol(input)
|
||||||
xcompiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
xcompiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
||||||
xcompiler.ruby_to_vool(as_main(input))
|
xcompiler.ruby_to_sol(as_main(input))
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_raises_muted &block
|
def assert_raises_muted &block
|
||||||
@ -28,25 +28,25 @@ module Ruby
|
|||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@vool = compile( "class Tryout < Base; #{attr_def};end" ).to_vool
|
@sol = compile( "class Tryout < Base; #{attr_def};end" ).to_sol
|
||||||
end
|
end
|
||||||
def getter
|
def getter
|
||||||
@vool.body.statements.first
|
@sol.body.statements.first
|
||||||
end
|
end
|
||||||
def setter
|
def setter
|
||||||
@vool.body.statements.last
|
@sol.body.statements.last
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::ClassExpression , @vool.class
|
assert_equal Sol::ClassExpression , @sol.class
|
||||||
end
|
end
|
||||||
def test_body
|
def test_body
|
||||||
assert_equal Vool::Statements , @vool.body.class
|
assert_equal Sol::Statements , @sol.body.class
|
||||||
end
|
end
|
||||||
def test_getter
|
def test_getter
|
||||||
assert_equal Vool::MethodExpression , getter.class
|
assert_equal Sol::MethodExpression , getter.class
|
||||||
end
|
end
|
||||||
def test_getter_return
|
def test_getter_return
|
||||||
assert_equal Vool::ReturnStatement , getter.body.class
|
assert_equal Sol::ReturnStatement , getter.body.class
|
||||||
end
|
end
|
||||||
def test_getter_name
|
def test_getter_name
|
||||||
assert_equal :page , getter.name
|
assert_equal :page , getter.name
|
||||||
|
@ -25,46 +25,46 @@ module Ruby
|
|||||||
assert_equal IvarAssignment , lst.class
|
assert_equal IvarAssignment , lst.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestAssignmentVoolLocal < MiniTest::Test
|
class TestAssignmentSolLocal < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "foo = bar").to_vool
|
@lst = compile( "foo = bar").to_sol
|
||||||
end
|
end
|
||||||
def test_tos
|
def test_tos
|
||||||
assert_equal "foo = self.bar()" , @lst.to_s
|
assert_equal "foo = self.bar()" , @lst.to_s
|
||||||
end
|
end
|
||||||
def test_local
|
def test_local
|
||||||
assert_equal Vool::LocalAssignment , @lst.class
|
assert_equal Sol::LocalAssignment , @lst.class
|
||||||
end
|
end
|
||||||
def test_bar
|
def test_bar
|
||||||
assert_equal Vool::SendStatement , @lst.value.class
|
assert_equal Sol::SendStatement , @lst.value.class
|
||||||
end
|
end
|
||||||
def test_local_name
|
def test_local_name
|
||||||
assert_equal :foo , @lst.name
|
assert_equal :foo , @lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestAssignmentVoolInst < MiniTest::Test
|
class TestAssignmentSolInst < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "@foo = bar").to_vool
|
@lst = compile( "@foo = bar").to_sol
|
||||||
end
|
end
|
||||||
def test_tos
|
def test_tos
|
||||||
assert_equal "@foo = self.bar()" , @lst.to_s
|
assert_equal "@foo = self.bar()" , @lst.to_s
|
||||||
end
|
end
|
||||||
def test_instance
|
def test_instance
|
||||||
assert_equal Vool::IvarAssignment , @lst.class
|
assert_equal Sol::IvarAssignment , @lst.class
|
||||||
end
|
end
|
||||||
def test_instance_name
|
def test_instance_name
|
||||||
assert_equal :foo , @lst.name
|
assert_equal :foo , @lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestAssignmentVoolConst < MiniTest::Test
|
class TestAssignmentSolConst < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "foo = 5").to_vool
|
@lst = compile( "foo = 5").to_sol
|
||||||
end
|
end
|
||||||
def test_const
|
def test_const
|
||||||
assert_equal Vool::IntegerConstant , @lst.value.class
|
assert_equal Sol::IntegerConstant , @lst.value.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Ruby
|
module Ruby
|
||||||
class TestVoolCallMulti2 < MiniTest::Test
|
class TestSolCallMulti2 < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "@foo = a.call(b)").to_vool
|
@lst = compile( "@foo = a.call(b)").to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
end
|
end
|
||||||
def test_first_class
|
def test_first_class
|
||||||
assert_equal Vool::LocalAssignment , @lst[0].class
|
assert_equal Sol::LocalAssignment , @lst[0].class
|
||||||
end
|
end
|
||||||
def test_first_name
|
def test_first_name
|
||||||
assert @lst[0].name.to_s.start_with?("tmp_")
|
assert @lst[0].name.to_s.start_with?("tmp_")
|
||||||
end
|
end
|
||||||
def test_second_class
|
def test_second_class
|
||||||
assert_equal Vool::LocalAssignment , @lst[1].class
|
assert_equal Sol::LocalAssignment , @lst[1].class
|
||||||
end
|
end
|
||||||
def test_second_name
|
def test_second_name
|
||||||
assert @lst[1].name.to_s.start_with?("tmp_")
|
assert @lst[1].name.to_s.start_with?("tmp_")
|
||||||
end
|
end
|
||||||
def test_last_class
|
def test_last_class
|
||||||
assert_equal Vool::IvarAssignment , @lst[2].class
|
assert_equal Sol::IvarAssignment , @lst[2].class
|
||||||
end
|
end
|
||||||
def test_second_name
|
def test_second_name
|
||||||
assert_equal :foo, @lst[2].name
|
assert_equal :foo, @lst[2].name
|
||||||
|
@ -79,7 +79,7 @@ module Ruby
|
|||||||
assert_equal TrueConstant , compile_const( "true")
|
assert_equal TrueConstant , compile_const( "true")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBasicTypesVool < MiniTest::Test
|
class TestBasicTypesSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -87,7 +87,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
def compile_const( input )
|
def compile_const( input )
|
||||||
lst = compile( input )
|
lst = compile( input )
|
||||||
lst.to_vool.to_s
|
lst.to_sol.to_s
|
||||||
end
|
end
|
||||||
def test_integer
|
def test_integer
|
||||||
assert_equal "123" , compile_const( "123")
|
assert_equal "123" , compile_const( "123")
|
||||||
|
@ -40,35 +40,35 @@ module Ruby
|
|||||||
|
|
||||||
def setup()
|
def setup()
|
||||||
input = "def self.tryout(arg1, arg2) ; a = arg1 ; end "
|
input = "def self.tryout(arg1, arg2) ; a = arg1 ; end "
|
||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal Vool::ClassMethodExpression , @lst.class
|
assert_equal Sol::ClassMethodExpression , @lst.class
|
||||||
end
|
end
|
||||||
def test_method_args
|
def test_method_args
|
||||||
assert_equal [:arg1, :arg2] , @lst.args
|
assert_equal [:arg1, :arg2] , @lst.args
|
||||||
end
|
end
|
||||||
def test_body_is_scope_zero_statement
|
def test_body_is_scope_zero_statement
|
||||||
assert_equal Vool::Statements , @lst.body.class
|
assert_equal Sol::Statements , @lst.body.class
|
||||||
end
|
end
|
||||||
def test_body_is_scope_zero_statement
|
def test_body_is_scope_zero_statement
|
||||||
assert_equal Vool::LocalAssignment , @lst.body.first.class
|
assert_equal Sol::LocalAssignment , @lst.body.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestClassMethodStatementImplicitReturn < MiniTest::Test
|
class TestClassMethodStatementImplicitReturn < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup()
|
def setup()
|
||||||
input = "def self.tryout(arg1, arg2) ; arg1 ; end "
|
input = "def self.tryout(arg1, arg2) ; arg1 ; end "
|
||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal Vool::ClassMethodExpression , @lst.class
|
assert_equal Sol::ClassMethodExpression , @lst.class
|
||||||
end
|
end
|
||||||
def test_method_args
|
def test_method_args
|
||||||
assert_equal [:arg1, :arg2] , @lst.args
|
assert_equal [:arg1, :arg2] , @lst.args
|
||||||
end
|
end
|
||||||
def test_body_is_scope_zero_statement
|
def test_body_is_scope_zero_statement
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.class
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestClassMethodStatement < MiniTest::Test
|
class TestClassMethodStatement < MiniTest::Test
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Ruby
|
module Ruby
|
||||||
class TestClassStatementVool < MiniTest::Test
|
class TestClassStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
input = "class Tryout < Base;def meth; a = 5 ;end; end"
|
input = "class Tryout < Base;def meth; a = 5 ;end; end"
|
||||||
@vool = compile( input ).to_vool
|
@sol = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::ClassExpression , @vool.class
|
assert_equal Sol::ClassExpression , @sol.class
|
||||||
end
|
end
|
||||||
def test_body
|
def test_body
|
||||||
assert_equal Vool::Statements , @vool.body.class
|
assert_equal Sol::Statements , @sol.body.class
|
||||||
end
|
end
|
||||||
def test_compile_class_name
|
def test_compile_class_name
|
||||||
assert_equal :Tryout , @vool.name
|
assert_equal :Tryout , @sol.name
|
||||||
end
|
end
|
||||||
def test_compile_class_super
|
def test_compile_class_super
|
||||||
assert_equal :Base , @vool.super_class_name
|
assert_equal :Base , @sol.super_class_name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -63,15 +63,15 @@ module Ruby
|
|||||||
|
|
||||||
def test_if
|
def test_if
|
||||||
input = "class Tryout < Base; false if(true) ; end"
|
input = "class Tryout < Base; false if(true) ; end"
|
||||||
assert_raises_muted { compile( input ).to_vool}
|
assert_raises_muted { compile( input ).to_sol}
|
||||||
end
|
end
|
||||||
def test_instance
|
def test_instance
|
||||||
input = "class Tryout < Base; @var = 5 ; end"
|
input = "class Tryout < Base; @var = 5 ; end"
|
||||||
assert_raises_muted { compile( input ).to_vool}
|
assert_raises_muted { compile( input ).to_sol}
|
||||||
end
|
end
|
||||||
def test_wrong_send
|
def test_wrong_send
|
||||||
input = "class Tryout < Base; hi() ; end"
|
input = "class Tryout < Base; hi() ; end"
|
||||||
assert_raises_muted { compile( input ).to_vool}
|
assert_raises_muted { compile( input ).to_sol}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,18 +9,18 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_method_len
|
def test_method_len
|
||||||
assert_equal 2 , @vool.body.length , "setter, getter"
|
assert_equal 2 , @sol.body.length , "setter, getter"
|
||||||
end
|
end
|
||||||
def test_setter
|
def test_setter
|
||||||
assert_equal Vool::MethodExpression , setter.class
|
assert_equal Sol::MethodExpression , setter.class
|
||||||
end
|
end
|
||||||
def test_setter_assign
|
def test_setter_assign
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Sol::Statements , setter.body.class
|
||||||
assert_equal Vool::IvarAssignment , setter.body.first.class
|
assert_equal Sol::IvarAssignment , setter.body.first.class
|
||||||
end
|
end
|
||||||
def test_setter_return
|
def test_setter_return
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Sol::Statements , setter.body.class
|
||||||
assert_equal Vool::ReturnStatement , setter.body.last.class
|
assert_equal Sol::ReturnStatement , setter.body.last.class
|
||||||
end
|
end
|
||||||
def test_setter_name
|
def test_setter_name
|
||||||
assert_equal :page= , setter.name
|
assert_equal :page= , setter.name
|
||||||
@ -36,7 +36,7 @@ module Ruby
|
|||||||
"attr_reader :page"
|
"attr_reader :page"
|
||||||
end
|
end
|
||||||
def test_method_len
|
def test_method_len
|
||||||
assert_equal 1 , @vool.body.length , "setter, getter"
|
assert_equal 1 , @sol.body.length , "setter, getter"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,18 +8,18 @@ module Ruby
|
|||||||
"attr :page , :size"
|
"attr :page , :size"
|
||||||
end
|
end
|
||||||
def test_method_len
|
def test_method_len
|
||||||
assert_equal 4 , @vool.body.length , "2 setters, 2 getters"
|
assert_equal 4 , @sol.body.length , "2 setters, 2 getters"
|
||||||
end
|
end
|
||||||
def test_setter
|
def test_setter
|
||||||
assert_equal Vool::MethodExpression , setter.class
|
assert_equal Sol::MethodExpression , setter.class
|
||||||
end
|
end
|
||||||
def test_setter_assign
|
def test_setter_assign
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Sol::Statements , setter.body.class
|
||||||
assert_equal Vool::IvarAssignment , setter.body.first.class
|
assert_equal Sol::IvarAssignment , setter.body.first.class
|
||||||
end
|
end
|
||||||
def test_setter_return
|
def test_setter_return
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Sol::Statements , setter.body.class
|
||||||
assert_equal Vool::ReturnStatement , setter.body.last.class
|
assert_equal Sol::ReturnStatement , setter.body.last.class
|
||||||
end
|
end
|
||||||
def test_setter_name
|
def test_setter_name
|
||||||
assert_equal :size= , setter.name
|
assert_equal :size= , setter.name
|
||||||
|
@ -1,51 +1,51 @@
|
|||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
module Ruby
|
module Ruby
|
||||||
class TestIfStatementVool < MiniTest::Test
|
class TestIfStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@lst = compile("if(true) ; a = 1 ; else ; a = 2 ; end").to_vool
|
@lst = compile("if(true) ; a = 1 ; else ; a = 2 ; end").to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::IfStatement , @lst.class
|
assert_equal Sol::IfStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_true
|
def test_true
|
||||||
assert_equal Vool::LocalAssignment , @lst.if_true.class
|
assert_equal Sol::LocalAssignment , @lst.if_true.class
|
||||||
assert @lst.has_true?
|
assert @lst.has_true?
|
||||||
end
|
end
|
||||||
def test_false
|
def test_false
|
||||||
assert_equal Vool::LocalAssignment , @lst.if_false.class
|
assert_equal Sol::LocalAssignment , @lst.if_false.class
|
||||||
assert @lst.has_false?
|
assert @lst.has_false?
|
||||||
end
|
end
|
||||||
def test_condition
|
def test_condition
|
||||||
assert_equal Vool::TrueConstant , @lst.condition.class
|
assert_equal Sol::TrueConstant , @lst.condition.class
|
||||||
end
|
end
|
||||||
def test_to_s
|
def test_to_s
|
||||||
assert_tos "if (true);a = 1;else;a = 2;end" , @lst
|
assert_tos "if (true);a = 1;else;a = 2;end" , @lst
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestIfStatementVoolHoisted < MiniTest::Test
|
class TestIfStatementSolHoisted < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@lst = compile("if(foo() == 1) ; a = 1 ; end").to_vool
|
@lst = compile("if(foo() == 1) ; a = 1 ; end").to_sol
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
end
|
end
|
||||||
def test_first_class
|
def test_first_class
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
end
|
end
|
||||||
def test_last_class
|
def test_last_class
|
||||||
assert_equal Vool::IfStatement , @lst.last.class
|
assert_equal Sol::IfStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
def test_true
|
def test_true
|
||||||
assert_equal Vool::LocalAssignment , @lst.last.if_true.class
|
assert_equal Sol::LocalAssignment , @lst.last.if_true.class
|
||||||
end
|
end
|
||||||
def test_condition
|
def test_condition
|
||||||
assert_equal Vool::SendStatement , @lst.last.condition.class
|
assert_equal Sol::SendStatement , @lst.last.condition.class
|
||||||
assert_equal :== , @lst.last.condition.name
|
assert_equal :== , @lst.last.condition.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,13 +25,13 @@ module Ruby
|
|||||||
class TestPlusEquals < Minitest::Test
|
class TestPlusEquals < Minitest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "X.plus_equals(1)").to_vool
|
@lst = compile( "X.plus_equals(1)").to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::MacroExpression , @lst.class
|
assert_equal Sol::MacroExpression , @lst.class
|
||||||
end
|
end
|
||||||
def test_arg1
|
def test_arg1
|
||||||
assert_equal Vool::IntegerConstant , @lst.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.arguments.first.class
|
||||||
end
|
end
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal :plus_equals , @lst.name
|
assert_equal :plus_equals , @lst.name
|
||||||
@ -40,22 +40,22 @@ module Ruby
|
|||||||
class TestPlusEqualsX < Minitest::Test
|
class TestPlusEqualsX < Minitest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile_main( "X.plus_equals(arg,1)").to_vool
|
@lst = compile_main( "X.plus_equals(arg,1)").to_sol
|
||||||
end
|
end
|
||||||
def method_body
|
def method_body
|
||||||
@lst.body.first.body
|
@lst.body.first.body
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::ClassExpression , @lst.class
|
assert_equal Sol::ClassExpression , @lst.class
|
||||||
assert_equal Vool::MethodExpression , @lst.body.first.class
|
assert_equal Sol::MethodExpression , @lst.body.first.class
|
||||||
end
|
end
|
||||||
def test_macro_class
|
def test_macro_class
|
||||||
assert_equal Vool::ReturnStatement , method_body.class
|
assert_equal Sol::ReturnStatement , method_body.class
|
||||||
assert_equal Vool::MacroExpression , method_body.return_value.class
|
assert_equal Sol::MacroExpression , method_body.return_value.class
|
||||||
end
|
end
|
||||||
def test_args
|
def test_args
|
||||||
assert_equal Vool::LocalVariable , method_body.return_value.arguments.first.class
|
assert_equal Sol::LocalVariable , method_body.return_value.arguments.first.class
|
||||||
assert_equal Vool::IntegerConstant , method_body.return_value.arguments.last.class
|
assert_equal Sol::IntegerConstant , method_body.return_value.arguments.last.class
|
||||||
end
|
end
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal :plus_equals , method_body.return_value.name
|
assert_equal :plus_equals , method_body.return_value.name
|
||||||
|
@ -7,47 +7,47 @@ module Ruby
|
|||||||
class TestMethodStatementRet < MiniTest::Test
|
class TestMethodStatementRet < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def test_single_const
|
def test_single_const
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; true ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; true ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.class
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
||||||
end
|
end
|
||||||
def test_single_instance
|
def test_single_instance
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; @a ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; @a ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.class
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
||||||
end
|
end
|
||||||
def test_single_call
|
def test_single_call
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.class
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multi_const
|
def test_multi_const
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); true ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); true ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.last.class
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
||||||
end
|
end
|
||||||
def test_multi_instance
|
def test_multi_instance
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); @a ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); @a ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.last.class
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
||||||
end
|
end
|
||||||
def test_multi_call
|
def test_multi_call
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; some_call() ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; some_call() ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.last.class
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return
|
def test_return
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; return 1 ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; return 1 ; end " ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.class
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
||||||
assert_equal Vool::IntegerConstant , @lst.body.return_value.class
|
assert_equal Sol::IntegerConstant , @lst.body.return_value.class
|
||||||
end
|
end
|
||||||
def test_local_assign
|
def test_local_assign
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; a = 1 ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; a = 1 ; end " ).to_sol
|
||||||
assert_equal Vool::Statements , @lst.body.class
|
assert_equal Sol::Statements , @lst.body.class
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.last.class
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
||||||
assert_equal Vool::LocalVariable , @lst.body.last.return_value.class
|
assert_equal Sol::LocalVariable , @lst.body.last.return_value.class
|
||||||
end
|
end
|
||||||
def test_local_assign
|
def test_local_assign
|
||||||
@lst = compile( "def tryout(arg1, arg2) ; @a = 1 ; end " ).to_vool
|
@lst = compile( "def tryout(arg1, arg2) ; @a = 1 ; end " ).to_sol
|
||||||
assert_equal Vool::Statements , @lst.body.class
|
assert_equal Sol::Statements , @lst.body.class
|
||||||
assert_equal Vool::ReturnStatement , @lst.body.last.class
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
||||||
assert_equal Vool::InstanceVariable , @lst.body.last.return_value.class
|
assert_equal Sol::InstanceVariable , @lst.body.last.return_value.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,30 +4,30 @@ module Ruby
|
|||||||
class TestSendRequireHelper < MiniTest::Test
|
class TestSendRequireHelper < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "require_relative 'helper'").to_vool
|
@lst = compile( "require_relative 'helper'").to_sol
|
||||||
end
|
end
|
||||||
def test_helper_class
|
def test_helper_class
|
||||||
assert_equal Vool::ClassExpression , @lst.class
|
assert_equal Sol::ClassExpression , @lst.class
|
||||||
assert_equal :ParfaitTest , @lst.name
|
assert_equal :ParfaitTest , @lst.name
|
||||||
end
|
end
|
||||||
def test_methods
|
def test_methods
|
||||||
assert_equal Vool::Statements , @lst.body.class
|
assert_equal Sol::Statements , @lst.body.class
|
||||||
assert_equal Vool::MethodExpression , @lst.body.first.class
|
assert_equal Sol::MethodExpression , @lst.body.first.class
|
||||||
assert_equal :setup , @lst.body.first.name
|
assert_equal :setup , @lst.body.first.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendRequireparfait < MiniTest::Test
|
class TestSendRequireparfait < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "require_relative 'object'").to_vool
|
@lst = compile( "require_relative 'object'").to_sol
|
||||||
end
|
end
|
||||||
def test_helper_class
|
def test_helper_class
|
||||||
assert_equal Vool::ClassExpression , @lst.class
|
assert_equal Sol::ClassExpression , @lst.class
|
||||||
assert_equal :Object , @lst.name
|
assert_equal :Object , @lst.name
|
||||||
end
|
end
|
||||||
def test_methods
|
def test_methods
|
||||||
assert_equal Vool::Statements , @lst.body.class
|
assert_equal Sol::Statements , @lst.body.class
|
||||||
assert_equal Vool::MethodExpression , @lst.body.first.class
|
assert_equal Sol::MethodExpression , @lst.body.first.class
|
||||||
assert_equal :type , @lst.body.first.name
|
assert_equal :type , @lst.body.first.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,30 +21,30 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
class TestReturnStatementVool < MiniTest::Test
|
class TestReturnStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def test_return_const
|
def test_return_const
|
||||||
lst = compile( "return 1" ).to_vool
|
lst = compile( "return 1" ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , lst.class
|
assert_equal Sol::ReturnStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_return_value
|
def test_return_value
|
||||||
lst = compile( "return 1" ).to_vool
|
lst = compile( "return 1" ).to_sol
|
||||||
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 = compile( "return foo" ).to_vool
|
lst = compile( "return foo" ).to_sol
|
||||||
assert_equal Vool::ReturnStatement , lst.class
|
assert_equal Sol::ReturnStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_return_send3
|
def test_return_send3
|
||||||
lst = compile( "return foo.bar.zoo" ).to_vool
|
lst = compile( "return foo.bar.zoo" ).to_sol
|
||||||
assert_equal Vool::LocalAssignment , lst.first.class
|
assert_equal Sol::LocalAssignment , lst.first.class
|
||||||
assert lst.first.name.to_s.start_with?("tmp_")
|
assert lst.first.name.to_s.start_with?("tmp_")
|
||||||
end
|
end
|
||||||
def test_return_send4
|
def test_return_send4
|
||||||
lst = compile( "return foo.bar.zoo" ).to_vool
|
lst = compile( "return foo.bar.zoo" ).to_sol
|
||||||
assert_equal Vool::ReturnStatement, lst[2].class
|
assert_equal Sol::ReturnStatement, lst[2].class
|
||||||
assert_equal :zoo, lst[2].return_value.name
|
assert_equal :zoo, lst[2].return_value.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,22 +25,22 @@ module Ruby
|
|||||||
assert_equal 1 , @lst.body.arguments.length
|
assert_equal 1 , @lst.body.arguments.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBlockStatementVool < MiniTest::Test
|
class TestBlockStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup()
|
def setup()
|
||||||
input = "plus_one{|arg1| arg1 + 1 } "
|
input = "plus_one{|arg1| arg1 + 1 } "
|
||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_block
|
def test_block
|
||||||
assert_equal Vool::SendStatement , @lst.class
|
assert_equal Sol::SendStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_send_name
|
def test_send_name
|
||||||
assert_equal :plus_one , @lst.name
|
assert_equal :plus_one , @lst.name
|
||||||
end
|
end
|
||||||
def test_send_block_arg
|
def test_send_block_arg
|
||||||
assert_equal 1 , @lst.arguments.length
|
assert_equal 1 , @lst.arguments.length
|
||||||
assert_equal Vool::LambdaExpression , @lst.arguments.first.class
|
assert_equal Sol::LambdaExpression , @lst.arguments.first.class
|
||||||
end
|
end
|
||||||
def test_block_args
|
def test_block_args
|
||||||
assert_equal [:arg1] , @lst.arguments.first.args
|
assert_equal [:arg1] , @lst.arguments.first.args
|
||||||
|
@ -24,28 +24,28 @@ module Ruby
|
|||||||
assert_equal ReturnStatement , @lst.last.class
|
assert_equal ReturnStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBlockReturnVool < MiniTest::Test
|
class TestBlockReturnSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup()
|
def setup()
|
||||||
input = "a = plus_one{return 1 } ; return a "
|
input = "a = plus_one{return 1 } ; return a "
|
||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_scope
|
def test_scope
|
||||||
assert_equal Vool::ScopeStatement , @lst.class
|
assert_equal Sol::ScopeStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_assign
|
def test_assign
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
assert_equal :a , @lst.first.name
|
assert_equal :a , @lst.first.name
|
||||||
end
|
end
|
||||||
def test_send
|
def test_send
|
||||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
assert_equal Sol::SendStatement , @lst.first.value.class
|
||||||
assert_equal :plus_one , @lst.first.value.name
|
assert_equal :plus_one , @lst.first.value.name
|
||||||
end
|
end
|
||||||
def test_block_arg
|
def test_block_arg
|
||||||
assert_equal Vool::LambdaExpression , @lst.first.value.arguments.first.class
|
assert_equal Sol::LambdaExpression , @lst.first.value.arguments.first.class
|
||||||
end
|
end
|
||||||
def test_ret
|
def test_ret
|
||||||
assert_equal Vool::ReturnStatement , @lst[1].class
|
assert_equal Sol::ReturnStatement , @lst[1].class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,69 +1,69 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Ruby
|
module Ruby
|
||||||
class TestSendNoArgVool < MiniTest::Test
|
class TestSendNoArgSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "foo").to_vool
|
@lst = compile( "foo").to_sol
|
||||||
end
|
end
|
||||||
def test_simple_class
|
def test_simple_class
|
||||||
assert_equal Vool::SendStatement , @lst.class
|
assert_equal Sol::SendStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_simple_name
|
def test_simple_name
|
||||||
assert_equal :foo , @lst.name
|
assert_equal :foo , @lst.name
|
||||||
end
|
end
|
||||||
def test_simple_receiver
|
def test_simple_receiver
|
||||||
assert_equal Vool::SelfExpression , @lst.receiver.class
|
assert_equal Sol::SelfExpression , @lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_simple_args
|
def test_simple_args
|
||||||
assert_equal [] , @lst.arguments
|
assert_equal [] , @lst.arguments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendSimpleArgVool < MiniTest::Test
|
class TestSendSimpleArgSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "bar(1)").to_vool
|
@lst = compile( "bar(1)").to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::SendStatement , @lst.class
|
assert_equal Sol::SendStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal :bar , @lst.name
|
assert_equal :bar , @lst.name
|
||||||
end
|
end
|
||||||
def test_receiver
|
def test_receiver
|
||||||
assert_equal Vool::SelfExpression , @lst.receiver.class
|
assert_equal Sol::SelfExpression , @lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_args
|
def test_args
|
||||||
assert_equal Vool::IntegerConstant , @lst.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.arguments.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendSuperVool < MiniTest::Test
|
class TestSendSuperSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def test_super0
|
def test_super0
|
||||||
lst = compile( "super").to_vool
|
lst = compile( "super").to_sol
|
||||||
assert_equal Vool::SuperStatement , lst.class
|
assert_equal Sol::SuperStatement , lst.class
|
||||||
end
|
end
|
||||||
def test_super0_receiver
|
def test_super0_receiver
|
||||||
lst = compile( "super").to_vool
|
lst = compile( "super").to_sol
|
||||||
assert_equal Vool::SelfExpression , lst.receiver.class
|
assert_equal Sol::SelfExpression , lst.receiver.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendSuperArgsVool < MiniTest::Test
|
class TestSendSuperArgsSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "super(1)").to_vool
|
@lst = compile( "super(1)").to_sol
|
||||||
end
|
end
|
||||||
def test_super_class
|
def test_super_class
|
||||||
assert_equal Vool::SuperStatement , @lst.class
|
assert_equal Sol::SuperStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_super_receiver
|
def test_super_receiver
|
||||||
assert_equal Vool::SelfExpression , @lst.receiver.class
|
assert_equal Sol::SelfExpression , @lst.receiver.class
|
||||||
end
|
end
|
||||||
def test_super_name
|
def test_super_name
|
||||||
assert_equal :super, @lst.name
|
assert_equal :super, @lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendReceiverTypeVool < MiniTest::Test
|
class TestSendReceiverTypeSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -71,12 +71,12 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_int_receiver
|
def test_int_receiver
|
||||||
sent = compile( "5.div4").to_vool
|
sent = compile( "5.div4").to_sol
|
||||||
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 = compile( "'5'.putstring").to_vool
|
sent = compile( "'5'.putstring").to_sol
|
||||||
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
|
||||||
@ -84,13 +84,13 @@ module Ruby
|
|||||||
class TestSendReceiver < MiniTest::Test
|
class TestSendReceiver < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "call.once.more").to_vool
|
@lst = compile( "call.once.more").to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
end
|
end
|
||||||
def test_one
|
def test_one
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
end
|
end
|
||||||
def test_one_name
|
def test_one_name
|
||||||
assert @lst[0].name.to_s.start_with?("tmp_")
|
assert @lst[0].name.to_s.start_with?("tmp_")
|
||||||
@ -105,7 +105,7 @@ module Ruby
|
|||||||
assert_equal :once , @lst[1].value.name
|
assert_equal :once , @lst[1].value.name
|
||||||
end
|
end
|
||||||
def test_three_class
|
def test_three_class
|
||||||
assert_equal Vool::SendStatement, @lst[2].class
|
assert_equal Sol::SendStatement, @lst[2].class
|
||||||
end
|
end
|
||||||
def test_three_name
|
def test_three_name
|
||||||
assert_equal :more , @lst[2].name
|
assert_equal :more , @lst[2].name
|
||||||
|
@ -4,67 +4,67 @@ module Ruby
|
|||||||
module LastBar
|
module LastBar
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def test_last_class
|
def test_last_class
|
||||||
assert_equal Vool::SendStatement , @lst.last.class
|
assert_equal Sol::SendStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
def test_last_name
|
def test_last_name
|
||||||
assert_equal :last , @lst.last.name
|
assert_equal :last , @lst.last.name
|
||||||
end
|
end
|
||||||
def test_last_arg
|
def test_last_arg
|
||||||
assert_equal Vool::LocalVariable , @lst.last.arguments.first.class
|
assert_equal Sol::LocalVariable , @lst.last.arguments.first.class
|
||||||
end
|
end
|
||||||
def test_lst_class
|
def test_lst_class
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
end
|
end
|
||||||
def test_lst_no_statements
|
def test_lst_no_statements
|
||||||
@lst.statements.each{|st| assert( ! st.is_a?(Vool::Statements) , st.class)}
|
@lst.statements.each{|st| assert( ! st.is_a?(Sol::Statements) , st.class)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestSendSendArgVool < MiniTest::Test
|
class TestSendSendArgSol < MiniTest::Test
|
||||||
include LastBar
|
include LastBar
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "last(foo(1))").to_vool
|
@lst = compile( "last(foo(1))").to_sol
|
||||||
end
|
end
|
||||||
def test_classes
|
def test_classes
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
assert_equal Vool::SendStatement , @lst.last.class
|
assert_equal Sol::SendStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
def test_foo1
|
def test_foo1
|
||||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
assert_equal Sol::SendStatement , @lst.first.value.class
|
||||||
assert_equal :foo , @lst.first.value.name
|
assert_equal :foo , @lst.first.value.name
|
||||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.first.value.arguments.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Test3SendVool < MiniTest::Test
|
class Test3SendSol < MiniTest::Test
|
||||||
include LastBar
|
include LastBar
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "last(foo(more(1)))").to_vool
|
@lst = compile( "last(foo(more(1)))").to_sol
|
||||||
end
|
end
|
||||||
def test_classes
|
def test_classes
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
assert_equal Vool::SendStatement , @lst.last.class
|
assert_equal Sol::SendStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
def test_foo
|
def test_foo
|
||||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
assert_equal Sol::SendStatement , @lst.first.value.class
|
||||||
assert_equal :more , @lst.first.value.name
|
assert_equal :more , @lst.first.value.name
|
||||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.first.value.arguments.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Test5SendVool < MiniTest::Test
|
class Test5SendSol < MiniTest::Test
|
||||||
include LastBar
|
include LastBar
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "last(foo(more(even_more(1),and_more(with_more))))").to_vool
|
@lst = compile( "last(foo(more(even_more(1),and_more(with_more))))").to_sol
|
||||||
end
|
end
|
||||||
def test_classes
|
def test_classes
|
||||||
assert_equal Vool::Statements , @lst.class
|
assert_equal Sol::Statements , @lst.class
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
||||||
assert_equal Vool::SendStatement , @lst.last.class
|
assert_equal Sol::SendStatement , @lst.last.class
|
||||||
end
|
end
|
||||||
def test_foo
|
def test_foo
|
||||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
assert_equal Sol::SendStatement , @lst.first.value.class
|
||||||
assert_equal :even_more , @lst.first.value.name
|
assert_equal :even_more , @lst.first.value.name
|
||||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.first.value.arguments.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,15 +8,15 @@ module Ruby
|
|||||||
assert_equal "Statement" , Statement.new.class_name
|
assert_equal "Statement" , Statement.new.class_name
|
||||||
end
|
end
|
||||||
def test_brother
|
def test_brother
|
||||||
assert_equal Vool::Statement , Statement.new.vool_brother
|
assert_equal Sol::Statement , Statement.new.sol_brother
|
||||||
end
|
end
|
||||||
def test_yield
|
def test_yield
|
||||||
lst = compile( "yield")
|
lst = compile( "yield")
|
||||||
assert_equal Vool::YieldStatement , lst.vool_brother
|
assert_equal Sol::YieldStatement , lst.sol_brother
|
||||||
end
|
end
|
||||||
def test_assign
|
def test_assign
|
||||||
lst = compile( "a = 4")
|
lst = compile( "a = 4")
|
||||||
assert_equal Vool::LocalAssignment , lst.vool_brother
|
assert_equal Sol::LocalAssignment , lst.sol_brother
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -52,38 +52,38 @@ module Ruby
|
|||||||
assert_equal :Module , lst.name
|
assert_equal :Module , lst.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestVariablesVool < MiniTest::Test
|
class TestVariablesSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def test_local_basic
|
def test_local_basic
|
||||||
lst = compile( "foo = 1 ; return foo").to_vool
|
lst = compile( "foo = 1 ; return foo").to_sol
|
||||||
assert_equal Vool::LocalVariable , lst.statements[1].return_value.class
|
assert_equal Sol::LocalVariable , lst.statements[1].return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_basic
|
def test_instance_basic
|
||||||
lst = compile( "@var" ).to_vool
|
lst = compile( "@var" ).to_sol
|
||||||
assert_equal Vool::InstanceVariable , lst.class
|
assert_equal Sol::InstanceVariable , lst.class
|
||||||
assert_equal :var , lst.name
|
assert_equal :var , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_return
|
def test_instance_return
|
||||||
lst = compile( "return @var" ).to_vool
|
lst = compile( "return @var" ).to_sol
|
||||||
assert_equal Vool::InstanceVariable , lst.return_value.class
|
assert_equal Sol::InstanceVariable , lst.return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_basic
|
def test_class_basic
|
||||||
lst = compile( "@@var" ).to_vool
|
lst = compile( "@@var" ).to_sol
|
||||||
assert_equal Vool::ClassVariable , lst.class
|
assert_equal Sol::ClassVariable , lst.class
|
||||||
assert_equal :var , lst.name
|
assert_equal :var , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_return
|
def test_class_return
|
||||||
lst = compile( "return @@var" ).to_vool
|
lst = compile( "return @@var" ).to_sol
|
||||||
assert_equal Vool::ClassVariable , lst.return_value.class
|
assert_equal Sol::ClassVariable , lst.return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_module_basic
|
def test_module_basic
|
||||||
lst = compile( "Module" ).to_vool
|
lst = compile( "Module" ).to_sol
|
||||||
assert_equal Vool::ModuleName , lst.class
|
assert_equal Sol::ModuleName , lst.class
|
||||||
assert_equal :Module , lst.name
|
assert_equal :Module , lst.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
module Ruby
|
module Ruby
|
||||||
class TestWhileStatementVool < MiniTest::Test
|
class TestWhileStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "while(@arg) ; @arg = 1 ; end" ).to_vool
|
@lst = compile( "while(@arg) ; @arg = 1 ; end" ).to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::WhileStatement , @lst.class
|
assert_equal Sol::WhileStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_body_class
|
def test_body_class
|
||||||
assert_equal Vool::IvarAssignment , @lst.body.class
|
assert_equal Sol::IvarAssignment , @lst.body.class
|
||||||
end
|
end
|
||||||
def test_condition_class
|
def test_condition_class
|
||||||
assert_equal Vool::InstanceVariable , @lst.condition.class
|
assert_equal Sol::InstanceVariable , @lst.condition.class
|
||||||
end
|
end
|
||||||
def test_no_hoist
|
def test_no_hoist
|
||||||
assert_nil @lst.hoisted
|
assert_nil @lst.hoisted
|
||||||
@ -22,20 +22,20 @@ module Ruby
|
|||||||
class TestWhileStatementHoist < MiniTest::Test
|
class TestWhileStatementHoist < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def setup
|
def setup
|
||||||
@lst = compile( "while(call(arg > 1)) ; arg = 1 ; end" ).to_vool
|
@lst = compile( "while(call(arg > 1)) ; arg = 1 ; end" ).to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::WhileStatement , @lst.class
|
assert_equal Sol::WhileStatement , @lst.class
|
||||||
assert_equal Vool::LocalAssignment , @lst.body.class
|
assert_equal Sol::LocalAssignment , @lst.body.class
|
||||||
end
|
end
|
||||||
def test_condition_class
|
def test_condition_class
|
||||||
assert_equal Vool::SendStatement , @lst.condition.class
|
assert_equal Sol::SendStatement , @lst.condition.class
|
||||||
end
|
end
|
||||||
def test_hoist
|
def test_hoist
|
||||||
assert_equal Vool::Statements , @lst.hoisted.class
|
assert_equal Sol::Statements , @lst.hoisted.class
|
||||||
end
|
end
|
||||||
def test_hoist_is_assi
|
def test_hoist_is_assi
|
||||||
assert_equal Vool::LocalAssignment , @lst.hoisted.first.class
|
assert_equal Sol::LocalAssignment , @lst.hoisted.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,18 +18,18 @@ module Ruby
|
|||||||
assert_equal "yield(0)" , @lst.to_s
|
assert_equal "yield(0)" , @lst.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestYieldStatementVool < MiniTest::Test
|
class TestYieldStatementSol < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def setup()
|
def setup()
|
||||||
input = "yield(0)"
|
input = "yield(0)"
|
||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_sol
|
||||||
end
|
end
|
||||||
def test_block
|
def test_block
|
||||||
assert_equal Vool::YieldStatement , @lst.class
|
assert_equal Sol::YieldStatement , @lst.class
|
||||||
end
|
end
|
||||||
def test_block_args
|
def test_block_args
|
||||||
assert_equal Vool::IntegerConstant , @lst.arguments.first.class
|
assert_equal Sol::IntegerConstant , @lst.arguments.first.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,18 +5,18 @@ module RubyX
|
|||||||
module RubyXHelper
|
module RubyXHelper
|
||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
def ruby_to_vool(input, options = {})
|
def ruby_to_sol(input, options = {})
|
||||||
options = RubyX.default_test_options.merge(options)
|
options = RubyX.default_test_options.merge(options)
|
||||||
RubyXCompiler.new(options).ruby_to_vool(input)
|
RubyXCompiler.new(options).ruby_to_sol(input)
|
||||||
end
|
end
|
||||||
def ruby_to_slot(input , options = {})
|
def ruby_to_slot(input , options = {})
|
||||||
options = RubyX.default_test_options.merge(options)
|
options = RubyX.default_test_options.merge(options)
|
||||||
RubyXCompiler.new(options).ruby_to_slot(input)
|
RubyXCompiler.new(options).ruby_to_slot(input)
|
||||||
end
|
end
|
||||||
def compile_in_test( input , options = {})
|
def compile_in_test( input , options = {})
|
||||||
vool = ruby_to_vool(in_Test(input) , options)
|
sol = ruby_to_sol(in_Test(input) , options)
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
vool.to_slot(nil)
|
sol.to_slot(nil)
|
||||||
itest = Parfait.object_space.get_class_by_name(:Test)
|
itest = Parfait.object_space.get_class_by_name(:Test)
|
||||||
assert itest
|
assert itest
|
||||||
itest
|
itest
|
||||||
|
@ -8,10 +8,10 @@ Since we need Parfait in the runtime, we need to parse it and compile it.
|
|||||||
And since it is early days, we expect errors at every level during this process, which
|
And since it is early days, we expect errors at every level during this process, which
|
||||||
means testing every layer for every file.
|
means testing every layer for every file.
|
||||||
|
|
||||||
Rather than create parfait tests for every layer (ie in the vool/slot_machine/risc directories)
|
Rather than create parfait tests for every layer (ie in the sol/slot_machine/risc directories)
|
||||||
we have one file per parfait file here. Each file tests all layers.
|
we have one file per parfait file here. Each file tests all layers.
|
||||||
|
|
||||||
The usual workflow is to start with a new file and create tests for vool, slot_machine, risc,binary
|
The usual workflow is to start with a new file and create tests for sol, slot_machine, risc,binary
|
||||||
in that order. Possibly fixing the compiler on the way. Then adding the file to
|
in that order. Possibly fixing the compiler on the way. Then adding the file to
|
||||||
the RubyXCompiler parfait load list.
|
the RubyXCompiler parfait load list.
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ module RubyX
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compiler
|
@compiler = compiler
|
||||||
@compiler.ruby_to_vool load_parfait(:object)
|
@compiler.ruby_to_sol load_parfait(:object)
|
||||||
end
|
end
|
||||||
def source
|
def source
|
||||||
load_parfait(:data_object)
|
load_parfait(:data_object)
|
||||||
@ -17,15 +17,15 @@ module RubyX
|
|||||||
assert source.include?("class DataObject")
|
assert source.include?("class DataObject")
|
||||||
assert source.length > 1500 , source.length
|
assert source.length > 1500 , source.length
|
||||||
end
|
end
|
||||||
def test_vool
|
def test_sol
|
||||||
vool = @compiler.ruby_to_vool source
|
sol = @compiler.ruby_to_sol source
|
||||||
assert_equal Vool::ScopeStatement , vool.class
|
assert_equal Sol::ScopeStatement , sol.class
|
||||||
assert_equal Vool::ClassExpression , vool[0].class
|
assert_equal Sol::ClassExpression , sol[0].class
|
||||||
assert_equal Vool::ClassExpression , vool[1].class
|
assert_equal Sol::ClassExpression , sol[1].class
|
||||||
assert_equal Vool::ClassExpression , vool[2].class
|
assert_equal Sol::ClassExpression , sol[2].class
|
||||||
assert_equal :DataObject , vool[1].name
|
assert_equal :DataObject , sol[1].name
|
||||||
assert_equal :Data4 , vool[2].name
|
assert_equal :Data4 , sol[2].name
|
||||||
assert_equal :Data8 , vool[3].name
|
assert_equal :Data8 , sol[3].name
|
||||||
end
|
end
|
||||||
def test_slot
|
def test_slot
|
||||||
slot = @compiler.ruby_to_slot source
|
slot = @compiler.ruby_to_slot source
|
||||||
|
@ -5,8 +5,8 @@ module RubyX
|
|||||||
include ParfaitHelper
|
include ParfaitHelper
|
||||||
def setup
|
def setup
|
||||||
@compiler = compiler
|
@compiler = compiler
|
||||||
@compiler.ruby_to_vool load_parfait(:object)
|
@compiler.ruby_to_sol load_parfait(:object)
|
||||||
@compiler.ruby_to_vool load_parfait(:data_object)
|
@compiler.ruby_to_sol load_parfait(:data_object)
|
||||||
end
|
end
|
||||||
def source
|
def source
|
||||||
get_preload("Space.main") + load_parfait(:integer)
|
get_preload("Space.main") + load_parfait(:integer)
|
||||||
@ -15,21 +15,21 @@ module RubyX
|
|||||||
assert source.include?("class Integer")
|
assert source.include?("class Integer")
|
||||||
assert source.length > 1500 , source.length
|
assert source.length > 1500 , source.length
|
||||||
end
|
end
|
||||||
def test_vool
|
def test_sol
|
||||||
vool = @compiler.ruby_to_vool source
|
sol = @compiler.ruby_to_sol source
|
||||||
assert_equal Vool::ScopeStatement , vool.class
|
assert_equal Sol::ScopeStatement , sol.class
|
||||||
assert_equal Vool::ClassExpression , vool[0].class
|
assert_equal Sol::ClassExpression , sol[0].class
|
||||||
assert_equal Vool::ClassExpression , vool[1].class
|
assert_equal Sol::ClassExpression , sol[1].class
|
||||||
assert_equal Vool::ClassExpression , vool[2].class
|
assert_equal Sol::ClassExpression , sol[2].class
|
||||||
assert_equal :DataObject , vool[1].name
|
assert_equal :DataObject , sol[1].name
|
||||||
assert_equal :Data4 , vool[2].name
|
assert_equal :Data4 , sol[2].name
|
||||||
assert_equal :Data8 , vool[3].name
|
assert_equal :Data8 , sol[3].name
|
||||||
end
|
end
|
||||||
def test_slot
|
def test_slot
|
||||||
vool = @compiler.ruby_to_vool source
|
sol = @compiler.ruby_to_sol source
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
#puts vool
|
#puts sol
|
||||||
slot = vool.to_slot(nil)
|
slot = sol.to_slot(nil)
|
||||||
assert_equal SlotMachine::SlotCollection , slot.class
|
assert_equal SlotMachine::SlotCollection , slot.class
|
||||||
end
|
end
|
||||||
def est_risc
|
def est_risc
|
||||||
|
@ -13,10 +13,10 @@ module RubyX
|
|||||||
assert source.include?("class Object")
|
assert source.include?("class Object")
|
||||||
assert source.length > 2000
|
assert source.length > 2000
|
||||||
end
|
end
|
||||||
def test_vool
|
def test_sol
|
||||||
vool = compiler.ruby_to_vool source
|
sol = compiler.ruby_to_sol source
|
||||||
assert_equal Vool::ClassExpression , vool.class
|
assert_equal Sol::ClassExpression , sol.class
|
||||||
assert_equal :Object , vool.name
|
assert_equal :Object , sol.name
|
||||||
end
|
end
|
||||||
def test_slot
|
def test_slot
|
||||||
slot = compiler.ruby_to_slot source
|
slot = compiler.ruby_to_slot source
|
||||||
|
@ -25,26 +25,26 @@ module RubyX
|
|||||||
assert_equal Ruby::ClassStatement , compiled[2].class
|
assert_equal Ruby::ClassStatement , compiled[2].class
|
||||||
assert_equal :TestObject , compiled[2].name
|
assert_equal :TestObject , compiled[2].name
|
||||||
end
|
end
|
||||||
def test_vool_object
|
def test_sol_object
|
||||||
vool = Ruby::RubyCompiler.compile(@input).to_vool
|
sol = Ruby::RubyCompiler.compile(@input).to_sol
|
||||||
assert_equal Vool::ScopeStatement , vool.class
|
assert_equal Sol::ScopeStatement , sol.class
|
||||||
assert_equal Vool::ClassExpression , vool.first.class
|
assert_equal Sol::ClassExpression , sol.first.class
|
||||||
end
|
end
|
||||||
def test_vool_helper
|
def test_sol_helper
|
||||||
vool = Ruby::RubyCompiler.compile(@input).to_vool
|
sol = Ruby::RubyCompiler.compile(@input).to_sol
|
||||||
assert_equal Vool::ClassExpression , vool[1].class
|
assert_equal Sol::ClassExpression , sol[1].class
|
||||||
assert_equal :ParfaitTest , vool[1].name
|
assert_equal :ParfaitTest , sol[1].name
|
||||||
end
|
end
|
||||||
def test_vool_test
|
def test_sol_test
|
||||||
vool = Ruby::RubyCompiler.compile(@input).to_vool
|
sol = Ruby::RubyCompiler.compile(@input).to_sol
|
||||||
assert_equal Vool::ClassExpression , vool[2].class
|
assert_equal Sol::ClassExpression , sol[2].class
|
||||||
assert_equal :TestObject , vool[2].name
|
assert_equal :TestObject , sol[2].name
|
||||||
end
|
end
|
||||||
def test_vool_methods
|
def test_sol_methods
|
||||||
vool = Ruby::RubyCompiler.compile(@input).to_vool
|
sol = Ruby::RubyCompiler.compile(@input).to_sol
|
||||||
assert_equal Vool::Statements , vool[2].body.class
|
assert_equal Sol::Statements , sol[2].body.class
|
||||||
vool[2].body.statements.each do |st|
|
sol[2].body.statements.each do |st|
|
||||||
assert_equal Vool::MethodExpression , st.class
|
assert_equal Sol::MethodExpression , st.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -54,15 +54,15 @@ module RubyX
|
|||||||
|
|
||||||
def self.runnable_methods
|
def self.runnable_methods
|
||||||
input = load_parfait(:object) + load_parfait_test(:object)
|
input = load_parfait(:object) + load_parfait_test(:object)
|
||||||
vool = Ruby::RubyCompiler.compile(input).to_vool
|
sol = Ruby::RubyCompiler.compile(input).to_sol
|
||||||
tests = [ ]
|
tests = [ ]
|
||||||
vool[2].body.statements.each do |method|
|
sol[2].body.statements.each do |method|
|
||||||
tests << method.name
|
tests << method.name
|
||||||
self.send(:define_method, method.name ) do
|
self.send(:define_method, method.name ) do
|
||||||
code = input + <<MAIN
|
code = input + <<MAIN
|
||||||
class Space
|
class Space
|
||||||
def main(args)
|
def main(args)
|
||||||
test = #{vool[2].name}.new
|
test = #{sol[2].name}.new
|
||||||
test.setup
|
test.setup
|
||||||
test.#{method.name}
|
test.#{method.name}
|
||||||
end
|
end
|
||||||
|
@ -16,15 +16,15 @@ module RubyX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_body_is_scope
|
def test_class_body_is_scope
|
||||||
clazz = ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = ruby_to_sol in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal Vool::Statements , clazz.body.class
|
assert_equal Sol::Statements , clazz.body.class
|
||||||
assert_equal Vool::MethodExpression , clazz.body.first.class
|
assert_equal Sol::MethodExpression , clazz.body.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_space_is_unchanged_by_compile
|
def test_space_is_unchanged_by_compile
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
space1 = Parfait.object_space.get_class_by_name(:Space)
|
space1 = Parfait.object_space.get_class_by_name(:Space)
|
||||||
compiler.ruby_to_vool "class Space ;end"
|
compiler.ruby_to_sol "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
|
||||||
@ -32,7 +32,7 @@ module RubyX
|
|||||||
def test_space_type_is_unchanged_by_compile
|
def test_space_type_is_unchanged_by_compile
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||||
compiler.ruby_to_vool "class Space ;end"
|
compiler.ruby_to_sol "class Space ;end"
|
||||||
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||||
assert_equal space1 , space2
|
assert_equal space1 , space2
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ module RubyX
|
|||||||
def test_space_type_is_unchanged_by_compile
|
def test_space_type_is_unchanged_by_compile
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||||
compiler.ruby_to_vool "class Space ;end"
|
compiler.ruby_to_sol "class Space ;end"
|
||||||
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||||
assert_equal space1 , space2
|
assert_equal space1 , space2
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ module RubyX
|
|||||||
|
|
||||||
def test_load
|
def test_load
|
||||||
object = Parfait.object_space.get_class_by_name(:Object)
|
object = Parfait.object_space.get_class_by_name(:Object)
|
||||||
assert_equal Parfait::VoolMethod , object.get_instance_method(:set_type).class
|
assert_equal Parfait::SolMethod , object.get_instance_method(:set_type).class
|
||||||
assert_equal Parfait::CallableMethod , object.instance_type.get_method(:set_type).class
|
assert_equal Parfait::CallableMethod , object.instance_type.get_method(:set_type).class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,23 +17,23 @@ module RubyX
|
|||||||
@linker = RubyXCompiler.ruby_to_binary(space_source_for("main"), RubyX.interpreter_test_options)
|
@linker = RubyXCompiler.ruby_to_binary(space_source_for("main"), RubyX.interpreter_test_options)
|
||||||
assert_equal Risc::Linker , @linker.class
|
assert_equal Risc::Linker , @linker.class
|
||||||
end
|
end
|
||||||
def test_one_vool_call
|
def test_one_sol_call
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
compiler.ruby_to_vool(space_source_for("main"))
|
compiler.ruby_to_sol(space_source_for("main"))
|
||||||
assert_equal Vool::ClassExpression , compiler.vool.class
|
assert_equal Sol::ClassExpression , compiler.sol.class
|
||||||
end
|
end
|
||||||
def test_two_vool_calls
|
def test_two_sol_calls
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
compiler.ruby_to_vool(space_source_for("main"))
|
compiler.ruby_to_sol(space_source_for("main"))
|
||||||
compiler.ruby_to_vool(space_source_for("twain"))
|
compiler.ruby_to_sol(space_source_for("twain"))
|
||||||
assert_equal Vool::ScopeStatement , compiler.vool.class
|
assert_equal Sol::ScopeStatement , compiler.sol.class
|
||||||
assert_equal 2 , compiler.vool.length
|
assert_equal 2 , compiler.sol.length
|
||||||
end
|
end
|
||||||
def test_bin_two_sources
|
def test_bin_two_sources
|
||||||
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
compiler = RubyXCompiler.new(RubyX.default_test_options)
|
||||||
compiler.ruby_to_vool(space_source_for("main"))
|
compiler.ruby_to_sol(space_source_for("main"))
|
||||||
compiler.ruby_to_vool(space_source_for("twain"))
|
compiler.ruby_to_sol(space_source_for("twain"))
|
||||||
assert_equal 2 , compiler.vool.length
|
assert_equal 2 , compiler.sol.length
|
||||||
linker = compiler.to_binary(:interpreter)
|
linker = compiler.to_binary(:interpreter)
|
||||||
assert_equal Risc::Linker , linker.class
|
assert_equal Risc::Linker , linker.class
|
||||||
assert_equal 4 , linker.assemblers.length
|
assert_equal 4 , linker.assemblers.length
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestBlockArg < MiniTest::Test
|
class TestBlockArg < MiniTest::Test
|
||||||
include SlotMachineCompile
|
include SlotMachineCompile
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassStatementSlotMachine < MiniTest::Test
|
class TestClassStatementSlotMachine < MiniTest::Test
|
||||||
include SlotMachineCompile
|
include SlotMachineCompile
|
||||||
|
|
||||||
|
@ -7,21 +7,21 @@ module SlotMachine
|
|||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_test_vool(str)
|
def in_test_sol(str)
|
||||||
vool = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(in_Test(str))
|
sol = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_sol(in_Test(str))
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
vool.to_slot(nil)
|
sol.to_slot(nil)
|
||||||
vool
|
sol
|
||||||
end
|
end
|
||||||
def create_method(body = "@ivar = 5;return")
|
def create_method(body = "@ivar = 5;return")
|
||||||
in_test_vool("def meth; #{body};end")
|
in_test_sol("def meth; #{body};end")
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
test.get_instance_method(:meth)
|
test.get_instance_method(:meth)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_has_source
|
def test_method_has_source
|
||||||
method = create_method
|
method = create_method
|
||||||
assert_equal Vool::Statements , method.source.class
|
assert_equal Sol::Statements , method.source.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_has_no_locals
|
def test_method_has_no_locals
|
||||||
@ -37,24 +37,24 @@ module SlotMachine
|
|||||||
def test_creates_method_in_class
|
def test_creates_method_in_class
|
||||||
method = create_method
|
method = create_method
|
||||||
assert method , "No method created"
|
assert method , "No method created"
|
||||||
assert_equal Parfait::VoolMethod , method.class
|
assert_equal Parfait::SolMethod , method.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_method_statement_in_class
|
def test_creates_method_statement_in_class
|
||||||
clazz = in_test_vool("def meth; @ivar = 5 ;return;end")
|
clazz = in_test_sol("def meth; @ivar = 5 ;return;end")
|
||||||
assert_equal Vool::Statements , clazz.body.class
|
assert_equal Sol::Statements , clazz.body.class
|
||||||
assert_equal Vool::MethodExpression , clazz.body.first.class
|
assert_equal Sol::MethodExpression , clazz.body.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_callable_method_instance_type
|
def test_callable_method_instance_type
|
||||||
in_test_vool("def meth; @ivar = 5; @ibar = 4;return;end")
|
in_test_sol("def meth; @ivar = 5; @ibar = 4;return;end")
|
||||||
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)
|
||||||
assert_equal 1, method.self_type.variable_index(:ivar)
|
assert_equal 1, method.self_type.variable_index(:ivar)
|
||||||
assert_equal 2, method.self_type.variable_index(:ibar)
|
assert_equal 2, method.self_type.variable_index(:ibar)
|
||||||
end
|
end
|
||||||
def test_callable_method_has_one_local
|
def test_callable_method_has_one_local
|
||||||
in_test_vool("def meth; local = 5 ; a = 6;return;end")
|
in_test_sol("def meth; local = 5 ; a = 6;return;end")
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
method = test.get_instance_method(:meth)
|
method = test.get_instance_method(:meth)
|
||||||
assert_equal 3 , method.frame_type.instance_length
|
assert_equal 3 , method.frame_type.instance_length
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassDef < MiniTest::Test
|
class TestClassDef < MiniTest::Test
|
||||||
include SlotMachine
|
include SlotMachine
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
@ -1,9 +1,9 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassInstance < MiniTest::Test
|
class TestClassInstance < MiniTest::Test
|
||||||
include SlotMachine
|
include SlotMachine
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
@ -1,9 +1,9 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassSendInherited < MiniTest::Test
|
class TestClassSendInherited < MiniTest::Test
|
||||||
include SlotMachine
|
include SlotMachine
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendClassSlotMachine < MiniTest::Test
|
class TestSendClassSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module VoolBlocks
|
module SolBlocks
|
||||||
class TestAssignSlotMachine < MiniTest::Test
|
class TestAssignSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "local = 5" )
|
@ins = compile_main_block( "local = 5" )
|
||||||
@ -28,7 +28,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
|
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "local = @a" , "@a = 5") #second arg in method scope
|
@ins = compile_main_block( "local = @a" , "@a = 5") #second arg in method scope
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignToArg < MiniTest::Test
|
class TestAssignToArg < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "arg = 5")
|
@ins = compile_main_block( "arg = 5")
|
||||||
@ -62,7 +62,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignSlotMachineToInstance < MiniTest::Test
|
class TestAssignSlotMachineToInstance < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
def test_assigns_const
|
def test_assigns_const
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module VoolBlocks
|
module SolBlocks
|
||||||
class TestClassAssignSlotMachine < MiniTest::Test
|
class TestClassAssignSlotMachine < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -11,18 +11,18 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
def test_block_not_compiles
|
def test_block_not_compiles
|
||||||
source = "main{|val| val = 0}"
|
source = "main{|val| val = 0}"
|
||||||
vool = Ruby::RubyCompiler.compile( as_class_method(source) ).to_vool
|
sol = Ruby::RubyCompiler.compile( as_class_method(source) ).to_sol
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
begin
|
begin
|
||||||
vool.to_slot(nil)
|
sol.to_slot(nil)
|
||||||
rescue => err
|
rescue => err
|
||||||
assert err.message.include?("Blocks") , err.message
|
assert err.message.include?("Blocks") , err.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_assign_compiles
|
def test_assign_compiles
|
||||||
vool = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_vool
|
sol = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_sol
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
assert_equal SlotMachine::SlotCollection , vool.to_slot(nil).class
|
assert_equal SlotMachine::SlotCollection , sol.to_slot(nil).class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module VoolBlocks
|
module SolBlocks
|
||||||
class TestConditionIfSlotMachine < MiniTest::Test
|
class TestConditionIfSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end" , "local=5", "Integer.div4")
|
@ins = compile_main_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end" , "local=5", "Integer.div4")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module VoolBlocks
|
module SolBlocks
|
||||||
class TestSimpleWhileSlotMachine < MiniTest::Test
|
class TestSimpleWhileSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "while(@a) ; @a = 5 ; end")
|
@ins = compile_main_block( "while(@a) ; @a = 5 ; end")
|
@ -1,9 +1,9 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
# relies on @ins and receiver_type method
|
# relies on @ins and receiver_type method
|
||||||
module SimpleSendHarness
|
module SimpleSendHarness
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
include SlotMachine
|
include SlotMachine
|
||||||
|
|
||||||
def setup
|
def setup
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendCachedSimpleSlotMachine < MiniTest::Test
|
class TestSendCachedSimpleSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "5.div8")
|
@compiler = compile_main( "5.div8")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendArgsSendSlotMachine < MiniTest::Test
|
class TestSendArgsSendSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "a = main(4.div4);return a" , "Integer.div4")
|
@compiler = compile_main( "a = main(4.div4);return a" , "Integer.div4")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendCachedSimpleSlotMachine < MiniTest::Test
|
class TestSendCachedSimpleSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "a = 5; a.div4;return ")
|
@compiler = compile_main( "a = 5; a.div4;return ")
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendSelfSlotMachine < MiniTest::Test
|
class TestSendSelfSlotMachine < MiniTest::Test
|
||||||
include SimpleSendHarness
|
include SimpleSendHarness
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendSimpleSlotMachine < MiniTest::Test
|
class TestSendSimpleSlotMachine < MiniTest::Test
|
||||||
include SimpleSendHarness
|
include SimpleSendHarness
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSendSimpleArgsSlotMachine < MiniTest::Test
|
class TestSendSimpleArgsSlotMachine < MiniTest::Test
|
||||||
include SimpleSendHarness
|
include SimpleSendHarness
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestAssignSlotMachine < MiniTest::Test
|
class TestAssignSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "local = 5;return")
|
@compiler = compile_main( "local = 5;return")
|
||||||
@ -31,7 +31,7 @@ module Vool
|
|||||||
|
|
||||||
#otherwise as above, but assigning instance, so should get a SlotLoad
|
#otherwise as above, but assigning instance, so should get a SlotLoad
|
||||||
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
|
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "@a = 5 ; local = @a;return")
|
@compiler = compile_main( "@a = 5 ; local = @a;return")
|
||||||
@ins = @compiler.slot_instructions.next
|
@ins = @compiler.slot_instructions.next
|
||||||
@ -43,7 +43,7 @@ module Vool
|
|||||||
|
|
||||||
#compiling to an argument should result in different second parameter in the slot array
|
#compiling to an argument should result in different second parameter in the slot array
|
||||||
class TestAssignToArg < MiniTest::Test
|
class TestAssignToArg < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "arg = 5;return")
|
@compiler = compile_main( "arg = 5;return")
|
||||||
@ -65,7 +65,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignSlotMachineToInstance < MiniTest::Test
|
class TestAssignSlotMachineToInstance < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
end
|
end
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestBuiltin < MiniTest::Test
|
class TestBuiltin < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ -12,9 +12,9 @@ module Vool
|
|||||||
@ruby = Ruby::RubyCompiler.compile(@code)
|
@ruby = Ruby::RubyCompiler.compile(@code)
|
||||||
end
|
end
|
||||||
def as_slot
|
def as_slot
|
||||||
vool = as_ruby.to_vool
|
sol = as_ruby.to_sol
|
||||||
vool.to_parfait
|
sol.to_parfait
|
||||||
vool.to_slot(nil)
|
sol.to_slot(nil)
|
||||||
end
|
end
|
||||||
def test_boot
|
def test_boot
|
||||||
assert_equal String , @code.class
|
assert_equal String , @code.class
|
||||||
@ -25,16 +25,16 @@ module Vool
|
|||||||
assert_equal Ruby::MethodStatement , @ruby.body.first.class
|
assert_equal Ruby::MethodStatement , @ruby.body.first.class
|
||||||
assert_equal :+ , @ruby.body.first.name
|
assert_equal :+ , @ruby.body.first.name
|
||||||
end
|
end
|
||||||
def test_compile_vool
|
def test_compile_sol
|
||||||
vool = as_ruby.to_vool
|
sol = as_ruby.to_sol
|
||||||
assert_equal Vool::ClassExpression , vool.class
|
assert_equal Sol::ClassExpression , sol.class
|
||||||
assert_equal Vool::MethodExpression , vool.body.first.class
|
assert_equal Sol::MethodExpression , sol.body.first.class
|
||||||
end
|
end
|
||||||
def test_vool_method
|
def test_sol_method
|
||||||
vool = as_ruby.to_vool
|
sol = as_ruby.to_sol
|
||||||
assert_equal :+ , vool.body.first.name
|
assert_equal :+ , sol.body.first.name
|
||||||
assert_equal Vool::ReturnStatement , vool.body.first.body.class
|
assert_equal Sol::ReturnStatement , sol.body.first.body.class
|
||||||
assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class
|
assert_equal Sol::MacroExpression , sol.body.first.body.return_value.class
|
||||||
end
|
end
|
||||||
def test_slot_basic
|
def test_slot_basic
|
||||||
slot = as_slot
|
slot = as_slot
|
@ -1,32 +1,32 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassStatement < MiniTest::Test
|
class TestClassStatement < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
||||||
@vool = ruby_tree.to_vool
|
@sol = ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal ClassExpression , @vool.class
|
assert_equal ClassExpression , @sol.class
|
||||||
assert_equal :Test , @vool.name
|
assert_equal :Test , @sol.name
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal MethodExpression , @vool.body.first.class
|
assert_equal MethodExpression , @sol.body.first.class
|
||||||
end
|
end
|
||||||
def test_create_class
|
def test_create_class
|
||||||
assert_equal Parfait::Class , @vool.create_class_object.class
|
assert_equal Parfait::Class , @sol.create_class_object.class
|
||||||
end
|
end
|
||||||
def test_create_class
|
def test_create_class
|
||||||
assert_equal :Test , @vool.to_parfait.name
|
assert_equal :Test , @sol.to_parfait.name
|
||||||
end
|
end
|
||||||
def test_class_instance
|
def test_class_instance
|
||||||
assert_equal :a , @vool.to_parfait.instance_type.names[1]
|
assert_equal :a , @sol.to_parfait.instance_type.names[1]
|
||||||
end
|
end
|
||||||
def test_to_s
|
def test_to_s
|
||||||
assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @vool
|
assert_tos "class Test < Object;def main(arg);@a = 5;return @a;end;end" , @sol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestClassStatementTypeCreation < MiniTest::Test
|
class TestClassStatementTypeCreation < MiniTest::Test
|
||||||
@ -36,9 +36,9 @@ module Vool
|
|||||||
end
|
end
|
||||||
def check_type_for(input)
|
def check_type_for(input)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
||||||
vool = ruby_tree.to_vool
|
sol = ruby_tree.to_sol
|
||||||
assert_equal ClassExpression , vool.class
|
assert_equal ClassExpression , sol.class
|
||||||
clazz = vool.to_parfait
|
clazz = sol.to_parfait
|
||||||
assert_equal Parfait::Class , clazz.class
|
assert_equal Parfait::Class , clazz.class
|
||||||
assert_equal :a , clazz.instance_type.names[1]
|
assert_equal :a , clazz.instance_type.names[1]
|
||||||
end
|
end
|
||||||
@ -76,8 +76,8 @@ module Vool
|
|||||||
as_test_main("return 1") + ";class Test < Space ; def main();return 1;end;end"
|
as_test_main("return 1") + ";class Test < Space ; def main();return 1;end;end"
|
||||||
end
|
end
|
||||||
def test_mismatch
|
def test_mismatch
|
||||||
vool_tree = Ruby::RubyCompiler.compile( space_test).to_vool
|
sol_tree = Ruby::RubyCompiler.compile( space_test).to_sol
|
||||||
assert_raises {vool_tree.to_parfait}
|
assert_raises {sol_tree.to_parfait}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassStatementCompile < MiniTest::Test
|
class TestClassStatementCompile < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return")
|
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestClassMethodExpression < MiniTest::Test
|
class TestClassMethodExpression < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def class_code
|
def class_code
|
||||||
"class Space;def self.meth; return meth(22 + 22) ; end;end"
|
"class Space;def self.meth; return meth(22 + 22) ; end;end"
|
||||||
@ -10,7 +10,7 @@ module Vool
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( class_code )
|
ruby_tree = Ruby::RubyCompiler.compile( class_code )
|
||||||
@clazz = ruby_tree.to_vool
|
@clazz = ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
def method
|
def method
|
||||||
@clazz.body.first
|
@clazz.body.first
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestIfNoElse < MiniTest::Test
|
class TestIfNoElse < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "if(@a) ; @a = 5 ; end;return")
|
@compiler = compile_main( "if(@a) ; @a = 5 ; end;return")
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestIfNoIf < MiniTest::Test
|
class TestIfNoIf < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "unless(@a) ; @a = 5 ; end;return")
|
@compiler = compile_main( "unless(@a) ; @a = 5 ; end;return")
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSimpleIfSlotMachine < MiniTest::Test
|
class TestSimpleIfSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end;return")
|
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end;return")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestConditionIfSlotMachine < MiniTest::Test
|
class TestConditionIfSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return" , "Integer.div4")
|
@compiler = compile_main( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return" , "Integer.div4")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestIvarSlotMachine < MiniTest::Test
|
class TestIvarSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "@a = 5")
|
@compiler = compile_main( "@a = 5")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestLocalSlotMachine < MiniTest::Test
|
class TestLocalSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "a = 5")
|
@compiler = compile_main( "a = 5")
|
||||||
@ -33,7 +33,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestArgSlotMachine < MiniTest::Test
|
class TestArgSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
@ -13,9 +13,9 @@ module SlotMachine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestMacroSlotMachine < MiniTest::Test
|
class TestMacroSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "X.plus_equals(arg,1)")
|
@compiler = compile_main( "X.plus_equals(arg,1)")
|
||||||
@ -26,11 +26,11 @@ module Vool
|
|||||||
assert_equal SlotMachine::PlusEquals , @ins.class , @ins
|
assert_equal SlotMachine::PlusEquals , @ins.class , @ins
|
||||||
end
|
end
|
||||||
def test_arg1
|
def test_arg1
|
||||||
assert_equal Vool::LocalVariable , @ins.a.class
|
assert_equal Sol::LocalVariable , @ins.a.class
|
||||||
assert_equal :arg , @ins.a.name
|
assert_equal :arg , @ins.a.name
|
||||||
end
|
end
|
||||||
def test_arg2
|
def test_arg2
|
||||||
assert_equal Vool::IntegerConstant , @ins.b.class
|
assert_equal Sol::IntegerConstant , @ins.b.class
|
||||||
assert_equal 1 , @ins.b.value
|
assert_equal 1 , @ins.b.value
|
||||||
end
|
end
|
||||||
def test_to_risc
|
def test_to_risc
|
@ -1,13 +1,13 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestMethodExpression < MiniTest::Test
|
class TestMethodExpression < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") )
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") )
|
||||||
@clazz = ruby_tree.to_vool
|
@clazz = ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
def method
|
def method
|
||||||
@clazz.body.first
|
@clazz.body.first
|
||||||
@ -25,7 +25,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
def test_creates_instance_method
|
def test_creates_instance_method
|
||||||
main = @clazz.to_parfait.get_instance_method(:main)
|
main = @clazz.to_parfait.get_instance_method(:main)
|
||||||
assert_equal Parfait::VoolMethod , main.class
|
assert_equal Parfait::SolMethod , main.class
|
||||||
assert_equal :main , main.name
|
assert_equal :main , main.name
|
||||||
end
|
end
|
||||||
def test_creates_type_method
|
def test_creates_type_method
|
||||||
@ -36,12 +36,12 @@ module Vool
|
|||||||
|
|
||||||
end
|
end
|
||||||
class TestMethodExpressionDoubleDef < MiniTest::Test
|
class TestMethodExpressionDoubleDef < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") + ";" + as_main("a = 5") )
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") + ";" + as_main("a = 5") )
|
||||||
@clazz = ruby_tree.to_vool
|
@clazz = ruby_tree.to_sol
|
||||||
end
|
end
|
||||||
def method
|
def method
|
||||||
@clazz.body.first
|
@clazz.body.first
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestReturnSlotMachine < MiniTest::Test
|
class TestReturnSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "return 5")
|
@compiler = compile_main( "return 5")
|
||||||
@ -38,7 +38,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestReturnSendSlotMachine < MiniTest::Test
|
class TestReturnSendSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "return 5.div4" , "Integer.div4" )
|
@compiler = compile_main( "return 5.div4" , "Integer.div4" )
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestSimpleWhileSlotMachine < MiniTest::Test
|
class TestSimpleWhileSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "while(@a) ; @a = 5 ; end;return")
|
@compiler = compile_main( "while(@a) ; @a = 5 ; end;return")
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestWhileConditionSlotMachine < MiniTest::Test
|
class TestWhileConditionSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "while(5.div4) ; 5.div4 ; end;return" , "Integer.div4")
|
@compiler = compile_main( "while(5.div4) ; 5.div4 ; end;return" , "Integer.div4")
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Sol
|
||||||
class TestYieldArgsSendSlotMachine < MiniTest::Test
|
class TestYieldArgsSendSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "return yield(1)" )
|
@compiler = compile_main( "return yield(1)" )
|
||||||
@ -66,7 +66,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestYieldNoArgsSendSlotMachine < MiniTest::Test
|
class TestYieldNoArgsSendSlotMachine < MiniTest::Test
|
||||||
include VoolCompile
|
include SolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "return yield(some.extra.calls)" )
|
@compiler = compile_main( "return yield(some.extra.calls)" )
|
@ -4,7 +4,7 @@ module ScopeHelper
|
|||||||
|
|
||||||
def compiler_with_main(options = {})
|
def compiler_with_main(options = {})
|
||||||
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options))
|
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options))
|
||||||
compiler.ruby_to_vool( "class Space;def main(arg);return;end;end" )
|
compiler.ruby_to_sol( "class Space;def main(arg);return;end;end" )
|
||||||
compiler
|
compiler
|
||||||
end
|
end
|
||||||
def in_Test(statements)
|
def in_Test(statements)
|
||||||
@ -28,7 +28,7 @@ module ScopeHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
module VoolCompile
|
module SolCompile
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include SlotMachine
|
include SlotMachine
|
||||||
include Preloader
|
include Preloader
|
||||||
|
@ -2,11 +2,11 @@ module Preloader
|
|||||||
def get_preload(preload)
|
def get_preload(preload)
|
||||||
return "" unless preload
|
return "" unless preload
|
||||||
if( preload == "all" )
|
if( preload == "all" )
|
||||||
loading = Vool::Builtin.builtin.keys
|
loading = Sol::Builtin.builtin.keys
|
||||||
else
|
else
|
||||||
loading = preload.split(";")
|
loading = preload.split(";")
|
||||||
end
|
end
|
||||||
loading.collect { |loads| Vool::Builtin.load_builtin(loads)}.join(";") + ";"
|
loading.collect { |loads| Sol::Builtin.load_builtin(loads)}.join(";") + ";"
|
||||||
end
|
end
|
||||||
def preload
|
def preload
|
||||||
get_preload(@preload)
|
get_preload(@preload)
|
||||||
|
Loading…
Reference in New Issue
Block a user