mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
SRFI-22 now requires the -r (run) option.
This commit is contained in:
parent
28460d3664
commit
3373469883
9 changed files with 52 additions and 44 deletions
|
@ -26,21 +26,21 @@
|
||||||
|
|
||||||
(define (print . args) (for-each display args) (newline))
|
(define (print . args) (for-each display args) (newline))
|
||||||
|
|
||||||
(define (main args)
|
(let* ((args (command-line))
|
||||||
(let* ((n (string->number (cadr args)))
|
(n (string->number (cadr args)))
|
||||||
(min-depth 4)
|
(min-depth 4)
|
||||||
(max-depth (max (+ min-depth 2) n))
|
(max-depth (max (+ min-depth 2) n))
|
||||||
(stretch-depth (+ max-depth 1)))
|
(stretch-depth (+ max-depth 1)))
|
||||||
(print "stretch tree of depth " stretch-depth "\t check: "
|
(print "stretch tree of depth " stretch-depth "\t check: "
|
||||||
(check (make 0 stretch-depth)))
|
(check (make 0 stretch-depth)))
|
||||||
(let ((long-lived-tree (make 0 max-depth)))
|
(let ((long-lived-tree (make 0 max-depth)))
|
||||||
(do ((d min-depth (+ d 2)))
|
(do ((d min-depth (+ d 2)))
|
||||||
((>= d max-depth))
|
((>= d max-depth))
|
||||||
(let ((iterations (* 2 (+ (- max-depth d) min-depth))))
|
(let ((iterations (* 2 (+ (- max-depth d) min-depth))))
|
||||||
(print (* 2 iterations) "\t trees of depth " d "\t check: "
|
(print (* 2 iterations) "\t trees of depth " d "\t check: "
|
||||||
(do ((i 0 (+ i 1))
|
(do ((i 0 (+ i 1))
|
||||||
(c 0 (+ c (check (make i d)) (check (make (- i) d)))))
|
(c 0 (+ c (check (make i d)) (check (make (- i) d)))))
|
||||||
((>= i iterations)
|
((>= i iterations)
|
||||||
c)))))
|
c)))))
|
||||||
(print "long lived tree of depth " max-depth "\t check: "
|
(print "long lived tree of depth " max-depth "\t check: "
|
||||||
(check long-lived-tree)))))
|
(check long-lived-tree))))
|
||||||
|
|
|
@ -6,7 +6,7 @@ chibi-scheme \- a tiny Scheme interpreter
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B chibi-scheme
|
.B chibi-scheme
|
||||||
[-qfV]
|
[-qrfV]
|
||||||
[-I
|
[-I
|
||||||
.I path
|
.I path
|
||||||
]
|
]
|
||||||
|
@ -86,6 +86,9 @@ Don't load the initialization file. The resulting
|
||||||
environment will only contain the core syntactic forms
|
environment will only contain the core syntactic forms
|
||||||
and primitives coded in C.
|
and primitives coded in C.
|
||||||
.TP
|
.TP
|
||||||
|
.BI -r
|
||||||
|
Run the "main" procedure when the script finishes loading as in SRFI-22.
|
||||||
|
.TP
|
||||||
.BI -f
|
.BI -f
|
||||||
Change the reader to case-fold symbols as in R5RS.
|
Change the reader to case-fold symbols as in R5RS.
|
||||||
.TP
|
.TP
|
||||||
|
|
17
main.c
17
main.c
|
@ -314,7 +314,7 @@ void run_main (int argc, char **argv) {
|
||||||
char *impmod, *p;
|
char *impmod, *p;
|
||||||
sexp_sint_t len;
|
sexp_sint_t len;
|
||||||
#endif
|
#endif
|
||||||
char *arg, *prefix=NULL, *suffix=NULL;
|
char *arg, *prefix=NULL, *suffix=NULL, *main_symbol=NULL;
|
||||||
sexp_sint_t i, j, c, quit=0, print=0, init_loaded=0, mods_loaded=0,
|
sexp_sint_t i, j, c, quit=0, print=0, init_loaded=0, mods_loaded=0,
|
||||||
fold_case=SEXP_DEFAULT_FOLD_CASE_SYMS;
|
fold_case=SEXP_DEFAULT_FOLD_CASE_SYMS;
|
||||||
sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE;
|
sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE;
|
||||||
|
@ -451,6 +451,9 @@ void run_main (int argc, char **argv) {
|
||||||
if (ctx) sexp_global(ctx, SEXP_G_FOLD_CASE_P) = SEXP_TRUE;
|
if (ctx) sexp_global(ctx, SEXP_G_FOLD_CASE_P) = SEXP_TRUE;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case 'r':
|
||||||
|
main_symbol = argv[i][2] == '\0' ? "main" : argv[i]+2;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "unknown option: %s\n", argv[i]);
|
fprintf(stderr, "unknown option: %s\n", argv[i]);
|
||||||
sexp_usage(1);
|
sexp_usage(1);
|
||||||
|
@ -492,11 +495,13 @@ void run_main (int argc, char **argv) {
|
||||||
sexp_warn_undefs(ctx, env, tmp, SEXP_VOID);
|
sexp_warn_undefs(ctx, env, tmp, SEXP_VOID);
|
||||||
#endif
|
#endif
|
||||||
/* SRFI-22: run main if specified */
|
/* SRFI-22: run main if specified */
|
||||||
sym = sexp_intern(ctx, "main", -1);
|
if (main_symbol) {
|
||||||
tmp = sexp_env_ref(env, sym, SEXP_FALSE);
|
sym = sexp_intern(ctx, main_symbol, -1);
|
||||||
if (sexp_procedurep(tmp)) {
|
tmp = sexp_env_ref(env, sym, SEXP_FALSE);
|
||||||
args = sexp_list1(ctx, args);
|
if (sexp_procedurep(tmp)) {
|
||||||
check_exception(ctx, sexp_apply(ctx, tmp, args));
|
args = sexp_list1(ctx, args);
|
||||||
|
check_exception(ctx, sexp_apply(ctx, tmp, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
repl(ctx, env);
|
repl(ctx, env);
|
||||||
|
|
|
@ -666,7 +666,7 @@ div#footer {padding-bottom: 50px}
|
||||||
,@(reverse (append-map (lambda (x) (extract-docs x defs exports 'ffi))
|
,@(reverse (append-map (lambda (x) (extract-docs x defs exports 'ffi))
|
||||||
(module-shared-includes mod)))))))
|
(module-shared-includes mod)))))))
|
||||||
|
|
||||||
(define (main args)
|
(let ((args (command-line)))
|
||||||
(case (length args)
|
(case (length args)
|
||||||
((0 1)
|
((0 1)
|
||||||
(convert (current-input-port)))
|
(convert (current-input-port)))
|
||||||
|
|
|
@ -1639,7 +1639,7 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; main
|
;; main
|
||||||
|
|
||||||
(define (main args)
|
(let ((args (command-line)))
|
||||||
(if (not (null? args)) (set! args (cdr args)))
|
(if (not (null? args)) (set! args (cdr args)))
|
||||||
(let* ((compile? (and (pair? args) (member (car args) '("-c" "--compile"))))
|
(let* ((compile? (and (pair? args) (member (car args) '("-c" "--compile"))))
|
||||||
(args (if compile? (cdr args) args))
|
(args (if compile? (cdr args) args))
|
||||||
|
|
|
@ -209,17 +209,17 @@
|
||||||
(display (init-name (cdr lib)))
|
(display (init-name (cdr lib)))
|
||||||
(display " },\n"))
|
(display " },\n"))
|
||||||
|
|
||||||
(define (main args)
|
(let* ((args (command-line))
|
||||||
(let ((c-libs (find-c-libs (if (pair? args) (cdr args) args))))
|
(c-libs (find-c-libs (if (pair? args) (cdr args) args))))
|
||||||
(newline)
|
(newline)
|
||||||
(for-each include-c-lib c-libs)
|
(for-each include-c-lib c-libs)
|
||||||
(newline)
|
(newline)
|
||||||
;; (display "typedef struct {\n")
|
;; (display "typedef struct {\n")
|
||||||
;; (display " const char *name;\n")
|
;; (display " const char *name;\n")
|
||||||
;; (display " sexp_init_proc init;\n")
|
;; (display " sexp_init_proc init;\n")
|
||||||
;; (display "} sexp_library_entry_t;\n")
|
;; (display "} sexp_library_entry_t;\n")
|
||||||
;; (newline)
|
;; (newline)
|
||||||
(display "struct sexp_library_entry_t sexp_static_libraries[] = {\n")
|
(display "struct sexp_library_entry_t sexp_static_libraries[] = {\n")
|
||||||
(for-each init-c-lib c-libs)
|
(for-each init-c-lib c-libs)
|
||||||
(display " { NULL, NULL }\n")
|
(display " { NULL, NULL }\n")
|
||||||
(display "};\n\n")))
|
(display "};\n\n"))
|
||||||
|
|
|
@ -96,7 +96,7 @@
|
||||||
(lambda () (make-iset))))))))))
|
(lambda () (make-iset))))))))))
|
||||||
(lp))))))))
|
(lp))))))))
|
||||||
|
|
||||||
(define (main args)
|
(let ((args (command-line)))
|
||||||
(let lp ((ls (cdr args))
|
(let lp ((ls (cdr args))
|
||||||
(min-count 26)
|
(min-count 26)
|
||||||
(max-char-sets #f)
|
(max-char-sets #f)
|
||||||
|
|
|
@ -178,7 +178,7 @@
|
||||||
"Whitespace=Zs,Zl,Zp,0009,000A,000B,000C,000D"
|
"Whitespace=Zs,Zl,Zp,0009,000A,000B,000C,000D"
|
||||||
"Digit=Nd"))
|
"Digit=Nd"))
|
||||||
|
|
||||||
(define (main args)
|
(let ((args (command-line)))
|
||||||
(let lp ((ls (cdr args))
|
(let lp ((ls (cdr args))
|
||||||
(data "data/UnicodeData.txt")
|
(data "data/UnicodeData.txt")
|
||||||
(derived "data/DerivedCoreProperties.txt")
|
(derived "data/DerivedCoreProperties.txt")
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
(for-each (lambda (i) (hash-table-set! ls2-tab i #t)) ls2)
|
(for-each (lambda (i) (hash-table-set! ls2-tab i #t)) ls2)
|
||||||
(remove (lambda (i) (hash-table-exists? ls2-tab i)) ls1)))
|
(remove (lambda (i) (hash-table-exists? ls2-tab i)) ls1)))
|
||||||
|
|
||||||
(define (main args)
|
(let ((args (command-line)))
|
||||||
(let lp ((ls (cdr args)) (ascii? #f))
|
(let lp ((ls (cdr args)) (ascii? #f))
|
||||||
(cond
|
(cond
|
||||||
((and (pair? ls) (not (equal? "" (car ls)))
|
((and (pair? ls) (not (equal? "" (car ls)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue