skint/pre/k.sf

90 lines
2.7 KiB
Text
Raw Normal View History

2024-07-20 05:17:06 +02:00
;------------------------------------------------------------------------------
2023-02-28 06:31:08 +01:00
;
; SKINT Startup code (minimal)
2023-02-28 06:31:08 +01:00
;
;------------------------------------------------------------------------------
2023-02-28 06:31:08 +01:00
(load "n-service.sf") ; needed for constants (pairs, strings, symbols)
2023-02-28 06:31:08 +01:00
;---------------------------------------------------------------------------------------------
2023-04-14 00:31:20 +02:00
; Runtime globals
2023-02-28 06:31:08 +01:00
;---------------------------------------------------------------------------------------------
(%localdef "#include \"i.h\"")
2023-02-28 06:31:08 +01:00
(define *globals* (make-vector 991 '())) ; nice prime number
2023-02-28 06:31:08 +01:00
2023-03-30 05:18:39 +02:00
(define *dynamic-state* (list #f)) ; for dynamic-wind
(define *current-input* #f)
(define *current-output* #f)
(define *current-error* #f)
2023-03-30 05:18:39 +02:00
2023-02-28 06:31:08 +01: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 19:18:00 +01:00
; Initial environment
2023-02-28 06:31:08 +01:00
;---------------------------------------------------------------------------------------------
; initial transformers
(define *transformers* '())
2023-03-11 19:41:44 +01:00
; adapter code for continuation closures produced by letcc
2023-03-30 05:18:39 +02:00
(define continuation-adapter-code #f) ; inited via (decode "k!...") in i.c
2023-02-28 06:31:08 +01:00
2023-03-06 21:53:37 +01:00
; adapter closure for values/call-with-values pair
(define callmv-adapter-closure (make-closure (decode "K5")))
2023-02-28 06:31:08 +01: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 19:18:00 +01:00
(define initialize-modules
(%prim "{ /* define initialize-modules */
static obj c[] = { obj_from_objptr(vmcases+7) };
$return objptr(c); }"))
(initialize-modules)
2023-02-28 06:31:08 +01:00
;---------------------------------------------------------------------------------------------
; Main
2023-02-28 06:31:08 +01:00
;---------------------------------------------------------------------------------------------
2024-07-12 01:12:03 +02:00
(define (tcode-repl)
(execute-thunk-closure (make-closure (decode "${@(y4:repl)[00}"))))
2024-07-12 01:12:03 +02:00
2023-02-28 06:31:08 +01: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 06:31:08 +01:00