diff --git a/lib/builtin/integer.rb b/lib/builtin/integer.rb index 9180bec1..24a5caa6 100644 --- a/lib/builtin/integer.rb +++ b/lib/builtin/integer.rb @@ -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 diff --git a/lib/builtin/kernel.rb b/lib/builtin/kernel.rb new file mode 100644 index 00000000..965d8143 --- /dev/null +++ b/lib/builtin/kernel.rb @@ -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 diff --git a/lib/builtin/object.rb b/lib/builtin/object.rb index bdc451d1..7c9691f2 100644 --- a/lib/builtin/object.rb +++ b/lib/builtin/object.rb @@ -78,4 +78,4 @@ end require_relative "integer" require_relative "string" require_relative "array" -require_relative "system" +require_relative "kernel" diff --git a/lib/builtin/string.rb b/lib/builtin/string.rb index 71bb3676..e1b57543 100644 --- a/lib/builtin/string.rb +++ b/lib/builtin/string.rb @@ -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 diff --git a/lib/builtin/system.rb b/lib/builtin/system.rb deleted file mode 100644 index 0b260c18..00000000 --- a/lib/builtin/system.rb +++ /dev/null @@ -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 diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index 3cf8af90..85fd564e 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -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