download 2021 site
This commit is contained in:
commit
dd6e4afb13
138 changed files with 37730 additions and 0 deletions
414
lab/0.html
Normal file
414
lab/0.html
Normal file
|
|
@ -0,0 +1,414 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Rules for the Course Project</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
<a class="text-dark" href="https://weblab.tudelft.nl/cs4200/2021-2022/rules">
|
||||
Rules for the Course Project
|
||||
</a>
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
<a class="text-primary" href="https://weblab.tudelft.nl/cs4200/2021-2022/rules">
|
||||
Project Rules
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 01, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<h2 id="submission">Submission</h2>
|
||||
|
||||
<p>We rely on GitLab for project assignment submissions. We assign a private GitLab repository to each student and encourage students to commit and push their work frequently.</p>
|
||||
|
||||
<ul>
|
||||
<li>To submit your assignment, you need to file a merge request. There are two kinds of submissions.</li>
|
||||
<li>To check your progress on an assignment, you can submit a <em>preliminary solution</em>. We will provide limited feedback on preliminary solutions. This feedback typically comes with a tentative grade and points out areas where your solution is incomplete or insufficient, without giving any details on the reasons.</li>
|
||||
<li>To submit your solution for grading, you need to submit a <em>final solution</em>. As the name suggests, you cannot submit another final solution for the same assignment.
|
||||
We will provide a detailed grading report on final solutions. To ensure fairness and equal chances for all students, grading reports will not be published before 2 days after the submission deadline. We do our best to hand out grading reports as quick as possible, but manual grading can be tedious and might result in longer waiting times for some assignments.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="grades">Grades</h2>
|
||||
|
||||
<p>We grade the first final solution of each of your assignments. Grades reflect on correctness, clarity, shown programming skills, and readability of your submission. To pass the practical part of the course, you need to meet all of the following criteria:</p>
|
||||
|
||||
<ol>
|
||||
<li>You completed each assignment with a grade of 4.0 or better.</li>
|
||||
<li>You completed the assignments of each milestone with an average grade of 5.0 or better.</li>
|
||||
<li>You completed all the assignments with an average grade of 6.0 better.</li>
|
||||
</ol>
|
||||
|
||||
<p>These rules allow you to compensate for lower grades in single assignments, but ensure a minimal quality in all your milestones as well as in your overall practical work.</p>
|
||||
|
||||
<h2 id="deadlines">Deadlines</h2>
|
||||
|
||||
<p>Assignments must be submitted by the published deadline. You get a standard deadline extension of 48 hours with a penalty of 2 grade points computed proportionally to the amount of extra time you use.</p>
|
||||
|
||||
<p>If you think you cannot meet deadlines due to special personal circumstances, you should contact the academic counsellor. Together we will try to find an individual solution for you. Remember to contact the academic counsellor as soon as possible, once you become aware of your situation. Otherwise, you might lose your chance for a deadline extension.</p>
|
||||
|
||||
<h2 id="academic-misconduct">Academic Misconduct</h2>
|
||||
|
||||
<ul>
|
||||
<li>All actual, detailed work on assignments must be <strong>individual work</strong>.</li>
|
||||
<li>You are encouraged to discuss assignments, programming languages used to solve the assignments, their libraries, and general solution techniques in these languages with each other. If you do so, then you must <strong>acknowledge</strong> the people with whom you discussed at the top of your submission.</li>
|
||||
<li>You should not look for assignment solutions elsewhere; but if material is taken from elsewhere, then you must <strong>acknowledge</strong> its source.</li>
|
||||
<li>You are not permitted to provide or receive any kind of solutions of assignments. This includes partial, incomplete, or erroneous solutions.</li>
|
||||
<li>You are also not permitted to provide or receive programming help from people other than the teaching assistants, PhD students associated with this course, or the course manager.</li>
|
||||
</ul>
|
||||
|
||||
<p>Any violation of these rules will be reported as a suspected case of fraud to the Board of Examiners and handled according to the EEMCS Faculty’s fraud procedure. If the case is proven, a penalty will be imposed: a minimum of exclusion from the course for the duration of one academic year up to a maximum of a one-year exclusion form all courses at TU Delft. For details on the procedure, see Section 2.1.26 in the faculty’s Study Guide for MSc Programmes.</p>
|
||||
|
||||
<h2 id="retry">Retry</h2>
|
||||
|
||||
<p>To ensure fairness and equal chances for all students, you are not allowed to take the same practical assignments in another edition of this course. In case you participated in previous editions of the course, please contact the course manager to discuss an individual assignment.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0a.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="0.html#submission">Submission</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="0.html#grades">Grades</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="0.html#deadlines">Deadlines</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="0.html#academic-misconduct">Academic Misconduct</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="0.html#retry">Retry</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0a.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
1020
lab/0a.html
Normal file
1020
lab/0a.html
Normal file
File diff suppressed because it is too large
Load diff
379
lab/0b.html
Normal file
379
lab/0b.html
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 0(b): Registering Your Project</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
<a href="https://tudelft-cs4200.github.io/2021">
|
||||
<img class="border border-dark" width="100%" src="../project/2021/00-lab0b/netid.png"/>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
<a class="text-dark" href="https://weblab.tudelft.nl/cs4200/2021-2022/assignment/87898/view">
|
||||
Lab 0(b): Registering Your Project
|
||||
</a>
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
<a class="text-primary" href="https://weblab.tudelft.nl/cs4200/2021-2022/assignment/87898/view">
|
||||
WebLab
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 03, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>We use the Git version control system with https://gitlab.ewi.tudelft.nl to manage submissions and grade assignments. You can access EWI GitLab with you NetID.</p>
|
||||
|
||||
<p>To setup your individual repository, we need to know your NetID. Please provide it in your answer to <a href="https://weblab.tudelft.nl/cs4200/2021-2022/assignment/87898/view">this question</a> on WebLab. If your GitLab username is different than your NetID, provide it in your answer too.</p>
|
||||
|
||||
<p>If you are in doubt about your answer, check the model answer by clicking the A button in the top right corner.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0a.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1a.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0a.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1a.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
503
lab/10.html
Normal file
503
lab/10.html
Normal file
|
|
@ -0,0 +1,503 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 10: Instruction Selection</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 10: Instruction Selection
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
November 26, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>See the slides of <a href="../lecture/12.html">Lecture 12</a> on code generation for an approach to get started.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<p>Develop tests for your compiler that explore the edge cases.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Define a transformation strategy that translates ChocoPy expressions to RISC-V code, including variable definitions, integer and boolean constants and operators.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Develop a simplification transformation that transforms expressions such that more concise code can be generated.</p>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="basic-compiler-pipeline">Basic Compiler Pipeline</h3>
|
||||
|
||||
<p>Follow the slides of <a href="../lecture/12.html">Lecture 12</a> to set up a basic compiler pipeline:</p>
|
||||
|
||||
<pre><code class="language-stratego:"> compile-to-rv32im-ast :: Program -> RProgram
|
||||
|
||||
compile-to-rv32im-ast =
|
||||
compile-cpy-to-cir
|
||||
; compile-cir-to-rv32im
|
||||
; compile-rv32im
|
||||
|
||||
</code></pre>
|
||||
|
||||
<h4 id="debugging">Debugging</h4>
|
||||
|
||||
<p>Use <code class="language-plaintext highlighter-rouge">debug(!msg)</code> or <code class="language-plaintext highlighter-rouge">dbg(|msg)</code> to print the current term to the console.</p>
|
||||
|
||||
<p>You can also debug your generated code, by creating a <code class="language-plaintext highlighter-rouge">.cpy</code> file, transforming it to an <code class="language-plaintext highlighter-rouge">.rv32im</code> file using the <code class="language-plaintext highlighter-rouge">Spoofax > Generation</code> menu, and copying the generated output to the online Venus editor, where you can use the <code class="language-plaintext highlighter-rouge">Simulator</code> tab to run your code or step through each line, and inspect the memory and registers.</p>
|
||||
|
||||
<h3 id="from-chocopy-to-c-ir">From ChocoPy to C-IR</h3>
|
||||
|
||||
<p>Develop a first compilation phase to transform ChocoPy programs to an intermediate language that makes control flow explicit.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> compile-cpy-to-cir :: Program -> CProgram
|
||||
|
||||
compile-cpy-to-cir =
|
||||
explicate-types
|
||||
; desugar
|
||||
; uniquify
|
||||
; remove-complex-operands
|
||||
; explicate-control
|
||||
</code></pre></div></div>
|
||||
|
||||
<h4 id="explicate-types">Explicate Types</h4>
|
||||
|
||||
<p>A useful transformation is to type specialize the constructors of the AST, such that the analysis results are no longer needed.
|
||||
That is useful when applying transformations, since preserving those annotations cannot be done for all transformations.
|
||||
<strong>The following <code class="language-plaintext highlighter-rouge">explicate-types</code> transformation should be invoked on the AST before invoking the compiler transformation.</strong></p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>signature
|
||||
constructors
|
||||
AddInt : Exp * Exp -> Exp
|
||||
|
||||
rules
|
||||
|
||||
explicate-types =
|
||||
innermost(type-specialize)
|
||||
|
||||
type-specialize :
|
||||
add@Add(e1, e2) -> AddInt(e1, e2)
|
||||
where <get-type> add => Int()
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Note that the rules for translating integer additions should be adapted to reflect the change in constructors.</p>
|
||||
|
||||
<h4 id="desugar">Desugar</h4>
|
||||
|
||||
<p>To improve the result of code generation, it can be useful to transform the source language expression.
|
||||
For example, left-associative additions may produce a better result.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> desugar-exp :
|
||||
AddInt(e1, AddInt(e2, e3)) -> AddInt(AddInt(e1, e2), e3)
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Define a transformation to <code class="language-plaintext highlighter-rouge">desugar</code> ChocoPy programs, making the task of downstream compilation easier.</p>
|
||||
|
||||
<p>This simplification can include constant folding, eventually.
|
||||
However, do not yet include constant folding rules, since you want to test the translation of operators.
|
||||
That is, your code generator should be able to translate arbitrary combinations of operators, so be prepared for the general case.</p>
|
||||
|
||||
<p>Think about (and try out in the online compiler!) the differences between adding integers and concatenating strings in RISC-V. In ChocoPy, they initially both use the <code class="language-plaintext highlighter-rouge">Add(...)</code> constructor, so make sure to disambiguate them into separate constructors you will later use for code generation. The same holds for other operations, but you have to think about those yourself.</p>
|
||||
|
||||
<h4 id="uniquify">Uniquify</h4>
|
||||
|
||||
<p>Define a transformation that eliminates shadowing. (See slides)</p>
|
||||
|
||||
<h4 id="remove-complex-operands">Remove Complex Operands</h4>
|
||||
|
||||
<p>To simplify instruction selection, simplify expressions to only use atomic expressions (constants or variables) creating new variables to store intermediate results.</p>
|
||||
|
||||
<h4 id="explicate-control-using-c-ir">Explicate Control using C-IR</h4>
|
||||
|
||||
<p>Use an intermediate language to explicate control.
|
||||
That is, the <code class="language-plaintext highlighter-rouge">explicate-control</code> strategy translates from ChocoPy ASTs</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>signature
|
||||
sorts CID CINT CProgram CBlock CLabel CTail CStmt
|
||||
CType CExp CAtom CVar
|
||||
constructors
|
||||
: string -> CID
|
||||
: string -> CINT
|
||||
CProgram : List(CBlock) -> CProgram
|
||||
CBlock : CLabel * CTail -> CBlock
|
||||
CLabel : CID -> CLabel
|
||||
CReturn : CExp -> CTail
|
||||
CReturnNone : CTail
|
||||
CSeq : CStmt * CTail -> CTail
|
||||
CVarDec : CVar * CType * CExp -> CStmt
|
||||
CAssign : CVar * CExp -> CStmt
|
||||
CIntT : CType
|
||||
: CAtom -> CExp
|
||||
CMin : CAtom -> CExp
|
||||
CAdd : CAtom * CAtom -> CExp
|
||||
CMul : CAtom * CAtom -> CExp
|
||||
CDiv : CAtom * CAtom -> CExp
|
||||
CInt : CINT -> CAtom
|
||||
: CVar -> CAtom
|
||||
CVar : CID -> CVar
|
||||
</code></pre></div></div>
|
||||
|
||||
<h3 id="instruction-selection">Instruction Selection</h3>
|
||||
|
||||
<p>Define a transformation from C-IR to RISC-V instructions:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> compile-cir-to-rv32im :: CProgram -> RProgram
|
||||
|
||||
compile-cir-to-rv32im =
|
||||
select-instructions-cprogram
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>The essence of this translation consists of instruction selection, i.e. mapping the high-level instructions of the intermediate language to concrete RISC-V instructions.
|
||||
For example, register allocation for integer constants, variables, and addition may be defined as follows:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> select-instrs-exp(|RArg) :: CExp -> List(RLine)
|
||||
|
||||
select-instrs-exp(|x) :
|
||||
CInt(i) -> [RLi(x, <cint-to-rint>i)]
|
||||
|
||||
select-instrs-exp(|x) :
|
||||
CVar(y) -> [RMv(x, RVar(<cid-to-string>y))]
|
||||
|
||||
select-instrs-exp(|x) :
|
||||
CAdd(y@CVar(_), z@CVar(_)) -> [RAdd(x, <cvar-to-rvar>y, <cvar-to-rvar>z)]
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Note that because expressions have been transformed to applications of operators to atomic expressions, this step does not need to invent names for intermediate results.
|
||||
We use <code class="language-plaintext highlighter-rouge">RVar(x)</code> as symbolic registers in RISC-V code in order to postpone the mapping to concrete registers.</p>
|
||||
|
||||
<p>Define transformation rules for all operators of ChocoPy expressions.</p>
|
||||
|
||||
<h4 id="special-cases">Special Cases</h4>
|
||||
|
||||
<p>RISC-V provides specialized instructions for some operations.
|
||||
For example, the <code class="language-plaintext highlighter-rouge">addi</code> instruction allows directly adding an integer constant (between -2048 and 2047) to a register.
|
||||
A compiler can make use of such instructions, by detecting special patterns in the source language.
|
||||
For example, the following rule, detects additions with an integer constant, and translates those to applications of <code class="language-plaintext highlighter-rouge">addi</code>, avoiding the use of an extra register.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>select-instrs-exp(|x) :
|
||||
CAdd(z@CVar(_), CInt(i)) -> [RAddi(x, <cvar-to-rvar>z, <cint-to-rint>i)]
|
||||
with debug(!"select-instrs-exp: ")
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Can you detect other specialized instructions and corresponding source language patterns that provide a more concise and/or faster target code?</p>
|
||||
|
||||
<h4 id="booleans">Booleans</h4>
|
||||
|
||||
<p>In ChocoPy we compile the Booleans <code class="language-plaintext highlighter-rouge">True</code> and <code class="language-plaintext highlighter-rouge">False</code> to integers in RISC-V (<code class="language-plaintext highlighter-rouge">1</code> and <code class="language-plaintext highlighter-rouge">0</code>, respectively).
|
||||
Implement the Boolean operators <code class="language-plaintext highlighter-rouge">and</code>, <code class="language-plaintext highlighter-rouge">or</code> and <code class="language-plaintext highlighter-rouge">not</code>, and integer comparison operators <code class="language-plaintext highlighter-rouge">==</code>, <code class="language-plaintext highlighter-rouge">!=</code>, <code class="language-plaintext highlighter-rouge"><</code>, <code class="language-plaintext highlighter-rouge">></code>, <code class="language-plaintext highlighter-rouge"><=</code>, <code class="language-plaintext highlighter-rouge">>=</code> (you can ignore <code class="language-plaintext highlighter-rouge">is</code> for now since it operates on objects).</p>
|
||||
|
||||
<p>You can make use of the online compiler, or the RISC-V instruction set to find the proper instructions in RISC-V.</p>
|
||||
|
||||
<!-- Also implement the ternary operator `... if ... else ...`. (See [Short-circuit Boolean operations](#shortcircuit) to get an idea on how to implement it.) -->
|
||||
|
||||
<h3 id="patching-risc-v-instructions">Patching RISC-V instructions</h3>
|
||||
|
||||
<p>Finally, we define a compiler stage that patches up the RISC-V code:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> compile-rv32im :: RProgram -> RProgram
|
||||
|
||||
compile-rv32im =
|
||||
assign-homes
|
||||
; patch-instructions
|
||||
</code></pre></div></div>
|
||||
|
||||
<h4 id="assign-homes">Assign Homes</h4>
|
||||
|
||||
<p>Map symbolic registers to concrete registers.
|
||||
Either by mapping variables to actual registers or by using a stack discipline.
|
||||
We will look at register allocation next, so keep it simple.</p>
|
||||
|
||||
<h4 id="patch-instructions">Patch Instructions</h4>
|
||||
|
||||
<p>This is the place for any mopping up that needs to be done.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="9.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="11.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#objectives">Objectives</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#basic-compiler-pipeline">Basic Compiler Pipeline</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#debugging">Debugging</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#from-chocopy-to-c-ir">From ChocoPy to C-IR</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#explicate-types">Explicate Types</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#desugar">Desugar</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#uniquify">Uniquify</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#remove-complex-operands">Remove Complex Operands</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#explicate-control-using-c-ir">Explicate Control using C-IR</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#instruction-selection">Instruction Selection</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#special-cases">Special Cases</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#booleans">Booleans</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#patching-risc-v-instructions">Patching RISC-V instructions</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#assign-homes">Assign Homes</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#patch-instructions">Patch Instructions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="9.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="11.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
644
lab/11.html
Normal file
644
lab/11.html
Normal file
|
|
@ -0,0 +1,644 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 11: Implementing Register Allocation and Control Flow</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 11: Implementing Register Allocation and Control Flow
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
December 03, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<h2 id="register-allocation">Register Allocation</h2>
|
||||
|
||||
<p>In this lab you implement register allocation taking the implementation from the slides as basis.</p>
|
||||
|
||||
<h3 id="liveness-analysis">Liveness Analysis</h3>
|
||||
|
||||
<p>Implement liveness analysis to determine when (at what instructions) variables are live.
|
||||
Extend the analysis to deal with control flow and loops.
|
||||
This requires a fixed point analysis.</p>
|
||||
|
||||
<h3 id="graph-coloring">Graph Coloring</h3>
|
||||
|
||||
<p>Next implement register allocation bases on the outcome of the liveness analysis.
|
||||
Use the priority queue data structure to represent the interference graph with the nodes representing variables with the most inference listed first.
|
||||
Coloring the graph with a limited number of registers.
|
||||
How do you treat spilling variables to memory?</p>
|
||||
|
||||
<h2 id="control-flow">Control Flow</h2>
|
||||
|
||||
<p>Extend the fragment of the language that is supported by your compiler with control-flow constructs such as if-then-else and booleans.</p>
|
||||
|
||||
<h3 id="desugaring">Desugaring</h3>
|
||||
|
||||
<p>Define desugaring rules to reduce the number of constructs that the downstream compiler has to deal with.
|
||||
Consider whether or for which language constructs this is worthwhile; the target machine may have instructions that correspond directly to the source language operators.</p>
|
||||
|
||||
<h3 id="explicating-control-translation-to-c-ir">Explicating Control: Translation to C-IR</h3>
|
||||
|
||||
<p>Translate the recursive expressions for control flow in ChocoPy to jumps in the control flow graph.</p>
|
||||
|
||||
<h3 id="instruction-selection">Instruction Selection</h3>
|
||||
|
||||
<p>Translate to RISC-V instructions.</p>
|
||||
|
||||
<!-- In this lab you extend your ChocoPy code generator with translation of function definitions and function calls.
|
||||
|
||||
See the slides of [Lecture 13](/2021/lecture/13) on code generation mechanics and the [ChocoPy v2.2: RISC-V Implementation Guide](https://chocopy.org/chocopy_implementation_guide.pdf) for an explanation of the calling convention for ChocoPy.
|
||||
|
||||
### Objectives
|
||||
|
||||
1. Compiling functions
|
||||
- Compiling function definitions according to calling convention
|
||||
- Compiling variables referring to formal parameters and local variables
|
||||
- Generate code for function calls according to calling convention
|
||||
- Define a transformation that lifts nested function calls to top-level assignment statements.
|
||||
2. Integrate the execution environment
|
||||
3. Challenges
|
||||
- Optimize generated code
|
||||
- Alternative calling conventions
|
||||
|
||||
### Context-Sensitive Transformation
|
||||
|
||||
In the previous lab you used rewrite rules to transform source ASTs to target ASTs.
|
||||
The transformations were context-free. That is, an addition operation can be translated without any information about the context in which it appears.
|
||||
This is not the case for transformations in a compiler.
|
||||
For example, compiling a variable in an expression requires knowing where it is stored on the stack, i.e. its offset from the frame pointer.
|
||||
|
||||
The slides of [Lecture 13](/2021/lecture/13) introduce the use of dynamic rewrite rules in Stratego to implement such context-sensitive transformations. See the paper by Bravenboer et al. (2006) referenced on the lecture page for an overview, including applications of dynamic rules.
|
||||
We discuss some examples here that may be useful for your compiler.
|
||||
|
||||
#### Dynamic Rewrite Rules
|
||||
|
||||
A dynamic rewrite rule in Stratego is like a normal rewrite rule, but it is generated at run-time (dynamically) and some of its variables are bound in the context of its definition.
|
||||
For example, consider the following definition of a constant propagation transformation strategy that propagates assignments of constants to variables to uses of those variables (in straight-line code):
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
prop-const =
|
||||
PropConst
|
||||
<+ prop-const-assign
|
||||
<+ (all(prop-const); try(eval))
|
||||
|
||||
prop-const-assign =
|
||||
Assign([Target(?x)], prop-const => e)
|
||||
; if <is-value> e
|
||||
then rules( PropConst : Var(x) -> e )
|
||||
else rules( PropConst :- Var(x) )
|
||||
end
|
||||
|
||||
eval : Add(Int(i), Int(j)) -> Int(<addS>(i, j))
|
||||
|
||||
is-value = ?Int(_)
|
||||
```
|
||||
|
||||
The construct `rules( PropConst : Var(x) -> e )` generates a new dynamic rule for the specific values of `x` and `e` found in the context.
|
||||
Thus, if `PropConst` is later applied to a concrete variable for which a rule has been defined, it is replaced with the corresponding right-hand side.
|
||||
If a different rule had been defined previously for `Var(x)`, the new rule overwrites the old one.
|
||||
|
||||
The construct `rules( PropConst :- Var(x) )` undefines all dynamic `PropConst` rules for `Var(x)`.
|
||||
|
||||
We discuss some examples of applications of dynamic rules that can be useful in your compiler.
|
||||
|
||||
#### Keeping Track of the Stack
|
||||
|
||||
Dynamic rules can be used to implement a counter. For example, the following rules keep track of stack offsets:
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
stack-set(|n) =
|
||||
rules(Stack : () -> n); !n
|
||||
|
||||
stack-get =
|
||||
<Stack>() <+ !0
|
||||
|
||||
stack-inc(|n) =
|
||||
stack-set(|<add>(<stack-get>, n))
|
||||
```
|
||||
|
||||
Dynamic rules can be scoped using the construct `{| L : s}`, where `L` is the label of the dynamic rule. For example, the stack rules above can be used in a transformation to generate subsequent stack offset and at end retrieve the total offset needed:
|
||||
|
||||
```
|
||||
{| Stack
|
||||
: stack-set(|0)
|
||||
; <some-transformation> t => instrs
|
||||
; size := <stack-get>
|
||||
|}
|
||||
```
|
||||
|
||||
After leaving the scope, all definitions for `Stack` in the scope are eliminated and the value before the scope is available again. For example,
|
||||
the code
|
||||
|
||||
```
|
||||
stack-set(|10)
|
||||
; debug(!"stack: ")
|
||||
; {| Stack
|
||||
: stack-set(|20)
|
||||
; debug(!"stack: ")
|
||||
|}
|
||||
; stack-get
|
||||
; debug(!"stack: ")
|
||||
```
|
||||
|
||||
will print
|
||||
|
||||
```
|
||||
stack: 10
|
||||
stack: 20
|
||||
stack: 10
|
||||
```
|
||||
|
||||
#### Binding Variable Offsets
|
||||
|
||||
Another application of dynamic rules is to distribute contex-sensitive information about bindings. For example, the following rules bind an offset with respect to the framepointer to a variable name:
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
var-offset-set(|x, n) =
|
||||
rules(VarOffset : x -> n)
|
||||
|
||||
var-offset-get :
|
||||
x -> n
|
||||
with <VarOffset> x => n
|
||||
```
|
||||
|
||||
This can be used in handling the formal parameters of a function to associate with parameter the next offset in the stack:
|
||||
|
||||
```
|
||||
rules
|
||||
fun-arg :
|
||||
TypedVar(x, t) -> offset
|
||||
with var-offset-set(|x, <stack-get => offset>)
|
||||
with stack-inc(|4)
|
||||
```
|
||||
|
||||
Then, when translating a variable, the dynamic rule can be used to lookup its offset:
|
||||
|
||||
```
|
||||
rules
|
||||
exp-to-instrs-(|r, regs) :
|
||||
Var(x) -> [Lw(r, <int-to-string>offset, "fp")]
|
||||
with <var-offset-get>x => offset
|
||||
``` -->
|
||||
|
||||
<!-- #### Collecting Information
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
transform :
|
||||
Foo(x, y) -> Bar(x)
|
||||
where rules( Collect :+ )
|
||||
|
||||
``` -->
|
||||
|
||||
<!--
|
||||
### Compiling Functions
|
||||
|
||||
The main objective of this lab is to implement the compilation of function definitions and function calls.
|
||||
We illustrate the process with the following example ChocoPy program:
|
||||
|
||||
```
|
||||
def callee(x : int, y : int, z: int) -> int:
|
||||
a : int = 1
|
||||
b : int = 2
|
||||
return x + y + z + a + b
|
||||
|
||||
def caller():
|
||||
d : int = 0
|
||||
d = callee(345, 4357, 235)
|
||||
```
|
||||
|
||||
#### Compiling Function Definitions
|
||||
|
||||
Compiling a function definition consists of generating code for setting up and breaking down an activation record (aka call frame).
|
||||
This process follows a calling convention such that caller and callee agree about how to pass arguments to and return results from function calls.
|
||||
The process starts with advancing the stack pointer register `sp` so that the call frame has enough space for the local variables and tempories in the call.
|
||||
Then, the return address (`ra`) and frame pointer (`fp`) registers are saved in the call frame so that they are not overwritten on subsequent calls.
|
||||
Next, the local variables are initialized.
|
||||
This is followed by the computation of the body of the function, leaving the return value in the `a0` register.
|
||||
Finally, the return address and frame pointer registers are restored, and the function jumps to the return address.
|
||||
|
||||
The function `callee` above is translated as follows:
|
||||
|
||||
```
|
||||
.globl $callee
|
||||
$callee:
|
||||
addi sp, sp, -@callee.size # reserve space for stack frame
|
||||
sw ra, @callee.size-4(sp) # save return address
|
||||
sw fp, @callee.size-8(sp) # save control link (fp)
|
||||
sw fp, @callee.size(sp) # new fp is at old SP
|
||||
li a0, 1 # initialize local variable a
|
||||
sw a0, -16(fp)
|
||||
li a0, 2 # initialize local variable b
|
||||
sw a0, -12(fp)
|
||||
lw a0, 8(fp) # load argument x
|
||||
lw t0, 4(fp) # load argument y
|
||||
add a0, a0, t0 # x + y
|
||||
lw t0, 0(fp) # load argument z
|
||||
add a0, a0, t0 # (x + y) + z
|
||||
lw t0, -16(fp) # load local variable a
|
||||
add a0, a0, t0 # (x + y + z) + a
|
||||
lw t0, -12(fp) # load local variable b
|
||||
add a0, a0, t0 # (x + y + z + a) + b
|
||||
j label_47
|
||||
mv a0, zero
|
||||
j label_47
|
||||
label_47:
|
||||
.equiv @callee.size, 16
|
||||
lw ra, -4(fp) # restore return address
|
||||
lw fp, -8(fp) # restore frame pointer
|
||||
addi sp, sp, @callee.size # restore stack pointer
|
||||
jr ra # return to caller
|
||||
```
|
||||
|
||||
In this translation you should compute the size of the stack frame needed to hold all local variables, temporaries, return address, and frame pointer
|
||||
|
||||
#### Compiling Variables
|
||||
|
||||
To compile variables bind the stack offsets of formal parameters and local variables and transfer these offsets from definition site to use site. (See the discussion about dynamic rewrite rules above.)
|
||||
Given these offsets using a variable and updating a variable is a matter of loading the variable from the stack into a register (see the `lw` instructions in the code above), and storing the value a register into the stack (see the `sw` instructions in the code above).
|
||||
|
||||
#### Compiling Function Calls
|
||||
|
||||
Executing a function call requires computing the values of the actual parameters and transferring these to the code of the function following the calling convention.
|
||||
The default ChocoPy calling convention is to pass arguments on the stack _in the same order as the function expects them_.
|
||||
|
||||
For example, the following ChocoPy function call
|
||||
|
||||
```
|
||||
def caller():
|
||||
d : int = 0
|
||||
d = callee(345, 4357, 235)
|
||||
```
|
||||
|
||||
is translated to the following RISC-V code:
|
||||
|
||||
```
|
||||
.globl $caller
|
||||
$caller:
|
||||
addi sp, sp, -@caller.size
|
||||
sw ra, @caller.size-4(sp)
|
||||
sw fp, @caller.size-8(sp)
|
||||
sw fp, @caller.size(sp)
|
||||
li a0, 0 # initialize local variable d
|
||||
sw a0, -12(fp)
|
||||
sw sp, -12(sp) # reserve space for arguments
|
||||
li a0, 345 # evaluate first argument
|
||||
sw a0, 12(sp) # push on stack
|
||||
li a0, 4357 # evaluate second argument
|
||||
sw a0, 8(sp) # push on stack
|
||||
li a0, 235 # evaluate third argument
|
||||
sw a0, 4(sp) # push on stack
|
||||
jal $callee # call function
|
||||
sw sp, 12(sp) # clean up stack
|
||||
sw a0, -12(fp) # return value in a0
|
||||
j label_48
|
||||
mv a0, zero
|
||||
j label_48
|
||||
label_48:
|
||||
.equiv @caller.size, 12
|
||||
lw ra, -4(fp)
|
||||
lw fp, -8(fp)
|
||||
addi sp, sp, @caller.size
|
||||
jr ra
|
||||
```
|
||||
|
||||
#### Lifting Nested Function Calls
|
||||
|
||||
When using registers to store the intermediate values of an expression, a function call in the middle of such an expression may overwrite such registers.
|
||||
One approach for avoiding this is to lift function calls to the top-level statements in the context.
|
||||
For example, the nested call to `inc` in the following function
|
||||
|
||||
```
|
||||
def caller():
|
||||
d : int = 0
|
||||
d = callee(345 + 81 + inc(13), 4357, 235)
|
||||
```
|
||||
|
||||
can be lifted to top-level using an extra local variable:
|
||||
|
||||
```
|
||||
def caller( ) :
|
||||
d : int = 0
|
||||
temp_2 : int = 0
|
||||
temp_2 = inc(13)
|
||||
d = callee(345 + 81 + temp_2, 4357, 235)
|
||||
```
|
||||
|
||||
Define a transformation that lifts nested functions to top-level.
|
||||
You can use `<newname> "temp_"` to generate a unique new name.
|
||||
|
||||
#### Execution Environment
|
||||
|
||||
The ChocoPy language includes an execution envionrment consisting of a suite of standard functions such as `print`.
|
||||
We provide implementations of these functions as a set of Stratego strategies in the project template.
|
||||
Integrate this execution environment in the code your compiler generates.
|
||||
|
||||
### Challenges
|
||||
|
||||
#### Challenge: Optimizing Generated Code
|
||||
|
||||
Generating code in a systematic way will generate combinations of instructions that are not very efficient.
|
||||
For example, storing a register on the stack only to retrieve it from the stack in the next instruction.
|
||||
As a challenge, consider avoiding to generate such instructions or to transform the generated code
|
||||
|
||||
#### Challenge: Alternative Calling Convention
|
||||
|
||||
The ChocoPy calling convention uses the stack to pass all arguments to functions. Design an alternative calling convention that passes the first `n` arguments via registers (for some small value of `n`). For functions with few arguments or that doesn't call other functions, this may be quite efficient. (But if a function calls another function, it may end saving the registers on the stack after all.)
|
||||
|
||||
|
||||
### Challenges
|
||||
|
||||
#### Running out of registers
|
||||
|
||||
The approach sketched above does not generalize to arbitrary expressions.
|
||||
Create test cases that require more temporary registers than are available.
|
||||
|
||||
Start thinking about solutions for this limitation. Two standard solutions are using the stack for temporaries (which is slow since it involves writing to and reading from memory), and register allocation (which requires a program analysis on the generated code).
|
||||
|
||||
#### <a name="shortcircuit"></a>Short-circuit Boolean operations.
|
||||
|
||||
When encountering a Boolean operation of the form `False and ...`, do we really care about the right side of the operator? Similarly, when we encounter `True or ...`?
|
||||
|
||||
Think about how we can use conditional jumps in RISC-V to short-circuit (any) Boolean operators. Have a look at the instruction set and online compiler.
|
||||
|
||||
A conditional jump in RISC-V takes a label, which represents an address in memory. In Stratego, labels can be generated using `<newname> "L" => label`. (Note that `"L"` can be anything you want, as long as it is a string.) -->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="10.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="12.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#register-allocation">Register Allocation</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#liveness-analysis">Liveness Analysis</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#graph-coloring">Graph Coloring</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#control-flow">Control Flow</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#desugaring">Desugaring</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#explicating-control-translation-to-c-ir">Explicating Control: Translation to C-IR</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="11.html#instruction-selection">Instruction Selection</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="10.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="12.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
486
lab/12.html
Normal file
486
lab/12.html
Normal file
|
|
@ -0,0 +1,486 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 12: Loops & Functions</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 12: Loops & Functions
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
December 10, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<h2 id="while-loops">While Loops</h2>
|
||||
|
||||
<p>Extend your compiler to generate code for while loops.
|
||||
Remember to extend liveness analysis to cater for loops.
|
||||
That is, there may be multipe blocks that jump to a block.
|
||||
This requires that the analysis performs a fixpoint computation.</p>
|
||||
|
||||
<h2 id="functions">Functions</h2>
|
||||
|
||||
<p>Extend your compiler to generate code for functions.
|
||||
To cater for nested functions, you should pass a pointer to the call frame to the lecically enclosing function (a so called static link).
|
||||
Note that the static link may <em>not</em> point to the caller of the function.</p>
|
||||
|
||||
<!-- In this lab you develop code generation for statements and extend your implementation of functions to deal with nested functions.
|
||||
|
||||
See the slides of [Lecture 14](/2021/lecture/14) for a discussion of static links and several critical example ChocoPy programs.
|
||||
|
||||
### Objectives
|
||||
|
||||
1. Compiling statements
|
||||
2. Compiling string constants
|
||||
3. Execution environment
|
||||
4. Compiling nested functions
|
||||
5. Challenges
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
#### Compiling Statements
|
||||
|
||||
Develop transformation rules for assignments and control-flow statements.
|
||||
Here is a sketch for a rule transforming the `if` statement.
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
stat-to-instrs-(|r, regs) :
|
||||
IfElse(e, Block(stats1), Else(Block(stats2))) -> <concat>[
|
||||
…
|
||||
]
|
||||
with <exp-to-instrs(|r, regs)> e => instrs0
|
||||
with <stats-to-instrs(|r, regs)> stats1 => instrs1
|
||||
with <stats-to-instrs(|r, regs)> stats2 => instrs2
|
||||
```
|
||||
|
||||
#### String Constants
|
||||
|
||||
String constants in ChocoPy can be encoded as constant objects.
|
||||
We will discuss objects in more detail next week, but you can already translate string constants.
|
||||
For example
|
||||
|
||||
```
|
||||
message : str = "hello"
|
||||
target : str = "world"
|
||||
|
||||
print(message + " " + target)
|
||||
```
|
||||
|
||||
A constant can be translated to a constant object.
|
||||
For example, the string constant `"hello"` becomes:
|
||||
|
||||
```
|
||||
.globl const_286
|
||||
const_286:
|
||||
.word 3
|
||||
.word 6
|
||||
.word $str$dispatchTable
|
||||
.word 5
|
||||
.string "hello"
|
||||
.align 2
|
||||
```
|
||||
|
||||
You can then use the label (`const_286` in this case) to load the string into a register.
|
||||
|
||||
```
|
||||
la a0, const_286 # load string constant
|
||||
```
|
||||
|
||||
#### Execution Environment
|
||||
|
||||
From the reference compiler at <chocopy.org> you can obtain the implementation of the built-in functions of ChocoPy.
|
||||
|
||||
### Compiling Nested Functions
|
||||
|
||||
#### Handling Shadowing: Making Names Unique
|
||||
|
||||
In ChocoPy definitions can shadow (make invisible) the definition of other names.
|
||||
You will have encountered this in your definition of a type system for Statix.
|
||||
For example, the following program defines two functions named `foo` and several variables named `a`:
|
||||
|
||||
```
|
||||
a : int = 10
|
||||
def foo(a: int) !- int:
|
||||
def foo(b : int) !- int:
|
||||
a : int = 20
|
||||
return a + b
|
||||
return foo(a + 10)
|
||||
|
||||
print(foo(a))
|
||||
```
|
||||
|
||||
In order to make code generation unambiguous you can transform programs to make names unique.
|
||||
For example, the program above could be compiled to the following program, where the name of the enclosing function is used to disambiguate names:
|
||||
|
||||
```
|
||||
$a : int = 10
|
||||
def $foo($foo.a: int) !- int:
|
||||
def $foo.foo($foo.foo.b : int) !- int:
|
||||
$foo.foo.a : int = 20
|
||||
return $foo.foo.a + $foo.foo.b
|
||||
return $foo($foo.a + 10)
|
||||
|
||||
print($foo($a))
|
||||
```
|
||||
|
||||
Note that this program does not parse, since `$` is not part of the syntax of identifiers.
|
||||
But the approach can be used in abstract syntax, and the names _can_ be used in the target RISC-V code.
|
||||
|
||||
#### Nested Functions
|
||||
|
||||
ChocoPy supports the definition of nested functions.
|
||||
That is, a function definition can be nested in another function defintion.
|
||||
This entails that they body of a nested function can access the parameters and local variables of the enclosing function(s).
|
||||
For example, here is a (contrived) program with nested functions:
|
||||
|
||||
```
|
||||
a : int = 10
|
||||
|
||||
def foo(x : int) -> int:
|
||||
b : int = 0
|
||||
|
||||
def aux(i : int) -> int:
|
||||
return b + i
|
||||
|
||||
def bar(y : int) -> int:
|
||||
c : int = 0
|
||||
|
||||
def baz(z : int) -> int:
|
||||
d : int = 0
|
||||
d = aux(c + 1)
|
||||
return a + x + y + z
|
||||
|
||||
return baz(a + b + x)
|
||||
|
||||
b = aux(x)
|
||||
return bar(b + 10)
|
||||
|
||||
print(foo(a))
|
||||
```
|
||||
|
||||
#### Static Links
|
||||
|
||||
Global variables can be accessed directly using their named label.
|
||||
Formal parameters and local variables can be accessed via their offset from the frame pointer.
|
||||
The parameters and local variables of enclosing functions are accessible to nested functions.
|
||||
They are stored in the call frame of the corresponding function, which is on the stack when a nested function is being executed.
|
||||
Thus, to access those variables we need to find the corresponding call frame.
|
||||
However, the call frame of the enclosing function is not necessarily the call frame of the caller of a function.
|
||||
For example, when a function is recursive, there may be multiple call frames separating the call frame of a nested function and that of its (statically) enclosing function.
|
||||
|
||||
A _static link_ is an additional implicit argument of a function that points to the call frame of its directly enclosing function.
|
||||
Via the chain of static links, the call frames of all enclosing functions can be reached.
|
||||
See the slides of [Lecture 14](/2021/lecture/14) for example ChocoPy programs with nested functions and the use of static links to implement them.
|
||||
|
||||
#### Making Nesting Explicit
|
||||
|
||||
Once you have added static links to your code generator, you can implement the calling of nested functions and access to local variables and formal parameters of nested functions.
|
||||
To do that correctly, you need to know how many static links to follow.
|
||||
One approach is to compute before code generation as a program transformation, annotating all function calls with the number of links to follow.
|
||||
For example, for the program above that would lead to:
|
||||
|
||||
```
|
||||
a : int = 10
|
||||
|
||||
def foo(x : int) -> int:
|
||||
b : int = 0
|
||||
|
||||
def aux(i : int) -> int:
|
||||
return b/1 + i/0
|
||||
|
||||
def bar(y : int) -> int:
|
||||
c : int = 0
|
||||
|
||||
def baz(z : int) -> int:
|
||||
d : int = 0
|
||||
d = aux/2(c/1 + 1)
|
||||
return a/0 + x/2 + y/1 + z/0
|
||||
|
||||
return baz/0(a/0 + b/1 + x/1)
|
||||
|
||||
b = aux/0(x/0)
|
||||
return bar/0(b/0 + 10)
|
||||
|
||||
print(foo/0(a/0))
|
||||
```
|
||||
|
||||
#### Evaluation Order
|
||||
|
||||
A question to consider when compiling function calls is whether the order of evaluation of function arguments is relevant.
|
||||
For a language such as C, the order of evaluation is not defined, and up to the compiler to chose an order.
|
||||
This means that programmers cannot count on the order being deterministic.
|
||||
Is the order of evaluation of function call arguments defined for ChocoPy?
|
||||
Does that correspond to the semantics of Python?
|
||||
|
||||
### Challenges
|
||||
|
||||
#### Boxed vs Unboxed Representation of Primitive Values
|
||||
|
||||
The ChocoPy reference implementation uses a boxed representation of strings, integers, and booleans. Is that necessary? Is it possible to use an unboxed representation?
|
||||
|
||||
#### Functions as First-Class Citizens
|
||||
|
||||
Functions in ChocoPy can be nested. This means that they can have 'free variables' that are defined in the context of the function definitions.
|
||||
But ChocoPy functions are not first-class citizens.
|
||||
Thus, one cannot pass a function to another function or store it in a data structure.
|
||||
Can you extend ChocoPy with functions as first-class citizens, i.e. add anonymous function literals to the language?
|
||||
What syntax would you give to such function literals?
|
||||
What would be your strategy for implementing this feature? -->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="11.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="13.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="12.html#while-loops">While Loops</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="12.html#functions">Functions</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="11.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="13.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
394
lab/13.html
Normal file
394
lab/13.html
Normal file
|
|
@ -0,0 +1,394 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 13: Compiling Objects</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 13: Compiling Objects
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
December 17, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Develop code generation for ChocoPy classes and methods.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<ol>
|
||||
<li>Compiling objects</li>
|
||||
<li>Compiling lists</li>
|
||||
<li>Challenges
|
||||
<ul>
|
||||
<li>Garbage collection</li>
|
||||
<li>Register allocation</li>
|
||||
<li>Peephole optimizations</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="compiling-objects">Compiling Objects</h3>
|
||||
|
||||
<p>The main objective for today’s lab is to extend your compiler to support the compilation of classes.
|
||||
See also the slides of <a href="../lecture/15.html">Lecture 15</a> and the <a href="https://chocopy.org/chocopy_implementation_guide.pdf">ChocoPy implementation guide</a>.</p>
|
||||
|
||||
<h4 id="objects-in-chocopy">Objects in ChocoPy</h4>
|
||||
|
||||
<p>ChocoPy supports object-oriented programming through classes with attributes and methods.
|
||||
The following example program (from the reference manual) illustrates many of the features of classes in ChocoPy:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class animal(object):
|
||||
makes_noise:bool = False
|
||||
|
||||
def make_noise(self: "animal") -> object:
|
||||
if (self.makes_noise):
|
||||
print(self.sound())
|
||||
|
||||
def sound(self: "animal") -> str:
|
||||
return "???"
|
||||
|
||||
class cow(animal):
|
||||
def __init__(self: "cow"):
|
||||
self.makes_noise = True
|
||||
|
||||
def sound(self: "cow") -> str:
|
||||
return "moo"
|
||||
|
||||
c:animal = None
|
||||
c = cow()
|
||||
c.make_noise()
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>A class defines a type and inherits from a superclass of which it is a subtype.</p>
|
||||
|
||||
<p>A class has attributes that are initialized with a literal value, which is <code class="language-plaintext highlighter-rouge">None</code> in the case of object types.</p>
|
||||
|
||||
<p>A class has method defintions, which are regular ChocoPy function definitions, except that methods always have a first argument (<code class="language-plaintext highlighter-rouge">self</code>) of the enclosing class type, which represents the objects to which the method is applied.
|
||||
Methods can have nested functions.</p>
|
||||
|
||||
<p>A method call <code class="language-plaintext highlighter-rouge">e0.f(e1, ...)</code> invokes a method on the object. The actual implementation called corresponds to the <em>dynamic</em> type of the object value. That is, when the object is of a subtype <code class="language-plaintext highlighter-rouge">t</code> of the static type of <code class="language-plaintext highlighter-rouge">e0</code>, and the method <code class="language-plaintext highlighter-rouge">f</code> has been overridden in <code class="language-plaintext highlighter-rouge">t</code> or a supertype of <code class="language-plaintext highlighter-rouge">t</code>, the method lowest in the class hierarchy is called. This is known as <em>dynamic dispatch</em>.</p>
|
||||
|
||||
<p>A function with the same name as the class (e.g. <code class="language-plaintext highlighter-rouge">cow()</code> in the example above) is used to create objects.
|
||||
When a class or one of its superclasses has an <code class="language-plaintext highlighter-rouge">__init__</code> method, that method is called implicitly on construction of the object.</p>
|
||||
|
||||
<h4 id="object-layout-and-prototypes">Object Layout and Prototypes</h4>
|
||||
|
||||
<p>An object value is represented by a chunk of memory in the heap, consisting of a type tag, the size of the object, a pointer to the dispatch table (see below) of the class, and the values of the attributes of the class.</p>
|
||||
|
||||
<p>Objects are allocated by the <code class="language-plaintext highlighter-rouge">alloc</code> function in the execution environment, by copying a pointer to a prototype object.
|
||||
The prototype object for a class is an object following the layout described above with attribute values set to their initial values in the corresponding class.
|
||||
Thus, there is not need to perform the default initialization programmatically.
|
||||
After copying the prototype object, the <code class="language-plaintext highlighter-rouge">__init__</code> method is invoked to apply further custom initialization.</p>
|
||||
|
||||
<h4 id="dispatch-tables">Dispatch Tables</h4>
|
||||
|
||||
<p>Since all object instance of a class share the same set of methods, there is no need to copy the addresses of the corresponding functions into each object.
|
||||
Instead, an object contains a pointer to a dispatch table, which contains the addresses (labels) of the functions implementing the methods.
|
||||
Note that the methods of inherited method are also included in the dispatch table.</p>
|
||||
|
||||
<h4 id="compiling-methods">Compiling Methods</h4>
|
||||
|
||||
<p>Methods are standard top-level functions and can be compiled using the same approach as used for those.
|
||||
The first argument of a function is a pointer to the object to which the method is applied.
|
||||
Since methods and attributes are accessed through this <code class="language-plaintext highlighter-rouge">self</code> argument, no special measures are needed.</p>
|
||||
|
||||
<h4 id="calling-methods">Calling Methods</h4>
|
||||
|
||||
<p>Method calls are similar to top-level function calles, but the first argument is passed as a receiver object.
|
||||
That is, <code class="language-plaintext highlighter-rouge">e0.f(e1, ...)</code> is essentially a function call <code class="language-plaintext highlighter-rouge">f(e0, e1, ...)</code>.
|
||||
However, the actual function to be called should be obtained through the dispatch table to which the value of <code class="language-plaintext highlighter-rouge">e0</code> points.
|
||||
In order to access that object it should not be <code class="language-plaintext highlighter-rouge">None</code>.</p>
|
||||
|
||||
<h4 id="accessing-attributes">Accessing Attributes</h4>
|
||||
|
||||
<p>An attribute access <code class="language-plaintext highlighter-rouge">e.x</code> is implemented by accessing the object at the offset corresponding to the attribute <code class="language-plaintext highlighter-rouge">x</code>.
|
||||
Also for attribute accesses, the object should not be <code class="language-plaintext highlighter-rouge">None</code>.</p>
|
||||
|
||||
<h3 id="compiling-lists">Compiling Lists</h3>
|
||||
|
||||
<p>ChocoPy has lists, which are mutable sequences of a fixed length. So, lists behave like arrays in C. Operations on lists are length <code class="language-plaintext highlighter-rouge">len</code>, indexing <code class="language-plaintext highlighter-rouge">lst[i]</code>, and concatenation <code class="language-plaintext highlighter-rouge">lst1 + lst2</code>.
|
||||
Lists are represented as objects with <code class="language-plaintext highlighter-rouge">len</code> attributes to represent the elements of the list.
|
||||
Concatenation constructs a new list copying the original lists.</p>
|
||||
|
||||
<h3 id="challenges">Challenges</h3>
|
||||
|
||||
<h4 id="garbage-collection">Garbage Collection</h4>
|
||||
|
||||
<p>Objects are allocated on the heap. What happens when your program runs out of heap memory to allocate objects? Is compiled code memory safe? Develop a garbage collection algorithm for the execution environment of ChocoPy progams in order to support automatic memory management.</p>
|
||||
|
||||
<!-- #### Register Allocation
|
||||
|
||||
In [Lecture 15](/2021/lecture/15) we discussed register allocation using graph coloring. Use a separate register allocation phase to assign temporary values to registers in order to avoid saving values to memory. -->
|
||||
|
||||
<h4 id="peephole-optimization">Peephole Optimization</h4>
|
||||
|
||||
<p>A peephole optimization can be applied to generated code, i.e. to the AST of the generated program. A peephole optimization recognizes a couple of adjacent instructions and replaces them with something more efficient.
|
||||
Extend your compiler with a peephole optimization phase after code generation that optimizes generated code.
|
||||
Make sure that optimizations do preserve the semantics of the code.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="12.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="14.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#objectives">Objectives</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#compiling-objects">Compiling Objects</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#objects-in-chocopy">Objects in ChocoPy</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#object-layout-and-prototypes">Object Layout and Prototypes</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#dispatch-tables">Dispatch Tables</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#compiling-methods">Compiling Methods</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#calling-methods">Calling Methods</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#accessing-attributes">Accessing Attributes</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#compiling-lists">Compiling Lists</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#challenges">Challenges</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#garbage-collection">Garbage Collection</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="13.html#peephole-optimization">Peephole Optimization</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="12.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="14.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
259
lab/14.html
Normal file
259
lab/14.html
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 14: Implementing Lists & Testing Your Compiler</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 14: Implementing Lists & Testing Your Compiler
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
December 24, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Implement lists in ChocoPy.</p>
|
||||
|
||||
<p>Test all corner cases of the ChocoPy language and make sure your compiler deals with them correctly.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="13.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="15.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="13.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="15.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
252
lab/15.html
Normal file
252
lab/15.html
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 15: Finishing Touches</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 15: Finishing Touches
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
January 14, 2022
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Make sure your code is ready for final submission.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="14.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/3.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="14.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/3.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
959
lab/1a.html
Normal file
959
lab/1a.html
Normal file
|
|
@ -0,0 +1,959 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 1(a): Setting up Spoofax</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
<a href="https://tudelft-cs4200.github.io/2021">
|
||||
<img class="border border-dark" width="100%" src="../project/2021/00-lab1a/spoofax.png"/>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 1(a): Setting up Spoofax
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project Set-up
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 07, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>For the course project and for some of the homework assignments we will use the <a href="https://www.spoofax.dev/spoofax-pie/develop">Spoofax Language Workbench</a> version <a href="https://www.spoofax.dev/spoofax-pie/develop/">Spoofax 3</a>.</p>
|
||||
|
||||
<h3 id="installing-spoofax">Installing Spoofax</h3>
|
||||
|
||||
<p>Follow the <a href="https://www.spoofax.dev/spoofax-pie/develop/tutorial/install/">tutorial</a> on installing Spoofax3.</p>
|
||||
|
||||
<h3 id="language-projects">Language Projects</h3>
|
||||
|
||||
<p>In Spoofax you develop a programming language in a ‘language project’.</p>
|
||||
|
||||
<p>Follow the tutorial on <a href="https://www.spoofax.dev/spoofax-pie/develop/tutorial/create_language_project/">Creating a language project</a> to create a project with syntax and syntax tests.</p>
|
||||
|
||||
<h3 id="chocopy-project">ChocoPy Project</h3>
|
||||
|
||||
<p>Create a Spoofax project for the ChocoPy language. Configure your project to use the Chocopy name and <code class="language-plaintext highlighter-rouge">cpy</code> identifier, and place it in the <em>root of your repository</em>. See the image below for an example.</p>
|
||||
|
||||
<p><img src="https://i.imgur.com/wFAbX9K.png" alt="" /></p>
|
||||
|
||||
<p>Your project can be located in either <code class="language-plaintext highlighter-rouge">student-<yournetid>/chocopy.syntax</code> or <code class="language-plaintext highlighter-rouge">student-<yournetid>/chocopy</code>. If you place your project in a nested folder, or in a differently named folder, the grader will automatically reject your submission.</p>
|
||||
|
||||
<h3 id="updating-spoofax">Updating Spoofax</h3>
|
||||
|
||||
<p>During the course of the project, bugfixes and new features may be added to Spoofax 3. The grader will always test your project using the most recent version of Spoofax 3 that is backwards compatible with the initial project version (0.11.6).</p>
|
||||
|
||||
<p>To update your local installation to the newest version of Spoofax 3, launch Eclipse and select <code class="language-plaintext highlighter-rouge">Help</code> from the top menu, followed by <code class="language-plaintext highlighter-rouge">Install new software</code>.</p>
|
||||
|
||||
<p><img src="https://i.imgur.com/P8v2gj9.png" alt="" /></p>
|
||||
|
||||
<p>In the dialog that opens, enter the release URL of the latest Spoofax 3 release in the <code class="language-plaintext highlighter-rouge">Work with:</code> field. This URL starts with <code class="language-plaintext highlighter-rouge">https://artifacts.metaborg.org</code> and can be found on the <a href="https://www.spoofax.dev/spoofax-pie/develop/release/download/">Spoofax 3 releases page</a>. After entering the URL, hit enter to load all available packages for that release, then select the Spoofax package.</p>
|
||||
|
||||
<p><img src="https://i.imgur.com/j0Q91n8.png" alt="" /></p>
|
||||
|
||||
<p>Finally, hit next, accept the license if needed, and confirm the install. During installation, Eclipse may prompt that the package is unsigned. When this happens, select <code class="language-plaintext highlighter-rouge">Install anyway</code>.</p>
|
||||
|
||||
<p><img src="https://i.imgur.com/sKLxdGp.png" alt="" /></p>
|
||||
|
||||
<p>Then, restart Eclipse.
|
||||
After Eclipse has restarted, clean your ChocoPy language project by selecting it in the Package Explorer, choosing Project -> Clean from the main menu, and by pressing Clean.
|
||||
After the project is cleaned, build it once and continue.</p>
|
||||
|
||||
<h3 id="references">References</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="list-group list-group-flush pb-3">
|
||||
|
||||
|
||||
<li class="list-group-item pl-lg-0 border-0 pb-0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bd-callout border-success pl-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<a name="Spoofax3"></a>
|
||||
|
||||
<a class="font-weight-bold text-dark" target="_blank" href="https://www.spoofax.dev/spoofax-pie/develop/">Spoofax 3 (Documentation) </a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light" style="font-size:90%;">
|
||||
|
||||
(editor).
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
|
||||
|
||||
|
||||
|
||||
https://www.spoofax.dev/spoofax-pie/develop/ 2021
|
||||
|
||||
|
||||
|
||||
[<a class="text-secondary" target="_blank" href="https://researchr.org/publication/Spoofax3/bibtex">bib</a>, <a href="https://researchr.org/publication/Spoofax3" class="text-secondary" target="_blank">researchr</a>]
|
||||
|
||||
<!-- Spoofax3 -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="list-group-item pl-lg-0 border-0 pb-0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bd-callout border-success pl-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<a name="Spoofax2021"></a>
|
||||
|
||||
<a class="font-weight-bold text-dark" target="_blank" href="https://www.spoofax.dev/">Spoofax: The Language Designer's Workbench</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light" style="font-size:90%;">
|
||||
|
||||
(editor).
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
|
||||
|
||||
|
||||
|
||||
https://www.spoofax.dev/ 2021
|
||||
|
||||
|
||||
|
||||
[<a class="text-secondary" target="_blank" href="https://researchr.org/publication/Spoofax2021/bibtex">bib</a>, <a href="https://researchr.org/publication/Spoofax2021" class="text-secondary" target="_blank">researchr</a>]
|
||||
|
||||
<!-- Spoofax2021 -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0b.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1b.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1a.html#installing-spoofax">Installing Spoofax</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1a.html#language-projects">Language Projects</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1a.html#chocopy-project">ChocoPy Project</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1a.html#updating-spoofax">Updating Spoofax</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1a.html#references">References</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="0b.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1b.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
975
lab/1b.html
Normal file
975
lab/1b.html
Normal file
|
|
@ -0,0 +1,975 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 1(b): Creating Syntax Tests</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
<a href="https://tudelft-cs4200.github.io/2021">
|
||||
<img class="border border-dark" width="100%" src="../project/2021/00-lab1b/spt.png"/>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 1(b): Creating Syntax Tests
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 07, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Before getting started with your syntax definition, you set up a test suite for syntax analysis.
|
||||
Develop the test suite in tandem with the development of your syntax definition.
|
||||
The test suite consists of positive and negative test cases.
|
||||
We will <em>not</em> grade this test suite, but you should develop one to get confidence in the quality of your syntax definition.
|
||||
When you are asking for help from the course staff, we will first ask what tests you have written to demonstrate the problem.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<p>Develop a test suite for syntax analysis.
|
||||
The test suite should provide</p>
|
||||
|
||||
<ol>
|
||||
<li>Syntactically valid and invalid test cases for the <code class="language-plaintext highlighter-rouge">Start</code> sort</li>
|
||||
<li>Disambiguation tests for associativity and precedence in expressions.</li>
|
||||
<li>Test cases for layout-sensitive language constructs</li>
|
||||
<li>Test cases for mandatory and optional whitespace.</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="anatomy-of-a-test-suite">Anatomy of a Test Suite</h3>
|
||||
|
||||
<p>In Spoofax, a test suite consists of one or more <code class="language-plaintext highlighter-rouge">.spt</code> files.
|
||||
Consider the following example file:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module example
|
||||
|
||||
test FUN composite [[func(1+1, 3*2)]] parse succeeds
|
||||
test FUN only comma [[func(,)]] parse fails
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>The first line specifies the name of the test <code class="language-plaintext highlighter-rouge">module</code>,
|
||||
In this <code class="language-plaintext highlighter-rouge">example</code> module, we test syntax of the <code class="language-plaintext highlighter-rouge">ChocoPy</code> language.</p>
|
||||
|
||||
<p>The last two lines specify a positive and a negative test case.
|
||||
Each test case consists of
|
||||
a name,
|
||||
a code fragment in double square brackets, and
|
||||
a condition which determines
|
||||
what kind of test should be performed (parsing) and
|
||||
what the expected outcome is (success or failure).</p>
|
||||
|
||||
<p>You get instant feedback while editing a test suite.
|
||||
Since you have not yet implemented the ChocoPy editor, all your positive test cases fail.
|
||||
You will work on this during the next lab.
|
||||
To read more on SPT, visit the documentation.</p>
|
||||
|
||||
<h4 id="chocopy-syntax-definition">ChocoPy Syntax Definition</h4>
|
||||
|
||||
<p>To write your own test cases, you need to understand ChocoPy’s syntax.
|
||||
You can find the definitive ChocoPy syntax definition in the <a href="0b.html">Reference Manual</a>.</p>
|
||||
|
||||
<h3 id="test-cases">Test Cases</h3>
|
||||
|
||||
<p>You can now start writing your own test cases.</p>
|
||||
|
||||
<h4 id="lexical-and-context-free-syntax">Lexical and Context-free Syntax</h4>
|
||||
|
||||
<p>Start with the lexical syntax and think about valid and invalid identifiers.
|
||||
Try to focus on corner cases such as</p>
|
||||
|
||||
<ul>
|
||||
<li>identifiers made of a single character,</li>
|
||||
<li>mixings of letters and digits (Which kinds of mixing are allowed? Which are not?),</li>
|
||||
<li>underscores in identifiers.</li>
|
||||
</ul>
|
||||
|
||||
<p class="notice notice-warning">The content for the tests for lexical symbols should not be surrounded by layout.</p>
|
||||
|
||||
<p>Next, you should walk through the whole syntax definition.
|
||||
Keep thinking of valid and invalid code fragments.
|
||||
Identify interesting corner cases and turn them into positive and negative test cases.</p>
|
||||
|
||||
<p>Try to keep your test cases small.
|
||||
Each test case should focus on a single aspect.
|
||||
For example, a negative test case should only contain one error.
|
||||
The name of a test case should reflect the aspect it addresses.</p>
|
||||
|
||||
<p>You can organise test cases which focus on similar aspects in test modules.
|
||||
Again, the name of a test module should reflect these aspects.
|
||||
Finally, you can organise test suites in folders.</p>
|
||||
|
||||
<p class="notice notice-warning">When writing tests that target the differences between Python and ChocoPy, only consider the syntactic differences.
|
||||
For example, identifiers in Python are limited to a certain size.
|
||||
This <strong>should not</strong> be checked by your tests as this limitation is not specified in the context-free grammar of Python.</p>
|
||||
|
||||
<h4 id="disambiguation">Disambiguation</h4>
|
||||
|
||||
<p>Next, you need to focus on disambiguation.
|
||||
Come up with positive test cases which specify the correct ASTs for nested expressions.
|
||||
As an alternative, you can also specify two fragments in concrete syntax, which should result in the same AST:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>test left associative addition [[21 + 14 + 14]] parse to [[(21 + 14) + 14]]
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>You can find a table listing the associativity and priorities of operators in the reference manual.
|
||||
Do not focus only on binary expressions.</p>
|
||||
|
||||
<p class="notice notice-warning">You <strong>do not</strong> have to test for constructs that are non-associative. In lab 2, <code class="language-plaintext highlighter-rouge">non-assoc</code> leads to semantic errors rather than syntactic errors during parse time. Since our language does not have analysis at that point, we cannot test the semantic errors and thus they are also not required for this lab.</p>
|
||||
|
||||
<h4 id="layout">Layout</h4>
|
||||
|
||||
<p>Finally, you can focus on layout.
|
||||
Think about places where whitespace is not optional but mandatory and define corresponding positive and negative test cases.
|
||||
Finish with test cases for single-line comments.
|
||||
Single-line comments cannot only end with a newline character, but also at the end of file.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="list-group list-group-flush pb-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="list-group-item pl-lg-0 border-0 pb-0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bd-callout border-primary pl-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<a name="KatsVV11"></a>
|
||||
|
||||
<a class="font-weight-bold text-dark" target="_blank" href="http://doi.acm.org/10.1145/2048066.2048080">Integrated language definition testing: enabling test-driven language development</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
<a class="text-secondary" href="http://www.lclnet.nl/">Lennart C. L. Kats</a>, <a class="text-secondary" href="https://researchr.org/profile/robvermaas/publications">Rob Vermaas</a>, <a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
|
||||
|
||||
OOPSLA 2011
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[<a href="../publications/2011/KatsVV11.pdf" class="text-secondary" target="_blank">pdf</a>, <a class="text-secondary" href="http://doi.acm.org/10.1145/2048066.2048080" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/KatsVV11/bibtex">bib</a>, <a href="https://researchr.org/publication/KatsVV11" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="1b.html#AbstractKatsVV11" role="button" aria-expanded="false" aria-controls="AbstractKatsVV11"">abstract</a>]
|
||||
|
||||
<!-- -->
|
||||
|
||||
</div>
|
||||
|
||||
<div class="collapse mt-1 mb-2" id="AbstractKatsVV11">
|
||||
<div class="">
|
||||
The reliability of compilers, interpreters, and development environments for programming languages is essential for effective software development and maintenance. They are often tested only as an afterthought. Languages with a smaller scope, such as domain-specific languages, often remain untested. General-purpose testing techniques and test case generation methods fall short in providing a low-threshold solution for test-driven language development. In this paper we introduce the notion of a language-parametric testing language (LPTL) that provides a reusable, generic basis for declaratively specifying language definition tests. We integrate the syntax, semantics, and editor services of a language under test into the LPTL for writing test inputs. This paper describes the design of an LPTL and the tool support provided for it, shows use cases using examples, and describes our implementation in the form of the Spoofax testing language.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1a.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1c.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#objectives">Objectives</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#anatomy-of-a-test-suite">Anatomy of a Test Suite</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#chocopy-syntax-definition">ChocoPy Syntax Definition</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#test-cases">Test Cases</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#lexical-and-context-free-syntax">Lexical and Context-free Syntax</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#disambiguation">Disambiguation</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#layout">Layout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1a.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1c.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
485
lab/1c.html
Normal file
485
lab/1c.html
Normal file
|
|
@ -0,0 +1,485 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 1(c): Syntax Definition</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
<a href="https://tudelft-cs4200.github.io/2021">
|
||||
<img class="border border-dark" width="100%" src="../project/2021/00-lab1c/grammar.png"/>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 1(c): Syntax Definition
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 07, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>In this lab, you define the concrete and abstract syntax of ChocoPy in Spoofax.
|
||||
From this definition, you generate an Eclipse editor, which provides syntax checking, error recovery, and syntax highlighting.</p>
|
||||
|
||||
<p>In this lab, focus on translating the grammar in Figure 3 of the ChocoPy Reference Manual to an <em>idiomatic</em> context-free syntax definition with constructors.
|
||||
In the <a href="2.html">next lab</a>, you extend this definition with <em>disambiguation rules</em> for associativity, priority, and layout constraints.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<p>Develop a syntax definition for ChocoPy in SDF3 and generate an Eclipse editor from it.
|
||||
The definition should include:</p>
|
||||
|
||||
<ol>
|
||||
<li>The start symbol <code class="language-plaintext highlighter-rouge">Start</code></li>
|
||||
<li>A lexical syntax definition for all ChocoPy lexemes</li>
|
||||
<li>A context-free syntax definition ChocoPy complying with the grammar in Figure 3 of the reference manual</li>
|
||||
<li>Constructor names for context-free syntax productions</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="syntax-definition">Syntax Definition</h3>
|
||||
|
||||
<p>You should define your syntax in SDF3.
|
||||
You can start by opening the file <code class="language-plaintext highlighter-rouge">src/start.sdf3</code> in your chocopy project.
|
||||
You can also split your syntax definition over several modules in <code class="language-plaintext highlighter-rouge">src/</code> and import modules into module <code class="language-plaintext highlighter-rouge">start</code>.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module start
|
||||
imports lex
|
||||
imports expressions
|
||||
imports statements
|
||||
// etc.
|
||||
context-free start symbols Start
|
||||
</code></pre></div></div>
|
||||
|
||||
<!-- The module already imports a module `Common.sdf3`, which you can find in any initial Spoofax editor project.
|
||||
This module provides syntax definitions for common lexical sorts such as identifiers, integers, strings, whitespace, and comments. -->
|
||||
|
||||
<!-- For more information on how to write SDF3 syntax definitions, also check the documentation on how to define a language in Spoofax.
|
||||
{: .notice .notice-warning} -->
|
||||
|
||||
<p>For more information on how to write SDF3 syntax definitions, you can also review the <a href="http://www.metaborg.org/en/latest/source/langdev/meta/lang/sdf3/index.html">old SDF3 reference manual</a> and the new <a href="https://www.spoofax.dev/references/syntax/">SDF3 reference</a>.</p>
|
||||
|
||||
<p class="notice notice-warning"><strong>Note that both of these are written for Spoofax 2, and that not all information may still be correct in Spoofax 3!</strong></p>
|
||||
|
||||
<h4 id="context-free-syntax">Context-free Syntax</h4>
|
||||
|
||||
<p>Start with the context-free syntax of the language.
|
||||
Use the context-free grammar in the <em>ChocoPy Language Reference Manual</em> as a reference.</p>
|
||||
|
||||
<!-- When you define your syntax definition bottom-up, you start with sorts such as `Type` and `VarDecl`.
|
||||
This allows you to run your tests frequently and check your progress. -->
|
||||
|
||||
<p>We recommend to use <em>template productions</em> for your context-free syntax definition, since they help when generating artifacts other than just the parser.
|
||||
When you use template productions, you need to make sure that templates are correctly tokenised.
|
||||
Otherwise, the parser would reject layout in certain positions, for example between <code class="language-plaintext highlighter-rouge">[</code> and <code class="language-plaintext highlighter-rouge">]</code> in an array type.
|
||||
Check the SDF3 documentation for details.
|
||||
In case you want to use <code class="language-plaintext highlighter-rouge"><</code> or <code class="language-plaintext highlighter-rouge">></code> as symbols inside a template, you can use alternate template brackets <code class="language-plaintext highlighter-rouge">[...]</code>.</p>
|
||||
|
||||
<h4 id="lexical-syntax">Lexical Syntax</h4>
|
||||
|
||||
<p>Continue with the lexical syntax definition including identifiers, integer, and simple layout.
|
||||
<!-- The `Common` module in `syntax/Common.sdf3` already provides definitions, but these do not necessarily comply with the lexical syntax of ChocoPy. -->
|
||||
<!-- You can either fix these definitions in `Common`, or define and import your own module and use `Common` only for inspiration. --></p>
|
||||
|
||||
<p>First, define lexical syntax rules:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical syntax
|
||||
ID = ...
|
||||
INT = ...
|
||||
LAYOUT = ...
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Second, define follow restrictions to ensure longest match:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical restrictions
|
||||
ID -/- ...
|
||||
INT -/- ...
|
||||
context-free restrictions
|
||||
LAYOUT? -/- ...
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Finally, use rejection rules to rule out reserved words.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical syntax
|
||||
ID = ... {reject}
|
||||
</code></pre></div></div>
|
||||
|
||||
<h4 id="testing-your-syntax-definition">Testing Your Syntax Definition</h4>
|
||||
|
||||
<p>You now can check your tests.</p>
|
||||
|
||||
<p class="notice notice-danger">It is important to get your grammar working at this stage. Do not move on if you have issues here, since there is a high chance that these issues influence your other tests as well. If you experience weird behaviour on your tests or a large amount of ambiguity, this is most likely caused by an erroneous definition of <code class="language-plaintext highlighter-rouge">LAYOUT</code>.</p>
|
||||
|
||||
<p>Finally, you should add lexical syntax rules for comments to your syntax definition.
|
||||
Start with single line comments.
|
||||
Do not forget to define follow restrictions.</p>
|
||||
|
||||
<!-- ### Editor Services
|
||||
|
||||
When developing a language in Spoofax, the syntax definition written in SDF3 does not only produce a parser but other editor services as well.
|
||||
|
||||
#### Pretty Printing
|
||||
|
||||
Spoofax generates pretty-printing rules from your syntax definition.
|
||||
|
||||
In order to test the pretty-print builder, you need to build your project.
|
||||
Your ChocoPy editor provides a menu entry named `Format` that uses these generated rules to pretty-print a ChocoPy file.
|
||||
Create or open a `.cpy` test file with a valid program, go to the *Spoofax* -> *Syntax* menu and choose `Format`.
|
||||
This will apply `Format` to the current file and show the result in a new editor.
|
||||
|
||||
Typically, the pretty-printed code lacks proper indentation and line breaks.
|
||||
You can fix this by improving your templates in the syntax definition.
|
||||
The pretty-printer follows the indentation and line breaks from the syntax definition.
|
||||
|
||||
You should improve your syntax definition in order to get readable code with a consistent indentation.
|
||||
You might read on [indent styles](http://en.wikipedia.org/wiki/Indent_style) for some inspiration.
|
||||
|
||||
Make sure that your altered syntax definition is still correct and can be used to parse ChocoPy programs.
|
||||
{: .notice .notice-warning}
|
||||
|
||||
#### Syntactic Code Completion
|
||||
|
||||
Together with a pretty-printer, Spoofax also automatically derives syntactic code completion from the syntax definition. This feature allows for example, for new users to discover the language's syntax while editing the program. To know more details about syntactic code completion in Spoofax, check the documentation. -->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1b.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1d.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1c.html#objectives">Objectives</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1c.html#syntax-definition">Syntax Definition</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1c.html#context-free-syntax">Context-free Syntax</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1c.html#lexical-syntax">Lexical Syntax</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1c.html#testing-your-syntax-definition">Testing Your Syntax Definition</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1b.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1d.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
555
lab/1d.html
Normal file
555
lab/1d.html
Normal file
|
|
@ -0,0 +1,555 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 1(d): Git(Lab), CI, and Submissions</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 1(d): Git(Lab), CI, and Submissions
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 07, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>We use the Git version control system with <a href="https://gitlab.ewi.tudelft.nl">gitlab.ewi.tudelft.nl</a> to manage submissions and grade assignments.</p>
|
||||
|
||||
<h3 id="git">Git</h3>
|
||||
|
||||
<p>Download and install Git from <a href="https://git-scm.com/downloads">this page</a>. We will be using the Git command-line, since it is more powerful and easier to troubleshoot than GUI clients. On Linux and macOS, installing Git should provide a <code class="language-plaintext highlighter-rouge">git</code> command on your shell. On Windows, Git installs <code class="language-plaintext highlighter-rouge">Git BASH</code> to provide a command-line shell, which you need to start to use Git from the command-line.</p>
|
||||
|
||||
<p>We will explain the steps needed to work on and submit assignments on this page. To learn the basics of git, read <a href="http://rogerdudler.github.io/git-guide/">git - the simple guide</a> and <a href="https://try.github.io/">try out the Git command-line</a>. If you’d like to learn more, <a href="https://help.github.com/articles/good-resources-for-learning-git-and-github/">have a look at these resources</a>.</p>
|
||||
|
||||
<h3 id="repository-structure">Repository Structure</h3>
|
||||
|
||||
<p>Let’s look at the repository structure first.</p>
|
||||
|
||||
<p>On GitLab, we will create a private git repository for you, which is owned by us, and is only visible to you and the compiler construction team. This repository will host assignment templates and your submissions in <strong>protected</strong> branches. Note that you <strong>do not</strong> have write access to protected branches. You can only read from it and submit assignments to it by opening merge requests. This is to ensure that you cannot mess with submitted assignments after the deadline. You <strong>do</strong> have access to non-protected branches, and this is where you can push your work frequently.</p>
|
||||
|
||||
<h3 id="getting-started">Getting started</h3>
|
||||
|
||||
<p>First, find your private repository in the <a href="https://gitlab.ewi.tudelft.nl/CS4200/2021-2022">CS4200/2021-2022</a> group on GitLab, it should be called <code class="language-plaintext highlighter-rouge">student-id</code> where <code class="language-plaintext highlighter-rouge">id</code> is your NetID.</p>
|
||||
|
||||
<p>To actually do work in the Git repository, you need to make a <em>local</em> clone of the repository on your computer. You can find the URL needed to clone on the bottom right of the page, be sure to use <code class="language-plaintext highlighter-rouge">HTTPS</code>.</p>
|
||||
|
||||
<p><img src="../project/2021/00-submissions/clone_url.png" alt="Clone URL" /></p>
|
||||
|
||||
<p>Open up the command line and make a local clone with your URL:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://gitlab.ewi.tudelft.nl/CS4200/2021-2022/student-netid.git
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Now cd into the local clone and confirm that it works:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd </span>student-netid
|
||||
git status
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>which should output something like:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>On branch master
|
||||
Your branch is up-to-date with <span class="s1">'origin/master'</span><span class="nb">.</span>
|
||||
nothing to commit, working directory clean
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Your local repository is set up now! Follow the steps below to work on an assignment.</p>
|
||||
|
||||
<h3 id="starting-an-assignment">Starting an assignment</h3>
|
||||
|
||||
<p>You work on each assignment in its own development branch, named <code class="language-plaintext highlighter-rouge">milestone-0-develop</code>, <code class="language-plaintext highlighter-rouge">milestone-1-develop</code>, etc.
|
||||
The correct assignment branch must be checked out in your local Git repository to be able to work on it.
|
||||
The steps to check out a branch depend on whether we provide you with a template, or if you continue with work from a previous assignment.</p>
|
||||
|
||||
<h4 id="template">Template</h4>
|
||||
|
||||
<p>If the assignments asks you to check out a template, which for example <code class="language-plaintext highlighter-rouge">milestone-0-template</code> does, use the following steps:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git fetch origin
|
||||
git checkout <span class="nt">-b</span> milestone-0-develop origin/milestone-0-template
|
||||
git push <span class="nt">-u</span> origin milestone-0-develop
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>This checks out a fresh branch from the remote repository. It does not contain any of your previous work.</p>
|
||||
|
||||
<h4 id="continue-from-previous-assignment">Continue from previous assignment</h4>
|
||||
|
||||
<p>If the assignment asks you to continue from the previous assignment, which for example milestone 2 does, use the following steps instead:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git checkout <span class="nt">-b</span> milestone-2-develop
|
||||
git push <span class="nt">-u</span> origin milestone-2-develop
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>The new <code class="language-plaintext highlighter-rouge">milestone-2-develop</code> branch will be in an identical state to the <code class="language-plaintext highlighter-rouge">milestone-1-develop</code> branch, but changes will only be committed to the <code class="language-plaintext highlighter-rouge">milestone-2-develop</code> branch, leaving the <code class="language-plaintext highlighter-rouge">milestone-1-develop</code> branch as is.
|
||||
Now you have the assignment branch checked out in your local repository and can start working.</p>
|
||||
|
||||
<h3 id="saving-work">Saving work</h3>
|
||||
|
||||
<p>Whenever you have changes that you’d like to save, such as after getting (a part of) the assignment working, you need to add, commit, and push your changes:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git add <span class="nt">--all</span>
|
||||
git commit <span class="nt">-m</span> <span class="s2">"Message describing your changes"</span>
|
||||
git push
|
||||
</code></pre></div></div>
|
||||
|
||||
<h3 id="continuous-integration-ci">Continuous Integration (CI)</h3>
|
||||
|
||||
<p>The template contains a <code class="language-plaintext highlighter-rouge">.gitlab-ci.yml</code> file that configures continuous integration in GitLab.
|
||||
It runs <code class="language-plaintext highlighter-rouge">gradle buildAll</code> on each push to <code class="language-plaintext highlighter-rouge">milestone-*-develop</code>. It also invokes the grader when the project is submitted using a merge request.</p>
|
||||
|
||||
<p>By default, both language projects used for milestones 0-2 are enabled in the gradle build. If, for some reason, building of a project needs to be disabled, the following lines should be commented out in the <code class="language-plaintext highlighter-rouge">settings.gradle.kts</code> file.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>includeLanguageIfExists("chocopy.syntax")
|
||||
includeLanguageIfExists("chocopy.types")
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Enabling the build of your <em>language</em> projects in CI is <strong>recommended</strong> but <strong>not required</strong> when submitting your work.</p>
|
||||
|
||||
<h3 id="submitting-a-milestone">Submitting a milestone</h3>
|
||||
|
||||
<p><a href="https://docs.gitlab.com/ee/gitlab-basics/add-merge-request.html">Merge requests</a> are used to submit a milestone from your <em>develop</em> branch to its corresponding <em>submission</em> branch.</p>
|
||||
|
||||
<p>Make sure you’ve pushed all your changes first, then go to your repository on GitLab.
|
||||
Navigate to <strong>Merge Requests</strong> and click the <strong>New merge request</strong> button:</p>
|
||||
|
||||
<p><img src="../project/2021/00-submissions/new_merge_request.png" alt="New merge request" /></p>
|
||||
|
||||
<p>Select the <em>develop</em> branch as source and its corresponding <em>submission</em> branch as target.
|
||||
Click <em>Compare branches and continue</em>.</p>
|
||||
|
||||
<p>If all is well, you can review your changes and you can press the <code class="language-plaintext highlighter-rouge">Submit merge request</code> button to submit your milestone. If not, check the troubleshooting section.</p>
|
||||
|
||||
<p><img src="../project/2021/00-submissions/merge_request.png" alt="Merge request" /></p>
|
||||
|
||||
<p>We will grade your milestone and post the results as an issue in your project, so check back later.</p>
|
||||
|
||||
<h3 id="switching-to-another-milestone">Switching to another milestone</h3>
|
||||
|
||||
<p>If you’d like to work on an another milestone, for example to fix things for a new submission, you can just check out the branch for that milestone.
|
||||
Be sure to push any changes to your current branch first, then check out the branch for the milestone you wish to switch to:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git checkout milestone-1-develop
|
||||
</code></pre></div></div>
|
||||
|
||||
<h3 id="pulling-in-changes-from-template">Pulling in changes from template</h3>
|
||||
|
||||
<p>If there’s something wrong in the template for a milestone, we fix it in the <em>template</em> branch, and you have to merge in those changes.
|
||||
Use the following commands to merge in changes (use the correct branch!):</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git fetch origin
|
||||
git merge origin/milestone-1-template
|
||||
git push
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>In most cases, Git will automatically merge in any changes, but sometimes conflicts can occur. See <a href="https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/">Resolving a merge conflict</a> on how to resolve conflicts.</p>
|
||||
|
||||
<h3 id="git-gui-clients">Git GUI clients</h3>
|
||||
|
||||
<p>This guide uses command-line Git commands, but if you’d rather use a GUI, use <a href="https://www.sourcetreeapp.com/">SourceTree</a>.</p>
|
||||
|
||||
<h3 id="troubleshooting">Troubleshooting</h3>
|
||||
|
||||
<h4 id="cannot-push">Cannot push</h4>
|
||||
|
||||
<p><strong>No access/rights</strong></p>
|
||||
|
||||
<p>When Git complains about not being able to push because you do not have access or rights to the repository, this probably means that you’re trying to push to a <em>template</em> or <em>submission</em> branch rather than a <em>develop</em> branch.</p>
|
||||
|
||||
<p><strong>Out of date branch</strong></p>
|
||||
|
||||
<p>You cannot push changes to a remote when that remote has changes that you haven’t yet pulled, you’ll get an error like:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git push
|
||||
To ...
|
||||
<span class="o">!</span> <span class="o">[</span>rejected] milestone-1-develop -> milestone-1-develop <span class="o">(</span>non-fast-forward<span class="o">)</span>
|
||||
error: failed to push some refs to <span class="s1">'...'</span>
|
||||
hint: Updates were rejected because the tip of your current branch is behind
|
||||
hint: its remote counterpart. Integrate the remote changes <span class="o">(</span>e.g.
|
||||
hint: <span class="s1">'git pull ...'</span><span class="o">)</span> before pushing again.
|
||||
hint: See the <span class="s1">'Note about fast-forwards'</span> <span class="k">in</span> <span class="s1">'git push --help'</span> <span class="k">for </span>details.
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>First pull changes with <code class="language-plaintext highlighter-rouge">git pull</code> and then push your changes.</p>
|
||||
|
||||
<h4 id="cannot-pull">Cannot pull</h4>
|
||||
|
||||
<p><strong>Local changes</strong></p>
|
||||
|
||||
<p>When you have changes in your local repository that you have not committed yet, and you try to pull, Git may complain about your changes being overwritten.
|
||||
First add and commit your changes locally with:</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git add <span class="nt">--all</span>
|
||||
git commit <span class="nt">-m</span> <span class="s2">"Message describing your changes"</span>
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>and then pull changes with <code class="language-plaintext highlighter-rouge">git pull</code>.</p>
|
||||
|
||||
<h4 id="cannot-automatically-merge-merge-request">Cannot automatically merge merge request</h4>
|
||||
|
||||
<p>If a merge request cannot be automatically merged, your branch is out of date with the <em>template</em> branch.
|
||||
Merge in changes from the template (use the correct branch!):</p>
|
||||
|
||||
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git fetch origin
|
||||
git merge origin/milestone-1-template
|
||||
git push
|
||||
</code></pre></div></div>
|
||||
|
||||
<h4 id="resolving-merge-conflicts">Resolving merge conflicts</h4>
|
||||
|
||||
<p>See <a href="https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/">Resolving a merge conflict</a> on how to resolve merge conflicts.
|
||||
You can also try a GUI merge tool such as <a href="https://sourcegear.com/diffmerge/">DiffMerge</a> to resolve merge conflicts.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1c.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/0.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#git">Git</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#repository-structure">Repository Structure</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#getting-started">Getting started</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#starting-an-assignment">Starting an assignment</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#template">Template</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#continue-from-previous-assignment">Continue from previous assignment</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#saving-work">Saving work</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#continuous-integration-ci">Continuous Integration (CI)</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#submitting-a-milestone">Submitting a milestone</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#switching-to-another-milestone">Switching to another milestone</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#pulling-in-changes-from-template">Pulling in changes from template</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#git-gui-clients">Git GUI clients</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#troubleshooting">Troubleshooting</a>
|
||||
<ul class="toc-sub pl-0">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#cannot-push">Cannot push</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#cannot-pull">Cannot pull</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#cannot-automatically-merge-merge-request">Cannot automatically merge merge request</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1d.html#resolving-merge-conflicts">Resolving merge conflicts</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1c.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/0.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
1060
lab/2.html
Normal file
1060
lab/2.html
Normal file
File diff suppressed because it is too large
Load diff
895
lab/3a.html
Normal file
895
lab/3a.html
Normal file
|
|
@ -0,0 +1,895 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 3(a): Setting up Static Analysis</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
<a href="https://tudelft-cs4200.github.io/2021">
|
||||
<img class="border border-dark" width="100%" src="../project/2021/00-lab1a/spoofax.png"/>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 3(a): Setting up Static Analysis
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project Set-up
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 22, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>In this lab, you define the static analysis of ChocoPy in Spoofax.
|
||||
Follow the instructions from <a href="https://tudelft-cs4200.github.io/2021/lab/1a/">Lab 1(a)</a> for using Spoofax.</p>
|
||||
|
||||
<h4 id="modifying-the-static-analysis">Modifying the Static Analysis</h4>
|
||||
|
||||
<p>Static analysis is implement in the Statix language of Spoofax.
|
||||
The <code class="language-plaintext highlighter-rouge">/src/main.stx</code> file is the main Statix file.
|
||||
You can define static analysis rules in this main file, but it is probably a good idea to distribute your Statix definition over multiple modules, as Statix is a modular language.
|
||||
If you create new modules, you must import them into <code class="language-plaintext highlighter-rouge">/src/main.stx</code>.</p>
|
||||
|
||||
<h3 id="references">References</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="list-group list-group-flush pb-3">
|
||||
|
||||
|
||||
<li class="list-group-item pl-lg-0 border-0 pb-0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bd-callout border-success pl-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<a name="Spoofax3"></a>
|
||||
|
||||
<a class="font-weight-bold text-dark" target="_blank" href="https://www.spoofax.dev/spoofax-pie/develop/">Spoofax 3 (Documentation) </a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light" style="font-size:90%;">
|
||||
|
||||
(editor).
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
|
||||
|
||||
|
||||
|
||||
https://www.spoofax.dev/spoofax-pie/develop/ 2021
|
||||
|
||||
|
||||
|
||||
[<a class="text-secondary" target="_blank" href="https://researchr.org/publication/Spoofax3/bibtex">bib</a>, <a href="https://researchr.org/publication/Spoofax3" class="text-secondary" target="_blank">researchr</a>]
|
||||
|
||||
<!-- Spoofax3 -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="list-group-item pl-lg-0 border-0 pb-0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bd-callout border-success pl-3">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<a name="Spoofax2021"></a>
|
||||
|
||||
<a class="font-weight-bold text-dark" target="_blank" href="https://www.spoofax.dev/">Spoofax: The Language Designer's Workbench</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light" style="font-size:90%;">
|
||||
|
||||
(editor).
|
||||
</div>
|
||||
|
||||
<div class="font-weight-light text-secondary" style="font-size:90%;">
|
||||
|
||||
|
||||
|
||||
|
||||
https://www.spoofax.dev/ 2021
|
||||
|
||||
|
||||
|
||||
[<a class="text-secondary" target="_blank" href="https://researchr.org/publication/Spoofax2021/bibtex">bib</a>, <a href="https://researchr.org/publication/Spoofax2021" class="text-secondary" target="_blank">researchr</a>]
|
||||
|
||||
<!-- Spoofax2021 -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="2.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3b.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3a.html#modifying-the-static-analysis">Modifying the Static Analysis</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="2.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3b.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
615
lab/3b.html
Normal file
615
lab/3b.html
Normal file
|
|
@ -0,0 +1,615 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 3(b): Creating Static Analysis Tests</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 3(b): Creating Static Analysis Tests
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 22, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Before getting started with your static analysis definition, you set up a test suite for static analysis. Develop the test suite in tandem with the development of your static analysis. The test suite consists of positive and negative test cases. We will not grade this test suite, but you should develop one to get confidence in the quality of your static analysis. When you are asking for help from the course staff, we will first ask what tests you have written to demonstrate the problem.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<p>In your chocopy project, develop a test suite for static analysis. The test suite should provide</p>
|
||||
|
||||
<ol>
|
||||
<li>Test cases for types</li>
|
||||
<li>Test cases for name resolution</li>
|
||||
<li>Test cases for errors</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="testing-type-constraints">Testing Type Constraints</h3>
|
||||
|
||||
<p>See the example tests in the WebLab homework assignments for Week 3.</p>
|
||||
|
||||
<h3 id="testing-reference-resolution">Testing Reference Resolution</h3>
|
||||
|
||||
<p>In test cases for reference resolution,
|
||||
you write syntactically correct programs and
|
||||
mark names at definition and use sites with inner square bracket blocks.
|
||||
You can then relate the use site with the definition site in a <code class="language-plaintext highlighter-rouge">resolve x to y</code> clause,
|
||||
using numbers to refer to the inner blocks.
|
||||
For example, the following two test cases require to resolve the type <code class="language-plaintext highlighter-rouge">Foo</code> to the name in the definition of class <code class="language-plaintext highlighter-rouge">Foo</code>:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module resolution
|
||||
|
||||
test class name resolution[[
|
||||
class [[A]](object):
|
||||
pass
|
||||
|
||||
class B(object):
|
||||
a:[[A]] = None
|
||||
]] resolve #2 to #1
|
||||
|
||||
test class field resolution[[
|
||||
class Foo(object):
|
||||
[[bar]]:int = 0
|
||||
|
||||
foo:Foo = None
|
||||
foo = Foo()
|
||||
print(foo.[[bar]])
|
||||
]] resolve #2 to #1
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>After copying this into an SPT file Spoofax will add the error <em>“Reference resolution failed”</em> and <em>“No constraint generation rule for …“</em>. This is expected, since your project is missing an implementation for reference resolution (this is part of the next lab).</p>
|
||||
|
||||
<p>You can use <em>fixtures</em> to avoid repeating parts in similar test cases. See the SPT documentation for details.</p>
|
||||
|
||||
<p>You should come up with test cases for the resolution of class names, field names, parameter names, and variable names.
|
||||
Start with simple test cases, but keep in mind that coverage is the main criterion for your grade.
|
||||
It is important to think about
|
||||
forward and backward references,
|
||||
global and non-local declarations in functions,
|
||||
and resolution in the presence of homonyms.</p>
|
||||
|
||||
<p class="notice notice-warning">Make sure that there are no errors in tests with a <code class="language-plaintext highlighter-rouge">resolve x to y</code> clause, these tests are invalid when there are errors.</p>
|
||||
|
||||
<h3 id="testing-error-checking">Testing Error Checking</h3>
|
||||
|
||||
<p>In test cases for error checking, you need to specify the number of errors, warnings, or notes in a
|
||||
test case in <code class="language-plaintext highlighter-rouge">errors</code>, <code class="language-plaintext highlighter-rouge">warnings</code>, or <code class="language-plaintext highlighter-rouge">notes</code> clauses. For example, the following test cases
|
||||
specify a correct ChocoPy program, a program with two errors which are reported on the name of a
|
||||
duplicate class <code class="language-plaintext highlighter-rouge">Foo</code>, and another program with an error which is reported on the name of an unknown
|
||||
class <code class="language-plaintext highlighter-rouge">Bar</code>:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module correctness
|
||||
|
||||
language chocopy
|
||||
|
||||
test correct program [[
|
||||
class Counter(object):
|
||||
count:int = 0
|
||||
|
||||
def getCount(self:Counter)->int:
|
||||
return self.count
|
||||
|
||||
def increaseCount(self:Counter):
|
||||
self.count = self.count + 1
|
||||
]] 0 errors
|
||||
|
||||
test incorrect program [[
|
||||
class Counter(object):
|
||||
count:bool = False
|
||||
|
||||
def getCount(self:Counter)->int:
|
||||
return self.count
|
||||
|
||||
def increaseCount(self:Counter):
|
||||
self.count = self.count + 1
|
||||
]] >= 1 errors // or 3 errors
|
||||
|
||||
test error on unknown class [[
|
||||
class Foo(object):
|
||||
bar:Bar = None
|
||||
]] >= 1 errors
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>You can start with test cases for duplicate and missing definitions. Similar to your syntax test
|
||||
cases, you can pair up positive (<code class="language-plaintext highlighter-rouge">0 errors</code>) and negative test cases. For duplicate definitions, we
|
||||
expect errors on the definitions with the same name.</p>
|
||||
|
||||
<p class="notice notice-warning">The number of errors can be hard to predict, because errors sometimes cascade. Therefore, if you
|
||||
expect any errors, you should use the <code class="language-plaintext highlighter-rouge">>= 1 errors</code> expectation, even if you expect a specific
|
||||
number of errors. For example, this expectation was used in the duplicate class test, even though we
|
||||
would expect exactly two errors.</p>
|
||||
|
||||
<p>Next, you should develop test cases for fields and variables which hide global variables, global and non-local declarations, and class
|
||||
instantiation, subclassing, referencing. Again, you should keep in mind that coverage is the main
|
||||
criterion for your grade.</p>
|
||||
|
||||
<h3 id="testing-types-of-expressions">Testing Types of Expressions</h3>
|
||||
|
||||
<p>In test cases for type analysis,
|
||||
you write syntactically correct programs and
|
||||
mark expressions with inner square bracket blocks.
|
||||
You can then specify the expected type of the marked expression in a <code class="language-plaintext highlighter-rouge">run x to y</code> clause.
|
||||
For example, the following two test cases require an integer literal to be of type <code class="language-plaintext highlighter-rouge">Int()</code>
|
||||
and a variable reference to be of its declared type <code class="language-plaintext highlighter-rouge">Bool()</code>:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module types
|
||||
|
||||
test integer literal [[
|
||||
print([[1]])
|
||||
]] run get-type on #1 to Int()
|
||||
|
||||
test boolean condition [[
|
||||
b1:bool = True
|
||||
b2:bool = False
|
||||
if [[b1 and b2]]:
|
||||
print("Yes!")
|
||||
]] run get-type on #1 to Bool()
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>In order for these tests to succeed, you need to define your own Stratego rule <code class="language-plaintext highlighter-rouge">get-type</code>. For this, you can copy and paste the following code into <code class="language-plaintext highlighter-rouge">src/main.str2</code></p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>signature
|
||||
sorts
|
||||
Type
|
||||
|
||||
constructors
|
||||
Int : Type
|
||||
Bool : Type
|
||||
String : Type
|
||||
ClassType : scope * ID -> Type
|
||||
List : Type -> Type
|
||||
NoneType : Type
|
||||
EmptyList : Type
|
||||
Object : Type
|
||||
FunType : Type * list(Type) -> Type
|
||||
// We expect to get these types in the grading pipeline
|
||||
// you are free to use your own (custom) types in your Statix file
|
||||
// as long as you write transformation rules from your types to our types
|
||||
// in resolve-type
|
||||
|
||||
// Here you can define the signature of the types you have used in your Statix definitions.
|
||||
// This is just an example on how to do it.
|
||||
// signature
|
||||
// sorts
|
||||
// MyCustomType
|
||||
//
|
||||
// constructors
|
||||
// MyCustomIntType : MyCustomType
|
||||
// MyCustomClassType : ID * scope -> MyCustomType
|
||||
|
||||
rules
|
||||
// get-type: SimpleStatement(expr) -> <get-type> expr // An example on how to match on AST nodes.
|
||||
get-type: expr -> type' // Defines a rule which matches on node and returns type'
|
||||
where
|
||||
// Assigns variable a to be the result of the Statix analysis of the entire program (or throws an error)
|
||||
a := <stx-get-ast-analysis <+ fail-msg(|$[no analysis on node [<strip-annos;write-to-string> expr]])>;
|
||||
// Gets the type of the given node (or throws an error)
|
||||
type := <stx-get-ast-type(|a) <+ fail-msg(|$[no type on node [<strip-annos;write-to-string> expr]])> expr;
|
||||
// Calls a rule to convert the type given by Statix to a type for our tests.
|
||||
type' := <resolve-type> type
|
||||
|
||||
// resolve-type: MyCustomIntType() -> Int() // This rule matches on your custom type, and returns a type we need in our tests.
|
||||
// resolve-type: MyCustomClassType(name, scope) -> ClassType(scope, name) // This rule matches on your custom type, and returns a type we need in our tests.
|
||||
// TODO: Define your own transformation rules to transform types from your Statix defintion to the types we expect in our tests
|
||||
resolve-type: a -> a // This rule matches on a and returns a (trivial rule given as example). This implies no transformation actually takes place. Define your own rules ABOVE this rule.
|
||||
|
||||
fail-msg(|msg) = err-msg(|$[get-type: [msg]]); fail
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>This code defines a Stratego rule <code class="language-plaintext highlighter-rouge">get-type</code> which we can use to map AST Nodes to their types using the results of the Statix analysis. In our tests for the Early Feedback and Grading, we expect certain types, so it is highly recommended to use the same types in your Statix rules. If not, you might need to perform some extra transformations from your types to our types in the <code class="language-plaintext highlighter-rouge">resolve-type</code> rule.</p>
|
||||
|
||||
<p>For more information on the Stratego language, visit the Stratego documentation.</p>
|
||||
|
||||
<p>You can use <em>fixtures</em> to avoid repeating parts in similar test cases. See the
|
||||
SPT documentation
|
||||
for details.</p>
|
||||
|
||||
<p>When applying <code class="language-plaintext highlighter-rouge">get-type</code> to objects, we expect a <code class="language-plaintext highlighter-rouge">ClassType</code> constructor.</p>
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>test class type [[
|
||||
class Foo(object):
|
||||
pass
|
||||
[[Foo()]]
|
||||
]] run get-type on #1 to ClassType(_, "Foo") // We don't care about the scope, only the classname.
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>You should come up with test cases for the types of all kinds of expressions. Just like previous
|
||||
testing assignments, this assignment is all about the coverage of your test suite.</p>
|
||||
|
||||
<p>The constructors for various types are:</p>
|
||||
|
||||
<ul>
|
||||
<li>Integer: <code class="language-plaintext highlighter-rouge">Int()</code></li>
|
||||
<li>Boolean: <code class="language-plaintext highlighter-rouge">Bool()</code></li>
|
||||
<li>String: <code class="language-plaintext highlighter-rouge">String()</code></li>
|
||||
<li>List of Type T: <code class="language-plaintext highlighter-rouge">List(T)</code></li>
|
||||
<li>Empty list type: <code class="language-plaintext highlighter-rouge">EmptyList()</code></li>
|
||||
<li>None type: <code class="language-plaintext highlighter-rouge">NoneType()</code></li>
|
||||
<li>Class with name Foo and scope s: <code class="language-plaintext highlighter-rouge">ClassType(s, "Foo")</code></li>
|
||||
<li>Function with return Type RT and a list of parameter types PTs: <code class="language-plaintext highlighter-rouge">FunType(RT, PTs)</code></li>
|
||||
<li>Object: <code class="language-plaintext highlighter-rouge">Object()</code></li>
|
||||
</ul>
|
||||
|
||||
<p class="notice notice-warning">Tests that contain a <code class="language-plaintext highlighter-rouge">run x to y</code> clause are invalid if the semantic analysis yields errors. Ensure that the snippet of ChocoPy that you are testing does not contain any errors if you want to use <code class="language-plaintext highlighter-rouge">get-type</code> or other strategies.</p>
|
||||
|
||||
<p class="notice notice-warning">If you use a start symbol other than <code class="language-plaintext highlighter-rouge">Program</code>, replace any samples in this guide that use <code class="language-plaintext highlighter-rouge">Program</code> with your start symbol instead.</p>
|
||||
|
||||
<p>Make sure to actually append your AST nodes with their types using <code class="language-plaintext highlighter-rouge">@x.type := T</code> (in a similar way to assigning the <code class="language-plaintext highlighter-rouge">ref</code> property, which is needed for name resolution). Otherwise the rule will not find any types on your AST node.</p>
|
||||
|
||||
<h3 id="testing-method-name-resolution">Testing Method Name Resolution</h3>
|
||||
|
||||
<p>Consider the following test case as an example:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>test method name resolution [[
|
||||
class Foo(object):
|
||||
def [[run]](self:Foo)->int:
|
||||
return 1
|
||||
Foo().[[run]]()
|
||||
]] resolve #2 to #1
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>The type of the callee expression determines the class in which the method declaration can be found.
|
||||
In this example, the expression <code class="language-plaintext highlighter-rouge">Foo()</code> is of type <code class="language-plaintext highlighter-rouge">ClassType(_, "Foo")</code> and
|
||||
the corresponding class <code class="language-plaintext highlighter-rouge">Foo</code> contains a method declaration for <code class="language-plaintext highlighter-rouge">run()</code>.</p>
|
||||
|
||||
<p>You should come up with test cases for the resolution of method names.
|
||||
Start with simple test cases, but keep in mind that method name resolution is quite complex
|
||||
and that coverage is the main criterion for your grade.
|
||||
It is important to think about forward and backward references,
|
||||
resolution in the presence of homonyms and overriding,
|
||||
and the influence of class hierarchies on resolution.</p>
|
||||
|
||||
<p>You should also come up with test cases for error checking on method names.
|
||||
This should include test cases for errors on duplicate definitions, missing definitions, and method overloading.
|
||||
Similar to previous test cases, you can pair up positive (<code class="language-plaintext highlighter-rouge">0 errors</code>) and negative test cases.</p>
|
||||
|
||||
<p class="notice notice-warning">Make sure that there are no errors in tests with a <code class="language-plaintext highlighter-rouge">resolve x to y</code> clause. These tests are invalid when there are errors.</p>
|
||||
|
||||
<h3 id="testing-type-error-checking">Testing Type Error Checking</h3>
|
||||
|
||||
<p>A type error occurs, when the type of an expression does not conform to its expected type.
|
||||
Consider the following test case as an example:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>test print boolean [[
|
||||
def printInt(i:int):
|
||||
print(i)
|
||||
printInt(True)
|
||||
]] 1 error
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Type errors can occur in statements, expressions, and method declarations.
|
||||
You should come up with test cases for such errors.
|
||||
Subtyping is a common source for errors not only in programs, but also in language implementations.
|
||||
It is therefore important to have positive and negative typing tests, which involve correct and incorrect subtyping.</p>
|
||||
|
||||
<p>Again, keep in mind that coverage is the main criterion for your grade.</p>
|
||||
|
||||
<h3 id="number-of-errors">Number of errors</h3>
|
||||
|
||||
<p>Similar to the previous testing lab, you need to be careful about the number of errors, because
|
||||
errors sometimes cascade. For example, if you expect <em>2</em> errors, you should use the <code class="language-plaintext highlighter-rouge">>= 2 errors</code>
|
||||
expectation, even if you expect an exact number of errors.</p>
|
||||
|
||||
<h3 id="a-final-note">A final note</h3>
|
||||
<p>A great way of testing expected ChocoPy behavior, when you want to know whether something is allowed or not, is to try it out on the <a href="https://chocopy.org/">ChocoPy Website</a></p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3a.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3c.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#objectives">Objectives</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-type-constraints">Testing Type Constraints</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-reference-resolution">Testing Reference Resolution</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-error-checking">Testing Error Checking</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-types-of-expressions">Testing Types of Expressions</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-method-name-resolution">Testing Method Name Resolution</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#testing-type-error-checking">Testing Type Error Checking</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#number-of-errors">Number of errors</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="3b.html#a-final-note">A final note</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3a.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3c.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
332
lab/3c.html
Normal file
332
lab/3c.html
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 3(c): Simple Types</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 3(c): Simple Types
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 22, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Read Section 4 of the <a href="https://tudelft-cs4200.github.io/labl/0a">ChocoPy Reference Manual</a> with the type rules of the language.
|
||||
In the remaining labs of the course, you will translate those type rules into formal Statix rules in order to implement a type checker.
|
||||
You should submit the result, a complete type system implementation of ChocoPy in Statix, in <a href="../milestone/2.html">Milestone 2</a>.
|
||||
You can proceed at your own pace, but in this and the following lab descriptions, we give some ideas for ordering the task.</p>
|
||||
|
||||
<p>In this lab, follow <a href="../lecture/4.html">Lecture 4</a> and the homework assignments for <a href="../homework/1-3.html">Week 3</a> to define a predicate (say <code class="language-plaintext highlighter-rouge">typeOfExp</code>) to test the type correctness of expressions without names (variables, functions).</p>
|
||||
|
||||
<p>For more information on Statix, see also the <a href="https://www.spoofax.dev/references/statix/">Spoofax 2 documentation on Statix</a>. Most of the information in this document will also apply to Spoofax 3.</p>
|
||||
|
||||
<p>For now, ignore the contexts in the typing rules. You can see (by tracing the rules) that for expressions not involving names, those contexts are irrelevant. In the predicate, you can either leave the context out entirely, or you can pass around a dummy ‘scope’. (We will study scopes in the next lecture.)
|
||||
In the latter case, you need to figure out how to create the dummy scope. In the former case you will need to add scopes later, but that should be a simple find-and-replace action.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3b.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/1.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="3b.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/1.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
318
lab/4.html
Normal file
318
lab/4.html
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 4: Local Names</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 4: Local Names
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
September 29, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>In this lab, follow <a href="../lecture/5.html">Lecture 5</a> and the homework assignments for <a href="../homework/1-4.html">Week 4</a> to extend the type checking predicates with name resolution.</p>
|
||||
|
||||
<p>Continue your study of Section 4 of the <a href="0a.html">ChocoPy Reference Manual</a> with the type rules of the language.</p>
|
||||
|
||||
<p>Start with the definition of local variable declarations and variable references in this first lab. Next add formal parameters of functions.</p>
|
||||
|
||||
<p>Define test cases to validate your definition. Make sure to test for shadowing of variables. Did you implement the correct visibility policy in your resolution queries?</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/1.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="5.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/1.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="5.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
311
lab/5.html
Normal file
311
lab/5.html
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 5: Functions and Classes</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 5: Functions and Classes
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
October 06, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>Continue your study of Section 4 of the <a href="https://tudelft-cs4200.github.io/2021/labl/0a">ChocoPy Reference Manual</a> with the type rules of the language.</p>
|
||||
|
||||
<p>Finish the definition of local variables and function parameters (<a href="4.html">Lab 4</a>).</p>
|
||||
|
||||
<p>Move on to definition of function definitions and function calls, classes with inheritance, method definitions, and method calls.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="4.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="6.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="4.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="6.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
304
lab/6.html
Normal file
304
lab/6.html
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 6: Preparing Milestone 2 Submission (2020)</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 6: Preparing Milestone 2 Submission (2020)
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
October 13, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>You have two labs left until the <a href="../milestone/2.html">Milestone 2</a>.</p>
|
||||
|
||||
<p>Make sure to test the corner cases of type checking ChocoPy and use the early feedback to see how well you are doing.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="5.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="7.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="5.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="7.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
299
lab/7.html
Normal file
299
lab/7.html
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 7: Finish Front-End (2020)</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 7: Finish Front-End (2020)
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
October 20, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>You have one lab left until the <a href="../milestone/2.html">Milestone 2</a>.</p>
|
||||
|
||||
<p>Make sure to test the corner cases of type checking ChocoPy and use the early feedback to see how well you are doing.</p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="6.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/2.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="6.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/2.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
659
lab/8.html
Normal file
659
lab/8.html
Normal file
|
|
@ -0,0 +1,659 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 8: Simple Transformation</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 8: Simple Transformation
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
November 12, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>During this lab get to know Stratego by making the <a href="https://weblab.tudelft.nl/cs4200/2021-2022/assignment/88076/view">homework assignments for Week 1</a> either in Spoofax 3 or in WebLab.</p>
|
||||
|
||||
<!--
|
||||
|
||||
This lab is your first encounter with Stratego.
|
||||
You add an outline view and a desugaring transformation to an initial editor provided by us.
|
||||
|
||||
|
||||
### Objectives
|
||||
|
||||
1. Specify rewrite rules `to-outline-label` which map AST nodes to labels in an outline view. You should include:
|
||||
* classes (class name and, if available, parent class name),
|
||||
* fields (field name and type),
|
||||
* methods (method name, parameter types, return type) and
|
||||
* local variables (variable name and type).
|
||||
2. Define rewrite rules `desugar` which desugar
|
||||
* unary expressions into terms of the form `UnExp(op, exp)`,
|
||||
* binary expressions into terms of the form `BinExp(op, exp1, exp2)` and
|
||||
3. Integrate `desugar` into a strategy `desugar-all` which desugars subtrees in an AST.
|
||||
|
||||
For grading, it is required to comply with all constructor names, rule names, and strategy names literally.
|
||||
|
||||
<!-- ### Submission
|
||||
|
||||
You need to submit your ChocoPy project with a merge request against branch `assignment-3-submission` on GitLab.
|
||||
The [Git documentation](/project/lab1d) explains how to file such a request. -->
|
||||
|
||||
<!-- ### Early Feedback
|
||||
|
||||
We provide early feedback for the correctness of your outline and desugarings.
|
||||
This feedback is a score out of 90 points; the strategy choice (10 points) is graded manually.
|
||||
You have 3 early feedback attempts. -->
|
||||
|
||||
<!--
|
||||
### Preliminaries
|
||||
|
||||
#### GitLab Repository
|
||||
|
||||
We provide you with a template for this assignment.
|
||||
See the [Git documentation](/2021/lab/1d) on how to check out this branch.
|
||||
Make sure to read the `README.md` in the root of the repository, as it contains further instructions that are specific to this template.
|
||||
|
||||
#### Anatomy of a Spoofax Project
|
||||
|
||||
Until now, you mainly worked on files in the `syntax` folder of your project.
|
||||
During this lab you will also edit files in the `trans` folder.
|
||||
So, this is a good point to talk about the general structure of a Spoofax project.
|
||||
Note: this general structure does not apply to the template we've given you for the project, considering it contains a compiled version of the front-end already.
|
||||
|
||||
First of all, every Spoofax project may be part of an Eclipse plug-in project.
|
||||
This allows you to deploy your editor as a plugin using the Eclipse update site mechanism.
|
||||
Users do not need to have Spoofax installed for using your editor.
|
||||
|
||||
The actual language definition is spread over three folders:
|
||||
|
||||
* `syntax` contains all syntax definition files, including the main file `chocopy.sdf3`.
|
||||
* `trans` contains all transformation files, including the main file `chocopy.str`.
|
||||
* `editor` contains editor service definition files, including the main file `Main.esv`.
|
||||
|
||||
In the `src-gen` folder, you will find files which were generated from your syntax definition.
|
||||
For each file `<name>.sdf3`, there are generated files:
|
||||
|
||||
* `syntax/<name>.sdf`: an SDF2 definition which is equivalent to the SDF3 definition.
|
||||
* `completions/<name>-cp.str`: abstract placeholder expansions for syntactic code completion derived from SDF3 templates.
|
||||
* `completions/colorer/<name>-cc-esv.esv`: instructions to color placeholders for syntactic completions in gray.
|
||||
* `pp/<name>-pp.str`: pretty-printing strategies derived from SDF3 templates.
|
||||
* `signatures/<name>-sig.str`: signatures derived from SDF3 templates.
|
||||
|
||||
You can find more generated files in `src-gen` and `target/metaborg` folders:
|
||||
|
||||
* `src-gen/syntax/ChocoPy.def`: your complete syntax definition in SDF2.
|
||||
* `src-gen/syntax/ChocoPy-Permissive.def`: a permissive version of the syntax definition, which supports error recovery.
|
||||
* `target/metaborg/ChocoPy.tbl`: the parse table of your language.
|
||||
* `src-gen/pp/ChocoPy-parenthesize.str`: strategies to add parentheses to an AST according to the priorities of your language.
|
||||
* `target/metaborg/stratego.ctree` and/or `target/metaborg/stratego.jar`: compiled Stratego code of your language.
|
||||
|
||||
#### Initial Editor Project
|
||||
|
||||
We provide you with an initial ChocoPy project in the branch `milestone-3-template`.
|
||||
This project is a common starting point for all of you.
|
||||
It includes:
|
||||
|
||||
* A compiled version of a front-end ChocoPy project.
|
||||
* corresponding signatures `reference/src-gen/signatures/*-sig.str`,
|
||||
* pretty-printing definitions `reference/src-gen/pp/*-pp.str`, and a
|
||||
* content-completion definitions `reference/src-gen/completion/*-cp.str` (errors in the completion files can be ignored).
|
||||
|
||||
During the building of the project the contents of `reference` will be copied over to `src-gen`.
|
||||
So, when importing any module from the reference, you can just use the 'local' variant.
|
||||
I.e. instead of importing `reference/src-gen/signatures/chocopy-sig`, please import `signatures/chocopy-sig`.
|
||||
|
||||
#### Signature
|
||||
|
||||
Signatures declare sorts and constructors for terms.
|
||||
In Spoofax, terms are used to represent abstract syntax trees.
|
||||
The corresponding signature is generated from the constructors in a syntax definition.
|
||||
You can find the signature for ChocoPy in the files `reference/src-gen/signatures/*-sig.str`.
|
||||
The signature was generated from a syntax definition, which itself is not included in the initial project.
|
||||
If you write your own syntax definition, the generated signatures can be found in `src-gen/signatures/`.
|
||||
|
||||
### Outline View
|
||||
|
||||
#### Rewrite Rules
|
||||
|
||||
An outline view can be specified by rewrite rules `to-outline-label` in `trans/outline.str`.
|
||||
These rules should rewrite AST nodes to their label in an outline view.
|
||||
For example, the following rule rewrites a variable declaration to its name, which will be used as a label.
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
to-outline-label: Var(t, v) -> v
|
||||
```
|
||||
|
||||
On the left-hand side, the rule matches a variable declaration.
|
||||
During the match, variables `t` and `v` are bound to actual terms.
|
||||
On the right-hand side, the rule instantiates a label.
|
||||
During the instantiation, variable `v` is replaced with the term it is bound to.
|
||||
You can extend `to-outline-label` to provide labels for
|
||||
|
||||
* class declarations,
|
||||
* field declarations and
|
||||
* method declarations.
|
||||
|
||||
When you build the project and open a ChocoPy file, you will get an outline of this program in the outline view.
|
||||
In case you do not see any outline view, you can select it in *Show View* from Eclipse's *Window* menu.
|
||||
|
||||
#### Naming Conventions
|
||||
|
||||
In Stratego, we use the following naming conventions:
|
||||
|
||||
* constructor and sort names: camel case, starting with an upper case (e.g. `Add`, `BinExp`)
|
||||
* rule names, strategy names, variable names: lower case, multiple words separated by `-` (e.g. `e1`, `project-path`)
|
||||
|
||||
#### String Interpolation
|
||||
|
||||
In many cases, you want to provide more information than just the name.
|
||||
For example, you might want to show not only a variable's name, but also it's type.
|
||||
The following rule achieves this:
|
||||
|
||||
```
|
||||
to-outline-label:
|
||||
Var(t, v) -> label
|
||||
where
|
||||
t' := <pp-partial-ChocoPy-string> t
|
||||
; label := <concat-strings> [v, ": ", t']
|
||||
```
|
||||
|
||||
On its right-hand side, it produces a `label`, which is bound in the `where` clause.
|
||||
First, the term bound to `t` is turned into a string bound to `t'` by applying a strategy `pp-partial-ChocoPy-string`.
|
||||
This strategy is defined in `ChocoPy/trans/pp.str` and uses the pretty-printing rules generated from our SDF3 grammar for ChocoPy.
|
||||
|
||||
Next, the label is bound to the concatenation of
|
||||
the string bound to `v`,
|
||||
a constant string `": "`,
|
||||
and the string bound to `t'`.
|
||||
|
||||
String concatenation is not very intuitive.
|
||||
Instead, you can also use string interpolation:
|
||||
|
||||
```
|
||||
to-outline-label:
|
||||
Var(t, v) -> $[[v]: [t']]
|
||||
where
|
||||
t' := <pp-partial-ChocoPy-string> t
|
||||
```
|
||||
|
||||
String interpolation allows you to combine text with variables.
|
||||
Text is enclosed in `$[` and `]`, while variables inside the text are enclosed in `[` and `]`.
|
||||
These variables need to be bound to strings.
|
||||
|
||||
You should provide the following information in your outline labels:
|
||||
|
||||
* class name and super class name
|
||||
* field name and type
|
||||
* method name, parameter types (not parameter names), return type
|
||||
* variable name and type
|
||||
|
||||
For parameter types, you need to turn a list of parameters into a string.
|
||||
You can do this with a recursive strategy:
|
||||
|
||||
```
|
||||
pp-params: // empty parameter list
|
||||
[] -> ...
|
||||
|
||||
pp-params: // single parameter
|
||||
[TypedVar(p, t)] -> ...
|
||||
|
||||
pp-params: // at least two parameters
|
||||
[TypedVar(p, t), param | params] -> ...
|
||||
where
|
||||
// do something on first parameter
|
||||
...
|
||||
// recursive call on remaining parameters
|
||||
... := <pp-params> [param | params]
|
||||
```
|
||||
|
||||
For grading, it is required to define a strategy `pp-params` that always rewrites a list of `TypedVar`s to a *string*.
|
||||
{: .notice .notice-warning}
|
||||
|
||||
Your current outline view is missing a root node.
|
||||
You can add a root node by providing a label for programs.
|
||||
|
||||
#### Annotations
|
||||
|
||||
In Stratego, terms can be annotated with additional information.
|
||||
The Spoofax outline view uses annotations to determine the icon of a node.
|
||||
You can specify the icon to use in an annotation:
|
||||
|
||||
```
|
||||
to-outline-label:
|
||||
Var(t, v) -> label{icon}
|
||||
where
|
||||
t' := <pp-partial-ChocoPy-string> t
|
||||
; label := $[[v]: [t']]
|
||||
; icon := "icons/var.gif"
|
||||
```
|
||||
|
||||
We do not require you to use icons and you will not earn any points with them.
|
||||
If you want to use them anyway, you should put the icons into the folder `icons`
|
||||
and place a proper attribution or license file next to them.
|
||||
|
||||
#### Challenge
|
||||
|
||||
Challenges are meant to distinguish excellent solutions from good solutions.
|
||||
Typically, they are less guided and require more investigation or higher programming skills.
|
||||
{: .notice .notice-success}
|
||||
|
||||
|
||||
1. Provide the file name as the root node label. In `outline.str`: import, command/control click and study `libspoofax/term/origin` for a suitable strategy.
|
||||
|
||||
2. Outline the main method as a subnode of the main class.
|
||||
You need to change this strategy in the `outline.str` file:
|
||||
|
||||
```
|
||||
outline := <custom-label-outline(to-outline-label, to-outline-node)> ast
|
||||
```
|
||||
|
||||
Also import, command/control click, and investigate `libspoofax/editor/outline` for inspiration.
|
||||
|
||||
3. Use one of the library strategies for folding to implement `pp-params`. You can find various folding strategies in the [API docs](http://releases.strategoxt.org/docs/api/libstratego-lib/stable/docs/).
|
||||
|
||||
### Desugaring
|
||||
|
||||
A uniform representation of unary and binary expressions eases static analysis and code generation.
|
||||
To get such a uniform representation, you need to desugar abstract syntax trees during the analysis phase.
|
||||
|
||||
#### Signature
|
||||
|
||||
Before you can implement a desugaring,
|
||||
you need to define a signature for the uniform representation of expressions in `trans/desugar.str`:
|
||||
|
||||
1. Identify unary and binary expressions in ChocoPy.
|
||||
A unary expression has one subexpression and an operator.
|
||||
A binary expression has two subexpressions and an operator.
|
||||
There are more than one kind of unary expressions and more than three kinds of binary expressions in ChocoPy.
|
||||
2. Specify new constants for unary and binary operators in a signature.
|
||||
Use `UnOp` and `BinOp` as types of these operators.
|
||||
Again, you should use names based on the semantics of an operator, not on its syntax.
|
||||
Reading an expression aloud might help you to find suitable constructor names.
|
||||
3. Define constructors `UnExp` and `BinExp`,
|
||||
which combine an operator and an expression (respectively two expressions) to an expression.
|
||||
|
||||
#### Rewrite Rules
|
||||
|
||||
The following rewrite rule defines a rule to desugar an addition:
|
||||
|
||||
```
|
||||
rules
|
||||
|
||||
desugar: Add(e1, e2) -> BinExp(Plus(), e1, e2)
|
||||
```
|
||||
|
||||
This rewrite rule is named `desugar`.
|
||||
On the left-hand side, the rule matches an addition.
|
||||
During the match, variables `e1` and `e2` are bound to actual terms.
|
||||
On the right-hand side, the rule instantiates a binary expression (in a uniform representation).
|
||||
During the instantiation, variables `e1` and `e2` are replaced with the terms they are bound to.
|
||||
You can extend `desugar` to replace the different unary and binary expressions in the abstract syntax tree
|
||||
with a uniform representation of these expressions.
|
||||
Define a rewrite rule `desugar` in `trans/desugar.str` for every unary or binary operator,
|
||||
which transforms the original expression into a uniform representation.
|
||||
|
||||
#### Editor Integration
|
||||
|
||||
To test your transformation, you need to define a builder.
|
||||
This is done similar to the builder for pretty-printing.
|
||||
First, import the `desugar` module (defined in `trans/desugar.str`) into the main `chocopy` module.
|
||||
Then, add the following rewrite rule to `trans/chocopy.str`:
|
||||
|
||||
```
|
||||
editor-desugar:
|
||||
(_, _, ast, path, project-path) -> (filename, text)
|
||||
where
|
||||
filename := <guarantee-extension(|"desugared.aterm")> path ;
|
||||
text := <desugar-all> ast
|
||||
```
|
||||
|
||||
This rule follows Spoofax' convention for strategies which implement editor services.
|
||||
On the left-hand site, it matches a tuple of
|
||||
|
||||
* the first two parts are ignored
|
||||
* the `path` of the current file and
|
||||
* the `project path`.
|
||||
|
||||
On the right-hand site, it instantiates a pair, consisting of a `filename` and the designated `text` of the file.
|
||||
Both variables are bound in the `where` clause.
|
||||
The file name is derived from the path of the current file,
|
||||
while the content of the file is a desugared version of the selected AST node.
|
||||
You also need to hook your strategy into the editor, making desugaring available in the *Syntax* menu.
|
||||
You can do this in `editor/Syntax.esv` under the *Show Parsed AST* action:
|
||||
|
||||
```
|
||||
action : "Show desugared syntax" = editor-desugar (source)
|
||||
```
|
||||
|
||||
This rule defines
|
||||
|
||||
* a builder,
|
||||
* its label in the *Syntax* menu, and
|
||||
* its implementation strategy `editor-desugar`.
|
||||
|
||||
Annotations can be used for different variants of builders:
|
||||
|
||||
* `(openeditor)` from the Syntax menu ensures that a new editor window is opened for the result.
|
||||
* Finally, `(source)` tells Spoofax to run the builder on an unanalysed (and also not desugared) AST.
|
||||
|
||||
Note that the `editor-desugar` rule uses `desugar-all`. You should implement this strategy as explained in the next section. Until you do, the menu option will not work.
|
||||
{: .notice .notice-warning}
|
||||
|
||||
|
||||
#### Strategies
|
||||
|
||||
Rewrite rules typically define local transformations inside an AST.
|
||||
Rewrite rules with the same name define a strategy of this name.
|
||||
Furthermore, strategies can be defined to orchestrate rewrite rules to complex transformations of complete ASTs.
|
||||
A strategy consists of a name and a definition, which is typically a combination of strategy applications.
|
||||
For example, the following strategy orchestrates local desugarings to a desugaring of complete ASTs:
|
||||
|
||||
```
|
||||
strategies
|
||||
|
||||
desugar-all = innermost(desugar)
|
||||
```
|
||||
|
||||
This strategy is named `desugar-all`.
|
||||
It applies local `desugar` rules.
|
||||
The application is guided by a generic traversal strategy `innermost`,
|
||||
which tries to apply its parameter inside a tree, starting at the leaves (bottom-up, left-to-right).
|
||||
Whenever an application is successful, the result is traversed again.
|
||||
|
||||
Same results can be achieved with different generic traversals.
|
||||
You should try different traversals in `trans/desugar.str`:
|
||||
|
||||
* `desugar-all = innermost(desugar)`
|
||||
* `desugar-all = topdown(desugar)`
|
||||
* `desugar-all = topdown(try(desugar))`
|
||||
* `desugar-all = bottomup(desugar)`
|
||||
* `desugar-all = bottomup(try(desugar))`
|
||||
* `desugar-all = alltd(desugar)`
|
||||
|
||||
Try to understand what is going on and decide for a suitable one.
|
||||
You can use the library strategy `debug` to print the currently visited node.
|
||||
For example, `innermost(debug; desugar)` will `debug` all nodes before it tries to `desugar` them.
|
||||
|
||||
As preparation for the exam, provide an explanation of
|
||||
1. the choice you made,
|
||||
2. why this choice is suitable for this project, and
|
||||
3. why other choices would be less suitable.
|
||||
|
||||
Try changing the `editor-desugar` rule to use `desugar-all` instead of `desugar`. If you chose a suitable strategy, the builder should succeed even when no node is selected in the ChocoPy program.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/2.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="9.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../milestone/2.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="9.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
550
lab/9.html
Normal file
550
lab/9.html
Normal file
|
|
@ -0,0 +1,550 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Eelco Visser">
|
||||
<meta name="generator" content="Jekyll v3.8.5">
|
||||
<title>Lab 9: A Basic Compiler Pipeline</title>
|
||||
<!-- <base href="/2021"> -->
|
||||
|
||||
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
|
||||
|
||||
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="../css/main.css" rel="stylesheet">
|
||||
<link href="../css/borders-responsive.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../css/pl.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
TU Delft | CS4200
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
|
||||
|
||||
|
||||
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
|
||||
<div class="text-dark font-weight-bold">
|
||||
<h1>
|
||||
|
||||
Lab 9: A Basic Compiler Pipeline
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
||||
Project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div>
|
||||
November 19, 2021
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
|
||||
<p>In this lab you make a start with compiling ChocoPy to RISC-V code using Stratego.
|
||||
You translate expression statements with expressions containing constants, operators, and variables.
|
||||
While it would be possible to completely compute the values of such expressions using constant folding, this is not the aim of this lab.
|
||||
Rather, we want the basis for a translation of expressions using variables and function calls as well.</p>
|
||||
|
||||
<h3 id="a-minimial-viable-example">A Minimial Viable Example</h3>
|
||||
|
||||
<p>The following is a minimal ChocoPy program:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>y : int = 3
|
||||
1 + y
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Aim to get the complete compiler pipeline working for this example first.
|
||||
Then work on extending the various stages.</p>
|
||||
|
||||
<h3 id="nano-pass-compiler-architecture">Nano-Pass Compiler Architecture</h3>
|
||||
|
||||
<p>Follow the setup of the pipeline in <em>Essentials of Compiling</em> consisting of the following strategies:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>compile =
|
||||
compile-cpy-to-cir
|
||||
; compile-cir-to-rv32im
|
||||
; compile-rv32im
|
||||
|
||||
compile-cpy-to-cir =
|
||||
explicate-types
|
||||
; desugar
|
||||
; uniquify
|
||||
; remove-complex-operands
|
||||
; explicate-control
|
||||
|
||||
compile-cir-to-rv32im =
|
||||
select-instructions-cprogram
|
||||
|
||||
compile-rv32im =
|
||||
assign-homes
|
||||
; patch-instructions
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Be sure to replace the <code class="language-plaintext highlighter-rouge">compile</code> rule in <code class="language-plaintext highlighter-rouge">src/compile.str2</code> with the above <code class="language-plaintext highlighter-rouge">compile</code> strategy.</p>
|
||||
|
||||
<h3 id="risc-v-resources">RISC-V Resources</h3>
|
||||
|
||||
<p>Consult the following resources as documentation on the RISC-V architecture and instruction set:</p>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://github.com/jameslzhu/riscv-card/blob/master/riscv-card.pdf">RISC-V Reference</a> by James Zhu. Provides a concise overview of the instruction set.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://chocopy.org/venus.html">Venus Editor</a> on ChocoPy site.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://chocopy.org/">ChocoPy Reference Compiler</a> on the ChocoPy site. Produces RISC-V code with annotations.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://riscv.org/technical/specifications/">RISC-V Specifications</a>. The offical specification.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://github.com/riscv/riscv-isa-manual">RISC-V Instruction Set Manual</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md">RISC-V Assembly Programmer’s Manual</a> for an overview of the instruction set.</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 id="prebuilt">Prebuilt</h3>
|
||||
|
||||
<p>The <code class="language-plaintext highlighter-rouge">prebuilt</code> directory of your project template should have</p>
|
||||
|
||||
<ul>
|
||||
<li>The ChocoPy signature and pretty-printer</li>
|
||||
<li>The RV32IM signature and pretty-printer</li>
|
||||
</ul>
|
||||
|
||||
<p>The template should also have implementations of the ChocoPy parser and type checker.</p>
|
||||
|
||||
<h3 id="compiler-testing">Compiler Testing</h3>
|
||||
|
||||
<p>Develop tests in SPT to test your compiler.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module test
|
||||
|
||||
language chocopy
|
||||
|
||||
test 1+1 [[
|
||||
1+1
|
||||
]] transform "To RV32IM and execute" to "2"
|
||||
</code></pre></div></div>
|
||||
|
||||
<!-- See the slides of [Lecture 12](/2021/lecture/12/) on code generation for an approach to get started. -->
|
||||
|
||||
<!-- ### Objectives
|
||||
|
||||
1. Develop tests for your compiler that explore the edge cases.
|
||||
|
||||
2. Define a transformation strategy that translates ChocoPy constant expressions to RISC-V code. I.e. including integer and boolean constants and operators.
|
||||
|
||||
3. Develop a simplification transformation that transforms expressions such that more concise code can be generated.
|
||||
|
||||
|
||||
|
||||
### Basic Compiler Pipeline
|
||||
|
||||
Follow the slides of [Lecture 12](/2021/lecture/12) to set up a basic compiler pipeline for translating statement expressions and print the resulting value.
|
||||
|
||||
```
|
||||
program-to-rv32im:
|
||||
ast@Program(definitions, [stat]) -> Program(instrs2)
|
||||
where
|
||||
a := <stx-get-ast-analysis>
|
||||
; <stat-to-instrs(|"a1", <registers>)> stat => instrs1
|
||||
; instrs2 := <concat> [
|
||||
[PSText()]
|
||||
, instrs1
|
||||
, [Li("a0", "1"),
|
||||
Ecall()]
|
||||
]
|
||||
```
|
||||
|
||||
Note that you will eventually have to extend this rule to cover all of ChocoPy.
|
||||
|
||||
The `stat-to-instrs` strategy transforms statements. For now, we are only defining it for expression statements:
|
||||
|
||||
```
|
||||
stat-to-instrs(|r, regs) :
|
||||
Exp(e) -> instrs
|
||||
where <exp-to-instrs(|r, regs)> e => instrs
|
||||
```
|
||||
|
||||
The strategy is parameterized with a register in which it expects the value of the expression to be stored and a list of registers that can be used as temporaries. For now this is defined as follows:
|
||||
|
||||
```
|
||||
registers = !["t0", "t1", "t2", "t3", "t4", "t5", "t6"]
|
||||
```
|
||||
|
||||
That is, the `t` registers can all be used as temporaries. You will probably have to adjust this in the future.
|
||||
|
||||
|
||||
|
||||
|
||||
### Translating Expressions
|
||||
|
||||
Define a strategy that transforms expressions to lists of instructions. The example rules below show how to do this for integer constants and integer additions. These rules use registers to store the intermediate values of sub-expressions, by drawing from a list of registers. Note that this a naive approach that does not scale to arbitrary expressions. You will have to discover the limitations and figure out how to overcome those.
|
||||
|
||||
#### Debugging
|
||||
|
||||
The following strategy definition defines `exp-to-instrs` in terms of an auxiliary rule `exp-to-instrs-`:
|
||||
|
||||
```
|
||||
exp-to-instrs(|r, regs) =
|
||||
exp-to-instrs-(|r, regs)
|
||||
<+ (debug(!"exp-to-instr fails: "); fail)
|
||||
```
|
||||
|
||||
This is a useful pattern in Stratego, as it catches a possible failure of the `exp-to-instrs-` rule and reports it in the Eclipse Console. For example, this strategy will report when you apply the compiler to an operator that is not (yet) supported.
|
||||
|
||||
You can also debug your generated code, by creating a `.cpy` file, transforming it to an `.rv32im` file using the `Spoofax > Generation` menu, and copying the generated output to the online Venus editor, where you can use the `Simulator` tab to run your code or step through each line, and inspect the memory and registers.
|
||||
|
||||
#### Translating Constants
|
||||
|
||||
Integer constants are translated to instructions that load the constant value into a register:
|
||||
|
||||
```
|
||||
exp-to-instrs-(|r, regs) :
|
||||
Int(i) -> [Li(r, i)]
|
||||
```
|
||||
|
||||
Can other types of constants be treated similarly?
|
||||
|
||||
#### Translating Operators
|
||||
|
||||
Operators combine expressions into new expressions. In order to translate an operator, its sub-expressions should be translated recursively the lists of instructions. Furthermore, while the value of the second sub-expression is computed, the value of the first sub-expression should be stored. This typically requires a new register. Thus, integer addition can be translated as follows:
|
||||
|
||||
```
|
||||
exp-to-instrs-(|r, regs@[r2 | regs']) :
|
||||
add@Add(e1, e2) -> <concat> [
|
||||
instrs1
|
||||
, instrs2
|
||||
, [Add(r, r, r2)]
|
||||
]
|
||||
where <stx-get-ast-analysis> add => a
|
||||
; <get-type(|a)> add => INT()
|
||||
; <exp-to-instrs(|r, regs)> e1 => instrs1
|
||||
; <exp-to-instrs(|r2, regs')> e2 => instrs2
|
||||
```
|
||||
|
||||
Note that the list of registers is used to obtain a fresh register.
|
||||
|
||||
Define transformation rules for all operators of ChocoPy expressions.
|
||||
|
||||
#### Special Cases
|
||||
|
||||
RISC-V provides specialized instructions for some operations. For example, the `addi` instruction allows directly adding an integer constant (between -2048 and 2047) to a register. A compiler can make use of such instructions, by detecting special patterns in the source language. For example, the following rule (when listed before the general rule for addition above), detects additions with an integer constant, and translates those to applications of `addi`, avoiding the use of an extra register.
|
||||
|
||||
```
|
||||
exp-to-instrs-(|r, regs) :
|
||||
add@Add(e, Int(i)) -> <concat> [
|
||||
instrs
|
||||
, [Addi(r, r, i)]
|
||||
]
|
||||
where <gtS>(i, "-2049"); <ltS>(i, "2048")
|
||||
; <stx-get-ast-analysis> add => a
|
||||
; <get-type(|a)> add => INT()
|
||||
; <exp-to-instrs(|r, regs)> e => instrs
|
||||
```
|
||||
|
||||
Can you detect other specialized instructions and corresponding source language patterns that provide a more concise and/or faster target code?
|
||||
|
||||
### Simplification
|
||||
|
||||
To improve the result of code generation, it can be useful to transform the source language expression. For example, left-associative additions produce a better result with the rules for addition above. Another useful transformation is to type specialize the constructors of the AST, such that the analysis results are no longer needed. That is useful when applying transformations, since preserving those annotations cannot be done for all transformations. **The following `simplify-all` transformation should be invoked on the AST before invoking the compiler transformation.**
|
||||
|
||||
```
|
||||
signature
|
||||
constructors
|
||||
AddInt : Exp * Exp -> Exp
|
||||
|
||||
rules
|
||||
|
||||
simplify-all =
|
||||
innermost(type-specialize <+ simplify)
|
||||
|
||||
type-specialize :
|
||||
add@Add(e1, e2) -> AddInt(e1, e2)
|
||||
where <stx-get-ast-analysis> add => a
|
||||
; <get-type(|a)> add => INT()
|
||||
|
||||
simplify :
|
||||
AddInt(e1, AddInt(e2, e3)) -> AddInt(AddInt(e1, e2), e3)
|
||||
```
|
||||
|
||||
Note that the rules for translating integer additions should be adapted to reflect the change in constructors.
|
||||
|
||||
This simplification can include constant folding, eventually. However, do not yet include constant folding rules, since you want to test the translation of operators. That is, your code generator should be able to translate arbitrary combinations of operators, so be prepared for the general case.
|
||||
|
||||
Think about (and try out in the online compiler!) the differences between adding integers and concatenating strings in RISC-V. In ChocoPy, they initially both use the `Add(...)` constructor, so make sure to disambiguate them into separate constructors you will later use for code generation. The same holds for other operations, but you have to think about those yourself.
|
||||
|
||||
### Booleans
|
||||
|
||||
In ChocoPy we compile the Booleans `True` and `False` to integers in RISC-V (`1` and `0`, respectively). Implement the Boolean operators `and`, `or` and `not`, and integer comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` (you can ignore `is` for now since it operates on objects).
|
||||
|
||||
You can make use of the online compiler, or the RISC-V instruction set to find the proper instructions in RISC-V.
|
||||
|
||||
Also implement the ternary operator `... if ... else ...`. (See [Short-circuit Boolean operations](#shortcircuit) to get an idea on how to implement it.)
|
||||
|
||||
### Challenges
|
||||
|
||||
#### Running out of registers
|
||||
|
||||
The approach sketched above does not generalize to arbitrary expressions.
|
||||
Create test cases that require more temporary registers than are available.
|
||||
|
||||
Start thinking about solutions for this limitation. Two standard solutions are using the stack for temporaries (which is slow since it involves writing to and reading from memory), and register allocation (which requires a program analysis on the generated code).
|
||||
|
||||
#### <a name="shortcircuit"></a>Short-circuit Boolean operations.
|
||||
|
||||
When encountering a Boolean operation of the form `False and ...`, do we really care about the right side of the operator? Similarly, when we encounter `True or ...`?
|
||||
|
||||
Think about how we can use conditional jumps in RISC-V to short-circuit (any) Boolean operators. Have a look at the instruction set and online compiler.
|
||||
|
||||
A conditional jump in RISC-V takes a label, which represents an address in memory. In Stratego, labels can be generated using `<newname> "L" => label`. (Note that `"L"` can be anything you want, as long as it is a string.) -->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
|
||||
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
|
||||
<div class="pb4 mb3 border-bottom border-grey ">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-left">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="8.html">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
^
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="10.html">»</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="9.html#a-minimial-viable-example">A Minimial Viable Example</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="9.html#nano-pass-compiler-architecture">Nano-Pass Compiler Architecture</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="9.html#risc-v-resources">RISC-V Resources</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="9.html#prebuilt">Prebuilt</a></li>
|
||||
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="9.html#compiler-testing">Compiler Testing</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="border-top border-bottom border-grey mt-3 pt-3">
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="8.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="10.html">Next</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="../project/index.html">
|
||||
Index
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue