Hello all,
I having some issue with some code I'm using to have a go at meta compilation, I'm building a 32 bit 'Target' and when I try to write some bytes into the Target which I have alloted space for, it just won't show up.
Here is it is interactive in gForth:
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
CREATE TARGET 64 ALLOT ok
TARGET 64 ERASE ok
ok
\ Lets add a word to examine our target: ok
ok
: .## ( c) 0 <# # # #> TYPE SPACE ; ok
: REVIEW compiled
BASE @ >R HEX \ Show target addess space. compiled
2 0 DO CR 32 0 DO J 32 * I + TARGET C@ .## LOOP LOOP compiled
R> BASE ! ; ok
ok
ok
REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
ok
\ Lets add some references to the Target address ok
ok
: T@ ( a) TARGET + @ ; ok
: T! ( n a) TARGET + ! ; ok
: TC@ ( a) TARGET + C@ ; ok
: TC! ( n a) TARGET + C! ; ok
ok
\ Lets add some words to work in the target space ok
ok
VARIABLE TP ( Target Pointer) 1 TP ! ok
: THERE ( - a) TP @ ; ok
ok
2 CONSTANT TCELL ( 2 bytes per target cell) ok
ok
: TC, ( n) THERE TC! 1 TP +! ; ok
: T, ( n) THERE T! TCELL TP +! ; ok
: RENEW TARGET 32 ERASE 1 TP ! ; RENEW ok
ok
\ Lets work with our target by adding bytes ok
ok
RENEW 1 TC, 2 TC, 3 TC, REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
Any ideas on what I have missed?
On 23/08/2023 19:20, SpainHackForth wrote:
Hello all,
I having some issue with some code I'm using to have a go at meta compilation, I'm building a 32 bit 'Target' and when I try to write some bytes into the Target which I have alloted space for, it just won't show up.
Here is it is interactive in gForth:
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc. Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
CREATE TARGET 64 ALLOT ok
TARGET 64 ERASE ok
ok
\ Lets add a word to examine our target: ok
ok
: .## ( c) 0 <# # # #> TYPE SPACE ; ok
: REVIEW compiled
BASE @ >R HEX \ Show target addess space. compiled
2 0 DO CR 32 0 DO J 32 * I + TARGET C@ .## LOOP LOOP compiled
BASE ! ; okok
ok
REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
If you execute .s here you will see 0 to 63 left on the data stack.
That is left there by:
I + TARGET C@
in the inner loop of REVIEW, this should be:
I + TARGET + C@
I think it all works then.
Always test your test words like REVIEW in a simple way before using
them to test the rest of your code by putting some known data in a
simple way. erasing it and displaying 0's isn't a lot of good.
ok
\ Lets add some references to the Target address ok
ok
: T@ ( a) TARGET + @ ; ok
: T! ( n a) TARGET + ! ; ok
: TC@ ( a) TARGET + C@ ; ok
: TC! ( n a) TARGET + C! ; ok
ok
\ Lets add some words to work in the target space ok
ok
VARIABLE TP ( Target Pointer) 1 TP ! ok
: THERE ( - a) TP @ ; ok
ok
2 CONSTANT TCELL ( 2 bytes per target cell) ok
ok
: TC, ( n) THERE TC! 1 TP +! ; ok
: T, ( n) THERE T! TCELL TP +! ; ok
: RENEW TARGET 32 ERASE 1 TP ! ; RENEW ok
ok
\ Lets work with our target by adding bytes ok
ok
RENEW 1 TC, 2 TC, 3 TC, REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
Any ideas on what I have missed?
--
Gerry
If you execute .s here you will see 0 to 63 left on the data stack.THANK YOU!!! Let me try that...
That is left there by:
I + TARGET C@
in the inner loop of REVIEW, this should be:
I + TARGET + C@
I think it all works then.
Always test your test words like REVIEW in a simple way before using
them to test the rest of your code by putting some known data in a
simple way. erasing it and displaying 0's isn't a lot of good.
Gerry
On Wednesday, August 23, 2023 at 10:55:48 PM UTC+2, Gerry Jackson wrote:
Ah, I now see where I changed my code and must have just removed the + sign there Garry, THANK YOU for capturing that... I went down a deeeeeep rat whole looking from something in how I was writing TC,If you execute .s here you will see 0 to 63 left on the data stack.
That is left there by:
I + TARGET C@
in the inner loop of REVIEW, this should be:
I + TARGET + C@
I think it all works then.
Always test your test words like REVIEW in a simple way before usingTHANK YOU!!! Let me try that...
them to test the rest of your code by putting some known data in a
simple way. erasing it and displaying 0's isn't a lot of good.
Gerry
On Wednesday, August 23, 2023 at 4:55:48 PM UTC-4, Gerry Jackson wrote:Ah, OK let me try that!
On 23/08/2023 19:20, SpainHackForth wrote:
Hello all,
I having some issue with some code I'm using to have a go at meta compilation, I'm building a 32 bit 'Target' and when I try to write some bytes into the Target which I have alloted space for, it just won't show up.
Here is it is interactive in gForth:
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc. Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license' Type `bye' to exit
CREATE TARGET 64 ALLOT ok
TARGET 64 ERASE ok
ok
\ Lets add a word to examine our target: ok
ok
: .## ( c) 0 <# # # #> TYPE SPACE ; ok
: REVIEW compiled
BASE @ >R HEX \ Show target addess space. compiled
2 0 DO CR 32 0 DO J 32 * I + TARGET C@ .## LOOP LOOP compiled
BASE ! ; okok
ok
REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
If you execute .s here you will see 0 to 63 left on the data stack.
That is left there by:
I + TARGET C@
in the inner loop of REVIEW, this should be:
I + TARGET + C@
I think it all works then.
Always test your test words like REVIEW in a simple way before using
them to test the rest of your code by putting some known data in a
simple way. erasing it and displaying 0's isn't a lot of good.
ok
\ Lets add some references to the Target address ok
ok
: T@ ( a) TARGET + @ ; ok
: T! ( n a) TARGET + ! ; ok
: TC@ ( a) TARGET + C@ ; ok
: TC! ( n a) TARGET + C! ; ok
ok
\ Lets add some words to work in the target space ok
ok
VARIABLE TP ( Target Pointer) 1 TP ! ok
: THERE ( - a) TP @ ; ok
ok
2 CONSTANT TCELL ( 2 bytes per target cell) ok
ok
: TC, ( n) THERE TC! 1 TP +! ; ok
: T, ( n) THERE T! TCELL TP +! ; ok
: RENEW TARGET 32 ERASE 1 TP ! ; RENEW ok
ok
\ Lets work with our target by adding bytes ok
ok
RENEW 1 TC, 2 TC, 3 TC, REVIEW
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ok
Any ideas on what I have missed?
--I think it is because your target uses 2 byte cells but 32bit GForth is a 4 byte cell.
Gerry
This means you need to store and fetch 2 bytes.
32 bit GForth that I have has W! and W@ for 2 bytes words.
So if you change your T! and T@ to use the W words it should help.
: T@ ( a) TARGET + W@ ;
: T! ( n a) TARGET + W! ;
It's interesting to see that you did something very similar to my own code. Mine is simpler because I compile on a 16 bit machine to a 16 bit target.
I have thought for a while of rebuilding my cross-compiler on GForth.
On Thursday, August 24, 2023 at 12:48:51 PM UTC+2, SpainHackForth wrote:
On Wednesday, August 23, 2023 at 10:55:48 PM UTC+2, Gerry Jackson wrote:
how to get some of the variable folding in place... that is a deeper rat whole at the moment...If you execute .s here you will see 0 to 63 left on the data stack.
That is left there by:
I + TARGET C@
in the inner loop of REVIEW, this should be:
I + TARGET + C@
I think it all works then.
Ah, I now see where I changed my code and must have just removed the + sign there Garry, THANK YOU for capturing that... I went down a deeeeeep rat whole looking from something in how I was writing TC,Always test your test words like REVIEW in a simple way before using them to test the rest of your code by putting some known data in a simple way. erasing it and displaying 0's isn't a lot of good.THANK YOU!!! Let me try that...
Gerry
Bryan, any benefit in using W@ vs @, I'm looking at how I build some meta-compilation for 32 bit ARMv8 so I was looking it at a byte level, I have most of the code in place, just getting some inconsistencies in building my headers, then I'm exploring
Thank you both... I did create a simpler version of the REVIEW word just to check if I was doing something wrong in storing:* Variable Folding should be constant folding...
: REVIEW
BASE @ >R HEX ( Show target addess space.)
TARGET 32 0 DO ( loop 32 times )
DUP C@ .## ( fetch byte from address, display it, then push the address back )
1+ ( increment the address to point to the next byte )
LOOP
DROP ( drop the remaining address )
BASE ! ( Return address space. );
Cheers!
On Thursday, August 24, 2023 at 12:48:51 PM UTC+2, SpainHackForth wrote:how to get some of the variable folding in place... that is a deeper rat whole at the moment...
Bryan, any benefit in using W@ vs @, I'm looking at how I build some meta-compilation for 32 bit ARMv8 so I was looking it at a byte level, I have most of the code in place, just getting some inconsistencies in building my headers, then I'm exploring
On Thursday, August 24, 2023 at 7:07:14 AM UTC-4, SpainHackForth wrote:how to get some of the variable folding in place... that is a deeper rat whole at the moment...
On Thursday, August 24, 2023 at 12:48:51 PM UTC+2, SpainHackForth wrote:
Bryan, any benefit in using W@ vs @, I'm looking at how I build some meta-compilation for 32 bit ARMv8 so I was looking it at a byte level, I have most of the code in place, just getting some inconsistencies in building my headers, then I'm exploring
I don't know the ARMv8 instruction set details but if there are cases where the instruction fits into 16bits thenAwesome, THANK YOU !!! I'll have a look! Ah, relocation might be an issue latter on, I believe that might pop up when I get it running.
you can use W!.
Of course you could make your own version using shifts and OR and two C! words but W! is there to use.
BTW Here is how I did it for a machine with fixed size instructions of 16 bits.
I just replicated the way the Forth dictionary works with a T prefix on the word names.
It keeps my human memory load manageable.
\ target memory management
VARIABLE TDP \ target dictionary pointer
\ set where the Cross-assembler puts its code
HEX
: ORG ( addr -- ) TDP ! ;
: NEW 2000 2000 FF FILL 1FFF H ! ; \ H is the HEAP pointer in this system.
\ Target versions of HERE and ALLOT
: THERE ( -- addr) TDP @ ;
: TALLOT ( n -- ) TDP +! ;
\ integer and byte "Target" compilers
: T, ( n -- ) THERE ! 1 CELLS TALLOT ;
: TC, ( c -- ) THERE C! 1 TALLOT ;
Later in the cross-compiler I needed to deal with relocation.
The case is:
- the image compiled in a buffer on the machine.
- The programmer wants the program to load and run at a different address.
It might be more confusing, but if it helps the source code for this Machine Forth
is here:
https://github.com/bfox9900/MachForth/tree/main/COMPILER/src
Search for REL>TARG to see what I did for relocation and where it was used.
On Thursday, August 24, 2023 at 7:07:14 AM UTC-4, SpainHackForth wrote:how to get some of the variable folding in place... that is a deeper rat whole at the moment...
On Thursday, August 24, 2023 at 12:48:51 PM UTC+2, SpainHackForth wrote:
Bryan, any benefit in using W@ vs @, I'm looking at how I build some meta-compilation for 32 bit ARMv8 so I was looking it at a byte level, I have most of the code in place, just getting some inconsistencies in building my headers, then I'm exploring
I don't know the ARMv8 instruction set details but if there are cases where the instruction fits into 16bits thenJust took a peek, and that is some clean code! thank you again for sharing this! I see some resemblance in the structure, very readable and well constrained in the sections and how you build the code up. I did not look to much into the code "yet" but I
you can use W!.
Of course you could make your own version using shifts and OR and two C! words but W! is there to use.
BTW Here is how I did it for a machine with fixed size instructions of 16 bits.
I just replicated the way the Forth dictionary works with a T prefix on the word names.
It keeps my human memory load manageable.
\ target memory management
VARIABLE TDP \ target dictionary pointer
\ set where the Cross-assembler puts its code
HEX
: ORG ( addr -- ) TDP ! ;
: NEW 2000 2000 FF FILL 1FFF H ! ; \ H is the HEAP pointer in this system.
\ Target versions of HERE and ALLOT
: THERE ( -- addr) TDP @ ;
: TALLOT ( n -- ) TDP +! ;
\ integer and byte "Target" compilers
: T, ( n -- ) THERE ! 1 CELLS TALLOT ;
: TC, ( c -- ) THERE C! 1 TALLOT ;
Later in the cross-compiler I needed to deal with relocation.
The case is:
- the image compiled in a buffer on the machine.
- The programmer wants the program to load and run at a different address.
It might be more confusing, but if it helps the source code for this Machine Forth
is here:
https://github.com/bfox9900/MachForth/tree/main/COMPILER/src
Search for REL>TARG to see what I did for relocation and where it was used.
On Thursday, August 24, 2023 at 4:37:00 PM UTC+2, Brian Fox wrote:exploring how to get some of the variable folding in place... that is a deeper rat whole at the moment...
On Thursday, August 24, 2023 at 7:07:14 AM UTC-4, SpainHackForth wrote:
On Thursday, August 24, 2023 at 12:48:51 PM UTC+2, SpainHackForth wrote:
Bryan, any benefit in using W@ vs @, I'm looking at how I build some meta-compilation for 32 bit ARMv8 so I was looking it at a byte level, I have most of the code in place, just getting some inconsistencies in building my headers, then I'm
think I saw how you build the different opcodes based on their conditional formats, or at least that is how I'm setting up the code I'm working on, they are structured differently.I don't know the ARMv8 instruction set details but if there are cases where the instruction fits into 16bits then
you can use W!.
Of course you could make your own version using shifts and OR and two C! words but W! is there to use.
BTW Here is how I did it for a machine with fixed size instructions of 16 bits.
I just replicated the way the Forth dictionary works with a T prefix on the word names.
It keeps my human memory load manageable.
\ target memory management
VARIABLE TDP \ target dictionary pointer
\ set where the Cross-assembler puts its code
HEX
: ORG ( addr -- ) TDP ! ;
: NEW 2000 2000 FF FILL 1FFF H ! ; \ H is the HEAP pointer in this system.
\ Target versions of HERE and ALLOT
: THERE ( -- addr) TDP @ ;
: TALLOT ( n -- ) TDP +! ;
\ integer and byte "Target" compilers
: T, ( n -- ) THERE ! 1 CELLS TALLOT ;
: TC, ( c -- ) THERE C! 1 TALLOT ;
Later in the cross-compiler I needed to deal with relocation.
The case is:
- the image compiled in a buffer on the machine.
- The programmer wants the program to load and run at a different address.
It might be more confusing, but if it helps the source code for this Machine Forth
is here:
https://github.com/bfox9900/MachForth/tree/main/COMPILER/src
Search for REL>TARG to see what I did for relocation and where it was used.Just took a peek, and that is some clean code! thank you again for sharing this! I see some resemblance in the structure, very readable and well constrained in the sections and how you build the code up. I did not look to much into the code "yet" but I
Here is the sheet I work with to see all the opcodes: https://montcs.bloomu.edu/Information/ARMv8/legv8-green-card.compressed.pdf
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:16:50 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,091 |