rpl.rb/lib/core/branch.rb

28 lines
756 B
Ruby
Raw Normal View History

2021-12-07 16:09:17 +01:00
# frozen_string_literal: true
2021-11-24 16:34:13 +01:00
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
module Core
module_function
2021-11-24 16:34:13 +01:00
2021-12-07 15:50:58 +01:00
# 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]] )
2021-11-24 16:34:13 +01:00
2021-12-07 15:50:58 +01:00
stack << args[ args[2][:value] ? 1 : 0 ]
2021-11-24 16:34:13 +01:00
2021-12-07 15:50:58 +01:00
Rpl::Lang::Core.eval( stack, dictionary )
end
2021-12-08 13:15:33 +01:00
2021-12-08 13:46:06 +01:00
# Implemented in Rpl
2021-12-08 13:15:33 +01:00
# 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
2021-11-24 16:34:13 +01:00
end
end
end