Created
October 4, 2018 19:33
-
-
Save nurpax/90c9b11051e4ec16a16c2699485057a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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