Renaming Vool exppressions rightly
Class, Method and Lambda (was block) are expressions. Just making things clearer, especially for the blocks (ahem, lambdas) is matters. wip
This commit is contained in:
parent
ae16551ed0
commit
f87526f86f
@ -5,13 +5,13 @@ module Mom
|
|||||||
class Constant
|
class Constant
|
||||||
end
|
end
|
||||||
|
|
||||||
class BlockConstant < Constant
|
class LambdaConstant < Constant
|
||||||
attr_reader :block
|
attr_reader :lambda
|
||||||
def initialize(bl)
|
def initialize(bl)
|
||||||
@block = bl
|
@lambda = bl
|
||||||
end
|
end
|
||||||
def to_parfait(compiler)
|
def to_parfait(compiler)
|
||||||
@block
|
@lambda
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,14 +20,12 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
["object" , "factory" ].each do |file_name|
|
["object" , "data_object","integer","factory" ].each do |file_name|
|
||||||
path = File.expand_path( "../parfait/#{file_name}.rb" , __FILE__)
|
path = File.expand_path( "../parfait/#{file_name}.rb" , __FILE__)
|
||||||
module_eval( File.read path)
|
module_eval( File.read path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "parfait/data_object"
|
|
||||||
require_relative "parfait/integer"
|
|
||||||
require_relative "parfait/behaviour"
|
require_relative "parfait/behaviour"
|
||||||
require_relative "parfait/class"
|
require_relative "parfait/class"
|
||||||
require_relative "parfait/meta_class"
|
require_relative "parfait/meta_class"
|
||||||
|
@ -19,11 +19,10 @@
|
|||||||
# DataObjects still have a type, and so can have objects before the data starts
|
# DataObjects still have a type, and so can have objects before the data starts
|
||||||
#
|
#
|
||||||
# A marker class
|
# A marker class
|
||||||
module Parfait
|
|
||||||
class DataObject < Object
|
class DataObject < Object
|
||||||
|
|
||||||
def self.type_length
|
def self.type_length
|
||||||
raise "called #{self}"
|
raise "called " + self.to_s
|
||||||
end
|
end
|
||||||
def padded_length
|
def padded_length
|
||||||
self.class.memory_size * 4
|
self.class.memory_size * 4
|
||||||
@ -53,4 +52,3 @@ module Parfait
|
|||||||
32
|
32
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
module Parfait
|
|
||||||
# Integer class for representing maths on Integers
|
# Integer class for representing maths on Integers
|
||||||
# Integers are Objects, specifically DataObjects
|
# Integers are Objects, specifically DataObjects
|
||||||
# - they have fixed value
|
# - they have fixed value
|
||||||
@ -92,4 +91,3 @@ module Parfait
|
|||||||
1 # 0 type
|
1 # 0 type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -23,7 +23,7 @@ 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" unless source.is_a?(Vool::Statement)
|
raise "source must be vool not#{source.class}" unless source.is_a?(Vool::Statement)
|
||||||
raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?)
|
raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ module Ruby
|
|||||||
class ClassMethodStatement < MethodStatement
|
class ClassMethodStatement < MethodStatement
|
||||||
|
|
||||||
def to_vool
|
def to_vool
|
||||||
Vool::ClassMethodStatement.new( @name , @args.dup , @body.to_vool)
|
Vool::ClassMethodExpression.new( @name , @args.dup , @body.to_vool)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -29,7 +29,7 @@ module Ruby
|
|||||||
meths += transform_statement(meth)
|
meths += transform_statement(meth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Vool::ClassStatement.new(@name , @super_class_name, Vool::Statements.new(meths) )
|
Vool::ClassExpression.new(@name , @super_class_name, Vool::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)
|
||||||
|
@ -14,7 +14,7 @@ module Ruby
|
|||||||
else
|
else
|
||||||
@body = replace_return( @body )
|
@body = replace_return( @body )
|
||||||
end
|
end
|
||||||
Vool::MethodStatement.new( @name , @args.dup , @body.to_vool)
|
Vool::MethodExpression.new( @name , @args.dup , @body.to_vool)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_return(statement)
|
def replace_return(statement)
|
||||||
|
@ -20,7 +20,7 @@ module Ruby
|
|||||||
#
|
#
|
||||||
def to_vool
|
def to_vool
|
||||||
block_name = "implicit_block_#{object_id}".to_sym
|
block_name = "implicit_block_#{object_id}".to_sym
|
||||||
block = Vool::LambdaStatement.new( @args.dup , @body.to_vool)
|
block = Vool::LambdaExpression.new( @args.dup , @body.to_vool)
|
||||||
assign = Vool::LocalAssignment.new( block_name , block)
|
assign = Vool::LocalAssignment.new( block_name , block)
|
||||||
sendd = @send.to_vool
|
sendd = @send.to_vool
|
||||||
if(sendd.is_a?(Vool::Statements))
|
if(sendd.is_a?(Vool::Statements))
|
||||||
|
@ -34,11 +34,12 @@ module Ruby
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
def to_vool
|
def to_vool
|
||||||
if( single? )
|
return first.to_vool if( single? )
|
||||||
first.to_vool
|
brother = vool_brother.new(nil)
|
||||||
else
|
@statements.each do |s|
|
||||||
vool_brother.new(@statements.collect{|s| s.to_vool})
|
brother << s.to_vool
|
||||||
end
|
end
|
||||||
|
brother
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -33,7 +33,7 @@ module Vool
|
|||||||
# Derived classes do not implement to_mom, only slot_position
|
# Derived classes do not implement to_mom, only slot_position
|
||||||
def to_mom(compiler)
|
def to_mom(compiler)
|
||||||
to = Mom::SlotDefinition.new(:message , self.slot_position(compiler))
|
to = Mom::SlotDefinition.new(:message , self.slot_position(compiler))
|
||||||
from = @value.slot_definition(compiler)
|
from = @value.to_slot(compiler)
|
||||||
assign = Mom::SlotLoad.new(self,to,from)
|
assign = Mom::SlotLoad.new(self,to,from)
|
||||||
return assign unless @value.is_a?(CallStatement)
|
return assign unless @value.is_a?(CallStatement)
|
||||||
@value.to_mom(compiler) << assign
|
@value.to_mom(compiler) << assign
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
module Vool
|
module Vool
|
||||||
#Marker class for different constants
|
#Marker class for different constants
|
||||||
class Constant < Expression
|
class Constant < Expression
|
||||||
#gobble it up
|
|
||||||
def each(&block)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# An integer at the vool level
|
# An integer at the vool level
|
||||||
@ -12,17 +9,15 @@ module Vool
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
Parfait.object_space.get_type_by_class_name(:Integer)
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s(depth = 0)
|
||||||
value.to_s
|
value.to_s
|
||||||
end
|
end
|
||||||
def each(&block)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# An float at the vool level
|
# An float at the vool level
|
||||||
class FloatConstant < Constant
|
class FloatConstant < Constant
|
||||||
@ -33,7 +28,7 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s(depth = 0)
|
||||||
value.to_s
|
value.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -42,7 +37,7 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:True)
|
Parfait.object_space.get_type_by_class_name(:True)
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
@ -54,7 +49,7 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:False)
|
Parfait.object_space.get_type_by_class_name(:False)
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
@ -66,7 +61,7 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
Parfait.object_space.get_type_by_class_name(:Nil)
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
@ -80,7 +75,7 @@ module Vool
|
|||||||
def initialize(type = nil)
|
def initialize(type = nil)
|
||||||
@my_type = type
|
@my_type = type
|
||||||
end
|
end
|
||||||
def slot_definition(compiler)
|
def to_slot(compiler)
|
||||||
@my_type = compiler.receiver_type
|
@my_type = compiler.receiver_type
|
||||||
Mom::SlotDefinition.new(:message , [:receiver])
|
Mom::SlotDefinition.new(:message , [:receiver])
|
||||||
end
|
end
|
||||||
@ -101,7 +96,7 @@ module Vool
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
|
@ -10,7 +10,7 @@ module Vool
|
|||||||
|
|
||||||
# When used as right hand side, this tells what data to move to get the result into
|
# When used as right hand side, this tells what data to move to get the result into
|
||||||
# a varaible. It is (off course) the return value of the message
|
# a varaible. It is (off course) the return value of the message
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
Mom::SlotDefinition.new(:message ,[ :return_value])
|
Mom::SlotDefinition.new(:message ,[ :return_value])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,14 +8,14 @@ module Vool
|
|||||||
#
|
#
|
||||||
# The Parfait class gets created lazily on the way down to mom, ie the clazz
|
# The Parfait class gets created lazily on the way down to mom, ie the clazz
|
||||||
# attribute will only be set after to_mom, or a direct call to create_class
|
# attribute will only be set after to_mom, or a direct call to create_class
|
||||||
class ClassStatement < Statement
|
class ClassExpression < Expression
|
||||||
attr_reader :name, :super_class_name , :body
|
attr_reader :name, :super_class_name , :body
|
||||||
attr_reader :clazz
|
attr_reader :clazz
|
||||||
|
|
||||||
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
|
||||||
when MethodStatement
|
when MethodExpression
|
||||||
@body = Statements.new([body])
|
@body = Statements.new([body])
|
||||||
when Statements
|
when Statements
|
||||||
@body = body
|
@body = body
|
@ -1,5 +1,5 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class ClassMethodStatement < Statement
|
class ClassMethodExpression < Expression
|
||||||
attr_reader :name, :args , :body
|
attr_reader :name, :args , :body
|
||||||
|
|
||||||
def initialize( name , args , body )
|
def initialize( name , args , body )
|
@ -15,7 +15,7 @@ module Vool
|
|||||||
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
|
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
|
||||||
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
|
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
|
||||||
|
|
||||||
check = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label)
|
check = Mom::TruthCheck.new(condition.to_slot(compiler) , false_label)
|
||||||
if @condition.is_a?(CallStatement)
|
if @condition.is_a?(CallStatement)
|
||||||
head = @condition.to_mom(compiler)
|
head = @condition.to_mom(compiler)
|
||||||
head << check
|
head << check
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class LambdaStatement < Statement
|
class LambdaExpression < Expression
|
||||||
attr_reader :args , :body , :clazz
|
attr_reader :args , :body , :clazz
|
||||||
|
|
||||||
def initialize( args , body , clazz = nil)
|
def initialize( args , body , clazz = nil)
|
||||||
@ -13,7 +13,7 @@ module Vool
|
|||||||
#
|
#
|
||||||
# This means we do the compiler here (rather than to_mom, which is in
|
# This means we do the compiler here (rather than to_mom, which is in
|
||||||
# fact never called)
|
# fact never called)
|
||||||
def slot_definition(compiler)
|
def to_slot(compiler)
|
||||||
return Mom::SlotDefinition.new(Mom::LambdaConstant.new(parfait_block(compiler)) , [])
|
return Mom::SlotDefinition.new(Mom::LambdaConstant.new(parfait_block(compiler)) , [])
|
||||||
end
|
end
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class MethodStatement < Statement
|
class MethodExpression < Expression
|
||||||
attr_reader :name, :args , :body
|
attr_reader :name, :args , :body
|
||||||
|
|
||||||
def initialize( name , args , body )
|
def initialize( name , args , body )
|
@ -18,7 +18,7 @@ module Vool
|
|||||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
load = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
load = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
||||||
@return_value.slot_definition(compiler) )
|
@return_value.to_slot(compiler) )
|
||||||
if @return_value.is_a?(CallStatement)
|
if @return_value.is_a?(CallStatement)
|
||||||
ret = @return_value.to_mom(compiler)
|
ret = @return_value.to_mom(compiler)
|
||||||
ret << load
|
ret << load
|
||||||
|
@ -46,11 +46,11 @@ module Vool
|
|||||||
|
|
||||||
def message_setup(compiler,called_method)
|
def message_setup(compiler,called_method)
|
||||||
setup = Mom::MessageSetup.new( called_method )
|
setup = Mom::MessageSetup.new( called_method )
|
||||||
mom_receive = @receiver.slot_definition(compiler)
|
mom_receive = @receiver.to_slot(compiler)
|
||||||
arg_target = [:message , :next_message , :arguments]
|
arg_target = [:message , :next_message , :arguments]
|
||||||
args = []
|
args = []
|
||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
||||||
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.to_slot(compiler))
|
||||||
end
|
end
|
||||||
setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
|
setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
|
||||||
end
|
end
|
||||||
@ -90,7 +90,7 @@ module Vool
|
|||||||
|
|
||||||
private
|
private
|
||||||
def receiver_type_definition(compiler)
|
def receiver_type_definition(compiler)
|
||||||
defi = @receiver.slot_definition(compiler)
|
defi = @receiver.to_slot(compiler)
|
||||||
defi.slots << :type
|
defi.slots << :type
|
||||||
defi
|
defi
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Object Oriented
|
# Object Oriented
|
||||||
# Language
|
# Language
|
||||||
#
|
#
|
||||||
# VOOL is the abstraction of ruby, ruby minus some of the fluff
|
# VOOL is the abstraction of ruby, ruby minusthe 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
|
||||||
@ -10,19 +10,17 @@
|
|||||||
# Also, Vool is a typed tree, not abstract, so there is a base class Statement
|
# Also, Vool is a typed tree, not abstract, so there is a base class Statement
|
||||||
# and all it's derivation that make up the syntax tree
|
# and all it's derivation that make up the syntax tree
|
||||||
#
|
#
|
||||||
# Also Vool has expression and statements and simple syntax. So returns must be explicit
|
# Also Vool has expression and statements, revealing that age old dichotomy of code and
|
||||||
# not everthing is just assignable, ifs can only test simple expressions etc (wip)
|
# data. Statements represent code whereas Expressions resolve to data.
|
||||||
#
|
# (in ruby there are no pure statements, everthing resolves to data)
|
||||||
# This allows us to write compilers or passes of the compiler(s) as functions on the
|
|
||||||
# classes.
|
|
||||||
#
|
|
||||||
module Vool
|
module Vool
|
||||||
|
|
||||||
# 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
|
||||||
#
|
#
|
||||||
# Compilers or compiler passes are written by implementing methods.
|
# Basically Statements represent code, generally speaking code "does things".
|
||||||
#
|
# But Vool distinguishes Expressions (see below), that represent data, and as such
|
||||||
|
# don't do things themselves, rather passively participate in being pushed around
|
||||||
class Statement
|
class Statement
|
||||||
|
|
||||||
def to_mom( _ )
|
def to_mom( _ )
|
||||||
@ -37,7 +35,13 @@ module Vool
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Expression
|
# An Expression is a Statement that represents data. ie variables constants
|
||||||
|
# (see basic_values) , but alos classes, methods and lambdas
|
||||||
|
class Expression < Statement
|
||||||
|
|
||||||
|
def each(&block)
|
||||||
|
block.call(self)
|
||||||
|
end
|
||||||
|
|
||||||
def ct_type
|
def ct_type
|
||||||
nil
|
nil
|
||||||
@ -46,20 +50,13 @@ module Vool
|
|||||||
def normalize
|
def normalize
|
||||||
raise "should not be normalized #{self}"
|
raise "should not be normalized #{self}"
|
||||||
end
|
end
|
||||||
def to_mom(compiler)
|
|
||||||
raise "should not be momed #{self}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# for loading into a lot, return the "slot_definition" that can be passed to
|
# for loading into a slot, return the "slot_definition" that can be passed to
|
||||||
# SlotLoad.
|
# SlotLoad.
|
||||||
def slot_definition(compiler)
|
def to_slot(compiler)
|
||||||
raise "not iplemented in #{self}"
|
raise "not iplemented in #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def at_depth(depth , *strings)
|
|
||||||
prefix = " " * 2 * depth
|
|
||||||
strings.collect{|str| prefix + str}.join("\n")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -67,14 +64,14 @@ end
|
|||||||
|
|
||||||
require_relative "assignment"
|
require_relative "assignment"
|
||||||
require_relative "basic_values"
|
require_relative "basic_values"
|
||||||
require_relative "block_statement"
|
|
||||||
require_relative "call_statement"
|
require_relative "call_statement"
|
||||||
require_relative "class_statement"
|
require_relative "class_expression"
|
||||||
require_relative "if_statement"
|
require_relative "if_statement"
|
||||||
require_relative "ivar_assignment"
|
require_relative "ivar_assignment"
|
||||||
|
require_relative "lambda_expression"
|
||||||
require_relative "local_assignment"
|
require_relative "local_assignment"
|
||||||
require_relative "method_statement"
|
require_relative "method_expression"
|
||||||
require_relative "class_method_statement"
|
require_relative "class_method_expression"
|
||||||
require_relative "return_statement"
|
require_relative "return_statement"
|
||||||
require_relative "statements"
|
require_relative "statements"
|
||||||
require_relative "send_statement"
|
require_relative "send_statement"
|
||||||
|
@ -36,13 +36,18 @@ module Vool
|
|||||||
end
|
end
|
||||||
def <<(o)
|
def <<(o)
|
||||||
if(o.is_a?(Statements))
|
if(o.is_a?(Statements))
|
||||||
o.each {|s| @statements << s }
|
o.statements.each do |s|
|
||||||
|
raise "not a statement #{s}" unless s.is_a?(Statement)
|
||||||
|
@statements << s
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
||||||
@statements << o
|
@statements << o
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
def prepend(o)
|
def prepend(o)
|
||||||
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
||||||
@statements = [o] + @statements
|
@statements = [o] + @statements
|
||||||
end
|
end
|
||||||
def shift
|
def shift
|
||||||
@ -62,7 +67,12 @@ module Vool
|
|||||||
stats = @statements.dup
|
stats = @statements.dup
|
||||||
first = stats.shift.to_mom(compiler)
|
first = stats.shift.to_mom(compiler)
|
||||||
while( nekst = stats.shift )
|
while( nekst = stats.shift )
|
||||||
first.append nekst.to_mom(compiler)
|
next_mom = nekst.to_mom(compiler)
|
||||||
|
if next_mom.is_a?(Mom::BlockCompiler)
|
||||||
|
compiler.block_compilers << next_mom
|
||||||
|
else
|
||||||
|
first.append next_mom
|
||||||
|
end
|
||||||
end
|
end
|
||||||
first
|
first
|
||||||
end
|
end
|
||||||
|
@ -10,11 +10,11 @@ module Vool
|
|||||||
|
|
||||||
class LocalVariable < Expression
|
class LocalVariable < Expression
|
||||||
include Named
|
include Named
|
||||||
def slot_definition(compiler)
|
def to_slot(compiler)
|
||||||
slot_def = compiler.slot_type_for(@name)
|
slot_def = compiler.slot_type_for(@name)
|
||||||
Mom::SlotDefinition.new(:message , slot_def)
|
Mom::SlotDefinition.new(:message , slot_def)
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s(depth = 0)
|
||||||
name.to_s
|
name.to_s
|
||||||
end
|
end
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@ -24,7 +24,7 @@ module Vool
|
|||||||
|
|
||||||
class InstanceVariable < Expression
|
class InstanceVariable < Expression
|
||||||
include Named
|
include Named
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
|
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
|
||||||
end
|
end
|
||||||
# used to collect type information
|
# used to collect type information
|
||||||
@ -51,7 +51,7 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
get_named_class.meta_class.instance_type
|
get_named_class.meta_class.instance_type
|
||||||
end
|
end
|
||||||
def slot_definition(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new( get_named_class, [])
|
return Mom::SlotDefinition.new( get_named_class, [])
|
||||||
end
|
end
|
||||||
def get_named_class
|
def get_named_class
|
||||||
|
@ -15,7 +15,7 @@ module Vool
|
|||||||
codes = cond_label
|
codes = cond_label
|
||||||
codes << @hoisted.to_mom(compiler) if @hoisted
|
codes << @hoisted.to_mom(compiler) if @hoisted
|
||||||
codes << @condition.to_mom(compiler) if @condition.is_a?(SendStatement)
|
codes << @condition.to_mom(compiler) if @condition.is_a?(SendStatement)
|
||||||
codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
|
codes << Mom::TruthCheck.new(condition.to_slot(compiler) , merge_label)
|
||||||
codes << @body.to_mom(compiler)
|
codes << @body.to_mom(compiler)
|
||||||
codes << Mom::Jump.new(cond_label)
|
codes << Mom::Jump.new(cond_label)
|
||||||
codes << merge_label
|
codes << merge_label
|
||||||
|
@ -49,11 +49,11 @@ module Vool
|
|||||||
def yield_arg_block(compiler)
|
def yield_arg_block(compiler)
|
||||||
arg_index = compiler.get_method.arguments_type.get_length - 1
|
arg_index = compiler.get_method.arguments_type.get_length - 1
|
||||||
setup = Mom::MessageSetup.new( arg_index )
|
setup = Mom::MessageSetup.new( arg_index )
|
||||||
mom_receive = @receiver.slot_definition(compiler)
|
mom_receive = @receiver.to_slot(compiler)
|
||||||
arg_target = [:message , :next_message , :arguments]
|
arg_target = [:message , :next_message , :arguments]
|
||||||
args = []
|
args = []
|
||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
||||||
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.to_slot(compiler))
|
||||||
end
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( self , mom_receive , args )
|
setup << Mom::ArgumentTransfer.new( self , mom_receive , args )
|
||||||
setup << Mom::BlockYield.new( self , arg_index )
|
setup << Mom::BlockYield.new( self , arg_index )
|
||||||
|
@ -29,13 +29,13 @@ module Ruby
|
|||||||
@vool.body.statements.last
|
@vool.body.statements.last
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::ClassStatement , @vool.class
|
assert_equal Vool::ClassExpression , @vool.class
|
||||||
end
|
end
|
||||||
def test_body
|
def test_body
|
||||||
assert_equal Vool::Statements , @vool.body.class
|
assert_equal Vool::Statements , @vool.body.class
|
||||||
end
|
end
|
||||||
def test_getter
|
def test_getter
|
||||||
assert_equal Vool::MethodStatement , getter.class
|
assert_equal Vool::MethodExpression , getter.class
|
||||||
end
|
end
|
||||||
def test_getter_return
|
def test_getter_return
|
||||||
assert_equal Vool::ReturnStatement , getter.body.class
|
assert_equal Vool::ReturnStatement , getter.body.class
|
||||||
|
@ -43,7 +43,7 @@ module Ruby
|
|||||||
@lst = compile( input ).to_vool
|
@lst = compile( input ).to_vool
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal Vool::ClassMethodStatement , @lst.class
|
assert_equal Vool::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
|
||||||
|
@ -9,7 +9,7 @@ module Ruby
|
|||||||
@vool = compile( input ).to_vool
|
@vool = compile( input ).to_vool
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal Vool::ClassStatement , @vool.class
|
assert_equal Vool::ClassExpression , @vool.class
|
||||||
end
|
end
|
||||||
def test_body
|
def test_body
|
||||||
assert_equal Vool::Statements , @vool.body.class
|
assert_equal Vool::Statements , @vool.body.class
|
||||||
|
@ -12,7 +12,7 @@ module Ruby
|
|||||||
assert_equal 2 , @vool.body.length , "setter, getter"
|
assert_equal 2 , @vool.body.length , "setter, getter"
|
||||||
end
|
end
|
||||||
def test_setter
|
def test_setter
|
||||||
assert_equal Vool::MethodStatement , setter.class
|
assert_equal Vool::MethodExpression , setter.class
|
||||||
end
|
end
|
||||||
def test_setter_assign
|
def test_setter_assign
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Vool::Statements , setter.body.class
|
||||||
|
@ -11,7 +11,7 @@ module Ruby
|
|||||||
assert_equal 4 , @vool.body.length , "2 setters, 2 getters"
|
assert_equal 4 , @vool.body.length , "2 setters, 2 getters"
|
||||||
end
|
end
|
||||||
def test_setter
|
def test_setter
|
||||||
assert_equal Vool::MethodStatement , setter.class
|
assert_equal Vool::MethodExpression , setter.class
|
||||||
end
|
end
|
||||||
def test_setter_assign
|
def test_setter_assign
|
||||||
assert_equal Vool::Statements , setter.body.class
|
assert_equal Vool::Statements , setter.body.class
|
||||||
|
@ -38,7 +38,7 @@ module Ruby
|
|||||||
def test_first
|
def test_first
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||||
assert @lst.first.name.to_s.start_with?("implicit_block_")
|
assert @lst.first.name.to_s.start_with?("implicit_block_")
|
||||||
assert_equal Vool::LambdaStatement , @lst.first.value.class
|
assert_equal Vool::LambdaExpression , @lst.first.value.class
|
||||||
end
|
end
|
||||||
def test_last_send
|
def test_last_send
|
||||||
assert_equal 2 , @lst.length
|
assert_equal 2 , @lst.length
|
||||||
|
@ -41,7 +41,7 @@ module Ruby
|
|||||||
assert @lst.first.first.name.to_s.start_with?("implicit_block")
|
assert @lst.first.first.name.to_s.start_with?("implicit_block")
|
||||||
end
|
end
|
||||||
def test_block_assign_right
|
def test_block_assign_right
|
||||||
assert_equal Vool::LambdaStatement , @lst.first.first.value.class
|
assert_equal Vool::LambdaExpression , @lst.first.first.value.class
|
||||||
end
|
end
|
||||||
def test_a_assign
|
def test_a_assign
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.last.class
|
assert_equal Vool::LocalAssignment , @lst.first.last.class
|
||||||
|
@ -55,8 +55,8 @@ module Ruby
|
|||||||
class TestVariablesVool < MiniTest::Test
|
class TestVariablesVool < MiniTest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
def test_local_basic
|
def test_local_basic
|
||||||
lst = compile( "foo = 1 ; foo").to_vool
|
lst = compile( "foo = 1 ; return foo").to_vool
|
||||||
assert_equal Vool::LocalVariable , lst.statements[1].class
|
assert_equal Vool::LocalVariable , lst.statements[1].return_value.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_basic
|
def test_instance_basic
|
||||||
|
41
test/rubyx/parfait/test_data_object.rb
Normal file
41
test/rubyx/parfait/test_data_object.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module RubyX
|
||||||
|
|
||||||
|
class TestDatObjectCompile #< MiniTest::Test
|
||||||
|
include ParfaitHelper
|
||||||
|
def setup
|
||||||
|
@compiler = compiler
|
||||||
|
@compiler.ruby_to_vool load_parfait(:object)
|
||||||
|
end
|
||||||
|
def source
|
||||||
|
load_parfait(:data_object)
|
||||||
|
end
|
||||||
|
def test_load
|
||||||
|
assert source.include?("class DataObject")
|
||||||
|
assert source.length > 1500 , source.length
|
||||||
|
end
|
||||||
|
def test_vool
|
||||||
|
vool = @compiler.ruby_to_vool source
|
||||||
|
assert_equ Vool::ScopeStatement , vool.class
|
||||||
|
assert_equal Vool::ClassStatement , vool[0].class
|
||||||
|
assert_equal Vool::ScopeStatement , vool[1].class
|
||||||
|
assert_equal Vool::ClassStatement , vool[1][0].class
|
||||||
|
assert_equal :DataObject , vool[1][0].name
|
||||||
|
assert_equal :Data4 , vool[1][1].name
|
||||||
|
assert_equal :Data8 , vool[1][2].name
|
||||||
|
end
|
||||||
|
def test_mom
|
||||||
|
mom = @compiler.ruby_to_mom source
|
||||||
|
assert_equal Mom::MomCollection , mom.class
|
||||||
|
end
|
||||||
|
def qtest_risc
|
||||||
|
risc = compiler.ruby_to_risc source
|
||||||
|
assert_equal Risc::RiscCollection , risc.class
|
||||||
|
end
|
||||||
|
def qtest_binary
|
||||||
|
risc = compiler.ruby_to_binary source , :interpreter
|
||||||
|
assert_equal Risc::Linker , risc.class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
32
test/rubyx/parfait/test_integer.rb
Normal file
32
test/rubyx/parfait/test_integer.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module RubyX
|
||||||
|
|
||||||
|
class TestIntegerCompile < MiniTest::Test
|
||||||
|
include ParfaitHelper
|
||||||
|
def source
|
||||||
|
load_parfait(:integer)
|
||||||
|
end
|
||||||
|
def test_load
|
||||||
|
assert source.include?("class Integer")
|
||||||
|
assert source.length > 2000
|
||||||
|
end
|
||||||
|
def qtest_vool
|
||||||
|
vool = compiler.ruby_to_vool source
|
||||||
|
assert_equal Vool::ClassStatement , vool.class
|
||||||
|
assert_equal :Object , vool.name
|
||||||
|
end
|
||||||
|
def qtest_mom
|
||||||
|
mom = compiler.ruby_to_mom source
|
||||||
|
assert_equal Mom::MomCollection , mom.class
|
||||||
|
end
|
||||||
|
def qtest_risc
|
||||||
|
risc = compiler.ruby_to_risc source
|
||||||
|
assert_equal Risc::RiscCollection , risc.class
|
||||||
|
end
|
||||||
|
def qtest_binary
|
||||||
|
risc = compiler.ruby_to_binary source , :interpreter
|
||||||
|
assert_equal Risc::Linker , risc.class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user