kevinlawler / kona

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

Reference count in Windows #640

Closed tavmem closed 1 year ago

tavmem commented 1 year ago

If you make these 2 code changes to show the details of the K-structure (instead of simply showing the result)

diff --git a/src/kc.c b/src/kc.c
index 5fcfebc..269afb0 100644
--- a/src/kc.c
+++ b/src/kc.c
@@ -277,7 +277,7 @@ I line(FILE*f, S*a, I*n, PDA*p)     //just starting or just executed: *a=*n=*p=0
     if(o&&k)O("Elapsed: %.7f\n",d);
   #endif
  next:
-  if(o && fam && !feci)show(k);
+  if(o && fam && !feci)sd_(k,2);              //show(k);
   cd(k);
  cleanup:
   if(fCheck && (strlen(s)==0 || s[strlen(s)-1]<0)) exit(0);
diff --git a/src/kc.h b/src/kc.h
index 46a0f44..93c118b 100644
--- a/src/kc.h
+++ b/src/kc.h
@@ -1,6 +1,7 @@
 void init_genrand64(unsigned long long seed);
 extern I SEED;
 extern C cdp[];
+extern K sd_(K x,I f);
 V alloc(size_t sz);
 K _dot_t();
 K newE(S s,K k);
$

Then, in Windows, if you start up kona and then simply hit carriage return, you get

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

     00000000001c0040 00000000001c0058            7175-6 6 0

the "7175" is much too high.

tavmem commented 1 year ago

If you make the same 2 code changes in Linux, you get

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

     0x7fe2048c5040 0x7fe2048c5058            7-6 6 0   
  \\

In IOS, you get

$ ./k
kona    \ for help.  \\ to exit.

     0x1077e7040  0x1077e7058            7-6 6 0
  \\
$
tavmem commented 1 year ago

The problem in Windows first occurs in commit 440fd474b7d2d44bf807c0c82575d7b4fc8941b0 titled "generalize the test for adding memory" committed on Oct 22, 2022