Have (eval) use global scope.

Add simple (run) (stdout) and (stderr) to pebblisp.pbl
This commit is contained in:
Sage Vaillancourt 2022-04-08 16:30:05 -04:00 committed by Sage Vaillancourt
parent 85fb91b4ed
commit c1580523ee
4 changed files with 30 additions and 5 deletions

View File

@ -20,6 +20,28 @@
""
)))
(struct Output (stdout stderr))
(def run (fn (command)
"Run the given shell command and return an Output struct" (
(def stdout "/tmp/pebblisp.stdout")
(def stderr "/tmp/pebblisp.stderr")
(def piped (cat command " > " stdout " 2> " stderr))
(sys piped)
(Output (rf stdout) (rf stderr))
)))
(def stdout (fn (command)
"Run the given shell command and return the stdout as a string" (
(def output (run command))
output.stdout
)))
(def stderr (fn (command)
"Run the given shell command and return the stderr as a string" (
(def output (run command))
output.stderr
)))
(def first (fn (list) (at 0 list)))
(def up "..")
@ -51,9 +73,12 @@
(def commRunning F)
(def saveCurPos "")
(def loadCurPos "")
(def promptUpdater (fn () (
(if commRunning () (
(prn (cat "" (prompt "")))
(prn (cat saveCurPos " " (prompt "") loadCurPos))
))
(sys "sleep 1")
(promptUpdater)

View File

@ -148,7 +148,7 @@ void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env)
int nestedSegfault = 0;
void handler(unused int nSignum, unused siginfo_t* si, void* vcontext)
void segfaultHandler(unused int nSignum, unused siginfo_t* si, void* vcontext)
{
if (nestedSegfault) {
printf("Nested segfault!!!\n");
@ -173,7 +173,7 @@ void setupSegfaultHandler()
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = handler;
action.sa_sigaction = segfaultHandler;
sigaction(SIGSEGV, &action, NULL);
}
@ -224,7 +224,6 @@ void getSettings(int argc, const char* argv[])
int main(int argc, const char* argv[])
{
setupSegfaultHandler();
getSettings(argc, argv);
struct Environment env = defaultEnv();

View File

@ -278,6 +278,7 @@ Object parseEvalO(Object* params, unused int length, struct Environment* env)
{
Object text = params[0];
env = global();
switch (text.type) {
case TYPE_SYMBOL: {
Object string = eval(&text, env);

View File

@ -226,7 +226,7 @@ tfn(substring, "substr",
/// STRING/SLIST => ANY
fn(parseEvalO, "eval",
"Evaluate the given string or quoted list.",
"Evaluate the given string or quoted list. Uses the global scope.",
"(eval \"(1 2 3)\")", "( 1 2 3 )",
"(eval '(+ 5 5))", "10",
);