From b3b02165a47e5d2618d7287fc6f56ed6eeb8bb00 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 9 Feb 2023 16:44:45 +0100 Subject: [PATCH] [words] add SYSEVAL to run underlying OS commands --- lib/rpl.rb | 3 ++- lib/rpl/words.rb | 1 + lib/rpl/words/system.rb | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 lib/rpl/words/system.rb diff --git a/lib/rpl.rb b/lib/rpl.rb index ef9363a..94a4d3c 100644 --- a/lib/rpl.rb +++ b/lib/rpl.rb @@ -41,7 +41,7 @@ class Rpl < Interpreter end def run!( input ) - stack = super + stack = super( input ) persist_state if @live_persistence @@ -64,6 +64,7 @@ class Rpl < Interpreter prepend RplLang::Words::Store prepend RplLang::Words::String prepend RplLang::Words::StringAndList + prepend RplLang::Words::System prepend RplLang::Words::Test prepend RplLang::Words::TimeAndDate prepend RplLang::Words::Trig diff --git a/lib/rpl/words.rb b/lib/rpl/words.rb index ecc14eb..3b6765d 100644 --- a/lib/rpl/words.rb +++ b/lib/rpl/words.rb @@ -18,4 +18,5 @@ require 'rpl/words/time-date' require 'rpl/words/trig' require 'rpl/words/logarithm' require 'rpl/words/filesystem' +require 'rpl/words/system' require 'rpl/words/list' diff --git a/lib/rpl/words/system.rb b/lib/rpl/words/system.rb new file mode 100644 index 0000000..da7bb2a --- /dev/null +++ b/lib/rpl/words/system.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module RplLang + module Words + module System + include Types + + def populate_dictionary + super + + category = 'System' + + @dictionary.add_word!( ['syseval'], + category, + '( string -- output ) run string in OS shell and put output on stack', + proc do + args = stack_extract( [[RplString]] ) + + @stack << Types.new_object( RplString, "\"#{`#{args[0].value}`}\"" ) + end ) + end + end + end +end