xcalm.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ; vim:ft=fasm:
  2. ; taken from: https://github.com/tgrysztar/fasmg
  3. ; Helper commands for writing CALM instructions
  4. ; INIT
  5. ; this command can be used to give an initial numeric value to local variable
  6. ; at the time when the CALM instruction is defined
  7. calminstruction calminstruction?.init? var*, val:0
  8. compute val, val
  9. publish var, val
  10. end calminstruction
  11. ; INITSYM
  12. ; this command can be used to give an initial symbolic value to local variable
  13. ; at the time when the CALM instruction is defined
  14. ; (any symbols in the value also keep the context of that instruction's namespace)
  15. calminstruction calminstruction?.initsym? var*, val&
  16. publish var, val
  17. end calminstruction
  18. ; ASM
  19. ; generates code to assemble given line of text as-is
  20. ; (any symbols in this text keep the context of the instruction's namespace)
  21. calminstruction calminstruction?.asm? line&
  22. local name, i
  23. initsym name, name.0
  24. match name.i, name
  25. compute i, i+1
  26. arrange name, name.i
  27. publish name:, line
  28. arrange line, =assemble name
  29. assemble line
  30. end calminstruction
  31. ; UNIQUE
  32. ; generates a new unique identifier at the definition time of CALM instruction;
  33. ; the identifier is stored in variable specified by name,
  34. ; and the same name is used as a prefix for generated identifier
  35. calminstruction calminstruction?.unique? name
  36. local i, buffer
  37. init i
  38. compute i, i+1
  39. arrange buffer, name#i
  40. publish name, buffer
  41. end calminstruction
  42. ; XCALL
  43. ; extends the CALL command with the ability to define some arguments as literal values;
  44. ; arguments enclosed with () are treated as numeric,
  45. ; ones enclosed with <> are treated as a text of symbolic value
  46. calminstruction calminstruction?.xcall? instruction*, arguments&
  47. arrange instruction, =call instruction
  48. convert:
  49. match , arguments
  50. jyes ready
  51. local v
  52. match v=,arguments, arguments, <>
  53. jyes recognize
  54. arrange v, arguments
  55. arrange arguments,
  56. recognize:
  57. match (v), v
  58. jyes numeric
  59. match <v>, v
  60. jyes symbolic
  61. append:
  62. arrange instruction, instruction=,v
  63. jump convert
  64. numeric:
  65. compute v, v
  66. symbolic:
  67. local name
  68. asm unique name
  69. publish name, v
  70. arrange instruction, instruction=,name
  71. jump convert
  72. ready:
  73. assemble instruction
  74. end calminstruction