Barry Schwartz avatar Barry Schwartz committed 49234f4

Some rearrangement of code generation.

Comments (0)

Files changed (4)

examples/c3ga.xml

     dmv (mv slice_index::int components::matrix) =
         mv slice_index (dmatrix components);
 
-    <generate element="constant"/>
+    <generate key="constants"/>
 
     add_constdef $ [val ("d" + str c)--&gt;dmv (eval c) |
                     c = ['no,'e1,'e2,'e3,'ni,'I3,'I5,'I5i]];
 
-    <generate element="procedure"/>
+    <generate key="procedures"/>
 
     a::double ::* b::dmv        |
     a::dmv ::* b::dmv_or_double |

geomalg/markup_augment.pure

     my_root
   else
     (xml::set_node_attr (nodes!0) "mv" (str mv_value) $$
-     xml::set_node_attr (nodes!0) "pure-generator" pure_generator $$
      my_root
        when
          nodes = xml::select my_root (sprintf "constant[@name='%s']" name);
          multiblade_value = eval_multiblade_expr my_root (val blade_string);
          slices = get_mvslices_bitmap_groups my_root;
          mv_value = multiblade::mv_of_multiblade slices multiblade_value;
-         pure_generator = "::geomalg::markup::constant_pure_generator";
        end);
 
 augment_the_constants my_root =
   
 register_augmenter ('augment_the_constants);
 
-constant_pure_generator constant_node =
-  sprintf "const %s = %s;\n" (constant_name,
-                              __str__ (mv_symbol slice_index components))
-  when
-    _ slice_index components = val (xml::node_attr constant_node "mv");
-    constant_name = xml::node_attr constant_node "name";
-    opts = options "pure" [] constant_node;
-    mv_symbol = catch (cst ('::geomalg::symb::mv)) (val (opts!"mv-symbol"));
-  end;
-
 //-------------------------------------------------------------------------

geomalg/markup_generate.pure

 
 //-------------------------------------------------------------------------
 
-using markup, text_tree;
+using hashdict, markup, text_tree;
 
 namespace geomalg;
 namespace geomalg::markup;
 
 //-------------------------------------------------------------------------
 
-generate_element language::string element_type::string my_root =
-  text_tree::traverse_text_tree [generate n | n = stream nodes]
+let generators = hashdict [];
+
+register_generator ((lang::string, key::string)=>func) =
+  insert generators ((lang,key)=>func_name)
+  when func_name = if stringp func then func else str func end;
+
+deregister_generator (lang::string, key::string) =
+  delete generators (lang,key);
+deregister_generator ((lang::string, key::string)=>func) =
+  delete generators ((lang,key)=>func_name)
+  when func_name = if stringp func then func else str func end;
+
+//-------------------------------------------------------------------------
+
+pure_constants_generator my_root generate_node =
+  [sprintf "const %s = %s;\n" v | v = names_vals]
+  when
+    opts = options "pure" [] generate_node;
+    mv_symbol = catch (cst ('::geomalg::symb::mv)) (val (opts!"mv-symbol"));
+    constant_nodes = xml::select my_root "constant[@name][@mv]";
+    names_vals = [xml::node_attr n "name",
+                  __str__ (mv_symbol slice_index components)
+                  when
+                    _ slice_index components = val (xml::node_attr n "mv");
+                  end | n = constant_nodes];
+  end;
+
+register_generator (("pure","constants")=>pure_constants_generator);
+
+//-------------------------------------------------------------------------
+
+pure_procedures_generator my_root generate_node =
+  [generate n | n = procedure_nodes]
   with
-    generate node =
-      if stringp code then [code] else code
-      when
-        generator = val (xml::node_attr node generator_attr);
-        code = eval (generator node);
-      end;
+    generate n = func my_root generate_node n
+      when func = eval (xml::node_attr n "pure-generator") end;
   end
   when
-    generator_attr = language + "-generator";
-    nodes = xml::select my_root (sprintf "//%s[@%s]"
-                                 (element_type, generator_attr));
+    procedure_nodes = xml::select my_root "//procedure[@pure-generator]";
   end;
 
+register_generator (("pure","procedures")=>pure_procedures_generator);
+
 //-------------------------------------------------------------------------
 //
 // Templates.
 
-generate_generate_element my_root node =
-  generate_element language element_type my_root
+public generator_not_found;
+
+call_generator my_root generate_node =
+  if member opts "exclude" then
+    []
+  else
+    (eval generator) my_root generate_node
   when
-    language = search_toward_root (flip xml::node_attr "language") node;
-    element_type = xml::node_attr node "element";
+    lang = search_toward_root (flip xml::node_attr "language") generate_node;
+    opts = options lang [] generate_node;
+    key = xml::node_attr generate_node "key";
+    generator = catch (\_ -> throw (generator_not_found (lang,key))) (generators!(lang,key));
   end;
 
 generate_template_node my_root node =
       (case xml::node_info n of
          xml::text s = s;
          xml::element "generate" _ _ =
-           generate_generate_element my_root n
-           if stringp (xml::node_attr n "element");
+           call_generator my_root n
+           if stringp (xml::node_attr n "key");
          _ = [];
        end)
       when
         language = search_toward_root (flip xml::node_attr "language") node;
-        opts = options language [] n;
+        opts = options language [] node;
         fold = if member opts "fortran-fold" then
                  text_tree::text_tree_fortran_fold 132
                else

geomalg/operation_product.pure

     opts = markup::options "pure" [] procedure_node;
   end;
 
-mv_product_pure_generator procedure_node =
+mv_product_pure_generator _my_root _generate_node procedure_node =
   // FIXME: Perhaps come up with a better way to pretty-print the left
   // side of a rule, or the rule as a whole.
   [[foldl1 (\s t -> s + "::" + t) (split "__type__" (__str__ left)),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.