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.

43 lines
830 B

  1. export enum LocType {
  2. REGISTER = "register",
  3. TEMPORARY = "temporary",
  4. VARIABLE = "variable",
  5. }
  6. export class Loc {
  7. type: LocType
  8. name: string
  9. constructor(type: LocType, name: string) {
  10. this.type = type
  11. this.name = name
  12. }
  13. toString(): string {
  14. let sigil = ''
  15. switch (this.type) {
  16. case 'register':
  17. sigil = '%'
  18. break
  19. case 'temporary':
  20. sigil = '#'
  21. break
  22. }
  23. return sigil + this.name
  24. }
  25. static vari(name: string): Loc {
  26. return new Loc(LocType.VARIABLE, name)
  27. }
  28. static temp(name: string): Loc {
  29. return new Loc(LocType.TEMPORARY, name)
  30. }
  31. static reg(name: string): Loc {
  32. return new Loc(LocType.REGISTER, name)
  33. }
  34. }