#assign directive seems to work, still prints a lot of debug info, more testing needed
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Tue, 13 May 2025 13:15:41 +0000 (06:15 -0700)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Tue, 13 May 2025 13:15:41 +0000 (06:15 -0700)
experimentđź–‰/#assign_directive.c# [new file with mode: 0644]
experimentđź–‰/assign_directive.c
script_gcc_min-12đź–‰/directives.cc
script_gcc_min-12đź–‰/macro.cc

diff --git a/experimentđź–‰/#assign_directive.c# b/experimentđź–‰/#assign_directive.c#
new file mode 100644 (file)
index 0000000..76e1eb4
--- /dev/null
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+#assign ()(Number)(0x2d9)
+
+#assign ()(NAME)(ONE)
+#assign ()[ NAME() ](1)
+
+#undef NAME
+#define NAME TwentySeven
+#assign ()[NAME](
+  Number / 27
+)
+
+int main(void){
+#if 1
+  printf("forty-two: %x\n" ,Number);
+  printf("ONE: %x\n" ,ONE);
+  printf("TwentySeven: %x\n" ,TwentySeven);
+#endif
+  printf("And thus begins the dance.\n");
+  return 0;
+}
index eb1e1d0..bb75d82 100644 (file)
@@ -1,13 +1,13 @@
 #include <stdio.h>
 
-#assign (Number)(0x2d9)
+#assign ()(Number)(0x2d9)
 
-#assign (NAME)(ONE)
-#assign [NAME]( 1 )
+#assign ()(NAME)(ONE)
+#assign ()[NAME]( 1 )
 
 #undef NAME
 #define NAME TwentySeven
-#assign [NAME](
+#assign ()[NAME](
   Number / 27
 )
 
index b94016d..26fea53 100644 (file)
@@ -2923,20 +2923,6 @@ void print_token_list(const cpp_token *tokens ,size_t count){
 /*--------------------------------------------------------------------------------
   RT extention, directive `#assign`
 
-    cmd        ::= "#assign" name body ;
-
-    name       ::= clause ;
-    body       ::= clause ;
-
-    clause     ::= "(" literal? ")" | "[" expr? "]" ;
-
-    literal    ::= ; sequence parsed into tokens
-    expr       ::= ; sequence parsed into tokens with recursive expansion of each token
-
-    ; white space, including new lines, is ignored.
-
-will be deprecate `#macro` and modify `#assign` like this:
-
     cmd        ::= "#assign" params name body ;
 
     params     ::= "(" param_list? ")" ;
@@ -2967,29 +2953,6 @@ static void do_assign(cpp_reader *pfile){
 
   _cpp_create_assign(pfile);
 
-#if 0
-
-
-  cpp_hashnode *node = lex_macro_node(pfile, true);
-
-  if(node)
-    {
-      /* If we have been requested to expand comments into macros,
-        then re-enable saving of comments.  */
-      pfile->state.save_comments =
-       ! CPP_OPTION (pfile, discard_comments_in_macro_exp);
-
-      if(pfile->cb.before_define)
-       pfile->cb.before_define (pfile);
-
-      if( _cpp_create_assign(pfile, node) )
-       if (pfile->cb.define)
-         pfile->cb.define (pfile, pfile->directive_line, node);
-
-      node->flags &= ~NODE_USED;
-    }
-#endif
-
 }
 
 
index 6b86e79..c80a523 100644 (file)
@@ -4611,9 +4611,9 @@ bool _cpp_create_assign(cpp_reader *pfile){
     unsigned int param_count;
     bool is_variadic;
 
-    if(!make_parameter_list(pfile ,&params ,&param_count ,&is_variadic)
+    if (!make_parameter_list(pfile, &params, &param_count, &is_variadic)) {
       return false;
-
+    }
 
   /* Parse name clause into a temporary macro. 
 
@@ -4625,8 +4625,8 @@ bool _cpp_create_assign(cpp_reader *pfile){
       ,_cpp_reserve_room( pfile, 0, sizeof(cpp_macro) ) 
     );
     name_macro->variadic = is_variadic;
-    name_macro->paramc = param_count;
     name_macro->parm.params = params;
+    name_macro->paramc = param_count;
     name_macro->fun_like = true;
 
     unsigned int num_extra_tokens = 0;
@@ -4735,6 +4735,11 @@ bool _cpp_create_assign(cpp_reader *pfile){
       ,body_macro->exp.tokens
       ,sizeof(cpp_token) * body_macro->count
     );
+    assign_macro->variadic = body_macro->variadic;
+    assign_macro->parm.params = body_macro->parm.params;
+    assign_macro->paramc = body_macro->paramc;
+    assign_macro->fun_like = true;
+
 
   /* Install the assign macro under name_node.
 
@@ -4764,6 +4769,7 @@ bool _cpp_create_assign(cpp_reader *pfile){
       ,NODE_NAME(name_node)
     );
   #endif
+
   return true;
 
 }
@@ -4771,3 +4777,12 @@ bool _cpp_create_assign(cpp_reader *pfile){
 
 
 
+
+
+
+
+
+
+
+
+