2019-08-26 08:24:06 +02:00
|
|
|
module Vool
|
2019-09-13 18:07:51 +02:00
|
|
|
module Builtin
|
2019-08-26 08:24:06 +02:00
|
|
|
def self.boot_methods(options)
|
|
|
|
return if options[:boot_methods] == false
|
2019-09-13 18:07:51 +02:00
|
|
|
load_builtin( "Integer.plus" )
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
|
|
|
|
2019-09-13 18:07:51 +02:00
|
|
|
def self.load_builtin(loads)
|
2019-09-24 20:20:12 +02:00
|
|
|
return "class Space;def main(arg);return 0; end; end" if(loads == "Space.main")
|
|
|
|
raise "no preload #{loads}" unless builtin[loads]
|
2019-09-13 18:07:51 +02:00
|
|
|
clazz , meth = loads.split(".")
|
2019-09-24 20:20:12 +02:00
|
|
|
"class #{clazz} #{derive(clazz)}; #{builtin[loads]};end;"
|
2019-09-24 14:44:33 +02:00
|
|
|
end
|
2019-09-24 20:20:12 +02:00
|
|
|
|
2019-09-24 14:44:33 +02:00
|
|
|
def self.derive(clazz) #must get derived classes rigth, so no mismatch
|
|
|
|
case clazz
|
|
|
|
when "Integer"
|
|
|
|
"< Data4"
|
|
|
|
when "Word"
|
|
|
|
" < Data8"
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
2019-09-13 18:07:51 +02:00
|
|
|
end
|
|
|
|
def self.builtin
|
|
|
|
{
|
|
|
|
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
|
2019-09-17 19:18:00 +02:00
|
|
|
"Object.missing" => "def method_missing(at); X.method_missing(:r1);end",
|
2019-09-13 18:07:51 +02:00
|
|
|
"Object.exit" => "def exit; X.exit;end",
|
|
|
|
"Integer.div4" => "def div4; X.div4;end",
|
|
|
|
"Integer.div10" => "def div10; X.div10;end",
|
|
|
|
"Integer.gt" => "def >; X.comparison(:>);end",
|
|
|
|
"Integer.lt" => "def <; X.comparison(:<);end",
|
|
|
|
"Integer.ge" => "def >=; X.comparison(:>=);end",
|
|
|
|
"Integer.le" => "def <=; X.comparison(:<=);end",
|
|
|
|
"Integer.plus" => "def +; X.int_operator(:+);end",
|
|
|
|
"Integer.minus" => "def -; X.int_operator(:-);end",
|
|
|
|
"Integer.mul" => "def *; X.int_operator(:*);end",
|
|
|
|
"Integer.and" => "def &; X.int_operator(:&);end",
|
|
|
|
"Integer.or" => "def |; X.int_operator(:|);end",
|
|
|
|
"Integer.ls" => "def <<; X.int_operator(:<<);end",
|
|
|
|
"Integer.rs" => "def >>; X.int_operator(:>>);end",
|
|
|
|
"Word.put" => "def putstring(at); X.putstring;end",
|
|
|
|
"Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end",
|
|
|
|
"Word.get" => "def get_internal_byte(at); X.get_internal_byte;end",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
def self.builtin_code
|
|
|
|
keys = builtin.keys
|
|
|
|
keys.pop
|
|
|
|
keys.collect { |loads| load_builtin(loads)}.join
|
2019-08-26 08:24:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|