diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index e8d8f15b..7be2efa4 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -7,7 +7,7 @@ module Ast Virtual::Argument.new( p.name , Virtual::Mystery.new ) end r = receiver ? receiver.compile(frame,method) : Virtual::SelfReference.new - method = Virtual::Method.new(name , args , r ) + method = Virtual::MethodDefinition.new(name , args , r ) frame = frame.new_frame return_type = nil body.each do |ex| diff --git a/lib/boot/boot_class.rb b/lib/boot/boot_class.rb index 37dc7920..cc221628 100644 --- a/lib/boot/boot_class.rb +++ b/lib/boot/boot_class.rb @@ -4,28 +4,28 @@ 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 , super_class = :Object + def initialize name , super_class_name = :Object super() # class methods - @methods = [] + @method_definitions = [] @name = name.to_sym - @super_class = super_class + @super_class_name = super_class_name.to_sym @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 + def add_method_definition method + raise "not a method #{method}" unless method.is_a? Virtual::MethodDefinition raise "syserr " unless method.name.is_a? Symbol - @methods << method + @method_definitions << method end - def get_method fname + def get_method_definition fname fname = fname.to_sym - f = @methods.detect{ |f| f.name == fname } - names = @methods.collect{|f| f.name } + f = @method_definitions.detect{ |f| f.name == fname } + names = @method_definitions.collect{|f| f.name } f end @@ -33,7 +33,7 @@ module Boot def resolve_method name fun = get_method name unless fun or name == :Object - supr = @context.object_space.get_or_create_class(@super_class) + supr = @context.object_space.get_or_create_class(@super_class_name) fun = supr.get_method name puts "#{supr.methods.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of end diff --git a/lib/boot/boot_space.rb b/lib/boot/boot_space.rb index 3010b1fb..20cb11e4 100644 --- a/lib/boot/boot_space.rb +++ b/lib/boot/boot_space.rb @@ -5,13 +5,13 @@ require "boot/object" require "boot/string" module Boot - # The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo + # The BootSpace contains all objects for a program. In functional terms it is a program, but in oo # it is a collection of objects, some of which are data, some classes, some functions # The main entry is a function called (of all things) "main", This _must be supplied by the compling # There is a start and exit block that call main, which receives an array of strings - # While data "ususally" would live in a .data section, we may also "inline" it into the code + # While data ususally would live in a .data section, we may also "inline" it into the code # in an oo system all data is represented as objects class BootSpace @@ -21,7 +21,7 @@ module Boot def initialize machine = nil super() @classes = {} - @main = Virtual::Method.new("main" , [] ) + @main = Virtual::MethodDefinition.new("main" , [] ) #global objects (data) @objects = [] boot_classes @@ -43,24 +43,24 @@ module Boot # boot the classes, ie create a minimal set of classes with a minimal set of functions # minimal means only that which can not be coded in ruby - # Functions are grabbed from respective modules by sending the sunction name. This should return the - # implementation of the function (ie a function object), not actually try to implement it (as that's impossible in ruby) + # MethodDefinitions are grabbed from respective modules by sending the method name. This should return the + # implementation of the method (ie a method object), not actually try to implement it (as that's impossible in ruby) def boot_classes # very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we have to define some # dummies, just for the other to compile obj = get_or_create_class :Object [:index_of , :_get_instance_variable , :_set_instance_variable].each do |f| #puts "Boot Object::#{f}" - obj.add_method Boot::Object.send(f , @context) + obj.add_method_definition Boot::Object.send(f , @context) end [:putstring,:putint,:fibo,:exit].each do |f| #puts "Boot Kernel::#{f}" - obj.add_method Crystal::Kernel.send(f , @context) + obj.add_method_definition Crystal::Kernel.send(f , @context) end obj = get_or_create_class :String [:get , :set].each do |f| #puts "Boot String::#{f}" - obj.add_method Boot::String.send(f , @context) + obj.add_method_definition Boot::String.send(f , @context) end end diff --git a/lib/boot/object.rb b/lib/boot/object.rb index 7405c711..5e334a58 100644 --- a/lib/boot/object.rb +++ b/lib/boot/object.rb @@ -6,7 +6,7 @@ module Boot # set/get instance variable use it. # This is just a placeholder, as we code this in ruby, but the instance methods need the definition before. def index_of context , name = Virtual::Integer - index_function = Virtual::Method.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer ) + index_function = Virtual::MethodDefinition.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer ) return index_function end @@ -23,7 +23,7 @@ module Boot # end # The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby def _get_instance_variable context , name = Virtual::Integer - get_function = Virtual::Method.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery ) + get_function = Virtual::MethodDefinition.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery ) return get_function me = get_function.receiver var_name = get_function.args.first @@ -44,7 +44,7 @@ module Boot end def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer ) - set_function = Virtual::Method.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery ) + set_function = Virtual::MethodDefinition.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery ) return set_function receiver set_function me = set_function.receiver diff --git a/lib/boot/string.rb b/lib/boot/string.rb index 3917fef7..cc12f462 100644 --- a/lib/boot/string.rb +++ b/lib/boot/string.rb @@ -2,11 +2,11 @@ module Boot class String module ClassMethods def get context , index = Virtual::Integer - get_function = Virtual::Method.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer ) + get_function = Virtual::MethodDefinition.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer ) return get_function end def set context , index = Virtual::Integer , char = Virtual::Integer - set_function = Virtual::Method.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer ) + set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer ) return set_function end end diff --git a/lib/kernel/integer.rb b/lib/kernel/integer.rb index 87368ef3..ea691648 100644 --- a/lib/kernel/integer.rb +++ b/lib/kernel/integer.rb @@ -7,7 +7,7 @@ module Crystal # As we write before we recurse (save a push) we write the number backwards # arguments: string address , integer def self.utoa context - utoa_function = Virtual::Method.new(:utoa , [ Virtual::Integer ] , Virtual::Integer ,Virtual::Integer ) + utoa_function = Virtual::MethodDefinition.new(:utoa , [ Virtual::Integer ] , Virtual::Integer ,Virtual::Integer ) return utoa_function str_addr = utoa_function.receiver number = utoa_function.args.first @@ -25,7 +25,7 @@ module Crystal end def self.putint context - putint_function = Virtual::Method.new(:putint , [] , Virtual::Integer ,Virtual::Integer ) + putint_function = Virtual::MethodDefinition.new(:putint , [] , Virtual::Integer ,Virtual::Integer ) return putint_function buffer = Virtual::StringConstant.new(" ") # create a buffer context.object_space.add_object buffer # and save it (function local variable: a no no) @@ -52,7 +52,7 @@ module Crystal # a hand coded version of the fibonachi numbers # not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html def self.fibo context - fibo_function = Virtual::Method.new(:fibo , [] , Virtual::Integer ,Virtual::Integer ) + fibo_function = Virtual::MethodDefinition.new(:fibo , [] , Virtual::Integer ,Virtual::Integer ) return fibo_function result = fibo_function.return_type int = fibo_function.receiver diff --git a/lib/kernel/string.rb b/lib/kernel/string.rb index aeb5ca33..1d53b17c 100644 --- a/lib/kernel/string.rb +++ b/lib/kernel/string.rb @@ -1,7 +1,7 @@ module Crystal module Kernel def self.putstring context - function = Virtual::Method.new(:putstring , [] ) + function = Virtual::MethodDefinition.new(:putstring , [] ) return function ret = Virtual::RegisterMachine.instance.write_stdout(function) function.set_return ret diff --git a/lib/kernel/system.rb b/lib/kernel/system.rb index ffdc016d..8dec9170 100644 --- a/lib/kernel/system.rb +++ b/lib/kernel/system.rb @@ -1,7 +1,7 @@ module Crystal module Kernel def self.exit context - function = Virtual::Method.new(:exit , [] , Virtual::Integer) + function = Virtual::MethodDefinition.new(:exit , [] , Virtual::Integer) return function ret = Virtual::RegisterMachine.instance.exit(function) function.set_return ret diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index 3854f5ff..491914a3 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -29,7 +29,7 @@ module Virtual end # following classes are stubs. currently in brainstorming mode, so anything may change anytime - class MethodEnter < Instruction + class MethodDefinitionEnter < Instruction end class FrameGet < Instruction diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index a9c9fdb6..671ed2ac 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -52,7 +52,7 @@ end require_relative "list" require_relative "instruction" -require_relative "method" +require_relative "method_definition" require_relative "frame" require_relative "value" require_relative "type" diff --git a/lib/virtual/method.rb b/lib/virtual/method_definition.rb similarity index 89% rename from lib/virtual/method.rb rename to lib/virtual/method_definition.rb index 342a9d1a..bda74910 100644 --- a/lib/virtual/method.rb +++ b/lib/virtual/method_definition.rb @@ -9,15 +9,15 @@ module Virtual # known local variable names # temp variables (numbered) # - class Method < Virtual::Object + class MethodDefinition < Virtual::Object #return the main function (the top level) into which code is compiled - def Method.main - Method.new(:main , [] , Virtual::SelfReference ) + def MethodDefinition.main + MethodDefinition.new(:main , [] , Virtual::SelfReference ) end def attributes [:name , :args , :receiver , :return_type , :start] end - def initialize name , args , receiver = Virtual::SelfReference.new , return_type = Virtual::Mystery , start = MethodEnter.new + def initialize name , args , receiver = Virtual::SelfReference.new , return_type = Virtual::Mystery , start = MethodDefinitionEnter.new @name = name.to_sym @args = args @locals = [] diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index eaf0ea65..fe3c0794 100644 --- a/test/virtual/test_methods.rb +++ b/test/virtual/test_methods.rb @@ -9,7 +9,7 @@ def foo(x) 5 end HERE - @output = [Virtual::Method.new(:foo,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Virtual::SelfReference.new(nil),Virtual::IntegerConstant.new(5),Virtual::MethodEnter.new(nil))] + @output = [Virtual::MethodDefinition.new(:foo,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Virtual::SelfReference.new(nil),Virtual::IntegerConstant.new(5),Virtual::MethodDefinitionEnter.new(nil))] check end @@ -19,7 +19,7 @@ def String.length(x) @length end HERE - @output = [Virtual::Method.new(:length,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Boot::BootClass.new(:String,:Object),Virtual::Return.new(Virtual::Mystery.new()),Virtual::MethodEnter.new(Virtual::ObjectGet.new(:length,nil)))] + @output = [Virtual::MethodDefinition.new(:length,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Boot::BootClass.new(:String,:Object),Virtual::Return.new(Virtual::Mystery.new()),Virtual::MethodDefinitionEnter.new(Virtual::ObjectGet.new(:length,nil)))] check end @@ -30,7 +30,7 @@ def foo(x) 2 + 5 end HERE - @output = [Virtual::Method.new(:foo,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Virtual::SelfReference.new(nil),Virtual::Return.new(Virtual::Mystery),Virtual::MethodEnter.new(Virtual::FrameSet.new(:abba,Virtual::IntegerConstant.new(5),Virtual::LoadSelf.new(Virtual::IntegerConstant.new(2),Virtual::FrameSend.new(:+,[Virtual::IntegerConstant.new(5)],nil)))))] + @output = [Virtual::MethodDefinition.new(:foo,[Virtual::Argument.new(:x,Virtual::Mystery.new())],Virtual::SelfReference.new(nil),Virtual::Return.new(Virtual::Mystery),Virtual::MethodDefinitionEnter.new(Virtual::FrameSet.new(:abba,Virtual::IntegerConstant.new(5),Virtual::LoadSelf.new(Virtual::IntegerConstant.new(2),Virtual::FrameSend.new(:+,[Virtual::IntegerConstant.new(5)],nil)))))] check end @@ -40,7 +40,7 @@ def foo() 2 + 5 end HERE - @output = [Virtual::Method.new(:foo,[],Virtual::SelfReference.new(nil),Virtual::Return.new(Virtual::Mystery),Virtual::MethodEnter.new(Virtual::LoadSelf.new(Virtual::IntegerConstant.new(2),Virtual::FrameSend.new(:+,[Virtual::IntegerConstant.new(5)],nil))))] + @output = [Virtual::MethodDefinition.new(:foo,[],Virtual::SelfReference.new(nil),Virtual::Return.new(Virtual::Mystery),Virtual::MethodDefinitionEnter.new(Virtual::LoadSelf.new(Virtual::IntegerConstant.new(2),Virtual::FrameSend.new(:+,[Virtual::IntegerConstant.new(5)],nil))))] check end @@ -65,7 +65,7 @@ def retvar(n) return i end HERE - @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] + @output = [Virtual::MethodDefinition.new(:foo,[Ast::NameExpression.new(:x)])] check end @@ -79,7 +79,7 @@ def retvar(n) end end HERE - @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] + @output = [Virtual::MethodDefinition.new(:foo,[Ast::NameExpression.new(:x)])] check end @@ -92,7 +92,7 @@ def retvar(n) end end HERE - @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] + @output = [Virtual::MethodDefinition.new(:foo,[Ast::NameExpression.new(:x)])] check end @@ -106,7 +106,7 @@ def fibonaccit(n) end end HERE - @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] + @output = [Virtual::MethodDefinition.new(:foo,[Ast::NameExpression.new(:x)])] check end @@ -124,7 +124,7 @@ def fibonaccit(n) end end HERE - @output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)])] + @output = [Virtual::MethodDefinition.new(:foo,[Ast::NameExpression.new(:x)])] check end end \ No newline at end of file diff --git a/test/virtual/virtual_helper.rb b/test/virtual/virtual_helper.rb index f38df69d..cbe4dde2 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -12,7 +12,7 @@ module VirtualHelper syntax = parser.parse_with_debug(@string_input) parts = Parser::Transform.new.apply(syntax) machine = Virtual::Machine.new - main = Virtual::Method.main + main = Virtual::MethodDefinition.main expressions = parts.compile(machine.frame , main ) assert_equal @output , expressions end