intecode.txt interpreter coding prototype version 1.3 Created: 2010.12.04 Revised: 2011.03.30 Corrections from 2010.12.19 release: Immediate “small” size is [-30,31] not [-60,63]. Formatted in ISO-8859-1, 60-character width window. ==== Script Text ==== Sample function ::ff(p) { p[1] + p[(2)] ##was `p.1 + p.(2)` } #[ with only a single level of optimizations == ff == 1400 mov p,X 1281 mov X[1],A 1400 mov p,X 0200 psh A 1202 mov #2,A 13C0 mov X[A],X 1000 mov -,A 7040 add X,A 0100 ret ]# String ops `+` appends copy if both are strs, otherwise adds to ptr `-` subtracts length; negative clips length (all others would currently force a number conversion) Directives, Miscelaneous Symbols #cs #ci case [in]sensitive; also, #cy, #cn #% string form :: define function -> store (follows destination) ->+ ->- add to, subtract from... '...' string (no \ needed for `"`) "..." string (no \ needed for `'`) `...` script text Comments ## end-of-line comment #[ block comment ]# Type classes. # class type-A type-B binary raw data ([bina]) executable (exec) text ISO-8859-1 (TEXT) UTF-8 (text) script raw uint16 (sobj) function (func) list/link object (lobj) stack (link) unsigned little endian (uint) big endian (Uint) signed little endian (sint) big endian (Sint) float single little endian (sing) big endian (Sing) double little endian (doub) big endian (Doub) Notes Byte orderings are 'native' unless specified. Integers are 32-bit by default unless specified. ==== Code Prototype (Binary) ==== 2010.12.01-05 The code is now officially in 16-bit words. This time the cause was less about code size and more abt. covering all of the addressing modes needed for fast text parsing for script binaries. An advantage with this code type is that there is always a displacement/immediate value; fewer addition instrucions are needed for some routines. And instead of reading an 8-octet (byte) string for doubles, four 16-bit words can be read, so long as the byte order is correct, maintained. Objects uint32 what [name.24] [ismalloc.1] [sizelock.1] [datalock.1] [typelock.1] [type.4] ## see "classes" above uint32 [isptr.1] [size.31] data: uint8[8] ptr: uint8*, int32 offs Registers F: frame; parameter end (in size), start, pending I: instruction pointer A: accumulator; result X: auxiliary Opcode bits oooooaar ccxxxxxx o = operation r = register; 0=A, 1=X; usually the destination a = addressing mode source c = complex mode bits x = value starting bits addressing modes (a) n form kind 0 - pop (S) 1 #xxx register (X) 2 ^xxx | name parameter (S) 3 *xxx relative (I) complex modes (c) 0 none 1 X, register/excessed 2 X[] displaced 3 X[A,] indexed Value (xxx): Immediates (imm) and Relatives (rel) 10 0001: half size; 1 (int) or 2 (num) more words 10 0000: full size; 2 (int) or 4 (num) more words otherwise, small integers [-30,31]. 2/4 bytes integer, sign extended 4/8 bytes double; zero ext. Parameter mode note: Negatives point to the frame's param end for direct access to the current function's stack. Line-zero codes hex abbr description 00 lax load/pull A/X 01 ret return; pulls I/F 02 psh push -- 05 does relative 06 bra branch/jump (regardless of A) 07 bza branch/jump if zero A 08 ulk unlink; pulls, exch. A/X, resets F pending 0A lnk link; pushes reg, inits F pending 0C mov move, store context (reversed-order params) Operation table hi dec abbr desc. unary 10 2 mov move, load context 18 3 sqr square root 20 4 abs absolute value 28 5 neg negate 30 6 not bin. not (uint) 38 7 bno bool not (uint) dyadic 40 8 ban bool and (uint) 48 9 bor bool or (uint) 50 10 and bin. and (uint) 58 11 ior bin. or (uint) 60 12 eor exclusive-or (uint) 68 13 asr arithmetic shift right (sint) 70 14 shr shift right 78 15 shl shift left 80 16 add add or append 88 17 sub subtract or reduce/clip 90 18 mcl multiply or call (push I/F, set I/F) 98 19 pow raise to power A0 20 div divide A8 21 dvs divide signed (sint) B0 22 mod modulus B8 23 mds modulus signed (sint) C0 24 clt compare less than C8 25 cge .. greater or equal D0 26 cgt .. greater D8 27 cle .. lesser or equal E0 28 ceq .. equal E8 29 cne .. not equal F0 30 cid .. identical data F8 31 cni .. not identical data Calling method The multiply operation doubles as the call function. 9840 mcl X,A ; call if X is a func, else multiply 9E... mcl foo,A ; foo is relative to an object Normal use with parameters 0A00 lnk A ; link A/F ... ; parameters 9E... mcl foo,A ; call foo 0800 ulk A ; unlink A/F Mnemonics 1000 mov -,A ; pla (pull A) 1140 mov X,X ; nop (no-operation) 5200 ior #0 ; uin (zero extension) 6200 asr #0 ; sin (sign extension) 7200 add #0 ; ref (force reference) 8200 sub #0 ; (slower no-op) Character encodings ISO-8859-1's characters from C0-FF, except for D7 (times) and F7 (divide), are all Latin letters 3140 not X (¬) EOF e32s1m95 floating point type (128 bits) int32 exp [sgn.1] [man.95]