From bc0c740cc1f6d470b4a182bea3d65a65d9011e75 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Wed, 13 Nov 2024 21:05:15 -0600 Subject: [PATCH] added easier way to compile webasm version also rediscovered there's a major bug in strings where I'm not terminating them properly, appears on webasm version --- .gitignore | 3 +++ Makefile | 3 +++ src/Makefile | 19 ++++++++++++++++ src/emscr.c | 34 ++++++++++++++++++++++++++++ src/repl.c | 3 +++ src/test.c | 3 +++ web/kl.png | Bin 0 -> 2683 bytes web/manifest.json | 15 +++++++++++++ web/shell.html | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 136 insertions(+) create mode 100644 src/emscr.c create mode 100644 web/kl.png create mode 100644 web/manifest.json create mode 100644 web/shell.html diff --git a/.gitignore b/.gitignore index b8678e1..28518dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *~ /src/linenoise.c /src/linenoise.h +/build/ +/web/static/ +/web/build/ \ No newline at end of file diff --git a/Makefile b/Makefile index db9b141..aec8428 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,6 @@ test: .PHONY: clean clean: cd src; $(MAKE) clean +.PHONY: web +web: + cd src; $(MAKE) web diff --git a/src/Makefile b/src/Makefile index ff4cd89..4246aba 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,6 +13,9 @@ DEPS:= $(OBJS:%.o=%.d) BIN_OBJS:= $(filter-out $(BUILD)/test.o,$(OBJS)) TEST_OBJS:= $(filter-out $(BUILD)/repl.o,$(OBJS)) +WEB_BUILD:= ../web/build +WEB_OBJS:= $(patsubst %.c,$(WEB_BUILD)/%.o,$(SRCS)) +WEB_SHELL:= ../web/shell.html #LIBRARIES = poppler-glib MagickWand libexif taglib_c libmagic libavcodec libavformat sqlite3 uuid fuse3 libbsd-overlay @@ -33,6 +36,22 @@ $(OBJS): $(BUILD)/%.o:%.c Makefile $(CC) -c $< -MMD -o $@ $(CFLAGS) + +$(WEB_OBJS): $(WEB_BUILD)/%.o:%.c Makefile + mkdir -p $(WEB_BUILD)/builtins + emcc -c $< -MMD -o $@ $(CFLAGS) + +.PHONY: web +web: $(WEB_OBJS) + emcc $(WEB_OBJS) --shell-file $(WEB_SHELL) -o $(WEB_BUILD)/klrepl.html -s NO_EXIT_RUNTIME=1 -s "EXPORTED_RUNTIME_METHODS=['ccall']" --preload-file ../demos.kl@demos.kl + mkdir -p $(WEB_BUILD)/../static + cp $(WEB_BUILD)/../kl.png $(WEB_BUILD)/../static + cp $(WEB_BUILD)/../manifest.json $(WEB_BUILD)/../static + cp $(WEB_BUILD)/klrepl.data $(WEB_BUILD)/../static + cp $(WEB_BUILD)/klrepl.js $(WEB_BUILD)/../static + cp $(WEB_BUILD)/klrepl.wasm $(WEB_BUILD)/../static + cp $(WEB_BUILD)/klrepl.html $(WEB_BUILD)/../static/index.html + .PHONY: test test: $(TEST_OBJS) $(CC) $(TEST_OBJS) $(LDFLAGS) -o $(BUILD)/$(TEST_BIN) diff --git a/src/emscr.c b/src/emscr.c new file mode 100644 index 0000000..f312ade --- /dev/null +++ b/src/emscr.c @@ -0,0 +1,34 @@ +#ifdef __EMSCRIPTEN__ + +#include +#include +#include "types.h" +#include "sexpr.h" +#include "dict.h" +#include "parser.h" +#include "builtins.h" +#include "eval.h" +#include "util.h" + +Sexpr* my_env = NULL; + +int main() { + my_env = init_dict(); + load_env(my_env); + load_file(my_env, "/demos.kl"); + printf(" ready\n"); + return 0; +} + +EMSCRIPTEN_KEEPALIVE char* ems_eval(char* s) { + //printf("called wasm with %s\n", s); + Sexpr* in = parse(s); + if(in == NULL) return "bad input\n"; + Sexpr* out = eval(clone(in), my_env); + char* outstr = sprint_sexpr(out); + sexpr_free(in); + sexpr_free(out); + return outstr; +} + +#endif diff --git a/src/repl.c b/src/repl.c index 9bc64d8..d1c7940 100644 --- a/src/repl.c +++ b/src/repl.c @@ -1,4 +1,5 @@ +#ifndef __EMSCRIPTEN__ #include #include @@ -77,3 +78,5 @@ int main(int argc, char** argv) { free(histfile); return 0; } + +#endif diff --git a/src/test.c b/src/test.c index 672bc8e..db89c82 100644 --- a/src/test.c +++ b/src/test.c @@ -1,3 +1,4 @@ +#ifndef __EMSCRIPTEN__ #include #include @@ -414,3 +415,5 @@ int main() { run_tests(); return 0; } + +#endif diff --git a/web/kl.png b/web/kl.png new file mode 100644 index 0000000000000000000000000000000000000000..0ffbc0579a4f78960b8d5ddefaa58dd22a54080b GIT binary patch literal 2683 zcmc&!Yfuwc6uz6y%V5fa2q9RAW3dQ|k1AB5un-jx&}ii;RdfgjMS>6nCJ9+6C>ASH ztyHZTN};VLn5fO^?^k}5is)hL5fHPBSP;+ol)v^to~?bZuaiE=X~ee^PPJ( z3l@5@SzHzXfbHWwcL@L#xTOFl`H*t?KLdcINAdXrA3mQK8z+v8iWUN3mm|;l#Jdvb zY`j&ppm3>KgGbePenJT^uxjxEK{_ixP;^bxrZ@8Eer0Cir8%zEUS4%gb2cQ15#)gl zBI`HAE|KJzR`{}}tSWCU-PEt@Z`ZltqQG5i9{GX&k(PHNJTG(vo>e=fapry#85UXO z_My+Dq^-r$fq@i@){y1|#nvI2CW2V>L7wpBN)s`*NE|w+Q{KXK_&vELzGeOAj^2aS z31{1#FWGLQTYST#YR@c zZ!_wnzT|D5H`ybNNlREN$jIPyb0v+X0!8xJumq-)Jv zx5q58L;6(LADy?uuG2!Ro8(RMC%+Um zRoHA#k2_X#su_c_jEeORi3h-O0=bZ+LiY{O$dLH>&tr74urXsDenL}5LzAUsUa*8O zUbjvdBLVz4;Yx`xf|nR25%Iiy`~^X&?^yuA6#C5dSen$(-K1IHy8z2r>|tVj+k|?1 zQvQQ8R`*NNfn}sV@2Ebp*!58TzEIDBn$SICT%N{Q|W5lv%Ckh#w*}110Ak20ZMiv-ftb6oIjRl#DWE8RjRS$0n zaNt=sl}eUIu;bJxuLxn*GG?E_@IdBdh7kgt5kf|pwZ|Bfxc?AtOQmncGyihy(Ibwh zv8Eyh5>*dPN6N15Dj#Qn6YR(yME@UY$gG2R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