rpl.rb/lib/core/test.rb

100 lines
2.4 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
# binary operator >
2022-02-10 14:33:09 +01:00
def greater_than
args = stack_extract( %i[any any] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] > args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# binary operator >=
2022-02-10 14:33:09 +01:00
def greater_than_or_equal
args = stack_extract( %i[any any] )
2021-12-07 15:50:58 +01:00
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] >= args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# binary operator <
2022-02-10 14:33:09 +01:00
def less_than
args = stack_extract( %i[any any] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] < args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# binary operator <=
2022-02-10 14:33:09 +01:00
def less_than_or_equal
args = stack_extract( %i[any any] )
2021-12-07 15:50:58 +01:00
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] <= args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator != (different)
2022-02-10 14:33:09 +01:00
def different
args = stack_extract( %i[any any] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] != args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator and
2022-02-10 14:33:09 +01:00
def boolean_and
args = stack_extract( [%i[boolean], %i[boolean]] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] && args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator or
2022-02-10 14:33:09 +01:00
def boolean_or
args = stack_extract( [%i[boolean], %i[boolean]] )
2021-12-07 15:50:58 +01:00
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] || args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator xor
2022-02-10 14:33:09 +01:00
def xor
args = stack_extract( [%i[boolean], %i[boolean]] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] ^ args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator not
2022-02-10 14:33:09 +01:00
def boolean_not
args = stack_extract( [%i[boolean]] )
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: !args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# boolean operator same (equal)
2022-02-10 14:33:09 +01:00
def same
args = stack_extract( %i[any any] )
2021-12-07 15:50:58 +01:00
2022-02-10 14:33:09 +01:00
@stack << { type: :boolean,
value: args[1][:value] == args[0][:value] }
2021-12-07 15:50:58 +01:00
end
# true boolean
2022-02-10 14:33:09 +01:00
def boolean_true
@stack << { type: :boolean,
value: true }
2021-12-07 15:50:58 +01:00
end
# false boolean
2022-02-10 14:33:09 +01:00
def boolean_false
@stack << { type: :boolean,
value: false }
2021-12-07 15:50:58 +01:00
end
2021-11-24 16:09:57 +01:00
end
end
end