Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added hw7 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ atomic units over the entire quarter. By *atomic* I mean, for example, that
- [HW #4][hw4-git], due Mon 11/07 by 23:59pm
- [HW #5][hw5-git], due Mon 11/14 by 23:59pm
- [HW #6][hw6-git], due Tue 11/29 by 23:59pm
- [HW #7][hw7-git], due Sun 12/04 by 23:59pm



Expand Down Expand Up @@ -52,4 +53,5 @@ atomic units over the entire quarter. By *atomic* I mean, for example, that
[hw4-git]: https://github.com/ucsd-cse131/04-diamondback
[hw5-git]: https://github.com/ucsd-cse131/05-egg-eater
[hw6-git]: https://github.com/ucsd-cse131/06-fer-de-lance
[hw7-git]: https://github.com/ucsd-cse131/07-garter

1 change: 1 addition & 0 deletions docs/assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ <h2 id="programming-assignments">Programming Assignments</h2>
<li><a href="https://github.com/ucsd-cse131/04-diamondback">HW #4</a>, due Mon 11/07 by 23:59pm</li>
<li><a href="https://github.com/ucsd-cse131/05-egg-eater">HW #5</a>, due Mon 11/14 by 23:59pm</li>
<li><a href="https://github.com/ucsd-cse131/06-fer-de-lance">HW #6</a>, due Tue 11/29 by 23:59pm</li>
<li><a href="https://github.com/ucsd-cse131/07-garter">HW #7</a>, due Sun 12/04 by 23:59pm</li>
</ul>
<!--

Expand Down
7 changes: 7 additions & 0 deletions docs/lectures.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ <h1>Lecture Notes</h1>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr class="odd">
<td align="center">11/29</td>
<td align="left">Static Types &amp; Inference</td>
<td align="center"><a href="lectures/09-garter.html">html</a> <a href="http://github.com/ucsd-progsys/131-web/blob/master/lectures/09-garter.md">md</a></td>
<td align="center"></td>
<td align="center"></td>
</tr>
</tbody>
</table>
<h2 id="discussions">Discussions</h2>
Expand Down
20 changes: 12 additions & 8 deletions docs/lectures/08-fer-de-lance.html
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,9 @@ <h3 id="transforms-compiler-app">Transforms: Compiler: <code>App</code></h3>
<span class="fu">++</span> assertArity env vE (length vXs) <span class="co">-- check vE arity</span>
<span class="fu">++</span> tupleReadRaw (immArg env vE) (repr (<span class="dv">1</span><span class="ot"> ::</span> <span class="dt">Int</span>)) <span class="co">-- load vE[1] into EAX</span>
<span class="fu">++</span> [<span class="dt">IPush</span> (param env vX) <span class="fu">|</span> vX <span class="ot">&lt;-</span> reverse vXs] <span class="co">-- push args</span>
<span class="fu">++</span> [<span class="dt">IPush</span> (param env vE)] <span class="co">-- push closure-ptr</span>
<span class="fu">++</span> [<span class="dt">ICall</span> (<span class="dt">Reg</span> <span class="dt">EAX</span>)] <span class="co">-- call EAX</span>
<span class="fu">++</span> [<span class="dt">IAdd</span> (<span class="dt">Reg</span> <span class="dt">ESP</span>) (<span class="dv">4</span> <span class="fu">*</span> n)] <span class="co">-- pop args</span></code></pre></div>
<span class="fu">++</span> [<span class="dt">IAdd</span> (<span class="dt">Reg</span> <span class="dt">ESP</span>) (<span class="dv">4</span> <span class="fu">*</span> (n <span class="fu">+</span> <span class="dv">1</span>)] <span class="co">-- pop args</span></code></pre></div>
<h2 id="a-problem-scope">A Problem: Scope</h2>
<p>Consider the following program:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">let</span> one <span class="fu">=</span> <span class="dv">1</span>
Expand Down Expand Up @@ -721,13 +722,16 @@ <h2 id="computing-free-variables">Computing Free Variables</h2>
freeVars e <span class="fu">=</span> S.toList (go e)
<span class="kw">where</span>
<span class="ot"> go ::</span> <span class="dt">Expr</span> <span class="ot">-&gt;</span> <span class="dt">S.Set</span> <span class="dt">Id</span>
go (<span class="dt">Id</span> x) <span class="fu">=</span> <span class="fu">?</span><span class="dv">1</span>
go (<span class="dt">Number</span> _) <span class="fu">=</span> <span class="fu">?</span><span class="dv">2</span>
go (<span class="dt">Boolean</span> _) <span class="fu">=</span> <span class="fu">?</span><span class="dv">2</span>
go (<span class="dt">If</span> e e1 e2) <span class="fu">=</span> <span class="fu">?</span><span class="dv">3</span>
go (<span class="dt">App</span> e es) <span class="fu">=</span> <span class="fu">?</span><span class="dv">4</span>
go (<span class="dt">Let</span> x e1 e2) <span class="fu">=</span> <span class="fu">?</span><span class="dv">5</span>
go (<span class="dt">Lam</span> xs e) <span class="fu">=</span> <span class="fu">?</span><span class="dv">6</span></code></pre></div>
go (<span class="dt">Id</span> x) <span class="fu">=</span> S.singleton x
go (<span class="dt">Number</span> _) <span class="fu">=</span> S.empty
go (<span class="dt">Boolean</span> _) <span class="fu">=</span> S.empty
go (<span class="dt">If</span> e e1 e2) <span class="fu">=</span> S.unions (map go [e1, e2, e3])
go (<span class="dt">App</span> e es) <span class="fu">=</span> S.unions (map go (e<span class="fu">:</span>es))
go (<span class="dt">Let</span> x e1 e2) <span class="fu">=</span> S.union (go e1) (S.delete x (go e2))
go (<span class="dt">Lam</span> xs e) <span class="fu">=</span> S.difference (go e) (S.fromList xs)<span class="fu">=</span></code></pre></div>
<p>lambda (x1,x2,x3): e</p>
<p>let x = y + 10 in x + z</p>
<p>A. {x} B. {} C. { gobble_gobble }</p>
<p><strong>TODO-IN-CLASS</strong></p>
<h2 id="free-variables-and-lambdas">Free Variables and Lambdas</h2>
<p><strong>Free Variables</strong> of a <code>lambda</code></p>
Expand Down
Loading