A "high-level" language for the Gameboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.2 KiB

  1. export type Program = Array<Decl | Stmt>
  2. // Declarations
  3. export type Decl = VarDecl
  4. export type VarDecl = ADecl<"var", {
  5. type: Type,
  6. }>
  7. type ADecl<Ty, Args> = {
  8. type: "decl",
  9. decl_type: Ty,
  10. attrs: Array<Attr>,
  11. name: string,
  12. args: Args,
  13. }
  14. // Statements
  15. export type Stmt = LabelStmt | GotoStmt | AssignStmt
  16. export type LabelStmt = AStmt<"label", {
  17. name: string,
  18. }>
  19. export type GotoStmt = AStmt<"goto", {
  20. name: string,
  21. }>
  22. export type AssignStmt = AStmt<"assign", {
  23. name: string,
  24. expr: Expr,
  25. }>
  26. type AStmt<Ty, Args> = {
  27. type: "stmt",
  28. stmt_type: Ty,
  29. args: Args,
  30. }
  31. // Expressions
  32. export type Expr = BinaryExpr | UnaryExpr | BasicExpr
  33. type BinaryExpr = {
  34. type: "binary",
  35. op: BinaryOp,
  36. left: Expr,
  37. right: Expr,
  38. }
  39. type UnaryExpr = {
  40. type: "unary",
  41. op: UnaryOp,
  42. arg: Expr,
  43. }
  44. type BasicExpr = number | string
  45. type UnaryOp = "arith_negate" | "bit_negate"
  46. type BinaryOp = "add" | "subtract" | "shift_left" | "shift_right" | "bit_and"
  47. | "bit_xor" | "bit_or"
  48. // Attributes
  49. export type Attr = {
  50. name: string,
  51. args: Array<string | number>,
  52. }
  53. // Types
  54. export type Type = PrimitiveType
  55. export type PrimitiveType = "s8" | "u8" | "u16"