blob: f85e715e5141799fcb862fc6eb64056321db3773 (
plain) (
tree)
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 012transform.cc</title>
<meta name="Generator" content="Vim/7.3">
<meta name="plugin-version" content="vim7.3_v6">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css">
<style type="text/css">
<!--
pre { font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
.Identifier { color: #804000; }
.CommentedCode { color: #6c6c6c; }
.Constant { color: #00a0a0; }
.Normal { color: #eeeeee; background-color: #080808; }
.Delimiter { color: #a04060; }
.Comment { color: #9090ff; }
-->
</style>
</head>
<body>
<pre>
<span class="Comment">//: Phase 2: Filter loaded recipes through an extensible list of 'transforms'.</span>
<span class="Comment">//:</span>
<span class="Comment">//: The hope is that this framework of transform tools will provide a</span>
<span class="Comment">//: deconstructed alternative to conventional compilers.</span>
<span class="Comment">//:</span>
<span class="Comment">//: We're going to have many transforms in mu, and getting their order right</span>
<span class="Comment">//: (not the same as ordering of layers) is a well-known problem. Some tips:</span>
<span class="Comment">//: a) Design each layer to rely on as few previous layers as possible.</span>
<span class="Comment">//:</span>
<span class="Comment">//: b) When positioning transforms, try to find the tightest constraint in</span>
<span class="Comment">//: each transform relative to previous layers.</span>
<span class="Comment">//:</span>
<span class="Comment">//: c) Even so you'll periodically need to try adjusting each transform</span>
<span class="Comment">//: relative to those in previous layers to find a better arrangement.</span>
<span class="Delimiter">:(before "End recipe Fields")</span>
<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> transformed_until<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End recipe Constructor")</span>
transformed_until = -<span class="Constant">1</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Types")</span>
<span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>recipe_ordinal<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Globals")</span>
vector<transform_fn> Transform<span class="Delimiter">;</span>
<span class="Delimiter">:(after "int main")</span>
<span class="Comment">// Begin Transforms</span>
<span class="Comment">// Begin Instruction Inserting/Deleting Transforms</span>
<span class="Comment">// End Instruction Inserting/Deleting Transforms</span>
<span class="Comment">// Begin Instruction Modifying Transforms</span>
<span class="Comment">// End Instruction Modifying Transforms</span>
<span class="Comment">// End Transforms</span>
<span class="Comment">// Begin Checks</span>
<span class="Comment">// End Checks</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> transform_all<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9990</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"=== transform_all()"</span> << end<span class="Delimiter">();</span>
<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < SIZE<span class="Delimiter">(</span>Transform<span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cerr << "transform " << t << '\n';</span>
<span class="Normal">for</span> <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>transformed_until != t-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Comment">// End Transform Checks</span>
<span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span><span class="Comment">/*</span><span class="Comment">recipe_ordinal</span><span class="Comment">*/</span>p<span class="Delimiter">-></span>first<span class="Delimiter">);</span>
r<span class="Delimiter">.</span>transformed_until = t<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="CommentedCode">//? cerr << "wrapping up transform\n";</span>
parse_int_reagents<span class="Delimiter">();</span> <span class="Comment">// do this after all other transforms have run</span>
<span class="Comment">// End Transform All</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> parse_int_reagents<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"--- parsing any uninitialized reagents as integers"</span> << end<span class="Delimiter">();</span>
<span class="CommentedCode">//? cerr << "--- parsing any uninitialized reagents as integers" << '\n';</span>
<span class="Normal">for</span> <span class="Delimiter">(</span>map<recipe_ordinal<span class="Delimiter">,</span> recipe>::iterator p = Recipe<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Recipe<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
recipe& r = p<span class="Delimiter">-></span>second<span class="Delimiter">;</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>r<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span>
instruction& inst = r<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span>
<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
populate_value<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
populate_value<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> populate_value<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Comment">// End Reagent-parsing Exceptions</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>to_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Comment">// helper for tests -- temporarily suppress run</span>
<span class="Normal">void</span> transform<span class="Delimiter">(</span>string form<span class="Delimiter">)</span> <span class="Delimiter">{</span>
load<span class="Delimiter">(</span>form<span class="Delimiter">);</span>
transform_all<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
|