rename
This commit is contained in:
parent
33c62a7db1
commit
525f9d45c5
@ -5,7 +5,7 @@ module Ast
|
|||||||
class IntegerExpression < Expression
|
class IntegerExpression < Expression
|
||||||
# attr_reader :value
|
# attr_reader :value
|
||||||
def compile context
|
def compile context
|
||||||
Vm::IntegerConstant.new value
|
Virtual::IntegerConstant.new value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ module Ast
|
|||||||
class StringExpression < Expression
|
class StringExpression < Expression
|
||||||
# attr_reader :string
|
# attr_reader :string
|
||||||
def compile context
|
def compile context
|
||||||
value = Vm::StringConstant.new(string)
|
value = Virtual::StringConstant.new(string)
|
||||||
context.object_space.add_object value
|
context.object_space.add_object value
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ module Ast
|
|||||||
elsif receiver.is_a?(NameExpression)
|
elsif receiver.is_a?(NameExpression)
|
||||||
if(receiver.name == :self)
|
if(receiver.name == :self)
|
||||||
function = context.current_class.resolve_function(name)
|
function = context.current_class.resolve_function(name)
|
||||||
value_receiver = Vm::Integer.new(Vm::RegisterMachine.instance.receiver_register)
|
value_receiver = Virtual::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
|
||||||
else
|
else
|
||||||
value_receiver = receiver.compile(context)
|
value_receiver = receiver.compile(context)
|
||||||
# TODO HACK warning: should determine class dynamically
|
# TODO HACK warning: should determine class dynamically
|
||||||
@ -35,7 +35,7 @@ module Ast
|
|||||||
end
|
end
|
||||||
raise "No such method error #{inspect}" if (function.nil?)
|
raise "No such method error #{inspect}" if (function.nil?)
|
||||||
raise "No receiver error #{inspect}:#{receiver}" if (value_receiver.nil?)
|
raise "No receiver error #{inspect}:#{receiver}" if (value_receiver.nil?)
|
||||||
call = Vm::CallSite.new( name , value_receiver , params , function)
|
call = Virtual::CallSite.new( name , value_receiver , params , function)
|
||||||
current_function = context.function
|
current_function = context.function
|
||||||
into.push([]) unless current_function.nil?
|
into.push([]) unless current_function.nil?
|
||||||
call.load_args into
|
call.load_args into
|
||||||
|
10
lib/ast/expression_list.rb
Normal file
10
lib/ast/expression_list.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module Ast
|
||||||
|
class ExpressionList < Expression
|
||||||
|
# attr_reader :expressions
|
||||||
|
def compile binding
|
||||||
|
expressions.each do |part|
|
||||||
|
expr = part.compile( binding )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -6,13 +6,13 @@ module Ast
|
|||||||
locals = {}
|
locals = {}
|
||||||
params.each_with_index do |param , index|
|
params.each_with_index do |param , index|
|
||||||
arg = param.name
|
arg = param.name
|
||||||
register = Vm::RegisterReference.new(Vm::RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
|
register = Virtual::RegisterReference.new(Virtual::RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
|
||||||
arg_value = Vm::Integer.new(register)
|
arg_value = Virtual::Integer.new(register)
|
||||||
locals[arg] = arg_value
|
locals[arg] = arg_value
|
||||||
args << arg_value
|
args << arg_value
|
||||||
end
|
end
|
||||||
# class depends on receiver
|
# class depends on receiver
|
||||||
me = Vm::Integer.new( Vm::RegisterMachine.instance.receiver_register )
|
me = Virtual::Integer.new( Virtual::RegisterMachine.instance.receiver_register )
|
||||||
if receiver.nil?
|
if receiver.nil?
|
||||||
clazz = context.current_class
|
clazz = context.current_class
|
||||||
else
|
else
|
||||||
@ -20,7 +20,7 @@ module Ast
|
|||||||
clazz = c.meta_class
|
clazz = c.meta_class
|
||||||
end
|
end
|
||||||
|
|
||||||
function = Vm::Function.new(name , me , args )
|
function = Virtual::Function.new(name , me , args )
|
||||||
clazz.add_function function
|
clazz.add_function function
|
||||||
|
|
||||||
parent_locals = context.locals
|
parent_locals = context.locals
|
||||||
@ -32,11 +32,11 @@ module Ast
|
|||||||
body.each do |b|
|
body.each do |b|
|
||||||
puts "compiling in function #{b}"
|
puts "compiling in function #{b}"
|
||||||
last_compiled = b.compile(context)
|
last_compiled = b.compile(context)
|
||||||
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Vm::Word
|
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Virtual::Word
|
||||||
end
|
end
|
||||||
|
|
||||||
return_reg = Vm::Integer.new(Vm::RegisterMachine.instance.return_register)
|
return_reg = Virtual::Integer.new(Virtual::RegisterMachine.instance.return_register)
|
||||||
if last_compiled.is_a?(Vm::IntegerConstant) or last_compiled.is_a?(Vm::ObjectConstant)
|
if last_compiled.is_a?(Virtual::IntegerConstant) or last_compiled.is_a?(Virtual::ObjectConstant)
|
||||||
return_reg.load function , last_compiled if last_compiled.register_symbol != return_reg.register_symbol
|
return_reg.load function , last_compiled if last_compiled.register_symbol != return_reg.register_symbol
|
||||||
else
|
else
|
||||||
return_reg.move( function, last_compiled ) if last_compiled.register_symbol != return_reg.register_symbol
|
return_reg.move( function, last_compiled ) if last_compiled.register_symbol != return_reg.register_symbol
|
||||||
|
@ -11,7 +11,7 @@ module Ast
|
|||||||
|
|
||||||
puts "compiling if condition #{cond}"
|
puts "compiling if condition #{cond}"
|
||||||
cond_val = cond.compile(context)
|
cond_val = cond.compile(context)
|
||||||
unless cond_val.is_a? Vm::BranchCondition
|
unless cond_val.is_a? Virtual::BranchCondition
|
||||||
cond_val = cond_val.is_true? f
|
cond_val = cond_val.is_true? f
|
||||||
end
|
end
|
||||||
f.b true_block , condition_code: cond_val.operator
|
f.b true_block , condition_code: cond_val.operator
|
||||||
|
@ -7,8 +7,8 @@ module Ast
|
|||||||
expression_value = expression.compile(context)
|
expression_value = expression.compile(context)
|
||||||
# copied from function expression: TODO make function
|
# copied from function expression: TODO make function
|
||||||
|
|
||||||
return_reg = Vm::Integer.new(Vm::RegisterMachine.instance.return_register)
|
return_reg = Virtual::Integer.new(Virtual::RegisterMachine.instance.return_register)
|
||||||
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::ObjectConstant)
|
if expression_value.is_a?(Virtual::IntegerConstant) or expression_value.is_a?(Virtual::ObjectConstant)
|
||||||
return_reg.load into , expression_value
|
return_reg.load into , expression_value
|
||||||
else
|
else
|
||||||
return_reg.move( into, expression_value ) if expression_value.register_symbol != return_reg.register_symbol
|
return_reg.move( into, expression_value ) if expression_value.register_symbol != return_reg.register_symbol
|
||||||
|
@ -3,7 +3,7 @@ require_relative "meta_class"
|
|||||||
module Boot
|
module Boot
|
||||||
# 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 < Vm::ObjectConstant
|
class BootClass < Virtual::ObjectConstant
|
||||||
def initialize name , context , super_class = :Object
|
def initialize name , context , super_class = :Object
|
||||||
super()
|
super()
|
||||||
@context = context
|
@context = context
|
||||||
@ -16,7 +16,7 @@ module Boot
|
|||||||
attr_reader :name , :functions , :meta_class , :context , :super_class
|
attr_reader :name , :functions , :meta_class , :context , :super_class
|
||||||
|
|
||||||
def add_function function
|
def add_function function
|
||||||
raise "not a function #{function}" unless function.is_a? Vm::Function
|
raise "not a function #{function}" unless function.is_a? Virtual::Function
|
||||||
raise "syserr " unless function.name.is_a? Symbol
|
raise "syserr " unless function.name.is_a? Symbol
|
||||||
@functions << function
|
@functions << function
|
||||||
end
|
end
|
||||||
|
@ -18,28 +18,28 @@ module Boot
|
|||||||
|
|
||||||
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
|
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
|
||||||
|
|
||||||
class BootSpace < Vm::Code
|
class BootSpace < Virtual::Code
|
||||||
|
|
||||||
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
|
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
|
||||||
# with a XXXMachine in it that derives from Vm::RegisterMachine
|
# with a XXXMachine in it that derives from Virtual::RegisterMachine
|
||||||
def initialize machine = nil
|
def initialize machine = nil
|
||||||
super()
|
super()
|
||||||
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
||||||
machine = "intel" if machine == "x86_64"
|
machine = "intel" if machine == "x86_64"
|
||||||
machine = machine.capitalize
|
machine = machine.capitalize
|
||||||
Vm::RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
|
Virtual::RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
|
||||||
@classes = {}
|
@classes = {}
|
||||||
@context = Vm::Context.new(self)
|
@context = Virtual::Context.new(self)
|
||||||
@context.current_class = get_or_create_class :Object
|
@context.current_class = get_or_create_class :Object
|
||||||
@main = Vm::Function.new("main")
|
@main = Virtual::Function.new("main")
|
||||||
@context.function = @main
|
@context.function = @main
|
||||||
#global objects (data)
|
#global objects (data)
|
||||||
@objects = []
|
@objects = []
|
||||||
@entry = Vm::RegisterMachine.instance.main_start @context
|
@entry = Virtual::RegisterMachine.instance.main_start @context
|
||||||
#main gets executed between entry and exit
|
#main gets executed between entry and exit
|
||||||
@exit = Vm::RegisterMachine.instance.main_exit @context
|
@exit = Virtual::RegisterMachine.instance.main_exit @context
|
||||||
boot_classes
|
boot_classes
|
||||||
@passes = [ Vm::MoveMoveReduction.new , Vm::LogicMoveReduction.new, Vm::NoopReduction.new, Vm::SaveLocals.new ]
|
@passes = [ Virtual::MoveMoveReduction.new , Virtual::LogicMoveReduction.new, Virtual::NoopReduction.new, Virtual::SaveLocals.new ]
|
||||||
end
|
end
|
||||||
attr_reader :context , :main , :classes , :entry , :exit
|
attr_reader :context , :main , :classes , :entry , :exit
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ module Boot
|
|||||||
# Objects are data and get assembled after functions
|
# Objects are data and get assembled after functions
|
||||||
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? Vm::Code
|
raise "must be derived from Code #{o.inspect}" unless o.is_a? Virtual::Code
|
||||||
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ module Boot
|
|||||||
# PS: can't say i fancy the << self syntax and am considerernig adding a keyword for it, like meta
|
# 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(...)
|
# 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
|
# So one could write def meta.function(...) and thus define on the meta-class
|
||||||
class MetaClass < Vm::ObjectConstant
|
class MetaClass < Virtual::ObjectConstant
|
||||||
# no name, nor nothing. as this is just the object really
|
# no name, nor nothing. as this is just the object really
|
||||||
|
|
||||||
def initialize(object)
|
def initialize(object)
|
||||||
@ -19,7 +19,7 @@ module Boot
|
|||||||
|
|
||||||
# in a non-booting version this should map to _add_singleton_method
|
# in a non-booting version this should map to _add_singleton_method
|
||||||
def add_function function
|
def add_function function
|
||||||
raise "not a function #{function}" unless function.is_a? Vm::Function
|
raise "not a function #{function}" unless function.is_a? Virtual::Function
|
||||||
raise "syserr " unless function.name.is_a? Symbol
|
raise "syserr " unless function.name.is_a? Symbol
|
||||||
@functions << function
|
@functions << function
|
||||||
end
|
end
|
||||||
|
@ -5,13 +5,13 @@ module Boot
|
|||||||
# return the index of the variable. Now "normal" code can't really do anything with that, but
|
# return the index of the variable. Now "normal" code can't really do anything with that, but
|
||||||
# set/get instance variable use it.
|
# 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.
|
# 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
|
def index_of context , name = Virtual::Integer
|
||||||
index_function = Vm::Function.new(:index_of , Vm::Reference , [Vm::Reference] , Vm::Integer )
|
index_function = Virtual::Function.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
|
||||||
return index_function
|
return index_function
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.layout
|
def self.layout
|
||||||
layout_function = Vm::Function.new(:layout , Vm::Reference , [ ] , Vm::Reference )
|
layout_function = Virtual::Function.new(:layout , Virtual::Reference , [ ] , Virtual::Reference )
|
||||||
layout_function.at_index 2
|
layout_function.at_index 2
|
||||||
layout_function
|
layout_function
|
||||||
end
|
end
|
||||||
@ -22,8 +22,8 @@ module Boot
|
|||||||
# return at_index(i)
|
# return at_index(i)
|
||||||
# end
|
# end
|
||||||
# The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
|
# The at_index is just "below" the api, something 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
|
def _get_instance_variable context , name = Virtual::Integer
|
||||||
get_function = Vm::Function.new(:_get_instance_variable , Vm::Reference , [ Vm::Reference ] , Vm::Mystery )
|
get_function = Virtual::Function.new(:_get_instance_variable , Virtual::Reference , [ Virtual::Reference ] , Virtual::Mystery )
|
||||||
me = get_function.receiver
|
me = get_function.receiver
|
||||||
var_name = get_function.args.first
|
var_name = get_function.args.first
|
||||||
return_to = get_function.return_type
|
return_to = get_function.return_type
|
||||||
@ -42,8 +42,8 @@ module Boot
|
|||||||
return get_function
|
return get_function
|
||||||
end
|
end
|
||||||
|
|
||||||
def _set_instance_variable(context , name = Vm::Integer , value = Vm::Integer )
|
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
|
||||||
set_function = Vm::Function.new(:_set_instance_variable , Vm::Reference ,[Vm::Reference ,Vm::Reference], Vm::Mystery )
|
set_function = Virtual::Function.new(:_set_instance_variable , Virtual::Reference ,[Virtual::Reference ,Virtual::Reference], Virtual::Mystery )
|
||||||
me = set_function.receiver
|
me = set_function.receiver
|
||||||
var_name = set_function.args.first
|
var_name = set_function.args.first
|
||||||
return_to = set_function.return_type
|
return_to = set_function.return_type
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Boot
|
module Boot
|
||||||
class String
|
class String
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def get context , index = Vm::Integer
|
def get context , index = Virtual::Integer
|
||||||
get_function = Vm::Function.new(:get , Vm::Integer , [ Vm::Integer] , Vm::Integer )
|
get_function = Virtual::Function.new(:get , Virtual::Integer , [ Virtual::Integer] , Virtual::Integer )
|
||||||
return get_function
|
return get_function
|
||||||
end
|
end
|
||||||
def set context , index = Vm::Integer , char = Vm::Integer
|
def set context , index = Virtual::Integer , char = Virtual::Integer
|
||||||
set_function = Vm::Function.new(:set , Vm::Integer ,[Vm::Integer, Vm::Integer] , Vm::Integer )
|
set_function = Virtual::Function.new(:set , Virtual::Integer ,[Virtual::Integer, Virtual::Integer] , Virtual::Integer )
|
||||||
return set_function
|
return set_function
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,11 +7,11 @@ module Crystal
|
|||||||
# As we write before we recurse (save a push) we write the number backwards
|
# As we write before we recurse (save a push) we write the number backwards
|
||||||
# arguments: string address , integer
|
# arguments: string address , integer
|
||||||
def self.utoa context
|
def self.utoa context
|
||||||
utoa_function = Vm::Function.new(:utoa , Vm::Integer , [ Vm::Integer ] , Vm::Integer )
|
utoa_function = Virtual::Function.new(:utoa , Virtual::Integer , [ Virtual::Integer ] , Virtual::Integer )
|
||||||
str_addr = utoa_function.receiver
|
str_addr = utoa_function.receiver
|
||||||
number = utoa_function.args.first
|
number = utoa_function.args.first
|
||||||
remainder = utoa_function.new_local
|
remainder = utoa_function.new_local
|
||||||
Vm::RegisterMachine.instance.div10( utoa_function , number , remainder )
|
Virtual::RegisterMachine.instance.div10( utoa_function , number , remainder )
|
||||||
# make char out of digit (by using ascii encoding) 48 == "0"
|
# make char out of digit (by using ascii encoding) 48 == "0"
|
||||||
utoa_function.instance_eval do
|
utoa_function.instance_eval do
|
||||||
add( remainder , remainder , 48)
|
add( remainder , remainder , 48)
|
||||||
@ -24,8 +24,8 @@ module Crystal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.putint context
|
def self.putint context
|
||||||
putint_function = Vm::Function.new(:putint , Vm::Integer , [] , Vm::Integer )
|
putint_function = Virtual::Function.new(:putint , Virtual::Integer , [] , Virtual::Integer )
|
||||||
buffer = Vm::StringConstant.new(" ") # create a buffer
|
buffer = Virtual::StringConstant.new(" ") # create a buffer
|
||||||
context.object_space.add_object buffer # and save it (function local variable: a no no)
|
context.object_space.add_object buffer # and save it (function local variable: a no no)
|
||||||
int = putint_function.receiver
|
int = putint_function.receiver
|
||||||
moved_int = putint_function.new_local
|
moved_int = putint_function.new_local
|
||||||
@ -41,7 +41,7 @@ module Crystal
|
|||||||
add( int , buffer , nil ) # string to write to
|
add( int , buffer , nil ) # string to write to
|
||||||
mov( moved_int , buffer.length )
|
mov( moved_int , buffer.length )
|
||||||
end
|
end
|
||||||
Vm::RegisterMachine.instance.write_stdout(putint_function)
|
Virtual::RegisterMachine.instance.write_stdout(putint_function)
|
||||||
putint_function
|
putint_function
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ module Crystal
|
|||||||
# a hand coded version of the fibonachi numbers
|
# a hand coded version of the fibonachi numbers
|
||||||
# not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
|
# not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
|
||||||
def self.fibo context
|
def self.fibo context
|
||||||
fibo_function = Vm::Function.new(:fibo , Vm::Integer , [] , Vm::Integer )
|
fibo_function = Virtual::Function.new(:fibo , Virtual::Integer , [] , Virtual::Integer )
|
||||||
result = fibo_function.return_type
|
result = fibo_function.return_type
|
||||||
int = fibo_function.receiver
|
int = fibo_function.receiver
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Crystal
|
module Crystal
|
||||||
module Kernel
|
module Kernel
|
||||||
def self.putstring context
|
def self.putstring context
|
||||||
function = Vm::Function.new(:putstring , Vm::Reference , [] )
|
function = Virtual::Function.new(:putstring , Virtual::Reference , [] )
|
||||||
ret = Vm::RegisterMachine.instance.write_stdout(function)
|
ret = Virtual::RegisterMachine.instance.write_stdout(function)
|
||||||
function.set_return ret
|
function.set_return ret
|
||||||
function
|
function
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Crystal
|
module Crystal
|
||||||
module Kernel
|
module Kernel
|
||||||
def self.exit context
|
def self.exit context
|
||||||
function = Vm::Function.new(:exit , Vm::Integer , [] )
|
function = Virtual::Function.new(:exit , Virtual::Integer , [] )
|
||||||
ret = Vm::RegisterMachine.instance.exit(function)
|
ret = Virtual::RegisterMachine.instance.exit(function)
|
||||||
function.set_return ret
|
function.set_return ret
|
||||||
function
|
function
|
||||||
end
|
end
|
||||||
|
@ -7,19 +7,19 @@ module Vm
|
|||||||
|
|
||||||
def less_or_equal block , right
|
def less_or_equal block , right
|
||||||
block.cmp( self , right )
|
block.cmp( self , right )
|
||||||
Vm::BranchCondition.new :le
|
Virtual::BranchCondition.new :le
|
||||||
end
|
end
|
||||||
def greater_or_equal block , right
|
def greater_or_equal block , right
|
||||||
block.cmp( self , right )
|
block.cmp( self , right )
|
||||||
Vm::BranchCondition.new :ge
|
Virtual::BranchCondition.new :ge
|
||||||
end
|
end
|
||||||
def greater_than block , right
|
def greater_than block , right
|
||||||
block.cmp( self , right )
|
block.cmp( self , right )
|
||||||
Vm::BranchCondition.new :gt
|
Virtual::BranchCondition.new :gt
|
||||||
end
|
end
|
||||||
def less_than block , right
|
def less_than block , right
|
||||||
block.cmp( self , right )
|
block.cmp( self , right )
|
||||||
Vm::BranchCondition.new :lt
|
Virtual::BranchCondition.new :lt
|
||||||
end
|
end
|
||||||
def plus block , first , right
|
def plus block , first , right
|
||||||
block.add( self , left , right )
|
block.add( self , left , right )
|
||||||
@ -35,12 +35,12 @@ module Vm
|
|||||||
end
|
end
|
||||||
def equals block , right
|
def equals block , right
|
||||||
block.cmp( self , right )
|
block.cmp( self , right )
|
||||||
Vm::BranchCondition.new :eq
|
Virtual::BranchCondition.new :eq
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_true? function
|
def is_true? function
|
||||||
function.cmp( self , 0 )
|
function.cmp( self , 0 )
|
||||||
Vm::BranchCondition.new :ne
|
Virtual::BranchCondition.new :ne
|
||||||
end
|
end
|
||||||
|
|
||||||
def move block , right
|
def move block , right
|
||||||
|
70
test/virtual/test_basic.rb
Normal file
70
test/virtual/test_basic.rb
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
require_relative "virtual_helper"
|
||||||
|
|
||||||
|
class TestBasic < MiniTest::Test
|
||||||
|
# include the magic (setup and parse -> test method translation), see there
|
||||||
|
include VirtualHelper
|
||||||
|
|
||||||
|
def test_number
|
||||||
|
@string_input = '42 '
|
||||||
|
@output = Ast::IntegerExpression.new(42)
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_name
|
||||||
|
@string_input = 'foo '
|
||||||
|
@output = Ast::NameExpression.new('foo')
|
||||||
|
@parser = @parser.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_name_underscode_start
|
||||||
|
@string_input = '_bar '
|
||||||
|
@output = Ast::NameExpression.new('_bar')
|
||||||
|
@parser = @parser.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_name_underscode_middle
|
||||||
|
@string_input = 'foo_bar '
|
||||||
|
@parse_output = {:name => 'foo_bar'}
|
||||||
|
@output = Ast::NameExpression.new('foo_bar')
|
||||||
|
@parser = @parser.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_instance_variable
|
||||||
|
@string_input = '@foo_bar '
|
||||||
|
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
|
||||||
|
@output = Ast::VariableExpression.new(:foo_bar)
|
||||||
|
@parser = @parser.instance_variable
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_module_name
|
||||||
|
@string_input = 'FooBar '
|
||||||
|
@parse_output = {:module_name=>"FooBar"}
|
||||||
|
@output = Ast::ModuleName.new("FooBar")
|
||||||
|
@parser = @parser.module_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_comment
|
||||||
|
out = "# i am a comment \n"
|
||||||
|
@string_input = out.dup #NEEDS the return, which is what delimits the comment
|
||||||
|
@parse_output = out
|
||||||
|
@output = @parse_output #dont transform
|
||||||
|
@parser = @parser.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_string
|
||||||
|
@string_input = "\"hello\""
|
||||||
|
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
|
||||||
|
@output = Ast::StringExpression.new('hello')
|
||||||
|
@parser = @parser.string
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_string_escapes
|
||||||
|
out = 'hello \nyou'
|
||||||
|
@string_input = '"' + out + '"'
|
||||||
|
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"},
|
||||||
|
{:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]}
|
||||||
|
@output = Ast::StringExpression.new(out)
|
||||||
|
@parser = @parser.string
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user