summaryrefslogtreecommitdiff
path: root/chapter01
diff options
context:
space:
mode:
authorDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2023-09-26 17:43:36 +0100
committerGitHub <noreply@github.com>2023-09-26 09:43:36 -0700
commit29def92f2ddbfca64ba827f116172fe98b2df491 (patch)
treea49affb27d57e908429beafe300756d5e4c0c273 /chapter01
parent62bfd0d619b28892152a7d89639f3437bc9df573 (diff)
downloadSimple-29def92f2ddbfca64ba827f116172fe98b2df491.tar.gz
Simple-29def92f2ddbfca64ba827f116172fe98b2df491.zip
Chapter 2 (#4)
* Start on Chapter 2. * Start on Chapter 2. * Refactor * Refactor * Initial attempt at peephole opt for add operation * cleanup unused import * Start on graph visualizer * Start on graph visualizer * Rework chapter 2 Add a short discourse on the Types, and provide a Bottom type. Make a final toString; require each Node to specify its special printing via label(). Add a recursing printer called print(); toString is used by default in the debugger and so cannot be recursive. Make the peephole rules based on a proper Type and idealize calls. Big comments about the Type computations. Every node picks up a _print, compute and idealize() call. Rename long arith ops Divide, UnaryMinus, Multiply, Subtract into shorter uniform-length names. Cleans up the parser where he does the precedence op parsing. Rework Parser: - Drop Token class, its all Strings except in the one place we know a number is coming - Embed the Lexer as a field in the Parser, instead of trying to pass it around everywhere in the Parser - StartNode becomes a read-only global, so we don't have to pass it around everywhere in the Parser AND optimizer. - Lexer matches on strings and returns strings. Match and consume *at the moment* instead of carrying around a current token/string and forcing the next-token after consuming the current one. - All parse subexpressions shrink by 1/2 after these changes. * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Remove range * progress Chapter 2 Drop integer ranges. Broader lattice pic. Lots of prose changes in the readme. Fixed title in gviz dot generation. Fixed bug with peephole making redundant constants. * Implement compute for all the arithmetic node types Add a flag to switch off peephole so we can see the full graph Add post peephole graph to writeup * Implement compute for all the arithmetic node types Add a flag to switch off peephole so we can see the full graph Add post peephole graph to writeup * Fix bad path to the svg * Update pre-peephole diagram * Add dead code elimination ...and a set_def to proper update graph edges. * Update README.md * Cleanup the GraphVisualizer a bit. Update the graphs. Update the chapter list as chapter 3 deleted, and chapter 4 is now chapter 3. --------- Co-authored-by: Cliff Click <cliffc@acm.org>
Diffstat (limited to 'chapter01')
-rw-r--r--chapter01/README.md2
-rw-r--r--chapter01/docs/01-grammar.md1
-rw-r--r--chapter01/docs/01-graph.gv (renamed from chapter01/docs/02-graph.gv)0
-rw-r--r--chapter01/docs/01-graph.svg (renamed from chapter01/docs/02-graph.svg)0
-rw-r--r--chapter01/src/main/java/com/seaofnodes/simple/Parser.java4
-rw-r--r--chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java (renamed from chapter01/src/test/java/com/seaofnodes/simple/ParserTest.java)4
6 files changed, 6 insertions, 5 deletions
diff --git a/chapter01/README.md b/chapter01/README.md
index f3231d8c..57caa801 100644
--- a/chapter01/README.md
+++ b/chapter01/README.md
@@ -113,7 +113,7 @@ Here is visualization of the program:
return 1;
```
-![Sea of Nodes Visual](./docs/02-graph.svg)
+![Sea of Nodes Visual](./docs/01-graph.svg)
* Control nodes appear as square boxes
* Control edges are in bold red
diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md
index cf947dfc..5d9f3cf7 100644
--- a/chapter01/docs/01-grammar.md
+++ b/chapter01/docs/01-grammar.md
@@ -21,5 +21,6 @@ primaryExpression
INTEGER_LITERAL
: [1-9][0-9]*
+ | [0]
;
``` \ No newline at end of file
diff --git a/chapter01/docs/02-graph.gv b/chapter01/docs/01-graph.gv
index 40181544..40181544 100644
--- a/chapter01/docs/02-graph.gv
+++ b/chapter01/docs/01-graph.gv
diff --git a/chapter01/docs/02-graph.svg b/chapter01/docs/01-graph.svg
index fbf92d7d..fbf92d7d 100644
--- a/chapter01/docs/02-graph.svg
+++ b/chapter01/docs/01-graph.svg
diff --git a/chapter01/src/main/java/com/seaofnodes/simple/Parser.java b/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
index 8fb1ebaf..cdfff842 100644
--- a/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
@@ -80,7 +80,7 @@ public class Parser {
* Parse integer literal
*
* <pre>
- * integerLiteral: [1-9][0-9]*
+ * integerLiteral: [1-9][0-9]* | [0]
* </pre>
*/
private ConstantNode parseIntegerLiteral(Lexer lexer) {
@@ -245,7 +245,7 @@ public class Parser {
private Token parsePuncuation() {
int start = _position-1;
- while( isPunctuation(nextChar()) );
+ if( isPunctuation(nextChar()) );
return Token.newPunct(new String(_input,start,--_position-start));
}
diff --git a/chapter01/src/test/java/com/seaofnodes/simple/ParserTest.java b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index 887f63b8..14c22437 100644
--- a/chapter01/src/test/java/com/seaofnodes/simple/ParserTest.java
+++ b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -4,7 +4,7 @@ import com.seaofnodes.simple.node.*;
import org.junit.Test;
import static org.junit.Assert.*;
-public class ParserTest {
+public class Chapter01Test {
@Test
public void testSimpleProgram() {
@@ -54,7 +54,7 @@ public class ParserTest {
@Test
public void testBad3() {
try { new Parser().parse("return --12;"); }
- catch( RuntimeException e ) { assertEquals("syntax error, expected integer literal: --",e.getMessage()); }
+ catch( RuntimeException e ) { assertEquals("syntax error, expected integer literal: -",e.getMessage()); }
}
@Test