From 7b4b3bc2b16d3a478e13da91d6f296357ee5dda4 Mon Sep 17 00:00:00 2001 From: ESL Date: Fri, 31 May 2024 23:28:29 -0400 Subject: [PATCH] (skint repl) library is built at init time --- src/t.scm | 30 ++++++++++++++++++++---------- t.c | 16 ++++++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/t.scm b/src/t.scm index 9261b92..5ed0b05 100644 --- a/src/t.scm +++ b/src/t.scm @@ -1227,14 +1227,17 @@ (define (get-env-vec! lib) (cond [(assoc lib *std-lib->env*) => cdr] - [else (let* ([n 37] ; use prime number - [env (make-vector n '())]) + [else (let* ([n (if (eq? lib '(skint repl)) 101 37)] ; use prime number + [env (make-vector n '())]) (set! *std-lib->env* (cons (cons lib env) *std-lib->env*)) env)])) (let loop ([name (car r)] [keys (cdr r)]) - (unless (null? keys) - (put-loc! (get-env-vec! (key->lib (car keys))) name (root-environment name 'ref)) - (loop name (cdr keys))))) + (cond + [(null? keys) + (put-loc! (get-env-vec! '(skint repl)) name (root-environment name 'ref))] + [else + (put-loc! (get-env-vec! (key->lib (car keys))) name (root-environment name 'ref)) + (loop name (cdr keys))]))) '((* v b) (+ v b) (- v b) (... v u b) (/ v b) (< v b) (<= v b) (= v b) (=> v u b) (> v b) (>= v b) (_ b) (abs v b) (and v u b) (append v b) (apply v b) (assoc v b) (assq v b) @@ -1341,11 +1344,18 @@ (define (std-lib->env lib) (cond [(assoc lib *std-lib->env*) => (lambda (lv) - (let* ([v (cdr lv)] [n (vector-length v)]) - (lambda (id at) - (and (eq? at 'ref) - (let* ([i (immediate-hash id n)] [al (vector-ref v i)] [p (assq id al)]) - (if p (cdr p) #f))))))] + (let* ([v (cdr lv)] [n (vector-length v)]) + (if (eq? lib '(skint repl)) + (lambda (id at) + (let* ([i (immediate-hash id n)] [al (vector-ref v i)] [p (assq id al)]) + (if p (cdr p) + (let ([loc (make-location (list 'ref id))]) + (vector-set! v i (cons (cons id loc) al)) + loc)))) + (lambda (id at) + (and (eq? at 'ref) + (let* ([i (immediate-hash id n)] [al (vector-ref v i)] [p (assq id al)]) + (if p (cdr p) #f)))))))] [else #f])) diff --git a/t.c b/t.c index 7438667..0f2843e 100644 --- a/t.c +++ b/t.c @@ -715,14 +715,18 @@ char *t_code[] = { "h),.1v?{'(l2:y6:scheme;y4:char;)]2}'(y1:l),.1v?{'(l2:y6:scheme;y11:cas" "e-lambda;)]2}'(y1:b),.1v?{'(l2:y6:scheme;y4:base;)]2}]2}.!0&0{%3.0V3,." "0,.3H2,.0,.3V4,.0,.5A3,.0?{.6,.1sd]7}.1,.7,.7cc,.3,.6V5]7}.!1&0{%1@(y1" - "4:*std-lib->env*),.1A5,.0?{.0d]2}'(i37),n,.1V2,@(y14:*std-lib->env*),." - "1,.5cc@!(y14:*std-lib->env*).0]4}.!2.3d,.4a,,#0.5,.4,.6,.3,&4{%2.1u~?{" - "${${'(y3:ref),.5,@(y16:root-environment)[02},.3,${${.9a,:2^[01},:3^[01" - "},:1^[03}.1d,.1,:0^[22}]2}.!0.0^_1[42},@(y10:%25for-each1)[02}", + "4:*std-lib->env*),.1A5,.0?{.0d]2}'(l2:y5:skint;y4:repl;),.2q?{'(i101)}" + "{'(i37)},n,.1V2,@(y14:*std-lib->env*),.1,.5cc@!(y14:*std-lib->env*).0]" + "4}.!2.3d,.4a,,#0.0,.5,.5,.8,&4{%2.1u?{${'(y3:ref),.3,@(y16:root-enviro" + "nment)[02},.1,${'(l2:y5:skint;y4:repl;),:0^[01},:2^[23}${${'(y3:ref),." + "5,@(y16:root-environment)[02},.3,${${.9a,:1^[01},:0^[01},:2^[03}.1d,.1" + ",:3^[22}.!0.0^_1[42},@(y10:%25for-each1)[02}", "P", "std-lib->env", - "%1@(y14:*std-lib->env*),.1A5,.0?{.0,.0d,.0V3,.1,.1,&2{%2'(y3:ref),.2q?" - "{:0,.1H2,.0,:1V4,.0,.3A3,.0?{.0d]5}f]5}f]2}]5}f]2", + "%1@(y14:*std-lib->env*),.1A5,.0?{.0,.0d,.0V3,'(l2:y5:skint;y4:repl;),." + "5q?{.0,.2,&2{%2:1,.1H2,.0,:0V4,.0,.3A3,.0?{.0d]5}.3,'(y3:ref),l2b,.2,." + "1,.6cc,.4,:0V5.0]6}]5}.1,.1,&2{%2'(y3:ref),.2q?{:0,.1H2,.0,:1V4,.0,.3A" + "3,.0?{.0d]5}f]5}f]2}]5}f]2", "C", 0, "f@!(y7:*reset*)",