tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit f8f6339949cee35f03251d899786a85c7f5cc724
parent 5c1bba0d331b21889513e708c6bdfdd0b8dc9757
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat,  5 Oct 2019 13:05:36 -0700

Support statically included tisp code with xxd

Diffstat:
.gitignore | 1+
Makefile | 12+++++++++---
main.c | 2++
test.c | 3++-
tibs/repl.tsp | 1-
tisp.c | 9+++++++++
tisp.h | 1+
tsp | 6++----
8 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -7,6 +7,7 @@ # compiled files tisp test +libs.tsp.h *.exe *.out *.app diff --git a/Makefile b/Makefile @@ -22,6 +22,12 @@ options: @echo "CFLAGS = $(CFLAGS)" @echo "LDFLAGS = $(LDFLAGS)" +libs.tsp.h: $(TSP) + @echo xxd $@ + @echo "char libs_tsp[] = { 0x28, 0x64, 0x6f, 0x20," > $@ + @cat $(TSP) | xxd -i - >> $@ + @echo ", 0x29, 0x00};" >> $@ + .o: @echo $(LD) $@ @$(LD) -o $@ $< $(LDFLAGS) @@ -30,7 +36,7 @@ options: @echo $(CC) $< @$(CC) -c -o $@ $< $(CFLAGS) -$(OBJ): config.mk +$(OBJ): config.mk libs.tsp.h $(LIB): $(TIB) @echo $(CC) -o $@ @@ -42,7 +48,7 @@ $(EXE): $(OBJ) $(LIB) clean: @echo cleaning - @rm -f $(OBJ) $(LIB) $(EXE) test test.o test.out + @rm -f $(OBJ) $(LIB) $(EXE) test test.o test.out libs.tsp.h install: all @echo installing $(EXE) to $(DESTDIR)$(PREFIX)/bin @@ -50,7 +56,7 @@ install: all @cp -f $(EXE) $(DESTDIR)$(PREFIX)/bin @chmod 755 $(DESTDIR)$(PREFIX)/bin/$(EXE) @echo installing tsp to $(DESTDIR)$(PREFIX)/bin - @sed -e "s@\./@@g" -e "s@tibs/@$(DESTDIR)$(PREFIX)/share/tisp/@g" < tsp > $(DESTDIR)$(PREFIX)/bin/tsp + @sed -e "s@\./@@g" < tsp > $(DESTDIR)$(PREFIX)/bin/tsp @chmod 755 $(DESTDIR)$(PREFIX)/bin/tsp @echo installing manual page to $(DESTDIR)$(MANPREFIX)/man1 @mkdir -p $(DESTDIR)$(MANPREFIX)/man1 diff --git a/main.c b/main.c @@ -23,6 +23,8 @@ main(int argc, char *argv[]) tib_env_math(env); tib_env_io(env); tib_env_time(env); +# include "libs.tsp.h" + tisp_env_lib(env, libs_tsp); #endif if (argc == 1) diff --git a/test.c b/test.c @@ -6,6 +6,7 @@ #include <unistd.h> #include "tisp.h" +#include "libs.tsp.h" tsp_include_tib(math); @@ -441,7 +442,7 @@ main(void) int errors[LEN(tests)] = {0}; Env env = tisp_env_init(1024); tib_env_math(env); - tisp_eval(env, tisp_parse_file(env, "tibs/lib.tsp")); + tisp_env_lib(env, libs_tsp); for (int i = 0; ; i++) { if (!tests[i][1]) { diff --git a/tibs/repl.tsp b/tibs/repl.tsp @@ -14,4 +14,3 @@ (newline) (repl-simple)) -(repl) diff --git a/tisp.c b/tisp.c @@ -1069,6 +1069,15 @@ tisp_env_init(size_t cap) } void +tisp_env_lib(Env env, char* lib) +{ + struct Str s; + if (!(s.d = strndup(lib, strlen(lib)))) + return; + tisp_eval(env, tisp_read(env, &s)); +} + +void tisp_env_free(Env env) { int i; diff --git a/tisp.h b/tisp.h @@ -168,4 +168,5 @@ Val tisp_parse_file(Env env, char *fname); void tisp_env_add(Env e, char *key, Val v); Env tisp_env_init(size_t cap); +void tisp_env_lib(Env env, char* lib); void tisp_env_free(Env env); diff --git a/tsp b/tsp @@ -1,10 +1,8 @@ #!/bin/sh -CMD="./tisp $@ tibs/lib.tsp tibs/repl.tsp" - # if rlwrap is not installed, run without it command -v rlwrap >/dev/null 2>&1 || { - $CMD + ./tisp $@ -c "(repl)" exit 0 } -rlwrap -nAcr -M ".tsp" -pWhite -q"\"" $CMD +rlwrap -ncr -M ".tsp" -pWhite -q"\"" ./tisp $@ -c "(repl)"