From d6a9ca91fa7af0848b4502fd6008a229f38bb079 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 1 Jul 2015 07:21:54 +0000 Subject: [PATCH] added JUMP2_FORWARD and JUMP2_BACKWARD --- stix/lib/comp.c | 40 +++-- stix/lib/exec.c | 93 +++++++++-- stix/lib/stix-prv.h | 208 ++++++++++++------------ stix/lib/test-005.st | 372 +------------------------------------------ 4 files changed, 209 insertions(+), 504 deletions(-) diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 1613995..8c80e23 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -1499,7 +1499,6 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para case BCODE_JUMP_BACKWARD_0: case BCODE_JUMP_IF_TRUE_0: case BCODE_JUMP_IF_FALSE_0: - case BCODE_JUMP_BY_OFFSET_0: if (param_1 < 4) { bc = (stix_byte_t)(cmd & 0xFC) | (stix_byte_t)param_1; @@ -1511,6 +1510,11 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para bc = cmd | 0x80; goto write_long; } + + case BCODE_JUMP2_FORWARD: + case BCODE_JUMP2_BACKWARD: + bc = cmd; + goto write_long; } stix->errnum = STIX_EINVAL; @@ -2503,21 +2507,35 @@ printf ("\treturn_from_block\n"); } block_code_size = stix->c->mth.code.len - jump_inst_pos - (STIX_BCODE_LONG_PARAM_SIZE + 1); - if (block_code_size > MAX_CODE_BLKCODE) + if (block_code_size > MAX_CODE_JUMP * 2) { -/* TOOD: increate the max block code size and - * if it exceedes the limit for BCODE_JUMP_FORWARD_X, switch to BECODE_JUMP_BY_OFFSET */ set_syntax_error (stix, STIX_SYNERR_BLKFLOOD, &block_loc, STIX_NULL); return -1; } + else + { + stix_size_t jump_offset; - /* note that the jump offset is a signed number */ -#if (STIX_BCODE_LONG_PARAM_SIZE == 2) - stix->c->mth.code.ptr[jump_inst_pos + 1] = block_code_size >> 8; - stix->c->mth.code.ptr[jump_inst_pos + 2] = ((stix_int16_t)block_code_size & 0xFF); -#else - stix->c->mth.code.ptr[jump_inst_pos + 1] = block_code_size ; -#endif + if (block_code_size > MAX_CODE_JUMP) + { +printf ("\tfixed jump to jump2\n"); + stix->c->mth.code.ptr[jump_inst_pos] = BCODE_JUMP2_FORWARD; + jump_offset = block_code_size - MAX_CODE_JUMP; + } + else + { + jump_offset = block_code_size; + } + +printf ("\tfixed jump offset to %u\n", (unsigned int)jump_offset); + + #if (STIX_BCODE_LONG_PARAM_SIZE == 2) + stix->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset >> 8; + stix->c->mth.code.ptr[jump_inst_pos + 2] = jump_offset & 0xFF; + #else + stix->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset; + #endif + } /* restore the temporary count */ stix->c->mth.tmprs.len = saved_tmprs_len; diff --git a/stix/lib/exec.c b/stix/lib/exec.c index f8809f4..450ce4b 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -728,6 +728,58 @@ static int primitive_integer_sub (stix_t* stix, stix_ooi_t nargs) return 0; } +static int primitive_integer_mul (stix_t* stix, stix_ooi_t nargs) +{ + stix_ooi_t tmp; + stix_oop_t rcv, arg; + + STIX_ASSERT (nargs == 1); + + rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + arg = ACTIVE_STACK_GET(stix, stix->sp); + + if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg)) + { + tmp = STIX_OOP_TO_SMINT(rcv) * STIX_OOP_TO_SMINT(arg); + /* TODO: check overflow. if so convert it to LargeInteger */ + + ACTIVE_STACK_POP (stix); + ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(tmp)); + return 1; + } + +/* TODO: handle LargeInteger */ + return 0; +} + +static int primitive_integer_eq (stix_t* stix, stix_ooi_t nargs) +{ + stix_oop_t rcv, arg; + + STIX_ASSERT (nargs == 1); + + rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + arg = ACTIVE_STACK_GET(stix, stix->sp); + + if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg)) + { + ACTIVE_STACK_POP (stix); + if (STIX_OOP_TO_SMINT(rcv) < STIX_OOP_TO_SMINT(arg)) + { + ACTIVE_STACK_SETTOP (stix, stix->_true); + } + else + { + ACTIVE_STACK_SETTOP (stix, stix->_false); + } + + return 1; + } + +/* TODO: handle LargeInteger */ + return 0; +} + static int primitive_integer_lt (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; @@ -796,17 +848,19 @@ typedef struct primitive_t primitive_t; static primitive_t primitives[] = { - { -1, primitive_dump }, - { 0, primitive_new }, - { 1, primitive_new_with_size }, - { 0, primitive_basic_size }, - { 1, primitive_basic_at }, - { 2, primitive_basic_at_put }, - { -1, primitive_block_context_value }, - { 1, primitive_integer_add }, - { 1, primitive_integer_sub }, - { 1, primitive_integer_lt }, - { 1, primitive_integer_gt } + { -1, primitive_dump }, /* 0 */ + { 0, primitive_new }, /* 1 */ + { 1, primitive_new_with_size }, /* 2 */ + { 0, primitive_basic_size }, /* 3 */ + { 1, primitive_basic_at }, /* 4 */ + { 2, primitive_basic_at_put }, /* 5 */ + { -1, primitive_block_context_value }, /* 6 */ + { 1, primitive_integer_add }, /* 7 */ + { 1, primitive_integer_sub }, /* 8 */ + { 1, primitive_integer_mul }, /* 9 */ + { 1, primitive_integer_eq }, /* 10 */ + { 1, primitive_integer_lt }, /* 11 */ + { 1, primitive_integer_gt } /* 12 */ }; @@ -1127,7 +1181,6 @@ printf ("JUMP_BACKWARD %d\n", (int)(bcode & 0x3)); case BCODE_JUMP_IF_TRUE_X: case BCODE_JUMP_IF_FALSE_X: - case BCODE_JUMP_BY_OFFSET_X: case BCODE_JUMP_IF_TRUE_0: case BCODE_JUMP_IF_TRUE_1: case BCODE_JUMP_IF_TRUE_2: @@ -1136,13 +1189,21 @@ printf ("JUMP_BACKWARD %d\n", (int)(bcode & 0x3)); case BCODE_JUMP_IF_FALSE_1: case BCODE_JUMP_IF_FALSE_2: case BCODE_JUMP_IF_FALSE_3: - case BCODE_JUMP_BY_OFFSET_0: - case BCODE_JUMP_BY_OFFSET_1: - case BCODE_JUMP_BY_OFFSET_2: - case BCODE_JUMP_BY_OFFSET_3: printf ("<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>> \n"); stix->errnum = STIX_ENOIMPL; return -1; + + case BCODE_JUMP2_FORWARD: + FETCH_PARAM_CODE_TO (stix, b1); +printf ("JUMP2_FORWARD %d\n", (int)b1); + stix->ip += MAX_CODE_JUMP + b1; + break; + break; + + case BCODE_JUMP2_BACKWARD: + FETCH_PARAM_CODE_TO (stix, b1); +printf ("JUMP2_BACKWARD %d\n", (int)b1); + stix->ip -= MAX_CODE_JUMP + b1; break; /* -------------------------------------------------------- */ diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 35b4107..2b2ad48 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -43,7 +43,6 @@ #define STIX_DEBUG_GC_001 - #include /* TODO: delete these header inclusion lines */ #include #include @@ -477,7 +476,7 @@ struct stix_compiler_t # define MAX_CODE_NBLKARGS (0xFFu) # define MAX_CODE_NBLKTMPRS (0xFFu) # define MAX_CODE_PRIMNO (0xFFFFu) -# define MAX_CODE_JUMP (0xFF) +# define MAX_CODE_JUMP (0xFFu) #elif defined(STIX_BCODE_LONG_PARAM_SIZE) && (STIX_BCODE_LONG_PARAM_SIZE == 2) # define MAX_CODE_INDEX (0xFFFFu) # define MAX_CODE_NTMPRS (0xFFFFu) @@ -485,14 +484,11 @@ struct stix_compiler_t # define MAX_CODE_NBLKARGS (0xFFFFu) # define MAX_CODE_NBLKTMPRS (0xFFFFu) # define MAX_CODE_PRIMNO (0xFFFFu) -# define MAX_CODE_JUMP (0xFFFF) +# define MAX_CODE_JUMP (0xFFFFu) #else # error Unsupported STIX_BCODE_LONG_PARAM_SIZE #endif -#define MAX_CODE_BLKCODE MAX_CODE_JUMP - - /* ---------------------------------------------------------------------------------------------------------------- @@ -527,8 +523,8 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C 72-75 0100 10XX JUMP_BACKWARD 200 1100 1000 XXXXXXXX JUMP_BACKWARD_X 76-79 0100 11XX JUMP_IF_TRUE 204 1100 1100 XXXXXXXX JUMP_IF_TRUE_X 80-83 0101 00XX JUMP_IF_FALSE 208 1101 0000 XXXXXXXX JUMP_IF_FALSE_X -84-87 0101 01XX JUMP_BY_OFFSET 212 1101 0100 XXXXXXXX JUMP_BY_OFFSET_X -# for JUMP_BY_OFFSET, XX is an index to literal frame pointing to a small integer. + +84-87 0101 01XX UNUSED vv 88-91 0101 10XX YYYYYYYY STORE_INTO_CTXTEMPVAR 216 1101 1000 XXXXXXXX YYYYYYYY STORE_INTO_CTXTEMPVAR_X (bit 3 on, bit 2 off) @@ -557,117 +553,114 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C enum stix_bcode_t { - BCODE_STORE_INTO_INSTVAR_0 = 0x00, - BCODE_STORE_INTO_INSTVAR_1 = 0x01, - BCODE_STORE_INTO_INSTVAR_2 = 0x02, - BCODE_STORE_INTO_INSTVAR_3 = 0x03, + BCODE_STORE_INTO_INSTVAR_0 = 0x00, + BCODE_STORE_INTO_INSTVAR_1 = 0x01, + BCODE_STORE_INTO_INSTVAR_2 = 0x02, + BCODE_STORE_INTO_INSTVAR_3 = 0x03, - BCODE_STORE_INTO_INSTVAR_4 = 0x04, - BCODE_STORE_INTO_INSTVAR_5 = 0x05, - BCODE_STORE_INTO_INSTVAR_6 = 0x06, - BCODE_STORE_INTO_INSTVAR_7 = 0x07, + BCODE_STORE_INTO_INSTVAR_4 = 0x04, + BCODE_STORE_INTO_INSTVAR_5 = 0x05, + BCODE_STORE_INTO_INSTVAR_6 = 0x06, + BCODE_STORE_INTO_INSTVAR_7 = 0x07, - BCODE_POP_INTO_INSTVAR_0 = 0x08, - BCODE_POP_INTO_INSTVAR_1 = 0x09, - BCODE_POP_INTO_INSTVAR_2 = 0x0A, - BCODE_POP_INTO_INSTVAR_3 = 0x0B, + BCODE_POP_INTO_INSTVAR_0 = 0x08, + BCODE_POP_INTO_INSTVAR_1 = 0x09, + BCODE_POP_INTO_INSTVAR_2 = 0x0A, + BCODE_POP_INTO_INSTVAR_3 = 0x0B, - BCODE_POP_INTO_INSTVAR_4 = 0x0C, - BCODE_POP_INTO_INSTVAR_5 = 0x0D, - BCODE_POP_INTO_INSTVAR_6 = 0x0E, - BCODE_POP_INTO_INSTVAR_7 = 0x0F, + BCODE_POP_INTO_INSTVAR_4 = 0x0C, + BCODE_POP_INTO_INSTVAR_5 = 0x0D, + BCODE_POP_INTO_INSTVAR_6 = 0x0E, + BCODE_POP_INTO_INSTVAR_7 = 0x0F, - BCODE_PUSH_INSTVAR_0 = 0x10, - BCODE_PUSH_INSTVAR_1 = 0x11, - BCODE_PUSH_INSTVAR_2 = 0x12, - BCODE_PUSH_INSTVAR_3 = 0x13, + BCODE_PUSH_INSTVAR_0 = 0x10, + BCODE_PUSH_INSTVAR_1 = 0x11, + BCODE_PUSH_INSTVAR_2 = 0x12, + BCODE_PUSH_INSTVAR_3 = 0x13, - BCODE_PUSH_INSTVAR_4 = 0x14, - BCODE_PUSH_INSTVAR_5 = 0x15, - BCODE_PUSH_INSTVAR_6 = 0x16, - BCODE_PUSH_INSTVAR_7 = 0x17, + BCODE_PUSH_INSTVAR_4 = 0x14, + BCODE_PUSH_INSTVAR_5 = 0x15, + BCODE_PUSH_INSTVAR_6 = 0x16, + BCODE_PUSH_INSTVAR_7 = 0x17, - BCODE_PUSH_TEMPVAR_0 = 0x18, - BCODE_PUSH_TEMPVAR_1 = 0x19, - BCODE_PUSH_TEMPVAR_2 = 0x1A, - BCODE_PUSH_TEMPVAR_3 = 0x1B, + BCODE_PUSH_TEMPVAR_0 = 0x18, + BCODE_PUSH_TEMPVAR_1 = 0x19, + BCODE_PUSH_TEMPVAR_2 = 0x1A, + BCODE_PUSH_TEMPVAR_3 = 0x1B, - BCODE_PUSH_TEMPVAR_4 = 0x1C, - BCODE_PUSH_TEMPVAR_5 = 0x1D, - BCODE_PUSH_TEMPVAR_6 = 0x1E, - BCODE_PUSH_TEMPVAR_7 = 0x1F, + BCODE_PUSH_TEMPVAR_4 = 0x1C, + BCODE_PUSH_TEMPVAR_5 = 0x1D, + BCODE_PUSH_TEMPVAR_6 = 0x1E, + BCODE_PUSH_TEMPVAR_7 = 0x1F, - BCODE_STORE_INTO_TEMPVAR_0 = 0x20, - BCODE_STORE_INTO_TEMPVAR_1 = 0x21, - BCODE_STORE_INTO_TEMPVAR_2 = 0x22, - BCODE_STORE_INTO_TEMPVAR_3 = 0x23, + BCODE_STORE_INTO_TEMPVAR_0 = 0x20, + BCODE_STORE_INTO_TEMPVAR_1 = 0x21, + BCODE_STORE_INTO_TEMPVAR_2 = 0x22, + BCODE_STORE_INTO_TEMPVAR_3 = 0x23, - BCODE_STORE_INTO_TEMPVAR_4 = 0x24, - BCODE_STORE_INTO_TEMPVAR_5 = 0x25, - BCODE_STORE_INTO_TEMPVAR_6 = 0x26, - BCODE_STORE_INTO_TEMPVAR_7 = 0x27, + BCODE_STORE_INTO_TEMPVAR_4 = 0x24, + BCODE_STORE_INTO_TEMPVAR_5 = 0x25, + BCODE_STORE_INTO_TEMPVAR_6 = 0x26, + BCODE_STORE_INTO_TEMPVAR_7 = 0x27, - BCODE_POP_INTO_TEMPVAR_0 = 0x28, - BCODE_POP_INTO_TEMPVAR_1 = 0x29, - BCODE_POP_INTO_TEMPVAR_2 = 0x2A, - BCODE_POP_INTO_TEMPVAR_3 = 0x2B, + BCODE_POP_INTO_TEMPVAR_0 = 0x28, + BCODE_POP_INTO_TEMPVAR_1 = 0x29, + BCODE_POP_INTO_TEMPVAR_2 = 0x2A, + BCODE_POP_INTO_TEMPVAR_3 = 0x2B, - BCODE_POP_INTO_TEMPVAR_4 = 0x2C, - BCODE_POP_INTO_TEMPVAR_5 = 0x2D, - BCODE_POP_INTO_TEMPVAR_6 = 0x2E, - BCODE_POP_INTO_TEMPVAR_7 = 0x2F, + BCODE_POP_INTO_TEMPVAR_4 = 0x2C, + BCODE_POP_INTO_TEMPVAR_5 = 0x2D, + BCODE_POP_INTO_TEMPVAR_6 = 0x2E, + BCODE_POP_INTO_TEMPVAR_7 = 0x2F, - BCODE_PUSH_LITERAL_0 = 0x30, - BCODE_PUSH_LITERAL_1 = 0x31, - BCODE_PUSH_LITERAL_2 = 0x32, - BCODE_PUSH_LITERAL_3 = 0x33, + BCODE_PUSH_LITERAL_0 = 0x30, + BCODE_PUSH_LITERAL_1 = 0x31, + BCODE_PUSH_LITERAL_2 = 0x32, + BCODE_PUSH_LITERAL_3 = 0x33, - BCODE_PUSH_LITERAL_4 = 0x34, - BCODE_PUSH_LITERAL_5 = 0x35, - BCODE_PUSH_LITERAL_6 = 0x36, - BCODE_PUSH_LITERAL_7 = 0x37, + BCODE_PUSH_LITERAL_4 = 0x34, + BCODE_PUSH_LITERAL_5 = 0x35, + BCODE_PUSH_LITERAL_6 = 0x36, + BCODE_PUSH_LITERAL_7 = 0x37, /* -------------------------------------- */ - BCODE_STORE_INTO_OBJECT_0 = 0x38, - BCODE_STORE_INTO_OBJECT_1 = 0x39, - BCODE_STORE_INTO_OBJECT_2 = 0x3A, - BCODE_STORE_INTO_OBJECT_3 = 0x3B, + BCODE_STORE_INTO_OBJECT_0 = 0x38, + BCODE_STORE_INTO_OBJECT_1 = 0x39, + BCODE_STORE_INTO_OBJECT_2 = 0x3A, + BCODE_STORE_INTO_OBJECT_3 = 0x3B, - BCODE_POP_INTO_OBJECT_0 = 0x3C, - BCODE_POP_INTO_OBJECT_1 = 0x3D, - BCODE_POP_INTO_OBJECT_2 = 0x3E, - BCODE_POP_INTO_OBJECT_3 = 0x3F, + BCODE_POP_INTO_OBJECT_0 = 0x3C, + BCODE_POP_INTO_OBJECT_1 = 0x3D, + BCODE_POP_INTO_OBJECT_2 = 0x3E, + BCODE_POP_INTO_OBJECT_3 = 0x3F, - BCODE_PUSH_OBJECT_0 = 0x40, - BCODE_PUSH_OBJECT_1 = 0x41, - BCODE_PUSH_OBJECT_2 = 0x42, - BCODE_PUSH_OBJECT_3 = 0x43, + BCODE_PUSH_OBJECT_0 = 0x40, + BCODE_PUSH_OBJECT_1 = 0x41, + BCODE_PUSH_OBJECT_2 = 0x42, + BCODE_PUSH_OBJECT_3 = 0x43, - BCODE_JUMP_FORWARD_0 = 0x44, /* 68 */ - BCODE_JUMP_FORWARD_1 = 0x45, /* 69 */ - BCODE_JUMP_FORWARD_2 = 0x46, /* 70 */ - BCODE_JUMP_FORWARD_3 = 0x47, /* 71 */ + BCODE_JUMP_FORWARD_0 = 0x44, /* 68 */ + BCODE_JUMP_FORWARD_1 = 0x45, /* 69 */ + BCODE_JUMP_FORWARD_2 = 0x46, /* 70 */ + BCODE_JUMP_FORWARD_3 = 0x47, /* 71 */ - BCODE_JUMP_BACKWARD_0 = 0x48, - BCODE_JUMP_BACKWARD_1 = 0x49, - BCODE_JUMP_BACKWARD_2 = 0x4A, - BCODE_JUMP_BACKWARD_3 = 0x4B, + BCODE_JUMP_BACKWARD_0 = 0x48, + BCODE_JUMP_BACKWARD_1 = 0x49, + BCODE_JUMP_BACKWARD_2 = 0x4A, + BCODE_JUMP_BACKWARD_3 = 0x4B, - BCODE_JUMP_IF_TRUE_0 = 0x4C, - BCODE_JUMP_IF_TRUE_1 = 0x4D, - BCODE_JUMP_IF_TRUE_2 = 0x4E, - BCODE_JUMP_IF_TRUE_3 = 0x4F, + BCODE_JUMP_IF_TRUE_0 = 0x4C, + BCODE_JUMP_IF_TRUE_1 = 0x4D, + BCODE_JUMP_IF_TRUE_2 = 0x4E, + BCODE_JUMP_IF_TRUE_3 = 0x4F, + + BCODE_JUMP_IF_FALSE_0 = 0x50, /* 80 */ + BCODE_JUMP_IF_FALSE_1 = 0x51, /* 81 */ + BCODE_JUMP_IF_FALSE_2 = 0x52, /* 82 */ + BCODE_JUMP_IF_FALSE_3 = 0x53, /* 83 */ - BCODE_JUMP_IF_FALSE_0 = 0x50, - BCODE_JUMP_IF_FALSE_1 = 0x51, - BCODE_JUMP_IF_FALSE_2 = 0x52, - BCODE_JUMP_IF_FALSE_3 = 0x53, - BCODE_JUMP_BY_OFFSET_0 = 0x54, - BCODE_JUMP_BY_OFFSET_1 = 0x55, - BCODE_JUMP_BY_OFFSET_2 = 0x56, - BCODE_JUMP_BY_OFFSET_3 = 0x57, BCODE_STORE_INTO_CTXTEMPVAR_0 = 0x58, /* 88 */ BCODE_STORE_INTO_CTXTEMPVAR_1 = 0x59, /* 89 */ @@ -729,7 +722,7 @@ enum stix_bcode_t BCODE_JUMP_BACKWARD_X = 0xC8, /* 200 */ BCODE_JUMP_IF_TRUE_X = 0xCC, /* 204 */ BCODE_JUMP_IF_FALSE_X = 0xD0, /* 208 */ - BCODE_JUMP_BY_OFFSET_X = 0xD4, /* 212 */ + BCODE_STORE_INTO_CTXTEMPVAR_X = 0xD8, /* 216 */ BCODE_POP_INTO_CTXTEMPVAR_X = 0xDC, /* 220 */ @@ -743,15 +736,18 @@ enum stix_bcode_t BCODE_SEND_MESSAGE_TO_SUPER_X = 0xF4, /* 244 */ - BCODE_PUSH_RECEIVER = 0x81, - BCODE_PUSH_NIL = 0x82, - BCODE_PUSH_TRUE = 0x83, - BCODE_PUSH_FALSE = 0x84, - BCODE_PUSH_CONTEXT = 0x85, - BCODE_PUSH_NEGONE = 0x86, - BCODE_PUSH_ZERO = 0x87, - BCODE_PUSH_ONE = 0x89, - BCODE_PUSH_TWO = 0x91, + BCODE_JUMP2_FORWARD = 0xC5, /* 197 */ + BCODE_JUMP2_BACKWARD = 0xC9, /* 201 */ + + BCODE_PUSH_RECEIVER = 0x81, /* 129 */ + BCODE_PUSH_NIL = 0x82, /* 130 */ + BCODE_PUSH_TRUE = 0x83, /* 131 */ + BCODE_PUSH_FALSE = 0x84, /* 132 */ + BCODE_PUSH_CONTEXT = 0x85, /* 133 */ + BCODE_PUSH_NEGONE = 0x86, /* 134 */ + BCODE_PUSH_ZERO = 0x87, /* 135 */ + BCODE_PUSH_ONE = 0x89, /* 137 */ + BCODE_PUSH_TWO = 0x8A, /* 138 */ /* UNUSED 0xE8 - 0xF8 */ diff --git a/stix/lib/test-005.st b/stix/lib/test-005.st index 78cf314..bded63c 100644 --- a/stix/lib/test-005.st +++ b/stix/lib/test-005.st @@ -1,375 +1,5 @@ -#class Stix(nil) -{ - #dcl(#class) sysdic. - #method(#class) yourself - { - ^self. - } - - #method yourself - { - ^self. - } - - #method(#class) dump - { - - } - - #method dump - { - - } - - #method(#class) new - { - - } - - #method(#class) new: anInteger - { - - } - - #method basicSize - { - - ^0 - } - - - #method basicAt: anInteger - { - - ## self error: 'out of range'. - } - - #method basicAt: anInteger put: anObject - { - - ## self error: 'out of range'. - } - - #method badReturnError - { - ## TODO: implement this - } - - #method mustBeBoolean - { - ## TODO: implement this - } - - #method doesNotUnderstand: aMessageSymbol - { - ## TODO: implement this - } - - #method error: anErrorString - { - anErrorString dump. - } -} - -#class Object(Stix) -{ - -} - -#class NilObject(Stix) -{ - -} - -#class(#pointer) Class(Stix) -{ - #dcl spec selfspec superclass subclasses name instvars classvars classinstvars instmthdic classmthdic. -} - - -#class Magnitude(Object) -{ -} - -#class Association(Magnitude) -{ - #dcl key value. -} - -#class Character(Magnitude) -{ -} - -#class Number(Magnitude) -{ - #method add: aNumber - { - - } - - #method + aNumber - { - - } - - #method - aNumber - { - - } - - #method < aNumber - { - - } -} - -#class SmallInteger(Number) -{ - -} - -#class Boolean(Object) -{ - -} - -#class True(Boolean) -{ - #method ifTrue: trueBlock ifFalse: falseBlock - { - ^trueBlock value. - } - - #method ifTrue: trueBlock - { - ^trueBlock value. - } - - #method ifFalse: falseBlock - { - ^nil. - } -} - -#class False(Boolean) -{ - #method ifTrue: trueBlock ifFalse: falseBlock - { - ^falseBlock value. - } - - #method ifTrue: trueBlock - { - ^nil. - } - - #method ifFalse: falseBlock - { - ^falseBlock value. - } -} - -#class Collection(Object) -{ -} - -#class(#byte) ByteArray(Collection) -{ - #method at: anInteger - { - ^self basicAt: anInteger. - } - - #method at: anInteger put: aValue - { - ^self basicAt: anInteger put: aValue. - } - -} - -#class(#pointer) Array(Collection) -{ - #method at: anInteger - { - ^self basicAt: anInteger. - } - - #method at: anInteger put: aValue - { - ^self basicAt: anInteger put: aValue. - } -} - -#class(#character) String(Array) -{ -} - -#class(#character) Symbol(Array) -{ -} - - -#class Set(Collection) -{ - #dcl tally bucket. -} - -#class SymbolSet(Set) -{ -} - -#class Dictionary(Set) -{ -} - -#class SystemDictionary(Dictionary) -{ -} - -#class MethodDictionary(Dictionary) -{ - -} - -#class(#pointer) Context(Stix) -{ -} - -#class(#pointer) MethodContext(Context) -{ - #dcl sender ip sp ntmprs method receiver home origin. - - #method pc - { - ^ip - } - - #method pc: anInteger - { - ip := anInteger. - "sp := sp - 1." "whould this always work??? " - } - - #method sp - { - ^sp. - - } - #method sp: anInteger - { - sp := anInteger. - } - - #method pc: aPC sp: aSP - { - ip := aPC. - sp := aSP. - ##sp := sp - 1. - } -} - -#class(#pointer) BlockContext(Context) -{ - #dcl caller ip sp ntmprs nargs source home origin. - - #method value - { - - } - - #method value: a - { - - } - - #method value: a value: b - { - - } - - #method value: a value: b value: c - { - - } - - #method whileTrue: aBlock - { -## http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without - -## ---------------------------------------------------------------------------- - -## ^(self value) ifTrue: [aBlock value. self whileTrue: aBlock]. - -## ---------------------------------------------------------------------------- - - ## less block context before whileTrue: is recursively sent. - ## whileTrue: is sent in a method context. -## (self value) ifFalse: [^nil]. -## aBlock value. -## self whileTrue: aBlock. - -## ---------------------------------------------------------------------------- - -## ---------------------------------------------------------------------------- - | pc sp xsp | - - sp := thisContext sp. - sp := sp - 1. "decrement sp by 1 becuase thisContext pushed above affects the sp method" - pc := thisContext pc. - self value ifFalse: [ ^nil "^self" ]. - aBlock value. - ##thisContext pc: pc - 3 sp: sp. - ##thisContext pc: pc + 2 sp: sp. - thisContext pc: pc + 1 sp: sp. - ## this +2 or - 3 above is dependent on the byte code instruction size used for 'store' - ## +2 to skip STORE_INTO_TEMP(pc) and POP_STACKTOP. - ## TODO: make it independent of the byte code size - -## ---------------------------------------------------------------------------- - -## #