*~
/src/linenoise.c
/src/linenoise.h
+/build/
+/web/static/
+/web/build/
\ No newline at end of file
.PHONY: clean
clean:
cd src; $(MAKE) clean
+.PHONY: web
+web:
+ cd src; $(MAKE) web
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
$(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)
--- /dev/null
+#ifdef __EMSCRIPTEN__
+
+#include <stdio.h>
+#include <emscripten/emscripten.h>
+#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
+#ifndef __EMSCRIPTEN__
#include <stdio.h>
#include <stdlib.h>
free(histfile);
return 0;
}
+
+#endif
+#ifndef __EMSCRIPTEN__
#include <stdio.h>
#include <stdlib.h>
run_tests();
return 0;
}
+
+#endif
--- /dev/null
+{
+ "background_color": "#8E5DCE",
+ "description": "klklkl",
+ "display": "fullscreen",
+ "icons": [
+ {
+ "src": "kl.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ],
+ "name": "kl",
+ "short_name": "kl",
+ "start_url": "."
+}
--- /dev/null
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="manifest" href="manifest.json" />
+ <link rel="icon" href="kl.png" />
+ <title>klrepl</title>
+ <style>
+ .console {
+ white-space: pre-wrap;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="repl" style="font-family: monospace;">
+ <div id="replout"></div>
+ <form id="replform">
+ <input id="replin" type="text" autocorrect="off" autocapitalize="off"></input>
+ </form>
+ </div>
+ <div class="console" id="output" rows="8"></div>
+ <script type='text/javascript'>
+ var Module = {
+ print: (function() {
+ var element = document.getElementById('output');
+ if (element) element.textContent = 'loading...';
+ return (...args) => {
+ var text = args.join(' ');
+ console.log(text);
+ if (element) {
+ element.textContent += text + "\n";
+ }
+ };
+ })(),
+ };
+ document.getElementById("replform").addEventListener("submit", e => {
+ e.preventDefault();
+ let outzone = document.getElementById("replout");
+ let newelt = document.createElement('div');
+ let inelt = document.createElement('div');
+ let input = e.target[0].value
+ inelt.textContent += "<- " + input + "\n"
+ let outelt = document.createElement('div');
+ let output = Module.ccall("ems_eval", 'string', ['string'], [input])
+ outelt.textContent += " -> " + output + "\n"
+ newelt.appendChild(inelt);
+ newelt.appendChild(outelt);
+ outzone.appendChild(newelt);
+ document.getElementById('replin').value = ""
+ });
+ </script>
+ {{{ SCRIPT }}}
+ </body>
+</html>