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/binary_code"
|
||||
require_relative "parfait/typed_method"
|
||||
require_relative "parfait/vool_method"
|
||||
require_relative "parfait/dictionary"
|
||||
require_relative "parfait/type"
|
||||
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 class carries the "current" type, ie the type an object would be if you created an instance
|
||||
@ -36,6 +36,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def add_method(method)
|
||||
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||
@methods[method.name] = method
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
# A TypedMethod is static object that primarily holds the executable code.
|
||||
# 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,
|
||||
# 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
|
||||
|
||||
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 "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 "source must be vool" unless source.is_a?(Vool::Statement)
|
||||
end
|
||||
|
||||
def normalize_source
|
@ -1,2 +1 @@
|
||||
require_relative "vool/vool_compiler"
|
||||
require_relative "vool/vool_method"
|
||||
|
@ -1,6 +1,7 @@
|
||||
# VOOL
|
||||
|
||||
Virtual Object Oriented Language
|
||||
--------------------------------
|
||||
|
||||
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
|
||||
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
|
||||
down to the Risc layer moves to an instruction stream.
|
||||
|
||||
|
@ -31,9 +31,16 @@ module Vool
|
||||
def create_objects
|
||||
args_type = make_type
|
||||
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 )
|
||||
# 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
|
||||
|
||||
private
|
||||
@ -52,23 +59,5 @@ module Vool
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
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
|
||||
|
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 )
|
||||
assert_equal Parfait::Class , lst.clazz.class , input
|
||||
@method = lst.clazz.get_method(:main)
|
||||
assert @method
|
||||
assert_equal Parfait::VoolMethod , @method.class
|
||||
res = lst.to_mom( nil )
|
||||
#puts "#{res.class}"
|
||||
res.first
|
||||
@ -40,7 +40,7 @@ module MomCompile
|
||||
test = is
|
||||
while(test)
|
||||
# if we assert here, we get output pointing here. Without stack, not useful
|
||||
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
||||
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
||||
index += 1
|
||||
test = test.next
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ module Vool
|
||||
def test_creates_method_in_class
|
||||
method = create_method
|
||||
assert method , "No method created"
|
||||
assert_equal Vool::VoolMethod , method.class
|
||||
assert_equal Parfait::VoolMethod , method.class
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user