skint/pre/k.sf

90 lines
2.7 KiB
Text
Raw Normal View History

2024-07-19 23:17:06 -04:00
;------------------------------------------------------------------------------
2023-02-28 00:31:08 -05:00
;
; SKINT Startup code (minimal)
2023-02-28 00:31:08 -05:00
;
;------------------------------------------------------------------------------
2023-02-28 00:31:08 -05:00
(load "n-service.sf") ; needed for constants (pairs, strings, symbols)
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
2023-04-13 18:31:20 -04:00
; Runtime globals
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
(%localdef "#include \"i.h\"")
2023-02-28 00:31:08 -05:00
(define *globals* (make-vector 991 '())) ; nice prime number
2023-02-28 00:31:08 -05:00
2023-03-29 23:18:39 -04:00
(define *dynamic-state* (list #f)) ; for dynamic-wind
(define *current-input* #f)
(define *current-output* #f)
(define *current-error* #f)
2023-03-29 23:18:39 -04:00
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
; Code deserializer and Evaluator (use built-ins)
;---------------------------------------------------------------------------------------------
(define execute-thunk-closure
(%prim "{ /* define execute-thunk-closure */
static obj c[] = { obj_from_objptr(vmcases+0) };
$return objptr(c); }"))
(define make-closure
(%prim "{ /* define make-closure */
static obj c[] = { obj_from_objptr(vmcases+1) };
$return objptr(c); }"))
(define decode-sexp
(%prim "{ /* define decode-sexp */
static obj c[] = { obj_from_objptr(vmcases+2) };
$return objptr(c); }"))
(define decode
(%prim "{ /* define decode */
static obj c[] = { obj_from_objptr(vmcases+3) };
$return objptr(c); }"))
;---------------------------------------------------------------------------------------------
2023-03-03 13:18:00 -05:00
; Initial environment
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
; initial transformers
(define *transformers* '())
2023-03-11 13:41:44 -05:00
; adapter code for continuation closures produced by letcc
2023-03-29 23:18:39 -04:00
(define continuation-adapter-code #f) ; inited via (decode "k!...") in i.c
2023-02-28 00:31:08 -05:00
2023-03-06 15:53:37 -05:00
; adapter closure for values/call-with-values pair
(define callmv-adapter-closure (make-closure (decode "K5")))
2023-02-28 00:31:08 -05:00
(define install-global-lambdas
(%prim "{ /* define install-global-lambdas */
static obj c[] = { obj_from_objptr(vmcases+6) };
$return objptr(c); }"))
(install-global-lambdas)
2023-03-03 13:18:00 -05:00
(define initialize-modules
(%prim "{ /* define initialize-modules */
static obj c[] = { obj_from_objptr(vmcases+7) };
$return objptr(c); }"))
(initialize-modules)
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
; Main
2023-02-28 00:31:08 -05:00
;---------------------------------------------------------------------------------------------
2024-07-11 19:12:03 -04:00
(define (tcode-repl)
(execute-thunk-closure (make-closure (decode "${@(y4:repl)[00}"))))
2024-07-11 19:12:03 -04:00
2023-02-28 00:31:08 -05:00
(define (main argv)
; if we fell out of tcode repl on error, go back
(unless (eq? (tcode-repl) #t) (main #f)))
2023-02-28 00:31:08 -05:00