Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wrote a large package of macros for a niche assembler using M4. It has some sophisticated things like a code generator for non-infix expressions. M4 was a blessing and a curse. It is very powerful and saved me from implementing my own macro language but debugging is not for the faint of heart once you get into anything complicated.

https://github.com/kevinpt/opbasm/blob/master/opbasm/picobla...

Michael Breen's notes are indispensable documentation on how to make effective use of the language.



I'm a fan of M4, and I don't know what these are doing but it surely looks too complex. You have defines within defines and OMG just an extract

  .. (just a snip follows)
  `define(`_'''$`'1```_LENGTH',strlenc(''$`'2``))'dnl
  `; "''$`'2``"'
  `ifdef(`PB3', ''$`'1```: calltable($4, $1, estr('''$`'2```))dnl
  return',dnl
  `table '''$`'1```#, [dec2pbhex(cstr('''$`'2```))]
  '''$`'1```: loadaddr($2, $3, _'''$`'1```_STR)
  jump __`'$5`'_handler
  _'''$`'1```_STR: load&return $1, '''$`'1```#')'
  )')'
I have to ask if this is right, or whether a parser would have been a whole lot less work. Credit for your skillz, but that looks like so much pain.


These are macros that generate user configurable codegen macros. I couldn't hard code register assignments so everything dynamically generated is prepared with these monstrosities. They also can't have fixed names since some need to be invoked multiple times with different parameters.

FWIW I didn't intend for things to go this far. I just started with some simple macros and it snowballed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: