1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-25 04:37:42 +00:00

Work on emscripten support. Works with sync code.

This commit is contained in:
Calvin Rose
2018-03-13 13:31:25 -04:00
parent 61645c82b1
commit 2b1dd79f55
10 changed files with 287 additions and 23 deletions

View File

@@ -145,6 +145,8 @@ If no match is found, returns nil"
(defn even? [x] (== 0 (% x 2)))
(defn odd? [x] (== 1 (% x 2)))
(defn inc [x] (+ x 1))
(defn dec [x] (- x 1))
(defmacro let [bindings & body]
(def head (ast-unwrap1 bindings))
@@ -247,6 +249,7 @@ onvalue."
(do
(defn val-stream [chunks onerr]
(var going true)
# Stream of characters
(def chars (fiber (fn []
(def buf @"")
(var len 1)
@@ -259,6 +262,7 @@ onvalue."
0)))
(var temp nil)
(var tempval nil)
# Stream of values
(def f (fiber (fn []
(def p (parser 1))
(while going
@@ -328,6 +332,7 @@ onvalue."
(def newenv (make-env))
(defn chunks [buf]
(file-write stdout ">> ")
(file-flush stdout)
(file-read stdin :line buf))
(defn onvalue [x]
(put newenv '_ @{'value x})

View File

@@ -31,6 +31,13 @@ typedef HINSTANCE Clib;
#define load_clib(name) LoadLibrary((name))
#define symbol_clib(lib, sym) GetProcAddress((lib), (sym))
#define error_clib() "could not load dynamic library"
#elif defined(DST_WEB)
#include <emscripten.h>
/* TODO - figure out how loading modules will work in JS */
typedef int Clib;
#define load_clib(name) 0
#define symbol_clib(lib, sym) 0
#define error_clib() "could not load dynamic library"
#else
#include <dlfcn.h>
typedef void *Clib;

View File

@@ -53,7 +53,9 @@ extern "C" {
#endif
/* Check Windows */
#if defined(WIN32) || defined(_WIN32)
#ifdef __EMSCRIPTEN__
#define DST_WEB 1
#elif defined(WIN32) || defined(_WIN32)
#define DST_WINDOWS 1
#endif

View File

@@ -32,6 +32,7 @@
(when (or should-repl no-file)
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))
(repl))
(repl)
(print "bye!"))
)