diff --git a/pa3-tests/README.md b/pa3-tests/README.md new file mode 100644 index 0000000..1e320cd --- /dev/null +++ b/pa3-tests/README.md @@ -0,0 +1,24 @@ +# Tests for PA3: ChocoPy Code Generation + +Clone a student repository: +``` +TEAM="team" +git clone --branch=pa3final \ + https://github.com/nyu-compiler-construction/pa3-chocopy-code-generation-${TEAM} +``` + +Build it: +``` +cd pa3-chocopy-code-generation-${TEAM} +mvn clean package +``` + +Clone the tests _into_ the student repository: +``` +git clone https://github.com/nyu-compiler-construction/pa3-tests +``` + +Run the tests: +``` +./pa3-tests/run-tests.sh +``` diff --git a/pa3-tests/benchmarks/exp.py b/pa3-tests/benchmarks/exp.py new file mode 100644 index 0000000..3915517 --- /dev/null +++ b/pa3-tests/benchmarks/exp.py @@ -0,0 +1,25 @@ +# Compute x**y +def exp(x: int, y: int) -> int: + a: int = 0 + def f(i: int) -> int: + nonlocal a + def geta() -> int: + return a + if i <= 0: + return geta() + else: + a = a * x + return f(i-1) + a = 1 + return f(y) + +# Input parameter +n:int = 42 + +# Run [0, n] +i:int = 0 + +# Crunch +while i <= n: + print(exp(2, i % 31)) + i = i + 1 \ No newline at end of file diff --git a/pa3-tests/benchmarks/exp.py.ast.typed b/pa3-tests/benchmarks/exp.py.ast.typed new file mode 100644 index 0000000..39a7fa1 --- /dev/null +++ b/pa3-tests/benchmarks/exp.py.ast.typed @@ -0,0 +1,562 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 26, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 14, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "exp" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 17, 2, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 28, 2, 30 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 2 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 5, 3, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 2, 13, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 6, 4, 6 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 8, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 8, 4, 8 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 5, 3, 5, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 3, 7, 12 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 10 ], + "name" : "geta" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 17, 6, 19 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 4, 7, 11 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } + } ] + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 13, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 11, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 4, 9, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 11, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 11, 9, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "geta" + }, + "args" : [ ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 4, 11, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 4, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 11, 8, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 12, 4, 12, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 11, 12, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 11, 12, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 12, 13, 12, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 12, 13, 12, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 15, 12, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 2, 13, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 2, 13, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 6, 13, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 2, 14, 12 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 14, 9, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 9, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 3, 20, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 9, 20, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 23, 1, 26, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 7, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 7, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 23, 12, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 2, 24, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 2, 24, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 24, 2, 24, 6 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 24, 8, 24, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 24, 8, 24, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "exp" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 24, 12, 24, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "BinaryExpr", + "location" : [ 24, 15, 24, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 24, 15, 24, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 19, 24, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 31 + } + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 2, 25, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 2, 25, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 25, 6, 25, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 25, 6, 25, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 10, 25, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/benchmarks/exp.py.ast.typed.s.result b/pa3-tests/benchmarks/exp.py.ast.typed.s.result new file mode 100644 index 0000000..6bce2e5 --- /dev/null +++ b/pa3-tests/benchmarks/exp.py.ast.typed.s.result @@ -0,0 +1,43 @@ +1 +2 +4 +8 +16 +32 +64 +128 +256 +512 +1024 +2048 +4096 +8192 +16384 +32768 +65536 +131072 +262144 +524288 +1048576 +2097152 +4194304 +8388608 +16777216 +33554432 +67108864 +134217728 +268435456 +536870912 +1073741824 +1 +2 +4 +8 +16 +32 +64 +128 +256 +512 +1024 +2048 diff --git a/pa3-tests/benchmarks/prime.py b/pa3-tests/benchmarks/prime.py new file mode 100644 index 0000000..7568705 --- /dev/null +++ b/pa3-tests/benchmarks/prime.py @@ -0,0 +1,30 @@ +# Get the n-th prime starting from 2 +def get_prime(n:int) -> int: + candidate:int = 2 + found:int = 0 + while True: + if is_prime(candidate): + found = found + 1 + if found == n: + return candidate + candidate = candidate + 1 + return 0 # Never happens + +def is_prime(x:int) -> bool: + div:int = 2 + while div < x: + if x % div == 0: + return False + div = div + 1 + return True + +# Input parameter +n:int = 15 + +# Run [1, n] +i:int = 1 + +# Crunch +while i <= n: + print(get_prime(i)) + i = i + 1 diff --git a/pa3-tests/benchmarks/prime.py.ast.typed b/pa3-tests/benchmarks/prime.py.ast.typed new file mode 100644 index 0000000..a3062b6 --- /dev/null +++ b/pa3-tests/benchmarks/prime.py.ast.typed @@ -0,0 +1,658 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 31, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 11, 29 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 13 ], + "name" : "get_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 15, 2, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 15 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 17, 2, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "candidate" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "found" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 5, 5, 11, 4 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 11, 5, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 6, 9, 10, 8 ], + "condition" : { + "kind" : "CallExpr", + "location" : [ 6, 12, 6, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "is_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 21, 6, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 13, 7, 29 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 7, 21, 7, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 7, 21, 7, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 29, 7, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 8, 13, 10, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 16, 8, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 25, 8, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 17, 9, 32 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 24, 9, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 33 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 10, 21, 10, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 10, 21, 10, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 33, 10, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 1, 19, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 12 ], + "name" : "is_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 14, 13, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 14, 13, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 16, 13, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 24, 13, 27 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 14, 5, 14, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 14, 5, 14, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 7 ], + "name" : "div" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 9, 14, 11 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 14, 15, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 15, 5, 19, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 11, 15, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 11, 15, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 15, 17, 15, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 16, 9, 18, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 12, 16, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 23, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 13, 17, 24 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 20, 17, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 18, 9, 18, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 9, 18, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 18, 15, 18, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 18, 15, 18, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 21, 18, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 19, 12, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 22, 1, 22, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 1, 22, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 3, 22, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 9, 22, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 15 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 1, 25, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 1, 25, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 3, 25, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 28, 1, 31, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 7, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 28, 7, 28, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 29, 5, 29, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 29, 5, 29, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 29, 5, 29, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 29, 11, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 29, 11, 29, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "get_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 5, 30, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 5, 30, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 9, 30, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 30, 9, 30, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 13, 30, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/benchmarks/prime.py.ast.typed.s.result b/pa3-tests/benchmarks/prime.py.ast.typed.s.result new file mode 100644 index 0000000..6beaeaa --- /dev/null +++ b/pa3-tests/benchmarks/prime.py.ast.typed.s.result @@ -0,0 +1,15 @@ +2 +3 +5 +7 +11 +13 +17 +19 +23 +29 +31 +37 +41 +43 +47 diff --git a/pa3-tests/benchmarks/sieve.py b/pa3-tests/benchmarks/sieve.py new file mode 100644 index 0000000..b6aa977 --- /dev/null +++ b/pa3-tests/benchmarks/sieve.py @@ -0,0 +1,107 @@ +# A resizable list of integers +class Vector(object): + items: [int] = None + size: int = 0 + + def __init__(self:"Vector"): + self.items = [0] + + # Returns current capacity + def capacity(self:"Vector") -> int: + return len(self.items) + + # Increases capacity of vector by one element + def increase_capacity(self:"Vector") -> int: + self.items = self.items + [0] + return self.capacity() + + # Appends one item to end of vector + def append(self:"Vector", item: int) -> object: + if self.size == self.capacity(): + self.increase_capacity() + + self.items[self.size] = item + self.size = self.size + 1 + + # Appends many items to end of vector + def append_all(self:"Vector", new_items: [int]) -> object: + item:int = 0 + for item in new_items: + self.append(item) + + # Removes an item from the middle of vector + def remove_at(self:"Vector", idx: int) -> object: + if idx < 0: + return + + while idx < self.size - 1: + self.items[idx] = self.items[idx + 1] + idx = idx + 1 + + self.size = self.size - 1 + + # Retrieves an item at a given index + def get(self:"Vector", idx: int) -> int: + return self.items[idx] + + # Retrieves the current size of the vector + def length(self:"Vector") -> int: + return self.size + +# A faster (but more memory-consuming) implementation of vector +class DoublingVector(Vector): + doubling_limit:int = 1000 + + # Overriding to do fewer resizes + def increase_capacity(self:"DoublingVector") -> int: + if (self.capacity() <= self.doubling_limit // 2): + self.items = self.items + self.items + else: + # If doubling limit has been reached, fall back to + # standard capacity increases + self.items = self.items + [0] + return self.capacity() + +# Makes a vector in the range [i, j) +def vrange(i:int, j:int) -> Vector: + v:Vector = None + v = DoublingVector() + + while i < j: + v.append(i) + i = i + 1 + + return v + +# Sieve of Eratosthenes (not really) +def sieve(v:Vector) -> object: + i:int = 0 + j:int = 0 + k:int = 0 + + while i < v.length(): + k = v.get(i) + j = i + 1 + while j < v.length(): + if v.get(j) % k == 0: + v.remove_at(j) + else: + j = j + 1 + i = i + 1 + +# Input parameter +n:int = 50 + +# Data +v:Vector = None +i:int = 0 + +# Crunch +v = vrange(2, n) +sieve(v) + +# Print +while i < v.length(): + print(v.get(i)) + i = i + 1 + diff --git a/pa3-tests/benchmarks/sieve.py.ast.typed b/pa3-tests/benchmarks/sieve.py.ast.typed new file mode 100644 index 0000000..1c0eb6c --- /dev/null +++ b/pa3-tests/benchmarks/sieve.py.ast.typed @@ -0,0 +1,2816 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 108, 1 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 52, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 12 ], + "name" : "Vector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 14, 2, 19 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "name" : "items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 8 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 5, 7, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 6, 18, 6, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 23, 6, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 32, 6, 32 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 9, 7, 24 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 7, 9, 7, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 22, 7, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 23, 7, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 36, 10, 38 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 30 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 11, 16, 11, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 16, 11, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 11, 20, 11, 29 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 11, 20, 11, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 11, 25, 11, 29 ], + "name" : "items" + } + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 16, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 27, 14, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 27, 14, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 32, 14, 39 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 45, 14, 47 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 15, 22, 15, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 22, 15, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 27, 15, 31 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 15, 35, 15, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 15, 36, 15, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 16, 16, 16, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 16, 16, 16, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 21, 16, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 19, 5, 24, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 19, 9, 19, 14 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 19, 16, 19, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 16, 19, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 21, 19, 28 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 19, 31, 19, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 31, 19, 34 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 37, 19, 39 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 19, 45, 19, 50 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 20, 9, 23, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 20, 12, 20, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 20, 12, 20, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 12, 20, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 17, 20, 20 ], + "name" : "size" + } + }, + "operator" : "==", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 20, 25, 20, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 20, 25, 20, 37 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 25, 20, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 30, 20, 37 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 21, 13, 21, 36 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 21, 13, 21, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 21, 13, 21, 34 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 18, 21, 34 ], + "name" : "increase_capacity" + } + }, + "args" : [ ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 23, 9, 23, 36 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 23, 9, 23, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 23, 9, 23, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 9, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 14, 23, 18 ], + "name" : "items" + } + }, + "index" : { + "kind" : "MemberExpr", + "location" : [ 23, 20, 23, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 20, 23, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 25, 23, 28 ], + "name" : "size" + } + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 24, 9, 24, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 14, 24, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 21, 24, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 21, 24, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 21, 24, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 26, 24, 29 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 33, 24, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 27, 5, 33, 4 ], + "name" : { + "kind" : "Identifier", + "location" : [ 27, 9, 27, 18 ], + "name" : "append_all" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 27, 20, 27, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 20, 27, 23 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 25, 27, 32 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 27, 35, 27, 50 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 35, 27, 43 ], + "name" : "new_items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 27, 46, 27, 50 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 27, 47, 27, 49 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 27, 56, 27, 61 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 28, 9, 28, 20 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 9, 28, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 14, 28, 16 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 29, 9, 33, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 29 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "new_items" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 30, 13, 30, 29 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 30, 13, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 30, 13, 30, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 30, 13, 30, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 30, 18, 30, 23 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 30, 25, 30, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + } ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 33, 5, 41, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 33, 9, 33, 17 ], + "name" : "remove_at" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 33, 19, 33, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 19, 33, 22 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 24, 33, 31 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 33, 34, 33, 41 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 34, 33, 36 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 39, 33, 41 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 33, 47, 33, 52 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 34, 9, 37, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 34, 12, 34, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 34, 12, 34, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 18, 34, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 35, 13, 35, 18 ], + "value" : null + } ], + "elseBody" : [ ] + }, { + "kind" : "WhileStmt", + "location" : [ 37, 9, 41, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 15, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 37, 15, 37, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 37, 21, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 37, 21, 37, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 37, 21, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 37, 26, 37, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 37, 33, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 49 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 38, 13, 38, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 13, 38, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 18, 38, 22 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 38, 24, 38, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 38, 31, 38, 49 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 31, 38, 40 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 38, 31, 38, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 36, 38, 40 ], + "name" : "items" + } + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 38, 42, 38, 48 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 38, 42, 38, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 48, 38, 48 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 39, 13, 39, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 39, 13, 39, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 39, 19, 39, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 39, 19, 39, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 39, 25, 39, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 41, 9, 41, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 41, 9, 41, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 9, 41, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 41, 21, 41, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 21, 41, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 21, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 26, 41, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 41, 33, 41, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 44, 5, 45, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 11 ], + "name" : "get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 44, 13, 44, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 18, 44, 25 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 28, 44, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 28, 44, 30 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 33, 44, 35 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 44, 41, 44, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 30 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 45, 16, 45, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 45, 16, 45, 25 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 21, 45, 25 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 45, 27, 45, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 5, 49, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 9, 48, 14 ], + "name" : "length" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 16, 48, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 16, 48, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 21, 48, 28 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 34, 48, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 49, 9, 49, 24 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 49, 16, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 49, 16, 49, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 21, 49, 24 ], + "name" : "size" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 52, 1, 66, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 52, 7, 52, 20 ], + "name" : "DoublingVector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 52, 22, 52, 27 ], + "name" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 53, 5, 53, 29 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 53, 5, 53, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 53, 5, 53, 18 ], + "name" : "doubling_limit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 53, 20, 53, 22 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 53, 26, 53, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1000 + } + }, { + "kind" : "FuncDef", + "location" : [ 56, 5, 63, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 56, 9, 56, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 56, 27, 56, 47 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 27, 56, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 56, 32, 56, 47 ], + "className" : "DoublingVector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 56, 53, 56, 55 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 57, 9, 63, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 57, 13, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 57, 13, 57, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 57, 13, 57, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 13, 57, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 18, 57, 25 ], + "name" : "capacity" + } + }, + "args" : [ ] + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 57, 32, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 57, 32, 57, 50 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 32, 57, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 37, 57, 50 ], + "name" : "doubling_limit" + } + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 57, 55, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 58, 13, 58, 48 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 58, 13, 58, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 13, 58, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 26, 58, 48 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 58, 26, 58, 35 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 26, 58, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 31, 58, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 58, 39, 58, 48 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 39, 58, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 44, 58, 48 ], + "name" : "items" + } + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 62, 13, 62, 41 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 62, 13, 62, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 62, 13, 62, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 18, 62, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 62, 26, 62, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 62, 26, 62, 35 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 62, 26, 62, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 31, 62, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 62, 39, 62, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 62, 40, 62, 40 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 63, 9, 63, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 63, 16, 63, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 63, 16, 63, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 63, 16, 63, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 63, 21, 63, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 66, 1, 74, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 66, 5, 66, 10 ], + "name" : "vrange" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 66, 12, 66, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 12, 66, 12 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 14, 66, 16 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 66, 19, 66, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 19, 66, 19 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 21, 66, 23 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 66, 29, 66, 34 ], + "className" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 67, 5, 67, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 5, 67, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 5, 67, 5 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 7, 67, 12 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 67, 16, 67, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 68, 5, 68, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 68, 5, 68, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 68, 9, 68, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 68, 9, 68, 22 ], + "name" : "DoublingVector" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 70, 5, 74, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 70, 11, 70, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 15, 70, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 71, 9, 71, 19 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 71, 9, 71, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 71, 9, 71, 16 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 71, 9, 71, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 71, 11, 71, 16 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 71, 18, 71, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 72, 9, 72, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 72, 9, 72, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 72, 13, 72, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 72, 13, 72, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 72, 17, 72, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 74, 5, 74, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 74, 12, 74, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 77, 1, 93, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 77, 5, 77, 9 ], + "name" : "sieve" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 77, 11, 77, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 77, 11, 77, 11 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 77, 13, 77, 18 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 77, 24, 77, 29 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 78, 5, 78, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 78, 5, 78, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 78, 5, 78, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 78, 7, 78, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 78, 13, 78, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 79, 5, 79, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 79, 5, 79, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 79, 5, 79, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 79, 7, 79, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 13, 79, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 80, 5, 80, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 80, 5, 80, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 80, 5, 80, 5 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 80, 7, 80, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 80, 13, 80, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 82, 5, 93, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 82, 11, 82, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 82, 11, 82, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 15, 82, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 15, 82, 22 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 82, 15, 82, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 17, 82, 22 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 83, 9, 83, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 83, 13, 83, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 83, 13, 83, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 83, 13, 83, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 83, 15, 83, 17 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 19, 83, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 84, 9, 84, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 84, 9, 84, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 84, 13, 84, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 84, 13, 84, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 84, 17, 84, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 85, 9, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 85, 15, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 85, 15, 85, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 85, 19, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 85, 19, 85, 26 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 85, 19, 85, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 85, 21, 85, 26 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 86, 13, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 86, 16, 86, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 86, 16, 86, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 86, 16, 86, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 86, 18, 86, 20 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 86, 22, 86, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ] + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 86, 27, 86, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 86, 32, 86, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 87, 17, 87, 30 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 87, 17, 87, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 87, 17, 87, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 87, 17, 87, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 87, 19, 87, 27 ], + "name" : "remove_at" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 87, 29, 87, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 89, 17, 89, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 89, 17, 89, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 89, 21, 89, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 89, 21, 89, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 89, 25, 89, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 90, 9, 90, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 90, 9, 90, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 90, 13, 90, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 90, 13, 90, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 90, 17, 90, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 93, 1, 93, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 93, 1, 93, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 93, 3, 93, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 9, 93, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 50 + } + }, { + "kind" : "VarDef", + "location" : [ 96, 1, 96, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 96, 1, 96, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 96, 1, 96, 1 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 96, 3, 96, 8 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 96, 12, 96, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 97, 1, 97, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 97, 1, 97, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 97, 1, 97, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 97, 3, 97, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 97, 9, 97, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 100, 1, 100, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 100, 1, 100, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 100, 5, 100, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 100, 5, 100, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "Vector" + } + }, + "name" : "vrange" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 100, 12, 100, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "Identifier", + "location" : [ 100, 15, 100, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 101, 1, 101, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 101, 1, 101, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 101, 1, 101, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "sieve" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 101, 7, 101, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 104, 1, 108, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 104, 7, 104, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 104, 7, 104, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 104, 11, 104, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 104, 11, 104, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 104, 11, 104, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 104, 13, 104, 18 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 105, 5, 105, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 105, 5, 105, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 105, 5, 105, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 105, 11, 105, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 11, 105, 15 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 105, 11, 105, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 13, 105, 15 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 105, 17, 105, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 106, 5, 106, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 106, 5, 106, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 106, 9, 106, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 106, 9, 106, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 106, 13, 106, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/benchmarks/sieve.py.ast.typed.s.result b/pa3-tests/benchmarks/sieve.py.ast.typed.s.result new file mode 100644 index 0000000..6beaeaa --- /dev/null +++ b/pa3-tests/benchmarks/sieve.py.ast.typed.s.result @@ -0,0 +1,15 @@ +2 +3 +5 +7 +11 +13 +17 +19 +23 +29 +31 +37 +41 +43 +47 diff --git a/pa3-tests/benchmarks/stdlib.py b/pa3-tests/benchmarks/stdlib.py new file mode 100644 index 0000000..e7323bd --- /dev/null +++ b/pa3-tests/benchmarks/stdlib.py @@ -0,0 +1,77 @@ +# ChocoPy library functions +def int_to_str(x: int) -> str: + digits:[str] = None + result:str = "" + + # Set-up digit mapping + digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + + # Write sign if necessary + if x < 0: + result = "-" + x = -x + + # Write digits using a recursive call + if x >= 10: + result = result + int_to_str(x // 10) + result = result + digits[x % 10] + return result + +def str_to_int(x: str) -> int: + result:int = 0 + digit:int = 0 + char:str = "" + sign:int = 1 + first_char:bool = True + + # Parse digits + for char in x: + if char == "-": + if not first_char: + return 0 # Error + sign = -1 + elif char == "0": + digit = 0 + elif char == "1": + digit = 1 + elif char == "2": + digit = 2 + elif char == "3": + digit = 3 + elif char == "3": + digit = 3 + elif char == "4": + digit = 4 + elif char == "5": + digit = 5 + elif char == "6": + digit = 6 + elif char == "7": + digit = 7 + elif char == "8": + digit = 8 + elif char == "9": + digit = 9 + else: + return 0 # On error + first_char = False + result = result * 10 + digit + + # Compute result + return result * sign + +# Input parameters +c:int = 42 +n:int = 10 + +# Run [-nc, nc] with step size c +s:str = "" +i:int = 0 +i = -n * c + +# Crunch +while i <= n * c: + s = int_to_str(i) + print(s) + i = str_to_int(s) + c + diff --git a/pa3-tests/benchmarks/stdlib.py.ast.typed b/pa3-tests/benchmarks/stdlib.py.ast.typed new file mode 100644 index 0000000..72079ff --- /dev/null +++ b/pa3-tests/benchmarks/stdlib.py.ast.typed @@ -0,0 +1,1813 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 78, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 18, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 14 ], + "name" : "int_to_str" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 16, 2, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 21 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 29 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 10 ], + "name" : "digits" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "str" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 12, 4, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 4, 18, 4, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 5, 7, 63 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "digits" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 14, 7, 63 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 15, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "0" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 20, 7, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "1" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 25, 7, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "2" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 30, 7, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 35, 7, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "4" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 40, 7, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "5" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 45, 7, 47 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "6" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 50, 7, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "7" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 55, 7, 57 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "8" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 60, 7, 62 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "9" + } ] + } + }, { + "kind" : "IfStmt", + "location" : [ 10, 5, 15, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 10, 8, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 10, 8, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 12, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 9, 11, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 11, 18, 11, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "-" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 12, 13, 12, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 12, 14, 12, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 15, 5, 17, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 8, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 8, 15, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 13, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 9, 16, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 16, 18, 16, 45 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "CallExpr", + "location" : [ 16, 27, 16, 45 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 36 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 16, 38, 16, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 38, 16, 38 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 43, 16, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + } ] + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 17, 5, 17, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 17, 14, 17, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 17, 14, 17, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "IndexExpr", + "location" : [ 17, 23, 17, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "digits" + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 17, 30, 17, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 17, 30, 17, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 34, 17, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 18, 5, 18, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 18, 12, 18, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 20, 1, 61, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 14 ], + "name" : "str_to_int" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 20, 16, 20, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 16, 20, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 19, 20, 21 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 20, 27, 20, 29 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 21, 5, 21, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 21, 5, 21, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 12, 21, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 21, 18, 21, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 22, 5, 22, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 5, 22, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 9 ], + "name" : "digit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 11, 22, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 17, 22, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 23, 5, 23, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 5, 23, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 8 ], + "name" : "char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 10, 23, 12 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 23, 16, 23, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 24, 5, 24, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 5, 24, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 5, 24, 8 ], + "name" : "sign" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 10, 24, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 16, 24, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 5, 25, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 5, 25, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 5, 25, 14 ], + "name" : "first_char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 16, 25, 19 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 23, 25, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 28, 5, 61, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 29, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 12, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 29, 20, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "-" + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 30, 13, 32, 12 ], + "condition" : { + "kind" : "UnaryExpr", + "location" : [ 30, 16, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "Identifier", + "location" : [ 30, 20, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "first_char" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 31, 17, 31, 24 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 24, 31, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 32, 13, 32, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 13, 32, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "sign" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 32, 20, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 21, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 33, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 14, 33, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 33, 14, 33, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 33, 22, 33, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "0" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 13, 34, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 13, 34, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 21, 34, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 35, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 35, 14, 35, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 35, 14, 35, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 35, 22, 35, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "1" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 36, 13, 36, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 36, 21, 36, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 37, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 14, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 37, 14, 37, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 37, 22, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "2" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 21, 38, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 39, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 39, 14, 39, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 39, 14, 39, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 39, 22, 39, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 40, 13, 40, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 21, 40, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 41, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 14, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 41, 22, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 13, 42, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 42, 13, 42, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 42, 21, 42, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 43, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 43, 14, 43, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 43, 14, 43, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 43, 22, 43, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "4" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 44, 13, 44, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 21, 44, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 45, 14, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 45, 14, 45, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 45, 22, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "5" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 13, 46, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 46, 13, 46, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 21, 46, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 47, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 47, 14, 47, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 47, 14, 47, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 47, 22, 47, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "6" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 48, 13, 48, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 13, 48, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 48, 21, 48, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 49, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 14, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 49, 14, 49, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 49, 22, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "7" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 50, 13, 50, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 50, 13, 50, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 50, 21, 50, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 51, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 51, 14, 51, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 51, 14, 51, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 51, 22, 51, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "8" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 52, 13, 52, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 52, 21, 52, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 8 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 53, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 53, 14, 53, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 53, 14, 53, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 53, 22, 53, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "9" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 54, 13, 54, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 54, 13, 54, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 54, 21, 54, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 56, 13, 56, 20 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 56, 20, 56, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 57, 9, 57, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 57, 9, 57, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "first_char" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 57, 22, 57, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 58, 9, 58, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 58, 27, 58, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 58, 32, 58, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 61, 5, 61, 24 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 61, 12, 61, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 61, 12, 61, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 61, 21, 61, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "sign" + } + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 64, 1, 64, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 64, 1, 64, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 64, 1, 64, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 64, 3, 64, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 64, 9, 64, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 65, 1, 65, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 65, 1, 65, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 65, 3, 65, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 65, 9, 65, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 68, 9, 68, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 69, 1, 69, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 69, 1, 69, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 69, 1, 69, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 69, 3, 69, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 69, 9, 69, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 70, 1, 70, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 70, 1, 70, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 70, 5, 70, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "UnaryExpr", + "location" : [ 70, 5, 70, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 70, 6, 70, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 10, 70, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 73, 1, 78, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 73, 7, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 73, 7, 73, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 73, 12, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 73, 12, 73, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 73, 16, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 74, 5, 74, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 5, 74, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 74, 9, 74, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 74, 9, 74, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 74, 20, 74, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 75, 5, 75, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 75, 5, 75, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 75, 11, 75, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 76, 5, 76, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 76, 9, 76, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 76, 9, 76, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 76, 9, 76, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "str_to_int" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 20, 76, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 76, 25, 76, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/benchmarks/stdlib.py.ast.typed.s.result b/pa3-tests/benchmarks/stdlib.py.ast.typed.s.result new file mode 100644 index 0000000..3a07fa4 --- /dev/null +++ b/pa3-tests/benchmarks/stdlib.py.ast.typed.s.result @@ -0,0 +1,21 @@ +-420 +-378 +-336 +-294 +-252 +-210 +-168 +-126 +-84 +-42 +0 +42 +84 +126 +168 +210 +252 +294 +336 +378 +420 diff --git a/pa3-tests/benchmarks/tree.py b/pa3-tests/benchmarks/tree.py new file mode 100644 index 0000000..9f337fd --- /dev/null +++ b/pa3-tests/benchmarks/tree.py @@ -0,0 +1,83 @@ +# Binary-search trees +class TreeNode(object): + value:int = 0 + left:"TreeNode" = None + right:"TreeNode" = None + + def insert(self:"TreeNode", x:int) -> bool: + if x < self.value: + if self.left is None: + self.left = makeNode(x) + return True + else: + return self.left.insert(x) + elif x > self.value: + if self.right is None: + self.right = makeNode(x) + return True + else: + return self.right.insert(x) + return False + + def contains(self:"TreeNode", x:int) -> bool: + if x < self.value: + if self.left is None: + return False + else: + return self.left.contains(x) + elif x > self.value: + if self.right is None: + return False + else: + return self.right.contains(x) + else: + return True + +class Tree(object): + root:TreeNode = None + size:int = 0 + + def insert(self:"Tree", x:int) -> object: + if self.root is None: + self.root = makeNode(x) + self.size = 1 + else: + if self.root.insert(x): + self.size = self.size + 1 + + def contains(self:"Tree", x:int) -> bool: + if self.root is None: + return False + else: + return self.root.contains(x) + +def makeNode(x: int) -> TreeNode: + b:TreeNode = None + b = TreeNode() + b.value = x + return b + + +# Input parameters +n:int = 100 +c:int = 4 + +# Data +t:Tree = None +i:int = 0 +k:int = 37813 + +# Crunch +t = Tree() +while i < n: + t.insert(k) + k = (k * 37813) % 37831 + if i % c != 0: + t.insert(i) + i = i + 1 + +print(t.size) + +for i in [4, 8, 15, 16, 23, 42]: + if t.contains(i): + print(i) diff --git a/pa3-tests/benchmarks/tree.py.ast.typed b/pa3-tests/benchmarks/tree.py.ast.typed new file mode 100644 index 0000000..a8d3cb3 --- /dev/null +++ b/pa3-tests/benchmarks/tree.py.ast.typed @@ -0,0 +1,2301 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 84, 2 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 14 ], + "name" : "TreeNode" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 21 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 6 ], + "name" : "value" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 2, 4, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 2, 4, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 2, 4, 5 ], + "name" : "left" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 16 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 20, 4, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 2, 5, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 2, 5, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 2, 5, 6 ], + "name" : "right" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 8, 5, 17 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 5, 21, 5, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 2, 20, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 6, 7, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 13, 7, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 27 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 30, 7, 34 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 30, 7, 30 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 32, 7, 34 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 40, 7, 43 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 8, 10, 8, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 8, 10, 8, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 9, 4, 14, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 9, 7, 9, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 9, 7, 9, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 9, 20, 9, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 10, 5, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 10, 10, 10, 13 ], + "name" : "left" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 10, 17, 10, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 17, 10, 24 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 10, 26, 10, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 12, 11, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 13, 5, 13, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 13, 12, 13, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 13, 12, 13, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 17, 13, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 22, 13, 27 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 29, 13, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 14, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 14, 8, 14, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 14, 8, 14, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 14, 12, 14, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 15, 4, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 7, 15, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 7, 15, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 15, 21, 15, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 5, 16, 28 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 5, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 10, 16, 14 ], + "name" : "right" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 18, 16, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 12, 17, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 19, 12, 19, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 17, 19, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 23, 19, 28 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 19, 30, 19, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 20, 3, 20, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 20, 10, 20, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 22, 2, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 22, 6, 22, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 22, 15, 22, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 15, 22, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 20, 22, 29 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 22, 32, 22, 36 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 32, 22, 32 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 34, 22, 36 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 22, 42, 22, 45 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 23, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 6, 23, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 6, 23, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 23, 10, 23, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 10, 23, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 24, 4, 28, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 7, 24, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 7, 24, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 7, 24, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 24, 20, 24, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 25, 5, 25, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 12, 25, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 27, 5, 27, 32 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 12, 27, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 29 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 12, 27, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 17, 27, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 22, 27, 29 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 27, 31, 27, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 28, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 8, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 28, 8, 28, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 28, 12, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 29, 4, 33, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 7, 29, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 29, 7, 29, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 7, 29, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 29, 21, 29, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 5, 30, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 30, 12, 30, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 32, 5, 32, 33 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 32, 12, 32, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 30 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 32, 12, 32, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 23, 32, 30 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 32, 32, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 34, 4, 34, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 34, 11, 34, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } ] + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 36, 1, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 10 ], + "name" : "Tree" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 37, 2, 37, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 2, 37, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 2, 37, 5 ], + "name" : "root" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 7, 37, 14 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 37, 18, 37, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 38, 2, 38, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 38, 2, 38, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 2, 38, 5 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 7, 38, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 13, 38, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 40, 2, 48, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 40, 6, 40, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 40, 13, 40, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 18, 40, 23 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 40, 26, 40, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 26, 40, 26 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 28, 40, 30 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 40, 36, 40, 41 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 41, 3, 48, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 6, 41, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 6, 41, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 6, 41, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 11, 41, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 4, 42, 26 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 42, 4, 42, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 42, 4, 42, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 42, 9, 42, 12 ], + "name" : "root" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 42, 16, 42, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 42, 16, 42, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 42, 25, 42, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 43, 4, 43, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 43, 4, 43, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 43, 4, 43, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 43, 9, 43, 12 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 43, 16, 43, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 4, 48, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 45, 7, 45, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 22 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 45, 7, 45, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 12, 45, 15 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 17, 45, 22 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 45, 24, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 5, 46, 29 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 46, 5, 46, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 46, 5, 46, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 10, 46, 13 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 46, 17, 46, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 46, 17, 46, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 46, 17, 46, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 22, 46, 25 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 29, 46, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 2, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 6, 48, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 15, 48, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 15, 48, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 20, 48, 25 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 48, 28, 48, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 28, 48, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 30, 48, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 38, 48, 41 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 49, 3, 54, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 6, 49, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 49, 6, 49, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 49, 6, 49, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 11, 49, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 49, 19, 49, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 50, 4, 50, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 50, 11, 50, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 52, 4, 52, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 52, 11, 52, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 52, 11, 52, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 16, 52, 19 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 21, 52, 28 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 30, 52, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 54, 1, 58, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 54, 5, 54, 12 ], + "name" : "makeNode" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 54, 14, 54, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 54, 14, 54, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 54, 17, 54, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 54, 25, 54, 32 ], + "className" : "TreeNode" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 55, 2, 55, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 55, 2, 55, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 55, 2, 55, 2 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 55, 4, 55, 11 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 55, 15, 55, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 56, 2, 56, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 56, 2, 56, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 56, 6, 56, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 56, 6, 56, 13 ], + "name" : "TreeNode" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 57, 2, 57, 12 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 57, 2, 57, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 2, 57, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 4, 57, 8 ], + "name" : "value" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 57, 12, 57, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + }, { + "kind" : "ReturnStmt", + "location" : [ 58, 2, 58, 9 ], + "value" : { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 62, 1, 62, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 62, 1, 62, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 62, 3, 62, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 62, 9, 62, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + }, { + "kind" : "VarDef", + "location" : [ 63, 1, 63, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 63, 1, 63, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 63, 3, 63, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 9, 63, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 66, 1, 66, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 66, 1, 66, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 1, 66, 1 ], + "name" : "t" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 3, 66, 6 ], + "className" : "Tree" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 66, 10, 66, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 67, 1, 67, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 1, 67, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 1, 67, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 3, 67, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 67, 9, 67, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 68, 9, 68, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37813 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 71, 1, 71, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 71, 1, 71, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 71, 5, 71, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 71, 5, 71, 8 ], + "name" : "Tree" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 72, 1, 79, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 72, 7, 72, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 72, 7, 72, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 72, 11, 72, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 73, 2, 73, 12 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 73, 2, 73, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 73, 2, 73, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 73, 2, 73, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 73, 4, 73, 9 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 73, 11, 73, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 74, 2, 74, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 2, 74, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 74, 6, 74, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 74, 7, 74, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 74, 7, 74, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 11, 74, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37813 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 20, 74, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37831 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 75, 2, 77, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 75, 9, 75, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 14, 75, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 76, 3, 76, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 76, 3, 76, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 76, 3, 76, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 76, 3, 76, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 10 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 12, 76, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 77, 2, 77, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 77, 2, 77, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 77, 6, 77, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 77, 6, 77, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 77, 10, 77, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 79, 1, 79, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 79, 1, 79, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 79, 7, 79, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 79, 7, 79, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 79, 9, 79, 12 ], + "name" : "size" + } + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 81, 1, 84, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 81, 5, 81, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 81, 10, 81, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 81, 11, 81, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 14, 81, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 8 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 17, 81, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 15 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 21, 81, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 16 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 25, 81, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 23 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 29, 81, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } ] + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 82, 2, 84, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 5, 82, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 5, 82, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 82, 5, 82, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 7, 82, 14 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 82, 16, 82, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 83, 3, 83, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 83, 3, 83, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 83, 3, 83, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/benchmarks/tree.py.ast.typed.s.result b/pa3-tests/benchmarks/tree.py.ast.typed.s.result new file mode 100644 index 0000000..bc9d65b --- /dev/null +++ b/pa3-tests/benchmarks/tree.py.ast.typed.s.result @@ -0,0 +1,4 @@ +175 +15 +23 +42 diff --git a/pa3-tests/chocopy-ref.jar b/pa3-tests/chocopy-ref.jar new file mode 100644 index 0000000..d036a97 Binary files /dev/null and b/pa3-tests/chocopy-ref.jar differ diff --git a/pa3-tests/core/call.py b/pa3-tests/core/call.py new file mode 100644 index 0000000..6b9ba64 --- /dev/null +++ b/pa3-tests/core/call.py @@ -0,0 +1,17 @@ +def f() -> int: + print("start f") + g() + print("end f") + return 42 + + +def g() -> object: + print("start g") + h() + print("end g") + +def h() -> object: + print("start h") + print("end h") + +print(f()) diff --git a/pa3-tests/core/call.py.ast.typed b/pa3-tests/core/call.py.ast.typed new file mode 100644 index 0000000..dd6d3f1 --- /dev/null +++ b/pa3-tests/core/call.py.ast.typed @@ -0,0 +1,386 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 11 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 5, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "f" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 12, 1, 14 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 2, 11, 2, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "start f" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 5, 3, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 5, 3, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "g" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 4, 11, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "end f" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 13 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 1, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "g" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 12, 8, 17 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 9, 5, 9, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 5, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 9, 11, 9, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "start g" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 5, 10, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 5, 10, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "h" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 5, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 5, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 11, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "end g" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 1, 15, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "h" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 12, 13, 17 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 14, 5, 14, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 5, 14, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 14, 11, 14, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "start h" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 5, 15, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 15, 11, 15, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "end h" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 17, 7, 17, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 7, 17, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/call.py.ast.typed.s.result b/pa3-tests/core/call.py.ast.typed.s.result new file mode 100644 index 0000000..ff1eea8 --- /dev/null +++ b/pa3-tests/core/call.py.ast.typed.s.result @@ -0,0 +1,7 @@ +start f +start g +start h +end h +end g +end f +42 diff --git a/pa3-tests/core/call_with_args.py b/pa3-tests/core/call_with_args.py new file mode 100644 index 0000000..bc9b16a --- /dev/null +++ b/pa3-tests/core/call_with_args.py @@ -0,0 +1,19 @@ +def f(x:int) -> int: + print("start f") + print(x) + g(1, x) + print("end f") + return x + + +def g(y:int, z:int) -> object: + print("start g") + print(y) + print(z) + h("h") + print("end g") + +def h(msg: str) -> object: + print(msg) + +print(f(4)) diff --git a/pa3-tests/core/call_with_args.py.ast.typed b/pa3-tests/core/call_with_args.py.ast.typed new file mode 100644 index 0000000..0ff917c --- /dev/null +++ b/pa3-tests/core/call_with_args.py.ast.typed @@ -0,0 +1,554 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 12 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 7, 1, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 9, 1, 11 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 17, 1, 19 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 2, 11, 2, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "start f" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 5, 3, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 5, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "g" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "Identifier", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 5, 5, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 5, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 5, 11, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "end f" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 6, 5, 6, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 9, 1, 14, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "g" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 7, 9, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 9, 9, 11 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 14, 9, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 14, 9, 14 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 16, 9, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 24, 9, 29 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 5, 10, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 5, 10, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 11, 10, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "start g" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 5, 11, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 5, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 5, 12, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 5, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 11, 12, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "z" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 5, 13, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 5, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "h" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 13, 7, 13, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "h" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 5, 14, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 5, 14, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 14, 11, 14, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "end g" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 1, 17, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "h" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 7, 16, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 9 ], + "name" : "msg" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 12, 16, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 20, 16, 25 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 17, 5, 17, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 17, 11, 17, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "msg" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 19, 9, 19, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/call_with_args.py.ast.typed.s.result b/pa3-tests/core/call_with_args.py.ast.typed.s.result new file mode 100644 index 0000000..816ee29 --- /dev/null +++ b/pa3-tests/core/call_with_args.py.ast.typed.s.result @@ -0,0 +1,9 @@ +start f +4 +start g +1 +4 +h +end g +end f +4 diff --git a/pa3-tests/core/error_div_zero.py b/pa3-tests/core/error_div_zero.py new file mode 100644 index 0000000..f4481c6 --- /dev/null +++ b/pa3-tests/core/error_div_zero.py @@ -0,0 +1 @@ +print(42 // 0) diff --git a/pa3-tests/core/error_div_zero.py.ast.typed b/pa3-tests/core/error_div_zero.py.ast.typed new file mode 100644 index 0000000..c498a39 --- /dev/null +++ b/pa3-tests/core/error_div_zero.py.ast.typed @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 15 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/error_div_zero.py.ast.typed.s.result b/pa3-tests/core/error_div_zero.py.ast.typed.s.result new file mode 100644 index 0000000..3233f6d --- /dev/null +++ b/pa3-tests/core/error_div_zero.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Division by zero +Exited with error code 2 diff --git a/pa3-tests/core/error_invalid_print.py b/pa3-tests/core/error_invalid_print.py new file mode 100644 index 0000000..ca057e5 --- /dev/null +++ b/pa3-tests/core/error_invalid_print.py @@ -0,0 +1 @@ +print(None) diff --git a/pa3-tests/core/error_invalid_print.py.ast.typed b/pa3-tests/core/error_invalid_print.py.ast.typed new file mode 100644 index 0000000..311e64a --- /dev/null +++ b/pa3-tests/core/error_invalid_print.py.ast.typed @@ -0,0 +1,46 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 12 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "NoneLiteral", + "location" : [ 1, 7, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/error_invalid_print.py.ast.typed.s.result b/pa3-tests/core/error_invalid_print.py.ast.typed.s.result new file mode 100644 index 0000000..cfb08fa --- /dev/null +++ b/pa3-tests/core/error_invalid_print.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Invalid argument +Exited with error code 1 diff --git a/pa3-tests/core/error_mod_zero.py b/pa3-tests/core/error_mod_zero.py new file mode 100644 index 0000000..09cfbef --- /dev/null +++ b/pa3-tests/core/error_mod_zero.py @@ -0,0 +1 @@ +print(42 % 0) diff --git a/pa3-tests/core/error_mod_zero.py.ast.typed b/pa3-tests/core/error_mod_zero.py.ast.typed new file mode 100644 index 0000000..371eb36 --- /dev/null +++ b/pa3-tests/core/error_mod_zero.py.ast.typed @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 14 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 12, 1, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/error_mod_zero.py.ast.typed.s.result b/pa3-tests/core/error_mod_zero.py.ast.typed.s.result new file mode 100644 index 0000000..3233f6d --- /dev/null +++ b/pa3-tests/core/error_mod_zero.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Division by zero +Exited with error code 2 diff --git a/pa3-tests/core/expr_if.py b/pa3-tests/core/expr_if.py new file mode 100644 index 0000000..e0f0764 --- /dev/null +++ b/pa3-tests/core/expr_if.py @@ -0,0 +1,2 @@ +print(3 if True else 4) +print(3 if False else 4) diff --git a/pa3-tests/core/expr_if.py.ast.typed b/pa3-tests/core/expr_if.py.ast.typed new file mode 100644 index 0000000..3b06e26 --- /dev/null +++ b/pa3-tests/core/expr_if.py.ast.typed @@ -0,0 +1,135 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 25 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IfExpr", + "location" : [ 1, 7, 1, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 12, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 22, 1, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 24 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IfExpr", + "location" : [ 2, 7, 2, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 7, 2, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 23, 2, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/expr_if.py.ast.typed.s.result b/pa3-tests/core/expr_if.py.ast.typed.s.result new file mode 100644 index 0000000..b944734 --- /dev/null +++ b/pa3-tests/core/expr_if.py.ast.typed.s.result @@ -0,0 +1,2 @@ +3 +4 diff --git a/pa3-tests/core/id_global.py b/pa3-tests/core/id_global.py new file mode 100644 index 0000000..d72c7d2 --- /dev/null +++ b/pa3-tests/core/id_global.py @@ -0,0 +1,2 @@ +x:int = 42 +print(x) diff --git a/pa3-tests/core/id_global.py.ast.typed b/pa3-tests/core/id_global.py.ast.typed new file mode 100644 index 0000000..9605936 --- /dev/null +++ b/pa3-tests/core/id_global.py.ast.typed @@ -0,0 +1,73 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/id_global.py.ast.typed.s.result b/pa3-tests/core/id_global.py.ast.typed.s.result new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/pa3-tests/core/id_global.py.ast.typed.s.result @@ -0,0 +1 @@ +42 diff --git a/pa3-tests/core/id_local.py b/pa3-tests/core/id_local.py new file mode 100644 index 0000000..ff6dec8 --- /dev/null +++ b/pa3-tests/core/id_local.py @@ -0,0 +1,5 @@ +def f() -> int: + x:int = 1 + return x + +print(f()) diff --git a/pa3-tests/core/id_local.py.ast.typed b/pa3-tests/core/id_local.py.ast.typed new file mode 100644 index 0000000..472aa17 --- /dev/null +++ b/pa3-tests/core/id_local.py.ast.typed @@ -0,0 +1,114 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 11 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "f" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 12, 1, 14 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 3, 2, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 3, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 3 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 5, 2, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 3, 3, 10 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 5, 7, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/id_local.py.ast.typed.s.result b/pa3-tests/core/id_local.py.ast.typed.s.result new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/pa3-tests/core/id_local.py.ast.typed.s.result @@ -0,0 +1 @@ +1 diff --git a/pa3-tests/core/input.py b/pa3-tests/core/input.py new file mode 100644 index 0000000..a47c902 --- /dev/null +++ b/pa3-tests/core/input.py @@ -0,0 +1,8 @@ +# Test of 'input' function. + +s: str = "" + +s = input() +while len(s) > 0: + print(s) + s = input() diff --git a/pa3-tests/core/input.py.ast.in b/pa3-tests/core/input.py.ast.in new file mode 100644 index 0000000..2638e9f --- /dev/null +++ b/pa3-tests/core/input.py.ast.in @@ -0,0 +1,4 @@ +First line. +Next line is blank. + +Last line. diff --git a/pa3-tests/core/input.py.ast.typed b/pa3-tests/core/input.py.ast.typed new file mode 100644 index 0000000..edf0a5d --- /dev/null +++ b/pa3-tests/core/input.py.ast.typed @@ -0,0 +1,196 @@ +{ + "kind" : "Program", + "location" : [ 3, 1, 9, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 6 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 10, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 5, 5, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "input" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 6, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 6, 7, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 6, 7, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 16, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 5, 8, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "input" + }, + "args" : [ ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/input.py.ast.typed.in b/pa3-tests/core/input.py.ast.typed.in new file mode 100644 index 0000000..2638e9f --- /dev/null +++ b/pa3-tests/core/input.py.ast.typed.in @@ -0,0 +1,4 @@ +First line. +Next line is blank. + +Last line. diff --git a/pa3-tests/core/input.py.ast.typed.s.result b/pa3-tests/core/input.py.ast.typed.s.result new file mode 100644 index 0000000..86e7fe4 --- /dev/null +++ b/pa3-tests/core/input.py.ast.typed.s.result @@ -0,0 +1,8 @@ +First line. + +Next line is blank. + + + +Last line. + diff --git a/pa3-tests/core/input.py.in b/pa3-tests/core/input.py.in new file mode 100644 index 0000000..2638e9f --- /dev/null +++ b/pa3-tests/core/input.py.in @@ -0,0 +1,4 @@ +First line. +Next line is blank. + +Last line. diff --git a/pa3-tests/core/len_invalid_1.py b/pa3-tests/core/len_invalid_1.py new file mode 100644 index 0000000..1dfa598 --- /dev/null +++ b/pa3-tests/core/len_invalid_1.py @@ -0,0 +1,3 @@ +x:[int] = None + +print(len(x)) diff --git a/pa3-tests/core/len_invalid_1.py.ast.typed b/pa3-tests/core/len_invalid_1.py.ast.typed new file mode 100644 index 0000000..170d7ee --- /dev/null +++ b/pa3-tests/core/len_invalid_1.py.ast.typed @@ -0,0 +1,103 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 1, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 3, 7, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 7, 3, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/len_invalid_1.py.ast.typed.s.result b/pa3-tests/core/len_invalid_1.py.ast.typed.s.result new file mode 100644 index 0000000..cfb08fa --- /dev/null +++ b/pa3-tests/core/len_invalid_1.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Invalid argument +Exited with error code 1 diff --git a/pa3-tests/core/len_invalid_2.py b/pa3-tests/core/len_invalid_2.py new file mode 100644 index 0000000..de46502 --- /dev/null +++ b/pa3-tests/core/len_invalid_2.py @@ -0,0 +1,3 @@ +x:int = 1 + +print(len(x)) diff --git a/pa3-tests/core/len_invalid_2.py.ast.typed b/pa3-tests/core/len_invalid_2.py.ast.typed new file mode 100644 index 0000000..afc264d --- /dev/null +++ b/pa3-tests/core/len_invalid_2.py.ast.typed @@ -0,0 +1,97 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 1, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 3, 7, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 7, 3, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/len_invalid_2.py.ast.typed.s.result b/pa3-tests/core/len_invalid_2.py.ast.typed.s.result new file mode 100644 index 0000000..cfb08fa --- /dev/null +++ b/pa3-tests/core/len_invalid_2.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Invalid argument +Exited with error code 1 diff --git a/pa3-tests/core/list_concat.py b/pa3-tests/core/list_concat.py new file mode 100644 index 0000000..d2ef21d --- /dev/null +++ b/pa3-tests/core/list_concat.py @@ -0,0 +1,12 @@ +def concat(x:[int], y:[int]) -> [int]: + return x + y + +z:[int] = None +i:int = 0 + +z = concat([1,2,3], [4,5,6]) + +while i < len(z): + print(z[i]) + i = i + 1 + diff --git a/pa3-tests/core/list_concat.py.ast.typed b/pa3-tests/core/list_concat.py.ast.typed new file mode 100644 index 0000000..38ba198 --- /dev/null +++ b/pa3-tests/core/list_concat.py.ast.typed @@ -0,0 +1,437 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 10 ], + "name" : "concat" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 12, 1, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 14, 1, 18 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 15, 1, 17 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 21, 1, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 21, 1, 21 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 23, 1, 27 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 24, 1, 26 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 1, 33, 1, 37 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 34, 1, 36 ], + "className" : "int" + } + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "y" + } + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "concat" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 7, 12, 7, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 15, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 17, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, { + "kind" : "ListExpr", + "location" : [ 7, 21, 7, 27 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 22, 7, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 24, 7, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 26, 7, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + } ] + } ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 9, 1, 13, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 9, 7, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 9, 11, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 11, 9, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ] + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 5, 10, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 5, 10, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 10, 11, 10, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 10, 11, 10, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 5, 11, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 13, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_concat.py.ast.typed.s.result b/pa3-tests/core/list_concat.py.ast.typed.s.result new file mode 100644 index 0000000..b414108 --- /dev/null +++ b/pa3-tests/core/list_concat.py.ast.typed.s.result @@ -0,0 +1,6 @@ +1 +2 +3 +4 +5 +6 diff --git a/pa3-tests/core/list_concat_2.py b/pa3-tests/core/list_concat_2.py new file mode 100644 index 0000000..ed0826c --- /dev/null +++ b/pa3-tests/core/list_concat_2.py @@ -0,0 +1,8 @@ +z:[int] = None +i:int = 0 + +z = [1,2,3] + [4,5,6] + [7,8,9] + +while i < len(z): + print(z[i]) + i = i + 1 diff --git a/pa3-tests/core/list_concat_2.py.ast.typed b/pa3-tests/core/list_concat_2.py.ast.typed new file mode 100644 index 0000000..f5a28b0 --- /dev/null +++ b/pa3-tests/core/list_concat_2.py.ast.typed @@ -0,0 +1,366 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 31 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 4, 15, 4, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 16, 4, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 18, 4, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 20, 4, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + } ] + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 4, 25, 4, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 26, 4, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 28, 4, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 8 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 30, 4, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } ] + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 6, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 6, 7, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 6, 11, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 15, 6, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ] + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 11, 7, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 5, 8, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_concat_2.py.ast.typed.s.result b/pa3-tests/core/list_concat_2.py.ast.typed.s.result new file mode 100644 index 0000000..0719398 --- /dev/null +++ b/pa3-tests/core/list_concat_2.py.ast.typed.s.result @@ -0,0 +1,9 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/pa3-tests/core/list_concat_none.py b/pa3-tests/core/list_concat_none.py new file mode 100644 index 0000000..ad0a310 --- /dev/null +++ b/pa3-tests/core/list_concat_none.py @@ -0,0 +1,4 @@ +x:[int] = None +y:[int] = None + +print(len(x+y)) diff --git a/pa3-tests/core/list_concat_none.py.ast.typed b/pa3-tests/core/list_concat_none.py.ast.typed new file mode 100644 index 0000000..5c50b2a --- /dev/null +++ b/pa3-tests/core/list_concat_none.py.ast.typed @@ -0,0 +1,156 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 4, 7, 4, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 4, 11, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 11, 4, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "y" + } + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_concat_none.py.ast.typed.s.result b/pa3-tests/core/list_concat_none.py.ast.typed.s.result new file mode 100644 index 0000000..ae52477 --- /dev/null +++ b/pa3-tests/core/list_concat_none.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/list_get_element.py b/pa3-tests/core/list_get_element.py new file mode 100644 index 0000000..54a3835 --- /dev/null +++ b/pa3-tests/core/list_get_element.py @@ -0,0 +1,6 @@ +x:[int] = None + +x = [1, 2, 3] +print(x[0]) +print(x[1]) +print(x[2]) diff --git a/pa3-tests/core/list_get_element.py.ast.typed b/pa3-tests/core/list_get_element.py.ast.typed new file mode 100644 index 0000000..71a94cb --- /dev/null +++ b/pa3-tests/core/list_get_element.py.ast.typed @@ -0,0 +1,259 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 7, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 5, 7, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element.py.ast.typed.s.result b/pa3-tests/core/list_get_element.py.ast.typed.s.result new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/pa3-tests/core/list_get_element.py.ast.typed.s.result @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/pa3-tests/core/list_get_element_complex.py b/pa3-tests/core/list_get_element_complex.py new file mode 100644 index 0000000..fe03e8d --- /dev/null +++ b/pa3-tests/core/list_get_element_complex.py @@ -0,0 +1,11 @@ +next:int = 0 + +def next_int() -> int: + global next + next = next + 1 + return next + +def make_list() -> [int]: + return [next_int(), next_int(), next_int()] + +print(make_list()[next_int() - 3]) diff --git a/pa3-tests/core/list_get_element_complex.py.ast.typed b/pa3-tests/core/list_get_element_complex.py.ast.typed new file mode 100644 index 0000000..f3c48bb --- /dev/null +++ b/pa3-tests/core/list_get_element_complex.py.ast.typed @@ -0,0 +1,313 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 35 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 12 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 4 ], + "name" : "next" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 6, 1, 8 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 12, 1, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 6, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 12 ], + "name" : "next_int" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 19, 3, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 4, 5, 4, 15 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 15 ], + "name" : "next" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 5, 5, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "next" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 12, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "next" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 19, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 6, 5, 6, 15 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "next" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 1, 9, 48 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 13 ], + "name" : "make_list" + }, + "params" : [ ], + "returnType" : { + "kind" : "ListType", + "location" : [ 8, 20, 8, 24 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 8, 21, 8, 23 ], + "className" : "int" + } + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 47 ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 12, 9, 47 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "CallExpr", + "location" : [ 9, 13, 9, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "next_int" + }, + "args" : [ ] + }, { + "kind" : "CallExpr", + "location" : [ 9, 25, 9, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 32 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "next_int" + }, + "args" : [ ] + }, { + "kind" : "CallExpr", + "location" : [ 9, 37, 9, 46 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 37, 9, 44 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "next_int" + }, + "args" : [ ] + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 34 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 11, 7, 11, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "CallExpr", + "location" : [ 11, 7, 11, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 15 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "make_list" + }, + "args" : [ ] + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 11, 19, 11, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 11, 19, 11, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 19, 11, 26 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "next_int" + }, + "args" : [ ] + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 32, 11, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element_complex.py.ast.typed.s.result b/pa3-tests/core/list_get_element_complex.py.ast.typed.s.result new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/pa3-tests/core/list_get_element_complex.py.ast.typed.s.result @@ -0,0 +1 @@ +2 diff --git a/pa3-tests/core/list_get_element_none.py b/pa3-tests/core/list_get_element_none.py new file mode 100644 index 0000000..871b395 --- /dev/null +++ b/pa3-tests/core/list_get_element_none.py @@ -0,0 +1,3 @@ +x:[int] = None + +print(x[0]) diff --git a/pa3-tests/core/list_get_element_none.py.ast.typed b/pa3-tests/core/list_get_element_none.py.ast.typed new file mode 100644 index 0000000..a95c813 --- /dev/null +++ b/pa3-tests/core/list_get_element_none.py.ast.typed @@ -0,0 +1,96 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 1, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 3, 7, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 3, 7, 3, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element_none.py.ast.typed.s.result b/pa3-tests/core/list_get_element_none.py.ast.typed.s.result new file mode 100644 index 0000000..ae52477 --- /dev/null +++ b/pa3-tests/core/list_get_element_none.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/list_get_element_oob_1.py b/pa3-tests/core/list_get_element_oob_1.py new file mode 100644 index 0000000..7b0e490 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_1.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [1, 2, 3] +print(x[-1]) diff --git a/pa3-tests/core/list_get_element_oob_1.py.ast.typed b/pa3-tests/core/list_get_element_oob_1.py.ast.typed new file mode 100644 index 0000000..c5e9254 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_1.py.ast.typed @@ -0,0 +1,156 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 7, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "UnaryExpr", + "location" : [ 4, 9, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element_oob_1.py.ast.typed.s.result b/pa3-tests/core/list_get_element_oob_1.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_1.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/list_get_element_oob_2.py b/pa3-tests/core/list_get_element_oob_2.py new file mode 100644 index 0000000..ba070b2 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_2.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [1, 2, 3] +print(x[3]) diff --git a/pa3-tests/core/list_get_element_oob_2.py.ast.typed b/pa3-tests/core/list_get_element_oob_2.py.ast.typed new file mode 100644 index 0000000..070d13b --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_2.py.ast.typed @@ -0,0 +1,147 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 7, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element_oob_2.py.ast.typed.s.result b/pa3-tests/core/list_get_element_oob_2.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_2.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/list_get_element_oob_3.py b/pa3-tests/core/list_get_element_oob_3.py new file mode 100644 index 0000000..827aae5 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_3.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [] +print(x[0]) diff --git a/pa3-tests/core/list_get_element_oob_3.py.ast.typed b/pa3-tests/core/list_get_element_oob_3.py.ast.typed new file mode 100644 index 0000000..aaeb34f --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_3.py.ast.typed @@ -0,0 +1,120 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 7, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_get_element_oob_3.py.ast.typed.s.result b/pa3-tests/core/list_get_element_oob_3.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_get_element_oob_3.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/list_len.py b/pa3-tests/core/list_len.py new file mode 100644 index 0000000..95ba341 --- /dev/null +++ b/pa3-tests/core/list_len.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [1, 2, 3] +print(len(x)) diff --git a/pa3-tests/core/list_len.py.ast.typed b/pa3-tests/core/list_len.py.ast.typed new file mode 100644 index 0000000..5a34893 --- /dev/null +++ b/pa3-tests/core/list_len.py.ast.typed @@ -0,0 +1,154 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 4, 7, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 11, 4, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_len.py.ast.typed.s.result b/pa3-tests/core/list_len.py.ast.typed.s.result new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/pa3-tests/core/list_len.py.ast.typed.s.result @@ -0,0 +1 @@ +3 diff --git a/pa3-tests/core/list_len_empty.py b/pa3-tests/core/list_len_empty.py new file mode 100644 index 0000000..52bd178 --- /dev/null +++ b/pa3-tests/core/list_len_empty.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [] +print(len(x)) diff --git a/pa3-tests/core/list_len_empty.py.ast.typed b/pa3-tests/core/list_len_empty.py.ast.typed new file mode 100644 index 0000000..4b70475 --- /dev/null +++ b/pa3-tests/core/list_len_empty.py.ast.typed @@ -0,0 +1,127 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 4, 7, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 11, 4, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_len_empty.py.ast.typed.s.result b/pa3-tests/core/list_len_empty.py.ast.typed.s.result new file mode 100644 index 0000000..573541a --- /dev/null +++ b/pa3-tests/core/list_len_empty.py.ast.typed.s.result @@ -0,0 +1 @@ +0 diff --git a/pa3-tests/core/list_set_element.py b/pa3-tests/core/list_set_element.py new file mode 100644 index 0000000..c678fe9 --- /dev/null +++ b/pa3-tests/core/list_set_element.py @@ -0,0 +1,9 @@ +x:[int] = None + +x = [1, 2, 3] +x[0] = 4 +x[1] = 5 +x[2] = 6 +print(x[0]) +print(x[1]) +print(x[2]) diff --git a/pa3-tests/core/list_set_element.py.ast.typed b/pa3-tests/core/list_set_element.py.ast.typed new file mode 100644 index 0000000..69649ee --- /dev/null +++ b/pa3-tests/core/list_set_element.py.ast.typed @@ -0,0 +1,382 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 3, 4, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 5, 1, 5, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 3, 5, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 8, 5, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 3, 6, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 7, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 8, 7, 8, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 9, 8, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 9, 7, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 9, 9, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_set_element.py.ast.typed.s.result b/pa3-tests/core/list_set_element.py.ast.typed.s.result new file mode 100644 index 0000000..4578bc1 --- /dev/null +++ b/pa3-tests/core/list_set_element.py.ast.typed.s.result @@ -0,0 +1,3 @@ +4 +5 +6 diff --git a/pa3-tests/core/list_set_element_none.py b/pa3-tests/core/list_set_element_none.py new file mode 100644 index 0000000..281c7b4 --- /dev/null +++ b/pa3-tests/core/list_set_element_none.py @@ -0,0 +1,4 @@ +x:[int] = None + +x[0] = 1 + diff --git a/pa3-tests/core/list_set_element_none.py.ast.typed b/pa3-tests/core/list_set_element_none.py.ast.typed new file mode 100644 index 0000000..fd16a97 --- /dev/null +++ b/pa3-tests/core/list_set_element_none.py.ast.typed @@ -0,0 +1,81 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 3, 1, 3, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 3, 3, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 8, 3, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_set_element_none.py.ast.typed.s.result b/pa3-tests/core/list_set_element_none.py.ast.typed.s.result new file mode 100644 index 0000000..ae52477 --- /dev/null +++ b/pa3-tests/core/list_set_element_none.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/list_set_element_oob_1.py b/pa3-tests/core/list_set_element_oob_1.py new file mode 100644 index 0000000..efd92ca --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_1.py @@ -0,0 +1,7 @@ +x:[int] = None + +x = [1, 2, 3] +x[-1] = 4 +print(x[0]) +print(x[1]) +print(x[2]) diff --git a/pa3-tests/core/list_set_element_oob_1.py.ast.typed b/pa3-tests/core/list_set_element_oob_1.py.ast.typed new file mode 100644 index 0000000..ed84b22 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_1.py.ast.typed @@ -0,0 +1,309 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "UnaryExpr", + "location" : [ 4, 3, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 4, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 5, 7, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 7, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_set_element_oob_1.py.ast.typed.s.result b/pa3-tests/core/list_set_element_oob_1.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_1.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/list_set_element_oob_2.py b/pa3-tests/core/list_set_element_oob_2.py new file mode 100644 index 0000000..301cea1 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_2.py @@ -0,0 +1,7 @@ +x:[int] = None + +x = [1, 2, 3] +x[4] = 4 +print(x[0]) +print(x[1]) +print(x[2]) diff --git a/pa3-tests/core/list_set_element_oob_2.py.ast.typed b/pa3-tests/core/list_set_element_oob_2.py.ast.typed new file mode 100644 index 0000000..5c06dca --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_2.py.ast.typed @@ -0,0 +1,300 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 3, 4, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 5, 7, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 7, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_set_element_oob_2.py.ast.typed.s.result b/pa3-tests/core/list_set_element_oob_2.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_2.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/list_set_element_oob_3.py b/pa3-tests/core/list_set_element_oob_3.py new file mode 100644 index 0000000..281c93c --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_3.py @@ -0,0 +1,4 @@ +x:[int] = None + +x = [] +x[0] = 4 diff --git a/pa3-tests/core/list_set_element_oob_3.py.ast.typed b/pa3-tests/core/list_set_element_oob_3.py.ast.typed new file mode 100644 index 0000000..ec34032 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_3.py.ast.typed @@ -0,0 +1,105 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 3, 4, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/list_set_element_oob_3.py.ast.typed.s.result b/pa3-tests/core/list_set_element_oob_3.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/list_set_element_oob_3.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/literal_bool.py b/pa3-tests/core/literal_bool.py new file mode 100644 index 0000000..54b7f1f --- /dev/null +++ b/pa3-tests/core/literal_bool.py @@ -0,0 +1,2 @@ +print(True) +print(False) diff --git a/pa3-tests/core/literal_bool.py.ast.typed b/pa3-tests/core/literal_bool.py.ast.typed new file mode 100644 index 0000000..436e5f7 --- /dev/null +++ b/pa3-tests/core/literal_bool.py.ast.typed @@ -0,0 +1,83 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 1, 7, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 2, 7, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/literal_bool.py.ast.typed.s.result b/pa3-tests/core/literal_bool.py.ast.typed.s.result new file mode 100644 index 0000000..1cc8b5e --- /dev/null +++ b/pa3-tests/core/literal_bool.py.ast.typed.s.result @@ -0,0 +1,2 @@ +True +False diff --git a/pa3-tests/core/literal_int.py b/pa3-tests/core/literal_int.py new file mode 100644 index 0000000..3e78541 --- /dev/null +++ b/pa3-tests/core/literal_int.py @@ -0,0 +1,2 @@ +print(42) +print(65999) diff --git a/pa3-tests/core/literal_int.py.ast.typed b/pa3-tests/core/literal_int.py.ast.typed new file mode 100644 index 0000000..eed7bda --- /dev/null +++ b/pa3-tests/core/literal_int.py.ast.typed @@ -0,0 +1,83 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 7, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 65999 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/literal_int.py.ast.typed.s.result b/pa3-tests/core/literal_int.py.ast.typed.s.result new file mode 100644 index 0000000..454025b --- /dev/null +++ b/pa3-tests/core/literal_int.py.ast.typed.s.result @@ -0,0 +1,2 @@ +42 +65999 diff --git a/pa3-tests/core/literal_str.py b/pa3-tests/core/literal_str.py new file mode 100644 index 0000000..ad35e5a --- /dev/null +++ b/pa3-tests/core/literal_str.py @@ -0,0 +1 @@ +print("Hello World") diff --git a/pa3-tests/core/literal_str.py.ast.typed b/pa3-tests/core/literal_str.py.ast.typed new file mode 100644 index 0000000..9b924a5 --- /dev/null +++ b/pa3-tests/core/literal_str.py.ast.typed @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 21 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 7, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello World" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/literal_str.py.ast.typed.s.result b/pa3-tests/core/literal_str.py.ast.typed.s.result new file mode 100644 index 0000000..557db03 --- /dev/null +++ b/pa3-tests/core/literal_str.py.ast.typed.s.result @@ -0,0 +1 @@ +Hello World diff --git a/pa3-tests/core/nested.py b/pa3-tests/core/nested.py new file mode 100644 index 0000000..3faa85b --- /dev/null +++ b/pa3-tests/core/nested.py @@ -0,0 +1,11 @@ +g: int = 1 +def foo(x: int) -> int: + y: int = 2 + def bar() -> int: + z: int = 3 + def baz() -> int: + return y + return baz() + return bar() + +print(foo(g)) diff --git a/pa3-tests/core/nested.py.ast.typed b/pa3-tests/core/nested.py.ast.typed new file mode 100644 index 0000000..ecdc57d --- /dev/null +++ b/pa3-tests/core/nested.py.ast.typed @@ -0,0 +1,272 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "g" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 2, 1, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 8, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 9, 5, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 12, 5, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 18, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 9, 7, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 13, 6, 15 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 22, 6, 24 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 13, 7, 20 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 20, 7, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 20 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 16, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "baz" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 12, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 11, 7, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "g" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/nested.py.ast.typed.s.result b/pa3-tests/core/nested.py.ast.typed.s.result new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/pa3-tests/core/nested.py.ast.typed.s.result @@ -0,0 +1 @@ +2 diff --git a/pa3-tests/core/nested2.py b/pa3-tests/core/nested2.py new file mode 100644 index 0000000..abafcce --- /dev/null +++ b/pa3-tests/core/nested2.py @@ -0,0 +1,14 @@ +g: int = 1 +def foo(x: int) -> int: + y: int = 2 + def bar() -> int: + z: int = 3 + def baz() -> int: + return qux(y) + return baz() + def qux(p: int) -> int: + return p + + return bar() + +print(foo(g)) diff --git a/pa3-tests/core/nested2.py.ast.typed b/pa3-tests/core/nested2.py.ast.typed new file mode 100644 index 0000000..8955e9f --- /dev/null +++ b/pa3-tests/core/nested2.py.ast.typed @@ -0,0 +1,337 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "g" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 2, 1, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 8, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 9, 5, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 12, 5, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 18, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 9, 7, 26 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 13, 6, 15 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 22, 6, 24 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 13, 7, 25 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 20, 7, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 20, 7, 22 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "qux" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 24, 7, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 20 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 16, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "baz" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 16, 9, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 24, 9, 26 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "p" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 5, 12, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 12, 12, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 12, 12, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 14, 7, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "g" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/nested2.py.ast.typed.s.result b/pa3-tests/core/nested2.py.ast.typed.s.result new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/pa3-tests/core/nested2.py.ast.typed.s.result @@ -0,0 +1 @@ +2 diff --git a/pa3-tests/core/object_attr_get.py b/pa3-tests/core/object_attr_get.py new file mode 100644 index 0000000..a6bed67 --- /dev/null +++ b/pa3-tests/core/object_attr_get.py @@ -0,0 +1,16 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + +a:A = None +b:B = None + +a = b = B() +print(a.a) +print(b.a) +print(b.b) diff --git a/pa3-tests/core/object_attr_get.py.ast.typed b/pa3-tests/core/object_attr_get.py.ast.typed new file mode 100644 index 0000000..f87f054 --- /dev/null +++ b/pa3-tests/core/object_attr_get.py.ast.typed @@ -0,0 +1,387 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 10, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 10, 1, 10, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 10, 1, 10, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 3, 10, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 7, 10, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 13, 9, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 9 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 7, 15, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "b" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_attr_get.py.ast.typed.s.result b/pa3-tests/core/object_attr_get.py.ast.typed.s.result new file mode 100644 index 0000000..79171bc --- /dev/null +++ b/pa3-tests/core/object_attr_get.py.ast.typed.s.result @@ -0,0 +1,4 @@ +B +42 +42 +True diff --git a/pa3-tests/core/object_attr_get_none.py b/pa3-tests/core/object_attr_get_none.py new file mode 100644 index 0000000..270bb16 --- /dev/null +++ b/pa3-tests/core/object_attr_get_none.py @@ -0,0 +1,16 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + +a:A = None +b:B = None + +a = B() +print(a.a) +print(b.a) +print(b.b) diff --git a/pa3-tests/core/object_attr_get_none.py.ast.typed b/pa3-tests/core/object_attr_get_none.py.ast.typed new file mode 100644 index 0000000..2787984 --- /dev/null +++ b/pa3-tests/core/object_attr_get_none.py.ast.typed @@ -0,0 +1,379 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 10, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 10, 1, 10, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 10, 1, 10, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 3, 10, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 7, 10, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 13, 5, 13, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 7, 15, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "b" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_attr_get_none.py.ast.typed.s.result b/pa3-tests/core/object_attr_get_none.py.ast.typed.s.result new file mode 100644 index 0000000..80d81d1 --- /dev/null +++ b/pa3-tests/core/object_attr_get_none.py.ast.typed.s.result @@ -0,0 +1,4 @@ +B +42 +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/object_attr_set.py b/pa3-tests/core/object_attr_set.py new file mode 100644 index 0000000..4183999 --- /dev/null +++ b/pa3-tests/core/object_attr_set.py @@ -0,0 +1,18 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + +a:A = None +b:B = None + +a = b = B() +b.a = 1 +b.b = False +print(a.a) +print(b.a) +print(b.b) diff --git a/pa3-tests/core/object_attr_set.py.ast.typed b/pa3-tests/core/object_attr_set.py.ast.typed new file mode 100644 index 0000000..4ea6427 --- /dev/null +++ b/pa3-tests/core/object_attr_set.py.ast.typed @@ -0,0 +1,455 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 10, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 10, 1, 10, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 10, 1, 10, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 3, 10, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 7, 10, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 13, 9, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 9 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 14, 1, 14, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 1, 14, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 3, 14, 3 ], + "name" : "a" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 11 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 1, 15, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 3, 15, 3 ], + "name" : "b" + } + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 15, 7, 15, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 17, 7, 17, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 17, 7, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 18, 7, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 18, 9, 18, 9 ], + "name" : "b" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_attr_set.py.ast.typed.s.result b/pa3-tests/core/object_attr_set.py.ast.typed.s.result new file mode 100644 index 0000000..abf1b17 --- /dev/null +++ b/pa3-tests/core/object_attr_set.py.ast.typed.s.result @@ -0,0 +1,4 @@ +B +1 +1 +False diff --git a/pa3-tests/core/object_attr_set_eval_order.py b/pa3-tests/core/object_attr_set_eval_order.py new file mode 100644 index 0000000..162559d --- /dev/null +++ b/pa3-tests/core/object_attr_set_eval_order.py @@ -0,0 +1,33 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + +a:A = None +b:B = None + +def get_b() -> B: + print("Getting B") + return b + +def get_one() -> int: + print("Getting 1") + return 1 + +def get_false() -> bool: + print("Getting False") + return False + +a = b = B() +get_b().a = get_one() +print("Assigned B.a") +get_b().b = get_false() +print("Assigned B.b") + +print(a.a) +print(b.a) +print(b.b) diff --git a/pa3-tests/core/object_attr_set_eval_order.py.ast.typed b/pa3-tests/core/object_attr_set_eval_order.py.ast.typed new file mode 100644 index 0000000..16ae244 --- /dev/null +++ b/pa3-tests/core/object_attr_set_eval_order.py.ast.typed @@ -0,0 +1,771 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 33, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 10, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 10, 1, 10, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 10, 1, 10, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 3, 10, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 7, 10, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "FuncDef", + "location" : [ 13, 1, 15, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 9 ], + "name" : "get_b" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 16, 13, 16 ], + "className" : "B" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 14, 5, 14, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 5, 14, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 14, 11, 14, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Getting B" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 15, 5, 15, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 19, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 11 ], + "name" : "get_one" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 5, 18, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 5, 18, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 18, 11, 18, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Getting 1" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 12, 19, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 21, 1, 23, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 13 ], + "name" : "get_false" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 21, 20, 21, 23 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 5, 22, 26 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 22, 11, 22, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Getting False" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 23, 5, 23, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 23, 12, 23, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 25, 1, 25, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 25, 5, 25, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 25, 9, 25, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 9 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 1, 26, 21 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 26, 1, 26, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "B" + } + }, + "name" : "get_b" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 9, 26, 9 ], + "name" : "a" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 26, 13, 26, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 26, 13, 26, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "get_one" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 27, 1, 27, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 27, 7, 27, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Assigned B.a" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 28, 1, 28, 23 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 28, 1, 28, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 28, 1, 28, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "B" + } + }, + "name" : "get_b" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 9 ], + "name" : "b" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 28, 13, 28, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 28, 13, 28, 21 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "get_false" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 29, 1, 29, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 29, 1, 29, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 29, 7, 29, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Assigned B.b" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 31, 1, 31, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 31, 1, 31, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 31, 1, 31, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 31, 7, 31, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 31, 7, 31, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 31, 9, 31, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 32, 1, 32, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 32, 1, 32, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 32, 7, 32, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 32, 7, 32, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 9, 32, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 33, 1, 33, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 33, 1, 33, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 33, 1, 33, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 33, 7, 33, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 33, 7, 33, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 33, 9, 33, 9 ], + "name" : "b" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_attr_set_eval_order.py.ast.typed.s.result b/pa3-tests/core/object_attr_set_eval_order.py.ast.typed.s.result new file mode 100644 index 0000000..3f82dac --- /dev/null +++ b/pa3-tests/core/object_attr_set_eval_order.py.ast.typed.s.result @@ -0,0 +1,10 @@ +B +Getting 1 +Getting B +Assigned B.a +Getting False +Getting B +Assigned B.b +1 +1 +False diff --git a/pa3-tests/core/object_attr_set_none.py b/pa3-tests/core/object_attr_set_none.py new file mode 100644 index 0000000..bfd3184 --- /dev/null +++ b/pa3-tests/core/object_attr_set_none.py @@ -0,0 +1,19 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + +a:A = None +b:B = None + +a = B() +print(a.a) + +b.a = 1 +b.b = False +print(b.a) +print(b.b) diff --git a/pa3-tests/core/object_attr_set_none.py.ast.typed b/pa3-tests/core/object_attr_set_none.py.ast.typed new file mode 100644 index 0000000..e6f5695 --- /dev/null +++ b/pa3-tests/core/object_attr_set_none.py.ast.typed @@ -0,0 +1,447 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 10, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 10, 1, 10, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 10, 1, 10, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 3, 10, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 7, 10, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 13, 5, 13, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 1, 16, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 3, 16, 3 ], + "name" : "a" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 7, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 11 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 17, 1, 17, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 17, 3, 17, 3 ], + "name" : "b" + } + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 7, 17, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 18, 7, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 18, 9, 18, 9 ], + "name" : "a" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 7, 19, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 9, 19, 9 ], + "name" : "b" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_attr_set_none.py.ast.typed.s.result b/pa3-tests/core/object_attr_set_none.py.ast.typed.s.result new file mode 100644 index 0000000..80d81d1 --- /dev/null +++ b/pa3-tests/core/object_attr_set_none.py.ast.typed.s.result @@ -0,0 +1,4 @@ +B +42 +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/object_init.py b/pa3-tests/core/object_init.py new file mode 100644 index 0000000..e48a5cd --- /dev/null +++ b/pa3-tests/core/object_init.py @@ -0,0 +1,11 @@ +class A(object): + a:int = 42 + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + +B() diff --git a/pa3-tests/core/object_init.py.ast.typed b/pa3-tests/core/object_init.py.ast.typed new file mode 100644 index 0000000..1ed066e --- /dev/null +++ b/pa3-tests/core/object_init.py.ast.typed @@ -0,0 +1,173 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 14, 5, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 23, 7, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 15, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "B" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_init.py.ast.typed.s.result b/pa3-tests/core/object_init.py.ast.typed.s.result new file mode 100644 index 0000000..223b783 --- /dev/null +++ b/pa3-tests/core/object_init.py.ast.typed.s.result @@ -0,0 +1 @@ +B diff --git a/pa3-tests/core/object_method.py b/pa3-tests/core/object_method.py new file mode 100644 index 0000000..6b71299 --- /dev/null +++ b/pa3-tests/core/object_method.py @@ -0,0 +1,16 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + return self.foo(self.b) + +print(B().bar()) diff --git a/pa3-tests/core/object_method.py.ast.typed b/pa3-tests/core/object_method.py.ast.typed new file mode 100644 index 0000000..955c83b --- /dev/null +++ b/pa3-tests/core/object_method.py.ast.typed @@ -0,0 +1,387 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 16, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 14, 32 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 14, 9, 14, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 14, 16, 14, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 14, 16, 14, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 21, 14, 23 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 25, 14, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 25, 14, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 30, 14, 30 ], + "name" : "b" + } + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 16, 7, 16, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 16, 7, 16, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 11, 16, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_method.py.ast.typed.s.result b/pa3-tests/core/object_method.py.ast.typed.s.result new file mode 100644 index 0000000..418c69b --- /dev/null +++ b/pa3-tests/core/object_method.py.ast.typed.s.result @@ -0,0 +1,2 @@ +B +42 diff --git a/pa3-tests/core/object_method_complex_call.py b/pa3-tests/core/object_method_complex_call.py new file mode 100644 index 0000000..d82ec1b --- /dev/null +++ b/pa3-tests/core/object_method_complex_call.py @@ -0,0 +1,19 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + return self.foo(self.foo(print("..."))) + + def foo(self:"B", ignore:object) -> int: + return 1 + +print(B().bar()) diff --git a/pa3-tests/core/object_method_complex_call.py.ast.typed b/pa3-tests/core/object_method_complex_call.py.ast.typed new file mode 100644 index 0000000..270f634 --- /dev/null +++ b/pa3-tests/core/object_method_complex_call.py.ast.typed @@ -0,0 +1,492 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 19, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 14, 48 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 14, 9, 14, 47 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 14, 16, 14, 47 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 14, 16, 14, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 21, 14, 23 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 14, 25, 14, 46 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 14, 25, 14, 32 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 25, 14, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 30, 14, 32 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 14, 34, 14, 45 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 34, 14, 38 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 14, 40, 14, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "..." + } ] + } ] + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 5, 17, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 13, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 13, 16, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 23, 16, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 23, 16, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 30, 16, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 41, 16, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 9, 17, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 16, 17, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 19, 7, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 19, 7, 19, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 19, 7, 19, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 11, 19, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_method_complex_call.py.ast.typed.s.result b/pa3-tests/core/object_method_complex_call.py.ast.typed.s.result new file mode 100644 index 0000000..f83c3f1 --- /dev/null +++ b/pa3-tests/core/object_method_complex_call.py.ast.typed.s.result @@ -0,0 +1,3 @@ +B +... +1 diff --git a/pa3-tests/core/object_method_nested.py b/pa3-tests/core/object_method_nested.py new file mode 100644 index 0000000..b193ecd --- /dev/null +++ b/pa3-tests/core/object_method_nested.py @@ -0,0 +1,18 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + def qux(p: bool) -> int: + return self.foo(p) + return qux(True) + +print(B().bar()) diff --git a/pa3-tests/core/object_method_nested.py.ast.typed b/pa3-tests/core/object_method_nested.py.ast.typed new file mode 100644 index 0000000..5480892 --- /dev/null +++ b/pa3-tests/core/object_method_nested.py.ast.typed @@ -0,0 +1,439 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 18, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 16, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 14, 9, 15, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 23 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 29, 14, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 15, 13, 15, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 15, 20, 15, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 15, 20, 15, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 20, 15, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 25, 15, 27 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 29, 15, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "p" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 24 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 16, 16, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "qux" + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 16, 20, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 18, 7, 18, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 18, 7, 18, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 18, 7, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 18, 11, 18, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_method_nested.py.ast.typed.s.result b/pa3-tests/core/object_method_nested.py.ast.typed.s.result new file mode 100644 index 0000000..418c69b --- /dev/null +++ b/pa3-tests/core/object_method_nested.py.ast.typed.s.result @@ -0,0 +1,2 @@ +B +42 diff --git a/pa3-tests/core/object_method_none.py b/pa3-tests/core/object_method_none.py new file mode 100644 index 0000000..cd50666 --- /dev/null +++ b/pa3-tests/core/object_method_none.py @@ -0,0 +1,17 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + a:A = None + return a.foo(self.b) + +print(B().bar()) diff --git a/pa3-tests/core/object_method_none.py.ast.typed b/pa3-tests/core/object_method_none.py.ast.typed new file mode 100644 index 0000000..db92330 --- /dev/null +++ b/pa3-tests/core/object_method_none.py.ast.typed @@ -0,0 +1,412 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 15, 29 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 14, 9, 14, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 14, 9, 14, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 11, 14, 11 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 14, 15, 14, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 15, 9, 15, 28 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 15, 16, 15, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 15, 16, 15, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 16, 15, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 22, 15, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 27, 15, 27 ], + "name" : "b" + } + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 17, 7, 17, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 17, 7, 17, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 17, 7, 17, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 7, 17, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 17, 11, 17, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_method_none.py.ast.typed.s.result b/pa3-tests/core/object_method_none.py.ast.typed.s.result new file mode 100644 index 0000000..d9d147e --- /dev/null +++ b/pa3-tests/core/object_method_none.py.ast.typed.s.result @@ -0,0 +1,3 @@ +B +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/object_method_override.py b/pa3-tests/core/object_method_override.py new file mode 100644 index 0000000..879b2ba --- /dev/null +++ b/pa3-tests/core/object_method_override.py @@ -0,0 +1,19 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + return self.foo(self.b) + + def foo(self:"B", ignore:object) -> int: + return 1 + +print(B().bar()) diff --git a/pa3-tests/core/object_method_override.py.ast.typed b/pa3-tests/core/object_method_override.py.ast.typed new file mode 100644 index 0000000..5684f7d --- /dev/null +++ b/pa3-tests/core/object_method_override.py.ast.typed @@ -0,0 +1,441 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 19, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 14, 32 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 14, 9, 14, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 14, 16, 14, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 14, 16, 14, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 21, 14, 23 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 14, 25, 14, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 25, 14, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 30, 14, 30 ], + "name" : "b" + } + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 5, 17, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 13, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 13, 16, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 23, 16, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 23, 16, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 30, 16, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 41, 16, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 9, 17, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 16, 17, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 19, 7, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 19, 7, 19, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 19, 7, 19, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 11, 19, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/object_method_override.py.ast.typed.s.result b/pa3-tests/core/object_method_override.py.ast.typed.s.result new file mode 100644 index 0000000..9a6e55a --- /dev/null +++ b/pa3-tests/core/object_method_override.py.ast.typed.s.result @@ -0,0 +1,2 @@ +B +1 diff --git a/pa3-tests/core/op_add.py b/pa3-tests/core/op_add.py new file mode 100644 index 0000000..95e89ae --- /dev/null +++ b/pa3-tests/core/op_add.py @@ -0,0 +1 @@ +print(1 + 100) diff --git a/pa3-tests/core/op_add.py.ast.typed b/pa3-tests/core/op_add.py.ast.typed new file mode 100644 index 0000000..a0a2d9b --- /dev/null +++ b/pa3-tests/core/op_add.py.ast.typed @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 15 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_add.py.ast.typed.s.result b/pa3-tests/core/op_add.py.ast.typed.s.result new file mode 100644 index 0000000..398050c --- /dev/null +++ b/pa3-tests/core/op_add.py.ast.typed.s.result @@ -0,0 +1 @@ +101 diff --git a/pa3-tests/core/op_cmp_bool.py b/pa3-tests/core/op_cmp_bool.py new file mode 100644 index 0000000..7f8d4b5 --- /dev/null +++ b/pa3-tests/core/op_cmp_bool.py @@ -0,0 +1,8 @@ +print(True == True) +print(True == False) +print(False == True) +print(False == False) +print(True != True) +print(True != False) +print(False != True) +print(False != False) diff --git a/pa3-tests/core/op_cmp_bool.py.ast.typed b/pa3-tests/core/op_cmp_bool.py.ast.typed new file mode 100644 index 0000000..4c25364 --- /dev/null +++ b/pa3-tests/core/op_cmp_bool.py.ast.typed @@ -0,0 +1,443 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 22 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 7, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 15, 1, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 7, 2, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 15, 2, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 1, 3, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 3, 7, 3, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 7, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 16, 3, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 4, 7, 4, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 7, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 16, 4, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 5, 7, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 7, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "!=", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 15, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 6, 7, 6, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "!=", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 15, 6, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 7, 7, 7, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 7, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 16, 7, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 8, 7, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 7, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 16, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_cmp_bool.py.ast.typed.s.result b/pa3-tests/core/op_cmp_bool.py.ast.typed.s.result new file mode 100644 index 0000000..12ea2d4 --- /dev/null +++ b/pa3-tests/core/op_cmp_bool.py.ast.typed.s.result @@ -0,0 +1,8 @@ +True +False +False +True +False +True +True +False diff --git a/pa3-tests/core/op_cmp_int.py b/pa3-tests/core/op_cmp_int.py new file mode 100644 index 0000000..fd70a09 --- /dev/null +++ b/pa3-tests/core/op_cmp_int.py @@ -0,0 +1,16 @@ +x:int = 42 +y:int = 7 + +print(x == y) +print(x != y) +print(x < y) +print(x <= y) +print(x > y) +print(x >= y) + +print(x == x) +print(x != x) +print(x < x) +print(x <= x) +print(x > x) +print(x >= x) diff --git a/pa3-tests/core/op_cmp_int.py.ast.typed b/pa3-tests/core/op_cmp_int.py.ast.typed new file mode 100644 index 0000000..4b3633f --- /dev/null +++ b/pa3-tests/core/op_cmp_int.py.ast.typed @@ -0,0 +1,711 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 14 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 4, 7, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 5, 7, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "!=", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 6, 7, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 7, 7, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 8, 7, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 11, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 9, 7, 9, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 11, 7, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 12, 7, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "!=", + "right" : { + "kind" : "Identifier", + "location" : [ 12, 12, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 13, 7, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 13, 7, 13, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 13, 11, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 14, 7, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 15, 7, 15, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 15, 11, 15, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 16, 7, 16, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 12, 16, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_cmp_int.py.ast.typed.s.result b/pa3-tests/core/op_cmp_int.py.ast.typed.s.result new file mode 100644 index 0000000..4386d2a --- /dev/null +++ b/pa3-tests/core/op_cmp_int.py.ast.typed.s.result @@ -0,0 +1,12 @@ +False +True +False +False +True +True +True +False +False +True +False +True diff --git a/pa3-tests/core/op_div_mod.py b/pa3-tests/core/op_div_mod.py new file mode 100644 index 0000000..9e41a78 --- /dev/null +++ b/pa3-tests/core/op_div_mod.py @@ -0,0 +1,5 @@ +x:int = 42 +y:int = 9 + +print(x // y) +print(x % y) diff --git a/pa3-tests/core/op_div_mod.py.ast.typed b/pa3-tests/core/op_div_mod.py.ast.typed new file mode 100644 index 0000000..eded4a3 --- /dev/null +++ b/pa3-tests/core/op_div_mod.py.ast.typed @@ -0,0 +1,171 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 4, 7, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "//", + "right" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 5, 7, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 11, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_div_mod.py.ast.typed.s.result b/pa3-tests/core/op_div_mod.py.ast.typed.s.result new file mode 100644 index 0000000..cfbeb15 --- /dev/null +++ b/pa3-tests/core/op_div_mod.py.ast.typed.s.result @@ -0,0 +1,2 @@ +4 +6 diff --git a/pa3-tests/core/op_is.py b/pa3-tests/core/op_is.py new file mode 100644 index 0000000..4207f29 --- /dev/null +++ b/pa3-tests/core/op_is.py @@ -0,0 +1,19 @@ +class A(object): + a:int = 42 + +a1:A = None +a2:A = None +a3:A = None +a4:A = None + +a1 = A() +a2 = a1 +a3 = A() + +print(a1 is a1) +print(a1 is a2) +print(a1 is a3) +print(a1 is a4) +print(a1 is None) +print(a4 is None) +print(None is None) diff --git a/pa3-tests/core/op_is.py.ast.typed b/pa3-tests/core/op_is.py.ast.typed new file mode 100644 index 0000000..962be5e --- /dev/null +++ b/pa3-tests/core/op_is.py.ast.typed @@ -0,0 +1,598 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 20 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 2 ], + "name" : "a1" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 4 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 8, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 2 ], + "name" : "a2" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 4, 5, 4 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 5, 8, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 2 ], + "name" : "a3" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 4, 6, 4 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 8, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 7, 1, 7, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 1, 7, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 2 ], + "name" : "a4" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 4, 7, 4 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 7, 8, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 6, 9, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 6, 9, 6 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a2" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 6, 10, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a3" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 11, 6, 11, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 6, 11, 6 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 13, 7, 13, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 13, 7, 13, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + }, + "operator" : "is", + "right" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 14, 7, 14, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + }, + "operator" : "is", + "right" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a2" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 15, 7, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + }, + "operator" : "is", + "right" : { + "kind" : "Identifier", + "location" : [ 15, 13, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a3" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 16, 7, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + }, + "operator" : "is", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 13, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a4" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 17 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 17, 7, 17, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 17, 7, 17, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a1" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 17, 13, 17, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 17 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 18, 7, 18, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a4" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 18, 13, 18, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 19, 7, 19, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 19, 15, 19, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_is.py.ast.typed.s.result b/pa3-tests/core/op_is.py.ast.typed.s.result new file mode 100644 index 0000000..0ac4f5b --- /dev/null +++ b/pa3-tests/core/op_is.py.ast.typed.s.result @@ -0,0 +1,7 @@ +True +True +False +False +False +True +True diff --git a/pa3-tests/core/op_logical.py b/pa3-tests/core/op_logical.py new file mode 100644 index 0000000..7b55262 --- /dev/null +++ b/pa3-tests/core/op_logical.py @@ -0,0 +1,13 @@ +def f() -> bool: + print("f called") + return True + +def g() -> bool: + print("g called") + return False + +if f() or g(): # Short-circuit + if g() and f(): # Short-circuit + print("Never") + else: + print(not (f() and (g() or f()))) diff --git a/pa3-tests/core/op_logical.py.ast.typed b/pa3-tests/core/op_logical.py.ast.typed new file mode 100644 index 0000000..4aa1544 --- /dev/null +++ b/pa3-tests/core/op_logical.py.ast.typed @@ -0,0 +1,411 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 2 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "f" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 12, 1, 15 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 3, 2, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 3, 2, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "f called" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 3, 3, 3, 13 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 10, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 7, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "g" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 12, 5, 15 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 3, 6, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 3, 6, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 3, 6, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 6, 9, 6, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "g called" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 7, 3, 7, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 10, 7, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 9, 1, 14, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 9, 4, 9, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 9, 4, 9, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 4, 9, 4 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "f" + }, + "args" : [ ] + }, + "operator" : "or", + "right" : { + "kind" : "CallExpr", + "location" : [ 9, 11, 9, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 11, 9, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "g" + }, + "args" : [ ] + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 10, 3, 14, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 10, 6, 10, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 10, 6, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 6, 10, 6 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "g" + }, + "args" : [ ] + }, + "operator" : "and", + "right" : { + "kind" : "CallExpr", + "location" : [ 10, 14, 10, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 14, 10, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "f" + }, + "args" : [ ] + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 5, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 5, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 11, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Never" + } ] + } + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 13, 5, 13, 37 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 5, 13, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "UnaryExpr", + "location" : [ 13, 11, 13, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "BinaryExpr", + "location" : [ 13, 16, 13, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 13, 16, 13, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 16, 13, 16 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "f" + }, + "args" : [ ] + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 13, 25, 13, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 13, 25, 13, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 25, 13, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "g" + }, + "args" : [ ] + }, + "operator" : "or", + "right" : { + "kind" : "CallExpr", + "location" : [ 13, 32, 13, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 32, 13, 32 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "f" + }, + "args" : [ ] + } + } + } + } ] + } + } ] + } ], + "elseBody" : [ ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_logical.py.ast.typed.s.result b/pa3-tests/core/op_logical.py.ast.typed.s.result new file mode 100644 index 0000000..82c1ab2 --- /dev/null +++ b/pa3-tests/core/op_logical.py.ast.typed.s.result @@ -0,0 +1,6 @@ +f called +g called +f called +g called +f called +False diff --git a/pa3-tests/core/op_mul.py b/pa3-tests/core/op_mul.py new file mode 100644 index 0000000..cf6201d --- /dev/null +++ b/pa3-tests/core/op_mul.py @@ -0,0 +1 @@ +print(6*9*2) diff --git a/pa3-tests/core/op_mul.py.ast.typed b/pa3-tests/core/op_mul.py.ast.typed new file mode 100644 index 0000000..6ed26cc --- /dev/null +++ b/pa3-tests/core/op_mul.py.ast.typed @@ -0,0 +1,83 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_mul.py.ast.typed.s.result b/pa3-tests/core/op_mul.py.ast.typed.s.result new file mode 100644 index 0000000..3b20426 --- /dev/null +++ b/pa3-tests/core/op_mul.py.ast.typed.s.result @@ -0,0 +1 @@ +108 diff --git a/pa3-tests/core/op_negate.py b/pa3-tests/core/op_negate.py new file mode 100644 index 0000000..0f3b2be --- /dev/null +++ b/pa3-tests/core/op_negate.py @@ -0,0 +1,2 @@ +x:int = 42 +print(-x) diff --git a/pa3-tests/core/op_negate.py.ast.typed b/pa3-tests/core/op_negate.py.ast.typed new file mode 100644 index 0000000..4268b3b --- /dev/null +++ b/pa3-tests/core/op_negate.py.ast.typed @@ -0,0 +1,82 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "UnaryExpr", + "location" : [ 2, 7, 2, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 2, 8, 2, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_negate.py.ast.typed.s.result b/pa3-tests/core/op_negate.py.ast.typed.s.result new file mode 100644 index 0000000..6a0e60d --- /dev/null +++ b/pa3-tests/core/op_negate.py.ast.typed.s.result @@ -0,0 +1 @@ +-42 diff --git a/pa3-tests/core/op_sub.py b/pa3-tests/core/op_sub.py new file mode 100644 index 0000000..48aa45b --- /dev/null +++ b/pa3-tests/core/op_sub.py @@ -0,0 +1 @@ +print(1 - 100) diff --git a/pa3-tests/core/op_sub.py.ast.typed b/pa3-tests/core/op_sub.py.ast.typed new file mode 100644 index 0000000..2c927e8 --- /dev/null +++ b/pa3-tests/core/op_sub.py.ast.typed @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 15 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/op_sub.py.ast.typed.s.result b/pa3-tests/core/op_sub.py.ast.typed.s.result new file mode 100644 index 0000000..d3a0ef5 --- /dev/null +++ b/pa3-tests/core/op_sub.py.ast.typed.s.result @@ -0,0 +1 @@ +-99 diff --git a/pa3-tests/core/pass.py b/pa3-tests/core/pass.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/pa3-tests/core/pass.py @@ -0,0 +1 @@ +pass diff --git a/pa3-tests/core/pass.py.ast.typed b/pa3-tests/core/pass.py.ast.typed new file mode 100644 index 0000000..ceb0bbd --- /dev/null +++ b/pa3-tests/core/pass.py.ast.typed @@ -0,0 +1,11 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 5 ], + "declarations" : [ ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/pass.py.ast.typed.s.result b/pa3-tests/core/pass.py.ast.typed.s.result new file mode 100644 index 0000000..e69de29 diff --git a/pa3-tests/core/predef_constructors.py b/pa3-tests/core/predef_constructors.py new file mode 100644 index 0000000..0086564 --- /dev/null +++ b/pa3-tests/core/predef_constructors.py @@ -0,0 +1,4 @@ +print(object() is None) +print(int()) +print(str()) +print(bool()) diff --git a/pa3-tests/core/predef_constructors.py.ast.typed b/pa3-tests/core/predef_constructors.py.ast.typed new file mode 100644 index 0000000..3644f24 --- /dev/null +++ b/pa3-tests/core/predef_constructors.py.ast.typed @@ -0,0 +1,192 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 14 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 1, 7, 1, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 1, 7, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 12 ], + "name" : "object" + }, + "args" : [ ] + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 1, 19, 1, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 1, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 2, 7, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 9 ], + "name" : "int" + }, + "args" : [ ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 1, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 3, 7, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 7, 3, 9 ], + "name" : "str" + }, + "args" : [ ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 4, 7, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 10 ], + "name" : "bool" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/predef_constructors.py.ast.typed.s.result b/pa3-tests/core/predef_constructors.py.ast.typed.s.result new file mode 100644 index 0000000..8add9b0 --- /dev/null +++ b/pa3-tests/core/predef_constructors.py.ast.typed.s.result @@ -0,0 +1,4 @@ +False +0 + +False diff --git a/pa3-tests/core/stmt_for_list.py b/pa3-tests/core/stmt_for_list.py new file mode 100644 index 0000000..78c5c00 --- /dev/null +++ b/pa3-tests/core/stmt_for_list.py @@ -0,0 +1,7 @@ +x:int = 0 +z:[int] = None + +z = [1, 2, 3] + +for x in z: + print(x) diff --git a/pa3-tests/core/stmt_for_list.py.ast.typed b/pa3-tests/core/stmt_for_list.py.ast.typed new file mode 100644 index 0000000..53d6834 --- /dev/null +++ b/pa3-tests/core/stmt_for_list.py.ast.typed @@ -0,0 +1,178 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 6, 1, 8, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 6, 10, 6, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list.py.ast.typed.s.result new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/pa3-tests/core/stmt_for_list.py.ast.typed.s.result @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/pa3-tests/core/stmt_for_list_empty.py b/pa3-tests/core/stmt_for_list_empty.py new file mode 100644 index 0000000..23fba4a --- /dev/null +++ b/pa3-tests/core/stmt_for_list_empty.py @@ -0,0 +1,12 @@ +x:int = 0 +y:int = 0 +z:[int] = None +e:[int] = None + +z = [1,2,3] +e = [] + +for x in z: + for y in e: + print("Never") + print(x) diff --git a/pa3-tests/core/stmt_for_list_empty.py.ast.typed b/pa3-tests/core/stmt_for_list_empty.py.ast.typed new file mode 100644 index 0000000..ca4160c --- /dev/null +++ b/pa3-tests/core/stmt_for_list_empty.py.ast.typed @@ -0,0 +1,318 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 11, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "e" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 10, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "e" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "ForStmt", + "location" : [ 9, 1, 13, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 9, 10, 9, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ForStmt", + "location" : [ 10, 5, 12, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 10, 14, 10, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "e" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Never" + } ] + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 12, 5, 12, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 5, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 11, 12, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_empty.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_empty.py.ast.typed.s.result new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_empty.py.ast.typed.s.result @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/pa3-tests/core/stmt_for_list_eval.py b/pa3-tests/core/stmt_for_list_eval.py new file mode 100644 index 0000000..a77b171 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_eval.py @@ -0,0 +1,8 @@ +x:int = 0 +z:[int] = None + +z = [1, 2, 3] + +for x in z: + z = [] + print(x) diff --git a/pa3-tests/core/stmt_for_list_eval.py.ast.typed b/pa3-tests/core/stmt_for_list_eval.py.ast.typed new file mode 100644 index 0000000..c86d718 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_eval.py.ast.typed @@ -0,0 +1,202 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 6, 1, 9, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 6, 10, 6, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 5, 7, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 9, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 5, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 11, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_eval.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_eval.py.ast.typed.s.result new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_eval.py.ast.typed.s.result @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/pa3-tests/core/stmt_for_list_modify.py b/pa3-tests/core/stmt_for_list_modify.py new file mode 100644 index 0000000..3006cd2 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_modify.py @@ -0,0 +1,8 @@ +x:int = 0 +z:[int] = None + +z = [1, 2, 1] + +for x in z: + z[x] = x + print(x) diff --git a/pa3-tests/core/stmt_for_list_modify.py.ast.typed b/pa3-tests/core/stmt_for_list_modify.py.ast.typed new file mode 100644 index 0000000..fa19b60 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_modify.py.ast.typed @@ -0,0 +1,219 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 6, 1, 9, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 6, 10, 6, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 5, 7, 12 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 5, 7, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 5, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 11, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_modify.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_modify.py.ast.typed.s.result new file mode 100644 index 0000000..e8183f0 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_modify.py.ast.typed.s.result @@ -0,0 +1,3 @@ +1 +1 +1 diff --git a/pa3-tests/core/stmt_for_list_nested.py b/pa3-tests/core/stmt_for_list_nested.py new file mode 100644 index 0000000..b69f3f0 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested.py @@ -0,0 +1,9 @@ +x:int = 0 +y:int = 0 +z:[int] = None + +z = [1, 2, 3] + +for x in z: + for y in z: + print(x * y) diff --git a/pa3-tests/core/stmt_for_list_nested.py.ast.typed b/pa3-tests/core/stmt_for_list_nested.py.ast.typed new file mode 100644 index 0000000..0521e4a --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested.py.ast.typed @@ -0,0 +1,247 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 2 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 11, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 5, 6, 5, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 7, 1, 10, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 7, 10, 7, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ForStmt", + "location" : [ 8, 5, 10, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 8, 14, 8, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 9, 9, 9, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 9, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 9, 15, 9, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 19, 9, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_nested.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_nested.py.ast.typed.s.result new file mode 100644 index 0000000..0d1fb9e --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested.py.ast.typed.s.result @@ -0,0 +1,9 @@ +1 +2 +3 +2 +4 +6 +3 +6 +9 diff --git a/pa3-tests/core/stmt_for_list_nested_same_var.py b/pa3-tests/core/stmt_for_list_nested_same_var.py new file mode 100644 index 0000000..0057164 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested_same_var.py @@ -0,0 +1,9 @@ +x:int = 0 +y:int = 0 +z:[int] = None + +z = [1, 2, 3] + +for x in z: + for x in z: + print(x) diff --git a/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed b/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed new file mode 100644 index 0000000..2feac51 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed @@ -0,0 +1,229 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 2 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 11, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 5, 6, 5, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 7, 1, 10, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 7, 10, 7, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ForStmt", + "location" : [ 8, 5, 10, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 8, 14, 8, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 9, 9, 9, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 9, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed.s.result new file mode 100644 index 0000000..a8401b1 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nested_same_var.py.ast.typed.s.result @@ -0,0 +1,9 @@ +1 +2 +3 +1 +2 +3 +1 +2 +3 diff --git a/pa3-tests/core/stmt_for_list_none.py b/pa3-tests/core/stmt_for_list_none.py new file mode 100644 index 0000000..fd511fa --- /dev/null +++ b/pa3-tests/core/stmt_for_list_none.py @@ -0,0 +1,5 @@ +x:int = 0 +z:[int] = None + +for x in z: + print(x) diff --git a/pa3-tests/core/stmt_for_list_none.py.ast.typed b/pa3-tests/core/stmt_for_list_none.py.ast.typed new file mode 100644 index 0000000..00acc08 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_none.py.ast.typed @@ -0,0 +1,127 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 4, 1, 6, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 5, 5, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 5, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 5, 11, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_none.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_none.py.ast.typed.s.result new file mode 100644 index 0000000..ae52477 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_none.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Operation on None +Exited with error code 4 diff --git a/pa3-tests/core/stmt_for_list_nonlocal.py b/pa3-tests/core/stmt_for_list_nonlocal.py new file mode 100644 index 0000000..e9b54a2 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nonlocal.py @@ -0,0 +1,15 @@ +x:int = 0 +def crunch(zz:[[int]]) -> object: + z:[int] = None + global x + def make_z() -> object: + nonlocal z + for z in zz: + pass # Set z to last element in zz + + make_z() + for x in z: + pass # Set x to last element in z + +crunch([[1,2],[2,3],[4,5],[6,7]]) +print(x) diff --git a/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed b/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed new file mode 100644 index 0000000..2c686f8 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed @@ -0,0 +1,408 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 15, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 2, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 10 ], + "name" : "crunch" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 12, 2, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 13 ], + "name" : "zz" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 15, 2, 21 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 2, 16, 2, 20 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 17, 2, 19 ], + "className" : "int" + } + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 32 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 7, 3, 11 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 15, 3, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "GlobalDecl", + "location" : [ 4, 5, 4, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "name" : "x" + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 10, 4 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 14 ], + "name" : "make_z" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 21, 5, 26 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 6, 9, 6, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 18 ], + "name" : "z" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 7, 9, 10, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "zz" + }, + "body" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 5, 10, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 5, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "make_z" + }, + "args" : [ ] + } + }, { + "kind" : "ForStmt", + "location" : [ 11, 5, 14, 0 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 11, 14, 11, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 33 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 6 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "crunch" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 14, 8, 14, 32 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 14, 9, 14, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 14, 10, 14, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 14, 12, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + }, { + "kind" : "ListExpr", + "location" : [ 14, 15, 14, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 14, 16, 14, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 14, 18, 14, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, { + "kind" : "ListExpr", + "location" : [ 14, 21, 14, 25 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 14, 22, 14, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 14, 24, 14, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } ] + }, { + "kind" : "ListExpr", + "location" : [ 14, 27, 14, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 14, 28, 14, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + }, { + "kind" : "IntegerLiteral", + "location" : [ 14, 30, 14, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + } ] + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed.s.result new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/pa3-tests/core/stmt_for_list_nonlocal.py.ast.typed.s.result @@ -0,0 +1 @@ +7 diff --git a/pa3-tests/core/stmt_for_list_return.py b/pa3-tests/core/stmt_for_list_return.py new file mode 100644 index 0000000..35716dd --- /dev/null +++ b/pa3-tests/core/stmt_for_list_return.py @@ -0,0 +1,8 @@ +def print_list(z:[int]) -> object: + x:int = 0 + for x in z: + print(x) + if x >= 30: + return + +print_list([10,20,30,40]) diff --git a/pa3-tests/core/stmt_for_list_return.py.ast.typed b/pa3-tests/core/stmt_for_list_return.py.ast.typed new file mode 100644 index 0000000..4fca85f --- /dev/null +++ b/pa3-tests/core/stmt_for_list_return.py.ast.typed @@ -0,0 +1,241 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 26 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 14 ], + "name" : "print_list" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 18, 1, 22 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 19, 1, 21 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 28, 1, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 5, 8, 0 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 9, 4, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 9, 4, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "IfStmt", + "location" : [ 5, 9, 8, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 5, 12, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 17, 5, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 30 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 13, 6, 18 ], + "value" : null + } ], + "elseBody" : [ ] + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 25 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "print_list" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 8, 12, 8, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + }, { + "kind" : "IntegerLiteral", + "location" : [ 8, 16, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 20 + }, { + "kind" : "IntegerLiteral", + "location" : [ 8, 19, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 30 + }, { + "kind" : "IntegerLiteral", + "location" : [ 8, 22, 8, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 40 + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_list_return.py.ast.typed.s.result b/pa3-tests/core/stmt_for_list_return.py.ast.typed.s.result new file mode 100644 index 0000000..300ed6f --- /dev/null +++ b/pa3-tests/core/stmt_for_list_return.py.ast.typed.s.result @@ -0,0 +1,3 @@ +10 +20 +30 diff --git a/pa3-tests/core/stmt_for_str.py b/pa3-tests/core/stmt_for_str.py new file mode 100644 index 0000000..c3ab74f --- /dev/null +++ b/pa3-tests/core/stmt_for_str.py @@ -0,0 +1,5 @@ +x:str = "" +z:str = "abc" + +for x in z: + print(x) diff --git a/pa3-tests/core/stmt_for_str.py.ast.typed b/pa3-tests/core/stmt_for_str.py.ast.typed new file mode 100644 index 0000000..4b0e583 --- /dev/null +++ b/pa3-tests/core/stmt_for_str.py.ast.typed @@ -0,0 +1,121 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 4, 1, 6, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 5, 5, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 5, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 5, 11, 5, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_str.py.ast.typed.s.result b/pa3-tests/core/stmt_for_str.py.ast.typed.s.result new file mode 100644 index 0000000..de98044 --- /dev/null +++ b/pa3-tests/core/stmt_for_str.py.ast.typed.s.result @@ -0,0 +1,3 @@ +a +b +c diff --git a/pa3-tests/core/stmt_for_str_empty.py b/pa3-tests/core/stmt_for_str_empty.py new file mode 100644 index 0000000..9dc60e7 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_empty.py @@ -0,0 +1,8 @@ +x:str = "" +y:str = "123" +z:str = "abc" + +for x in z: + print(x) + for x in "": + print(x) diff --git a/pa3-tests/core/stmt_for_str_empty.py.ast.typed b/pa3-tests/core/stmt_for_str_empty.py.ast.typed new file mode 100644 index 0000000..9be591f --- /dev/null +++ b/pa3-tests/core/stmt_for_str_empty.py.ast.typed @@ -0,0 +1,205 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 2 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "123" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 5, 1, 9, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 5, 10, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 7, 5, 9, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "StringLiteral", + "location" : [ 7, 14, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_str_empty.py.ast.typed.s.result b/pa3-tests/core/stmt_for_str_empty.py.ast.typed.s.result new file mode 100644 index 0000000..de98044 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_empty.py.ast.typed.s.result @@ -0,0 +1,3 @@ +a +b +c diff --git a/pa3-tests/core/stmt_for_str_eval.py b/pa3-tests/core/stmt_for_str_eval.py new file mode 100644 index 0000000..69c2ea9 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_eval.py @@ -0,0 +1,6 @@ +x:str = "" +z:str = "abc" + +for x in z: + z = "doesn't matter" + print(x) diff --git a/pa3-tests/core/stmt_for_str_eval.py.ast.typed b/pa3-tests/core/stmt_for_str_eval.py.ast.typed new file mode 100644 index 0000000..1e64270 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_eval.py.ast.typed @@ -0,0 +1,142 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 4, 1, 7, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 4, 10, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 5, 5, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "doesn't matter" + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_str_eval.py.ast.typed.s.result b/pa3-tests/core/stmt_for_str_eval.py.ast.typed.s.result new file mode 100644 index 0000000..de98044 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_eval.py.ast.typed.s.result @@ -0,0 +1,3 @@ +a +b +c diff --git a/pa3-tests/core/stmt_for_str_nested.py b/pa3-tests/core/stmt_for_str_nested.py new file mode 100644 index 0000000..81f0f46 --- /dev/null +++ b/pa3-tests/core/stmt_for_str_nested.py @@ -0,0 +1,8 @@ +x:str = "" +y:str = "123" +z:str = "abc" + +for x in z: + print(x) + for x in y: + print(x) diff --git a/pa3-tests/core/stmt_for_str_nested.py.ast.typed b/pa3-tests/core/stmt_for_str_nested.py.ast.typed new file mode 100644 index 0000000..5260c3b --- /dev/null +++ b/pa3-tests/core/stmt_for_str_nested.py.ast.typed @@ -0,0 +1,205 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 2 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "123" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 5, 1, 9, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 5, 10, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 7, 5, 9, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 9, 8, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 9, 8, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_str_nested.py.ast.typed.s.result b/pa3-tests/core/stmt_for_str_nested.py.ast.typed.s.result new file mode 100644 index 0000000..c2cb64d --- /dev/null +++ b/pa3-tests/core/stmt_for_str_nested.py.ast.typed.s.result @@ -0,0 +1,12 @@ +a +1 +2 +3 +b +1 +2 +3 +c +1 +2 +3 diff --git a/pa3-tests/core/stmt_for_str_same_var.py b/pa3-tests/core/stmt_for_str_same_var.py new file mode 100644 index 0000000..438c74e --- /dev/null +++ b/pa3-tests/core/stmt_for_str_same_var.py @@ -0,0 +1,4 @@ +x:str = "xXx" + +for x in x: + print(x) diff --git a/pa3-tests/core/stmt_for_str_same_var.py.ast.typed b/pa3-tests/core/stmt_for_str_same_var.py.ast.typed new file mode 100644 index 0000000..e3870ec --- /dev/null +++ b/pa3-tests/core/stmt_for_str_same_var.py.ast.typed @@ -0,0 +1,95 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "xXx" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 11, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_for_str_same_var.py.ast.typed.s.result b/pa3-tests/core/stmt_for_str_same_var.py.ast.typed.s.result new file mode 100644 index 0000000..723425f --- /dev/null +++ b/pa3-tests/core/stmt_for_str_same_var.py.ast.typed.s.result @@ -0,0 +1,3 @@ +x +X +x diff --git a/pa3-tests/core/stmt_if.py b/pa3-tests/core/stmt_if.py new file mode 100644 index 0000000..61bc605 --- /dev/null +++ b/pa3-tests/core/stmt_if.py @@ -0,0 +1,7 @@ +if False: + print("No") +elif True: + if True: + print("Yes") +else: + pass diff --git a/pa3-tests/core/stmt_if.py.ast.typed b/pa3-tests/core/stmt_if.py.ast.typed new file mode 100644 index 0000000..0b67124 --- /dev/null +++ b/pa3-tests/core/stmt_if.py.ast.typed @@ -0,0 +1,125 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "No" + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 6, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 4, 5, 6, 0 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 8, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 9, 5, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 9, 5, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 5, 15, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Yes" + } ] + } + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_if.py.ast.typed.s.result b/pa3-tests/core/stmt_if.py.ast.typed.s.result new file mode 100644 index 0000000..dcd7a5d --- /dev/null +++ b/pa3-tests/core/stmt_if.py.ast.typed.s.result @@ -0,0 +1 @@ +Yes diff --git a/pa3-tests/core/stmt_return_early.py b/pa3-tests/core/stmt_return_early.py new file mode 100644 index 0000000..267eab7 --- /dev/null +++ b/pa3-tests/core/stmt_return_early.py @@ -0,0 +1,6 @@ +def f() -> int: + while True: + return 1 + return 0 + +print(f()) diff --git a/pa3-tests/core/stmt_return_early.py.ast.typed b/pa3-tests/core/stmt_return_early.py.ast.typed new file mode 100644 index 0000000..4568349 --- /dev/null +++ b/pa3-tests/core/stmt_return_early.py.ast.typed @@ -0,0 +1,113 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 11 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 4, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "f" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 12, 1, 14 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 5, 4, 4 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 11, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "body" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 6, 7, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_return_early.py.ast.typed.s.result b/pa3-tests/core/stmt_return_early.py.ast.typed.s.result new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/pa3-tests/core/stmt_return_early.py.ast.typed.s.result @@ -0,0 +1 @@ +1 diff --git a/pa3-tests/core/stmt_while.py b/pa3-tests/core/stmt_while.py new file mode 100644 index 0000000..acb4d7a --- /dev/null +++ b/pa3-tests/core/stmt_while.py @@ -0,0 +1,4 @@ +x:int = 1 +while x < 10: + print(x) + x = x + 1 diff --git a/pa3-tests/core/stmt_while.py.ast.typed b/pa3-tests/core/stmt_while.py.ast.typed new file mode 100644 index 0000000..3802a75 --- /dev/null +++ b/pa3-tests/core/stmt_while.py.ast.typed @@ -0,0 +1,143 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 1, 5, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 5, 3, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 5, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 5, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 4, 9, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/stmt_while.py.ast.typed.s.result b/pa3-tests/core/stmt_while.py.ast.typed.s.result new file mode 100644 index 0000000..0719398 --- /dev/null +++ b/pa3-tests/core/stmt_while.py.ast.typed.s.result @@ -0,0 +1,9 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/pa3-tests/core/str_cat.py b/pa3-tests/core/str_cat.py new file mode 100644 index 0000000..f28db5e --- /dev/null +++ b/pa3-tests/core/str_cat.py @@ -0,0 +1,17 @@ +a:str = "Hello" +b:str = "World" +c:str = "ChocoPy" + +def cat2(a:str, b:str) -> str: + return a + b + +def cat3(a:str, b:str, c:str) -> str: + return a + b + c + +print(cat2(a, b)) +print(cat2("", c)) +print(cat3(a, " ", c)) +print(len(a)) +print(len(cat2(a,a))) +print(len(cat2("",""))) + diff --git a/pa3-tests/core/str_cat.py.ast.typed b/pa3-tests/core/str_cat.py.ast.typed new file mode 100644 index 0000000..1db5a86 --- /dev/null +++ b/pa3-tests/core/str_cat.py.ast.typed @@ -0,0 +1,738 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "ChocoPy" + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 6, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 8 ], + "name" : "cat2" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 10, 5, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 10, 5, 10 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 12, 5, 14 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 17, 5, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 17, 5, 17 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 21 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 27, 5, 29 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 5, 6, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 12, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 6, 16, 6, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 1, 9, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 8 ], + "name" : "cat3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 10, 8, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 10, 8, 10 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 12, 8, 14 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 17, 8, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 17, 8, 17 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 19, 8, 21 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 24, 8, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 24, 8, 24 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 26, 8, 28 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 34, 8, 36 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 20 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 12, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 9, 12, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 20, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 17 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 11, 7, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 12, 7, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 12, 12, 12, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + }, { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 13, 7, 13, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat3" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 12, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "StringLiteral", + "location" : [ 13, 15, 13, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : " " + }, { + "kind" : "Identifier", + "location" : [ 13, 20, 13, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 14, 7, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 15, 7, 15, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 15, 11, 15, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 11, 15, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 16, 15, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 16, 7, 16, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 16, 11, 16, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 11, 16, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 16, 16, 16, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + }, { + "kind" : "StringLiteral", + "location" : [ 16, 19, 16, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_cat.py.ast.typed.s.result b/pa3-tests/core/str_cat.py.ast.typed.s.result new file mode 100644 index 0000000..b2e262a --- /dev/null +++ b/pa3-tests/core/str_cat.py.ast.typed.s.result @@ -0,0 +1,6 @@ +HelloWorld +ChocoPy +Hello ChocoPy +5 +10 +0 diff --git a/pa3-tests/core/str_cat_2.py b/pa3-tests/core/str_cat_2.py new file mode 100644 index 0000000..f8367c0 --- /dev/null +++ b/pa3-tests/core/str_cat_2.py @@ -0,0 +1,19 @@ +a:str = "no" +b:str = "o" +c:str = "" +d:str = "" +e:str = "" + +def cat2(a:str, b:str) -> str: + return a + b + +def cat3(a:str, b:str, c:str) -> str: + return a + b + c + +c = cat2(b, a) +d = cat2(a, a) +e = cat3(a, b, cat2(b, b)) + +print(c) +print(d) +print(e) diff --git a/pa3-tests/core/str_cat_2.py.ast.typed b/pa3-tests/core/str_cat_2.py.ast.typed new file mode 100644 index 0000000..543fa96 --- /dev/null +++ b/pa3-tests/core/str_cat_2.py.ast.typed @@ -0,0 +1,638 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 19, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 12 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "no" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "o" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "d" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 4, 9, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "e" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 8 ], + "name" : "cat2" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 10, 7, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 10, 7, 10 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 12, 7, 14 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 17, 7, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 17, 7, 17 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 19, 7, 21 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 27, 7, 29 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 12, 8, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 1, 11, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 8 ], + "name" : "cat3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 10, 10, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 10, 10, 10 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 12, 10, 14 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 10, 17, 10, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 17, 10, 17 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 19, 10, 21 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 10, 24, 10, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 24, 10, 24 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 26, 10, 28 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 34, 10, 36 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 20 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 11, 12, 11, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 11, 12, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 16, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 20, 11, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 13, 5, 13, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 10, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 14, 1, 14, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "d" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 14, 5, 14, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 10, 14, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "e" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat3" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 10, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 15, 13, 15, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + }, { + "kind" : "CallExpr", + "location" : [ 15, 16, 15, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 16, 15, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "cat2" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 21, 15, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 15, 24, 15, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 17, 7, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "d" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 19, 1, 19, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 19, 1, 19, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "e" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_cat_2.py.ast.typed.s.result b/pa3-tests/core/str_cat_2.py.ast.typed.s.result new file mode 100644 index 0000000..2f6ff88 --- /dev/null +++ b/pa3-tests/core/str_cat_2.py.ast.typed.s.result @@ -0,0 +1,3 @@ +ono +nono +noooo diff --git a/pa3-tests/core/str_cmp.py b/pa3-tests/core/str_cmp.py new file mode 100644 index 0000000..9258cd9 --- /dev/null +++ b/pa3-tests/core/str_cmp.py @@ -0,0 +1,17 @@ +a:str = "Hello" +b:str = "World" +c:str = "ChocoPy" + +def eq(a:str, b:str) -> bool: + return a == b + +def neq(a:str, b:str) -> bool: + return a != b + +print(eq(a,a)) +print(eq(a,b)) +print(neq(a,b)) +print(neq(b,b)) +print(eq(c,a)) +print(neq(c,b)) + diff --git a/pa3-tests/core/str_cmp.py.ast.typed b/pa3-tests/core/str_cmp.py.ast.typed new file mode 100644 index 0000000..b185ac1 --- /dev/null +++ b/pa3-tests/core/str_cmp.py.ast.typed @@ -0,0 +1,659 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 16, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "ChocoPy" + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 6, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 6 ], + "name" : "eq" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 8, 5, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 8, 5, 8 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 10, 5, 12 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 15, 5, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 15, 5, 15 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 17, 5, 19 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 25, 5, 28 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 5, 6, 17 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 12, 6, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 6, 17, 6, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 7 ], + "name" : "neq" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 9, 8, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 11, 8, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 16, 8, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 20 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 26, 8, 29 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 17 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 12, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, + "operator" : "!=", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 17, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 11, 7, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "eq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 11, 10, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 12, 7, 12, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "eq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 10, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 12, 12, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 13, 7, 13, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 7, 13, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "neq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 11, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 14, 7, 14, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "neq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 15, 7, 15, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 8 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "eq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 10, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + }, { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 16, 1, 16, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 16, 1, 16, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 16, 7, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 7, 16, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "neq" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 16, 11, 16, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + }, { + "kind" : "Identifier", + "location" : [ 16, 13, 16, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_cmp.py.ast.typed.s.result b/pa3-tests/core/str_cmp.py.ast.typed.s.result new file mode 100644 index 0000000..72232fd --- /dev/null +++ b/pa3-tests/core/str_cmp.py.ast.typed.s.result @@ -0,0 +1,6 @@ +True +False +True +False +False +True diff --git a/pa3-tests/core/str_get_element.py b/pa3-tests/core/str_get_element.py new file mode 100644 index 0000000..8681a05 --- /dev/null +++ b/pa3-tests/core/str_get_element.py @@ -0,0 +1,14 @@ +x:str = "abc" +a:str = "" +b:str = "" +c:str = "" + +def str_get(s:str, i:int) -> str: + return s[i] + +a = str_get(x, 0) +b = str_get(x, 1) +c = str_get(x, 2) +print(a) +print(b) +print(c) diff --git a/pa3-tests/core/str_get_element.py.ast.typed b/pa3-tests/core/str_get_element.py.ast.typed new file mode 100644 index 0000000..ff9c449 --- /dev/null +++ b/pa3-tests/core/str_get_element.py.ast.typed @@ -0,0 +1,462 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 4, 9, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 1, 7, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 11 ], + "name" : "str_get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 6, 13, 6, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 13, 6, 13 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 15, 6, 17 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 6, 20, 6, 24 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 20, 6, 20 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 22, 6, 24 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 30, 6, 32 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 5, 7, 15 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 7, 12, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 5, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "IntegerLiteral", + "location" : [ 9, 16, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 10, 5, 10, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "IntegerLiteral", + "location" : [ 10, 16, 10, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 11, 5, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 7, 13, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 14, 1, 14, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 14, 1, 14, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 1, 14, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_get_element.py.ast.typed.s.result b/pa3-tests/core/str_get_element.py.ast.typed.s.result new file mode 100644 index 0000000..de98044 --- /dev/null +++ b/pa3-tests/core/str_get_element.py.ast.typed.s.result @@ -0,0 +1,3 @@ +a +b +c diff --git a/pa3-tests/core/str_get_element_oob_1.py b/pa3-tests/core/str_get_element_oob_1.py new file mode 100644 index 0000000..b6613d1 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_1.py @@ -0,0 +1,8 @@ +x:str = "abc" +a:str = "" + +def str_get(s:str, i:int) -> str: + return s[i] + +a = str_get(x, -1) +print(a) diff --git a/pa3-tests/core/str_get_element_oob_1.py.ast.typed b/pa3-tests/core/str_get_element_oob_1.py.ast.typed new file mode 100644 index 0000000..4ce2733 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_1.py.ast.typed @@ -0,0 +1,235 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 11 ], + "name" : "str_get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 13 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 15, 4, 17 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 20, 4, 24 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 20, 4, 20 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 22, 4, 24 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 15 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 5, 12, 5, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "UnaryExpr", + "location" : [ 7, 16, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 17, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_get_element_oob_1.py.ast.typed.s.result b/pa3-tests/core/str_get_element_oob_1.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_1.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/str_get_element_oob_2.py b/pa3-tests/core/str_get_element_oob_2.py new file mode 100644 index 0000000..4c4e0e0 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_2.py @@ -0,0 +1,8 @@ +x:str = "abc" +a:str = "" + +def str_get(s:str, i:int) -> str: + return s[i] + +a = str_get(x, 3) +print(a) diff --git a/pa3-tests/core/str_get_element_oob_2.py.ast.typed b/pa3-tests/core/str_get_element_oob_2.py.ast.typed new file mode 100644 index 0000000..3a10e59 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_2.py.ast.typed @@ -0,0 +1,226 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "abc" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 11 ], + "name" : "str_get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 13 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 15, 4, 17 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 20, 4, 24 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 20, 4, 20 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 22, 4, 24 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 15 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 5, 12, 5, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 16, 7, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_get_element_oob_2.py.ast.typed.s.result b/pa3-tests/core/str_get_element_oob_2.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_2.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/str_get_element_oob_3.py b/pa3-tests/core/str_get_element_oob_3.py new file mode 100644 index 0000000..28e545a --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_3.py @@ -0,0 +1,8 @@ +x:str = "" +a:str = "" + +def str_get(s:str, i:int) -> str: + return s[i] + +a = str_get(x, 0) +print(a) diff --git a/pa3-tests/core/str_get_element_oob_3.py.ast.typed b/pa3-tests/core/str_get_element_oob_3.py.ast.typed new file mode 100644 index 0000000..bac1f18 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_3.py.ast.typed @@ -0,0 +1,226 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 11 ], + "name" : "str_get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 13 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 15, 4, 17 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 20, 4, 24 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 20, 4, 20 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 22, 4, 24 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 15 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 5, 12, 5, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "str_get" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "IntegerLiteral", + "location" : [ 7, 16, 7, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_get_element_oob_3.py.ast.typed.s.result b/pa3-tests/core/str_get_element_oob_3.py.ast.typed.s.result new file mode 100644 index 0000000..144d019 --- /dev/null +++ b/pa3-tests/core/str_get_element_oob_3.py.ast.typed.s.result @@ -0,0 +1,2 @@ +Index out of bounds +Exited with error code 3 diff --git a/pa3-tests/core/str_len.py b/pa3-tests/core/str_len.py new file mode 100644 index 0000000..829f00b --- /dev/null +++ b/pa3-tests/core/str_len.py @@ -0,0 +1 @@ +print(len("ChocoPy")) diff --git a/pa3-tests/core/str_len.py.ast.typed b/pa3-tests/core/str_len.py.ast.typed new file mode 100644 index 0000000..d76359c --- /dev/null +++ b/pa3-tests/core/str_len.py.ast.typed @@ -0,0 +1,71 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 22 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 21 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 1, 7, 1, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 11, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "ChocoPy" + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/str_len.py.ast.typed.s.result b/pa3-tests/core/str_len.py.ast.typed.s.result new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/pa3-tests/core/str_len.py.ast.typed.s.result @@ -0,0 +1 @@ +7 diff --git a/pa3-tests/core/var_assign.py b/pa3-tests/core/var_assign.py new file mode 100644 index 0000000..c56b7ca --- /dev/null +++ b/pa3-tests/core/var_assign.py @@ -0,0 +1,4 @@ +x:int = 0 +y:object = 1 +x = y = 42 +print(x) diff --git a/pa3-tests/core/var_assign.py.ast.typed b/pa3-tests/core/var_assign.py.ast.typed new file mode 100644 index 0000000..83fb4c4 --- /dev/null +++ b/pa3-tests/core/var_assign.py.ast.typed @@ -0,0 +1,128 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 12 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 12, 2, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa3-tests/core/var_assign.py.ast.typed.s.result b/pa3-tests/core/var_assign.py.ast.typed.s.result new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/pa3-tests/core/var_assign.py.ast.typed.s.result @@ -0,0 +1 @@ +42 diff --git a/pa3-tests/run-tests.sh b/pa3-tests/run-tests.sh new file mode 100755 index 0000000..24a51be --- /dev/null +++ b/pa3-tests/run-tests.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +JAVA="java -cp pa3-tests/chocopy-ref.jar:target/assignment.jar chocopy.ChocoPy" + +echo "# CORE TESTS" +${JAVA} --pass=..s --test --run --dir pa3-tests/core + +echo +echo "# BENCHMARK CORRECTNESS TESTS" +${JAVA} --pass=..s --test --run --dir pa3-tests/benchmarks + +echo +echo "# BENCHMARK PERFORMANCE TESTS" +${JAVA} --pass=..s --run --profile --dir pa3-tests/benchmarks | grep -e Reading -e Cycles