This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

"C--"



Hi gcc list.

How portable are GNU "as" assembly directives? 

I am writing an address-interpreted Forth-like language in GNU C and
as, on Linux. It's called H3sm, Hohensee's 3-stack machine. I use asm 
escapes from the C, wrapped in m4 macros, to insert as assembler 
directives to build all the H3sm keywords' "dictionary headers", 
which is a singly back-linked list and some other info for each keyword.
The code bodies of fundamental keywords are written entirely in C,
except for a couple syscalls. The interpreter is made of derived words,
which are threads of execution addresses of fundamental words. The 
interpreter is also written entirely with assembler directives.

The only things that need specific machine opcodes are syscalls, and
argv and envp handling. 

This technique is a huge win for a threaded language. H3sm has gotten
several times smaller, and simpler. eForth is an all-x86-asm Forth.
It's about 13k, static. H3sm is currently about 24k, and models a much
more complex VM. And again, all the hard code, like variable-precision
plus and other H3sm oddities, is in C. Meaning I never would have written 
it at all in straight asm.

This is my m4 macro for the header of a fundamental word...

asm     ("
        `ALTLABEL'
        .byte   `len($2)'
        .byte   0
        .byte   0x80
        .byte   0
        .ascii  \"`$2'\"
        .align  4, 0
        .int    `ALTREF'
        .equ    `$1'CFA, .
        ");
`$1':
)

The macros for address-threads of derived words use the same directives.

My main question:
How portable is that? 
I only have x86 machines. 

Are there any well-known examples of code that uses this type of technique
to this extent? H3sm also uses labels-as-values and computed-goto like 
GForth, which makes this technique possible, I think; At least the way I
interlace metadata as directives and C-written code. Thus it is a gcc
thing, "C--" if you will.

Congrats to all gcc and as people for making such things possible. It's 
a special thing to see what can in fact be done with the GNU tools.

H3sm 0.8 and/or 0.9 is in 
ftp://linux01.gwdg.de/pub/cLIeNUX/interim

Rick Hohensee


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]