1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-09 09:18:01 +00:00

M2: Add function/array parsing, IR data structures and lowering

Parser extensions:
- Function declarations with params and return types (fun, inline fun)
- Array type syntax (u8[16]), array literal expressions ([1, 2, 3])
- fast/slow variable placement hints
- Functions stored in Program AST

IR module (new):
- IrProgram, IrFunction, IrBasicBlock, IrOp, IrTerminator types
- AST-to-IR lowering pass with:
  - Expression lowering to virtual temps
  - Control flow (if/else, while, loop) to basic blocks with branches
  - Break/continue via loop context stack
  - Short-circuit logical and/or
  - Button reads, draw sprites, wait_frame
  - Constants inlined as LoadImm
  - State handlers lowered as separate IR functions

Tests: 6 new parser tests, 11 new IR lowering tests (153 total)

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-11 23:25:26 +00:00
parent fd5a940c89
commit 664ccc05db
No known key found for this signature in database
8 changed files with 1295 additions and 22 deletions

View file

@ -76,9 +76,7 @@ pub struct ConstDecl {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Placement {
#[allow(dead_code)]
Fast,
#[allow(dead_code)]
Slow,
Auto,
}
@ -89,7 +87,6 @@ pub enum NesType {
I8,
U16,
Bool,
#[allow(dead_code)]
Array(Box<NesType>, u16),
}
@ -121,6 +118,7 @@ pub enum Expr {
UnaryOp(UnaryOp, Box<Expr>, Span),
Call(String, Vec<Expr>, Span),
ButtonRead(Option<Player>, String, Span),
ArrayLiteral(Vec<Expr>, Span),
}
impl Expr {
@ -133,7 +131,8 @@ impl Expr {
| Self::BinaryOp(_, _, _, s)
| Self::UnaryOp(_, _, s)
| Self::Call(_, _, s)
| Self::ButtonRead(_, _, s) => *s,
| Self::ButtonRead(_, _, s)
| Self::ArrayLiteral(_, s) => *s,
}
}
}