mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Emscripten support by default. Patch from Marc Nieper-Wi?kirchen.
This commit is contained in:
parent
3f85d7c2c0
commit
dc5e7e397d
7 changed files with 78 additions and 30 deletions
|
@ -37,6 +37,7 @@ lib/chibi/process.c
|
|||
lib/chibi/system.c
|
||||
lib/chibi/time.c
|
||||
lib/chibi/stty.c
|
||||
lib/chibi/emscripten.c
|
||||
doc/*.html
|
||||
doc/lib/chibi/*.html
|
||||
misc/*
|
||||
|
|
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ CHIBI_DEPENDENCIES = ./chibi-scheme$(EXE)
|
|||
CHIBI_COMPILED_LIBS = lib/chibi/filesystem$(SO) lib/chibi/process$(SO) \
|
||||
lib/chibi/time$(SO) lib/chibi/system$(SO) lib/chibi/stty$(SO) \
|
||||
lib/chibi/weak$(SO) lib/chibi/heap-stats$(SO) lib/chibi/disasm$(SO) \
|
||||
lib/chibi/net$(SO) lib/chibi/ast$(SO)
|
||||
lib/chibi/net$(SO) lib/chibi/ast$(SO) lib/chibi/emscripten$(SO)
|
||||
CHIBI_IO_COMPILED_LIBS = lib/chibi/io/io$(SO)
|
||||
CHIBI_OPT_COMPILED_LIBS = lib/chibi/optimize/rest$(SO) \
|
||||
lib/chibi/optimize/profile$(SO)
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
;;(unsigned-long c_ospeed term-attrs-ospeed term-attrs-ospeed-set!)
|
||||
)
|
||||
|
||||
(cond-expand
|
||||
(emscripten)
|
||||
(else
|
||||
(define-c unsigned-long (term-attrs-ispeed cfgetispeed) (termios))
|
||||
(define-c unsigned-long (term-attrs-ospeed cfgetospeed) (termios))
|
||||
(define-c errno (term-attrs-ispeed-set! cfsetispeed) (termios unsigned-long))
|
||||
(define-c errno (term-attrs-ospeed-set! cfsetospeed) (termios unsigned-long))
|
||||
(define-c errno (term-attrs-ospeed-set! cfsetospeed) (termios unsigned-long))))
|
||||
|
||||
(define-c-struct winsize
|
||||
predicate: winsize?
|
||||
|
|
|
@ -57,6 +57,9 @@
|
|||
|
||||
(define-c errno (set-root-directory! "chroot") (string))
|
||||
|
||||
(cond-expand
|
||||
(emscripten)
|
||||
(else
|
||||
(define-c errno getpwuid_r
|
||||
(uid_t (result passwd)
|
||||
(link string)
|
||||
|
@ -67,7 +70,7 @@
|
|||
(string (result passwd)
|
||||
(link string)
|
||||
(value (string-size arg2) int)
|
||||
(result pointer passwd)))
|
||||
(result pointer passwd)))))
|
||||
|
||||
(define-c-struct group
|
||||
predicate: group?
|
||||
|
@ -77,6 +80,9 @@
|
|||
;;((array string) gr_mem group-members)
|
||||
)
|
||||
|
||||
(cond-expand
|
||||
(emscripten)
|
||||
(else
|
||||
(define-c errno getgrgid_r
|
||||
(gid_t (result group)
|
||||
(link string)
|
||||
|
@ -87,4 +93,5 @@
|
|||
(string (result group)
|
||||
(link string)
|
||||
(value (string-size arg2) int)
|
||||
(result pointer group)))
|
||||
(result pointer group)))))
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
(define-library (chibi time)
|
||||
(export current-seconds get-time-of-day set-time-of-day!
|
||||
(export current-seconds get-time-of-day
|
||||
seconds->time seconds->string time->seconds time->string
|
||||
make-timeval make-tm timeval-seconds timeval-microseconds
|
||||
timezone-offset timezone-dst-time
|
||||
|
@ -8,6 +8,10 @@
|
|||
time-day-of-week time-day-of-year time-dst? time-timezone-name
|
||||
time-offset
|
||||
tm? timeval? timezone?)
|
||||
(cond-expand
|
||||
(emscripten)
|
||||
(else
|
||||
(export set-time-of-day!)))
|
||||
(cond-expand
|
||||
((or bsd linux)
|
||||
(export rusage? resource-usage-time resource-usage-system-time
|
||||
|
|
|
@ -55,8 +55,11 @@
|
|||
;;> Set the current time from a timeval struct and
|
||||
;;> and optional timezone.
|
||||
|
||||
(cond-expand
|
||||
(emscripten)
|
||||
(else
|
||||
(define-c errno (set-time-of-day! "settimeofday")
|
||||
(timeval (maybe-null default NULL timezone)))
|
||||
(timeval (maybe-null default NULL timezone)))))
|
||||
|
||||
;;> Convert an integer number of epoch seconds to a broken-down tm struct.
|
||||
|
||||
|
|
34
main.c
34
main.c
|
@ -2,6 +2,10 @@
|
|||
/* Copyright (c) 2009-2013 Alex Shinn. All rights reserved. */
|
||||
/* BSD-style license: http://synthcode.com/license.txt */
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "chibi/eval.h"
|
||||
|
||||
#define sexp_argv_symbol "command-line"
|
||||
|
@ -383,6 +387,12 @@ static void do_init_context (sexp* ctx, sexp* env, sexp_uint_t heap_size,
|
|||
check_exception(ctx, env=sexp_load_standard_repl_env(ctx, env, SEXP_SEVEN, bootp)); \
|
||||
} while (0)
|
||||
|
||||
/* static globals for the sake of resuming from within emscripten */
|
||||
#ifdef EMSCRIPTEN
|
||||
static sexp sexp_resume_ctx = SEXP_FALSE;
|
||||
static sexp sexp_resume_proc = SEXP_FALSE;
|
||||
#endif
|
||||
|
||||
void run_main (int argc, char **argv) {
|
||||
#if SEXP_USE_MODULES
|
||||
char *impmod;
|
||||
|
@ -635,12 +645,20 @@ void run_main (int argc, char **argv) {
|
|||
if (sexp_procedurep(tmp)) {
|
||||
sym = sexp_c_string(ctx, argv[i], -1);
|
||||
sym = sexp_list2(ctx, sym, env);
|
||||
check_exception(ctx, sexp_apply(ctx, tmp, sym));
|
||||
tmp = check_exception(ctx, sexp_apply(ctx, tmp, sym));
|
||||
} else
|
||||
#endif
|
||||
check_exception(ctx, sexp_load(ctx, sym=sexp_c_string(ctx, argv[i], -1), env));
|
||||
tmp = check_exception(ctx, sexp_load(ctx, sym=sexp_c_string(ctx, argv[i], -1), env));
|
||||
#if SEXP_USE_WARN_UNDEFS
|
||||
sexp_warn_undefs(ctx, env, tmp, SEXP_VOID);
|
||||
#endif
|
||||
#ifdef EMSCRIPTEN
|
||||
if (sexp_applicablep(tmp)) {
|
||||
sexp_resume_ctx = ctx;
|
||||
sexp_resume_proc = tmp;
|
||||
sexp_preserve_object(ctx, sexp_resume_proc);
|
||||
emscripten_exit_with_live_runtime();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* SRFI-22: run main if specified */
|
||||
|
@ -661,6 +679,18 @@ void run_main (int argc, char **argv) {
|
|||
sexp_destroy_context(ctx);
|
||||
}
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
void sexp_resume() {
|
||||
sexp_gc_var1(tmp);
|
||||
sexp_gc_preserve(sexp_resume_ctx, tmp);
|
||||
tmp = sexp_list1(sexp_resume_ctx, SEXP_VOID);
|
||||
if (sexp_applicablep(sexp_resume_proc)) {
|
||||
sexp_resume_proc = check_exception(sexp_resume_ctx, sexp_apply(sexp_resume_ctx, sexp_resume_proc, tmp));
|
||||
}
|
||||
sexp_gc_release1(sexp_resume_ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
#if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT
|
||||
signal(SIGSEGV, sexp_segfault_handler);
|
||||
|
|
Loading…
Add table
Reference in a new issue