rpl.rb/lib/core/test.rb

126 lines
3.2 KiB
Ruby
Raw Normal View History

2021-12-07 16:09:17 +01:00
# frozen_string_literal: true
2021-11-24 16:09:57 +01:00
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
module Core
module_function
# binary operator >
2021-12-08 12:34:12 +01:00
def greater_than( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] > args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# binary operator >=
def greater_or_equal_than( stack )
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] >= args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# binary operator <
2021-12-08 12:34:12 +01:00
def less_than( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] < args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# binary operator <=
2021-12-08 12:34:12 +01:00
def less_or_equal_than( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] <= args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator != (different)
2021-12-08 12:34:12 +01:00
def different( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] != args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator and
2021-12-08 12:34:12 +01:00
def and( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
stack << { type: :boolean,
value: args[1][:value] && args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator or
2021-12-08 12:34:12 +01:00
def or( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
stack << { type: :boolean,
value: args[1][:value] || args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator xor
2021-12-08 12:34:12 +01:00
def xor( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
stack << { type: :boolean,
value: args[1][:value] ^ args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator not
2021-12-08 12:34:12 +01:00
def not( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean]] )
stack << { type: :boolean,
value: !args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# boolean operator same (equal)
2021-12-08 12:34:12 +01:00
def same( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
stack << { type: :boolean,
value: args[1][:value] == args[0][:value] }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# true boolean
2021-12-08 12:34:12 +01:00
def true( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack << { type: :boolean,
value: true }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
# false boolean
2021-12-08 12:34:12 +01:00
def false( stack, dictionary )
2021-12-07 15:50:58 +01:00
stack << { type: :boolean,
value: false }
[stack, dictionary]
2021-12-07 15:50:58 +01:00
end
2021-11-24 16:09:57 +01:00
end
end
end