Have (eval) use global scope.
Add simple (run) (stdout) and (stderr) to pebblisp.pbl
This commit is contained in:
parent
85fb91b4ed
commit
c1580523ee
|
@ -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 "[s")
|
||||
(def loadCurPos "[u")
|
||||
|
||||
(def promptUpdater (fn () (
|
||||
(if commRunning () (
|
||||
(prn (cat "[2A[1G" (prompt "")))
|
||||
(prn (cat saveCurPos " [2A[1G" (prompt "") loadCurPos))
|
||||
))
|
||||
(sys "sleep 1")
|
||||
(promptUpdater)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue