home .. forth .. colorforth mail list archive ..

[colorforth] New colored DTC forth for x86?


Hi,
I want to ask if this was already seen before on x86,
using ESP as a Virtual Instruction Pointer.

MOTIVATION
I came to do this after wanting to build
words using pushes and jumps. I tried to
simplify things to a maximum and I arrived
to this.

TOKENIZED SOURCE (ala AHA)
I want to use the following huffman encoded
byte tokenized source representation:
I chose the huffman encoding for the range
gradient. To decode them, a lsb shift and
a carry test are used.

Word    : xxxx xxx0 (Green)
Macro : xxxx xx01 (Yellow) Number : xxxx x100 (Magenta
Comment : xxxx x000 (White)

The first two are indexes and
the two others count dwords.
Tokens are packed 4 per cell.
Arguments are dwords placed after
a 4 token bundle.

DEFINITIONS
Definitions can be handled in two (many) ways:
-If the fetched dword is zero (AHA)
-If the token argument is zero

The first option make the editor code very simple.
Perhaps other things, comment as you like.

The second would make the range of adressable words
to 127 but would make the first cell of the array
a length indicator, which is the most sensible construct.
Zeroed token arguments for macro could also be used
as a EndOfSourceCode token (AHA) that could reinitialize
the dictionary for the next compile run by a single litteral
store (mov [Index], Index+4) and any other "exiting" actions.
Also, Red words for definitions could be implemented in the
editor.


Let's keep (public) forth alive!
Adam Marquis



Below is a quick code example:

    1                                  ;====================
    2                                  ;   Register Usage
    3                                  ;====================
    4                                  ; eax : Top of Stack
    5                                  ;[ebx]: Data Stack
    6                                  ; ecx : \ Scratch
    7                                  ; edx : /
    8                                  ;[ebp]: Return stack
    9                                  ;[esp]: Word Pointer
   10                                  ;[esi]: Source code
   11                                  ;[edi]: Compiled code
   12                                  ;*Last two used by compiler,
   13                                  ;optional
14 15 use32 16 17 %macro _colon 0
   18                                   mov [ebp], esp
   19                                   lea ebp, [ebp-4]
   20                                   mov dword esp, %%after
   21                                   ret
22 %%after: 23 %endmacro 24 25 _semicolon:
   26 00000000 8B6500                   mov esp, [ebp]
   27 00000003 8D6D04                   lea ebp, [ebp+4]
   28 00000006 C3                       ret
   29 00000007 90                       nop
30 31 _lit:
   32 00000008 8903                     mov [ebx], eax
   33 0000000A 8D5BFC                   lea ebx, [ebx-4]
   34 0000000D 58                       pop eax
   35 0000000E C3                       ret
36 37 _dup:
   38 0000000F 8903                     mov [ebx], eax
   39 00000011 8D5BFC                   lea ebx, [ebx-4]
   40 00000014 C3                       ret
   41 00000015 90                       nop
42 43 ;example of a forth word
   44                                  testword:
   45                                  _colon
   46 00000016 896500              <1>  mov [ebp], esp
   47 00000019 8D6DFC              <1>  lea ebp, [ebp-4]
   48 0000001C BC[22000000]        <1>  mov dword esp, %%after
   49 00000021 C3                  <1>  ret
   50                              <1> %%after:
   51 00000022 [08000000]               dd _lit
   52 00000026 60010000                 dd 160h
   53 0000002A [0F000000]               dd _dup
   54 0000002E [00000000]               dd _semicolon


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com