Skip to content

Commit d75781d

Browse files
chapter17: catch up with main
1 parent 3c7fea1 commit d75781d

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Rust implementation of https://github.com/SeaOfNodes/Simple
66

77
This is still a **work in progress** and the code is not very readable.
88

9-
The code is currently equivalent to `chapter17` of the Java implementation at commit `8d9cd9a0`.
9+
The code is currently equivalent to `chapter17` of the Java implementation at commit `fd5178db`.

src/sea_of_nodes/nodes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ impl Node {
357357
};
358358
match self.downcast(&sea.ops) {
359359
TypedNode::And(_) => binary_ints("&"),
360+
TypedNode::Add(_) => binary_ints(&sea[self].label()),
361+
TypedNode::Mul(_) => binary_ints(&sea[self].label()),
360362
TypedNode::Or(_) => binary_ints("|"),
361363
TypedNode::Xor(_) => binary_ints("^"),
362364
TypedNode::Sar(_) => binary_ints(">>"),

src/sea_of_nodes/nodes/idealize.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ impl Add {
5959
fn idealize_add(self, sea: &mut Nodes) -> Option<Node> {
6060
let lhs = self.inputs(sea)[1]?;
6161
let rhs = self.inputs(sea)[2]?;
62+
if rhs.err(sea).is_some() {
63+
return None;
64+
}
6265
let t2 = rhs.ty(sea)?;
6366

6467
// Add of 0. We do not check for (0+x) because this will already

src/sea_of_nodes/tests/chapter13.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ return n.i;
168168
);
169169
}
170170

171+
#[test]
172+
fn test_null_ref_4() {
173+
test_error_iterate("-null-5/null-5;", "Cannot 'Add' null");
174+
}
175+
176+
#[test]
177+
fn test_null_ref_5() {
178+
test_error_iterate("return null+42;", "Cannot 'Add' null");
179+
}
180+
171181
#[test]
172182
fn test_empty() {
173183
let arena = DroplessArena::new();

src/sea_of_nodes/tests/chapter17.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ use crate::sea_of_nodes::types::Types;
99
fn test_jig() {
1010
let arena = DroplessArena::new();
1111
let types = Types::new(&arena);
12-
let mut parser = Parser::new(
13-
"\
14-
int i = 0;
15-
i=i=1;
16-
return i;
17-
//return 3.14;
18-
",
19-
&types,
20-
);
12+
let mut parser = Parser::new("return 1;", &types);
2113
let stop = parser.parse().unwrap();
2214
parser.iterate(stop);
2315
parser.type_check(stop).unwrap();

0 commit comments

Comments
 (0)