[video member=pervognsen stream_platform=twitch project=bitwise title="Assembler Macro Expansion" vod_platform=youtube id=oGb1Rk37Fh0 annotator=Miblo]
[0:07][Recap and set the stage for the day][:speech]
[1:05][Review the new cmd_la() pseudo-instruction][:asm :research]
[4:03][Review the new two-operand syntax for three-operand instructions][:asm :research]
[5:48][Review the new partial inference of immediates from operands][:asm :research]
[7:52][Review the new support for '.' being the first character of an identifier][:asm :research]
[9:35][Review the new '>' and '<' jump-to-label directives, inspired by the NES Metroid source[ref
    site=GitHub
    page="MaximeGir/NES-Metroid-source-code"
    url=https://github.com/MaximeGir/NES-Metroid-source-code]][:asm :research]
[15:38][Describe the implementation of anonymous labels][:asm :parsing :research]
[19:43][Review the load immediate and mov pseudo-instructions][:asm :research]
[21:53][Q&A][:speech]
[22:03][@twitchplaysp0ng][Shouldn't 1545 be "lw x3, \[val\]"?][:asm]
[23:06][@miotatsu][I like all your changes personally, the only thing I would do different is dropping number labels and using the <# ># syntax for referring to anonymous labels. But it's all bikeshed discussion really][:asm]
[26:35][Macro Expansion][:asm :speech]
[28:07][Macros, Constant and Parameterized][:asm :language :speech]
[30:30][Spec'ing out our macros syntax, and considering how to implement it][:asm :language :speech]
[32:50][Dive right in to implementing macro expansion, separating out next_token() into a new scan_token() function][:asm :language :parsing]
[43:07][:Run it to see that it does not work][:asm :language :parsing]
[43:19][Fix next_token() to use the returned token from scan_token()][:asm :language :parsing]
[43:25][:Run it to see that it works][:asm :language :parsing]
[43:58][Introduce the notion of a TokenList, and init_scan() to build up that list][:asm :language :parsing]
[51:24][:Run it to see that it miraculously works][:asm :language :parsing]
[51:48][Stress test the :"error handling"][:asm :language :parsing :programming :run]
[54:08][Augment the TokenList with an index][:asm :language :parsing]
[58:03][:Run it to see that it's okay][:asm :language :parsing]
[58:27][Introduce the notion of a TokenListStack and its accompanying push_token_list() and pop_token_list() to handle "nested macro" expansion][:asm :language :parsing]
[1:07:54][:Run it to see that it seems to work][:asm :language :parsing]
[1:08:13][Embark on the actual macro expansion, introducing cmd_define()][:asm :language :parsing]
[1:16:02][Add a macro in asm_test()][:asm :language :parsing]
[1:16:36][:Run it with the macro established in the symbol table][:asm :language :parsing]
[1:16:40][Enable next_token() to perform macro expansion][:asm :language :parsing]
[1:18:51][The logic of the macro expansion][:asm :language :parsing :research]
[1:19:37][Fix next_token() to check that it even got a sym before checking that it is a SYM_MACRO][:asm :language :parsing]
[1:20:11][:Run it and unexpectedly hit an "Expected name, got integer" error][:asm :language :parsing]
[1:21:55][Separate some of next_token() out into next_unexpanded_token(), and (temporarily?) require the use of '`' to denote the identifier in macros][:asm :language :parsing]
[1:28:18][:Run it to see that it works][:asm :language :parsing]
[1:29:32][Test '`' quoting][:asm :language :parsing]
[1:29:49][:Run it to see that it doesn't work, and break into next_token() to investigate why][:asm :language :parsing]
[1:34:10][Temporarily make gen_sync_pos() return without doing anything, in an effort to figure out what's wrong][:asm :language :parsing]
[1:35:13][Make next_token() try and set the sym using get_sym() before checking that it successfully got a sym][:asm :language :parsing]
[1:37:23][Narrow down our test cases in asm_test()][:asm :language :parsing :programming :run]
[1:39:29][Fix scan_str() to skip the '`'][:asm :language :parsing]
[1:40:07][:Run it to see that it works][:asm :language :parsing]
[1:40:25][Test macro expansion in asm_test()][:asm :language :parsing]
[1:40:41][:Run it doing macro expansion, and hit our assertion in pop_token_list()][:asm :language :parsing]
[1:41:52][Make init_pass() and lex_test() call init_scan()][:asm :language :parsing]
[1:42:48][Step through push_token_list() to see that it all works][:asm :language :parsing :run]
[1:43:46][Add a more complex macro expansion test to asm_test()][:asm :language :parsing :run]
[1:44:47][:Run it and again hit our assertion in pop_token_list()][:asm :language :parsing]
[1:46:30][Try renaming that test macro from `x4_plus_4 to asdf][:asm :language :parsing]
[1:46:43][:Run it and hit our assertion in pop_token_list()][:asm :language :parsing]
[1:47:51][Fix our asdf macro to `asdf in asm_test()][:asm :language :parsing]
[1:47:58][:Run it and hit our pop_token_list() assertion on the `GETCHAR macro][:asm :language :parsing]
[1:48:29][Narrow down our test cases in asm_test()][:asm :language :parsing :programming :run]
[1:48:50][:Run it to see that it actually works][:asm :language :parsing]
[1:49:09][Rename that `asdf macro back to `x1_plus_4][:asm :language :parsing]
[1:49:28][:Run it to find that this works][:asm :language :parsing]
[1:49:42][Uncomment the `GETCHAR macro definition in asm_test()][:asm :language :parsing]
[1:49:56][:Run it and hit our pop_token_list() assertion on that `GETCHAR definition][:asm :language :parsing]
[1:50:38][Try flipping the order of the `x1_plus_4 and `GETCHAR macros][:asm :language :parsing]
[1:51:00][:Run it, hit our pop_token_list() assertion and consider that it's the second macro definition that asserts][:asm :language :parsing]
[1:52:17][Make init_scan() 0-initialise the token_list_stack and rename next_unexpanded_token() to next_raw_token()][:asm :language :parsing]
[1:59:32][Undo the buggy asm_test()][:asm :language :parsing]
[1:59:56][:Run it to see that it's fine][:asm :language :parsing]
[2:00:21][Reflect on our macro expansion with a glimpse into the future of parameterized macros and the determination to fix the bug off-stream][:asm :language :parsing :speech]
[2:03:36][That's it for today's stream][:speech]
[/video]
