Open saucisson opened 6 years ago
I have put an example of constant propagation for a subset of the abstract syntax tree. To do it, we had to update the anzen package. You must thus do the rm -rf .build Package.resolved
command before swift test
, in order to download the latest version.
You have mainly to fill the code within semantique/Sources/semantique/PropagateConstantVisitor.swift
for this homework.
The tests i am using for this homework are:
let test_expressions = [
// Already a constant:
"""
let x = 1
""",
// Expression on integers constants:
"""
let x = 1 + 2 * 3 - 4
""",
// Expression using integer constants and a variable:
"""
let x = 1
let y = x + 2
let z = -x + 2
""",
// Expression using a variable with no value:
"""
let x = 1
let y : Int
let z = x + y
""",
// Expression on Boolean values and variables:
"""
var x = true
x = x and false
""",
// Expression on string values and variables:
"""
let x = "abcdef"
let y = x
""",
// Condition:
"""
var x = 2
var y = 2
if x == y {
y = x
} else {
x = y
}
""",
// Function declaration and call:
"""
let x = 2
fun f(_ a: Int) -> Int {
return a * x
}
let y = f(x) * x
""",
// Function declaration and call:
"""
var x = 2
fun f(_ a: Int) -> Int {
return a * x
}
let y = f(x) * x
""",
]
Grades have been pushed into your repositories, under branch homework-1
. Please check them.
Homework #1 is available in README. It must be done before 20th march 2018 08:00. I will add some tests during this week. Feel free to add your own tests.