lynn / chibicc

A small C compiler… for uxn
MIT License
114 stars 4 forks source link

Support `asm()` #19

Closed lynn closed 1 year ago

lynn commented 1 year ago

It would be nice to support inline Uxntal, something like:

int max(int x, int y) {
    return asm(x, y, "LTH2k JMP SWP2 NIP2");
}

The syntax I'm picturing is: n values to push, followed by a literal string of Uxntal that leaves an int result on the stack.

Or maybe something top-level like this is even easier to implement, and more flexible in a way:

int max(int x, int y);
asm("@max_ LTH2k JMP SWP2 NIP2 JMP2r");
neauoire commented 1 year ago

That's a good idea, I would make use of this! I think the nested version is a bit more clear.