summaryrefslogtreecommitdiff
path: root/chapter24/ROADMAP.md
diff options
context:
space:
mode:
authorTamás Hadházy <85063808+Hels15@users.noreply.github.com>2025-08-14 19:23:59 +0100
committerGitHub <noreply@github.com>2025-08-14 11:23:59 -0700
commit080dde496d028702bb2dc3fea8ce9794e5a5cc8a (patch)
treececc2f68518dceb810d8170c0c9391312890708b /chapter24/ROADMAP.md
parenteef037df1c490ccea0c4fe84e831ef5ff40a757d (diff)
downloadSimple-080dde496d028702bb2dc3fea8ce9794e5a5cc8a.tar.gz
Simple-080dde496d028702bb2dc3fea8ce9794e5a5cc8a.zip
chapter24 chaining operator test cases (#227)
* Update Chapter14Test.java * fixed order of operands * base rex fixup * more bug fix * remove jukn files * minimal "make release" * further fixes * minor fixes * minor fixes * minor fixes * base != -1 check, precedence fix * Add regkills in IFG building Fix bug LRG union stats Adjust self-conflict splits to be slightly less aggressive In every use-side split, dont split-after-split same block. NewNode is a multi, does not define a register * 64 bit encoding for gpr(s) load * RA improvements Attempt to commute to keep reg-masks compatible. Clones with kills (x86 XOR killing flags to zero) fail before the flag-def. Bugfix failed to color last lrg. More smarts on picking trivial LRGs during coloring Drop isSplit, add SplitNode Pass regalloc round to all splits for debugging Self-conflict no split on loop backedge. Handle split that gets made goes dead No-reg-mask spilling handles case with many def/uses. Add DivIX86 BrainFuck, MergeSort now allocate as testing * 8 bit imm support * conditional jump fix * Push l,ast change, unbreak branch * XOR remove extra opcode, imm size supports 8 bit. * Finally pass the `new [u8]` double-copy test * Fix several ARM reg setup problems Finish Split bypass check ARM: rsp is also a fixed zero, in R31. R0 is a valid register. CallArm prints args, passes TFP for arg selection. Does not return a register. All CallEndARM which DOES return a register. Parms missing tfp for float args. ProjARM after a New missing regs. RetARM missing RPC. Remove hopeful DivIX86 * 64 bit imm for alu ops encoded in extra reg then use it in Op as an operand * Bunch of minor arm, risc fixes small constants not cloning * jump invert encoding * warning comment * Much ARM fixage One More Go-Round with Better Biased Colors Fix bug picking deepest spills to bias. ARM: remove default 2-address. Fix regmask overflow. Rename some ops to be canonical. * Fixes to release Port does not have to be in a Simple named directory. Call convention is just a string, no enum Missed some tests running RISC, ARM. * Minor release change to allow another foreign port * better split encoding and fix CallInMask * notNode * fix callInMask * riscv init * riscv basic ALU ops and types of instructions * Allowing non-Simple repo ports Expanding public API slightly so alternative (non-Simple repo) ports can happen. RegMask supports single-bit-set and a long bitmask. Bugfix GCM splitting multiple global constants. Bugfix LCM grabbing a projection vs multi Bugfix RegAlloc when avoiding splitting a clonable Source code in release More timing in CodeGen * riscv indirect addressing and function calls * Cleanup call ABI presentation Everybody uses the same names, same code shapes * Caller save regs ...not callee save yet * Expose caller save regs * Store Risc adjustments, no imm in MemOpRISC * specific print encoding for cpus * merge fixup * More x86,risc,arm call convention fixes Collect callee and caller save masks (inverts of each other, except for spills). Reorg layout to be closer to each other; remove dead mask definitions; add final keyword * lui fix up with 32 bit immediates * Callee-save registers Callee-save registers and masks and inserting LRGs for same and spilling and picking good spills. Insert CalleeSaveNodes and edges to RetXXXs and RegMasks for those edges. Iterators for regmask. Better printing post-allocation * RegMask supports 128 bits All regs available arm, risc. MergeSort compiles & runs * added flags splitting * Fix risc5 compares No flags on risc5. Branch takes 2 inputs (one can be imm12). Float compare only sets a GPR to 0/1. Bool has a isFloat Common risc5 imm-form handling * extend test cases * imm encoding, flags fixed * grep for Todo: relocs * float riscv fixed * flags for set * lui fix for small bits [0, 12] * arm init * arm last touches * fmov still needs fix * minor fixes * minor fixes(2) * got rid of unnecessary stuff * create ch21 * remove encodings from chapter20 dir * 1/2 pass cleaning up ARM encoding API * ARM encoding compiles * Risc R_TYPE and I_TYPE * Progress RISC encodings Missing lots of stuff still * progress risc encoding * risc encodings compile * Update README.md * Fold up redundant OP/OP-FP risc5 encoding * x86 mem opcodes first cut break out MemOp encodings into parts; change x86 indirectAdr to use Encoding class, remove redundant asserts & code * x86 mem op encodings * x86 reg+imm forms * most reg-reg forms * More x86 encodings * Last few encodings * switch to binary literals over decimals for opcodes * logical immediates fixed, bitwise ops imm forms * tfp and setArm fixed * PC relative float for riscv * readme init * Merged pr/169 * Fixed the array1 test encodings Clean up branch invert logic during BB layout Cleanup branch target printing for RISC,ARM ImmRISC ops mask imm12 to 12 bits Fix NewRISC; hardcode RPC as part of call Fix RISC inverting branchs >,>= * floatarm encoding * tfparm and intarm * uncontional jump encoding for arm and riscv * smarter IntARM, Intx86 does not always include rex. * REX after PREFIX * fixup load and store indirect * updated rex prefix, if its 0x40 then its not needed * Rex fix for floats, got rid of unnecessary stuff. * rename to camel case, better param name * add test export * merged * store opt * store and load optimised forms handled * tfp patch * Store/load float arm/riscv/x64 * got rid of debug print * splits for x86, riscv and arm * readme fixups * fix global symbol numbering for constants * fix TFP pathc on arm and riscv, keep symbols in good order. * fix opcode for store and loads, memOpRisc for Store and splitting * replace hard coded opcodes with major opcodes * replace hard coded opcodes with major opcodes * add asserts and fix reg numbering * add asserts and fix reg numbering * minor updates * revert changes * remove constant pool from encoder TODO: add flag for JIT * extend test cases * minor fixes * minor fixes * update float test case * stringHash fix on x64 * remove conditional ConstantPool write * brainfuck minor fixes * minor arm fixes * split fix * brainfuck and fib * brain fuck * arg_count, person * add ignore * typo * riscv test sieve attempt * minor changes * riscv5 emulator additions * arm eval setup * Update riscv.java * arm eval basics * delta fixes * arm fixes * testfib arm * arg_count * small update for test newton * small update for test newton * testNewton runs on x64, riscv and arm * arm additions * arm pc eval fix * arm workings * debugging * Progress sieve on ARM Most ops need WMASK as the output, to exclude RSP. calloc sentinal changes to multiple of 4 NewArm needs to set arg X0 to #1; arg X1 is length. Fix EvalARM calling calloc & not advancing PC. Fix EvalARM using ints vs longs. Fix EvalARM missing AndI encoding. * Fix some arm encoding Fix some OBOB in R5 calloc encoding. Sort EvalArm by major opcodes. Add ASL. Remove leading switch. Fix OBOB in calloc. Fix shift in ld/st with reg+offset * arm sieve test * test person push * brainFuck arm * "and" "or" syntactic sugar * update encoding * ch23 `and` `or` * hack parse trinary for and, or * close * fixed or issue * Update CallEndNode.java * fix type issue * fixed * Adjust parseTrinary precedence vs && || * Fix arm simulation return * Formatting * Formatting * simplify rn to be always 0. * ch24 init * stacked rel * stack init * stack rel * remove parenthesis * got rid of old test case * update * upgrade eval * arm encoding bugs encodeing cset had a shift wrong eval missed using 0 for r31 * remove debug prints * force main to encode first * fix for missing main * got rid of debug prints * backwards with ch23 * simple new test cases * update test cases * enable old test * got rid of own test case * fix test11 * inline Api * inline x86_64 * inline test cases * fix stacked_r_5 * got rid of redundant rdid -1 set * Several new fuzzer addDeps/keep bugs. Fix risc/arm spill code values for passing 20 args. * Update README Move ch23_ch24 branch into ROADMAP --------- Co-authored-by: Cliff Click <cliffc@acm.org>
Diffstat (limited to 'chapter24/ROADMAP.md')
-rw-r--r--chapter24/ROADMAP.md391
1 files changed, 391 insertions, 0 deletions
diff --git a/chapter24/ROADMAP.md b/chapter24/ROADMAP.md
new file mode 100644
index 00000000..4eea9da7
--- /dev/null
+++ b/chapter24/ROADMAP.md
@@ -0,0 +1,391 @@
+
+
+## Unifying Structs and Arrays
+
+The idea is that structs have fields indexed by names, and arrays have fields
+indexed by numbers, and these ideas are compatible with each other. This idea
+has been used by the C language for a long time - an array can follow a normal
+struct C and can index it with the usual array syntax.
+
+The alternative, using a field to hold a pointer to an array, exchanges some
+flexibility for an extra indirection. The obvious flexibility allows swapping
+the array out (generally for a larger one) and this is the basis of very common
+`Vector` or `ArrayList` generic containers.
+
+
+```java
+struct str {
+ int hash; // A cache of the strings hash code
+ u32 #; // The array length
+ u8 []; // Array of bytes
+};
+
+str X = "abc";
+print(X.hash); // Read the hash field
+X[0]=='a'; // Read array element 0
+X#; // Length of the array
+
+```
+
+Here, the field named `#` holds the array length and the field named `[]` is
+the actual array, which follows the other fields directly in memory.
+Here is another example for variable length array:
+
+```java
+struct vecInt {
+ u32 size; // Actual number of elements
+ u32 #; // The array length or capacity
+ int []; // Array of integers.
+};
+```
+
+The obvious limit here is that the array cannot be directly resized; it is
+literally in the same memory block as the leading fields. Such a `vecInt` can
+be *re-allocated* to a new larger `vecInt`, but the original `vecInt` will be
+reclaimed - you cannot use the same `vecInt` reference forever.
+
+Any number of named fields are allowed:
+
+```java
+struct Class {
+ str className;
+ str professor;
+ int time;
+ int credits;
+ Class prerequisite;
+ u16 #; // Limit of 65535 students per class
+ Student [];
+};
+```
+
+Or self-reference:
+
+```java
+struct NTree {
+ Some val;
+ u8 #; // Length is 0-255
+ NTree []; // More NTrees
+};
+```
+
+The syntax rules are:
+- the last field is named `[]` and can be of any type.
+- the second-to-last field is named `#` and must be some unsigned integer type
+ representing the maximum array length.
+- may require a leading space in front of ` []`
+
+
+
+### Constructors and Arrays
+
+The allocation includes the array length, and can include a constructor:
+`new NTree{val=17;}[2];`
+
+The constructor is optional, the array length is not.
+
+Optional function for initializing arrays, allows for write-once final arrays:
+`new u8[buffer#,{ u32 idx -> buffer[idx].toUpperCase() }]`
+
+
+
+### Changing array max length
+
+An issue for large numbers of range-checked small arrays is that reserving a
+full 4 bytes for array length can substantially increase the array overhead.
+Simple allows for arrays to have smaller max lengths, although these are
+treated as a different type than arrays with different max lengths.
+
+```java
+struct x0 { u8 #; u8[]; }; // Array limited to 0-255 length
+struct x1 { u16 #; u8[]; }; // Array limited to 0-65535 length
+struct x2 { u32 #; u8[]; }; //
+struct x3 { u64 #; u8[]; }; //
+
+x0 x = "abc"; // 4 bytes total: [3, 'a', 'b', 'c']
+x1 y = "def"; // 6 bytes total: [3, 0 , 'd', 'e', 'f', 0,]; 1 pad byte to acheieve 2-byte alignment
+x = y; // ERROR, "x1 is not x0", no auto-widening
+x += y; // OK, 7 bytes total: [6, 'a', 'b', 'c', 'd', 'e', 'f']
+y += x; // OK, 8 bytes total: [6, 0 , 'd', 'e', 'f', 'a', 'b', 'c']
+
+x += "VeryLongString.... ....255_chars"; // Runtime RangeCheck
+
+// Explicit conversion to widen string
+y = "" + x;
+```
+
+
+### Two flavors of extendable arrays/strings: an extra indirection or not
+
+With an extra indirection you get e.g. Java `ArrayList` or C++ `Vector`.
+
+Without, then any call which extends the extendable array return a potentially
+new object, only growing as needed.
+
+```java
+val vec1 = new vecInt[0].add(2); // len=1, capacity=1
+val vec2 = vec1.add(3); // NEW vecInt returned, only is deleted; len=2; capacity=2;
+vec1[0]; // ERROR, vec1 has been freed by call to `vec1.add(3)`
+vec2[0]; // OK
+vec2[1]; // OK
+vec2[2]; // Runtime error, AIOOBE
+```
+
+
+## A String Implementation
+
+Default strings have names like "str", "cstr", "ustr" or such.
+
+Always unicode8 with explicit u8 manipulations. Unicode "characters" will come
+as function calls over the base implementation, probably in another string class.
+
+## Default string
+
+Efficiently growable via concantenation. Supports a variety of IO/printf functions.
+The underlying array can be shared mutable if you ask for this.
+The defaults will always be private mutable and read-only shared.
+
+```java
+struct str {
+
+ // Add a string to the string, possibly growing
+ val add = { str str ->
+ val self = this;
+ for( int i=0; i<str#; i++ )
+ self = self.add(str[i]);
+ return self;
+ };
+
+ // Add an char to the string, possibly growing
+ val add = { u8 e ->
+ if( len >= # ) return copy(# ? #*2 : 1).add(e);
+ [size++] = e;
+ return this;
+ };
+
+ // Copy 'this' to a new larger size
+ val copy = { int sz2 ->
+ val v2 = new str[sz2];
+ for( int i=0; i<len; i++ )
+ v2[i] = [i];
+ v2.len = len;
+ sys.libc.free(this); // Needs a better Mem Management solution
+ return v2;
+ };
+
+ val print { -> sys.libc.write(1/*stdout*/,[]/*array base as argument to C*/,len); return this; }
+
+ u32 len; // In-use size
+ u32 #; // Max length is 4Gig, although variants can request smaller lengths
+ u8 []; // Character data
+};
+```
+
+
+### A Final String
+
+Intended to be a **immutable** string, possibly used as a base for a **secure**
+string. This needs to be created all at once, and probably requires a
+defensive copy.
+
+```java
+struct sstr {
+ // Possible static call syntax; no references to "this"
+ val make { str str -> new sstr[str#,str.at] };
+
+ // Array contents are immutable.
+ // Still figuring out good syntax for this.
+ u8 #;
+ u8 [~]; // Middlin '~'? Makes primitive array contents *immutable* and requires constructor syntax
+};
+
+// Construction requires a function that produces the array contents.
+// Here we are defining a defensive copy over `buf`.
+sstr safe = new sstr[buf.len,{ int idx -> buf[idx]; }];
+sstr safe = sstr.make("abc"); // Defensive copy is made
+```
+
+
+### A Extendable String (aka StringBuilder or StringBuffer)
+
+This API is intended to be a drop-in for a `StringBuilder` style, and takes an
+extra indirection with each usage.
+
+```java
+struct xstr {
+ str !_str; // The extra indirection is here
+ val add = { str str -> _str = str.add2(str); };
+ val write = { int fd -> _str.write(fd); };
+};
+```
+
+### A Unicode String
+
+This API is intended to support unicode character manipulation over a plain `str`
+
+```java
+struct ustr {
+ // Assuming idx is at the start of a character, return the character
+ // as a 32b integer. Returns junk integer if not at a character start.
+ // For all ASCII strings this will amount to a simple byte load.
+ // For bytes with high order bits set, this may read 1-4 characters.
+ val at = { int idx -> ... };
+};
+// Unicode character iterator
+struct ucharator {
+// Return successive unicode character codes
+};
+```
+
+### A "C" string
+
+A zero-terminated string, but the length has to be available directly
+
+```java
+struct cstr {
+ u8 #; // length including the trailing zero
+ u8[]; // always ends in a zero byte; suitable for direct passing to C string functions
+};
+```
+
+### A "german string": a very short string that can exist in a register
+
+Length in memory is 1 byte (3 bits?) of length, then 0-7 chars; max 8 chars.
+Fits in a 64 bit register.
+
+```java
+struct gstr { // aka germanString, or blend string and register "streg"
+ u3 #; // Size is 0-7 bytes???
+ u8 []; // Up to 7 bytes
+}
+// Using inlined object (see below). All these strings are short and are
+// represented as packed integers in a 64b register.
+*gstr prize1 = "gold";
+*gstr prize2 = "silver";
+*gstr prize3 = "bronze";
+
+```
+
+### Main becomes `val main = { str[] args -> ...}`
+
+
+## Structs can be inlined
+
+Structs are normally by-reference, but can be converted to by-value by using
+the `*` operator, pronounced "contents of" (this name might be changed to
+e.g. `inline`).
+
+This is a name-space change only, you cannot take the address of the internal
+struct without entirely consuming its lifetime. No "escaping".
+
+```java
+// 2 64-bit words, no other overheads
+struct Complex { f64 x,y; val len = { ->Math.sqrt(x*x+y*y); }; };
+
+// Current Simple rules: always by-reference
+struct ByRef {
+ Complex c; // 4-byte pointer to a Complex
+};
+print(new ByRef.c.y); // Lookup requires 1 extra memory load from ref to c
+
+// New behavior: by value (inlining a struct)
+// The '*' syntax indicator can be something else, e.g. a keyword "inline"
+// I am pronouncing '*' as "contents of"
+struct ByValue {
+ *Complex c; // c is inlined, full 16 bytes into ByValue
+};
+print(new ByValue.c.y); // x,y inlined into ByValue, no extra memory load
+
+// Mixing Refs and Struct Values. Basically, a ref can be converted
+// to a value by taking the "contents of" the ref, and values cannot
+// be *converted* to a ref, although they can be copied over a ref.
+ref. c = val.c; // Error, mixing refs and values
+ref.*c = val.c; // Allowed, whole structure copy. Does not allocate, requires ref.c not-null
+val. c = ref.c; // Error, mixing refs and values
+val. c = *ref.c; // Allowed, whole structure copy
+ref. c = ref.c; // Allowed, pointer copy
+val. c = val.c; // Allowed, whole structure copy.
+val *c = val.c; // Error, cannot take "contents of" a value
+
+// Alternative syntax, to avoid the "contents of" being on LHS and field applying to being on RHS:
+ref.c = val.*c; // Assign into ref.c the "contents of" val.c
+
+// Arrays of inlined structures
+var ary = new *Complex[99]; // Array of 99 Complex objects, inlined
+
+// Calling methods has the same syntax
+ref.c.len();
+val.c.len();
+
+// Function arguments use the same typing, so can pass-by-value
+val math.sin = { *Complex c -> ... }; // Passes a complex by value
+math.sin(ref.*c); // Requires de-reference to pass by value
+math.sin(val. c); // Pass by value
+
+```
+
+
+
+## RoadMap for other chapters
+
+`&&` and `||`
+Drop `int` to `i32`.
+Drop `TypeMemPtr` to 4 bytes; using `mmap` to make heap in low 4G.
+Add optimistic pass SCCP to `opto`
+Default parser for-loop construction, or partial peel.
+ `for( init; test; next ) body`
+becomes:
+```java
+{ init; // Normal scope entry to bound lifetime of index variable
+if( !test ) { // Zero-trip count test
+ do {
+ body;
+ next;
+ } while( test ); // Exit test at loop bottom by default
+} };
+```
+
+## `&&` and `||`
+
+The logical operators && (AND) and || (OR) are short-circuiting, meaning they may skip evaluating the second condition if the first one already determines the result:
+
+- `&&` stops if the first operand is false.
+- `||` stops if the first operand is true.
+
+They are syntactic sugar—used for cleaner control flow—but they don't create new nodes in the execution model.
+
+The `&&` and `||` constructs are simple syntactic sugars that only modify the control flow and do not
+introduce new nodes.
+
+Consider this example:
+```java
+int a = 1;
+int b = 0;
+
+if(a++ || b++ ) {
+ if(b == 0 && a == 2) {
+ sys.io.p("Or");
+ }
+} else{
+ sys.io.p("And");
+}
+return 0;
+```
+- `a++` evaluates to 1 (true), so `b++` is not evaluated.
+- As a result, `b` stays 0, `a` becomes 2, and "Or" is printed.
+
+```java
+int a = 1;
+int b = 1;
+
+int x=1;
+int y=1;
+int z=0;
+
+int g = x++ && y++ && z++;
+...
+```
+Here:
+- `x++` is true (1), so it evaluates `y++`, which is also true.
+- Then it evaluates `z++`, which is false (0).
+- Since `&&` requires all conditions to be true, the final result `g` is 0.
+- All operands up to the false one are evaluated, so `x`, `y`, and `z` are all incremented.