implement in pure Rpl
This commit is contained in:
parent
8ac18e6517
commit
21b090aa9f
2 changed files with 45 additions and 26 deletions
|
@ -5,11 +5,6 @@ module Rpl
|
|||
module Core
|
||||
module_function
|
||||
|
||||
# similar to if-then-end, <test-instruction> <true-instruction> ift
|
||||
def ift( stack, dictionary )
|
||||
ifte( stack << { type: :word, value: 'nop' }, dictionary )
|
||||
end
|
||||
|
||||
# similar to if-then-else-end, <test-instruction> <true-instruction> <false-instruction> ifte
|
||||
def ifte( stack, dictionary )
|
||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[program word], %i[program word], %i[boolean]] )
|
||||
|
@ -18,6 +13,14 @@ module Rpl
|
|||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
|
||||
# similar to if-then-end, <test-instruction> <true-instruction> ift
|
||||
def ift( stack, dictionary )
|
||||
stack << { value: '« « nop » ifte »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,16 +14,6 @@ module Rpl
|
|||
[stack, dictionary]
|
||||
end
|
||||
|
||||
# drop first stack entry
|
||||
def drop( stack, dictionary )
|
||||
dropn( stack << { type: :numeric, base: 10, value: 1 }, dictionary )
|
||||
end
|
||||
|
||||
# drop 2 first stack entries
|
||||
def drop2( stack, dictionary )
|
||||
dropn( stack << { type: :numeric, base: 10, value: 2 }, dictionary )
|
||||
end
|
||||
|
||||
# drop n first stack entries
|
||||
def dropn( stack, dictionary )
|
||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||
|
@ -46,16 +36,6 @@ module Rpl
|
|||
[stack, dictionary]
|
||||
end
|
||||
|
||||
# duplicate first stack entry
|
||||
def dup( stack, dictionary )
|
||||
dupn( stack << { type: :numeric, base: 10, value: 1 }, dictionary )
|
||||
end
|
||||
|
||||
# duplicate 2 first stack entries
|
||||
def dup2( stack, dictionary )
|
||||
dupn( stack << { type: :numeric, base: 10, value: 2 }, dictionary )
|
||||
end
|
||||
|
||||
# duplicate n first stack entries
|
||||
def dupn( stack, dictionary )
|
||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||
|
@ -129,9 +109,45 @@ module Rpl
|
|||
[stack, dictionary]
|
||||
end
|
||||
|
||||
# implemented in Rpl
|
||||
# push a copy of the element in stack level 2 onto the stack
|
||||
def over( stack, dictionary )
|
||||
pick( stack << { type: :numeric, base: 10, value: 2 }, dictionary )
|
||||
stack << { value: '« 2 pick »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
|
||||
# drop first stack entry
|
||||
def drop( stack, dictionary )
|
||||
stack << { value: '« 1 dropn »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
|
||||
# drop 2 first stack entries
|
||||
def drop2( stack, dictionary )
|
||||
stack << { value: '« 2 dropn »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
|
||||
# duplicate first stack entry
|
||||
def dup( stack, dictionary )
|
||||
stack << { value: '« 1 dupn »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
|
||||
# duplicate 2 first stack entries
|
||||
def dup2( stack, dictionary )
|
||||
stack << { value: '« 2 dupn »',
|
||||
type: :program }
|
||||
|
||||
Rpl::Lang::Core.eval( stack, dictionary )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue