From 775be84f5febfcf0bcbf7b40e3ece08241c3c737 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 6 Nov 2020 15:30:14 -0500 Subject: [PATCH] Add examples/. Install to system on `make install` Installs examples/* to /usr/share/pebblisp A basic REPL is one of these examples, replacing the built-in C version with one actually written in PebbLisp. It can be invoked the same way: running `pl` without any arguments. --- src/Makefile | 3 +++ src/examples/repl.pbl | 12 ++++++++++++ src/pebblisp.c | 8 +------- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100755 src/examples/repl.pbl diff --git a/src/Makefile b/src/Makefile index 2453986..d6ceea7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,3 +18,6 @@ run: install: cp ./$(exe) /usr/bin/pl + mkdir -p /usr/share/pebblisp/ + rm /usr/share/pebblisp/* + cp ./examples/* /usr/share/pebblisp/ diff --git a/src/examples/repl.pbl b/src/examples/repl.pbl new file mode 100755 index 0000000..0970ce9 --- /dev/null +++ b/src/examples/repl.pbl @@ -0,0 +1,12 @@ +#!/usr/bin/pl +(def repl (fn (_) ( + (prn "pebblisp::> ") + (def input (inp 0)) + (if (= input "q") () ( + (prn (eval input)) + (pch 10) + (repl 0) + )) +))) + +(repl 0) diff --git a/src/pebblisp.c b/src/pebblisp.c index 1e33f6d..2a7c02f 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -774,13 +774,7 @@ int readFile(const char *filename, struct Environment *env) { void repl(struct Environment *env) { - char input[200] = ""; - while(input[0] != 'q') { - printf("pebblisp>> "); - fgets(input, 100, stdin); - Object obj = parseEval(input, env); - printAndClean(&obj); - } + readFile("/usr/share/pebblisp/repl.pbl", env); } int main(int argc, const char* argv[])