2014-06-13 23:19:12 +02:00
|
|
|
#integer related kernel functions
|
2015-06-29 20:03:58 +02:00
|
|
|
module Register
|
|
|
|
module Builtin
|
|
|
|
module Integer
|
|
|
|
module ClassMethods
|
2015-10-18 16:20:19 +02:00
|
|
|
include AST::Sexp
|
2015-08-07 15:46:55 +02:00
|
|
|
|
2015-08-05 17:49:37 +02:00
|
|
|
# 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
|
|
|
|
# As we write before we recurse (save a push) we write the number backwards
|
|
|
|
# arguments: string address , integer
|
|
|
|
# def utoa context
|
2015-10-28 20:37:42 +01:00
|
|
|
# compiler = Soml::Compiler.new.create_method(:Integer ,:utoa , [ :Integer ] ).init_method
|
2015-10-14 15:16:03 +02:00
|
|
|
# function.source.receiver = :Integer
|
2015-08-05 17:49:37 +02:00
|
|
|
# return utoa_function
|
|
|
|
# # str_addr = utoa_function.receiver
|
|
|
|
# # number = utoa_function.args.first
|
|
|
|
# # remainder = utoa_function.new_local
|
2015-10-22 17:16:29 +02:00
|
|
|
# # RegisterMachine.instance.div10( utoa_function , number , remainder )
|
2015-08-05 17:49:37 +02:00
|
|
|
# # # make char out of digit (by using ascii encoding) 48 == "0"
|
|
|
|
# # utoa_function.instance_eval do
|
|
|
|
# # add( remainder , remainder , 48)
|
|
|
|
# # strb( remainder, str_addr )
|
|
|
|
# # sub( str_addr, str_addr , 1 )
|
|
|
|
# # cmp( number , 0 )
|
|
|
|
# # callne( utoa_function )
|
|
|
|
# # end
|
|
|
|
# # return utoa_function
|
2015-07-21 18:57:38 +02:00
|
|
|
# end
|
2014-06-13 23:19:12 +02:00
|
|
|
|
2015-11-11 19:41:02 +01:00
|
|
|
def mod context
|
|
|
|
compiler = Soml::Compiler.new.create_method(:Integer,:mod , {:Integer => :by} ).init_method
|
2015-10-28 20:37:42 +01:00
|
|
|
return compiler.method
|
2015-08-05 17:49:37 +02:00
|
|
|
end
|
2015-11-11 19:41:02 +01:00
|
|
|
def putint context
|
|
|
|
compiler = Soml::Compiler.new.create_method(:Integer,:putint ).init_method
|
2015-10-28 20:37:42 +01:00
|
|
|
return compiler.method
|
2015-08-05 17:49:37 +02:00
|
|
|
end
|
2015-11-11 19:41:02 +01:00
|
|
|
|
2015-06-29 20:03:58 +02:00
|
|
|
end
|
|
|
|
extend ClassMethods
|
2014-09-11 14:08:56 +02:00
|
|
|
end
|
2014-06-13 23:19:12 +02:00
|
|
|
end
|
2015-05-24 12:31:33 +02:00
|
|
|
end
|