fixup names in builtin module
This commit is contained in:
parent
5a5e977b8f
commit
e53de8ad43
@ -1,6 +1,6 @@
|
|||||||
#integer related kernel functions
|
#integer related kernel functions
|
||||||
module Builtin
|
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
|
# 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
|
# We set up variables, do the devision and write the result to the string
|
||||||
# then check if were done and recurse if neccessary
|
# then check if were done and recurse if neccessary
|
||||||
|
34
lib/builtin/kernel.rb
Normal file
34
lib/builtin/kernel.rb
Normal 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
|
@ -78,4 +78,4 @@ end
|
|||||||
require_relative "integer"
|
require_relative "integer"
|
||||||
require_relative "string"
|
require_relative "string"
|
||||||
require_relative "array"
|
require_relative "array"
|
||||||
require_relative "system"
|
require_relative "kernel"
|
||||||
|
@ -1,13 +1,4 @@
|
|||||||
module Builtin
|
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
|
class String
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def get context , index = Virtual::Integer
|
def get context , index = Virtual::Integer
|
||||||
|
@ -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
|
|
@ -70,16 +70,18 @@ module Virtual
|
|||||||
# dummies, just for the other to compile
|
# dummies, just for the other to compile
|
||||||
obj = get_or_create_class :Object
|
obj = get_or_create_class :Object
|
||||||
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
||||||
#puts "Boot Object::#{f}"
|
|
||||||
obj.add_instance_method Builtin::Object.send(f , @context)
|
obj.add_instance_method Builtin::Object.send(f , @context)
|
||||||
end
|
end
|
||||||
[:putstring,:putint,:fibo,:exit].each do |f|
|
obj = get_or_create_class :Kernel
|
||||||
#puts "Boot Kernel::#{f}"
|
[:main , :__init__,:putstring,:exit].each do |f|
|
||||||
obj.add_instance_method Builtin::Kernel.send(f , @context)
|
obj.add_instance_method Builtin::Kernel.send(f , @context)
|
||||||
end
|
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
|
obj = get_or_create_class :String
|
||||||
[:get , :set , :puts].each do |f|
|
[:get , :set , :puts].each do |f|
|
||||||
#puts "Boot String::#{f}"
|
|
||||||
obj.add_instance_method Builtin::String.send(f , @context)
|
obj.add_instance_method Builtin::String.send(f , @context)
|
||||||
end
|
end
|
||||||
obj = get_or_create_class :Array
|
obj = get_or_create_class :Array
|
||||||
|
Loading…
Reference in New Issue
Block a user