Closed drocha87 closed 3 years ago
I don't know, but that same code doesn't work in either. The simulated one errors at pop from empty list
and the compiled one segfaults:
EDIT: as my prompt shows that there have been changes to my local version of the repo, here is the git status
output so that you can see that I only changed some of the highlights for myself:
It's possible that this might be because of mixing the load store for single byte and 8-byte words. I'm taking a look. Hopefully it's not because of something I did wrong :sweat_smile:
So, the correct program to do what this code is trying to do would be the following (I think)
include "std.porth"
"abcdefghijklmnopqrstuvxyz\0"
mem swap .64
mem 8 + swap .
mem ,64 print // string address in memory
mem 8 + , print // 26 string length
mem ,64 cast(ptr) , print // 97 (a)
The order of operators (+ <int>
instead of <int> +
) was wrong and since the we are storing the pointer as a 64-bit value, we have to increment by 8 bytes (not 1) while reading from memory.
@zrthxn the main issue is that the code should fail or succeed in both simulation and compilation. If the code is wrong as you pointed out it should fail in simulation as well. Maybe the implementation of the operators in simulation and compilation is diverging.
@drocha87 Well at the moment with the type checking your program by itself does fail on both, with test.porth:6:14: ERROR: invalid argument type for STORE intrinsic
. However if type-checking was to be disabled then the simulation output is IndexError: pop from empty list
after printing 13
, however the compiled version just segfaults... so what you say can actually be happening
I reported this issue 14 days ago. The language has changed a lot at this point. I'll close this issue because maybe it's not a valid issue anymore.
The code below seems to generate the expected output in simulation mode but don't output anything in compilation mode.
Simulation output:
./porth.py sim
Compilation output is empty.
./porth.py com -r