From d12fc63571a2792f0f540ac4fe107e7fdcbe8e77 Mon Sep 17 00:00:00 2001 From: Sandy Brownlee Date: Fri, 19 Aug 2022 16:28:13 +0100 Subject: [PATCH 1/6] fixes for variable declarations --- .../src/main/java/triangle/contextualAnalyzer/Checker.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java index 9a9f5b2..d7296c7 100644 --- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java +++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java @@ -678,6 +678,7 @@ public final class Checker implements ActualParameterVisitor Date: Fri, 19 Aug 2022 17:28:49 +0100 Subject: [PATCH 2/6] bugfix --- .../src/main/java/triangle/contextualAnalyzer/Checker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java index d7296c7..c3f289f 100644 --- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java +++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java @@ -204,7 +204,7 @@ public final class Checker implements ActualParameterVisitor Date: Wed, 31 Aug 2022 12:25:57 +0100 Subject: [PATCH 3/6] added simple examples --- programs/assignments.tri | 9 +++++++++ programs/ifdemo.tri | 9 +++++++++ programs/simpleadding.tri | 10 ++++++++++ 3 files changed, 28 insertions(+) create mode 100644 programs/assignments.tri create mode 100644 programs/ifdemo.tri create mode 100644 programs/simpleadding.tri diff --git a/programs/assignments.tri b/programs/assignments.tri new file mode 100644 index 0000000..102bb78 --- /dev/null +++ b/programs/assignments.tri @@ -0,0 +1,9 @@ +let + var n : Integer; + var c : Char +in + + begin + c := '&'; + n := n + 1 + end diff --git a/programs/ifdemo.tri b/programs/ifdemo.tri new file mode 100644 index 0000000..ddc4df3 --- /dev/null +++ b/programs/ifdemo.tri @@ -0,0 +1,9 @@ +let + var a : Integer; + var n : Integer +in + begin + if a < 0 + then n := 0 + else n := 1 + end diff --git a/programs/simpleadding.tri b/programs/simpleadding.tri new file mode 100644 index 0000000..139847a --- /dev/null +++ b/programs/simpleadding.tri @@ -0,0 +1,10 @@ +let + var a : Integer; + var b : Integer; + var c : Integer + +in + begin + a := 1; b := 2; c := a / b; + end + From 62b666992a805e149b3d5042b3e3385a75d9291f Mon Sep 17 00:00:00 2001 From: Sandy Brownlee Date: Wed, 31 Aug 2022 15:01:38 +0100 Subject: [PATCH 4/6] Fix for type checking error in visitDotVName --- .../src/main/java/triangle/contextualAnalyzer/Checker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java index c3f289f..f1802aa 100644 --- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java +++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java @@ -681,7 +681,7 @@ public final class Checker implements ActualParameterVisitor Date: Wed, 31 Aug 2022 16:34:48 +0100 Subject: [PATCH 5/6] Fixed nullpointer caused by missing Frame object --- .../src/main/java/triangle/codeGenerator/Encoder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java b/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java index f3a650c..3066815 100644 --- a/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java +++ b/Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java @@ -545,7 +545,7 @@ public final class Encoder implements ActualParameterVisitor, public Integer visitRecordTypeDenoter(RecordTypeDenoter ast, Frame frame) { int typeSize; if (ast.entity == null) { - typeSize = ast.FT.visit(this, null); + typeSize = ast.FT.visit(this, frame); ast.entity = new TypeRepresentation(typeSize); writeTableDetails(ast); } else { @@ -556,6 +556,10 @@ public final class Encoder implements ActualParameterVisitor, @Override public Integer visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Frame frame) { + if (frame == null) { // in this case, we're just using the frame to wrap up the size + frame = Frame.Initial; + } + var offset = frame.getSize(); int fieldSize; if (ast.entity == null) { From 4be8f473512074d7efa27cbe3766ebda12cc1bcc Mon Sep 17 00:00:00 2001 From: Sandy Brownlee Date: Wed, 31 Aug 2022 16:56:56 +0100 Subject: [PATCH 6/6] bugfix for duplicate formal params --- .../contextualAnalyzer/IdentificationTable.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java index 6e8eabb..33d1157 100644 --- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java +++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java @@ -53,7 +53,7 @@ public final class IdentificationTable { // same identifier at the current level. public void enter(String id, Declaration attr) { - attr.duplicated = retrieve(id) != null; + attr.duplicated = retrieve(id, true) != null; this.latest = new IdEntry(id, attr, this.level, this.latest); } @@ -64,9 +64,15 @@ public final class IdentificationTable { // otherwise returns the attribute field of the entry found. public Declaration retrieve(String id) { + return retrieve(id, false); + } + + // thisLevelOnly limits the search to only the current level + + public Declaration retrieve(String id, boolean thisLevelOnly) { var entry = this.latest; while (true) { - if (entry == null) { + if (entry == null || (thisLevelOnly && entry.level < this.level)) { break; } else if (entry.id.equals(id)) { return entry.attr;