Merge branch 'master' of https://github.com/ruby-in-ruby/crystal
This commit is contained in:
commit
5145d21e37
@ -63,6 +63,7 @@ module Arm
|
|||||||
# return the block of the given name
|
# return the block of the given name
|
||||||
# or raise an exception, as this is meant to be called when the block is available
|
# or raise an exception, as this is meant to be called when the block is available
|
||||||
def get_block name
|
def get_block name
|
||||||
|
name = name.to_sym
|
||||||
block = @blocks.find {|b| b.name == name}
|
block = @blocks.find {|b| b.name == name}
|
||||||
raise "No block found for #{name} (in #{blocks.collect{|b|b.name}.join(':')})" unless block
|
raise "No block found for #{name} (in #{blocks.collect{|b|b.name}.join(':')})" unless block
|
||||||
block
|
block
|
||||||
|
@ -11,7 +11,7 @@ module Arm
|
|||||||
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
||||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||||
@operand = 0
|
@operand = 0
|
||||||
|
raise "alert" if right.is_a? Vm::Block
|
||||||
@pre_post_index = 0 #P flag
|
@pre_post_index = 0 #P flag
|
||||||
@add_offset = 0 #U flag
|
@add_offset = 0 #U flag
|
||||||
@is_load = opcode.to_s[0] == "l" ? 1 : 0 #L (load) flag
|
@is_load = opcode.to_s[0] == "l" ? 1 : 0 #L (load) flag
|
||||||
@ -31,7 +31,10 @@ module Arm
|
|||||||
@rn = arg
|
@rn = arg
|
||||||
if @right
|
if @right
|
||||||
@operand = @right
|
@operand = @right
|
||||||
|
#TODO better test, this operand integer (register) does not work. but sleep first
|
||||||
|
@operand = @operand.register if @operand.is_a? Vm::Integer
|
||||||
unless( @operand.is_a? Symbol)
|
unless( @operand.is_a? Symbol)
|
||||||
|
puts "operand #{@operand.inspect}"
|
||||||
if (@operand < 0)
|
if (@operand < 0)
|
||||||
@add_offset = 0
|
@add_offset = 0
|
||||||
#TODO test/check/understand
|
#TODO test/check/understand
|
||||||
|
@ -24,7 +24,7 @@ module Ast
|
|||||||
class NameExpression < Expression
|
class NameExpression < Expression
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
def initialize name
|
def initialize name
|
||||||
@name = name
|
@name = name.to_sym
|
||||||
end
|
end
|
||||||
# compiling a variable resolves it.
|
# compiling a variable resolves it.
|
||||||
# if it wasn't defined, nli is returned
|
# if it wasn't defined, nli is returned
|
||||||
@ -32,10 +32,10 @@ module Ast
|
|||||||
context.locals[name]
|
context.locals[name]
|
||||||
end
|
end
|
||||||
def inspect
|
def inspect
|
||||||
self.class.name + '.new("' + name + '")'
|
"#{self.class.name}.new(#{name})"
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name.to_s
|
||||||
end
|
end
|
||||||
def attributes
|
def attributes
|
||||||
[:name]
|
[:name]
|
||||||
@ -54,7 +54,7 @@ module Ast
|
|||||||
self.class.name + '.new("' + string + '")'
|
self.class.name + '.new("' + string + '")'
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
'"' + string + '"'
|
'"' + string.to_s + '"'
|
||||||
end
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
value = Vm::StringConstant.new(string)
|
value = Vm::StringConstant.new(string)
|
||||||
|
@ -4,15 +4,30 @@ module Ast
|
|||||||
class CallSiteExpression < Expression
|
class CallSiteExpression < Expression
|
||||||
attr_reader :name, :args , :receiver
|
attr_reader :name, :args , :receiver
|
||||||
|
|
||||||
def initialize name, args , receiver = Ast::NameExpression.new("self")
|
def initialize name, args , receiver = Ast::NameExpression.new(:self)
|
||||||
@name , @args , @receiver = name.to_sym , args , receiver
|
@name = name.to_sym
|
||||||
|
@args = args
|
||||||
|
@receiver = receiver
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile context , into
|
def compile context , into
|
||||||
params = args.collect{ |a| a.compile(context, into) }
|
params = args.collect{ |a| a.compile(context, into) }
|
||||||
#TOOD, this needs dynamic resolution
|
|
||||||
function = context.current_class.get_or_create_function(name)
|
if receiver.name == :self
|
||||||
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
|
function = context.current_class.get_or_create_function(name)
|
||||||
|
elsif receiver.is_a? ModuleName
|
||||||
|
c_name = receiver.name
|
||||||
|
clazz = context.object_space.get_or_create_class c_name
|
||||||
|
raise "uups #{clazz}.#{c_name}" unless clazz
|
||||||
|
#class qualifier, means call from metaclass
|
||||||
|
clazz = clazz.meta_class
|
||||||
|
function = clazz.get_or_create_function(name)
|
||||||
|
elsif receiver.is_a? VariableExpression
|
||||||
|
raise "not implemented instance var:#{receiver}"
|
||||||
|
else
|
||||||
|
raise "not implemented case (dare i say system error):#{receiver}"
|
||||||
|
end
|
||||||
|
raise "No such method error #{clazz.to_s}:#{name}" if function == nil
|
||||||
call = Vm::CallSite.new( name , params , function)
|
call = Vm::CallSite.new( name , params , function)
|
||||||
current_function = context.function
|
current_function = context.function
|
||||||
current_function.save_locals(context , into) if current_function
|
current_function.save_locals(context , into) if current_function
|
||||||
|
@ -31,10 +31,16 @@ module Ast
|
|||||||
locals[arg] = arg_value
|
locals[arg] = arg_value
|
||||||
args << arg_value
|
args << arg_value
|
||||||
end
|
end
|
||||||
class_name = context.current_class.name
|
|
||||||
function = Vm::Function.new(name , args )
|
|
||||||
# class depends on receiver
|
# class depends on receiver
|
||||||
context.current_class.add_function function
|
if receiver.nil?
|
||||||
|
clazz = context.current_class
|
||||||
|
else
|
||||||
|
c = context.object_space.get_or_create_class receiver.name.to_sym
|
||||||
|
clazz = c.meta_class
|
||||||
|
end
|
||||||
|
|
||||||
|
function = Vm::Function.new(name , args )
|
||||||
|
clazz.add_function function
|
||||||
|
|
||||||
parent_locals = context.locals
|
parent_locals = context.locals
|
||||||
parent_function = context.function
|
parent_function = context.function
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class ModuleExpression < Expression
|
class ModuleExpression < Expression
|
||||||
|
|
||||||
attr_reader :name ,:expressions
|
attr_reader :name ,:expressions
|
||||||
|
|
||||||
def initialize name , expressions
|
def initialize name , expressions
|
||||||
@name = name.to_sym
|
@name = name.to_sym
|
||||||
@expressions = expressions
|
@expressions = expressions
|
||||||
|
51
lib/boot/object.rb
Normal file
51
lib/boot/object.rb
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
module Boot
|
||||||
|
class Object
|
||||||
|
module ClassMethods
|
||||||
|
|
||||||
|
# return the index of the variable. Now "normal" code can't really do anything with that, but
|
||||||
|
# set/get instance variable use it.
|
||||||
|
# This is just a placeholder, as we code this in ruby, but the instance methods need the definition before.
|
||||||
|
def index_of context , name = Vm::Integer
|
||||||
|
index_function = Vm::Function.new(:index_of , [Vm::Integer] , Vm::Integer )
|
||||||
|
return index_function
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# in ruby, how this goes is
|
||||||
|
# def _get_instance_variable var
|
||||||
|
# i = self.index_of(var)
|
||||||
|
# return at_index(i)
|
||||||
|
# end
|
||||||
|
# The at_index is just "below" the api, somehting we need but don't want to expose, so we can't code the above in ruby
|
||||||
|
def _get_instance_variable context , name = Vm::Integer
|
||||||
|
get_function = Vm::Function.new(:_get_instance_variable , [Vm::Integer , Vm::Integer ] , Vm::Integer )
|
||||||
|
me = get_function.args[0]
|
||||||
|
var_name = get_function.args[1]
|
||||||
|
return_to = get_function.return_type
|
||||||
|
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
||||||
|
b = get_function.body
|
||||||
|
b.push( [me] )
|
||||||
|
b.call( index_function )
|
||||||
|
b.pop([me])
|
||||||
|
return_to.at_index( get_function.body , me , return_to )
|
||||||
|
get_function.set_return return_to
|
||||||
|
return get_function
|
||||||
|
end
|
||||||
|
|
||||||
|
def _set_instance_variable(name , value)
|
||||||
|
raise name
|
||||||
|
end
|
||||||
|
|
||||||
|
def _get_singleton_method(name )
|
||||||
|
raise name
|
||||||
|
end
|
||||||
|
def _add_singleton_method(method)
|
||||||
|
raise "4"
|
||||||
|
end
|
||||||
|
def initialize()
|
||||||
|
raise "4"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
extend ClassMethods
|
||||||
|
end
|
||||||
|
end
|
@ -1,26 +1,6 @@
|
|||||||
# this is not a "normal" ruby file, ie it is not required by crystal
|
# this is not a "normal" ruby file, ie it is not required by crystal
|
||||||
# instead it is parsed by crystal to define part of the crystal that runs
|
# instead it is parsed by crystal to define part of the crystal that runs
|
||||||
|
|
||||||
class BaseObject
|
|
||||||
|
|
||||||
def _set_instance_variable(name , value)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def _get_instance_variable( name )
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def _get_singleton_method(name )
|
|
||||||
|
|
||||||
end
|
|
||||||
def _add_singleton_method(method)
|
|
||||||
|
|
||||||
end
|
|
||||||
def initialize
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Array < BaseObject
|
class Array < BaseObject
|
||||||
def initialize size
|
def initialize size
|
||||||
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
module Core
|
|
||||||
class BaseObject
|
|
||||||
|
|
||||||
def _set_instance_variable(name , value)
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
|
|
||||||
def _get_instance_variable( name )
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
|
|
||||||
def _get_singleton_method(name )
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
def _add_singleton_method(method)
|
|
||||||
return 4
|
|
||||||
end
|
|
||||||
def initialize()
|
|
||||||
return 4
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -20,27 +20,6 @@ module Core
|
|||||||
def function_exit block , f_name
|
def function_exit block , f_name
|
||||||
Vm::RegisterMachine.instance.function_exit block , f_name
|
Vm::RegisterMachine.instance.function_exit block , f_name
|
||||||
end
|
end
|
||||||
|
|
||||||
# in ruby, how this goes is
|
|
||||||
# def _get_instance_variable var
|
|
||||||
# i = self.index_of(var)
|
|
||||||
# return at_index(i)
|
|
||||||
# end
|
|
||||||
# The at_index is just "below" the api, somehting we need but don't want to expose, so we can't code the above in ruby
|
|
||||||
def _get_instance_variable context , name = Vm::Integer
|
|
||||||
get_function = Vm::Function.new(:_get_instance_variable , [Vm::Integer , Vm::Integer ] , Vm::Integer )
|
|
||||||
me = get_function.args[0]
|
|
||||||
var_name = get_function.args[1]
|
|
||||||
return_to = get_function.return_type
|
|
||||||
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
|
||||||
b = get_function.body
|
|
||||||
b.push( me )
|
|
||||||
index = b.call( index_function )
|
|
||||||
b.pop(me)
|
|
||||||
return_to.at_index( get_function.body , me , index )
|
|
||||||
get_function.set_return return_to
|
|
||||||
return get_function
|
|
||||||
end
|
|
||||||
|
|
||||||
#TODO this is in the wrong place. It is a function that returns a function object
|
#TODO this is in the wrong place. It is a function that returns a function object
|
||||||
# while all other methods add their code into some block. --> kernel
|
# while all other methods add their code into some block. --> kernel
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
|
require_relative "meta_class"
|
||||||
|
|
||||||
module Vm
|
module Vm
|
||||||
# class is mainly a list of functions with a name (for now)
|
# class is mainly a list of functions with a name (for now)
|
||||||
# layout of object is seperated into Layout
|
# layout of object is seperated into Layout
|
||||||
class BootClass < Code
|
class BootClass < Code
|
||||||
def initialize name , context , superclass = :Object
|
def initialize name , context , super_class = :Object
|
||||||
|
super()
|
||||||
@context = context
|
@context = context
|
||||||
# class functions
|
# class functions
|
||||||
@functions = []
|
@functions = []
|
||||||
@name = name.to_sym
|
@name = name.to_sym
|
||||||
@superclass = superclass
|
@super_class = super_class
|
||||||
|
@meta_class = MetaClass.new(self)
|
||||||
end
|
end
|
||||||
attr_reader :name , :functions
|
attr_reader :name , :functions , :meta_class
|
||||||
|
|
||||||
def add_function function
|
def add_function function
|
||||||
raise "not a function #{function}" unless function.is_a? Function
|
raise "not a function #{function}" unless function.is_a? Function
|
||||||
@ -17,27 +21,32 @@ module Vm
|
|||||||
@functions << function
|
@functions << function
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_function name
|
def get_function fname
|
||||||
name = name.to_sym
|
fname = fname.to_sym
|
||||||
@functions.detect{ |f| f.name == name }
|
f = @functions.detect{ |f| f.name == fname }
|
||||||
|
names = @functions.collect{|f| f.name }
|
||||||
|
f
|
||||||
end
|
end
|
||||||
|
|
||||||
# preferred way of creating new functions (also forward declarations, will flag unresolved later)
|
# way of creating new functions that have not been parsed.
|
||||||
def get_or_create_function name
|
def get_or_create_function name
|
||||||
fun = get_function name
|
fun = get_function name
|
||||||
unless fun or name == :Object
|
unless fun or name == :Object
|
||||||
supr = @context.object_space.get_or_create_class(@superclass)
|
supr = @context.object_space.get_or_create_class(@super_class)
|
||||||
fun = supr.get_function name
|
fun = supr.get_function name
|
||||||
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
||||||
end
|
end
|
||||||
unless fun
|
unless fun
|
||||||
fun = Core::Kernel.send(name , @context)
|
fun = Core::Kernel.send(name , @context)
|
||||||
raise "no such function #{name}, #{name.class}" if fun == nil
|
return nil if fun == nil
|
||||||
@functions << fun
|
@functions << fun
|
||||||
end
|
end
|
||||||
fun
|
fun
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"BootClass #{@name} , super #{@super_class} #{@functions.length} functions"
|
||||||
|
end
|
||||||
# Code interface follows. Note position is inheitted as is from Code
|
# Code interface follows. Note position is inheitted as is from Code
|
||||||
|
|
||||||
# length of the class is the length of it's functions
|
# length of the class is the length of it's functions
|
||||||
|
@ -3,6 +3,7 @@ require_relative "boot_class"
|
|||||||
require_relative "call_site"
|
require_relative "call_site"
|
||||||
require "arm/arm_machine"
|
require "arm/arm_machine"
|
||||||
require "core/kernel"
|
require "core/kernel"
|
||||||
|
require "boot/object"
|
||||||
|
|
||||||
module Vm
|
module Vm
|
||||||
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
||||||
@ -35,9 +36,19 @@ module Vm
|
|||||||
#main gets executed between entry and exit
|
#main gets executed between entry and exit
|
||||||
@main = Block.new("main",nil)
|
@main = Block.new("main",nil)
|
||||||
@exit = Core::Kernel::main_exit Vm::Block.new("main_exit",nil)
|
@exit = Core::Kernel::main_exit Vm::Block.new("main_exit",nil)
|
||||||
|
boot_classes
|
||||||
end
|
end
|
||||||
attr_reader :context , :main , :classes , :entry , :exit
|
attr_reader :context , :main , :classes , :entry , :exit
|
||||||
|
|
||||||
|
def boot_classes
|
||||||
|
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we have to define some
|
||||||
|
# dummies, just for the other to compile
|
||||||
|
obj = get_or_create_class :Object
|
||||||
|
[:index_of , :_get_instance_variable].each do |f|
|
||||||
|
puts "adding #{f}"
|
||||||
|
obj.add_function Boot::Object.send(f , @context)
|
||||||
|
end
|
||||||
|
end
|
||||||
def add_object o
|
def add_object o
|
||||||
return if @objects.include? o
|
return if @objects.include? o
|
||||||
raise "must be derived from Code #{o.inspect}" unless o.is_a? Code
|
raise "must be derived from Code #{o.inspect}" unless o.is_a? Code
|
||||||
@ -45,7 +56,7 @@ module Vm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_or_create_class name
|
def get_or_create_class name
|
||||||
raise "uups #{name}" unless name.is_a? Symbol
|
raise "uups #{name}.#{name.class}" unless name.is_a? Symbol
|
||||||
c = @classes[name]
|
c = @classes[name]
|
||||||
unless c
|
unless c
|
||||||
c = BootClass.new(name,@context)
|
c = BootClass.new(name,@context)
|
||||||
|
@ -26,6 +26,7 @@ module Vm
|
|||||||
attr_reader :string
|
attr_reader :string
|
||||||
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
||||||
def initialize str
|
def initialize str
|
||||||
|
str = str.to_s if str.is_a? Symbol
|
||||||
length = str.length
|
length = str.length
|
||||||
# rounding up to the next 4 (always adding one for zero pad)
|
# rounding up to the next 4 (always adding one for zero pad)
|
||||||
pad = ((length / 4 ) + 1 ) * 4 - length
|
pad = ((length / 4 ) + 1 ) * 4 - length
|
||||||
|
37
lib/vm/meta_class.rb
Normal file
37
lib/vm/meta_class.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module Vm
|
||||||
|
# class that acts like a class, but is really the object
|
||||||
|
|
||||||
|
# described in the ruby language book as the eigenclass, what you get with
|
||||||
|
# class MyClass
|
||||||
|
# class << self <--- this is called the eigenclass, or metaclass, and really is just the class object
|
||||||
|
# .... but gives us the ability to use the syntax as if it were a class
|
||||||
|
# PS: can't say i fancy the << self syntax and am considerernig adding a keyword for it, like meta
|
||||||
|
# In effect it is a very similar construct to def self.function(...)
|
||||||
|
# So one could write def meta.function(...) and thus define on the meta-class
|
||||||
|
class MetaClass < Code
|
||||||
|
# no name, nor nothing. as this is just the object really
|
||||||
|
|
||||||
|
def initialize(object)
|
||||||
|
super()
|
||||||
|
@functions = []
|
||||||
|
@me_self = object
|
||||||
|
end
|
||||||
|
|
||||||
|
# in a non-booting version this should map to _add_singleton_method
|
||||||
|
def add_function function
|
||||||
|
raise "not a function #{function}" unless function.is_a? Function
|
||||||
|
raise "syserr " unless function.name.is_a? Symbol
|
||||||
|
@functions << function
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_function name
|
||||||
|
name = name.to_sym
|
||||||
|
f = @functions.detect{ |f| f.name == name }
|
||||||
|
puts "no function for #{name} in Meta #{@me_self.inspect}" unless f
|
||||||
|
f
|
||||||
|
end
|
||||||
|
def inspect
|
||||||
|
"#{@me_self}, #{@functions.length} functions"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -16,20 +16,25 @@ class Object
|
|||||||
return @layout.class()
|
return @layout.class()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
class Class
|
||||||
|
def Class.new_object( length )
|
||||||
|
return 4
|
||||||
|
end
|
||||||
|
end
|
||||||
class String
|
class String
|
||||||
|
def String.new_string( len )
|
||||||
|
return Class.new_object( len << 2 )
|
||||||
|
end
|
||||||
def length()
|
def length()
|
||||||
return @length
|
return @length
|
||||||
end
|
end
|
||||||
def self.new_string( len )
|
|
||||||
4
|
|
||||||
end
|
|
||||||
def plus(str)
|
def plus(str)
|
||||||
my_length = @length
|
my_length = @length
|
||||||
str_len = str.length()
|
str_len = str.length()
|
||||||
new_string = String.new_string(my_length + str_len)
|
new_string = String.new_string(my_length + str_len)
|
||||||
i = 0
|
i = 0
|
||||||
while( i < my_length) do
|
while( i < my_length) do
|
||||||
char = self.get(i)
|
char = get(i)
|
||||||
new_string.set(i , char)
|
new_string.set(i , char)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ require_relative 'helper'
|
|||||||
class TestWhileFragment < MiniTest::Test
|
class TestWhileFragment < MiniTest::Test
|
||||||
include Fragments
|
include Fragments
|
||||||
|
|
||||||
def test_while
|
def test_while_fibo
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def fibonaccit(n) # n == r0
|
def fibonaccit(n) # n == r0
|
||||||
a = 0 # a == r1
|
a = 0 # a == r1
|
||||||
|
@ -35,7 +35,7 @@ class TestBasic < MiniTest::Test
|
|||||||
def test_instance_variable
|
def test_instance_variable
|
||||||
@string_input = '@foo_bar '
|
@string_input = '@foo_bar '
|
||||||
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
|
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
|
||||||
@transform_output = Ast::VariableExpression.new('foo_bar')
|
@transform_output = Ast::VariableExpression.new(:foo_bar)
|
||||||
@parser = @parser.instance_variable
|
@parser = @parser.instance_variable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class TestCallSite < MiniTest::Test
|
|||||||
def test_single_instance
|
def test_single_instance
|
||||||
@string_input = '@var.foo(42)'
|
@string_input = '@var.foo(42)'
|
||||||
@parse_output = {:receiver=>{:instance_variable=>{:name=>"var"}}, :call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"42"}}]}
|
@parse_output = {:receiver=>{:instance_variable=>{:name=>"var"}}, :call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"42"}}]}
|
||||||
@transform_output = Ast::CallSiteExpression.new(:foo, [Ast::IntegerExpression.new(42)] ,Ast::VariableExpression.new("var"))
|
@transform_output = Ast::CallSiteExpression.new(:foo, [Ast::IntegerExpression.new(42)] ,Ast::VariableExpression.new(:var))
|
||||||
@parser = @parser.call_site
|
@parser = @parser.call_site
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class TestCallSite < MiniTest::Test
|
|||||||
def test_call_chaining_instance
|
def test_call_chaining_instance
|
||||||
@string_input = '@class.new(self.get(4))'
|
@string_input = '@class.new(self.get(4))'
|
||||||
@parse_output = {:receiver=>{:instance_variable=>{:name=>"class"}}, :call_site=>{:name=>"new"}, :argument_list=>[{:argument=>{:receiver=>{:name=>"self"}, :call_site=>{:name=>"get"}, :argument_list=>[{:argument=>{:integer=>"4"}}]}}]}
|
@parse_output = {:receiver=>{:instance_variable=>{:name=>"class"}}, :call_site=>{:name=>"new"}, :argument_list=>[{:argument=>{:receiver=>{:name=>"self"}, :call_site=>{:name=>"get"}, :argument_list=>[{:argument=>{:integer=>"4"}}]}}]}
|
||||||
@transform_output = Ast::CallSiteExpression.new(:new, [Ast::CallSiteExpression.new(:get, [Ast::IntegerExpression.new(4)] ,Ast::NameExpression.new("self"))] ,Ast::VariableExpression.new("class"))
|
@transform_output = Ast::CallSiteExpression.new(:new, [Ast::CallSiteExpression.new(:get, [Ast::IntegerExpression.new(4)] ,Ast::NameExpression.new("self"))] ,Ast::VariableExpression.new(:class))
|
||||||
@parser = @parser.call_site
|
@parser = @parser.call_site
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class Opers
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:module_name=>"Opers", :class_expressions=>[{:function_name=>{:name=>"foo"}, :parmeter_list=>[{:parmeter=>{:name=>"x"}}], :expressions=>[{:l=>{:instance_variable=>{:name=>"abba"}}, :o=>"= ", :r=>{:integer=>"5"}}, {:l=>{:integer=>"2"}, :o=>"+ ", :r=>{:integer=>"5"}}], :end=>"end"}], :end=>"end"}
|
@parse_output = {:module_name=>"Opers", :class_expressions=>[{:function_name=>{:name=>"foo"}, :parmeter_list=>[{:parmeter=>{:name=>"x"}}], :expressions=>[{:l=>{:instance_variable=>{:name=>"abba"}}, :o=>"= ", :r=>{:integer=>"5"}}, {:l=>{:integer=>"2"}, :o=>"+ ", :r=>{:integer=>"5"}}], :end=>"end"}], :end=>"end"}
|
||||||
@transform_output = Ast::ClassExpression.new(:Opers ,[Ast::FunctionExpression.new(:foo, [Ast::NameExpression.new("x")] , [Ast::OperatorExpression.new("=", Ast::VariableExpression.new("abba"),Ast::IntegerExpression.new(5)),Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))] )] )
|
@transform_output = Ast::ClassExpression.new(:Opers ,[Ast::FunctionExpression.new(:foo, [Ast::NameExpression.new("x")] , [Ast::OperatorExpression.new("=", Ast::VariableExpression.new(:abba),Ast::IntegerExpression.new(5)),Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))] )] )
|
||||||
@parser = @parser.class_definition
|
@parser = @parser.class_definition
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class Pifi
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:module_name=>"Pifi", :class_expressions=>[{:call_site=>{:name=>"ofthen"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+", :r=>{:integer=>"4"}}}, {:argument=>{:name=>"var"}}]}, {:function_name=>{:name=>"ofthen"}, :parmeter_list=>[{:parmeter=>{:name=>"n"}}, {:parmeter=>{:name=>"m"}}], :expressions=>[{:integer=>"44"}], :end=>"end"}], :end=>"end"}
|
@parse_output = {:module_name=>"Pifi", :class_expressions=>[{:call_site=>{:name=>"ofthen"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+", :r=>{:integer=>"4"}}}, {:argument=>{:name=>"var"}}]}, {:function_name=>{:name=>"ofthen"}, :parmeter_list=>[{:parmeter=>{:name=>"n"}}, {:parmeter=>{:name=>"m"}}], :expressions=>[{:integer=>"44"}], :end=>"end"}], :end=>"end"}
|
||||||
@transform_output =Ast::ClassExpression.new(:Pifi ,[Ast::CallSiteExpression.new(:ofthen, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),Ast::NameExpression.new("var")] ), Ast::FunctionExpression.new(:ofthen, [Ast::NameExpression.new("n"),Ast::NameExpression.new("m")] , [Ast::IntegerExpression.new(44)] )] )
|
@transform_output =Ast::ClassExpression.new(:Pifi ,[Ast::CallSiteExpression.new(:ofthen, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),Ast::NameExpression.new(:var)] ), Ast::FunctionExpression.new(:ofthen, [Ast::NameExpression.new("n"),Ast::NameExpression.new("m")] , [Ast::IntegerExpression.new(44)] )] )
|
||||||
@parser = @parser.class_definition
|
@parser = @parser.class_definition
|
||||||
end
|
end
|
||||||
def test_class_module
|
def test_class_module
|
||||||
@ -68,7 +68,7 @@ class Foo
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:module_name=>"Foo", :class_expressions=>[{:module_name=>"Boo", :module_expressions=>[{:call_site=>{:name=>"funcall"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+", :r=>{:integer=>"4"}}}, {:argument=>{:name=>"var"}}]}], :end=>"end"}], :end=>"end"}
|
@parse_output = {:module_name=>"Foo", :class_expressions=>[{:module_name=>"Boo", :module_expressions=>[{:call_site=>{:name=>"funcall"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+", :r=>{:integer=>"4"}}}, {:argument=>{:name=>"var"}}]}], :end=>"end"}], :end=>"end"}
|
||||||
@transform_output = Ast::ClassExpression.new(:Foo ,[Ast::ModuleExpression.new(:Boo ,[Ast::CallSiteExpression.new(:funcall, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),Ast::NameExpression.new("var")] )] )] )
|
@transform_output = Ast::ClassExpression.new(:Foo ,[Ast::ModuleExpression.new(:Boo ,[Ast::CallSiteExpression.new(:funcall, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),Ast::NameExpression.new(:var)] )] )] )
|
||||||
@parser = @parser.class_definition
|
@parser = @parser.class_definition
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -22,7 +22,7 @@ def String.length(x)
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:receiver=>{:module_name=>"String"}, :function_name=>{:name=>"length"}, :parmeter_list=>[{:parmeter=>{:name=>"x"}}], :expressions=>[{:instance_variable=>{:name=>"length"}}], :end=>"end"}
|
@parse_output = {:receiver=>{:module_name=>"String"}, :function_name=>{:name=>"length"}, :parmeter_list=>[{:parmeter=>{:name=>"x"}}], :expressions=>[{:instance_variable=>{:name=>"length"}}], :end=>"end"}
|
||||||
@transform_output = Ast::FunctionExpression.new(:length, [Ast::NameExpression.new("x")] , [Ast::VariableExpression.new("length")] ,Ast::ModuleName.new("String") )
|
@transform_output = Ast::FunctionExpression.new(:length, [Ast::NameExpression.new("x")] , [Ast::VariableExpression.new(:length)] ,Ast::ModuleName.new("String") )
|
||||||
@parser = @parser.function_definition
|
@parser = @parser.function_definition
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ module Opers
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:module_name=>"Opers", :module_expressions=>[{:l=>{:instance_variable=>{:name=>"abba"}}, :o=>"= ", :r=>{:integer=>"5"}}], :end=>"end"}
|
@parse_output = {:module_name=>"Opers", :module_expressions=>[{:l=>{:instance_variable=>{:name=>"abba"}}, :o=>"= ", :r=>{:integer=>"5"}}], :end=>"end"}
|
||||||
@transform_output = Ast::ModuleExpression.new(:Opers ,[Ast::OperatorExpression.new("=", Ast::VariableExpression.new("abba"),Ast::IntegerExpression.new(5))] )
|
@transform_output = Ast::ModuleExpression.new(:Opers ,[Ast::OperatorExpression.new("=", Ast::VariableExpression.new(:abba),Ast::IntegerExpression.new(5))] )
|
||||||
@parser = @parser.module_definition
|
@parser = @parser.module_definition
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,25 +31,25 @@ class TestExpressions < MiniTest::Test
|
|||||||
def test_op_variable
|
def test_op_variable
|
||||||
@string_input = "a + 35"
|
@string_input = "a + 35"
|
||||||
@parse_output = {:l=>{:name=>"a"}, :o=>"+ ", :r=>{:integer=>"35"}}
|
@parse_output = {:l=>{:name=>"a"}, :o=>"+ ", :r=>{:integer=>"35"}}
|
||||||
@transform_output = Ast::OperatorExpression.new("+", Ast::NameExpression.new("a"),Ast::IntegerExpression.new(35))
|
@transform_output = Ast::OperatorExpression.new("+", Ast::NameExpression.new(:a),Ast::IntegerExpression.new(35))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
def test_op_two_variable
|
def test_op_two_variable
|
||||||
@string_input = "a - b"
|
@string_input = "a - b"
|
||||||
@parse_output = {:l=>{:name=>"a"}, :o=>"- ", :r=>{:name=>"b"}}
|
@parse_output = {:l=>{:name=>"a"}, :o=>"- ", :r=>{:name=>"b"}}
|
||||||
@transform_output = Ast::OperatorExpression.new("-", Ast::NameExpression.new("a"),Ast::NameExpression.new("b"))
|
@transform_output = Ast::OperatorExpression.new("-", Ast::NameExpression.new(:a),Ast::NameExpression.new("b"))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
def test_op_instance_variable
|
def test_op_instance_variable
|
||||||
@string_input = "@a - 5"
|
@string_input = "@a - 5"
|
||||||
@parse_output = {:l=>{:instance_variable=>{:name=>"a"}}, :o=>"- ", :r=>{:integer=>"5"}}
|
@parse_output = {:l=>{:instance_variable=>{:name=>"a"}}, :o=>"- ", :r=>{:integer=>"5"}}
|
||||||
@transform_output = Ast::OperatorExpression.new("-", Ast::VariableExpression.new("a"),Ast::IntegerExpression.new(5))
|
@transform_output = Ast::OperatorExpression.new("-", Ast::VariableExpression.new(:a),Ast::IntegerExpression.new(5))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
def test_op_variable_string
|
def test_op_variable_string
|
||||||
@string_input = 'a - "st"'
|
@string_input = 'a - "st"'
|
||||||
@parse_output = {:l=>{:name=>"a"}, :o=>"- ", :r=>{:string=>[{:char=>"s"}, {:char=>"t"}]}}
|
@parse_output = {:l=>{:name=>"a"}, :o=>"- ", :r=>{:string=>[{:char=>"s"}, {:char=>"t"}]}}
|
||||||
@transform_output = Ast::OperatorExpression.new("-", Ast::NameExpression.new("a"),Ast::StringExpression.new("st"))
|
@transform_output = Ast::OperatorExpression.new("-", Ast::NameExpression.new(:a),Ast::StringExpression.new("st"))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
def test_two_same_ops
|
def test_two_same_ops
|
||||||
@ -73,13 +73,13 @@ class TestExpressions < MiniTest::Test
|
|||||||
def test_assignment
|
def test_assignment
|
||||||
@string_input = "a = 5"
|
@string_input = "a = 5"
|
||||||
@parse_output = {:l=>{:name=>"a"}, :o=>"= ", :r=>{:integer=>"5"}}
|
@parse_output = {:l=>{:name=>"a"}, :o=>"= ", :r=>{:integer=>"5"}}
|
||||||
@transform_output = Ast::OperatorExpression.new("=", Ast::NameExpression.new("a"),Ast::IntegerExpression.new(5))
|
@transform_output = Ast::OperatorExpression.new("=", Ast::NameExpression.new(:a),Ast::IntegerExpression.new(5))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
def test_assignment_instance
|
def test_assignment_instance
|
||||||
@string_input = "@a = 5"
|
@string_input = "@a = 5"
|
||||||
@parse_output = {:l=>{:instance_variable=>{:name=>"a"}}, :o=>"= ", :r=>{:integer=>"5"}}
|
@parse_output = {:l=>{:instance_variable=>{:name=>"a"}}, :o=>"= ", :r=>{:integer=>"5"}}
|
||||||
@transform_output = Ast::OperatorExpression.new("=", Ast::VariableExpression.new("a"),Ast::IntegerExpression.new(5))
|
@transform_output = Ast::OperatorExpression.new("=", Ast::VariableExpression.new(:a),Ast::IntegerExpression.new(5))
|
||||||
@parser = @parser.operator_expression
|
@parser = @parser.operator_expression
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user