1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-12 02:30:57 +00:00

Language: raw asm { ... } blocks

raw asm {
        LDA #\$42
        STA \$00
    }

Unlike regular \`asm\`, \`raw asm\` does not perform \`{var}\`
substitution — the body is passed to the inline parser verbatim.
Useful for writing completely unmanaged bytes that don't rely on
the analyzer's variable allocations, e.g. mapper init snippets.

Implementation:
- Parser: \`KwRaw\` followed by \`KwAsm\` emits
  \`Statement::RawAsm(body, span)\`.
- IR lowering: prepends a \`\\0RAW\\0\` marker to the body when
  emitting \`IrOp::InlineAsm\` so the codegen can distinguish raw
  from regular without adding a second op variant.
- IR codegen: strips the marker and skips substitution when present.
- AST codegen: same, handling \`Statement::RawAsm\` directly.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 17:34:17 +00:00
parent a283f87b79
commit a45944e0f9
No known key found for this signature in database
8 changed files with 82 additions and 16 deletions

View file

@ -947,6 +947,23 @@ impl Parser {
))
}
}
TokenKind::KwRaw => {
// `raw asm { ... }` — verbatim bytes, no `{var}`
// substitution.
let span = self.current_span();
self.advance(); // KwRaw
self.expect(&TokenKind::KwAsm)?;
if let TokenKind::AsmBody(body) = self.peek().clone() {
self.advance();
Ok(Statement::RawAsm(body, span))
} else {
Err(Diagnostic::error(
ErrorCode::E0201,
"expected `{` after `raw asm`",
self.current_span(),
))
}
}
TokenKind::Ident(_) => self.parse_assign_or_call(),
_ => Err(Diagnostic::error(
ErrorCode::E0201,