renamed method definition to compiled method

This commit is contained in:
Torsten Ruger
2014-08-28 08:10:33 +03:00
parent e09d3c2f65
commit 7d35732923
15 changed files with 31 additions and 31 deletions

View File

@ -14,7 +14,7 @@ When compiling we deal with two times, compile-time and run-time. All the headac
Similarly, the result of compiling is two-fold: a static and a dynamic part.
- the static part are objects like the constants, but also defined classes and their methods
- the dynamic part is the code, which is stored as streams of instructions in the MethodDefinition
- the dynamic part is the code, which is stored as streams of instructions in the CompiledMethod
Too make things a little simpler, we create a very high level instruction stream at first and then run
transformation and optimisation passes on the stream to improve it.
@ -23,8 +23,8 @@ Each ast class gets a compile method that does the compilation.
#### Method Definition and Instructions
The first argument to the compile method is the MethodDefinition. All code is encoded as a stream of Instructions in the
MethodDefinition. In fact Instructions are a linked list and so the MethodDefinition only hold the head, and the current
The first argument to the compile method is the CompiledMethod. All code is encoded as a stream of Instructions in the
CompiledMethod. In fact Instructions are a linked list and so the CompiledMethod only hold the head, and the current
insertion point.
Code is added to the method (using add()), rather than working with the actual instructions. This is so each compile method

View File

@ -7,7 +7,7 @@ module Ast
p.name
end
r = receiver ? receiver.compile(method,message) : Virtual::Self.new()
new_method = Virtual::MethodDefinition.new(name , args , r )
new_method = Virtual::CompiledMethod.new(name , args , r )
new_method.class_name = r.is_a?(BootClass) ? r.name : method.class_name
clazz = Virtual::BootSpace.space.get_or_create_class(new_method.class_name)
clazz.add_instance_method new_method

View File

@ -7,7 +7,7 @@ module Salama
# 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::MethodDefinition.new(:utoa , [ Virtual::Integer ] , Virtual::Integer ,Virtual::Integer )
utoa_function = Virtual::CompiledMethod.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 Salama
end
def self.putint context
putint_function = Virtual::MethodDefinition.new(:putint , [] , Virtual::Integer ,Virtual::Integer )
putint_function = Virtual::CompiledMethod.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 Salama
# 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::MethodDefinition.new(:fibo , [] , Virtual::Integer ,Virtual::Integer )
fibo_function = Virtual::CompiledMethod.new(:fibo , [] , Virtual::Integer ,Virtual::Integer )
return fibo_function
result = fibo_function.return_type
int = fibo_function.receiver

View File

@ -6,7 +6,7 @@ module Salama
# 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::MethodDefinition.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
index_function = Virtual::CompiledMethod.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
return index_function
end
@ -23,7 +23,7 @@ module Salama
# 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::MethodDefinition.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery )
get_function = Virtual::CompiledMethod.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 Salama
end
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
set_function = Virtual::MethodDefinition.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery )
set_function = Virtual::CompiledMethod.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery )
return set_function
receiver set_function
me = set_function.receiver

View File

@ -1,7 +1,7 @@
module Salama
module Kernel
def self.putstring context
function = Virtual::MethodDefinition.new(:putstring , [] )
function = Virtual::CompiledMethod.new(:putstring , [] )
return function
ret = Virtual::RegisterMachine.instance.write_stdout(function)
function.set_return ret
@ -11,15 +11,15 @@ module Salama
class String
module ClassMethods
def get context , index = Virtual::Integer
get_function = Virtual::MethodDefinition.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
get_function = Virtual::CompiledMethod.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
return get_function
end
def set context , index = Virtual::Integer , char = Virtual::Integer
set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
set_function = Virtual::CompiledMethod.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
return set_function
end
def puts context
puts_function = Virtual::MethodDefinition.new(:puts , [] )
puts_function = Virtual::CompiledMethod.new(:puts , [] )
return puts_function
end
end

View File

@ -1,7 +1,7 @@
module Salama
module Kernel
def self.exit context
function = Virtual::MethodDefinition.new(:exit , [] , Virtual::Integer)
function = Virtual::CompiledMethod.new(:exit , [] , Virtual::Integer)
return function
ret = Virtual::RegisterMachine.instance.exit(function)
function.set_return ret

View File

@ -13,7 +13,7 @@ require "virtual/meta_class"
end
attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name
def add_instance_method method
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod
raise "syserr " unless method.name.is_a? Symbol
@instance_methods << method
end

View File

@ -52,7 +52,7 @@ module Register
end
end
def assemble_MethodDefinition(method)
def assemble_CompiledMethod(method)
assemble_object(method.name)
method.blocks.each do |block|
assemble_object(block)

View File

@ -1,7 +1,7 @@
module Register
# This implements call logic, which is simply like a c call (not send, that involves lookup and all sorts)
#
# The only target for a call is a MethodDefinition, so we just need to get the address for the code
# The only target for a call is a CompiledMethod, so we just need to get the address for the code
# and call it.
#
# The only slight snag is that we would need to assemble before getting the address, but to assemble

View File

@ -53,7 +53,7 @@ module Register
length + link_Array(clazz.instance_methods , at + length)
end
def link_MethodDefinition(method , at)
def link_CompiledMethod(method , at)
length = members(2)
length += link_object(method.name ,at + length)
# NOT an ARRAY, just a bag of bytes

View File

@ -2,7 +2,7 @@ module Sof
class Volotile
@@mapping = {
Virtual::Block => [:method],
Virtual::MethodDefinition => [:current]
Virtual::CompiledMethod => [:current]
}
def self.attributes clazz
@@mapping[clazz] || []

View File

@ -18,7 +18,7 @@ module Virtual
def initialize machine = nil
super()
@classes = {}
@main = Virtual::MethodDefinition.new("main" , [] )
@main = Virtual::CompiledMethod.new("main" , [] )
#global objects (data)
@objects = []
boot_classes! # boot is a verb here
@ -63,7 +63,7 @@ module Virtual
end
# 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
# MethodDefinitions are grabbed from respective modules by sending the method name. This should return the
# CompiledMethods 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

View File

@ -29,10 +29,10 @@ module Virtual
# These (eg if/while) blocks may themselves have linear blocks ,but the last of these
# MUST have an uncoditional branch. And remember, all roads lead to return.
class MethodDefinition < Virtual::Object
class CompiledMethod < Virtual::Object
#return the main function (the top level) into which code is compiled
def MethodDefinition.main
MethodDefinition.new(:main , [] )
def CompiledMethod.main
CompiledMethod.new(:main , [] )
end
def initialize name , args , receiver = Virtual::Self.new , return_type = Virtual::Mystery
@name = name.to_sym

View File

@ -57,7 +57,7 @@ module Virtual
def compile_main bytes
syntax = @parser.parse_with_debug(bytes)
parts = Parser::Transform.new.apply(syntax)
main = Virtual::MethodDefinition.main
main = Virtual::CompiledMethod.main
expressions = parts.compile( main , self.message )
end
@ -76,7 +76,7 @@ end
#require_relative "list"
require_relative "instruction"
require_relative "method_definition"
require_relative "compiled_method"
require_relative "frame"
require_relative "message"
require_relative "value"