Skip to content

Instantly share code, notes, and snippets.

@nurpax
Created October 4, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurpax/90c9b11051e4ec16a16c2699485057a8 to your computer and use it in GitHub Desktop.
Save nurpax/90c9b11051e4ec16a16c2699485057a8 to your computer and use it in GitHub Desktop.
export interface Node {
loc: SourceLoc;
}
export type Expr = any | Ident | Literal
export type Stmt =
StmtInsn
| StmtSetPC
| StmtAlign
| StmtData
| StmtFill
| StmtInclude
| StmtBinary
| StmtIfElse
| StmtError
| StmtFor
| StmtMacro
| StmtCallMacro
| StmtLet
| StmtAssign
| StmtLoadPlugin
export type Insn = any
export interface StmtInsn extends Node {
type: 'insn';
insn: Insn;
}
export interface StmtSetPC extends Node {
type: 'setpc';
pc: Expr;
}
export interface StmtData extends Node {
type: 'data';
dataSize: DataSize;
values: Expr[];
}
export type Expr = any | Ident | Literal
export type Stmt =
StmtInsn
| StmtSetPC
| StmtAlign
| StmtData
| StmtFill
| StmtInclude
| StmtBinary
| StmtIfElse
| StmtError
| StmtFor
| StmtMacro
| StmtCallMacro
| StmtLet
| StmtAssign
| StmtLoadPlugin
// ...
// sit esim. tälläisiä nodeja käyttävässä koodissa voi tehdä vaikka
function evalStmt(s: Stmt): any {
if (s.type == 'setpc') {
// kääntäjä inferoi tähän haaraan et s on tyyppiä StmtSetPC
} else if (s.type == 'data') {
// kääntäjä inferoi et tässä haarassa ollaan StmtDataa käpistelemässä, jolloin esim. tästä tulis virhe:
return s.pc
}
}
// toi type siis voisi olla enumikin eikä stringi, mulla nyt vaan sattui olla tarvis tehdä ne stringeiksi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment