rename singleton_class to single_class and misc
was clashing with real ruby method name also many superclass mismatch fixes some misc
This commit is contained in:
parent
dd810cfc49
commit
3df54910cc
@ -52,7 +52,6 @@ module Parfait
|
|||||||
|
|
||||||
def get_instance_method( fname )
|
def get_instance_method( fname )
|
||||||
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
||||||
#if we had a hash this would be easier. Detect or find would help too
|
|
||||||
@instance_methods.find {|m| m.name == fname }
|
@instance_methods.find {|m| m.name == fname }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class Class < Behaviour
|
class Class < Behaviour
|
||||||
|
|
||||||
attr_reader :name , :super_class_name , :singleton_class
|
attr_reader :name , :super_class_name , :single_class
|
||||||
|
|
||||||
def self.type_length
|
def self.type_length
|
||||||
6
|
6
|
||||||
@ -30,7 +30,7 @@ module Parfait
|
|||||||
super(instance_type)
|
super(instance_type)
|
||||||
@name = name
|
@name = name
|
||||||
@super_class_name = superclass
|
@super_class_name = superclass
|
||||||
@singleton_class = SingletonClass.new( self , self.type || @name)
|
@single_class = SingletonClass.new( self , self.type || @name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rxf_reference_name
|
def rxf_reference_name
|
||||||
|
@ -51,7 +51,7 @@ module Parfait
|
|||||||
classes.each do |name , cl|
|
classes.each do |name , cl|
|
||||||
object_type = Parfait.object_space.get_type_by_class_name(name)
|
object_type = Parfait.object_space.get_type_by_class_name(name)
|
||||||
raise "nil type" unless object_type
|
raise "nil type" unless object_type
|
||||||
cl.singleton_class.instance_eval{ @instance_type = class_type}
|
cl.single_class.instance_eval{ @instance_type = class_type}
|
||||||
cl.instance_eval{ @instance_type = object_type}
|
cl.instance_eval{ @instance_type = object_type}
|
||||||
cl.instance_eval{ @super_class_name = super_names[name] || :Object}
|
cl.instance_eval{ @super_class_name = super_names[name] || :Object}
|
||||||
object_type.instance_eval{ @object_class = cl }
|
object_type.instance_eval{ @object_class = cl }
|
||||||
@ -79,6 +79,9 @@ module Parfait
|
|||||||
Data16: :DataObject ,
|
Data16: :DataObject ,
|
||||||
Data32: :DataObject ,
|
Data32: :DataObject ,
|
||||||
BinaryCode: :Data32 ,
|
BinaryCode: :Data32 ,
|
||||||
|
TrueClass: :Data4 ,
|
||||||
|
FalseClass: :Data4 ,
|
||||||
|
NilClass: :Data4 ,
|
||||||
Integer: :Data4 ,
|
Integer: :Data4 ,
|
||||||
Word: :Data8 ,
|
Word: :Data8 ,
|
||||||
List: :Data16 ,
|
List: :Data16 ,
|
||||||
@ -106,7 +109,7 @@ module Parfait
|
|||||||
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
||||||
name: :Word , blocks: :Block} ,
|
name: :Word , blocks: :Block} ,
|
||||||
Class: {instance_methods: :List, instance_type: :Type,
|
Class: {instance_methods: :List, instance_type: :Type,
|
||||||
name: :Word, super_class_name: :Word , singleton_class: :SingletonClass},
|
name: :Word, super_class_name: :Word , single_class: :SingletonClass},
|
||||||
DataObject: {},
|
DataObject: {},
|
||||||
Data4: {},
|
Data4: {},
|
||||||
Data8: {},
|
Data8: {},
|
||||||
|
@ -71,7 +71,11 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
at_depth(depth , "class #{name}" , @body.to_s(depth + 1) , "end")
|
at_depth(depth , "class #{name} #{super_s}\n#{@body.to_s(depth + 1)}\nend")
|
||||||
|
end
|
||||||
|
# deriviation if apropriate
|
||||||
|
def super_s
|
||||||
|
@super_class_name ? " < #{@super_class_name}" : ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ module Ruby
|
|||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
arg_str = @args.collect{|a| a.to_s}.join(', ')
|
arg_str = @args.collect{|a| a.to_s}.join(', ')
|
||||||
at_depth(depth , "def #{name}(#{arg_str})" , @body.to_s(depth + 1) , "end")
|
at_depth(depth , "def #{name}(#{arg_str})\n #{@body.to_s(1)}\nend")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,7 @@ module Vool
|
|||||||
when MethodExpression
|
when MethodExpression
|
||||||
node.to_mom(@clazz)
|
node.to_mom(@clazz)
|
||||||
when ClassMethodExpression
|
when ClassMethodExpression
|
||||||
node.to_mom(@clazz.singleton_class)
|
node.to_mom(@clazz.single_class)
|
||||||
else
|
else
|
||||||
raise "Only methods for now #{node.class}:#{node}"
|
raise "Only methods for now #{node.class}:#{node}"
|
||||||
end
|
end
|
||||||
@ -78,7 +78,7 @@ module Vool
|
|||||||
when MethodExpression
|
when MethodExpression
|
||||||
target = @clazz
|
target = @clazz
|
||||||
when ClassMethodExpression
|
when ClassMethodExpression
|
||||||
target = @clazz.singleton_class
|
target = @clazz.single_class
|
||||||
else
|
else
|
||||||
raise "Only methods for now #{node.class}:#{node}"
|
raise "Only methods for now #{node.class}:#{node}"
|
||||||
end
|
end
|
||||||
|
@ -12,11 +12,11 @@ module Vool
|
|||||||
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
||||||
def to_parfait( clazz = nil )
|
def to_parfait( clazz = nil )
|
||||||
raise "No class given to class method #{name}" unless clazz
|
raise "No class given to class method #{name}" unless clazz
|
||||||
clazz.add_instance_method_for(name , make_arg_type , make_frame , body )
|
clazz.single_class.add_instance_method_for(name , make_arg_type , make_frame , body )
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_mom(clazz)
|
def to_mom(clazz)
|
||||||
raise "not singleton" unless clazz.class == Parfait::SingletonClass
|
raise "not singleton #{clazz.class}" unless clazz.class == Parfait::SingletonClass
|
||||||
raise( "no class in #{self}") unless clazz
|
raise( "no class in #{self}") unless clazz
|
||||||
method = clazz.get_instance_method(name )
|
method = clazz.get_instance_method(name )
|
||||||
raise( "no class method in #{@name} in #{clazz}") unless method
|
raise( "no class method in #{@name} in #{clazz}") unless method
|
||||||
|
@ -49,7 +49,7 @@ module Vool
|
|||||||
class ModuleName < Expression
|
class ModuleName < Expression
|
||||||
include Named
|
include Named
|
||||||
def ct_type
|
def ct_type
|
||||||
get_named_class.singleton_class.instance_type
|
get_named_class.single_class.instance_type
|
||||||
end
|
end
|
||||||
def to_slot(_)
|
def to_slot(_)
|
||||||
return Mom::SlotDefinition.new( get_named_class, [])
|
return Mom::SlotDefinition.new( get_named_class, [])
|
||||||
|
@ -6,7 +6,7 @@ module Elf
|
|||||||
def test_string_put
|
def test_string_put
|
||||||
hello = "Hello World!\n"
|
hello = "Hello World!\n"
|
||||||
input = "return '#{hello}'.putstring"
|
input = "return '#{hello}'.putstring"
|
||||||
preload = "class Word;def putstring;X.putstring;end;end;"
|
preload = "class Word < Data8;def putstring;X.putstring;end;end;"
|
||||||
@stdout = hello
|
@stdout = hello
|
||||||
@exit_code = hello.length
|
@exit_code = hello.length
|
||||||
check preload + as_main(input), "hello"
|
check preload + as_main(input), "hello"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class Class
|
class Class < Behaviour
|
||||||
def name
|
def name
|
||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@ module Mains
|
|||||||
|
|
||||||
def whole_input
|
def whole_input
|
||||||
<<-eos
|
<<-eos
|
||||||
class Class
|
class Class < Behaviour
|
||||||
def get_name
|
def get_name
|
||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Parfait
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@try = @space.create_class( :Try , :Object).singleton_class
|
@try = @space.create_class( :Try , :Object).single_class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_type_forclass
|
def test_type_forclass
|
||||||
|
@ -28,7 +28,7 @@ module Parfait
|
|||||||
assert_equal Parfait::Class , space_class.class
|
assert_equal Parfait::Class , space_class.class
|
||||||
end
|
end
|
||||||
def test_get_singleton_class
|
def test_get_singleton_class
|
||||||
assert_equal Parfait::SingletonClass , space_class.singleton_class.class
|
assert_equal Parfait::SingletonClass , space_class.single_class.class
|
||||||
end
|
end
|
||||||
def test_get_type_by_class_name
|
def test_get_type_by_class_name
|
||||||
assert_equal Parfait::Type , Parfait.object_space.get_type_by_class_name(:Space).class
|
assert_equal Parfait::Type , Parfait.object_space.get_type_by_class_name(:Space).class
|
||||||
@ -74,7 +74,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
def test_all_singletons
|
def test_all_singletons
|
||||||
@space.classes.each do |name , clazz|
|
@space.classes.each do |name , clazz|
|
||||||
assert clazz.singleton_class , clazz.name
|
assert clazz.single_class , clazz.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_has_factory
|
def test_has_factory
|
||||||
|
@ -19,7 +19,6 @@ module Risc
|
|||||||
MAIN
|
MAIN
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
#Space type is wrong, shold be same as singleton_class.instance_type
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_main_ticks # get output of what is
|
#show_main_ticks # get output of what is
|
||||||
run_input @string_input
|
run_input @string_input
|
||||||
|
@ -15,6 +15,7 @@ module RubyX
|
|||||||
end
|
end
|
||||||
def compile_in_test( input , options = {})
|
def compile_in_test( input , options = {})
|
||||||
vool = ruby_to_vool(in_Test(input) , options)
|
vool = ruby_to_vool(in_Test(input) , options)
|
||||||
|
vool.to_parfait
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
itest = Parfait.object_space.get_class_by_name(:Test)
|
itest = Parfait.object_space.get_class_by_name(:Test)
|
||||||
assert itest
|
assert itest
|
||||||
@ -23,7 +24,7 @@ module RubyX
|
|||||||
end
|
end
|
||||||
module ParfaitHelper
|
module ParfaitHelper
|
||||||
include Preloader
|
include Preloader
|
||||||
|
|
||||||
def load_parfait(file)
|
def load_parfait(file)
|
||||||
File.read File.expand_path("../../../lib/parfait/#{file}.rb",__FILE__)
|
File.read File.expand_path("../../../lib/parfait/#{file}.rb",__FILE__)
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module RubyX
|
|||||||
def len ; 25 ; end
|
def len ; 25 ; end
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Integer
|
class Integer < Data4
|
||||||
def #{op}(other)
|
def #{op}(other)
|
||||||
X.comparison(:"#{op}")
|
X.comparison(:"#{op}")
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Integer
|
class Integer < Data4
|
||||||
def div10
|
def div10
|
||||||
X.div10
|
X.div10
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Integer
|
class Integer < Data4
|
||||||
def div4
|
def div4
|
||||||
X.div4
|
X.div4
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ module RubyX
|
|||||||
def op ; :+ ; end
|
def op ; :+ ; end
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Integer
|
class Integer < Data4
|
||||||
def #{op}(other)
|
def #{op}(other)
|
||||||
X.int_operator(:"#{op}")
|
X.int_operator(:"#{op}")
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Word
|
class Word < Data8
|
||||||
def get_internal_byte(at)
|
def get_internal_byte(at)
|
||||||
X.get_internal_byte
|
X.get_internal_byte
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Word
|
class Word < Data8
|
||||||
def putstring
|
def putstring
|
||||||
X.putstring
|
X.putstring
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Word
|
class Word < Data8
|
||||||
def set_internal_byte( at , value)
|
def set_internal_byte( at , value)
|
||||||
X.set_internal_byte
|
X.set_internal_byte
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
source = "class Integer;def +(other);X.int_operator(:+);end;end;" + class_main
|
source = "class Integer<Data4;def +(other);X.int_operator(:+);end;end;" + class_main
|
||||||
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
||||||
@ins = ret.compilers.find{|c|c.callable.name==:main}.mom_instructions.next
|
@ins = ret.compilers.find{|c|c.callable.name==:main}.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ module Vool
|
|||||||
def test_class_inst
|
def test_class_inst
|
||||||
space_class = Parfait.object_space.get_class
|
space_class = Parfait.object_space.get_class
|
||||||
assert_equal :Space , space_class.name
|
assert_equal :Space , space_class.name
|
||||||
names = space_class.singleton_class.instance_type.names
|
names = space_class.single_class.instance_type.names
|
||||||
assert names.index_of(:inst) , names
|
assert names.index_of(:inst) , names
|
||||||
end
|
end
|
||||||
def test_compiler
|
def test_compiler
|
||||||
|
@ -7,7 +7,7 @@ module Vool
|
|||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
||||||
class Object
|
class Space
|
||||||
def self.one_plus()
|
def self.one_plus()
|
||||||
return 1 + 1
|
return 1 + 1
|
||||||
end
|
end
|
||||||
|
@ -12,14 +12,16 @@ module VoolBlocks
|
|||||||
def test_block_not_compiles
|
def test_block_not_compiles
|
||||||
source = "main{|val| val = 0}"
|
source = "main{|val| val = 0}"
|
||||||
vool = Ruby::RubyCompiler.compile( as_class_method(source) ).to_vool
|
vool = Ruby::RubyCompiler.compile( as_class_method(source) ).to_vool
|
||||||
|
vool.to_parfait
|
||||||
begin
|
begin
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
rescue => err
|
rescue => err
|
||||||
assert err.message.include?("Blocks") , err.message
|
assert err.message.include?("Blocks") , err.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_assign_compiles
|
def test_assign_compiles
|
||||||
vool = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_vool
|
vool = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_vool
|
||||||
|
vool.to_parfait
|
||||||
assert_equal Mom::MomCollection , vool.to_mom(nil).class
|
assert_equal Mom::MomCollection , vool.to_mom(nil).class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestClassStatement #< MiniTest::Test
|
class TestClassStatement < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ -26,7 +26,7 @@ module Vool
|
|||||||
assert_equal :a , @vool.to_parfait.instance_type.names[1]
|
assert_equal :a , @vool.to_parfait.instance_type.names[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestClassStatementTypeCreation #< MiniTest::Test
|
class TestClassStatementTypeCreation < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
|
39
test/vool/test_class_method_expression.rb
Normal file
39
test/vool/test_class_method_expression.rb
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Vool
|
||||||
|
class TestClassMethodExpression < MiniTest::Test
|
||||||
|
include VoolCompile
|
||||||
|
|
||||||
|
def class_code
|
||||||
|
"class Space;def self.meth;return 1 ; end;end"
|
||||||
|
end
|
||||||
|
def setup
|
||||||
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
|
ruby_tree = Ruby::RubyCompiler.compile( class_code )
|
||||||
|
@clazz = ruby_tree.to_vool
|
||||||
|
end
|
||||||
|
def method
|
||||||
|
@clazz.body.first
|
||||||
|
end
|
||||||
|
def test_setup
|
||||||
|
assert_equal ClassExpression , @clazz.class
|
||||||
|
assert_equal Statements , @clazz.body.class
|
||||||
|
assert_equal ClassMethodExpression , method.class
|
||||||
|
end
|
||||||
|
def test_fail
|
||||||
|
assert_raises{ method.to_parfait }
|
||||||
|
end
|
||||||
|
def test_method
|
||||||
|
clazz = @clazz.to_parfait
|
||||||
|
assert_equal Parfait::Class , clazz.class
|
||||||
|
meth = method.to_parfait(clazz)
|
||||||
|
assert_equal Parfait::VoolMethod , meth.class
|
||||||
|
assert_equal :meth , meth.name
|
||||||
|
end
|
||||||
|
def test_is_class_method
|
||||||
|
clazz = @clazz.to_parfait
|
||||||
|
m = clazz.single_class.get_instance_method(:meth)
|
||||||
|
assert m , "no method :meth"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestMethodStatement < MiniTest::Test
|
class TestMethodExpression < MiniTest::Test
|
||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -23,7 +23,12 @@ module Vool
|
|||||||
def test_method
|
def test_method
|
||||||
clazz = @clazz.to_parfait
|
clazz = @clazz.to_parfait
|
||||||
assert_equal Parfait::Class , clazz.class
|
assert_equal Parfait::Class , clazz.class
|
||||||
assert_equal Parfait::VoolMethod , method.to_parfait(clazz).class
|
meth = method.to_parfait(clazz)
|
||||||
|
assert_equal Parfait::VoolMethod , meth.class
|
||||||
|
assert_equal :main , meth.name
|
||||||
|
end
|
||||||
|
def test_is_instance_method
|
||||||
|
assert main = @clazz.to_parfait.get_instance_method(:main)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user