shithub: femtolisp

Download patch

ref: 4cf907cc035cd84c90b4270f758d382861c15451
parent: 0864e3a7e23a6e3f6db9049abd3c70fd7e181606
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Dec 9 18:45:46 EST 2024

aref N: make N start at 0, do a better disassembly to make it more clear what's going on

--- a/compiler.lsp
+++ b/compiler.lsp
@@ -389,8 +389,8 @@
       (apply    (if (< nargs 2)
                     (argc-error b 2)
                     (emit g (if tail? 'tapply 'apply) nargs)))
-      (aref     (cond ((= nargs 2) (emit g 'aref0))
-                      ((> nargs 2) (emit g b (- nargs 2)))
+      (aref     (cond ((= nargs 2) (emit g 'aref2))
+                      ((> nargs 2) (emit g b (- nargs 3)))
                       (else (argc-error b 2))))
       (else     (emit g b)))))
 
@@ -782,7 +782,7 @@
                  ((loada seta loadc call tcall list + - * / vector
                    argc vargc loadi8 apply tapply closure box shift aref)
                   (print-inst inst i 1)
-                  (princ (number->string (aref code i)))
+                  (princ (number->string (+ (aref code i) (if (eq? inst 'aref) 3 0))))
                   (set! i (+ i 1)))
 
                  ((loada.l seta.l loadc.l largc lvargc call.l tcall.l box.l)
--- a/flisp.boot
+++ b/flisp.boot
@@ -49,7 +49,7 @@
   length=) 1arg-lambda?)
 	    <= #fn("6000n210L;IB0470051;380470151S:" #(nan?) <=) >
 	    #fn("6000n210L:" #() >) >= #fn("6000n201L;IB0470051;380470151S:" #(nan?) >=)
-	    Instructions #table(call.l 81  trycatch 75  largc 79  loadg.l 68  box 90  cadr 36  argc 62  setg 71  load0 21  vector? 45  fixnum? 41  loadc0 17  loada0 0  div0 59  keyargs 89  call 5  loada.l 69  brt.l 50  pair? 18  sub2 78  add2 29  loadc.l 70  loadc 9  builtin? 43  set-car! 47  brt 25  ret 10  loadi8 66  tapply 77  loada1 1  shift 46  aref0 23  boolean? 39  atom? 24  cdr 13  brne.l 83  / 58  loadf 31  equal? 52  apply 54  dup 11  loadt 20  jmp.l 48  null? 38  not 35  = 60  set-cdr! 30  eq? 33  * 57  load1 27  dummy_t 94  bound? 42  brf 3  function? 44  box.l 91  < 28  brnn.l 84  jmp 16  loadv 2  for 76  lvargc 80  dummy_eof 96  + 55  dummy_f 93  brne 19  compare 61  neg 37  loadv.l 67  number? 40  vargc 74  brn 85  brbound 88  vector 63  loadc1 22  setg.l 72  brf.l 49  aref 92  symbol? 34  aset! 64  car 12  cons 32  tcall.l 82  - 56  brn.l 86  optargs 87  closure 14  pop 4  eqv? 51  list 53  seta 15  seta.l 73  brnn 26  loadnil 65  loadg 7  loada 8  dummy_nil 95  tcall 6)
+	    Instructions #table(call.l 81  trycatch 75  largc 79  loadg.l 68  aref2 23  box 90  cadr 36  argc 62  setg 71  load0 21  vector? 45  fixnum? 41  loadc0 17  loada0 0  div0 59  keyargs 89  call 5  loada.l 69  brt.l 50  pair? 18  sub2 78  add2 29  loadc.l 70  loadc 9  builtin? 43  set-car! 47  brt 25  ret 10  loadi8 66  tapply 77  loada1 1  shift 46  boolean? 39  atom? 24  cdr 13  brne.l 83  / 58  loadf 31  equal? 52  apply 54  dup 11  loadt 20  jmp.l 48  null? 38  not 35  = 60  set-cdr! 30  eq? 33  * 57  load1 27  dummy_t 94  bound? 42  brf 3  function? 44  box.l 91  < 28  brnn.l 84  jmp 16  loadv 2  for 76  lvargc 80  dummy_eof 96  + 55  dummy_f 93  brne 19  compare 61  neg 37  loadv.l 67  number? 40  vargc 74  brn 85  brbound 88  vector 63  loadc1 22  setg.l 72  brf.l 49  aref 92  symbol? 34  aset! 64  car 12  cons 32  tcall.l 82  - 56  brn.l 86  optargs 87  closure 14  pop 4  eqv? 51  list 53  seta 15  seta.l 73  brnn 26  loadnil 65  loadg 7  loada 8  dummy_nil 95  tcall 6)
 	    __init_globals #fn("5000n020w1422w3474w5476w7478w9:" #("/"
 								   *directory-separator*
 								   "\n"
@@ -131,9 +131,9 @@
   bcode:stack)) #fn(length)) compile-arglist)
 	    compile-begin #fn("9000n483H3?0700182715064:83=H3>070018283<64:7001O83<5447202352474018283=64:" #(compile-in
   void emit pop compile-begin) compile-begin)
-	    compile-builtin-call #fn("=000n7207185O538;3I07283=8;52I=073858;52@30D4858<24CK086El3:07502662:750858663:8<27C[086El3:07502862:86r2l3:07502962:750858663:8<2:Cj086El3:07385K62:86Kl3:07502;62:86r2l3:07502<62:750858663:8<2=CK086El3:07502>62:750858663:8<2?CK086El3:07385K62:750858663:8<2@CM086El3<07502A2B63:750858663:8<2CCW086r2L3;07385r262:750823702D@402C8663:8<2ECc086r2l3:07502F62:7G86r2523?07508586r2~63:7385r262:7508562:" #(#fn(get)
+	    compile-builtin-call #fn("=000n7207185O538;3I07283=8;52I=073858;52@30D4858<24CK086El3:07502662:750858663:8<27C[086El3:07502862:86r2l3:07502962:750858663:8<2:Cj086El3:07385K62:86Kl3:07502;62:86r2l3:07502<62:750858663:8<2=CK086El3:07502>62:750858663:8<2?CK086El3:07385K62:750858663:8<2@CM086El3<07502A2B63:750858663:8<2CCW086r2L3;07385r262:750823702D@402C8663:8<2ECc086r2l3:07502F62:7G86r2523?07508586r3~63:7385r262:7508562:" #(#fn(get)
   arg-counts length= argc-error list emit loadnil + load0 add2 - neg sub2 *
-  load1 / vector loadv #() apply tapply aref aref0 >) compile-builtin-call)
+  load1 / vector loadv #() apply tapply aref aref2 >) compile-builtin-call)
 	    compile-f #fn("8000n2702101>22262:" #(call-with-values #fn("7000n070AF62:" #(compile-f-))
 						  #fn("5000n20:" #())) compile-f)
 	    compile-f- #fn("O000n270501T711T517215173741T52711518;J7025@408;87H360E@802687518=268:51~73778:528:\x85\xa208?JL07886298>88J708=@508=U54@r07:867;2<7=2<7>8?527?268?5151535152478862@8>268?5188J708=@508=U5547A8608:898>55@30D47B8=2C523I0788688J702D@402E8=53@W088\x85?078862F8=53@E08:J?078862G8=53@30O47H0897I7J1518952537K868@<52486r4268951r4Mp47L868@D7J15154478862M5247N2O7P7Q8651517R86518<537S865162:" #(make-code-emitter
@@ -187,7 +187,7 @@
   #fn(has?) #fn(put!))) member delete-duplicates) delete-duplicates)
 	    diff #fn("8000n20J40q:200<1523:0710=162:0<710=152P:" #(#fn(memq)
 								   diff) diff)
-	    disassemble #fn("T000\x871000.///\x881000I60O?14z282JD07001E53471504D:@30D482<2205123051DD2487>1?:425187>2?;4r4268851\x8a<D8<<8=L3\x85242728888<>2O79537:8<<r4523907150@30D4E87K~2;|48<8<<KM_48>2<8?2=523[08;8>8<<r45348:897>888<<52G5148<8<<r4M_@\x1112<8?2?523V08;8>8<<K5348:89888<<GG5148<8<<KM_@\xe212<8?2@523W08;8>8<<K5347A2B888<<G515148<8<<KM_@\xb212<8?2C523\\08;8>8<<r45347A2B7>888<<52515148<8<<r4M_@}12<8?2D523\xb808;8>8<<r88>2EC70r4@30EM5347A2B7>888<<52512F5248<8<<r4M_47A2B7>888<<52515148<8<<r4M_48>2ECY07A2F5147A2B7>888<<52512F5248<8<<r4M_@30D@\xec08?2Gc3^08;8>8<<r45347A2B7>888<<52512F5248<8<<r4M_@\xb802<8?2H523e08;8>8<<r25347A2I7J8<<r,7K888<<52g3515248<8<<r2M_@z02<8?2L523e08;8>8<<r45347A2I7J8<<r,7>888<<52g3515248<8<<r4M_@<08;8>8<<E53^1^1@\xd6-:" #(disassemble
+	    disassemble #fn("U000\x871000.///\x881000I60O?14z282JD07001E53471504D:@30D482<2205123051DD2487>1?:425187>2?;4r4268851\x8a<D8<<8=L3\x93242728888<>2O79537:8<<r4523907150@30D4E87K~2;|48<8<<KM_48>2<8?2=523[08;8>8<<r45348:897>888<<52G5148<8<<r4M_@\x1f12<8?2?523V08;8>8<<K5348:89888<<GG5148<8<<KM_@\xf012<8?2@523e08;8>8<<K5347A2B888<<G8>2CC70r3@30EM515148<8<<KM_@\xb212<8?2D523\\08;8>8<<r45347A2B7>888<<52515148<8<<r4M_@}12<8?2E523\xb808;8>8<<r88>2FC70r4@30EM5347A2B7>888<<52512G5248<8<<r4M_47A2B7>888<<52515148<8<<r4M_48>2FCY07A2G5147A2B7>888<<52512G5248<8<<r4M_@30D@\xec08?2Hc3^08;8>8<<r45347A2B7>888<<52512G5248<8<<r4M_@\xb802<8?2I523e08;8>8<<r25347A2J7K8<<r,7L888<<52g3515248<8<<r2M_@z02<8?2M523e08;8>8<<r45347A2J7K8<<r,7>888<<52g3515248<8<<r4M_@<08;8>8<<E53^1^1@\xc8-:" #(disassemble
   newline #fn(function:code) #fn(function:vals)
   #fn("9000n10\\3H00[IC07021514720OAKM63:73061:" #(princ "\n" disassemble print) print-val)
   #fn(";000n370A3S0FEl3M071A72151523@0A182ML37023@4024751r5~512602765:" #(princ
@@ -196,10 +196,13 @@
   Instructions > #fn("6000n1702161:" #(princ "\t"))
   #fn(memq) (loadv.l loadg.l setg.l) ref-int32-LE (loadv loadg setg)
   (loada seta loadc call tcall list + - * / vector argc vargc loadi8 apply
-   tapply closure box shift aref) princ #fn(number->string)
-  (loada.l seta.l loadc.l largc lvargc call.l tcall.l box.l) (optargs keyargs)
-  keyargs " " brbound (jmp brf brt brne brnn brn) "@" hex5 ref-int16-LE (jmp.l
-  brf.l brt.l brne.l brnn.l brn.l)) disassemble)
+   tapply closure box shift aref) princ #fn(number->string) aref (loada.l
+								  seta.l
+								  loadc.l largc
+								  lvargc call.l
+								  tcall.l box.l)
+  (optargs keyargs) keyargs " " brbound (jmp brf brt brne brnn brn) "@" hex5
+  ref-int16-LE (jmp.l brf.l brt.l brne.l brnn.l brn.l)) disassemble)
 	    div #fn("7000n201k0EL;3C041EL;3404K;I504r/;I404EM:" #() div) emit
 	    #fn("O000z20EG82JR0120CB087<21C:08722_@900E187Pp@\x9e123124523A075082<52e1?2@30D42612752883F07882<29523:088T?1@30D^142612:52883F07882<29523:088T?1@30D^1412;C\\0822<d3=02=?14q?2@F0822>d3=02??14q?2@30O@30D412@C\\0822<d3=02A?14q?2@F0822>d3=02B?14q?2@30O@30D487<12CQ;3\x9b04882DCM087T2ECE00E82<2F7G8751PPp@x0882DCB00E82<2H87=PPp@a0882ICB00E82<2J87=PPp@J0882ECB00E82<2K87=PPp@30O;I]0412HCI0882ECB00E82<2F87=PPp@?00E7L182P8752p^140:" #(car
   cdr cadr #fn(memq) (loadv loadg setg) bcode:indexfor #fn(assq)
--- a/flisp.c
+++ b/flisp.c
@@ -921,7 +921,7 @@
 		GOTO_OP_OFFSET(OP_LOADT),
 		GOTO_OP_OFFSET(OP_LOAD0),
 		GOTO_OP_OFFSET(OP_LOADC1),
-		GOTO_OP_OFFSET(OP_AREF0),
+		GOTO_OP_OFFSET(OP_AREF2),
 		GOTO_OP_OFFSET(OP_AREF),
 		GOTO_OP_OFFSET(OP_ATOMP),
 		GOTO_OP_OFFSET(OP_BRT),
@@ -1251,7 +1251,7 @@
 			PUSH(vector_elt(FL(stack)[bp+nargs], 1));
 			NEXT_OP;
 
-		OP(OP_AREF0)
+		OP(OP_AREF2)
 			FL(stack)[ipd] = (uintptr_t)ip;
 			v = FL(stack)[FL(sp)-2];
 			if(isvector(v)){
@@ -1271,7 +1271,7 @@
 
 		OP(OP_AREF)
 			FL(stack)[ipd] = (uintptr_t)ip;
-			n = 1 + *ip++;
+			n = 2 + *ip++;
 			v = FL(stack)[FL(sp)-n-1];
 			for(i = n; i > 0; i--){
 				if(isvector(v)){
--- a/gen.lsp
+++ b/gen.lsp
@@ -23,7 +23,7 @@
     OP_LOADT          loadt     #f      0
     OP_LOAD0          load0     #f      0
     OP_LOADC1         loadc1    #f      0
-    OP_AREF0          aref0     #f      0
+    OP_AREF2          aref2     #f      0
     OP_ATOMP          atom?     1       (λ (x) (atom? x))
     OP_BRT            brt       #f      0
     OP_BRNN           brnn      #f      0
--- a/maxstack.inc
+++ b/maxstack.inc
@@ -30,12 +30,12 @@
 		case OP_CONS: case OP_SETCAR: case OP_SETCDR:
 		case OP_EQ: case OP_EQV: case OP_EQUAL: case OP_ADD2: case OP_SUB2:
 		case OP_IDIV: case OP_NUMEQ: case OP_LT: case OP_COMPARE:
-		case OP_AREF0: case OP_TRYCATCH:
+		case OP_AREF2: case OP_TRYCATCH:
 			sp--;
 			break;
 
 		case OP_AREF:
-			n = 1 + *ip++;
+			n = 2 + *ip++;
 			sp -= n;
 			break;
 
--- a/opcodes.h
+++ b/opcodes.h
@@ -22,7 +22,7 @@
 	OP_LOADT,
 	OP_LOAD0,
 	OP_LOADC1,
-	OP_AREF0,
+	OP_AREF2,
 	OP_ATOMP,
 	OP_BRT,
 	OP_BRNN,