rpl.rb/lib/rpl/words/general.rb
2022-08-31 09:57:10 +02:00

50 lines
1.7 KiB
Ruby

# frozen_string_literal: true
module RplLang
module Words
module General
include Types
def populate_dictionary
super
category = 'General'
@dictionary.add_word( ['nop'],
category,
'( -- ) no operation',
proc {} )
@dictionary.add_word( ['help'],
category,
'( w -- s ) pop help string of the given word',
proc do
args = stack_extract( [[RplName]] )
word = @dictionary.words[ args[0].value ]
@stack << Types.new_object( RplString, "\"#{args[0].value}: #{word.nil? ? 'not a core word' : word[:help]}\"" )
end )
@dictionary.add_word( ['quit'],
category,
'( -- ) Stop and quit interpreter',
proc {} )
@dictionary.add_word( ['version'],
category,
'( -- n ) Pop the interpreter\'s version number',
proc do
@stack << Types.new_object( RplString, "\"#{@version}\"" )
end )
@dictionary.add_word( ['uname'],
category,
'( -- s ) Pop the interpreter\'s complete indentification string',
proc do
@stack << Types.new_object( RplString, "\"Rpl Interpreter version #{@version}\"" )
end )
end
end
end
end