kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

counts created by newK() for types 2, 5 and 6 are wrong #542

Closed tavmem closed 5 years ago

tavmem commented 5 years ago

If you add the following 3 lines to kona:

diff --git a/src/kc.c b/src/kc.c
index 6be8f2b..5f6384c 100644
--- a/src/kc.c
+++ b/src/kc.c
@@ -172,6 +172,8 @@ I kinit() {       //oom (return bad)
   kap(&KTREE,&x); cd(x);
   x=newE(sp("t"),_dot_t());
   kap(&KTREE,&x); cd(x);
+  O("KTREE->_c: %lld     (KTREE->_c)>>8: %lld\n",KTREE->_c,(KTREE->_c)>>8);
+  O("sd_(KTREE,9):\n");sd_(KTREE,9);
   KONA_WHO=newK(1,1);*kI(KONA_WHO)=0;
   KONA_PORT=newK(1,1);*kI(KONA_PORT)=0;
   KONA_GSET=_n();
diff --git a/src/kc.h b/src/kc.h
index d7902c3..0710b1a 100644
--- a/src/kc.h
+++ b/src/kc.h
@@ -1,5 +1,6 @@
 void init_genrand64(unsigned long long seed);
 extern I SEED;
+extern K sd_(K x,I f);
 V alloc(size_t sz);
 K _dot_t();
 K newE(S s,K k);

then, you get

$ rlwrap -n ./k
KTREE->_c: 139819837842182     (KTREE->_c)>>8: 546171241571
sd_(KTREE,9):
     0x7f2a57c46200 0x7f2a57c46218            546171241571 5 2   .[(`k;;);(`t;-4.922195e+08;)]
 0x7f2a57c46220     0x7f2a57c46380 0x7f2a57c46398            1 0 3   [`t;-4.922195e+08;]
 0x7f2a57c463a8     0x7f2a57c46040 0x7f2a57c46058            546171241572 6 0   
 0x7f2a57c463a0     0x7f2a57c46300 0x7f2a57c46318            546171241572 2 1   -4.922195e+08
 0x7f2a57c46398     0x7f2a57c463c0 0x7f2a57c463d8 0x18e8330  1 4 1   `t
 0x7f2a57c46218     0x7f2a57c46280 0x7f2a57c46298            1 0 3   [`k;;]
 0x7f2a57c462a8     0x7f2a57c46040 0x7f2a57c46058            546171241572 6 0   
 0x7f2a57c462a0     0x7f2a57c46040 0x7f2a57c46058            546171241572 6 0   
 0x7f2a57c46298     0x7f2a57c462c0 0x7f2a57c462d8 0x18e8310  1 4 1   `k
kona      \ for help. \\ to exit.

Note: the counts for type 2, 5 and 6 are wrong. This has been the case since commit b592c36a01924501ef698c17432dc5539e0cf42d titled: "merge pahihu: km: lane size stored in refcnt" committed on Nov 22, 2015.

tavmem commented 5 years ago

After the fix, you get:

$ rlwrap -n ./k
KTREE->_c: 262     (KTREE->_c)>>8: 1
sd_(KTREE,9):
     0x7f23c7010200 0x7f23c7010218            1 5 2   .[(`k;;);(`t;-4.92211e+08;)]
 0x7f23c7010220     0x7f23c7010380 0x7f23c7010398            1 0 3   [`t;-4.92211e+08;]
 0x7f23c70103a8     0x7f23c7010040 0x7f23c7010058            4 6 0   
 0x7f23c70103a0     0x7f23c7010300 0x7f23c7010318            1 2 1   -4.92211e+08
 0x7f23c7010398     0x7f23c70103c0 0x7f23c70103d8 0xaee330  1 4 1   `t
 0x7f23c7010218     0x7f23c7010280 0x7f23c7010298            1 0 3   [`k;;]
 0x7f23c70102a8     0x7f23c7010040 0x7f23c7010058            4 6 0   
 0x7f23c70102a0     0x7f23c7010040 0x7f23c7010058            4 6 0   
 0x7f23c7010298     0x7f23c70102c0 0x7f23c70102d8 0xaee310  1 4 1   `k
kona      \ for help. \\ to exit.