0 Members and 1 Guest are viewing this topic.
*[]byte x; // pointer to array of bytes[]*byte y; // array of pointers to bytebyte b;x[i] = b; // short for x*[i] = b;y[i] = b; // short for y[i] = &b;y[i]* = b; // no shorthandb = x[i]; // short for b = x*[i];b = y[i]; // short for b = y[i]*;
for { ... }for(test) { ... }for(init; test; next) { ... }for(var : a, b) { ... }for(var : a, b, i) { ... }for(var : arr) { ... }for(num) { ... }
while(c) { ... } // loop while c is trueuntil(c) { ... } // loop until c is truedo { ... } while(c); // do ... and then repeat while c is truedo { ... } until(c); // do ... and then repeat until c is truedo { ... } // do "forever" (useful)for(init; test; update) { ... } // C++/Java/C# "for"for(var, start, end, inc) { ... } // BASIC "for" (optional "inc")for(var : array) { ... } // "foreach" (probably added in later); possibly also// work with funcs/cofuncs where the last of the return-values is a bool
// "A" (a large chunk of code) is duplicated to do this:A;while(C) { B; A;}// My solution (just as it reads, i.e. begin at label "start"):do(start) { B;start: A;} while(C); // ...but repeat the WHOLE loop "while C" is true// A common solution (but requiring "loop manipulation"):do { A; if(!C){break;} B; } // !C is evil
foo: while(...) { bar: while(...) { while(...) { break; // break from the innermost loop (or switch) continue; // continue the innermost loop (or switch) break foo; // break from the "foo" loop (or switch) continue bar; // continue (skip to next iteration of) the "bar" loop (or switch) } }}
func Foo(byte a, b=2, char x='Y', y='Z') { ... }Foo(1,2,'a','b'); // Normal usageFoo(1,2,'a'); // Short for Foo(1,2,'a','Z');Foo(1,2); // Short for Foo(1,2,'Y','Z');Foo(1); // Short for Foo(1,2,'Y','Z');
each(a,b,c) = x; // Instead of (a=b=c=x;)each(a,b,c),d = x,y; // Instead of (a=b=c=x; d=y;) or (a,_ = b,_ = c,d = x,y;)
struct Foo { func Bar(...) { ... } } // declared internallyfunc Foo.Bar(...) { ... } // declared externally
word cursor@"curcol"; // cursor will refer to "currow" in the assembly code.byte curCo1@cursor; // curCol now refers to the leading byte of cursorbyte curRow@cursor+1; // refers to the trailing byte of cursor. WE CAN DISCUSS THIS SYNTAXfunc() f@"routine"; // f() now calls an assembly routine directly// Embedding variables within an array:values := [6]byte{0,1,2,3,4,5};byte a@values[2]; // a is literally stored at value[2]byte b@values[3]; // b is literally stored at value[3]a = 1; // values[2] is now 1;values[3] = 2; // b is now 2;// More compact way of embedding variables in an array can be one of these:values := [6]byte{0, 1, a=2, b=3, 4};values := [6]byte{0, 1, a@2, b@3, 4};
func(byte a, b):byte // Takes two bytes (a and b) and returns a bytefunc(byte a, b):(byte,byte) // ...Returns TWO bytesfunc():char // Takes nothing, returns a char
func(A, func(B : C) : func( : func())) // Old "inner" setupfunc(A, func(B) : C) : func() : func() // New "outer" setup// A simpler example (can you tell what it does by looking?):func( : func( : func(A : B))) // Old "inner" setupfunc() : func() : func(A) : B // New "outer" setup
byte a, b = c, d; // same as: byte a, (b = c), d;byte (a, b) = (c, d); // same as: byte a = c, b = d;byte a = (((b))); // same as: byte a = b; (as expected)(a,b,c) = ((x,y),z); // same as: (a,b,c) = (x,y,z)(a,b) = ((x,y),z); // INCORRECT: (x,y) is still TWO items
byte a = 5, b = a+7;if(a+b < 15) { doA(); }else { doB(); }while(a < 100) { a += a; }$while(b < 100) { b += b; }return $(a+b);// The compiler precomputes that code, resulting in THIS code:byte a = 5; // b = 12, but is never DIRECTLY needed, so it is removeddoB(); // 5+12 is clearly not less than 15while(a < 100) { a += a; } // The compiler leaves loop alone,// ... unless TOLD ($) to: b=12+12 ...24+24 ...96+96 ... b is 192return $(a+192); // ERROR! (value of a is unknown; cannot evaluate)
// Current setup:[]byte // Points to a byte-array[5]byte // IS a (static) byte-array (5 values)[_]byte // Same as above, but size is determined from usage*[5]byte // Same as []byte, but requires/assumes the underlying array is 5 bytes[5][5]byte // An array of five [5]byte values (no pointers!)[5][]byte // (static) Array of five []byte values (five pointers)[][5]byte // Points to an array of five [5]byte values[][]byte // Points to an array of pointers to arrays
// Hypothetical way to embed size-information:[byte]byte // A (static) byte-array, prefixed by a byte to store the size[word]byte // A (static) byte-array, prefixed by a word to store the size*[byte]byte // Pointer to such an array
[]byte // Array of (some determinable number of) bytes (previously indicated as [_]byte)[5]byte // Array of 5 bytes[byte]byte // Array of bytes (prefixed with a byte to indicate the size)*[]byte // Pointer to an array of bytes*[5]byte // Pointer to an array of 5 bytes*[byte]byte // Pointer to a (byte-) size-prefixed array of bytes[][]byte // Array of *[]byte values.[5][5]byte // Array of five *[5]byte values.[5,5]byte // Array of five [5]byte values (no pointers)[5][5,5]byte // Array of five *[5,5]byte values[5,5,5,5]byte // A 4-Dimensional array of bytes (no pointers)[5,5][5,5]byte // 2D array of pointers to [5,5]byte values
[,]byte // Static 2D array (NOTE: the sizes have to be determinable!)*[,]byte // ERROR! (cannot even COMPUTE where [d,e] is without the inner dimension)*[,5]byte // Pointer to a [?,5]byte (ok: [d,e] is [5*d+e])*[,byte]byte // (also ok, since [d,e] is [SIZE*d+e], and size is stored as a leading byte)*[byte,]byte // ERROR! (It's the inner dimension that matters)*[5,5]byte // Pointer to a [5,5]byte -- Very ok
[3,4,5]byte arr;*[3,4,5]byte p3 = &arr; // p3[d,e,f] refers to arr[d,e,f]*[,5]byte p2 = &arr; // treat arr as a [12,5]byte (e.g. p2[4*d + e, f])*[]byte p1 = &arr; // treat arr as a [60]byte (e.g. p1[5*4*d + 5*e + f])// I'd like NOT to allow this:arr[d] // gives the dth [4,5]byte valuearr[d,e] // gives the [d,e]th [5]byte value// ... because it means that arr[d][e][f] is the same as arr[d,e,f]