Compare commits
3 commits
300e061beb
...
8816e6ce32
Author | SHA1 | Date | |
---|---|---|---|
|
8816e6ce32 | ||
|
169e5249db | ||
|
e318296e29 |
9 changed files with 316 additions and 44 deletions
|
@ -45,7 +45,7 @@ module Rpl
|
||||||
[stack, args]
|
[stack, args]
|
||||||
end
|
end
|
||||||
|
|
||||||
def __todo( stack )
|
def __todo( stack, _dictionary )
|
||||||
puts '__NOT IMPLEMENTED__'
|
puts '__NOT IMPLEMENTED__'
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,9 +25,8 @@ module Rpl
|
||||||
def type( stack, dictionary )
|
def type( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any] )
|
||||||
|
|
||||||
stack << args[0]
|
|
||||||
stack << { type: :string,
|
stack << { type: :string,
|
||||||
value: args[0][:type].to_s }
|
value: "\"#{args[0][:type]}\"" }
|
||||||
|
|
||||||
[stack, dictionary]
|
[stack, dictionary]
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,6 @@ module Rpl
|
||||||
|
|
||||||
stack, dictionary = Rpl::Lang::Runner.new.run_input( parsed_input,
|
stack, dictionary = Rpl::Lang::Runner.new.run_input( parsed_input,
|
||||||
stack, dictionary )
|
stack, dictionary )
|
||||||
# TODO: check that STO actually updates dictionary
|
|
||||||
|
|
||||||
[stack, dictionary]
|
[stack, dictionary]
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,15 +5,113 @@ module Rpl
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# evaluate (run) a program, or recall a variable. ex: 'my_prog' eval
|
# store a variable. ex: 1 'name' sto
|
||||||
def sto( stack, dictionary )
|
def sto( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any, %i[name]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[name], :any] )
|
||||||
|
|
||||||
# TODO
|
dictionary.add_var( args[0][:value][1..-2], # removing surrounding '
|
||||||
dictionary.add( args[1][:value], proc { |stk| Rpl::Lang::Core.eval( stk << args[0][:value], dictionary ) } )
|
proc { |stk, dict, rcl_only = false|
|
||||||
|
stk << args[1]
|
||||||
|
|
||||||
|
if rcl_only
|
||||||
|
[stk, dict]
|
||||||
|
else
|
||||||
|
Rpl::Lang::Core.eval( stk, dict )
|
||||||
|
end
|
||||||
|
} )
|
||||||
|
|
||||||
[stack, dictionary]
|
[stack, dictionary]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# recall a variable. ex: 'name' rcl
|
||||||
|
def rcl( stack, dictionary )
|
||||||
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[name]] )
|
||||||
|
|
||||||
|
word = dictionary[ args[0][:value][1..-2] ]
|
||||||
|
|
||||||
|
stack, dictionary = word.call( stack, dictionary, true ) unless word.nil?
|
||||||
|
|
||||||
|
[stack, dictionary]
|
||||||
|
end
|
||||||
|
|
||||||
|
# delete a variable. ex: 'name' purge
|
||||||
|
def purge( stack, dictionary )
|
||||||
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[name]] )
|
||||||
|
|
||||||
|
dictionary.remove_var( args[0][:value][1..-2] )
|
||||||
|
|
||||||
|
[stack, dictionary]
|
||||||
|
end
|
||||||
|
|
||||||
|
# list all variables
|
||||||
|
def vars( stack, dictionary )
|
||||||
|
# stack << { type: :list,
|
||||||
|
# value: dictionary.vars.keys.map { |name| { value: name, type: :name } } }
|
||||||
|
stack << { type: :list,
|
||||||
|
value: dictionary.vars.keys.map { |name| "'#{name}'" } }
|
||||||
|
|
||||||
|
[stack, dictionary]
|
||||||
|
end
|
||||||
|
|
||||||
|
# erase all variables
|
||||||
|
def clusr( stack, dictionary )
|
||||||
|
dictionary.remove_all_vars
|
||||||
|
|
||||||
|
[stack, dictionary]
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit( stack, dictionary )
|
||||||
|
# TODO
|
||||||
|
[stack, dictionary]
|
||||||
|
end
|
||||||
|
|
||||||
|
# add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+
|
||||||
|
def sto_add( stack, dictionary )
|
||||||
|
stack << { value: '« dup type "name" == « swap » ift over rcl + swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
|
|
||||||
|
# substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-
|
||||||
|
def sto_subtract( stack, dictionary )
|
||||||
|
stack << { value: '« dup type "name" == « swap » ift over rcl swap - swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
|
|
||||||
|
# multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*
|
||||||
|
def sto_multiply( stack, dictionary )
|
||||||
|
stack << { value: '« dup type "name" == « swap » ift over rcl * swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
|
|
||||||
|
# divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/
|
||||||
|
def sto_divide( stack, dictionary )
|
||||||
|
stack << { value: '« dup type "name" == « swap » ift over rcl swap / swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
|
|
||||||
|
# negate a variable. ex: 'name' sneg
|
||||||
|
def sto_negate( stack, dictionary )
|
||||||
|
stack << { value: '« dup rcl -1 * swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
|
|
||||||
|
# inverse a variable. ex: 1 'name' sinv
|
||||||
|
def sto_inverse( stack, dictionary )
|
||||||
|
stack << { value: '« dup rcl 1 swap / swap sto »',
|
||||||
|
type: :program }
|
||||||
|
|
||||||
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Rpl
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# binary operator >
|
# binary operator >
|
||||||
def greater_than( stack )
|
def greater_than( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -26,7 +26,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# binary operator <
|
# binary operator <
|
||||||
def less_than( stack )
|
def less_than( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -36,7 +36,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# binary operator <=
|
# binary operator <=
|
||||||
def less_or_equal_than( stack )
|
def less_or_equal_than( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -46,7 +46,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator != (different)
|
# boolean operator != (different)
|
||||||
def different( stack )
|
def different( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -56,7 +56,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator and
|
# boolean operator and
|
||||||
def and( stack )
|
def and( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -66,7 +66,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator or
|
# boolean operator or
|
||||||
def or( stack )
|
def or( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -76,7 +76,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator xor
|
# boolean operator xor
|
||||||
def xor( stack )
|
def xor( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean], %i[boolean]] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -86,7 +86,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator not
|
# boolean operator not
|
||||||
def not( stack )
|
def not( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean]] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -96,7 +96,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# boolean operator same (equal)
|
# boolean operator same (equal)
|
||||||
def same( stack )
|
def same( stack, dictionary )
|
||||||
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
|
@ -106,7 +106,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# true boolean
|
# true boolean
|
||||||
def true( stack )
|
def true( stack, dictionary )
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: true }
|
value: true }
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ module Rpl
|
||||||
end
|
end
|
||||||
|
|
||||||
# false boolean
|
# false boolean
|
||||||
def false( stack )
|
def false( stack, dictionary )
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: false }
|
value: false }
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,12 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
module Lang
|
module Lang
|
||||||
class Dictionary
|
class Dictionary
|
||||||
|
attr_reader :vars
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@parser = Parser.new
|
@parser = Parser.new
|
||||||
@words = {}
|
@words = {}
|
||||||
|
@vars = {}
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
add( 'nop', proc { |stack, dictionary| Rpl::Lang::Core.nop( stack, dictionary ) } )
|
add( 'nop', proc { |stack, dictionary| Rpl::Lang::Core.nop( stack, dictionary ) } )
|
||||||
|
@ -133,19 +136,19 @@ module Rpl
|
||||||
add( 'repeat', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with while
|
add( 'repeat', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with while
|
||||||
|
|
||||||
# STORE
|
# STORE
|
||||||
add( 'sto', proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } ) # store a variable. ex: 1 'name' sto
|
add( 'sto', proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } )
|
||||||
add( '▶', proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } ) # alias
|
add( '▶', proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } ) # alias
|
||||||
add( 'rcl', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # recall a variable. ex: 'name' rcl
|
add( 'rcl', proc { |stack, dictionary| Rpl::Lang::Core.rcl( stack, dictionary ) } )
|
||||||
add( 'purge', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # delete a variable. ex: 'name' purge
|
add( 'purge', proc { |stack, dictionary| Rpl::Lang::Core.purge( stack, dictionary ) } )
|
||||||
add( 'vars', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # list all variables
|
add( 'vars', proc { |stack, dictionary| Rpl::Lang::Core.vars( stack, dictionary ) } )
|
||||||
add( 'clusr', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # erase all variables
|
add( 'clusr', proc { |stack, dictionary| Rpl::Lang::Core.clusr( stack, dictionary ) } )
|
||||||
add( 'edit', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # edit a variable content
|
add( 'edit', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # edit a variable content
|
||||||
add( 'sto+', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+
|
add( 'sto+', proc { |stack, dictionary| Rpl::Lang::Core.sto_add( stack, dictionary ) } )
|
||||||
add( 'sto-', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-
|
add( 'sto-', proc { |stack, dictionary| Rpl::Lang::Core.sto_subtract( stack, dictionary ) } )
|
||||||
add( 'sto*', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*
|
add( 'sto*', proc { |stack, dictionary| Rpl::Lang::Core.sto_multiply( stack, dictionary ) } )
|
||||||
add( 'sto/', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/
|
add( 'sto/', proc { |stack, dictionary| Rpl::Lang::Core.sto_divide( stack, dictionary ) } )
|
||||||
add( 'sneg', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # negate a variable. ex: 'name' sneg
|
add( 'sneg', proc { |stack, dictionary| Rpl::Lang::Core.sto_negate( stack, dictionary ) } )
|
||||||
add( 'sinv', proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse a variable. ex: 1 'name' sinv
|
add( 'sinv', proc { |stack, dictionary| Rpl::Lang::Core.sto_inverse( stack, dictionary ) } )
|
||||||
|
|
||||||
# PROGRAM
|
# PROGRAM
|
||||||
add( 'eval', proc { |stack, dictionary| Rpl::Lang::Core.eval( stack, dictionary ) } )
|
add( 'eval', proc { |stack, dictionary| Rpl::Lang::Core.eval( stack, dictionary ) } )
|
||||||
|
@ -194,11 +197,24 @@ module Rpl
|
||||||
@words[ name ] = implementation
|
@words[ name ] = implementation
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup( name )
|
def add_var( name, implementation )
|
||||||
@words[ name ] if @words.include?( name )
|
@vars[ name ] = implementation
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: alias
|
def remove_var( name )
|
||||||
|
@vars.delete( name )
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_all_vars
|
||||||
|
@vars = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def []( name )
|
||||||
|
word = @words[ name ]
|
||||||
|
word ||= @vars[ name ]
|
||||||
|
|
||||||
|
word
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Rpl
|
||||||
input.each do |elt|
|
input.each do |elt|
|
||||||
case elt[:type]
|
case elt[:type]
|
||||||
when :word
|
when :word
|
||||||
command = dictionary.lookup( elt[:value] )
|
command = dictionary[ elt[:value] ]
|
||||||
|
|
||||||
if command.nil?
|
if command.nil?
|
||||||
stack << { type: :name, value: "'#{elt[:value]}'" }
|
stack << { type: :name, value: "'#{elt[:value]}'" }
|
||||||
|
|
|
@ -26,11 +26,4 @@ class TestLanguageProgram < Test::Unit::TestCase
|
||||||
{ value: 4, type: :numeric, base: 10 }],
|
{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sto
|
|
||||||
stack, _dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup »', type: :program },
|
|
||||||
{ value: "'quatre'", type: :name }], Rpl::Lang::Dictionary.new )
|
|
||||||
|
|
||||||
assert_equal [], stack
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# coding: utf-8
|
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
@ -7,10 +6,178 @@ require_relative '../language'
|
||||||
|
|
||||||
class TestLanguageProgram < Test::Unit::TestCase
|
class TestLanguageProgram < Test::Unit::TestCase
|
||||||
def test_sto
|
def test_sto
|
||||||
stack, _dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup »', type: :program },
|
stack, dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup * »', type: :program },
|
||||||
|
{ value: "'quatre'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
assert_equal [], stack
|
||||||
|
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.eval( [{ value: 'quatre', type: :word }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rcl
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup * »', type: :program },
|
||||||
{ value: "'quatre'", type: :name }],
|
{ value: "'quatre'", type: :name }],
|
||||||
Rpl::Lang::Dictionary.new )
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [], stack
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'quatre'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: '« 2 dup * »', type: :program }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_purge
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup * »', type: :program },
|
||||||
|
{ value: "'quatre'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.purge( [{ value: "'quatre'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal nil,
|
||||||
|
dictionary['quatre']
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_vars
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup * »', type: :program },
|
||||||
|
{ value: "'quatre'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 1, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.vars( [],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: ["'quatre'", "'un'"], type: :list }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_clusr
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: '« 2 dup * »', type: :program },
|
||||||
|
{ value: "'quatre'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 1, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.clusr( [],
|
||||||
|
dictionary )
|
||||||
|
assert_equal( {},
|
||||||
|
dictionary.vars )
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_add
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 1, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_add( [{ value: "'un'", type: :name },
|
||||||
|
{ value: 3, type: :numeric, base: 10 }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_add( [{ value: 3, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 7, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_subtract
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 1, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_subtract( [{ value: "'un'", type: :name },
|
||||||
|
{ value: 3, type: :numeric, base: 10 }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: -2, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_subtract( [{ value: 3, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: -5, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_multiply
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 2, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_multiply( [{ value: "'un'", type: :name },
|
||||||
|
{ value: 3, type: :numeric, base: 10 }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 6, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_multiply( [{ value: 3, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 18, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_divide
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 2, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_divide( [{ value: "'un'", type: :name },
|
||||||
|
{ value: 4.0, type: :numeric, base: 10 }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 0.5, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_divide( [{ value: 5, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 0.1, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_negate
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 2, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_negate( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: -2, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sto_inverse
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto( [{ value: 2, type: :numeric, base: 10 },
|
||||||
|
{ value: "'un'", type: :name }],
|
||||||
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
_stack, dictionary = Rpl::Lang::Core.sto_inverse( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
stack, _dictionary = Rpl::Lang::Core.rcl( [{ value: "'un'", type: :name }],
|
||||||
|
dictionary )
|
||||||
|
assert_equal [{ value: 0.5, type: :numeric, base: 10 }],
|
||||||
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue