Core S*U Implementation -- * Memory Matrix of 65536 elements [X] of 256 pages [Y] default * Each element is 64 bits. * [X]=0 axis backward compatible with Brainfuck * Independant and selectable accumulator * 65536 element stack * 65536 element heap * Multi-value operations are big endian * Default datatype is int64 * Pages can change datatype. * Axises wrap at boundary ~~[ Legend ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [PC] Program Counter [PC] [A] Current Accumulator [Z01..ZEF] [X] X axis pointer (ZF0) [Y] Y axis pointer (ZF1) [C] Memory Cursor, or just Cursor [X][Y] [D] Destination Cursor [X2][Y2] [M] Memory, Value at Memory Cursor ([X][Y]) [I] Next value from STDIN [O] Value bucket to STDOUT [F] Special Function Specifiers (ZF7) [Z] System Page (Page 255) [ZP] System Page Pointer (ZFF) [S] Stack (Page 254) [SP] Stack Pointer (ZFE) [L] Location (Memory Cursor) Stack (Page 253) [LP] Location (Memory Cursor) Stack Pointer (ZFD) [H] Heap Area (Page 252) [HP] Heap Pointer (ZFC) [LSxx] Location stack offset ~~[ System page - 65536 values, page 255 : System page is multitype ]~~~ 0000 Default Accumulator 0001 Accumulator 1 .... 00EF Accumulator 239 00F0 Current X position [X] - int16 00F1 Current Y position [Y] - int16 00F2 Current X position #2 [X2] - int16 00F3 Current Y position #2 [Y2] - int16 00F4 Current X size (High value) [XS] - int16 00F5 Current Y size (High value) [YS] - int16 00F6 Current instruction pointer (PC) [PC] - int64 00F7 Special Function Specifier [F] 00F8 Accumulator Pointer [*A] 00F9 Reserved 00FA ~ATH Accumulator [~ATH] 00FB Function Page Pointer [FP] 00FC Heap Pointer [HP] 00FD Location Stack Pointer [KP] 00FE Stack Pointer [SP] 00FF System Page Pointer [ZP] 0100 For system use .... 8000 For program use .... FFFF Reserved ~~[ Stack - 65536 values, page 254 ]~~~~~~~~~~~~~~~~~~~~~~~~~ 0000-FFFF 64k value stack area [S0000..SFFFF] (variants) ~~[ Location Stack - 65536 values, page 253 ]~~~~~~~~~~~~~~~~~~~~~~~~~~ 0000-FFFF 64K value heap area [L0000..LFFFF] ~~[ Heap - 65536 values, page 252 ]~~~~~~~~~~~~~~~~~~~~~~~~~~ 0000-FFFF 64K value heap area [H0000..HFFFF] ~~[ Data Types ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0 Data bit bucket. All operations return 0, and will not change memory or the accumulator. 1 Byte (8 bit) 2 Short Int (16 bit) 3 Char (8 bit) 4 Int (32 bit) 5 Float (32 bit) 6 Double (64 bit) 7 Long (64 bit) 8 Pointer (32-256 bit) 9 Signed Byte (8 bit) A Signed Short(16 bit) B Unicode (64 bit) C Extreme Int (256 bit) D Signed Int (32 bit) E Large float (80 bit) F Signed Long (64 bit) ~~[ Brainf*ck I compatibility ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Increment value at RAM pointer by one: [M]+1 -> [M] - Decrement [M] by one: [M]-1 -> [M] < Move RAM cursor left: [X]-1 -> [X] > Move RAM cursor right: [X]+1 -> [X] , Read a character from stdin: [I] -> [M] ' Write a character to stdout: [M] -> [O] [ Jump to matching ] if zero: if [M]=00 goto ] ] Jump to matching [ if nonzero: if [M]<>00 goto [ /Expanded Canon: If you stick with just these 8 primitives, sgrebug is entirely compatible with Brainfuck./ ~~[ Navigation primitives ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { Move memory cursor down one page: [Y]-1 -> [Y] } Move memory cursor up one page: [Y]+1 -> [Y] Z Jump to element 0 on X axis (extreme left): 00 -> [X] V Jump to page 0 on Y axis (extreme bottom): 00 -> [Y] J Jump RAM cursor left/right by the amount in accumulator: ([X]+[A]) -> [X] K Jump RAM cursor up/down by the amount in accumulator: ([Y]+[A]) -> [Y] # Push current location onto location stack: [LP]+1 -> [LP] : [C] -> [L] $ Pull current location from location stack: [L] -> [C] : [LP]-1 -> [LP] ~~[ Accumulator primitives ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ? Get value at cursor into Accumulator: [M]->[A] = Set current location to value in accumulator: [A]->[M] % Swap Accumulator and value at cursor: [A]<->[M] & Increment location by amount in accumulator: [M]+[A] -> [M] X Jump RAM cursor left/right by the amount in accumulator (signed): [X]+[A] -> [X] Y Jump RAM cursor up/down by the amount in accumulator (signed): [Y]+[A] -> [Y] ( Jump to matching ( if value at RAM cursor = Accumulator: if [M]=[A] goto ) ) Jump to matching ) if value at RAM cursor <> Accumulator: if [M]<>[A] goto ( \ Store zero in accumulator: 00 -> [A] : Store Accumulator to Memory, Move RAM cursor right one and and set accumulator to 0, equal to '=>\': [A] -> [M] : [X]+1 -> [X] : 00 -> [A] 0 No operation 1 Add 1 to value in accumulator: [A]+1 -> [A] 2 Add 2: [A]+2 -> [A] 3 Add 3: [A]+3 -> [A] 4 Add 4: [A]+4 -> [A] 5 Add 5: [A]+5 -> [A] 6 Add 6: [A]+6 -> [A] 7 Add 7: [A]+7 -> [A] 8 Add 8: [A]+8 -> [A] 9 Add 9: [A]+9 -> [A] A Add 10: [A]+10 -> [A] B Add 11: [A]+11 -> [A] C Add 12: [A]+12 -> [A] D Add 13: [A]+13 -> [A] E Add 14: [A]+14 -> [A] F Add 15: [A]+15 -> [A] . Shift left 4 bits (Multiply by 16): [A] << 4 -> [A] " Shift right 4 bits (Divide by 16): [A] >> 4 -> [A] ~ Flip sign of accumulator -[A] -> [A] ` Flip sign of memory -[M] -> [M] U Save current memory cursor, and set memory cursor to accumulator selector [LP]+1 -> [LP] : [C] -> [L] : $FF -> [Y] : $FC -> [X] (/Example Use/ U\2.0=$ / Select accumulator 32 / U+$ / Select next accumulator ) /Expanded canon: You can place arbitrary valUes into the accUmUlator. /To put 64738 into the AccUmUlator: / \ Sets the accUmUlator to 0 / F Adds 15 to A (now 15) / . Multiplies by 16 (now 240) / C adds 12 to A (252) / . times 16 (4032) / E adds 14 (4046) / . time 16 (64736) / 2 adds 2 (64738) / In hexadecimal, 0xFCE2 = 64738. This is no coincidence. ~~[ Misc primitives ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ G Call Special Function specified by accumulator or raise Exception: [A] -> ([X(F7)][Y(FF)]) : [~ATH[A] = 0 : {SpecialFunc(A)} : {Exception(~ATH[A]) & HALT} ] ~~[ I/O primitives ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ H Output value in accumulator as hex code: [A]->[TOHEX]->[O] N Output value om accumulator as type: [A]->[TOINT]->[O] R Read [A] values from STDIN and put them into Memory: [I00]..[I([A]-1)] -> [M00]..[M([A]-1)] W Write [A] values from Memory to STDOUT: [M00]..[M([A]-1)] -> [O00]..[O([A]-1)] ~~[ Memory movement ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ M Copy [A] values at Memory Cursor to Destination Cursor: [M[C]]..[M([C]+[A]-1)] -> [M[D]]..[M([D]+[A]-1)] P SwaP [A] values at Memory Cursor with values at Destination Cursor: [M[C]]..[M([C]+[A]-1)] <-> [M[D]]..[M([D]+[A]-1)] _ Set Destination Cursor to current Memory Cursor [C] -> [D] ~~[ Stack primitives ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @ Pop one value off the stack into the accumulator: [S] -> [A] : [SP]-1 -> [SP] ! Push value in accumulator onto the stack: [SP]+1 -> [SP] : [A] -> [S] * Load value at top of stack into the accumulator (without popping it off): [S] -> [A] ^ Store value in the accumulator on the top of the stack (replacing what was there): [A] -> [S] S Swap the Stack Pointer and the value at the Memory Cursor [M] <-> [SP] /[Expanded canon] / Use @= ?! *= and ?^ to turn these into Memory operations! / To pick arbitrary values off the stack, use S to do a swap of the stack pointer into the current memory location. / S--*S : Swap the SP into memory, decrement it twice, make a copy of it, then swap it back. / Now the stack item 3 down from the top will be in your accumulator. ~~[ Documentation ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ / Ignore everything after this until newline or next '/' UnUsed: TQIO ~~[ Special functions ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00 Halt with returncode stored in accumulator 01 Change current page to BYTE datatype 02 Change current page to WORD datatype (16 bit int) 03 Change current page to CHAR datatype (8 bit, but outputs as ASCII) 04 Change current page to DWORD datatype (32 bit int) 05 Change current page to FLOAT datatype (32 bit float) 06 Change current page to UNICODE datatype (Each cell can store a single unicode character) 07 Toggle signnedness of current page 3F Toggle breaking of code data boundaries 40 Execute memory at RAM cursor as DebUgScript 80 Load matrix from file (if [7F]>00 then use filename in buffer, else use matrix.bfox) 81 Dump matrix to file (if [7F]>00 then use filename in buffer, else use matrix.bfox) FE Resize the matrix, preserving as much existing data as possible. FF Kill and resize matrix, filling it with value in accumulator ~~[ Example proggy ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ / Resize matrix to 1x1, this program only requires one value of RAM 0'.8i0'0= 0'9i0'1= 0'Ai0'0= 0'Bi0'1= F'FG / Now write HELLO WORLD! / H E L L O SP W O R L D ! CR LF 4.8'4.5'4.C'4.C'4.F'2.0'5.7'4.F'5.2'4.C'4.4'2.1'0.D'0.A' / Halt 0'0ig