shithub: sl

Download patch

ref: 3cfea02a4e7863afce7813a525fd6468be823846
parent: 2f893ee47b89cffc0834548a39ec0ba479c887d8
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Apr 4 23:51:23 EDT 2025

fix the rest of unboxed logic

--- a/boot/sl.boot
+++ b/boot/sl.boot
@@ -402,8 +402,8 @@
                                                   #fn("n10B3F00<20C?00T21C8072061:23061:" #(thrown-value
   ffound caddr #fn(raise))) str-join #fn(map) str reverse! "/" "λ") fname) reverse! length>
   list-tail *interactive* filter closure? #fn(map) #fn("n10Z;380420061:" #(#fn(top-level-value)))
-  #fn(environment) #fn(for-each) #fn("n17021A<0KGF52524222374051==5247025765249292<KM_:" #(princ "("
-  #fn(for-each) #fn("n1702151472061:" #(princ " " print)) vec->list ")" *linefeed*))) print-stack-trace)
+  #fn(environment) #fn(for-each) #fn("n17021A<0KGF52524222374051==52470257652492<El23?0770KG0EG52@30q49292<KM_:" #(princ
+  "(" #fn(for-each) #fn("n1702151472061:" #(princ " " print)) vec->list ")" *linefeed* fn-disasm))) print-stack-trace)
             print-to-str #fn("z02050212285>10524238561:" #(#fn(buffer)
                                                            #fn(for-each)
                                                            #fn("n1200A62:" #(#fn(write)))
@@ -439,7 +439,9 @@
             self-evaluating? #fn("n120051S;3Z040H;36040RS;JK0421051;3A040R;3:04022051Q:" #(#fn(gensym?)
   #fn(const?) #fn(top-level-value)) self-evaluating?)
             separate-doc-from-body #fn("\x8710002000W1000J60q?14I2021?65140<0=2287513F01JB0883=07388871P62:13X02487513O086258751513B07388=8788<P1P62:761510P:" #(#0#
-  #fn("n1r520051L2;3]040KG21Q;3R040r2G22Q;3F040r3G23Q;3:040r4G24Q:" #(#fn(length) #\d #\o #\c #\-) doc?)
+  #fn("n1r520051L2;3i04210K5222Q;3[04210r25223Q;3L04210r35224Q;3=04210r45225Q:" #(#fn(str-length)
+                                                                                  #fn(str-rune)
+                                                                                  #\d #\o #\c #\-) doc?)
   #fn(str?) separate-doc-from-body #fn(keyword?) #fn(str) reverse) separate-doc-from-body)
             set-syntax! #fn("n220710163:" #(#fn(put!) *syntax-environment*) set-syntax!) sort
             #fn("O200010003000W2000J7071?240=J400:0<7223182870>42418287>362:" #(#(:key 0) identity
@@ -467,7 +469,8 @@
                                                                                         #fn(str-length)
                                                                                         #fn(str-sub)) str-trim)
             sym-set-doc #fn("z220151873601@401<87360q@401=21Z3\xb40883\xaf0228823528:<8:=74258<528=;3H04268=5126778=28295351~8=;3?042:2;8>>18<52718;8?P23527<02=8@534893>07<02>8953@30q^1^1^1^1^1^1^1@30q482B3[07?02@527A2B8:>182527<02@2C8:8;5253^1^1@30q47D60:" #(#fn(str?)
-  str-join #fn(str-split) "\n" any #fn("n1E20051L2;3?040EG21Q;34040:" #(#fn(length) #\space))
+  str-join #fn(str-split) "\n" any #fn("n1E20051L2;3B04210E5222Q;34040:" #(#fn(str-length)
+                                                                           #fn(str-rune) #\space))
   #fn(length) str-trim " " "" #fn(map) #fn("n170A2105152390220A62:0:" #(<= #fn(length)
                                                                         #fn(str-sub))) putprop
   *doc* *doc-extra* getprop *formals-list* filter #fn("n1700A52S:" #(member))
--- a/src/equal.c
+++ b/src/equal.c
@@ -335,8 +335,8 @@
 			u.d = ubnumsval(a);
 		else if(isrune(a))
 			return inthash(torune(a));
-		else // FIXME(sigrid): unboxed
-			u.d = 0;
+		else
+			abort();
 		return doublehash(u.i64);
 	case TAG_FN:
 		if(uintval(a) > N_BUILTINS)
--- a/src/print.c
+++ b/src/print.c
@@ -873,8 +873,8 @@
 	else if(isrune(v)){
 		rune_print(f, torune(v));
 		return;
-	}else // FIXME(sigrid): unboxed
-		u = 0;
+	}else
+		abort();
 	int numtype = ubnumtype(v);
 	sl_v typesym = unboxedtypesyms[numtype];
 	sl_type *type = unboxedtypes[numtype];
--- a/src/sl.h
+++ b/src/sl.h
@@ -127,8 +127,7 @@
 
 /* UNBOXED
  * integers: ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|tttt0100|
- * strings:  ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|sss01100|
- * runes:    ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|00011100|
+ * runes:    ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|11111100|
  */
 #define TAG_UBNUM_SHIFT (TAG_BITS+1)
 #define isubnum(x)  ((tagext(x) & ((1<<TAG_UBNUM_SHIFT)-1)) == (0<<TAG_BITS | TAG_UNBOXED))
@@ -139,8 +138,8 @@
 extern sl_type *unboxedtypes[T_UNBOXED_NUM];
 extern sl_v unboxedtypesyms[T_UNBOXED_NUM];
 
-#define mk_rune(r) ((r)<<TAG_EXT_BITS | 0x1c)
-#define isrune(v) (((v) & 0xff) == 0x1c)
+#define mk_rune(r) ((r)<<TAG_EXT_BITS | 0xfc)
+#define isrune(v) (((v) & 0xff) == 0xfc)
 #define torune(v) ((v)>>8)
 
 // allocate n consecutive conses
--- a/src/system.sl
+++ b/src/system.sl
@@ -139,11 +139,11 @@
    contains the rest of the terms."
   :doc-group doc
   (def (doc? kw)
-    (and (> (length kw) 5)
-         (eq? (aref kw 1) #\d)
-         (eq? (aref kw 2) #\o)
-         (eq? (aref kw 3) #\c)
-         (eq? (aref kw 4) #\-)))
+    (and (> (str-length kw) 5)
+         (eq? (str-rune kw 1) #\d)
+         (eq? (str-rune kw 2) #\o)
+         (eq? (str-rune kw 3) #\c)
+         (eq? (str-rune kw 4) #\-)))
   (let {[hd (car body)]
         [tl (cdr body)]}
     (cond [(and (str? hd) (not doc) tl)
@@ -162,8 +162,8 @@
       (let* {[lines (str-split doc "\n")]
              [hd (car lines)]
              [tl (cdr lines)]
-             [snd (any (λ (s) (and (> (length s) 0)
-                                   (eq? (aref s 0) #\space)
+             [snd (any (λ (s) (and (> (str-length s) 0)
+                                   (eq? (str-rune s 0) #\space)
                                    s))
                        tl)]
              [indent (and snd
@@ -1424,7 +1424,7 @@
        (for-each (λ (p) (princ " ") (print p))
                  (cdr (cdr (vec->list f))))
        (princ ")" *linefeed*)
-       #;(when (= n 0)
+       (when (= n 0)
          (fn-disasm (aref f 1) (aref f 0)))
        (set! n (+ n 1)))
      st)))
--- a/src/vm.h
+++ b/src/vm.h
@@ -425,19 +425,6 @@
 	for(int i = n-1; i > 0; i--){
 		sl_v e = sp[-i];
 		usize isz = tosize(e);
-		if(sl_isstr(v)){
-			char *s = tostr(v);
-			usize sz = cv_len(ptr(v)), b, k;
-			for(b = k = 0; k < isz && b < sz; k++)
-				b += u8_seqlen(s+b);
-			if(k == isz && b < sz){
-				Rune r;
-				chartorune(&r, s+b);
-				v = mk_rune(r);
-				continue;
-			}
-			bounds_error(v, e);
-		}
 		if(isarr(v)){
 			sp[-i-1] = v;
 			v = cvalue_arr_aref(sp-i-1);
--- a/test/unittest.sl
+++ b/test/unittest.sl
@@ -83,7 +83,7 @@
 
 (assert (> 9223372036854775808 9223372036854775807))
 
-(assert-fail (fixnum? (- (aref "0" 0) #\0)))
+(assert-fail (fixnum? (- (str-rune "0" 0) #\0)))
 
 (assert (= (ash #bignum(1) -9999) 0))
 
@@ -441,8 +441,8 @@
 (assert (equal? 7 (aref a 1 2)))
 (assert (equal? 5 (aref a 1 (1+ 0) 1)))
 (assert-fail (aref a 1 1 3) bounds-error)
-(assert (equal? #\l (aref #("hello") 0 2)))
-(assert (equal? #\o (aref #("hello") 0 (1+ 3))))
+(assert (equal? #\l (rune (aref #("hello") 0 2))))
+(assert (equal? #\o (rune (aref #("hello") 0 (1+ 3)))))
 (assert-fail (aref #("hello") 0 5))
 (assert-fail (aref #("hello") 1 0))
 (assert-fail (aref '(NIL) 0 0))
--- a/tools/gen.sl
+++ b/tools/gen.sl
@@ -6,8 +6,8 @@
 
 (def (name->cname name)
   (let {[cname (buffer)]}
-    (for 0 (1- (length name))
-      (λ (i) (let {[r (rune (aref name i))]}
+    (for 0 (1- (str-length name))
+      (λ (i) (let {[r (str-rune name i)]}
                (io-write cname
                          (cond [(rune-alphanumeric? r) (rune-upcase r)]
                                [(eq? r #\?) #\P]