moving vool_method to parfait
This commit is contained in:
parent
b7701d0d5e
commit
bc5906fb83
@ -10,6 +10,7 @@ require_relative "parfait/list"
|
|||||||
require_relative "parfait/word"
|
require_relative "parfait/word"
|
||||||
require_relative "parfait/binary_code"
|
require_relative "parfait/binary_code"
|
||||||
require_relative "parfait/typed_method"
|
require_relative "parfait/typed_method"
|
||||||
|
require_relative "parfait/vool_method"
|
||||||
require_relative "parfait/dictionary"
|
require_relative "parfait/dictionary"
|
||||||
require_relative "parfait/type"
|
require_relative "parfait/type"
|
||||||
require_relative "parfait/message"
|
require_relative "parfait/message"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Class is mainly a list of methods with a name. The methods are untyped.
|
# Class is mainly a list of methods with a name. The methods are untyped, sis Vool.
|
||||||
|
|
||||||
# The memory layout of an object is determined by the Type (see there).
|
# The memory layout of an object is determined by the Type (see there).
|
||||||
# The class carries the "current" type, ie the type an object would be if you created an instance
|
# The class carries the "current" type, ie the type an object would be if you created an instance
|
||||||
@ -36,6 +36,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_method(method)
|
def add_method(method)
|
||||||
|
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||||
@methods[method.name] = method
|
@methods[method.name] = method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# A TypedMethod is static object that primarily holds the executable code.
|
# A TypedMethod is static object that primarily holds the executable code.
|
||||||
# It is called typed, because all arguments and variables it uses are typed.
|
# It is called typed, because all arguments and variables it uses are typed.
|
||||||
# (Type means basic type, ie integer or reference)
|
|
||||||
|
|
||||||
# It's relation to the method a ruby programmer knows (called RubyMethod) is many to one,
|
# It's relation to the method a ruby programmer knows (called RubyMethod) is many to one,
|
||||||
# meaning one RubyMethod (untyped) has many TypedMethod implementations.
|
# meaning one RubyMethod (untyped) has many TypedMethod implementations.
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
module Vool
|
module Parfait
|
||||||
|
|
||||||
|
# This represents the method at source code level (sis vool)
|
||||||
|
#
|
||||||
|
# Type objects are already created for args and locals, but the main attribute
|
||||||
|
# is the source, which is a Vool::Statement
|
||||||
|
#
|
||||||
|
# Classes store VoolMethods, while Types store TypedMethod
|
||||||
|
# A Type referes to a Class , but a Class (interface) is implemented by many types
|
||||||
|
# as it changes during the course of it's life. Types do not change. Objects have
|
||||||
|
# type, and so only indirectly a class.
|
||||||
|
#
|
||||||
class VoolMethod
|
class VoolMethod
|
||||||
|
|
||||||
attr_reader :name , :args_type , :locals_type , :source
|
attr_reader :name , :args_type , :locals_type , :source
|
||||||
@ -9,6 +19,7 @@ module Vool
|
|||||||
raise "Name must be symbol" unless name.is_a?(Symbol)
|
raise "Name must be symbol" unless name.is_a?(Symbol)
|
||||||
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
||||||
raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type)
|
raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type)
|
||||||
|
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_source
|
def normalize_source
|
@ -1,2 +1 @@
|
|||||||
require_relative "vool/vool_compiler"
|
require_relative "vool/vool_compiler"
|
||||||
require_relative "vool/vool_method"
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# VOOL
|
# VOOL
|
||||||
|
|
||||||
Virtual Object Oriented Language
|
Virtual Object Oriented Language
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
in other words, ruby without the fluff.
|
in other words, ruby without the fluff.
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ Possibly later other languages can compile to this level, eg by running in the s
|
|||||||
Vool is the layer of concrete syntax tree. The Parser gem is used to parse ruby. It creates
|
Vool is the layer of concrete syntax tree. The Parser gem is used to parse ruby. It creates
|
||||||
an abstract syntax tree which is then transformed.
|
an abstract syntax tree which is then transformed.
|
||||||
|
|
||||||
The next layer down is the Vom, Virtual object Machine, which uses an instruction tree.
|
The next layer down is the Mom, Minimal object Machine, which uses an instruction tree.
|
||||||
That is on the way down we create instructions, but stay in tree format. Only the next step
|
That is on the way down we create instructions, but stay in tree format. Only the next step
|
||||||
down to the Risc layer moves to an instruction stream.
|
down to the Risc layer moves to an instruction stream.
|
||||||
|
|
||||||
|
@ -31,9 +31,16 @@ module Vool
|
|||||||
def create_objects
|
def create_objects
|
||||||
args_type = make_type
|
args_type = make_type
|
||||||
locals_type = make_locals
|
locals_type = make_locals
|
||||||
method = Vool::VoolMethod.new(name , args_type , locals_type , body )
|
method = Parfait::VoolMethod.new(name , args_type , locals_type , body )
|
||||||
@clazz.add_method( method )
|
@clazz.add_method( method )
|
||||||
# compile_methods(clazz,methods)
|
end
|
||||||
|
|
||||||
|
def compile_methods(clazz , methods)
|
||||||
|
methods.each do |method|
|
||||||
|
code = Passes::MethodCompiler.new(method).get_code
|
||||||
|
typed_method = method.create_parfait_method(clazz.instance_type)
|
||||||
|
Vm::MethodCompiler.new( typed_method ).init_method.process( code )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -52,23 +59,5 @@ module Vool
|
|||||||
Parfait::NamedList.type_for( type_hash )
|
Parfait::NamedList.type_for( type_hash )
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_methods(clazz , body)
|
|
||||||
methods = Passes::MethodCollector.new.collect(body)
|
|
||||||
methods.each do |method|
|
|
||||||
clazz.add_method( method )
|
|
||||||
normalizer = Passes::Normalizer.new(method)
|
|
||||||
method.normalize_source { |sourc| normalizer.process( sourc ) }
|
|
||||||
end
|
|
||||||
methods
|
|
||||||
end
|
|
||||||
|
|
||||||
def compile_methods(clazz , methods)
|
|
||||||
methods.each do |method|
|
|
||||||
code = Passes::MethodCompiler.new(method).get_code
|
|
||||||
typed_method = method.create_parfait_method(clazz.instance_type)
|
|
||||||
Vm::MethodCompiler.new( typed_method ).init_method.process( code )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
26
test/fragments/test_adds.rb
Normal file
26
test/fragments/test_adds.rb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#require_relative 'helper'
|
||||||
|
|
||||||
|
module Rubyx
|
||||||
|
class TestRubyAdds < MiniTest::Test
|
||||||
|
# include RubyxTests
|
||||||
|
|
||||||
|
def pest_ruby_adds
|
||||||
|
@string_input = <<HERE
|
||||||
|
def fibo( n)
|
||||||
|
a = 0
|
||||||
|
b = 1
|
||||||
|
i = 1
|
||||||
|
while( i < n ) do
|
||||||
|
result = a + b
|
||||||
|
a = b
|
||||||
|
b = result
|
||||||
|
i+= 1
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@stdout = "Hello there"
|
||||||
|
check
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -25,7 +25,7 @@ module MomCompile
|
|||||||
lst = Vool::VoolCompiler.compile as_test_main( input )
|
lst = Vool::VoolCompiler.compile as_test_main( input )
|
||||||
assert_equal Parfait::Class , lst.clazz.class , input
|
assert_equal Parfait::Class , lst.clazz.class , input
|
||||||
@method = lst.clazz.get_method(:main)
|
@method = lst.clazz.get_method(:main)
|
||||||
assert @method
|
assert_equal Parfait::VoolMethod , @method.class
|
||||||
res = lst.to_mom( nil )
|
res = lst.to_mom( nil )
|
||||||
#puts "#{res.class}"
|
#puts "#{res.class}"
|
||||||
res.first
|
res.first
|
||||||
|
@ -33,7 +33,7 @@ module Vool
|
|||||||
def test_creates_method_in_class
|
def test_creates_method_in_class
|
||||||
method = create_method
|
method = create_method
|
||||||
assert method , "No method created"
|
assert method , "No method created"
|
||||||
assert_equal Vool::VoolMethod , method.class
|
assert_equal Parfait::VoolMethod , method.class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user