From c1580523ee280a6fa2500a0edf60f820fd019bf3 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 8 Apr 2022 16:30:05 -0400 Subject: [PATCH] Have (eval) use global scope. Add simple (run) (stdout) and (stderr) to pebblisp.pbl --- src/examples/pebblisp.pbl | 27 ++++++++++++++++++++++++++- src/main.c | 5 ++--- src/plfunc.c | 1 + src/plfunc.h | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/examples/pebblisp.pbl b/src/examples/pebblisp.pbl index 9f83b03..0ad409a 100644 --- a/src/examples/pebblisp.pbl +++ b/src/examples/pebblisp.pbl @@ -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) diff --git a/src/main.c b/src/main.c index 4df645a..60aca9f 100644 --- a/src/main.c +++ b/src/main.c @@ -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(); diff --git a/src/plfunc.c b/src/plfunc.c index 346abd7..e52d34b 100644 --- a/src/plfunc.c +++ b/src/plfunc.c @@ -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); diff --git a/src/plfunc.h b/src/plfunc.h index 114d8e6..a797e9e 100644 --- a/src/plfunc.h +++ b/src/plfunc.h @@ -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", );