summaryrefslogtreecommitdiff
path: root/chapter01
diff options
context:
space:
mode:
Diffstat (limited to 'chapter01')
-rw-r--r--chapter01/README.md18
-rw-r--r--chapter01/docs/01-grammar.md4
-rw-r--r--chapter01/pom.xml2
-rw-r--r--chapter01/src/main/java/com/seaofnodes/simple/Parser.java4
-rw-r--r--chapter01/src/main/java/com/seaofnodes/simple/node/Node.java4
-rw-r--r--chapter01/src/main/java/com/seaofnodes/simple/node/ReturnNode.java2
-rw-r--r--chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java8
7 files changed, 21 insertions, 21 deletions
diff --git a/chapter01/README.md b/chapter01/README.md
index fef83683..d4882f8a 100644
--- a/chapter01/README.md
+++ b/chapter01/README.md
@@ -8,9 +8,9 @@ return 1;
We implement the `return` statement.
The `return` statement accepts an `expression` as an argument.
-The only `expression` type is an integer literal, as shown in the example above.
+The only `expression` type is an integer literal, as shown in the example above.
-Here is the [complete language grammar](docs/01-grammar.md) for this chapter.
+Here is the [complete language grammar](docs/01-grammar.md) for this chapter.
To implement this simple language, we introduce a few key components and data structures.
@@ -25,7 +25,7 @@ If necessary the reader can consult a standard compiler text book.
## Architecture
-We construct the intermediate Sea of Nodes (SoN) representation directly as we parse the language. There is no Abstract Syntax Tree representation. The reason for this is to demonstrate a key benefit of the SoN IR:
+We construct the intermediate Sea of Nodes (SoN) representation directly as we parse the language. There is no Abstract Syntax Tree representation. The reason for this is to demonstrate a key benefit of the SoN IR:
a number of pessimistic peephole optimizations can be performed while parsing a language. This aspect is more fully explored from [Chapter 2](../chapter02/README.md) onwards.
## Data Structures
@@ -43,7 +43,7 @@ representation follow.
### Intermediate Representation as a Graph of Nodes
The intermediate representation is a graph of Node objects. The `Node` class is the base type for objects in the IR graph.
-The `Node` class provides common capabilities that are inherited by all subtypes.
+The `Node` class provides common capabilities that are inherited by all subtypes.
Each subtype implements semantics relevant to that subtype.
Each `Node` represents an "instruction" as it may appear in traditional IRs.
@@ -109,8 +109,8 @@ The following control and data nodes appear in this chapter.
| Return | Control | Represents the termination of a function | Predecessor control node, Data node value | Return value of the function |
| Constant | Data | Represents constants such as integer literals | None, however Start node is set as input to enable graph walking | Value of the constant |
-Within a traditional basic block, instructions are executed in sequence. In the Sea of Nodes model, the correct sequence of instructions is determined by a scheduling
-algorithm that depends only on dependencies between nodes (including control dependencies) that are explicit as edges in the graph. This enables a number of optimizations
+Within a traditional basic block, instructions are executed in sequence. In the Sea of Nodes model, the correct sequence of instructions is determined by a scheduling
+algorithm that depends only on dependencies between nodes (including control dependencies) that are explicit as edges in the graph. This enables a number of optimizations
at very little cost (nearly always small constant time) because all dependencies are always available.
### Unique Node ID
@@ -122,8 +122,8 @@ graph. We discuss Node equality in [Chapter 9](../chapter09/README.md).
### Start Node
-The Start node represents the start of the function. For now, we do not have any inputs to Start because our function does not
-yet accept parameters. When we add parameters the value of Start will be a tuple, and will require Projections to extract the values.
+The Start node represents the start of the function. For now, we do not have any inputs to Start because our function does not
+yet accept parameters. When we add parameters the value of Start will be a tuple, and will require Projections to extract the values.
We discuss this in detail in [Chapter 4](../chapter04/README.md).
### Constant Node
@@ -145,7 +145,7 @@ The Return node has two inputs. The first input is a control node and the
second is the data node that supplies the return value.
In this presentation, Return functions as a Stop node, since multiple `return` statements are not possible.
-The Stop node will be introduced in [Chapter 5](../chapter05/README.md) when we implement `if` statements.
+The Stop node will be introduced in [Chapter 5](../chapter05/README.md) when we implement `if` statements.
The Return's output is the value from the data node.
diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md
index 5d9f3cf7..c5ddae2c 100644
--- a/chapter01/docs/01-grammar.md
+++ b/chapter01/docs/01-grammar.md
@@ -22,5 +22,5 @@ primaryExpression
INTEGER_LITERAL
: [1-9][0-9]*
| [0]
- ;
-``` \ No newline at end of file
+ ;
+```
diff --git a/chapter01/pom.xml b/chapter01/pom.xml
index 2204bde8..08af80e1 100644
--- a/chapter01/pom.xml
+++ b/chapter01/pom.xml
@@ -11,4 +11,4 @@
<artifactId>chapter01</artifactId>
<packaging>jar</packaging>
<name>Chapter 1</name>
-</project> \ No newline at end of file
+</project>
diff --git a/chapter01/src/main/java/com/seaofnodes/simple/Parser.java b/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
index e2c1ca71..d79d23ff 100644
--- a/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter01/src/main/java/com/seaofnodes/simple/Parser.java
@@ -194,7 +194,7 @@ public class Parser {
return Long.parseLong(snum);
}
- // First letter of an identifier
+ // First letter of an identifier
private boolean isIdStart(char ch) {
return Character.isAlphabetic(ch) || ch == '_';
}
@@ -210,7 +210,7 @@ public class Parser {
return new String(_input, start, --_position - start);
}
- //
+ //
private boolean isPunctuation(char ch) {
return "=;[]<>()+-/*".indexOf(ch) != -1;
}
diff --git a/chapter01/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter01/src/main/java/com/seaofnodes/simple/node/Node.java
index cf465e94..5d74e206 100644
--- a/chapter01/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter01/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -52,7 +52,7 @@ public abstract class Node {
if( n != null )
n._outputs.add( this );
}
-
+
/**
* Gets the ith input node
* @param i Offset of the input node
@@ -67,7 +67,7 @@ public abstract class Node {
public boolean isUnused() { return nOuts() == 0; }
public boolean isCFG() { return false; }
-
+
/**
* Used to allow repeating tests in the same JVM. This just resets the
diff --git a/chapter01/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/chapter01/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
index 5e083cf2..85bbc83f 100644
--- a/chapter01/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
+++ b/chapter01/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
@@ -19,5 +19,5 @@ public class ReturnNode extends Node {
public Node expr() { return in(1); }
@Override public boolean isCFG() { return true; }
-
+
}
diff --git a/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index cb5a8a69..738ed702 100644
--- a/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java
+++ b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -17,7 +17,7 @@ public class Chapter01Test {
Parser parser = new Parser("return 1;");
ReturnNode ret = parser.parse();
StartNode start = Parser.START;
-
+
assertEquals(start, ret.ctrl());
Node expr = ret.expr();
if( expr instanceof ConstantNode con ) {
@@ -40,7 +40,7 @@ public class Chapter01Test {
@Test
public void testBad1() {
- try {
+ try {
new Parser("ret").parse();
fail();
} catch( RuntimeException e ) {
@@ -50,7 +50,7 @@ public class Chapter01Test {
@Test
public void testBad2() {
- try {
+ try {
new Parser("return 0123;").parse();
fail();
} catch( RuntimeException e ) {
@@ -67,7 +67,7 @@ public class Chapter01Test {
@Test
public void testBad4() {
- try {
+ try {
new Parser("return 100").parse();
fail();
} catch( RuntimeException e ) {