[video member=pervognsen stream_platform=twitch project=bitwise title="Parameterized Macros" vod_platform=youtube id=is6H67viWfs annotator=Miblo] [0:08][Recap and set the stage for the day with a mention of the bug fix from last stream][:speech] [0:52][Review our current macro expansion support, including the new '$' macro identifier][:asm :language :speech] [4:11][Review the removal of anonymous labels][:asm :language :speech] [5:11][Parameterized macros][:asm :language :speech] [8:02][The plan for parameterized macros][:asm :language :speech] [12:02][Implement multi-line macros, introducing cmd_macro() and cmd_endmacro()][:asm :language] [15:42][Add a multi-line macro test in asm_test() and fix cmd_macro() to skip the closing token][:asm :language] [16:35][:Run it to see that it works][:asm :language] [17:04][Setup to implement parameterized macros, similar to Ion][:asm :language :speech] [18:35][Dive into parameterized macros, augmenting the Assembler with local_syms for get_sym() to use][:asm :language] [21:10][:Run it to see that nothing broke][:asm :language] [21:26][Introduce push_sym() to handle our macro parameters][:asm :language] [26:25][:Run it to make sure it still works][:asm :language] [26:34][Augment Assembler with a temp_tokens array, and introduce parse_macro_param() to handle our macro parameters][:asm :language :parsing] [35:08][Enable pop_token_list() to pop our temp_tokens stack][:asm :language :parsing] [38:53][:Run it and crash in get_sym()][:asm :language :parsing] [39:07][Make init_assembler() reset the local_syms and temp_tokens][:asm :language :parsing] [39:28][:Run it to see that it works][:asm :language :parsing] [39:44][Enable cmd_macro() to handle newlines][:asm :language :parsing] [43:52][:Run it to see that we didn't break anything][:asm :language :parsing] [44:24][Add a parameterized macro test in asm_test()][:asm :language :parsing] [45:08][Step in to next_token() to see how it handles our parameterized macro][:asm :language :parsing :run] [46:11][Fix next_token() to skip past the '$' token][:asm :language :parsing] [47:29][:Run it to see that parse_macro_param() correctly parses a parameter][:asm :language :parsing] [48:14][Step through to the next macro, to see how $reg gets handled][:asm :language :parsing :run] [49:21][Rename the getchar macro in asm_test() to do_getchar][:asm :language :parsing] [49:41][:Run it to see that it seems to work][:asm :language :parsing] [50:04][Torture test macro parameter pre-expansion][:asm :language :parsing] [50:39][:Run it to see that it does work][:asm :language :parsing] [50:42][Continue the torture test of macro parameter expansion][:asm :language :parsing] [52:04][:Run it to see that it works][:asm :language :parsing] [52:24][Test macro parameter scoping][:asm :language :parsing] [52:41][:Run it and do not receive the expected error][:asm :language :parsing] [52:53][Augment the TokenList with saved_local_syms for next_token() to use and prevent parameters from leaking out of macros][:asm :language :parsing] [54:34][:Run it to see that our scoped parameter was properly destroyed, as evidenced by a "No macro or macro parameter named 'arg1'" error][:asm :language :parsing] [54:43][Comment out our error-causing macro][:asm :language :parsing] [54:48][:Run it to see that it works][:asm :language :parsing] [54:56][Test macro recursion][:asm :language :parsing] [55:11][:Run it and hit a "Temp tokens stack overflow" error][:asm :language :parsing] [55:44][A few words on the utility of this infinite macro recursion][:asm :language :parsing :speech] [56:29][Test macro argument shadowing][:asm :language :parsing] [57:18][:Run it to see that the arguments were not outputted in the reverse order][:asm :language :parsing] [59:10][Step in to next_token() to see what it does with our shadowed arguments][:asm :language :parsing :run] [1:05:12][Fix next_token() to call parse_macro_param() and evaluate the macro parameters before establishing the binding][:asm :language :parsing] [1:13:16][:Run it to see that it does the right thing][:asm :language :parsing] [1:13:46][Read back through next_token()][:asm :language :parsing :research] [1:14:26][Make next_token() set saved_local_syms after all the parse_macro_arg() calls][:asm :language :parsing] [1:15:13][:Run it to see that it's okay][:asm :language :parsing] [1:15:39][Q&A][:speech] [1:16:09][Consider the potential similarity of our assembler to lisp interpreters for symbolic languages][:asm :language :parsing :speech] [1:17:13][That's pretty much it for parameterized macros, with a glimpse into the future of doing expression evaluation][:asm :language :parsing :speech] [/video]