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.

59 lines
922 B

  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: string,
  30. left: Expr,
  31. right: Expr,
  32. }
  33. type UnaryExpr = {
  34. type: "unary",
  35. op: string,
  36. arg: Expr,
  37. }
  38. type BasicExpr = number | string
  39. // Attributes
  40. export type Attr = {
  41. name: string,
  42. args: Array<string | number>,
  43. }
  44. // Types
  45. export type Type = PrimitiveType
  46. export type PrimitiveType = "s8" | "u8" | "u16"