diff options
Diffstat (limited to 'core.e')
| -rw-r--r-- | core.e | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/core.e b/core.e index 1094e45..1bc73e1 100644 --- a/core.e +++ b/core.e @@ -65,6 +65,9 @@ ~ with the label transform, which can do forward references, but the log-load ~ transform's label support is special-cased to ONLY do this, and it will only ~ work with a backward reference. +~ +~ We begin by outputting the actual docol routine, the one that codewords +~ should point to. Note that this is before we've done any word header. here @ dup L!' docol-codeword-value :rsi pack-pushcontrol @@ -74,12 +77,18 @@ pack-next 8 packalign here ! -: docol - [ here @ - ~ Evaluated as a word, docol is a constant which returns a pointer. - L@' docol-codeword-value :rax mov-reg64-imm64 - :rax push-reg64 - here ! ] ;asm +~ We can't use colon to create docol, not even the part that's a word, +~ because colon tries to dynamically invoke docol to fill in the codeword. +s" docol" create +here @ +dup 8 + pack64 +L@' docol-codeword-value :rax mov-reg64-imm64 +:rax push-reg64 +pack-next +8 packalign +here ! +~ Now that we have docol, colon will work and we can define words the normal +~ way. ~ This is the mechanism to "return" from a word interpreted by docol. ~ We pop the control stack, and then, since this is threaded execution, we @@ -89,6 +98,11 @@ here ! :rsi pack-popcontrol here ! ] ;asm +~ Now that we have exit, semicolon will also work and we can define +~ non-assembly words. However, it will be hard to make them do much until we +~ have lit as well. There's no special hurry; most of the words in core.e are +~ assembly words. We'll get to it further down. + ~ Stack manipulation routines ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -581,7 +595,7 @@ here ! ~ storage operations heavily leverage the fact they have an object system ~ with type tags and so on; we want to stay close to the bytes. -~ Address on the top of the stack, value in the second position +~ (value, address --) : ! [ here @ :rbx pop-reg64 @@ -589,6 +603,7 @@ here ! :rax :rbx mov-indirect-reg64-reg64 here ! ] ;asm +~ (address -- value) : @ [ here @ :rax pop-reg64 @@ -596,8 +611,8 @@ here ! :rax push-reg64 here ! ] ;asm -~ I might have put the parameters the other way round, but this is what -~ Jonesforth does and it seems reasonable enough. +~ This follows the general convention that words that set things take the +~ destination as the final parameter. ~ ~ (value, address --) : +! @@ -676,10 +691,14 @@ here ! ~ register by that name, it's a Forth-provided abstraction. That's super ~ confusing, plus as discussed above we call it the control stack not the ~ return stack, so we call the words... +~ +~ (stack pointer --) : control! [ here @ :rbp pop-reg64 here ! ] ;asm + +~ (-- stack pointer) : control@ [ here @ :rbp push-reg64 @@ -687,6 +706,8 @@ here ! ~ Jonesforth calls this DSP!, for data stack pointer. Again, there's no ~ Intel register by that name, and we call it the value stack, so... +~ +~ (stack pointer --) : value! [ here @ ~ Per Intel's description of POP this reads from the old location, and @@ -695,6 +716,8 @@ here ! ~ order. :rsp pop-reg64 here ! ] ;asm + +~ (-- stack pointer) : value@ [ here @ ~ Per Intel's description of PUSH this pushes the old value. |