User:Zarutian/Smallcaps

Notes of what I have gleaned from the incomplete spefication and implementation of Smallcaps.

Smallcaps is a bytecode based format of executable code.

The opcodes are:

Hex Memnomic        Effects/Description 0x01 OP_DUP          [x],[] => OP_DUP => [x, x],[] 0x02 OP_POP          [x],[] => OP_POP => [],[] 0x03 OP_SWAP         [x, y],[] => OP_SWAP => [y, x],[] 0x04 OP_ROT          [x, y, z],[] => OP_ROT => [y, z, x],[] 0x05 OP_RETURN       [x],[] => OP_RETURN 0x08 OP_JUMP         [],[] => OP_JUMP(label) => [],[] label := ?Waterken Wholenum? 0x09 OP_BRANCH       [ootEjector, flag],[] => OP_BRANCH => [],[] 0x0A OP_CALL_ONLY    [recip, args...],[] => OP_CALL_ONLY(verb, arity) => [],[] 0x0B OP_CALL         [recip, args...],[] => OP_CALL(verb, arity) => [result],[] verb := ?Waterken UTF8 string? arity := ?Waterken Wholenum? 0x0E OP_EJECTOR_ONLY [],[] => OP_EJECTOR_ONLY(label) => [ejector],[handler] when ejector is invoked: [...],[...] => ejector(_) => [],[] 0x0F OP_EJECTOR      [],[] => OP_EJECTOR(label) => [ejector],[handler] when ejector is invoked: [...],[...] => ejector(result) => [result],[] 0x10 OP_TRY          [],[] => OP_TRY(label) => [],[handler] when handler is invoked: [...],[...] => handler(arg) => [arg],[] when handler is dropped: [...],[...] => handler.drop(_) => [...],[...] 0x11 OP_UNWIND       [],[] => OP_UNWIND(label) => [],[handler] when handler is invoked: [...],[...] => handler(arg) => [rethrower(arg)],[] when handler is dropped: [...],[...] => handler.drop(pc) => [returner(pc)],[] 0x12 OP_END_HANDLER  [],[handler] => OP_END_HANDLER => [],[] 0x16 OP_WHOLE_NUM    [],[] => OP_WHOLE_NUM(wholeNum) => [wholeNum],[] 0x17 OP_NEG_INT      [],[] => OP_NEG_INT(wholeNum) => [-wholeNum],[] 0x18 OP_FLOAT64      [],[] => OP_FLOAT64(float64) => [float64],[] 0x19 OP_CHAR         [],[] => OP_CHAR(chr) => [chr],[] 0x1A OP_STRING       [],[] => OP_STRING(str) => [str],[] 0x1B OP_TWINE        [],[] => OP_TWINE(twine) => [twine],[] 0x1C OP_TRUE         [],[] => OP_TRUE => [true],[] 0x1D OP_FALSE        [],[] => OP_FALSE => [false],[] 0x1E OP_NULL         [],[] => OP_NULL => [null],[] 0x1F OP_SCOPE        [],[] => OP_SCOPE => [scope],[] 0x20 OP_OBJECT       [ivars..., auditors...],[] => OP_OBJECT(wholeNum numOfFields, wholeNum scriptIndex) => [object],[] metanote: hypothesis: OP_OBJECT takes these immitiate args: wholenum of ivarAuditorpairs to pop of the stack some sort of reference to code that handles calls and sends to the object 0x21 OP_LIST_PATT    [optEjector, specimen],[] => OP_LIST_PATT(n) => [optEjector, specimen[n-1]..., optEjector, specimen[0]] metanote: is n a wholenum? 0x22 OP_CDR_PATT 0x28 OP_NOUN +addrMode 0x30 OP_SLOT +addrMode 0x38 OP_ASSIGN +addrMode 0x40 OP_BIND +addrMode 0x48 OP_BIND_SLOT +addrMode

dash pointed me to http://bazaar.launchpad.net/~washort/ecru/trunk/annotate/head:/doc/smallcaps.txt which is also a bit stale and to http://bazaar.launchpad.net/~washort/ecru/trunk/annotate/head:/esrc/com/twistedmatrix/ecru/compiler.emaker

http://bazaar.launchpad.net/~washort/ecru/trunk/annotate/head%3A/src/vm.c

See also http://epan.cvs.sourceforge.net/viewvc/epan/epan/lib/smallcaps/org/erights/e/elang/smallcaps/SmallcapsEncoder.java?view=markup

And http://epan.cvs.sourceforge.net/viewvc/epan/epan/lib/smallcaps/org/erights/e/elang/smallcaps/SmallcapsOps.java?view=markup

# A Tcl procedure that decodes smallcaps bytecode stream proc decode_smallcaps {input} { set output [list] set op [read_byte] switch -exact -- $op { "\x01" { lappend output [list OP_DUP] } "\x02" { lappend output [list OP_POP] } "\x03" { lappend output [list OP_SWAP] } "\x04" { lappend output [list OP_ROT] } "\x05" { lappend output [list [list OP_UNDERDUP OP_RETURN]] } "\x06" { lappend output [list [list OP_RETURN {}]] } "\x07" { lappend output [list unused_bytecode 1] } "\x08" { lappend output [list OP_JUMP [read_wholeNum]] } "\x09" { lappend output [list OP_BRANCH] } "\x0a" { lappend output [list OP_CALL_ONLY [read_string] [read_wholeNum]] } "\x0b" { lappend output [list OP_CALL [read_string] [read_wholeNum]] } "\x0c" { lappend output [list OP_SEND_ONLY [read_string] [read_wholeNum]] } "\x0d" { lappend output [list OP_SEND [read_string] [read_wholeNum]] } "\x0e" { lappend output [list OP_EJECTOR_ONLY [read_wholeNum]] } "\x0f" { lappend output [list OP_EJECTOR [read_wholeNum]] } "\x10" { lappend output [list OP_TRY [read_wholeNum]] } "\x11" { lappend output [list OP_UNWIND [read_wholeNum]] } "\x12" { lappend output [list OP_ENDHANDLER] } "\x13" { lappend output [list unused_bytecode 2] } "\x14" { lappend output [list unused_bytecode 3] } "\x15" { lappend output [list unused_bytecode 4] } "\x16" { lappend output [list OP_WHOLENUM [read_wholeNum]] } "\x17" { lappend output [list OP_NEG_INT [read_wholeNum]] } "\x18" { lappend output [list OP_FLOAT64 [read_float64]] } "\x19" { lappend output [list OP_CHAR [read_char]] } "\x1a" { lappend output [list OP_STRING [read_string]] } "\x1b" { lappend output [list OP_TWINE ???unknown_arity???]] } "\x1c" { lappend output [list OP_TRUE]] } "\x1d" { lappend output [list OP_FALSE]] } "\x1e" { lappend output [list OP_NULL]] } "\x1f" { lappend output [list OP_SCOPE]] } "\x20" { lappend output [list OP_OBJECT [read_wholeNum] [read_wholeNum]] } "\x21" { lappend output [list OP_LIST_PATT [read_wholeNum]] } "\x22" { lappend output [list OP_LIST_PATT_ONLY [read_wholeNum]] } "\x23" { lappend output [list OP_CDR_PATT [read_wholeNum]] } "\x24" { lappend output [list OP_CDR_PATT_ONLY [read_wholeNum]] } "\x25" { lappend output [list unused_bytecode 5]] } "\x26" { lappend output [list unused_bytecode 6]] } "\x27" { lappend output [list unused_bytecide 7]] } }

return $output }