Emscripten support by default. Patch from Marc Nieper-Wi?kirchen.

This commit is contained in:
Alex Shinn 2015-02-22 16:10:30 +09:00
parent 3f85d7c2c0
commit dc5e7e397d
7 changed files with 78 additions and 30 deletions

View file

@ -37,6 +37,7 @@ lib/chibi/process.c
lib/chibi/system.c lib/chibi/system.c
lib/chibi/time.c lib/chibi/time.c
lib/chibi/stty.c lib/chibi/stty.c
lib/chibi/emscripten.c
doc/*.html doc/*.html
doc/lib/chibi/*.html doc/lib/chibi/*.html
misc/* misc/*

View file

@ -22,7 +22,7 @@ CHIBI_DEPENDENCIES = ./chibi-scheme$(EXE)
CHIBI_COMPILED_LIBS = lib/chibi/filesystem$(SO) lib/chibi/process$(SO) \ 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/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/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_IO_COMPILED_LIBS = lib/chibi/io/io$(SO)
CHIBI_OPT_COMPILED_LIBS = lib/chibi/optimize/rest$(SO) \ CHIBI_OPT_COMPILED_LIBS = lib/chibi/optimize/rest$(SO) \
lib/chibi/optimize/profile$(SO) lib/chibi/optimize/profile$(SO)

View file

@ -14,10 +14,13 @@
;;(unsigned-long c_ospeed term-attrs-ospeed term-attrs-ospeed-set!) ;;(unsigned-long c_ospeed term-attrs-ospeed term-attrs-ospeed-set!)
) )
(define-c unsigned-long (term-attrs-ispeed cfgetispeed) (termios)) (cond-expand
(define-c unsigned-long (term-attrs-ospeed cfgetospeed) (termios)) (emscripten)
(define-c errno (term-attrs-ispeed-set! cfsetispeed) (termios unsigned-long)) (else
(define-c errno (term-attrs-ospeed-set! cfsetospeed) (termios unsigned-long)) (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-struct winsize (define-c-struct winsize
predicate: winsize? predicate: winsize?

View file

@ -57,17 +57,20 @@
(define-c errno (set-root-directory! "chroot") (string)) (define-c errno (set-root-directory! "chroot") (string))
(define-c errno getpwuid_r (cond-expand
(uid_t (result passwd) (emscripten)
(link string) (else
(value (string-size arg2) int) (define-c errno getpwuid_r
(result pointer passwd))) (uid_t (result passwd)
(link string)
(value (string-size arg2) int)
(result pointer passwd)))
(define-c errno getpwnam_r (define-c errno getpwnam_r
(string (result passwd) (string (result passwd)
(link string) (link string)
(value (string-size arg2) int) (value (string-size arg2) int)
(result pointer passwd))) (result pointer passwd)))))
(define-c-struct group (define-c-struct group
predicate: group? predicate: group?
@ -77,14 +80,18 @@
;;((array string) gr_mem group-members) ;;((array string) gr_mem group-members)
) )
(define-c errno getgrgid_r (cond-expand
(gid_t (result group) (emscripten)
(link string) (else
(value (string-size arg2) int) (define-c errno getgrgid_r
(result pointer group))) (gid_t (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))
(define-c errno getgrnam_r
(string (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))))
(define-c errno getgrnam_r
(string (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))

View file

@ -1,6 +1,6 @@
(define-library (chibi time) (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 seconds->time seconds->string time->seconds time->string
make-timeval make-tm timeval-seconds timeval-microseconds make-timeval make-tm timeval-seconds timeval-microseconds
timezone-offset timezone-dst-time timezone-offset timezone-dst-time
@ -8,6 +8,10 @@
time-day-of-week time-day-of-year time-dst? time-timezone-name time-day-of-week time-day-of-year time-dst? time-timezone-name
time-offset time-offset
tm? timeval? timezone?) tm? timeval? timezone?)
(cond-expand
(emscripten)
(else
(export set-time-of-day!)))
(cond-expand (cond-expand
((or bsd linux) ((or bsd linux)
(export rusage? resource-usage-time resource-usage-system-time (export rusage? resource-usage-time resource-usage-system-time

View file

@ -55,8 +55,11 @@
;;> Set the current time from a timeval struct and ;;> Set the current time from a timeval struct and
;;> and optional timezone. ;;> and optional timezone.
(define-c errno (set-time-of-day! "settimeofday") (cond-expand
(timeval (maybe-null default NULL timezone))) (emscripten)
(else
(define-c errno (set-time-of-day! "settimeofday")
(timeval (maybe-null default NULL timezone)))))
;;> Convert an integer number of epoch seconds to a broken-down tm struct. ;;> Convert an integer number of epoch seconds to a broken-down tm struct.

34
main.c
View file

@ -2,6 +2,10 @@
/* Copyright (c) 2009-2013 Alex Shinn. All rights reserved. */ /* Copyright (c) 2009-2013 Alex Shinn. All rights reserved. */
/* BSD-style license: http://synthcode.com/license.txt */ /* BSD-style license: http://synthcode.com/license.txt */
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
#include "chibi/eval.h" #include "chibi/eval.h"
#define sexp_argv_symbol "command-line" #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)); \ check_exception(ctx, env=sexp_load_standard_repl_env(ctx, env, SEXP_SEVEN, bootp)); \
} while (0) } 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) { void run_main (int argc, char **argv) {
#if SEXP_USE_MODULES #if SEXP_USE_MODULES
char *impmod; char *impmod;
@ -635,12 +645,20 @@ void run_main (int argc, char **argv) {
if (sexp_procedurep(tmp)) { if (sexp_procedurep(tmp)) {
sym = sexp_c_string(ctx, argv[i], -1); sym = sexp_c_string(ctx, argv[i], -1);
sym = sexp_list2(ctx, sym, env); sym = sexp_list2(ctx, sym, env);
check_exception(ctx, sexp_apply(ctx, tmp, sym)); tmp = check_exception(ctx, sexp_apply(ctx, tmp, sym));
} else } else
#endif #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 #if SEXP_USE_WARN_UNDEFS
sexp_warn_undefs(ctx, env, tmp, SEXP_VOID); 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 #endif
} }
/* SRFI-22: run main if specified */ /* SRFI-22: run main if specified */
@ -661,6 +679,18 @@ void run_main (int argc, char **argv) {
sexp_destroy_context(ctx); 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) { int main (int argc, char **argv) {
#if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT #if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT
signal(SIGSEGV, sexp_segfault_handler); signal(SIGSEGV, sexp_segfault_handler);