function test, slow but steady

This commit is contained in:
Torsten Ruger 2014-07-14 14:06:09 +03:00
parent 122452c21b
commit db8b1488d0
7 changed files with 21 additions and 19 deletions

View File

@ -48,7 +48,7 @@ module Ast
clazz = ::Virtual::Object.space.get_or_create_class name clazz = ::Virtual::Object.space.get_or_create_class name
raise "uups #{clazz}.#{name}" unless clazz raise "uups #{clazz}.#{name}" unless clazz
#class qualifier, means call from metaclass #class qualifier, means call from metaclass
clazz = clazz.meta_class #clazz = clazz.meta_class
clazz clazz
end end
end end

View File

@ -2,7 +2,9 @@ module Ast
class FunctionExpression < Expression class FunctionExpression < Expression
# attr_reader :name, :params, :body , :receiver # attr_reader :name, :params, :body , :receiver
def compile frame , method 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 end
def scratch def scratch
args = [] args = []

View File

@ -4,9 +4,8 @@ module Boot
# class is mainly a list of methods with a name (for now) # class is mainly a list of methods with a name (for now)
# layout of object is seperated into Layout # layout of object is seperated into Layout
class BootClass < Virtual::ObjectConstant class BootClass < Virtual::ObjectConstant
def initialize name , scope , super_class = :Object def initialize name , super_class = :Object
super() super()
@scope = scope
# class methods # class methods
@methods = [] @methods = []
@name = name.to_sym @name = name.to_sym
@ -14,7 +13,9 @@ module Boot
@meta_class = MetaClass.new(self) @meta_class = MetaClass.new(self)
end end
attr_reader :name , :methods , :meta_class , :context , :super_class attr_reader :name , :methods , :meta_class , :context , :super_class
def attributes
[:name , :super_class]
end
def add_method method def add_method method
raise "not a method #{method}" unless method.is_a? Virtual::Method raise "not a method #{method}" unless method.is_a? Virtual::Method
raise "syserr " unless method.name.is_a? Symbol raise "syserr " unless method.name.is_a? Symbol
@ -40,9 +41,6 @@ module Boot
fun fun
end end
def inspect
"BootClass #{@name} < #{@super_class}:#{@methods.collect(&:name)}"
end
def to_s def to_s
inspect inspect
end end

View File

@ -21,7 +21,7 @@ module Boot
def initialize machine = nil def initialize machine = nil
super() super()
@classes = {} @classes = {}
@main = Virtual::Method.new("main") @main = Virtual::Method.new("main" , [] )
#global objects (data) #global objects (data)
@objects = [] @objects = []
boot_classes boot_classes
@ -77,7 +77,7 @@ module Boot
raise "uups #{name}.#{name.class}" 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)
@classes[name] = c @classes[name] = c
end end
c c

View File

@ -1,4 +1,5 @@
require_relative "object" require_relative "object"
module Virtual module Virtual
# static description of a method # static description of a method
# name # name
@ -11,12 +12,12 @@ module Virtual
class Method < Virtual::Object class Method < Virtual::Object
#return the main function (the top level) into which code is compiled #return the main function (the top level) into which code is compiled
def Method.main def Method.main
Method.new(:main) Method.new(:main , [] , Virtual::SelfReference )
end end
def attributes def attributes
[:name , :args] [:name , :args , :receiver]
end 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 @name = name.to_sym
@args = args @args = args
@locals = [] @locals = []
@ -25,7 +26,7 @@ module Virtual
@start = MethodEnter.new @start = MethodEnter.new
@current = @start @current = @start
end end
attr_reader :name , :args attr_reader :name , :args , :receiver
def add instruction def add instruction
@current.next = instruction @current.next = instruction

View File

@ -12,6 +12,8 @@ module Virtual
block.ldr( self , left , right ) block.ldr( self , left , right )
self self
end end
end
class SelfReference < Reference
end end
end end

View File

@ -9,7 +9,7 @@ def foo(x)
5 5
end end
HERE HERE
@output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)],Virtual::SelfReference.new())]
check check
end end
@ -19,9 +19,8 @@ def String.length(x)
@length @length
end end
HERE HERE
@parse_output = {:receiver=>{:module_name=>"String"}, :function_name=>{:name=>"length"}, :parameter_list=>[{:parameter=>{:name=>"x"}}], :expressions=>[{:instance_variable=>{:name=>"length"}}], :end=>"end"} @output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object))]
@transform_output = Ast::FunctionExpression.new(:length, [Ast::NameExpression.new("x")] , [Ast::VariableExpression.new(:length)] ,Ast::ModuleName.new("String") ) check
@parser = @parser.function_definition
end end
def test_function_ops def test_function_ops