SpainHackForth
2023-02-13 02:36:34 UTC
Hi all,
I have been trying to create a simple compiler for a VM I wrote. I'm writing the compiler on GForth.
Here is the offending code.
https://gist.github.com/jemo07/18a47eeb0bd99ffb350bd78002d8498e
For what ever reason, I can't seem to figure out how to write data off the stack onto a file. Maybe that is my problem, that I need to extract the data first ? Just kind of thinking out loud as I'm off the bed.
Here is how I was attempting to use the code:
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-line throw
:454: File I/O exception
Then:
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-line ok
fd-out write-file
:460: Invalid memory address
fd-out >>>write-file<<<
Backtrace:
You can see here what looks like success but the file, although create, it's always empty.
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-file ok
fd-out close-file throw ok
Please advice on what am I getting wrong.
Thanks,
I have been trying to create a simple compiler for a VM I wrote. I'm writing the compiler on GForth.
Here is the offending code.
https://gist.github.com/jemo07/18a47eeb0bd99ffb350bd78002d8498e
For what ever reason, I can't seem to figure out how to write data off the stack onto a file. Maybe that is my problem, that I need to extract the data first ? Just kind of thinking out loud as I'm off the bed.
Here is how I was attempting to use the code:
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-line throw
:454: File I/O exception
Then:
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-line ok
fd-out write-file
:460: Invalid memory address
fd-out >>>write-file<<<
Backtrace:
You can see here what looks like success but the file, although create, it's always empty.
s" bytecode.out" open-output ok
10 vm_c,lit ,, ok
20 vm_c,lit ,, ok
VM_UM_PLUS vm_c, , ok
fd-out write-file ok
fd-out close-file throw ok
Please advice on what am I getting wrong.
Thanks,