about summary refs log blame commit diff stats
path: root/046tangle.cc
blob: 2b650e3de0fc0828b80311349a80e89c2c26a794 (plain) (tree)
1
2
3
4
5
6
7
8
9





                                                                 
                            
         
                            


                
                            




































                                                                                                                
                                                             
                                                   











                                                                                                                        
                                                              
                                                       





                                   
                            
         
                            

                
                            

               
                            










                                        
                            

         
                            

                
                            

               
                            

                
                            

               
                            














                                                                                         
                            
         
                            

                
                            

               
                            

                
                            

               
                            














                                                                
                            
         
                            

                

                            

               

                            












                                                         
                            

         
                            

                
                            

               
                            










                             
//: Allow code for recipes to be pulled in from multiple places.
//:
//: TODO: switch recipe.steps to a more efficient data structure.

:(scenario tangle_before)
recipe main [
  1:number <- copy 0:literal
  +label1
  3:number <- copy 0:literal
]

before +label1 [
  2:number <- copy 0:literal
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
+mem: storing 0 in location 3
# nothing else
$mem: 3

//: while loading recipes, load before/after fragments

:(before "End Globals")
map<string /*label*/, recipe> Before_fragments, After_fragments;
:(before "End Setup")
Before_fragments.clear();
After_fragments.clear();

:(before "End Command Handlers")
else if (command == "before") {
  string label = next_word(in);
  recipe tmp = slurp_recipe(in);
  Before_fragments[label].steps.insert(Before_fragments[label].steps.end(), tmp.steps.begin(), tmp.steps.end());
}
else if (command == "after") {
  string label = next_word(in);
  recipe tmp = slurp_recipe(in);
  After_fragments[label].steps.insert(After_fragments[label].steps.begin(), tmp.steps.begin(), tmp.steps.end());
}

//: after all recipes are loaded, insert fragments at appropriate labels

:(after "int main")
  Transform.push_back(insert_fragments);

:(code)
void insert_fragments(const recipe_number r) {
  // Copy into a new vector because insertions invalidate iterators.
  // But this way we can't insert into labels created inside before/after.
  vector<instruction> result;
  for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) {
    const instruction inst = Recipe[r].steps.at(i);
    if (!inst.is_label) {
      result.push_back(inst);
      continue;
    }
    if (Before_fragments.find(inst.label) != Before_fragments.end()) {
      result.insert(result.end(), Before_fragments[inst.label].steps.begin(), Before_fragments[inst.label].steps.end());
    }
    result.push_back(inst);
    if (After_fragments.find(inst.label) != After_fragments.end()) {
      result.insert(result.end(), After_fragments[inst.label].steps.begin(), After_fragments[inst.label].steps.end());
    }
  }
//?   for (long long int i = 0; i < SIZE(result); ++i) { //? 1
//?     cout << result.at(i).to_string() << '\n'; //? 1
//?   } //? 1
  Recipe[r].steps.swap(result);
}

:(scenario tangle_before_and_after)
recipe main [
  1:number <- copy 0:literal
  +label1
  4:number <- copy 0:literal
]
before +label1 [
  2:number <- copy 0:literal
]
after +label1 [
  3:number <- copy 0:literal
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
# label1
+mem: storing 0 in location 3
+mem: storing 0 in location 4
# nothing else
$mem: 4

:(scenario tangle_keeps_labels_separate)
recipe main [
  1:number <- copy 0:literal
  +label1
  +label2
  6:number <- copy 0:literal
]
before +label1 [
  2:number <- copy 0:literal
]
after +label1 [
  3:number <- copy 0:literal
]
before +label2 [
  4:number <- copy 0:literal
]
after +label2 [
  5:number <- copy 0:literal
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
# label1
+mem: storing 0 in location 3
# 'after' fragments for earlier label always go before 'before' fragments for later label
+mem: storing 0 in location 4
# label2
+mem: storing 0 in location 5
+mem: storing 0 in location 6
# nothing else
$mem: 6

:(scenario tangle_stacks_multiple_fragments)
recipe main [
  1:number <- copy 0:literal
  +label1
  6:number <- copy 0:literal
]
before +label1 [
  2:number <- copy 0:literal
]
after +label1 [
  3:number <- copy 0:literal
]
before +label1 [
  4:number <- copy 0:literal
]
after +label1 [
  5:number <- copy 0:literal
]
+mem: storing 0 in location 1
# 'before' fragments stack in order
+mem: storing 0 in location 2
+mem: storing 0 in location 4
# label1
# 'after' fragments stack in reverse order
+mem: storing 0 in location 5
+mem: storing 0 in location 3
+mem: storing 0 in location 6
# nothing else
$mem: 6

:(scenario tangle_supports_fragments_with_multiple_instructions)
recipe main [
  1:number <- copy 0:literal
  +label1
  6:number <- copy 0:literal
]
before +label1 [
  2:number <- copy 0:literal
  3:number <- copy 0:literal
]
after +label1 [
  4:number <- copy 0:literal
  5:number <- copy 0:literal
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
+mem: storing 0 in location 3
# label1
+mem: storing 0 in location 4
+mem: storing 0 in location 5
+mem: storing 0 in location 6
# nothing else
$mem: 6

:(scenario tangle_tangles_into_all_labels_with_same_name)
recipe main [
  1:number <- copy 0:literal
  +label1
  +label1
  4:number <- copy 0:literal
]
before +label1 [
  2:number <- copy 0:literal
]
after +label1 [
  3:number <- copy 0:literal
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
# label1
+mem: storing 0 in location 3
+mem: storing 0 in location 2
# label1
+mem: storing 0 in location 3
+mem: storing 0 in location 4
# nothing else
$mem: 6
lt show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 118 611 2000 end classcanvas 128898 class_ref 149378 // FM draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 143 185 2000 end classcanvas 129154 class_ref 128002 // Displayable draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 325 408 2000 end classcanvas 129666 class_ref 135426 // Console draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 627 149 2006 end classcanvas 129922 class_ref 128130 // UI draw_all_relations default hide_attributes default hide_operations yes hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 366 235 2006 end classcanvas 130178 class_ref 128386 // DisplayableContainer draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 299 311 2012 end classcanvas 131458 class_ref 155906 // FileSystemObject draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 71 416 2000 end classcanvas 131842 class_ref 128258 // DefaultUI draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 325 129 2012 end classcanvas 132610 class_ref 156034 // Widget draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 509 237 2017 end classcanvas 133250 class_ref 135170 // FileList draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 549 392 2023 end classcanvas 133506 class_ref 135042 // TitleBar draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 646 391 2023 end classcanvas 136322 class_ref 162690 // os draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 54 566 2000 end packagecanvas 136578 package_ref 134530 // builtin xyzwh 29 522 2006 225 181 end note 137346 "\"outer world\"" xyzwh 123 566 2011 117 37 relationcanvas 129026 relation_ref 156162 // <generalisation> decenter_begin 466 from ref 128898 z 2001 to ref 128002 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 129538 relation_ref 162946 // <aggregation> from ref 128258 z 2001 to ref 128130 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 130306 relation_ref 128386 // <generalisation> decenter_begin 441 decenter_end 407 from ref 130178 z 2001 to ref 129154 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 130434 relation_ref 135938 // <aggregation> decenter_begin 603 decenter_end 631 from ref 130178 z 2001 to ref 129154 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 130562 relation_ref 128258 // <generalisation> from ref 129922 z 2007 to ref 130178 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 130946 relation_ref 169730 // <unidirectional association> from ref 128130 z 2001 to point 180 56 line 137218 z 2001 to ref 128002 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 131202 relation_ref 169986 // <association> decenter_begin 514 from ref 129154 z 2001 to ref 128770 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 131586 relation_ref 170242 // <aggregation> decenter_begin 351 from ref 128642 z 2001 to ref 131458 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 131714 relation_ref 170370 // <association> from ref 128642 z 2001 to ref 129154 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 131970 relation_ref 128002 // <generalisation> from ref 131842 z 2007 to ref 129922 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 132354 relation_ref 170498 // <association> decenter_begin 435 decenter_end 347 from ref 131842 z 2013 to ref 128258 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 132738 relation_ref 170754 // <generalisation> decenter_end 126 from ref 132610 z 2001 to point 493 430 line 137474 z 2001 to ref 129154 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 132866 relation_ref 170882 // <generalisation> from ref 129666 z 2007 to ref 132610 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 133378 relation_ref 171138 // <generalisation> from ref 133250 z 2018 to ref 132610 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 133634 relation_ref 171010 // <generalisation> from ref 133506 z 2018 to ref 132610 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 133762 relation_ref 177922 // <unidirectional association> decenter_end 569 from ref 128898 z 2001 to ref 128642 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 135170 relation_ref 178050 // <unidirectional association> from ref 128898 z 2013 to ref 131842 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 135298 relation_ref 178178 // <aggregation> decenter_begin 558 from ref 131842 z 2018 to point 523 169 line 136194 z 2018 to ref 132610 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 136450 relation_ref 184706 // <association> from ref 136322 z 2001 to ref 131458 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 136834 relation_ref 170626 // <association> from ref 129666 z 2007 to point 564 94 line 137090 z 2007 to ref 128258 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end end