hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
719 stars 56 forks source link

Partial fix for issue #115: Initial support for local labels inside asm{} #120

Closed Emmett81 closed 11 months ago

Emmett81 commented 3 years ago

A label can only be used after it's defined, so no out-of-order support yet. Every line inside an asm{} that starts with TokenKind::Identifier && TokenKind:Colon is filtered out. The label name parsed and added via info.args(.set_label) with it's value set to the current instruction address.

Emmett81 commented 3 years ago

Second commit with full out-of-order implementation added.

Emmett81 commented 3 years ago

I was unable to write a test file for the "converge" error. So I included converge.asm as an example. For future reference, the original version did not detect when there was no convergance on output size. So it was rewritten.

Emmett81 commented 3 years ago

@hlorenzi I found an (for me) unexpected converge error case for the new combined fix. I haven't investigated it fully. But if in both asm{} and global space the labels are referenced out-of-order for the instruction being evaluated. And a global scope label involved has the same name as another global identifier. Then it seems to throw a converge error.

Emmett81 commented 3 years ago

@hlorenzi I found an (for me) unexpected converge error case for the new combined fix.

I was partially wrong in what triggers it. This a minimal example.

ruledef

{ emit {x} => x`8 call => asm { ;ret: emit ret emit andme ret:
}

} ;andme: call andme:

hlorenzi commented 11 months ago

I'll unfortunately close this for now since the assembler has received a complete infrastructure overhaul, and this PR can't be easily merged as is.