summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-22 09:54:23 -0700
committerCliff Click <cliffc@acm.org>2025-04-22 09:54:23 -0700
commit8d78c7c6384da8b0bade19f782509db94c4ca792 (patch)
tree8fd9c6e75e1eb2a113528305f09ae5ca9e91a870
parent698107491697cf6efdd574ca6d8891516ba65edb (diff)
downloadSimple-8d78c7c6384da8b0bade19f782509db94c4ca792.tar.gz
Simple-8d78c7c6384da8b0bade19f782509db94c4ca792.zip
More help for block layout
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java24
-rw-r--r--chapter22/README.md32
2 files changed, 43 insertions, 13 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
index c822a73e..3d6cd209 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
@@ -256,7 +256,7 @@ public class Encoding {
? (bb.nOuts()>1 || !(bb.cfg0() instanceof IfNode) )
// Forwards jump. If all the blocks, in RPO order, to our
// target are empty, we will fall in and not need a jump.
- : !isEmptyBackwardsScan(rpo,next);
+ : !backwardsEmptyScan(rpo,next);
if( needJump ) {
CFGNode jmp = _code._mach.jump();
jmp._ltree = bb._ltree;
@@ -277,12 +277,18 @@ public class Encoding {
// bld` is true, the `fld < bld` must be false, or else both directions
// exit the loop... and the IF test would not be in the loop.
- // true to exit a loop usually, keep true if taking an empty backwards branch
- if( tld < bld ) return emptyBackBlock(f,bld);
+ // true to exit a loop usually (and false falls into Yet Another Loop
+ // Block), invert if false is taking an empty backwards branch.
+ if( tld < bld ) return forwardsEmptyScan(f,bld);
// false to exit a loop, normally invert to true (except empty back)
- if( fld < bld ) return !emptyBackBlock(t,bld);
+ if( fld < bld ) return !forwardsEmptyScan(t,bld);
// Not exiting the loop; staying at this depth (or going deeper loop).
+
+ // Jump/true to an empty backwards block
+ if( forwardsEmptyScan(t,bld) ) return false;
+ if( forwardsEmptyScan(f,bld) ) return true ;
+
// Fall/false into a full block, Jump/true to an empty block.
if( f.nOuts()>1 && t.nOuts()==1 ) return false;
if( t.nOuts()>1 && f.nOuts()==1 ) return true ;
@@ -290,13 +296,17 @@ public class Encoding {
return t._pre > f._pre;
}
- private static boolean emptyBackBlock( CFGNode c, int bld ) {
- return c.loopDepth()==bld && c.nOuts()==1 && c.uctrl() instanceof LoopNode;
+ // Do we continue forwards from 'c' to the Loop back edge, without doing
+ // anything else? Then this branch can directly jump to the loop head.
+ private static boolean forwardsEmptyScan( CFGNode c, int bld ) {
+ if( c.nOuts()!=1 || c.loopDepth()!=bld ) return false;
+ return c.uctrl() instanceof RegionNode cfg &&
+ (cfg instanceof LoopNode || forwardsEmptyScan(cfg,bld));
}
// Is the CFG from "next" to the end empty? This means jumping to "next"
// will naturally fall into the end.
- private static boolean isEmptyBackwardsScan(Ary<CFGNode> rpo, CFGNode next) {
+ private static boolean backwardsEmptyScan(Ary<CFGNode> rpo, CFGNode next) {
for( int i=rpo._len-1; rpo.at(i)!=next; i-- )
if( rpo.at(i).nOuts()!=1 )
return false;
diff --git a/chapter22/README.md b/chapter22/README.md
index 63cd12bf..570490f8 100644
--- a/chapter22/README.md
+++ b/chapter22/README.md
@@ -1,4 +1,4 @@
-# Chapter 22: Strings and Such
+# Chapter 22: Strings and I/O
It's high time for Strings and printing! In this chapter we look at what it
takes to make a nice user-mode string. We are implementing strings in the base
@@ -46,11 +46,11 @@ Any number of named fields are allowed:
```java
struct Class {
- str className;
- str professor;
- int time;
- int credits;
- Class prerequisiste;
+ str className;
+ str professor;
+ int time;
+ int credits;
+ Class prerequisite;
u16 #; // Limit of 65535 students per class
Student [];
};
@@ -135,4 +135,24 @@ chapter.
## A String Implementation
+### A Final String
+
+### A Extendable String (aka StringBuilder or StringBuffer)
+
+```java
+struct xstr {
+// update-in-place expanding string
+
+};
+```
+
+
## FFI and I/O Calls
+
+Calling external / FFI functions.
+
+`{ i32 fd, u8[] buf, i32 len -> i32 } write = "C";`
+
+
+## Importing name spaces
+