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.

63 lines
1.1 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 = AssignStmt
  16. export type AssignStmt = AStmt<"assign", {
  17. name: string,
  18. expr: Expr,
  19. }>
  20. type AStmt<Ty, Args> = {
  21. type: "stmt",
  22. stmt_type: Ty,
  23. args: Args,
  24. }
  25. // Expressions
  26. export type Expr = BinaryExpr | UnaryExpr | BasicExpr
  27. type BinaryExpr = {
  28. type: "binary",
  29. op: BinaryOp,
  30. left: Expr,
  31. right: Expr,
  32. }
  33. type UnaryExpr = {
  34. type: "unary",
  35. op: UnaryOp,
  36. arg: Expr,
  37. }
  38. type BasicExpr = number | string
  39. type UnaryOp = "arith_negate" | "bit_negate"
  40. type BinaryOp = "add" | "subtract" | "shift_left" | "shift_right" | "bit_and"
  41. | "bit_xor" | "bit_or"
  42. // Attributes
  43. export type Attr = {
  44. name: string,
  45. args: Array<string | number>,
  46. }
  47. // Types
  48. export type Type = PrimitiveType
  49. export type PrimitiveType = "s8" | "u8" | "u16"