Rpl:: → Rpl::Lang::
This commit is contained in:
parent
803036b89e
commit
cfcbcc7ce5
22 changed files with 868 additions and 822 deletions
|
@ -11,6 +11,7 @@ require_relative './language/test'
|
||||||
require_relative './language/time-date'
|
require_relative './language/time-date'
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
@ -44,4 +45,5 @@ module Rpl
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,190 +1,191 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
class Dictionary
|
class Dictionary
|
||||||
def initialize
|
def initialize
|
||||||
@parser = Parser.new
|
@parser = Parser.new
|
||||||
@words = {}
|
@words = {}
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
add( 'nop', proc { |stack| Rpl::Core.nop( stack ) } )
|
add( 'nop', proc { |stack| Rpl::Lang::Core.nop( stack ) } )
|
||||||
add( 'help', proc { |stack| Rpl::Core.__todo( stack ) } ) # this help message
|
add( 'help', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # this help message
|
||||||
add( 'quit', proc { |stack| Rpl::Core.__todo( stack ) } ) # quit software
|
add( 'quit', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # quit software
|
||||||
add( 'version', proc { |stack| Rpl::Core.__todo( stack ) } ) # show rpn version
|
add( 'version', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # show rpn version
|
||||||
add( 'uname', proc { |stack| Rpl::Core.__todo( stack ) } ) # show rpn complete identification string
|
add( 'uname', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # show rpn complete identification string
|
||||||
add( 'history', proc { |stack| Rpl::Core.__todo( stack ) } ) # see commands history
|
add( 'history', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # see commands history
|
||||||
|
|
||||||
# STACK
|
# STACK
|
||||||
add( 'swap', proc { |stack| Rpl::Core.swap( stack ) } )
|
add( 'swap', proc { |stack| Rpl::Lang::Core.swap( stack ) } )
|
||||||
add( 'drop', proc { |stack| Rpl::Core.drop( stack ) } )
|
add( 'drop', proc { |stack| Rpl::Lang::Core.drop( stack ) } )
|
||||||
add( 'drop2', proc { |stack| Rpl::Core.drop2( stack ) } )
|
add( 'drop2', proc { |stack| Rpl::Lang::Core.drop2( stack ) } )
|
||||||
add( 'dropn', proc { |stack| Rpl::Core.dropn( stack ) } )
|
add( 'dropn', proc { |stack| Rpl::Lang::Core.dropn( stack ) } )
|
||||||
add( 'del', proc { |stack| Rpl::Core.del( stack ) } )
|
add( 'del', proc { |stack| Rpl::Lang::Core.del( stack ) } )
|
||||||
add( 'rot', proc { |stack| Rpl::Core.rot( stack ) } )
|
add( 'rot', proc { |stack| Rpl::Lang::Core.rot( stack ) } )
|
||||||
add( 'dup', proc { |stack| Rpl::Core.dup( stack ) } )
|
add( 'dup', proc { |stack| Rpl::Lang::Core.dup( stack ) } )
|
||||||
add( 'dup2', proc { |stack| Rpl::Core.dup2( stack ) } )
|
add( 'dup2', proc { |stack| Rpl::Lang::Core.dup2( stack ) } )
|
||||||
add( 'dupn', proc { |stack| Rpl::Core.dupn( stack ) } )
|
add( 'dupn', proc { |stack| Rpl::Lang::Core.dupn( stack ) } )
|
||||||
add( 'pick', proc { |stack| Rpl::Core.pick( stack ) } )
|
add( 'pick', proc { |stack| Rpl::Lang::Core.pick( stack ) } )
|
||||||
add( 'depth', proc { |stack| Rpl::Core.depth( stack ) } )
|
add( 'depth', proc { |stack| Rpl::Lang::Core.depth( stack ) } )
|
||||||
add( 'roll', proc { |stack| Rpl::Core.roll( stack ) } )
|
add( 'roll', proc { |stack| Rpl::Lang::Core.roll( stack ) } )
|
||||||
add( 'rolld', proc { |stack| Rpl::Core.rolld( stack ) } )
|
add( 'rolld', proc { |stack| Rpl::Lang::Core.rolld( stack ) } )
|
||||||
add( 'over', proc { |stack| Rpl::Core.over( stack ) } )
|
add( 'over', proc { |stack| Rpl::Lang::Core.over( stack ) } )
|
||||||
|
|
||||||
# USUAL OPERATIONS ON REALS AND COMPLEXES
|
# USUAL OPERATIONS ON REALS AND COMPLEXES
|
||||||
add( '+', proc { |stack| Rpl::Core.add( stack ) } )
|
add( '+', proc { |stack| Rpl::Lang::Core.add( stack ) } )
|
||||||
add( '-', proc { |stack| Rpl::Core.subtract( stack ) } )
|
add( '-', proc { |stack| Rpl::Lang::Core.subtract( stack ) } )
|
||||||
add( 'chs', proc { |stack| Rpl::Core.negate( stack ) } )
|
add( 'chs', proc { |stack| Rpl::Lang::Core.negate( stack ) } )
|
||||||
add( '*', proc { |stack| Rpl::Core.multiply( stack ) } )
|
add( '*', proc { |stack| Rpl::Lang::Core.multiply( stack ) } )
|
||||||
add( '×', proc { |stack| Rpl::Core.multiply( stack ) } ) # alias
|
add( '×', proc { |stack| Rpl::Lang::Core.multiply( stack ) } ) # alias
|
||||||
add( '/', proc { |stack| Rpl::Core.divide( stack ) } )
|
add( '/', proc { |stack| Rpl::Lang::Core.divide( stack ) } )
|
||||||
add( '÷', proc { |stack| Rpl::Core.divide( stack ) } ) # alias
|
add( '÷', proc { |stack| Rpl::Lang::Core.divide( stack ) } ) # alias
|
||||||
add( 'inv', proc { |stack| Rpl::Core.inverse( stack ) } )
|
add( 'inv', proc { |stack| Rpl::Lang::Core.inverse( stack ) } )
|
||||||
add( '^', proc { |stack| Rpl::Core.power( stack ) } )
|
add( '^', proc { |stack| Rpl::Lang::Core.power( stack ) } )
|
||||||
add( 'sqrt', proc { |stack| Rpl::Core.sqrt( stack ) } )
|
add( 'sqrt', proc { |stack| Rpl::Lang::Core.sqrt( stack ) } )
|
||||||
add( 'sq', proc { |stack| Rpl::Core.sq( stack ) } )
|
add( 'sq', proc { |stack| Rpl::Lang::Core.sq( stack ) } )
|
||||||
add( 'abs', proc { |stack| Rpl::Core.abs( stack ) } )
|
add( 'abs', proc { |stack| Rpl::Lang::Core.abs( stack ) } )
|
||||||
add( 'dec', proc { |stack| Rpl::Core.dec( stack ) } )
|
add( 'dec', proc { |stack| Rpl::Lang::Core.dec( stack ) } )
|
||||||
add( 'hex', proc { |stack| Rpl::Core.hex( stack ) } )
|
add( 'hex', proc { |stack| Rpl::Lang::Core.hex( stack ) } )
|
||||||
add( 'bin', proc { |stack| Rpl::Core.bin( stack ) } )
|
add( 'bin', proc { |stack| Rpl::Lang::Core.bin( stack ) } )
|
||||||
add( 'base', proc { |stack| Rpl::Core.base( stack ) } )
|
add( 'base', proc { |stack| Rpl::Lang::Core.base( stack ) } )
|
||||||
add( 'sign', proc { |stack| Rpl::Core.sign( stack ) } )
|
add( 'sign', proc { |stack| Rpl::Lang::Core.sign( stack ) } )
|
||||||
|
|
||||||
# OPERATIONS ON REALS
|
# OPERATIONS ON REALS
|
||||||
add( '%', proc { |stack| Rpl::Core.__todo( stack ) } ) # percent
|
add( '%', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # percent
|
||||||
add( '%CH', proc { |stack| Rpl::Core.__todo( stack ) } ) # inverse percent
|
add( '%CH', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # inverse percent
|
||||||
add( 'mod', proc { |stack| Rpl::Core.__todo( stack ) } ) # modulo
|
add( 'mod', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # modulo
|
||||||
add( 'fact', proc { |stack| Rpl::Core.__todo( stack ) } ) # n! for integer n or Gamma(x+1) for fractional x
|
add( 'fact', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # n! for integer n or Gamma(x+1) for fractional x
|
||||||
add( 'mant', proc { |stack| Rpl::Core.__todo( stack ) } ) # mantissa of a real number
|
add( 'mant', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # mantissa of a real number
|
||||||
add( 'xpon', proc { |stack| Rpl::Core.__todo( stack ) } ) # exponant of a real number
|
add( 'xpon', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # exponant of a real number
|
||||||
add( 'floor', proc { |stack| Rpl::Core.__todo( stack ) } ) # largest number <=
|
add( 'floor', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # largest number <=
|
||||||
add( 'ceil', proc { |stack| Rpl::Core.__todo( stack ) } ) # smallest number >=
|
add( 'ceil', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # smallest number >=
|
||||||
add( 'ip', proc { |stack| Rpl::Core.__todo( stack ) } ) # integer part
|
add( 'ip', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # integer part
|
||||||
add( 'fp', proc { |stack| Rpl::Core.__todo( stack ) } ) # fractional part
|
add( 'fp', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # fractional part
|
||||||
add( 'min', proc { |stack| Rpl::Core.__todo( stack ) } ) # min of 2 real numbers
|
add( 'min', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # min of 2 real numbers
|
||||||
add( 'max', proc { |stack| Rpl::Core.__todo( stack ) } ) # max of 2 real numbers
|
add( 'max', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # max of 2 real numbers
|
||||||
|
|
||||||
# OPERATIONS ON COMPLEXES
|
# OPERATIONS ON COMPLEXES
|
||||||
add( 're', proc { |stack| Rpl::Core.__todo( stack ) } ) # complex real part
|
add( 're', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # complex real part
|
||||||
add( 'im', proc { |stack| Rpl::Core.__todo( stack ) } ) # complex imaginary part
|
add( 'im', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # complex imaginary part
|
||||||
add( 'conj', proc { |stack| Rpl::Core.__todo( stack ) } ) # complex conjugate
|
add( 'conj', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # complex conjugate
|
||||||
add( 'arg', proc { |stack| Rpl::Core.__todo( stack ) } ) # complex argument in radians
|
add( 'arg', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # complex argument in radians
|
||||||
add( 'c->r', proc { |stack| Rpl::Core.__todo( stack ) } ) # transform a complex in 2 reals
|
add( 'c->r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # transform a complex in 2 reals
|
||||||
add( 'c→r', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'c→r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
add( 'r->c', proc { |stack| Rpl::Core.__todo( stack ) } ) # transform 2 reals in a complex
|
add( 'r->c', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # transform 2 reals in a complex
|
||||||
add( 'r→c', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'r→c', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
add( 'p->r', proc { |stack| Rpl::Core.__todo( stack ) } ) # cartesian to polar
|
add( 'p->r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # cartesian to polar
|
||||||
add( 'p→r', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'p→r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
add( 'r->p', proc { |stack| Rpl::Core.__todo( stack ) } ) # polar to cartesian
|
add( 'r->p', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # polar to cartesian
|
||||||
add( 'r→p', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'r→p', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
|
|
||||||
# MODE
|
# MODE
|
||||||
add( 'std', proc { |stack| Rpl::Core.__todo( stack ) } ) # standard floating numbers representation. ex: std
|
add( 'std', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # standard floating numbers representation. ex: std
|
||||||
add( 'fix', proc { |stack| Rpl::Core.__todo( stack ) } ) # fixed point representation. ex: 6 fix
|
add( 'fix', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # fixed point representation. ex: 6 fix
|
||||||
add( 'sci', proc { |stack| Rpl::Core.__todo( stack ) } ) # scientific floating point representation. ex: 20 sci
|
add( 'sci', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # scientific floating point representation. ex: 20 sci
|
||||||
add( 'prec', proc { |stack| Rpl::Core.prec( stack ) } )
|
add( 'prec', proc { |stack| Rpl::Lang::Core.prec( stack ) } )
|
||||||
add( 'round', proc { |stack| Rpl::Core.__todo( stack ) } ) # set float rounding mode. ex: ["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round
|
add( 'round', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # set float rounding mode. ex: ["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round
|
||||||
add( 'default', proc { |stack| Rpl::Core.default( stack ) } )
|
add( 'default', proc { |stack| Rpl::Lang::Core.default( stack ) } )
|
||||||
add( 'type', proc { |stack| Rpl::Core.type( stack ) } )
|
add( 'type', proc { |stack| Rpl::Lang::Core.type( stack ) } )
|
||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
add( '>', proc { |stack| Rpl::Core.greater_than( stack ) } )
|
add( '>', proc { |stack| Rpl::Lang::Core.greater_than( stack ) } )
|
||||||
add( '>=', proc { |stack| Rpl::Core.greater_or_equal_than( stack ) } )
|
add( '>=', proc { |stack| Rpl::Lang::Core.greater_or_equal_than( stack ) } )
|
||||||
add( '≥', proc { |stack| Rpl::Core.greater_or_equal_than( stack ) } ) # alias
|
add( '≥', proc { |stack| Rpl::Lang::Core.greater_or_equal_than( stack ) } ) # alias
|
||||||
add( '<', proc { |stack| Rpl::Core.less_than( stack ) } )
|
add( '<', proc { |stack| Rpl::Lang::Core.less_than( stack ) } )
|
||||||
add( '<=', proc { |stack| Rpl::Core.less_or_equal_than( stack ) } )
|
add( '<=', proc { |stack| Rpl::Lang::Core.less_or_equal_than( stack ) } )
|
||||||
add( '≤', proc { |stack| Rpl::Core.less_or_equal_than( stack ) } ) # alias
|
add( '≤', proc { |stack| Rpl::Lang::Core.less_or_equal_than( stack ) } ) # alias
|
||||||
add( '!=', proc { |stack| Rpl::Core.different( stack ) } )
|
add( '!=', proc { |stack| Rpl::Lang::Core.different( stack ) } )
|
||||||
add( '≠', proc { |stack| Rpl::Core.different( stack ) } ) # alias
|
add( '≠', proc { |stack| Rpl::Lang::Core.different( stack ) } ) # alias
|
||||||
add( '==', proc { |stack| Rpl::Core.same( stack ) } ) # alias
|
add( '==', proc { |stack| Rpl::Lang::Core.same( stack ) } ) # alias
|
||||||
add( 'and', proc { |stack| Rpl::Core.and( stack ) } )
|
add( 'and', proc { |stack| Rpl::Lang::Core.and( stack ) } )
|
||||||
add( 'or', proc { |stack| Rpl::Core.or( stack ) } )
|
add( 'or', proc { |stack| Rpl::Lang::Core.or( stack ) } )
|
||||||
add( 'xor', proc { |stack| Rpl::Core.xor( stack ) } )
|
add( 'xor', proc { |stack| Rpl::Lang::Core.xor( stack ) } )
|
||||||
add( 'not', proc { |stack| Rpl::Core.not( stack ) } )
|
add( 'not', proc { |stack| Rpl::Lang::Core.not( stack ) } )
|
||||||
add( 'same', proc { |stack| Rpl::Core.same( stack ) } )
|
add( 'same', proc { |stack| Rpl::Lang::Core.same( stack ) } )
|
||||||
add( 'true', proc { |stack| Rpl::Core.true( stack ) } ) # specific
|
add( 'true', proc { |stack| Rpl::Lang::Core.true( stack ) } ) # specific
|
||||||
add( 'false', proc { |stack| Rpl::Core.false( stack ) } ) # specific
|
add( 'false', proc { |stack| Rpl::Lang::Core.false( stack ) } ) # specific
|
||||||
|
|
||||||
# STRING
|
# STRING
|
||||||
add( '->str', proc { |stack| Rpl::Core.to_string( stack ) } )
|
add( '->str', proc { |stack| Rpl::Lang::Core.to_string( stack ) } )
|
||||||
add( '→str', proc { |stack| Rpl::Core.to_string( stack ) } ) # alias
|
add( '→str', proc { |stack| Rpl::Lang::Core.to_string( stack ) } ) # alias
|
||||||
add( 'str->', proc { |stack| Rpl::Core.from_string( stack ) } )
|
add( 'str->', proc { |stack| Rpl::Lang::Core.from_string( stack ) } )
|
||||||
add( 'str→', proc { |stack| Rpl::Core.from_string( stack ) } ) # alias
|
add( 'str→', proc { |stack| Rpl::Lang::Core.from_string( stack ) } ) # alias
|
||||||
add( 'chr', proc { |stack| Rpl::Core.chr( stack ) } )
|
add( 'chr', proc { |stack| Rpl::Lang::Core.chr( stack ) } )
|
||||||
add( 'num', proc { |stack| Rpl::Core.num( stack ) } )
|
add( 'num', proc { |stack| Rpl::Lang::Core.num( stack ) } )
|
||||||
add( 'size', proc { |stack| Rpl::Core.size( stack ) } )
|
add( 'size', proc { |stack| Rpl::Lang::Core.size( stack ) } )
|
||||||
add( 'pos', proc { |stack| Rpl::Core.pos( stack ) } )
|
add( 'pos', proc { |stack| Rpl::Lang::Core.pos( stack ) } )
|
||||||
add( 'sub', proc { |stack| Rpl::Core.sub( stack ) } )
|
add( 'sub', proc { |stack| Rpl::Lang::Core.sub( stack ) } )
|
||||||
|
|
||||||
# BRANCH
|
# BRANCH
|
||||||
add( 'if', proc { |stack| Rpl::Core.__todo( stack ) } ) # if <test-instruction> then <true-instructions> else <false-instructions> end
|
add( 'if', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # if <test-instruction> then <true-instructions> else <false-instructions> end
|
||||||
add( 'then', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with if
|
add( 'then', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with if
|
||||||
add( 'else', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with if
|
add( 'else', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with if
|
||||||
add( 'end', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with various branch instructions
|
add( 'end', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with various branch instructions
|
||||||
add( 'start', proc { |stack| Rpl::Core.__todo( stack ) } ) # <start> <end> start <instructions> next|<step> step
|
add( 'start', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # <start> <end> start <instructions> next|<step> step
|
||||||
add( 'for', proc { |stack| Rpl::Core.__todo( stack ) } ) # <start> <end> for <variable> <instructions> next|<step> step
|
add( 'for', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # <start> <end> for <variable> <instructions> next|<step> step
|
||||||
add( 'next', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with start and for
|
add( 'next', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with start and for
|
||||||
add( 'step', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with start and for
|
add( 'step', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with start and for
|
||||||
add( 'ift', proc { |stack| Rpl::Core.ift( stack, self ) } )
|
add( 'ift', proc { |stack| Rpl::Lang::Core.ift( stack, self ) } )
|
||||||
add( 'ifte', proc { |stack| Rpl::Core.ifte( stack, self ) } )
|
add( 'ifte', proc { |stack| Rpl::Lang::Core.ifte( stack, self ) } )
|
||||||
add( 'do', proc { |stack| Rpl::Core.__todo( stack ) } ) # do <instructions> until <condition> end
|
add( 'do', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # do <instructions> until <condition> end
|
||||||
add( 'until', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with do
|
add( 'until', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with do
|
||||||
add( 'while', proc { |stack| Rpl::Core.__todo( stack ) } ) # while <test-instruction> repeat <loop-instructions> end
|
add( 'while', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # while <test-instruction> repeat <loop-instructions> end
|
||||||
add( 'repeat', proc { |stack| Rpl::Core.__todo( stack ) } ) # used with while
|
add( 'repeat', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # used with while
|
||||||
|
|
||||||
# STORE
|
# STORE
|
||||||
add( 'sto', proc { |stack| Rpl::Core.__todo( stack ) } ) # store a variable. ex: 1 'name' sto
|
add( 'sto', proc { |stack| Rpl::Lang::Core.sto( stack ) } ) # store a variable. ex: 1 'name' sto
|
||||||
add( '▶', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( '▶', proc { |stack| Rpl::Lang::Core.sto( stack ) } ) # alias
|
||||||
add( 'rcl', proc { |stack| Rpl::Core.__todo( stack ) } ) # recall a variable. ex: 'name' rcl
|
add( 'rcl', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # recall a variable. ex: 'name' rcl
|
||||||
add( 'purge', proc { |stack| Rpl::Core.__todo( stack ) } ) # delete a variable. ex: 'name' purge
|
add( 'purge', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # delete a variable. ex: 'name' purge
|
||||||
add( 'vars', proc { |stack| Rpl::Core.__todo( stack ) } ) # list all variables
|
add( 'vars', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # list all variables
|
||||||
add( 'clusr', proc { |stack| Rpl::Core.__todo( stack ) } ) # erase all variables
|
add( 'clusr', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # erase all variables
|
||||||
add( 'edit', proc { |stack| Rpl::Core.__todo( stack ) } ) # edit a variable content
|
add( 'edit', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # edit a variable content
|
||||||
add( 'sto+', proc { |stack| Rpl::Core.__todo( stack ) } ) # add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+
|
add( 'sto+', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+
|
||||||
add( 'sto-', proc { |stack| Rpl::Core.__todo( stack ) } ) # substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-
|
add( 'sto-', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-
|
||||||
add( 'sto*', proc { |stack| Rpl::Core.__todo( stack ) } ) # multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*
|
add( 'sto*', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*
|
||||||
add( 'sto/', proc { |stack| Rpl::Core.__todo( stack ) } ) # divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/
|
add( 'sto/', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/
|
||||||
add( 'sneg', proc { |stack| Rpl::Core.__todo( stack ) } ) # negate a variable. ex: 'name' sneg
|
add( 'sneg', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # negate a variable. ex: 'name' sneg
|
||||||
add( 'sinv', proc { |stack| Rpl::Core.__todo( stack ) } ) # inverse a variable. ex: 1 'name' sinv
|
add( 'sinv', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # inverse a variable. ex: 1 'name' sinv
|
||||||
|
|
||||||
# PROGRAM
|
# PROGRAM
|
||||||
add( 'eval', proc { |stack| Rpl::Core.eval( stack, self ) } )
|
add( 'eval', proc { |stack| Rpl::Lang::Core.eval( stack, self ) } )
|
||||||
add( '->', proc { |stack| Rpl::Core.__todo( stack ) } ) # load program local variables. ex: << -> n m << 0 n m for i i + next >> >>
|
add( '->', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # load program local variables. ex: << -> n m << 0 n m for i i + next >> >>
|
||||||
add( '→', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( '→', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
|
|
||||||
# TRIG ON REALS AND COMPLEXES
|
# TRIG ON REALS AND COMPLEXES
|
||||||
add( 'pi', proc { |stack| Rpl::Core.__todo( stack ) } ) # pi constant
|
add( 'pi', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # pi constant
|
||||||
add( 'sin', proc { |stack| Rpl::Core.__todo( stack ) } ) # sinus
|
add( 'sin', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # sinus
|
||||||
add( 'asin', proc { |stack| Rpl::Core.__todo( stack ) } ) # arg sinus
|
add( 'asin', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # arg sinus
|
||||||
add( 'cos', proc { |stack| Rpl::Core.__todo( stack ) } ) # cosinus
|
add( 'cos', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # cosinus
|
||||||
add( 'acos', proc { |stack| Rpl::Core.__todo( stack ) } ) # arg cosinus
|
add( 'acos', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # arg cosinus
|
||||||
add( 'tan', proc { |stack| Rpl::Core.__todo( stack ) } ) # tangent
|
add( 'tan', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # tangent
|
||||||
add( 'atan', proc { |stack| Rpl::Core.__todo( stack ) } ) # arg tangent
|
add( 'atan', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # arg tangent
|
||||||
add( 'd->r', proc { |stack| Rpl::Core.__todo( stack ) } ) # convert degrees to radians
|
add( 'd->r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # convert degrees to radians
|
||||||
add( 'd→r', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'd→r', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
add( 'r->d', proc { |stack| Rpl::Core.__todo( stack ) } ) # convert radians to degrees
|
add( 'r->d', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # convert radians to degrees
|
||||||
add( 'r→d', proc { |stack| Rpl::Core.__todo( stack ) } ) # alias
|
add( 'r→d', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # alias
|
||||||
|
|
||||||
# LOGS ON REALS AND COMPLEXES
|
# LOGS ON REALS AND COMPLEXES
|
||||||
add( 'e', proc { |stack| Rpl::Core.__todo( stack ) } ) # Euler constant
|
add( 'e', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # Euler constant
|
||||||
add( 'ln', proc { |stack| Rpl::Core.__todo( stack ) } ) # logarithm base e
|
add( 'ln', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # logarithm base e
|
||||||
add( 'lnp1', proc { |stack| Rpl::Core.__todo( stack ) } ) # ln(1+x) which is useful when x is close to 0
|
add( 'lnp1', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # ln(1+x) which is useful when x is close to 0
|
||||||
add( 'exp', proc { |stack| Rpl::Core.__todo( stack ) } ) # exponential
|
add( 'exp', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # exponential
|
||||||
add( 'expm', proc { |stack| Rpl::Core.__todo( stack ) } ) # exp(x)-1 which is useful when x is close to 0
|
add( 'expm', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # exp(x)-1 which is useful when x is close to 0
|
||||||
add( 'log10', proc { |stack| Rpl::Core.__todo( stack ) } ) # logarithm base 10
|
add( 'log10', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # logarithm base 10
|
||||||
add( 'alog10', proc { |stack| Rpl::Core.__todo( stack ) } ) # exponential base 10
|
add( 'alog10', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # exponential base 10
|
||||||
add( 'log2', proc { |stack| Rpl::Core.__todo( stack ) } ) # logarithm base 2
|
add( 'log2', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # logarithm base 2
|
||||||
add( 'alog2', proc { |stack| Rpl::Core.__todo( stack ) } ) # exponential base 2
|
add( 'alog2', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # exponential base 2
|
||||||
add( 'sinh', proc { |stack| Rpl::Core.__todo( stack ) } ) # hyperbolic sine
|
add( 'sinh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # hyperbolic sine
|
||||||
add( 'asinh', proc { |stack| Rpl::Core.__todo( stack ) } ) # inverse hyperbolic sine
|
add( 'asinh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # inverse hyperbolic sine
|
||||||
add( 'cosh', proc { |stack| Rpl::Core.__todo( stack ) } ) # hyperbolic cosine
|
add( 'cosh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # hyperbolic cosine
|
||||||
add( 'acosh', proc { |stack| Rpl::Core.__todo( stack ) } ) # inverse hyperbolic cosine
|
add( 'acosh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # inverse hyperbolic cosine
|
||||||
add( 'tanh', proc { |stack| Rpl::Core.__todo( stack ) } ) # hyperbolic tangent
|
add( 'tanh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # hyperbolic tangent
|
||||||
add( 'atanh', proc { |stack| Rpl::Core.__todo( stack ) } ) # inverse hyperbolic tangent
|
add( 'atanh', proc { |stack| Rpl::Lang::Core.__todo( stack ) } ) # inverse hyperbolic tangent
|
||||||
|
|
||||||
# TIME AND DATE
|
# TIME AND DATE
|
||||||
add( 'time', proc { |stack| Rpl::Core.time( stack ) } )
|
add( 'time', proc { |stack| Rpl::Lang::Core.time( stack ) } )
|
||||||
add( 'date', proc { |stack| Rpl::Core.date( stack ) } )
|
add( 'date', proc { |stack| Rpl::Lang::Core.date( stack ) } )
|
||||||
add( 'ticks', proc { |stack| Rpl::Core.ticks( stack ) } )
|
add( 'ticks', proc { |stack| Rpl::Lang::Core.ticks( stack ) } )
|
||||||
end
|
end
|
||||||
|
|
||||||
def add( name, implementation )
|
def add( name, implementation )
|
||||||
|
@ -198,3 +199,4 @@ module Rpl
|
||||||
# TODO: alias
|
# TODO: alias
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
@ -9,11 +10,12 @@ module Rpl
|
||||||
|
|
||||||
# similar to if-then-else-end, <test-instruction> <true-instruction> <false-instruction> ifte
|
# similar to if-then-else-end, <test-instruction> <true-instruction> <false-instruction> ifte
|
||||||
def ifte( stack, dictionary )
|
def ifte( stack, dictionary )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[program word], %i[program word], %i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[program word], %i[program word], %i[boolean]] )
|
||||||
|
|
||||||
stack << args[ args[2][:value] ? 1 : 0 ]
|
stack << args[ args[2][:value] ? 1 : 0 ]
|
||||||
|
|
||||||
Rpl::Core.eval( stack, dictionary )
|
Rpl::Lang::Core.eval( stack, dictionary )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
@ -7,4 +8,5 @@ module Rpl
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# set float precision in bits. ex: 256 prec
|
# set float precision in bits. ex: 256 prec
|
||||||
def prec( stack )
|
def prec( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
Rpl::Core.precision = args[0][:value]
|
Rpl::Lang::Core.precision = args[0][:value]
|
||||||
|
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
# set float representation and precision to default
|
# set float representation and precision to default
|
||||||
def default( stack )
|
def default( stack )
|
||||||
Rpl::Core.precision = 12
|
Rpl::Lang::Core.precision = 12
|
||||||
|
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
# show type of stack first entry
|
# show type of stack first entry
|
||||||
def type( stack )
|
def type( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [:any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any] )
|
||||||
|
|
||||||
stack << args[0]
|
stack << args[0]
|
||||||
stack << { type: :string,
|
stack << { type: :string,
|
||||||
|
@ -28,4 +29,5 @@ module Rpl
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# addition
|
# addition
|
||||||
def add( stack )
|
def add( stack )
|
||||||
addable = %i[numeric string name]
|
addable = %i[numeric string name]
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [addable, addable] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [addable, addable] )
|
||||||
|
|
||||||
result = { type: case args[1][:type]
|
result = { type: case args[1][:type]
|
||||||
when :name
|
when :name
|
||||||
|
@ -40,7 +41,7 @@ module Rpl
|
||||||
|
|
||||||
# substraction
|
# substraction
|
||||||
def subtract( stack )
|
def subtract( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[1][:value] - args[0][:value] }
|
value: args[1][:value] - args[0][:value] }
|
||||||
|
@ -48,7 +49,7 @@ module Rpl
|
||||||
|
|
||||||
# negation
|
# negation
|
||||||
def negate( stack )
|
def negate( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[0][:value] * -1 }
|
value: args[0][:value] * -1 }
|
||||||
|
@ -56,7 +57,7 @@ module Rpl
|
||||||
|
|
||||||
# multiplication
|
# multiplication
|
||||||
def multiply( stack )
|
def multiply( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[1][:value] * args[0][:value] }
|
value: args[1][:value] * args[0][:value] }
|
||||||
|
@ -64,7 +65,7 @@ module Rpl
|
||||||
|
|
||||||
# division
|
# division
|
||||||
def divide( stack )
|
def divide( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
||||||
|
|
||||||
raise 'Division by 0' if args[0][:value].zero?
|
raise 'Division by 0' if args[0][:value].zero?
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ module Rpl
|
||||||
|
|
||||||
# inverse
|
# inverse
|
||||||
def inverse( stack )
|
def inverse( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
raise 'Division by 0' if args[0][:value].zero?
|
raise 'Division by 0' if args[0][:value].zero?
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ module Rpl
|
||||||
|
|
||||||
# power
|
# power
|
||||||
def power( stack )
|
def power( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[1][:value]**args[0][:value] }
|
value: args[1][:value]**args[0][:value] }
|
||||||
|
@ -92,15 +93,15 @@ module Rpl
|
||||||
|
|
||||||
# rpn_square root
|
# rpn_square root
|
||||||
def sqrt( stack )
|
def sqrt( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: BigMath.sqrt( BigDecimal( args[0][:value] ), Rpl::Core.precision ) }
|
value: BigMath.sqrt( BigDecimal( args[0][:value] ), Rpl::Lang::Core.precision ) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# rpn_square
|
# rpn_square
|
||||||
def sq( stack )
|
def sq( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[0][:value] * args[0][:value] }
|
value: args[0][:value] * args[0][:value] }
|
||||||
|
@ -108,7 +109,7 @@ module Rpl
|
||||||
|
|
||||||
# absolute value
|
# absolute value
|
||||||
def abs( stack )
|
def abs( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :numeric, base: 10,
|
stack << { type: :numeric, base: 10,
|
||||||
value: args[0][:value].abs }
|
value: args[0][:value].abs }
|
||||||
|
@ -131,7 +132,7 @@ module Rpl
|
||||||
|
|
||||||
# arbitrary base representation
|
# arbitrary base representation
|
||||||
def base( stack )
|
def base( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric]] )
|
||||||
|
|
||||||
args[1][:base] = args[0][:value]
|
args[1][:base] = args[0][:value]
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ module Rpl
|
||||||
|
|
||||||
# 1 if number at stack level 1 is > 0, 0 if == 0, -1 if <= 0
|
# 1 if number at stack level 1 is > 0, 0 if == 0, -1 if <= 0
|
||||||
def sign( stack )
|
def sign( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
value = if args[0][:value].positive?
|
value = if args[0][:value].positive?
|
||||||
1
|
1
|
||||||
elsif args[0][:value].negative?
|
elsif args[0][:value].negative?
|
||||||
|
@ -153,4 +154,5 @@ module Rpl
|
||||||
value: value }
|
value: value }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# evaluate (run) a program, or recall a variable. ex: 'my_prog' eval
|
# evaluate (run) a program, or recall a variable. ex: 'my_prog' eval
|
||||||
def eval( stack, dictionary )
|
def eval( stack, dictionary )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[program word name]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[program word name]] )
|
||||||
|
|
||||||
# we trim enclosing «»
|
# we trim enclosing «»
|
||||||
preparsed_input = args[0][:type] == :word ? args[0][:value] : args[0][:value][1..-2]
|
preparsed_input = args[0][:type] == :word ? args[0][:value] : args[0][:value][1..-2]
|
||||||
parsed_input = Rpl::Parser.new.parse_input( preparsed_input )
|
parsed_input = Rpl::Lang::Parser.new.parse_input( preparsed_input )
|
||||||
|
|
||||||
stack, _dictionary = Rpl::Runner.new.run_input( stack, dictionary, parsed_input )
|
stack, _dictionary = Rpl::Lang::Runner.new.run_input( stack, dictionary, parsed_input )
|
||||||
# TODO: check that STO actually updates dictionary
|
# TODO: check that STO actually updates dictionary
|
||||||
|
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# swap 2 first stack entries
|
# swap 2 first stack entries
|
||||||
def swap( stack )
|
def swap( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << args[0] << args[1]
|
stack << args[0] << args[1]
|
||||||
end
|
end
|
||||||
|
@ -21,8 +22,8 @@ module Rpl
|
||||||
|
|
||||||
# drop n first stack entries
|
# drop n first stack entries
|
||||||
def dropn( stack )
|
def dropn( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
stack, _args = Rpl::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
stack, _args = Rpl::Lang::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
||||||
|
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
@ -34,7 +35,7 @@ module Rpl
|
||||||
|
|
||||||
# rotate 3 first stack entries
|
# rotate 3 first stack entries
|
||||||
def rot( stack )
|
def rot( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any any] )
|
||||||
|
|
||||||
stack << args[1] << args[0] << args[2]
|
stack << args[1] << args[0] << args[2]
|
||||||
end
|
end
|
||||||
|
@ -51,9 +52,9 @@ module Rpl
|
||||||
|
|
||||||
# duplicate n first stack entries
|
# duplicate n first stack entries
|
||||||
def dupn( stack )
|
def dupn( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
n = args[0][:value]
|
n = args[0][:value]
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
||||||
|
|
||||||
args.reverse!
|
args.reverse!
|
||||||
|
|
||||||
|
@ -68,9 +69,9 @@ module Rpl
|
||||||
|
|
||||||
# push a copy of the given stack level onto the stack
|
# push a copy of the given stack level onto the stack
|
||||||
def pick( stack )
|
def pick( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
n = args[0][:value]
|
n = args[0][:value]
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
||||||
|
|
||||||
args.reverse!
|
args.reverse!
|
||||||
|
|
||||||
|
@ -89,9 +90,9 @@ module Rpl
|
||||||
|
|
||||||
# move a stack entry to the top of the stack
|
# move a stack entry to the top of the stack
|
||||||
def roll( stack )
|
def roll( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
n = args[0][:value]
|
n = args[0][:value]
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
||||||
|
|
||||||
args.reverse!
|
args.reverse!
|
||||||
|
|
||||||
|
@ -105,9 +106,9 @@ module Rpl
|
||||||
|
|
||||||
# move the element on top of the stack to a higher stack position
|
# move the element on top of the stack to a higher stack position
|
||||||
def rolld( stack )
|
def rolld( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
n = args[0][:value]
|
n = args[0][:value]
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any] * args[0][:value] )
|
||||||
|
|
||||||
args.reverse!
|
args.reverse!
|
||||||
|
|
||||||
|
@ -125,4 +126,5 @@ module Rpl
|
||||||
pick( stack << { type: :numeric, base: 10, value: 2 } )
|
pick( stack << { type: :numeric, base: 10, value: 2 } )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# convert an object into a string
|
# convert an object into a string
|
||||||
def to_string( stack )
|
def to_string( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [:any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any] )
|
||||||
|
|
||||||
stack << { type: :string,
|
stack << { type: :string,
|
||||||
value: args[0][:value].to_s }
|
value: args[0][:value].to_s }
|
||||||
|
@ -12,16 +13,16 @@ module Rpl
|
||||||
|
|
||||||
# convert a string into an object
|
# convert a string into an object
|
||||||
def from_string( stack )
|
def from_string( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[string]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[string]] )
|
||||||
|
|
||||||
parsed_input = Rpl::Parser.new.parse_input( args[0][:value] )
|
parsed_input = Rpl::Lang::Parser.new.parse_input( args[0][:value] )
|
||||||
|
|
||||||
stack + parsed_input
|
stack + parsed_input
|
||||||
end
|
end
|
||||||
|
|
||||||
# convert ASCII character code in stack level 1 into a string
|
# convert ASCII character code in stack level 1 into a string
|
||||||
def chr( stack )
|
def chr( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
|
||||||
|
|
||||||
stack << { type: :string,
|
stack << { type: :string,
|
||||||
value: args[0][:value].chr }
|
value: args[0][:value].chr }
|
||||||
|
@ -29,7 +30,7 @@ module Rpl
|
||||||
|
|
||||||
# return ASCII code of the first character of the string in stack level 1 as a real number
|
# return ASCII code of the first character of the string in stack level 1 as a real number
|
||||||
def num( stack )
|
def num( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[string]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[string]] )
|
||||||
|
|
||||||
stack << { type: :numeric,
|
stack << { type: :numeric,
|
||||||
base: 10,
|
base: 10,
|
||||||
|
@ -38,7 +39,7 @@ module Rpl
|
||||||
|
|
||||||
# return the length of the string
|
# return the length of the string
|
||||||
def size( stack )
|
def size( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[string]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[string]] )
|
||||||
|
|
||||||
stack << { type: :numeric,
|
stack << { type: :numeric,
|
||||||
base: 10,
|
base: 10,
|
||||||
|
@ -47,7 +48,7 @@ module Rpl
|
||||||
|
|
||||||
# search for the string in level 1 within the string in level 2
|
# search for the string in level 1 within the string in level 2
|
||||||
def pos( stack )
|
def pos( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[string], %i[string]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[string], %i[string]] )
|
||||||
|
|
||||||
stack << { type: :numeric,
|
stack << { type: :numeric,
|
||||||
base: 10,
|
base: 10,
|
||||||
|
@ -56,10 +57,11 @@ module Rpl
|
||||||
|
|
||||||
# return a substring of the string in level 3
|
# return a substring of the string in level 3
|
||||||
def sub( stack )
|
def sub( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[numeric], %i[numeric], %i[string]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric], %i[string]] )
|
||||||
|
|
||||||
stack << { type: :string,
|
stack << { type: :string,
|
||||||
value: args[2][:value][args[1][:value]..args[0][:value]] }
|
value: args[2][:value][args[1][:value]..args[0][:value]] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# binary operator >
|
# binary operator >
|
||||||
def greater_than( stack )
|
def greater_than( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] > args[0][:value] }
|
value: args[1][:value] > args[0][:value] }
|
||||||
|
@ -13,7 +14,7 @@ module Rpl
|
||||||
|
|
||||||
# binary operator >=
|
# binary operator >=
|
||||||
def greater_or_equal_than( stack )
|
def greater_or_equal_than( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] >= args[0][:value] }
|
value: args[1][:value] >= args[0][:value] }
|
||||||
|
@ -22,7 +23,7 @@ module Rpl
|
||||||
|
|
||||||
# binary operator <
|
# binary operator <
|
||||||
def less_than( stack )
|
def less_than( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] < args[0][:value] }
|
value: args[1][:value] < args[0][:value] }
|
||||||
|
@ -31,7 +32,7 @@ module Rpl
|
||||||
|
|
||||||
# binary operator <=
|
# binary operator <=
|
||||||
def less_or_equal_than( stack )
|
def less_or_equal_than( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] <= args[0][:value] }
|
value: args[1][:value] <= args[0][:value] }
|
||||||
|
@ -40,7 +41,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator != (different)
|
# boolean operator != (different)
|
||||||
def different( stack )
|
def different( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] != args[0][:value] }
|
value: args[1][:value] != args[0][:value] }
|
||||||
|
@ -49,7 +50,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator and
|
# boolean operator and
|
||||||
def and( stack )
|
def and( stack )
|
||||||
stack, args = Rpl::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,
|
||||||
value: args[1][:value] && args[0][:value] }
|
value: args[1][:value] && args[0][:value] }
|
||||||
|
@ -58,7 +59,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator or
|
# boolean operator or
|
||||||
def or( stack )
|
def or( stack )
|
||||||
stack, args = Rpl::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,
|
||||||
value: args[1][:value] || args[0][:value] }
|
value: args[1][:value] || args[0][:value] }
|
||||||
|
@ -67,7 +68,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator xor
|
# boolean operator xor
|
||||||
def xor( stack )
|
def xor( stack )
|
||||||
stack, args = Rpl::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,
|
||||||
value: args[1][:value] ^ args[0][:value] }
|
value: args[1][:value] ^ args[0][:value] }
|
||||||
|
@ -76,7 +77,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator not
|
# boolean operator not
|
||||||
def not( stack )
|
def not( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, [%i[boolean]] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[boolean]] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: !args[0][:value] }
|
value: !args[0][:value] }
|
||||||
|
@ -85,7 +86,7 @@ module Rpl
|
||||||
|
|
||||||
# boolean operator same (equal)
|
# boolean operator same (equal)
|
||||||
def same( stack )
|
def same( stack )
|
||||||
stack, args = Rpl::Core.stack_extract( stack, %i[any any] )
|
stack, args = Rpl::Lang::Core.stack_extract( stack, %i[any any] )
|
||||||
|
|
||||||
stack << { type: :boolean,
|
stack << { type: :boolean,
|
||||||
value: args[1][:value] == args[0][:value] }
|
value: args[1][:value] == args[0][:value] }
|
||||||
|
@ -106,4 +107,5 @@ module Rpl
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'date'
|
require 'date'
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
module Core
|
module Core
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
@ -25,4 +26,5 @@ module Rpl
|
||||||
value: now.to_i * 10_000_000 + now.nsec / 100 - ticks_since_epoch }
|
value: now.to_i * 10_000_000 + now.nsec / 100 - ticks_since_epoch }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
class Parser
|
class Parser
|
||||||
def initialize; end
|
def initialize; end
|
||||||
|
|
||||||
|
@ -85,4 +86,5 @@ module Rpl
|
||||||
parsed_tree
|
parsed_tree
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
|
module Lang
|
||||||
class Runner
|
class Runner
|
||||||
def initialize; end
|
def initialize; end
|
||||||
|
|
||||||
|
@ -23,4 +24,5 @@ module Rpl
|
||||||
[stack, dictionary]
|
[stack, dictionary]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
15
repl.rb
15
repl.rb
|
@ -9,7 +9,9 @@ require './lib/parser'
|
||||||
require './lib/runner'
|
require './lib/runner'
|
||||||
|
|
||||||
module Rpl
|
module Rpl
|
||||||
class Repl
|
class Language
|
||||||
|
attr_reader :stack
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@stack = []
|
@stack = []
|
||||||
@dictionary = Dictionary.new
|
@dictionary = Dictionary.new
|
||||||
|
@ -17,6 +19,17 @@ module Rpl
|
||||||
@runner = Runner.new
|
@runner = Runner.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run( input )
|
||||||
|
@stack, @dictionary = @runner.run_input( @stack, @dictionary,
|
||||||
|
@parser.parse_input( input ) )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Repl
|
||||||
|
def initialize
|
||||||
|
@lang = Rpl::Language.new
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
Readline.completion_proc = proc do |s|
|
Readline.completion_proc = proc do |s|
|
||||||
Readline::HISTORY.grep(/^#{Regexp.escape(s)}/)
|
Readline::HISTORY.grep(/^#{Regexp.escape(s)}/)
|
||||||
|
|
|
@ -7,7 +7,7 @@ require_relative '../lib/core'
|
||||||
|
|
||||||
class TestParser < Test::Unit::TestCase
|
class TestParser < Test::Unit::TestCase
|
||||||
def test_stack_extract
|
def test_stack_extract
|
||||||
stack, args = Rpl::Core.stack_extract [{ value: 1, type: :numeric },
|
stack, args = Rpl::Lang::Core.stack_extract [{ value: 1, type: :numeric },
|
||||||
{ value: 2, type: :numeric }],
|
{ value: 2, type: :numeric }],
|
||||||
[:any]
|
[:any]
|
||||||
assert_equal [{ value: 1, type: :numeric }],
|
assert_equal [{ value: 1, type: :numeric }],
|
||||||
|
@ -15,7 +15,7 @@ class TestParser < Test::Unit::TestCase
|
||||||
assert_equal [{ value: 2, type: :numeric }],
|
assert_equal [{ value: 2, type: :numeric }],
|
||||||
args
|
args
|
||||||
|
|
||||||
stack, args = Rpl::Core.stack_extract [{ value: 'test', type: :string },
|
stack, args = Rpl::Lang::Core.stack_extract [{ value: 'test', type: :string },
|
||||||
{ value: 2, type: :numeric }],
|
{ value: 2, type: :numeric }],
|
||||||
[[:numeric], :any]
|
[[:numeric], :any]
|
||||||
assert_equal [],
|
assert_equal [],
|
||||||
|
|
|
@ -10,18 +10,18 @@ require_relative '../lib/runner'
|
||||||
|
|
||||||
class TestLanguageBranch < Test::Unit::TestCase
|
class TestLanguageBranch < Test::Unit::TestCase
|
||||||
def test_ifte
|
def test_ifte
|
||||||
stack = Rpl::Core.ifte( [{ type: :boolean, value: true },
|
stack = Rpl::Lang::Core.ifte( [{ type: :boolean, value: true },
|
||||||
{ type: :program, value: '« 2 3 + »' },
|
{ type: :program, value: '« 2 3 + »' },
|
||||||
{ type: :program, value: '« 2 3 - »' }],
|
{ type: :program, value: '« 2 3 - »' }],
|
||||||
Rpl::Dictionary.new )
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.ifte( [{ type: :boolean, value: false },
|
stack = Rpl::Lang::Core.ifte( [{ type: :boolean, value: false },
|
||||||
{ type: :program, value: '« 2 3 + »' },
|
{ type: :program, value: '« 2 3 + »' },
|
||||||
{ type: :program, value: '« 2 3 - »' }],
|
{ type: :program, value: '« 2 3 - »' }],
|
||||||
Rpl::Dictionary.new )
|
Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
|
@ -7,155 +7,155 @@ require_relative '../lib/core'
|
||||||
|
|
||||||
class TesttLanguageOperations < Test::Unit::TestCase
|
class TesttLanguageOperations < Test::Unit::TestCase
|
||||||
def test_add
|
def test_add
|
||||||
stack = Rpl::Core.add [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.add [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 3, type: :numeric, base: 10 }],
|
assert_equal [{ value: 3, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.add [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: '"a"', type: :string }]
|
{ value: '"a"', type: :string }]
|
||||||
assert_equal [{ value: '"1a"', type: :string }],
|
assert_equal [{ value: '"1a"', type: :string }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.add [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: "'a'", type: :name }]
|
{ value: "'a'", type: :name }]
|
||||||
assert_equal [{ value: '"1a"', type: :string }],
|
assert_equal [{ value: '"1a"', type: :string }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: "'a'", type: :name },
|
stack = Rpl::Lang::Core.add [{ value: "'a'", type: :name },
|
||||||
{ value: 1, type: :numeric, base: 10 }]
|
{ value: 1, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: "'a1'", type: :name }],
|
assert_equal [{ value: "'a1'", type: :name }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: "'a'", type: :name },
|
stack = Rpl::Lang::Core.add [{ value: "'a'", type: :name },
|
||||||
{ value: '"b"', type: :string }]
|
{ value: '"b"', type: :string }]
|
||||||
assert_equal [{ value: "'ab'", type: :name }],
|
assert_equal [{ value: "'ab'", type: :name }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: "'a'", type: :name },
|
stack = Rpl::Lang::Core.add [{ value: "'a'", type: :name },
|
||||||
{ value: "'b'", type: :name }]
|
{ value: "'b'", type: :name }]
|
||||||
assert_equal [{ value: "'ab'", type: :name }],
|
assert_equal [{ value: "'ab'", type: :name }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: '"a"', type: :string },
|
stack = Rpl::Lang::Core.add [{ value: '"a"', type: :string },
|
||||||
{ value: '"b"', type: :string }]
|
{ value: '"b"', type: :string }]
|
||||||
assert_equal [{ value: '"ab"', type: :string }],
|
assert_equal [{ value: '"ab"', type: :string }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: '"a"', type: :string },
|
stack = Rpl::Lang::Core.add [{ value: '"a"', type: :string },
|
||||||
{ value: "'b'", type: :name }]
|
{ value: "'b'", type: :name }]
|
||||||
assert_equal [{ value: '"ab"', type: :string }],
|
assert_equal [{ value: '"ab"', type: :string }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.add [{ value: '"a"', type: :string },
|
stack = Rpl::Lang::Core.add [{ value: '"a"', type: :string },
|
||||||
{ value: 1, type: :numeric, base: 10 }]
|
{ value: 1, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: '"a1"', type: :string }],
|
assert_equal [{ value: '"a1"', type: :string }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_subtract
|
def test_subtract
|
||||||
stack = Rpl::Core.subtract [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.subtract [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.subtract [{ value: 2, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.subtract [{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 1, type: :numeric, base: 10 }]
|
{ value: 1, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_negate
|
def test_negate
|
||||||
stack = Rpl::Core.negate [{ value: -1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.negate [{ value: -1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.negate [{ value: 1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.negate [{ value: 1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiply
|
def test_multiply
|
||||||
stack = Rpl::Core.multiply [{ value: 3, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.multiply [{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }]
|
{ value: 4, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 12, type: :numeric, base: 10 }],
|
assert_equal [{ value: 12, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_divide
|
def test_divide
|
||||||
stack = Rpl::Core.divide [{ value: 3.0, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.divide [{ value: 3.0, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }]
|
{ value: 4, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 0.75, type: :numeric, base: 10 }],
|
assert_equal [{ value: 0.75, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
# stack = Rpl::Core.divide [{ value: 3, type: :numeric, base: 10 },
|
# stack = Rpl::Lang::Core.divide [{ value: 3, type: :numeric, base: 10 },
|
||||||
# { value: 4, type: :numeric, base: 10 }]
|
# { value: 4, type: :numeric, base: 10 }]
|
||||||
# assert_equal [{ value: 0.75, type: :numeric, base: 10 }],
|
# assert_equal [{ value: 0.75, type: :numeric, base: 10 }],
|
||||||
# stack
|
# stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inverse
|
def test_inverse
|
||||||
stack = Rpl::Core.inverse [{ value: 4, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.inverse [{ value: 4, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 0.25, type: :numeric, base: 10 }],
|
assert_equal [{ value: 0.25, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_power
|
def test_power
|
||||||
stack = Rpl::Core.power [{ value: 3, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.power [{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }]
|
{ value: 4, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 81, type: :numeric, base: 10 }],
|
assert_equal [{ value: 81, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sqrt
|
def test_sqrt
|
||||||
stack = Rpl::Core.sqrt [{ value: 16, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.sqrt [{ value: 16, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sq
|
def test_sq
|
||||||
stack = Rpl::Core.sq [{ value: 4, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.sq [{ value: 4, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 16, type: :numeric, base: 10 }],
|
assert_equal [{ value: 16, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_abs
|
def test_abs
|
||||||
stack = Rpl::Core.abs [{ value: -1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.abs [{ value: -1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.abs [{ value: 1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.abs [{ value: 1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dec
|
def test_dec
|
||||||
stack = Rpl::Core.dec [{ value: 1, type: :numeric, base: 16 }]
|
stack = Rpl::Lang::Core.dec [{ value: 1, type: :numeric, base: 16 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hex
|
def test_hex
|
||||||
stack = Rpl::Core.hex [{ value: 1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.hex [{ value: 1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 16 }],
|
assert_equal [{ value: 1, type: :numeric, base: 16 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bin
|
def test_bin
|
||||||
stack = Rpl::Core.bin [{ value: 1, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.bin [{ value: 1, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 2 }],
|
assert_equal [{ value: 1, type: :numeric, base: 2 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_base
|
def test_base
|
||||||
stack = Rpl::Core.base [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.base [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 31, type: :numeric, base: 10 }]
|
{ value: 31, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 31 }],
|
assert_equal [{ value: 1, type: :numeric, base: 31 }],
|
||||||
|
@ -163,16 +163,16 @@ class TesttLanguageOperations < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sign
|
def test_sign
|
||||||
stack = Rpl::Core.sign [{ value: -10, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.sign [{ value: -10, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.sign [{ value: 10, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.sign [{ value: 10, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
stack = Rpl::Core.sign [{ value: 0, type: :numeric, base: 10 }]
|
stack = Rpl::Lang::Core.sign [{ value: 0, type: :numeric, base: 10 }]
|
||||||
|
|
||||||
assert_equal [{ value: 0, type: :numeric, base: 10 }],
|
assert_equal [{ value: 0, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
|
@ -10,24 +10,31 @@ require_relative '../lib/runner'
|
||||||
|
|
||||||
class TestLanguageProgram < Test::Unit::TestCase
|
class TestLanguageProgram < Test::Unit::TestCase
|
||||||
def test_eval
|
def test_eval
|
||||||
stack = Rpl::Core.eval( [{ value: '« 2 dup * dup »', type: :program }], Rpl::Dictionary.new )
|
stack = Rpl::Lang::Core.eval( [{ value: '« 2 dup * dup »', type: :program }], Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }],
|
{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.eval( [{ value: 4, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.eval( [{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: "'dup'", type: :name }], Rpl::Dictionary.new )
|
{ value: "'dup'", type: :name }], Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }],
|
{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.eval( [{ value: 4, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.eval( [{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: 'dup', type: :word }], Rpl::Dictionary.new )
|
{ value: 'dup', type: :word }], Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }],
|
{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sto
|
||||||
|
stack = Rpl::Lang::Core.sto( [{ value: '« 2 dup »', type: :program },
|
||||||
|
{ value: "'quatre'", type: :name }], Rpl::Lang::Dictionary.new )
|
||||||
|
|
||||||
|
assert_equal [], stack
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ require_relative '../lib/core'
|
||||||
|
|
||||||
class TestLanguageStack < Test::Unit::TestCase
|
class TestLanguageStack < Test::Unit::TestCase
|
||||||
def test_swap
|
def test_swap
|
||||||
stack = Rpl::Core.swap [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.swap [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 1, type: :numeric, base: 10 }],
|
{ value: 1, type: :numeric, base: 10 }],
|
||||||
|
@ -15,21 +15,21 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_drop
|
def test_drop
|
||||||
stack = Rpl::Core.drop [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.drop [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_drop2
|
def test_drop2
|
||||||
stack = Rpl::Core.drop2 [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.drop2 [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [],
|
assert_equal [],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dropn
|
def test_dropn
|
||||||
stack = Rpl::Core.dropn [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.dropn [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 },
|
{ value: 4, type: :numeric, base: 10 },
|
||||||
|
@ -39,14 +39,14 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_del
|
def test_del
|
||||||
stack = Rpl::Core.del [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.del [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [],
|
assert_equal [],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rot
|
def test_rot
|
||||||
stack = Rpl::Core.rot [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.rot [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 }]
|
{ value: 3, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
||||||
|
@ -56,7 +56,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
stack = Rpl::Core.dup [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.dup [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
|
@ -65,7 +65,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup2
|
def test_dup2
|
||||||
stack = Rpl::Core.dup2 [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.dup2 [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
|
@ -75,7 +75,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dupn
|
def test_dupn
|
||||||
stack = Rpl::Core.dupn [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.dupn [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 },
|
{ value: 4, type: :numeric, base: 10 },
|
||||||
|
@ -91,7 +91,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pick
|
def test_pick
|
||||||
stack = Rpl::Core.pick [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.pick [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 },
|
{ value: 4, type: :numeric, base: 10 },
|
||||||
|
@ -105,11 +105,11 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_depth
|
def test_depth
|
||||||
stack = Rpl::Core.depth []
|
stack = Rpl::Lang::Core.depth []
|
||||||
assert_equal [{ value: 0, type: :numeric, base: 10 }],
|
assert_equal [{ value: 0, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.depth [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.depth [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }]
|
{ value: 2, type: :numeric, base: 10 }]
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
|
@ -118,7 +118,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_roll
|
def test_roll
|
||||||
stack = Rpl::Core.roll [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.roll [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 },
|
{ value: 4, type: :numeric, base: 10 },
|
||||||
|
@ -131,7 +131,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rolld
|
def test_rolld
|
||||||
stack = Rpl::Core.rolld [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.rolld [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 },
|
{ value: 4, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
|
@ -144,7 +144,7 @@ class TestLanguageStack < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_over
|
def test_over
|
||||||
stack = Rpl::Core.over [{ value: 1, type: :numeric, base: 10 },
|
stack = Rpl::Lang::Core.over [{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 },
|
{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: 4, type: :numeric, base: 10 }]
|
{ value: 4, type: :numeric, base: 10 }]
|
||||||
|
|
|
@ -8,19 +8,19 @@ require_relative '../lib/parser'
|
||||||
|
|
||||||
class TestLanguageString < Test::Unit::TestCase
|
class TestLanguageString < Test::Unit::TestCase
|
||||||
def test_to_string
|
def test_to_string
|
||||||
stack = Rpl::Core.to_string( [{ value: 2, type: :numeric, base: 10 }] )
|
stack = Rpl::Lang::Core.to_string( [{ value: 2, type: :numeric, base: 10 }] )
|
||||||
|
|
||||||
assert_equal [{ value: '2', type: :string }],
|
assert_equal [{ value: '2', type: :string }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_from_string
|
def test_from_string
|
||||||
stack = Rpl::Core.from_string( [{ value: '2', type: :string }] )
|
stack = Rpl::Lang::Core.from_string( [{ value: '2', type: :string }] )
|
||||||
|
|
||||||
assert_equal [{ value: 2, type: :numeric, base: 10 }],
|
assert_equal [{ value: 2, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
|
|
||||||
stack = Rpl::Core.from_string( [{ value: "« 2 dup * » 'carré' sto", type: :string }] )
|
stack = Rpl::Lang::Core.from_string( [{ value: "« 2 dup * » 'carré' sto", type: :string }] )
|
||||||
|
|
||||||
assert_equal [{ value: '« 2 dup * »', type: :program },
|
assert_equal [{ value: '« 2 dup * »', type: :program },
|
||||||
{ value: "'carré'", type: :name },
|
{ value: "'carré'", type: :name },
|
||||||
|
@ -29,28 +29,28 @@ class TestLanguageString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chr
|
def test_chr
|
||||||
stack = Rpl::Core.chr( [{ value: 71, type: :numeric, base: 10 }] )
|
stack = Rpl::Lang::Core.chr( [{ value: 71, type: :numeric, base: 10 }] )
|
||||||
|
|
||||||
assert_equal [{ value: 'G', type: :string }],
|
assert_equal [{ value: 'G', type: :string }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_num
|
def test_num
|
||||||
stack = Rpl::Core.num( [{ value: 'G', type: :string }] )
|
stack = Rpl::Lang::Core.num( [{ value: 'G', type: :string }] )
|
||||||
|
|
||||||
assert_equal [{ value: 71, type: :numeric, base: 10 }],
|
assert_equal [{ value: 71, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
stack = Rpl::Core.size( [{ value: 'test', type: :string }] )
|
stack = Rpl::Lang::Core.size( [{ value: 'test', type: :string }] )
|
||||||
|
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
assert_equal [{ value: 4, type: :numeric, base: 10 }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pos
|
def test_pos
|
||||||
stack = Rpl::Core.pos( [{ value: 'test of POS', type: :string },
|
stack = Rpl::Lang::Core.pos( [{ value: 'test of POS', type: :string },
|
||||||
{ value: 'of', type: :string }] )
|
{ value: 'of', type: :string }] )
|
||||||
|
|
||||||
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
||||||
|
@ -58,7 +58,7 @@ class TestLanguageString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sub
|
def test_sub
|
||||||
stack = Rpl::Core.sub( [{ value: 'test', type: :string },
|
stack = Rpl::Lang::Core.sub( [{ value: 'test', type: :string },
|
||||||
{ value: 1, type: :numeric, base: 10 },
|
{ value: 1, type: :numeric, base: 10 },
|
||||||
{ value: 2, type: :numeric, base: 10 }] )
|
{ value: 2, type: :numeric, base: 10 }] )
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ require_relative '../lib/core'
|
||||||
class TestLanguageTimeDate < Test::Unit::TestCase
|
class TestLanguageTimeDate < Test::Unit::TestCase
|
||||||
def test_time
|
def test_time
|
||||||
now = Time.now.to_s
|
now = Time.now.to_s
|
||||||
stack = Rpl::Core.time( [] )
|
stack = Rpl::Lang::Core.time( [] )
|
||||||
|
|
||||||
assert_equal [{ value: now, type: :string }],
|
assert_equal [{ value: now, type: :string }],
|
||||||
stack
|
stack
|
||||||
|
@ -16,14 +16,14 @@ class TestLanguageTimeDate < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_date
|
def test_date
|
||||||
now = Date.today.to_s
|
now = Date.today.to_s
|
||||||
stack = Rpl::Core.date( [] )
|
stack = Rpl::Lang::Core.date( [] )
|
||||||
|
|
||||||
assert_equal [{ value: now, type: :string }],
|
assert_equal [{ value: now, type: :string }],
|
||||||
stack
|
stack
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ticks
|
def test_ticks
|
||||||
stack = Rpl::Core.ticks( [] )
|
stack = Rpl::Lang::Core.ticks( [] )
|
||||||
|
|
||||||
# TODO: better test, but how?
|
# TODO: better test, but how?
|
||||||
assert_equal :numeric,
|
assert_equal :numeric,
|
||||||
|
|
|
@ -7,76 +7,76 @@ require_relative '../lib/parser'
|
||||||
|
|
||||||
class TestParser < Test::Unit::TestCase
|
class TestParser < Test::Unit::TestCase
|
||||||
def test_number
|
def test_number
|
||||||
result = Rpl::Parser.new.parse_input( '1' )
|
result = Rpl::Lang::Parser.new.parse_input( '1' )
|
||||||
assert_equal [{ value: 1, type: :numeric, base: 10 }], result
|
assert_equal [{ value: 1, type: :numeric, base: 10 }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_word
|
def test_word
|
||||||
result = Rpl::Parser.new.parse_input( 'dup' )
|
result = Rpl::Lang::Parser.new.parse_input( 'dup' )
|
||||||
assert_equal [{ value: 'dup', type: :word }], result
|
assert_equal [{ value: 'dup', type: :word }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_string
|
def test_string
|
||||||
result = Rpl::Parser.new.parse_input( '"test"' )
|
result = Rpl::Lang::Parser.new.parse_input( '"test"' )
|
||||||
assert_equal [{ value: '"test"', type: :string }], result
|
assert_equal [{ value: '"test"', type: :string }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '" test"' )
|
result = Rpl::Lang::Parser.new.parse_input( '" test"' )
|
||||||
assert_equal [{ value: '" test"', type: :string }], result
|
assert_equal [{ value: '" test"', type: :string }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '"test "' )
|
result = Rpl::Lang::Parser.new.parse_input( '"test "' )
|
||||||
assert_equal [{ value: '"test "', type: :string }], result
|
assert_equal [{ value: '"test "', type: :string }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '" test "' )
|
result = Rpl::Lang::Parser.new.parse_input( '" test "' )
|
||||||
assert_equal [{ value: '" test "', type: :string }], result
|
assert_equal [{ value: '" test "', type: :string }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
result = Rpl::Parser.new.parse_input( "'test'" )
|
result = Rpl::Lang::Parser.new.parse_input( "'test'" )
|
||||||
assert_equal [{ value: "'test'", type: :name }], result
|
assert_equal [{ value: "'test'", type: :name }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_program
|
def test_program
|
||||||
result = Rpl::Parser.new.parse_input( '« test »' )
|
result = Rpl::Lang::Parser.new.parse_input( '« test »' )
|
||||||
assert_equal [{ value: '« test »', type: :program }], result
|
assert_equal [{ value: '« test »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '«test »' )
|
result = Rpl::Lang::Parser.new.parse_input( '«test »' )
|
||||||
assert_equal [{ value: '« test »', type: :program }], result
|
assert_equal [{ value: '« test »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '« test»' )
|
result = Rpl::Lang::Parser.new.parse_input( '« test»' )
|
||||||
assert_equal [{ value: '« test »', type: :program }], result
|
assert_equal [{ value: '« test »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '«test»' )
|
result = Rpl::Lang::Parser.new.parse_input( '«test»' )
|
||||||
assert_equal [{ value: '« test »', type: :program }], result
|
assert_equal [{ value: '« test »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '« test test »' )
|
result = Rpl::Lang::Parser.new.parse_input( '« test test »' )
|
||||||
assert_equal [{ value: '« test test »', type: :program }], result
|
assert_equal [{ value: '« test test »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '« test « test » »' )
|
result = Rpl::Lang::Parser.new.parse_input( '« test « test » »' )
|
||||||
assert_equal [{ value: '« test « test » »', type: :program }], result
|
assert_equal [{ value: '« test « test » »', type: :program }], result
|
||||||
|
|
||||||
result = Rpl::Parser.new.parse_input( '« test "test" test »' )
|
result = Rpl::Lang::Parser.new.parse_input( '« test "test" test »' )
|
||||||
assert_equal [{ value: '« test "test" test »', type: :program }], result
|
assert_equal [{ value: '« test "test" test »', type: :program }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_number
|
def test_number_number
|
||||||
result = Rpl::Parser.new.parse_input( '2 3' )
|
result = Rpl::Lang::Parser.new.parse_input( '2 3' )
|
||||||
assert_equal [{ value: 2, type: :numeric, base: 10 }, { value: 3, type: :numeric, base: 10 }], result
|
assert_equal [{ value: 2, type: :numeric, base: 10 }, { value: 3, type: :numeric, base: 10 }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_number_word
|
def test_number_number_word
|
||||||
result = Rpl::Parser.new.parse_input( '2 3 +' )
|
result = Rpl::Lang::Parser.new.parse_input( '2 3 +' )
|
||||||
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
||||||
{ value: 3, type: :numeric, base: 10 },
|
{ value: 3, type: :numeric, base: 10 },
|
||||||
{ value: '+', type: :word }], result
|
{ value: '+', type: :word }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_string
|
def test_number_string
|
||||||
result = Rpl::Parser.new.parse_input( '4 "test"' )
|
result = Rpl::Lang::Parser.new.parse_input( '4 "test"' )
|
||||||
assert_equal [{ value: 4, type: :numeric, base: 10 }, { value: '"test"', type: :string }], result
|
assert_equal [{ value: 4, type: :numeric, base: 10 }, { value: '"test"', type: :string }], result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_program_name
|
def test_program_name
|
||||||
result = Rpl::Parser.new.parse_input( "« 2 dup * » 'carré' sto" )
|
result = Rpl::Lang::Parser.new.parse_input( "« 2 dup * » 'carré' sto" )
|
||||||
|
|
||||||
assert_equal [{ value: '« 2 dup * »', type: :program },
|
assert_equal [{ value: '« 2 dup * »', type: :program },
|
||||||
{ value: "'carré'", type: :name },
|
{ value: "'carré'", type: :name },
|
||||||
|
|
Loading…
Reference in a new issue