function test, slow but steady
This commit is contained in:
parent
122452c21b
commit
db8b1488d0
@ -48,7 +48,7 @@ module Ast
|
||||
clazz = ::Virtual::Object.space.get_or_create_class name
|
||||
raise "uups #{clazz}.#{name}" unless clazz
|
||||
#class qualifier, means call from metaclass
|
||||
clazz = clazz.meta_class
|
||||
#clazz = clazz.meta_class
|
||||
clazz
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,9 @@ module Ast
|
||||
class FunctionExpression < Expression
|
||||
# attr_reader :name, :params, :body , :receiver
|
||||
def compile frame , method
|
||||
method = Virtual::Method.new(name , params )
|
||||
args = params.collect{ |p| p.compile(frame , method )}
|
||||
r = receiver ? receiver.compile(frame,method) : Virtual::SelfReference.new
|
||||
method = Virtual::Method.new(name , params , r )
|
||||
end
|
||||
def scratch
|
||||
args = []
|
||||
|
@ -4,9 +4,8 @@ module Boot
|
||||
# class is mainly a list of methods with a name (for now)
|
||||
# layout of object is seperated into Layout
|
||||
class BootClass < Virtual::ObjectConstant
|
||||
def initialize name , scope , super_class = :Object
|
||||
def initialize name , super_class = :Object
|
||||
super()
|
||||
@scope = scope
|
||||
# class methods
|
||||
@methods = []
|
||||
@name = name.to_sym
|
||||
@ -14,7 +13,9 @@ module Boot
|
||||
@meta_class = MetaClass.new(self)
|
||||
end
|
||||
attr_reader :name , :methods , :meta_class , :context , :super_class
|
||||
|
||||
def attributes
|
||||
[:name , :super_class]
|
||||
end
|
||||
def add_method method
|
||||
raise "not a method #{method}" unless method.is_a? Virtual::Method
|
||||
raise "syserr " unless method.name.is_a? Symbol
|
||||
@ -40,9 +41,6 @@ module Boot
|
||||
fun
|
||||
end
|
||||
|
||||
def inspect
|
||||
"BootClass #{@name} < #{@super_class}:#{@methods.collect(&:name)}"
|
||||
end
|
||||
def to_s
|
||||
inspect
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ module Boot
|
||||
def initialize machine = nil
|
||||
super()
|
||||
@classes = {}
|
||||
@main = Virtual::Method.new("main")
|
||||
@main = Virtual::Method.new("main" , [] )
|
||||
#global objects (data)
|
||||
@objects = []
|
||||
boot_classes
|
||||
@ -77,7 +77,7 @@ module Boot
|
||||
raise "uups #{name}.#{name.class}" unless name.is_a? Symbol
|
||||
c = @classes[name]
|
||||
unless c
|
||||
c = BootClass.new(name,@context)
|
||||
c = BootClass.new(name)
|
||||
@classes[name] = c
|
||||
end
|
||||
c
|
||||
|
@ -1,4 +1,5 @@
|
||||
require_relative "object"
|
||||
|
||||
module Virtual
|
||||
# static description of a method
|
||||
# name
|
||||
@ -11,12 +12,12 @@ module Virtual
|
||||
class Method < Virtual::Object
|
||||
#return the main function (the top level) into which code is compiled
|
||||
def Method.main
|
||||
Method.new(:main)
|
||||
Method.new(:main , [] , Virtual::SelfReference )
|
||||
end
|
||||
def attributes
|
||||
[:name , :args]
|
||||
[:name , :args , :receiver]
|
||||
end
|
||||
def initialize name , args = [] , receiver = Virtual::Reference , return_type = Virtual::Reference
|
||||
def initialize name , args , receiver = Virtual::SelfReference.new , return_type = Virtual::Reference
|
||||
@name = name.to_sym
|
||||
@args = args
|
||||
@locals = []
|
||||
@ -25,7 +26,7 @@ module Virtual
|
||||
@start = MethodEnter.new
|
||||
@current = @start
|
||||
end
|
||||
attr_reader :name , :args
|
||||
attr_reader :name , :args , :receiver
|
||||
|
||||
def add instruction
|
||||
@current.next = instruction
|
||||
|
@ -12,6 +12,8 @@ module Virtual
|
||||
block.ldr( self , left , right )
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
class SelfReference < Reference
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ def foo(x)
|
||||
5
|
||||
end
|
||||
HERE
|
||||
@output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])]
|
||||
@output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)],Virtual::SelfReference.new())]
|
||||
check
|
||||
end
|
||||
|
||||
@ -19,9 +19,8 @@ def String.length(x)
|
||||
@length
|
||||
end
|
||||
HERE
|
||||
@parse_output = {:receiver=>{:module_name=>"String"}, :function_name=>{:name=>"length"}, :parameter_list=>[{:parameter=>{: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") )
|
||||
@parser = @parser.function_definition
|
||||
@output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object))]
|
||||
check
|
||||
end
|
||||
|
||||
def test_function_ops
|
||||
|
Loading…
Reference in New Issue
Block a user