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:
@ -33,7 +33,7 @@ module Vool
|
||||
# Derived classes do not implement to_mom, only slot_position
|
||||
def to_mom(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)
|
||||
return assign unless @value.is_a?(CallStatement)
|
||||
@value.to_mom(compiler) << assign
|
||||
|
@ -1,9 +1,6 @@
|
||||
module Vool
|
||||
#Marker class for different constants
|
||||
class Constant < Expression
|
||||
#gobble it up
|
||||
def each(&block)
|
||||
end
|
||||
end
|
||||
|
||||
# An integer at the vool level
|
||||
@ -12,17 +9,15 @@ module Vool
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
||||
end
|
||||
def to_s
|
||||
def to_s(depth = 0)
|
||||
value.to_s
|
||||
end
|
||||
def each(&block)
|
||||
end
|
||||
end
|
||||
# An float at the vool level
|
||||
class FloatConstant < Constant
|
||||
@ -33,7 +28,7 @@ module Vool
|
||||
def ct_type
|
||||
true
|
||||
end
|
||||
def to_s
|
||||
def to_s(depth = 0)
|
||||
value.to_s
|
||||
end
|
||||
end
|
||||
@ -42,7 +37,7 @@ module Vool
|
||||
def ct_type
|
||||
Parfait.object_space.get_type_by_class_name(:True)
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
||||
end
|
||||
def to_s(depth = 0)
|
||||
@ -54,7 +49,7 @@ module Vool
|
||||
def ct_type
|
||||
Parfait.object_space.get_type_by_class_name(:False)
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
||||
end
|
||||
def to_s(depth = 0)
|
||||
@ -66,7 +61,7 @@ module Vool
|
||||
def ct_type
|
||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
||||
end
|
||||
def to_s(depth = 0)
|
||||
@ -80,7 +75,7 @@ module Vool
|
||||
def initialize(type = nil)
|
||||
@my_type = type
|
||||
end
|
||||
def slot_definition(compiler)
|
||||
def to_slot(compiler)
|
||||
@my_type = compiler.receiver_type
|
||||
Mom::SlotDefinition.new(:message , [:receiver])
|
||||
end
|
||||
@ -101,7 +96,7 @@ module Vool
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
||||
end
|
||||
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
|
||||
# a varaible. It is (off course) the return value of the message
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
Mom::SlotDefinition.new(:message ,[ :return_value])
|
||||
end
|
||||
|
||||
|
@ -8,14 +8,14 @@ module Vool
|
||||
#
|
||||
# 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
|
||||
class ClassStatement < Statement
|
||||
class ClassExpression < Expression
|
||||
attr_reader :name, :super_class_name , :body
|
||||
attr_reader :clazz
|
||||
|
||||
def initialize( name , supe , body)
|
||||
@name , @super_class_name = name , supe
|
||||
case body
|
||||
when MethodStatement
|
||||
when MethodExpression
|
||||
@body = Statements.new([body])
|
||||
when Statements
|
||||
@body = body
|
@ -1,5 +1,5 @@
|
||||
module Vool
|
||||
class ClassMethodStatement < Statement
|
||||
class ClassMethodExpression < Expression
|
||||
attr_reader :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)}")
|
||||
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)
|
||||
head = @condition.to_mom(compiler)
|
||||
head << check
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Vool
|
||||
class LambdaStatement < Statement
|
||||
class LambdaExpression < Expression
|
||||
attr_reader :args , :body , :clazz
|
||||
|
||||
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
|
||||
# fact never called)
|
||||
def slot_definition(compiler)
|
||||
def to_slot(compiler)
|
||||
return Mom::SlotDefinition.new(Mom::LambdaConstant.new(parfait_block(compiler)) , [])
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Vool
|
||||
class MethodStatement < Statement
|
||||
class MethodExpression < Expression
|
||||
attr_reader :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)
|
||||
def to_mom( compiler )
|
||||
load = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
||||
@return_value.slot_definition(compiler) )
|
||||
@return_value.to_slot(compiler) )
|
||||
if @return_value.is_a?(CallStatement)
|
||||
ret = @return_value.to_mom(compiler)
|
||||
ret << load
|
||||
|
@ -46,11 +46,11 @@ module Vool
|
||||
|
||||
def message_setup(compiler,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]
|
||||
args = []
|
||||
@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
|
||||
setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
|
||||
end
|
||||
@ -90,7 +90,7 @@ module Vool
|
||||
|
||||
private
|
||||
def receiver_type_definition(compiler)
|
||||
defi = @receiver.slot_definition(compiler)
|
||||
defi = @receiver.to_slot(compiler)
|
||||
defi.slots << :type
|
||||
defi
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Object Oriented
|
||||
# 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
|
||||
# if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles,
|
||||
# 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
|
||||
# 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
|
||||
# not everthing is just assignable, ifs can only test simple expressions etc (wip)
|
||||
#
|
||||
# This allows us to write compilers or passes of the compiler(s) as functions on the
|
||||
# classes.
|
||||
#
|
||||
# Also Vool has expression and statements, revealing that age old dichotomy of code and
|
||||
# data. Statements represent code whereas Expressions resolve to data.
|
||||
# (in ruby there are no pure statements, everthing resolves to data)
|
||||
module Vool
|
||||
|
||||
# Base class for all statements in the tree. Derived classes correspond to known language
|
||||
# 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
|
||||
|
||||
def to_mom( _ )
|
||||
@ -37,7 +35,13 @@ module Vool
|
||||
|
||||
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
|
||||
nil
|
||||
@ -46,20 +50,13 @@ module Vool
|
||||
def normalize
|
||||
raise "should not be normalized #{self}"
|
||||
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.
|
||||
def slot_definition(compiler)
|
||||
def to_slot(compiler)
|
||||
raise "not iplemented in #{self}"
|
||||
end
|
||||
|
||||
def at_depth(depth , *strings)
|
||||
prefix = " " * 2 * depth
|
||||
strings.collect{|str| prefix + str}.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@ -67,14 +64,14 @@ end
|
||||
|
||||
require_relative "assignment"
|
||||
require_relative "basic_values"
|
||||
require_relative "block_statement"
|
||||
require_relative "call_statement"
|
||||
require_relative "class_statement"
|
||||
require_relative "class_expression"
|
||||
require_relative "if_statement"
|
||||
require_relative "ivar_assignment"
|
||||
require_relative "lambda_expression"
|
||||
require_relative "local_assignment"
|
||||
require_relative "method_statement"
|
||||
require_relative "class_method_statement"
|
||||
require_relative "method_expression"
|
||||
require_relative "class_method_expression"
|
||||
require_relative "return_statement"
|
||||
require_relative "statements"
|
||||
require_relative "send_statement"
|
||||
|
@ -36,13 +36,18 @@ module Vool
|
||||
end
|
||||
def <<(o)
|
||||
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
|
||||
raise "not a statement #{o}" unless o.is_a?(Statement)
|
||||
@statements << o
|
||||
end
|
||||
self
|
||||
end
|
||||
def prepend(o)
|
||||
raise "not a statement #{o}" unless o.is_a?(Statement)
|
||||
@statements = [o] + @statements
|
||||
end
|
||||
def shift
|
||||
@ -62,7 +67,12 @@ module Vool
|
||||
stats = @statements.dup
|
||||
first = stats.shift.to_mom(compiler)
|
||||
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
|
||||
first
|
||||
end
|
||||
|
@ -10,11 +10,11 @@ module Vool
|
||||
|
||||
class LocalVariable < Expression
|
||||
include Named
|
||||
def slot_definition(compiler)
|
||||
def to_slot(compiler)
|
||||
slot_def = compiler.slot_type_for(@name)
|
||||
Mom::SlotDefinition.new(:message , slot_def)
|
||||
end
|
||||
def to_s
|
||||
def to_s(depth = 0)
|
||||
name.to_s
|
||||
end
|
||||
def each(&block)
|
||||
@ -24,7 +24,7 @@ module Vool
|
||||
|
||||
class InstanceVariable < Expression
|
||||
include Named
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
|
||||
end
|
||||
# used to collect type information
|
||||
@ -51,7 +51,7 @@ module Vool
|
||||
def ct_type
|
||||
get_named_class.meta_class.instance_type
|
||||
end
|
||||
def slot_definition(_)
|
||||
def to_slot(_)
|
||||
return Mom::SlotDefinition.new( get_named_class, [])
|
||||
end
|
||||
def get_named_class
|
||||
|
@ -15,7 +15,7 @@ module Vool
|
||||
codes = cond_label
|
||||
codes << @hoisted.to_mom(compiler) if @hoisted
|
||||
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 << Mom::Jump.new(cond_label)
|
||||
codes << merge_label
|
||||
|
@ -49,11 +49,11 @@ module Vool
|
||||
def yield_arg_block(compiler)
|
||||
arg_index = compiler.get_method.arguments_type.get_length - 1
|
||||
setup = Mom::MessageSetup.new( arg_index )
|
||||
mom_receive = @receiver.slot_definition(compiler)
|
||||
mom_receive = @receiver.to_slot(compiler)
|
||||
arg_target = [:message , :next_message , :arguments]
|
||||
args = []
|
||||
@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
|
||||
setup << Mom::ArgumentTransfer.new( self , mom_receive , args )
|
||||
setup << Mom::BlockYield.new( self , arg_index )
|
||||
|
Reference in New Issue
Block a user