fixup names in builtin module

This commit is contained in:
Torsten Ruger 2014-09-10 21:35:52 +03:00
parent 5a5e977b8f
commit e53de8ad43
6 changed files with 42 additions and 26 deletions

View File

@ -1,6 +1,6 @@
#integer related kernel functions
module Builtin
module Kernel
module Integer
# The conversion to base10 is quite a bit more complicated than i thought. The bulk of it is in div10
# We set up variables, do the devision and write the result to the string
# then check if were done and recurse if neccessary

34
lib/builtin/kernel.rb Normal file
View File

@ -0,0 +1,34 @@
module Builtin
module Kernel
module ClassMethods
# main entry point, ie __init__ calls this
# defined here as empty, to be redefined
def main context
function = Virtual::CompiledMethod.new(:main , [] , Virtual::Integer)
return function
end
# this is the really really first place the machine starts.
# it isn't really a function, ie it is jumped to (not called), exits and may not return
# so it is responsible for initial setup (and relocation)
def __init__ context
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
return function
end
def putstring context
function = Virtual::CompiledMethod.new(:putstring , [] )
return function
ret = Virtual::RegisterMachine.instance.write_stdout(function)
function.set_return ret
function
end
def exit context
function = Virtual::CompiledMethod.new(:exit , [] , Virtual::Integer)
return function
ret = Virtual::RegisterMachine.instance.exit(function)
function.set_return ret
function
end
end
extend ClassMethods
end
end

View File

@ -78,4 +78,4 @@ end
require_relative "integer"
require_relative "string"
require_relative "array"
require_relative "system"
require_relative "kernel"

View File

@ -1,13 +1,4 @@
module Builtin
module Kernel
def self.putstring context
function = Virtual::CompiledMethod.new(:putstring , [] )
return function
ret = Virtual::RegisterMachine.instance.write_stdout(function)
function.set_return ret
function
end
end
class String
module ClassMethods
def get context , index = Virtual::Integer

View File

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

View File

@ -70,16 +70,18 @@ module Virtual
# 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_instance_method Builtin::Object.send(f , @context)
end
[:putstring,:putint,:fibo,:exit].each do |f|
#puts "Boot Kernel::#{f}"
obj = get_or_create_class :Kernel
[:main , :__init__,:putstring,:exit].each do |f|
obj.add_instance_method Builtin::Kernel.send(f , @context)
end
obj = get_or_create_class :Integer
[:putint,:fibo].each do |f|
obj.add_instance_method Builtin::Integer.send(f , @context)
end
obj = get_or_create_class :String
[:get , :set , :puts].each do |f|
#puts "Boot String::#{f}"
obj.add_instance_method Builtin::String.send(f , @context)
end
obj = get_or_create_class :Array