Commit a78d64d4 authored by Noric Couderc's avatar Noric Couderc
Browse files

Cleaned up directories for publications

These files aren't necessary for publication to the students
parent 15566433
# EDAP15, Homework Exercise 2: ...
You will be working with an extended version of TEAL, TEAL-1, which includes type qualifiers.
Type qualifiers are (blah (a way to insert dynamic checks based on type?) )
For example:
fun main() = {
var x : nonnull int;
x := null; // this will fail.
In this exercise we will focus on the qualifier `nonnull', which ensures that a given object reference is not null.
By default, TEAL checks this all dynamically (blah)
Implement a (local) dataflow analysis that checks each function body for assignments to _local_ nonnull variables (this includes parameters). and identifies all assignments to a nonnull variable in which we can be certain that the assignment requires no dynamic null check.
Your dataflow analysis should trust the declared return types of any functions.
- Recall that you are performing this analysis for optimisation, pick suitable merge fn.
- You can implement this on the IR.
- You can also implement this on the AST, but you need the control flow graph.
(maybe: You can use an existing MFP solver)
If you want to get started with the IR analysis, you can look at: `ir/teal3/analysis/`.
(I don't think they should. Because then _no_ student will try to learn the IR.)
(below is from EX1)
The exercise assumes that you are familiar with JastAdd for compiler
construction. If you are not and do not want to learn JastAdd at this
time, please contact us and we will provide you with a documented
Visitor interface that allows you to work directly in Java.
To implement your solutions, communicate with each other, and show
your solution to the TA, use the [CourseGit](
system that you can also reach from the course home page.
## Task Description
- Preparations
- Log all of your group members into the [CourseGit](
- Send an e-mail to Noric (`noric.couderc@cs...`) and Christoph (`christoph.reichenbach@cs....`)
- One of us will add you to your CourseGit project for you and notify you
- You will receive instructions for how to fork the [Exercise 1]( repository into own project; run those.
- Follow the build steps in the [README]( to build Teal-0 and run its test cases.
- Make sure that you can run Teal on the examples in the `examples/` subdirectory (one of which requires you to pass additional parameters):
- `java -jar ./compiler/teal-0.jar examples/hello-world.teal -r`
- `java -jar ./compiler/teal-0.jar examples/iterate-add.teal -r 1 8`
- Implement a pass on Teal that performs monomorphic type inference.
- Find a suitable main entry point. The [README]( describes how to use the command-line argument command `-Y` for this purpose; this is the easiest approach.
- Examine `teal/compiler/teal0/frontend/TypeInference.jrag`. This file gives you a skeleton for how to implement the inference and provides several helpers.
- Implement a *Fact Extraction* pass with fresh variables that satisfies the type constraints listed below (**Typing Rules**)
- Implement *Unification*.
- Make sure that your pass prints out the inferred types in the form described in the **Deliverables** section below.
- Commit your changes to `git` frequently.
- Test your code (see **Resources** below). You may want to write your own test cases.
- Book a TA slot in SAM and present your solution to the TA
## Deliverables
The expected deliverables are:
- A modified version of Teal-0 that solves the task and is committed to your CourseGit repository
- A `` file, also committed to the CourseGit, that takes a single parameter (one Teal file), analyses it, and prints output in the format described below (you can use the existing file or create your own)
- A presentation of your solution to the TA
### Output format
- assignments that are guaranteed nonnull with `<line-number> <column>` of assignment stmt
- return statements that guaranteed nonnull `<line-number> <column>` of return stmt
- method parameters that are guaranteed nonnull `<line-number> <column> <arg> ... <arg>` where the arg is 'T' if nonnull and '?' if unknown
# Typing Rules
The [language specification](docs/teal-0.pdf) lists types and type schemes for the built-in operations.
For all other language constructs, the following rules apply:
- All types in Teal allow `null` values, including `int`s.
- We represent logical values as `int`s, including in `if` and `while` statements and the unary `not` operation.
- Array literals such as `[3, 7, 23] : array[int]` must contain elements of exactly the same type.
- There is no notion of overloading in the language, so function types and binary operator types (which are largely the same thing) must match exactly.
- In Teal-0, The `new` operator is only allowed on `array` types, and the expression parameter must be an `int` that describes the array size.
- Assignments require that the left-hand side (LValue) and right-hand side (RValue) have exactly the same type.
- Return statements must match up exactly with the function return type.
- Any explicit type declarations are "absolute", i.e., `(1 : string)` has type `string` (and will also produce a type error with type inference, of course.)
- Variable and function types must be consistent across definitions and usage locations
## Hints and Starting Points
The []( file contains some high-level pieces of
information about Teal and pointers to good starting points. In
addition, you may find the following files worth investigating:
- [](compiler/teal0/java/lang/ is the main
entry point.
- [TypeInference.jrag](compiler/teal0/frontend/TypeInference.jrag)
contains a skeleton type inferencer. You can solve the exercise by modifying only this file and [](compiler/teal0/java/lang/
- [BuiltinTypes.jrag](compiler/teal0/frontend/BuiltinTypes.jrag)
handles built-in names and types. You may not need to do much with
it directly, but it illustrates how you can use [](ir/teal3/java/lang/common/
to get information about the built-in operations.
- [](ir/teal3/java/lang/common/ contains
approximate types of the built-in operations. This file doesn't
support type schemes, so it uses somewhat imprecise type information
You can modify the file to improve it or work around it by handling
built-in operations with type schemes differently from those who don't.
- [NameAnalysis.jrag](compiler/teal0/frontend/NameAnalysis.jrag) contains useful
attributes to look up names and function / variable declaration sites.
- [TypeAnalysis](compiler/teal0/frontend/TypeAnalysis.jrag) contains the attribute `implicitType()`, which
can help simplify your inference code a little (optionally).
## Resources
- The []( file contains general information about building, running, and extending Teal.
- You can find the language specification for Teal-0 [here](docs/teal-0.pdf).
- To test your program, you can use the Teal test programs that ship with
the distribution, in `compiler/testfiles/interpreter/*.in`, but you may
find it useful to build your own. (Note that not all of the programs in that directory will pass type checking!)
Assume that there is no subtyping in the language.
This requires you to itereate over input programs. You can implement this iteration in two ways:
- With JastAdd: _Extend_ the Teal source code package and add custom attributes.
- Without JastAdd: Use the TealVisitor interface to iterate over the AST.
You may not otherwise edit the TEAL source code (unless instructed by the TA).
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment