changed the byte code for push_intlit and push_negintlit.

added a new byte code push_charlit
This commit is contained in:
hyunghwan.chung 2016-09-14 04:56:00 +00:00
parent 0504fbde72
commit ab5dee8c77
5 changed files with 53 additions and 17 deletions

View File

@ -95,7 +95,12 @@
#method(#class) main
{
| v1 v2 |
System logNl: 'START OF MAIN'.
v2 := 'have fun'.
v2 at: 0 put: $H.
System logNl: ('START OF MAIN - ' , v2).
v1 := MyConsole output.
v1 clear.

View File

@ -1694,6 +1694,7 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para
case BCODE_JUMP2_BACKWARD:
case BCODE_PUSH_INTLIT:
case BCODE_PUSH_NEGINTLIT:
case BCODE_PUSH_CHARLIT:
bc = cmd;
goto write_long;
}
@ -1706,9 +1707,14 @@ write_short:
return 0;
write_long:
if (param_1 > MAX_CODE_PARAM)
{
stix->errnum = STIX_ERANGE;
return -1;
}
#if (STIX_BCODE_LONG_PARAM_SIZE == 2)
if (emit_byte_instruction(stix, bc) <= -1 ||
emit_byte_instruction(stix, param_1 >> 8) <= -1 ||
emit_byte_instruction(stix, (param_1 >> 8) & 0xFF) <= -1 ||
emit_byte_instruction(stix, param_1 & 0xFF) <= -1) return -1;
#else
if (emit_byte_instruction(stix, bc) <= -1 ||
@ -1759,13 +1765,19 @@ write_short:
return 0;
write_long:
if (param_1 > MAX_CODE_PARAM || param_2 > MAX_CODE_PARAM)
{
stix->errnum = STIX_ERANGE;
return -1;
}
#if (STIX_BCODE_LONG_PARAM_SIZE == 2)
if (emit_byte_instruction(stix, bc) <= -1 ||
emit_byte_instruction(stix, param_1 >> 8) <= -1 ||
emit_byte_instruction(stix, (param_1 >> 8) & 0xFF) <= -1 ||
emit_byte_instruction(stix, param_1 & 0xFF) <= -1 ||
emit_byte_instruction(stix, param_2 >> 8) <= -1 ||
emit_byte_instruction(stix, (param_2 >> 8) & 0xFF) <= -1 ||
emit_byte_instruction(stix, param_2 & 0xFF) <= -1) return -1;
#else
if (emit_byte_instruction(stix, bc) <= -1 ||
emit_byte_instruction(stix, param_1) <= -1 ||
emit_byte_instruction(stix, param_2) <= -1) return -1;
@ -1773,7 +1785,7 @@ write_long:
return 0;
}
static int emit_push_smint_literal (stix_t* stix, stix_ooi_t i)
static int emit_push_smooi_literal (stix_t* stix, stix_ooi_t i)
{
stix_oow_t index;
@ -1807,6 +1819,20 @@ static int emit_push_smint_literal (stix_t* stix, stix_ooi_t i)
return 0;
}
static int emit_push_character_literal (stix_t* stix, stix_ooch_t ch)
{
stix_oow_t index;
if (ch >= 0 && ch <= MAX_CODE_PARAM)
{
return emit_single_param_instruction (stix, BCODE_PUSH_CHARLIT, ch);
}
if (add_literal(stix, STIX_CHAR_TO_OOP(ch), &index) <= -1 ||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
return 0;
}
/* ---------------------------------------------------------------------
* Compiler
* --------------------------------------------------------------------- */
@ -1848,11 +1874,6 @@ static int add_literal (stix_t* stix, stix_oop_t lit, stix_oow_t* index)
return 0;
}
static STIX_INLINE int add_character_literal (stix_t* stix, stix_ooch_t ch, stix_oow_t* index)
{
return add_literal (stix, STIX_CHAR_TO_OOP(ch), index);
}
static int add_string_literal (stix_t* stix, const stix_oocs_t* str, stix_oow_t* index)
{
stix_oop_t lit;
@ -3068,8 +3089,8 @@ static int compile_block_expression (stix_t* stix)
if (emit_double_param_instruction(stix, BCODE_MAKE_BLOCK, block_arg_count, stix->c->mth.tmpr_count/*block_tmpr_count*/) <= -1) return -1;
#else
if (emit_byte_instruction(stix, BCODE_PUSH_CONTEXT) <= -1 ||
emit_push_smint_literal(stix, block_arg_count) <= -1 ||
emit_push_smint_literal(stix, stix->c->mth.tmpr_count/*block_tmpr_count*/) <= -1 ||
emit_push_smooi_literal(stix, block_arg_count) <= -1 ||
emit_push_smooi_literal(stix, stix->c->mth.tmpr_count/*block_tmpr_count*/) <= -1 ||
emit_byte_instruction(stix, BCODE_SEND_BLOCK_COPY) <= -1) return -1;
#endif
@ -3520,8 +3541,7 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c
case STIX_IOTOK_CHARLIT:
STIX_ASSERT (stix->c->tok.name.len == 1);
if (add_character_literal(stix, stix->c->tok.name.ptr[0], &index) <= -1 ||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
if (emit_push_character_literal(stix, stix->c->tok.name.ptr[0]) <= -1) return -1;
GET_TOKEN (stix);
break;
@ -3549,7 +3569,7 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c
if (STIX_OOP_IS_SMOOI(tmp))
{
if (emit_push_smint_literal(stix, STIX_OOP_TO_SMOOI(tmp)) <= -1) return -1;
if (emit_push_smooi_literal(stix, STIX_OOP_TO_SMOOI(tmp)) <= -1) return -1;
}
else
{

View File

@ -445,6 +445,10 @@ return -1;
LOG_INST_1 (stix, "push_negintlit %zd", -b1);
break;
case BCODE_PUSH_CHARLIT:
FETCH_PARAM_CODE_TO (stix, b1);
LOG_INST_1 (stix, "push_charlit %zd", b1);
break;
/* -------------------------------------------------------- */
case BCODE_DUP_STACKTOP:

View File

@ -3789,6 +3789,11 @@ return -1;
STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-b1));
break;
case BCODE_PUSH_CHARLIT:
FETCH_PARAM_CODE_TO (stix, b1);
LOG_INST_1 (stix, "push_charlit %zd", b1);
STIX_STACK_PUSH (stix, STIX_CHAR_TO_OOP(b1));
break;
/* -------------------------------------------------------- */
case BCODE_DUP_STACKTOP:

View File

@ -887,8 +887,10 @@ enum stix_bcode_t
BCODE_PUSH_ONE = 0x8A, /* 138 */
BCODE_PUSH_TWO = 0x8B, /* 139 */
BCODE_PUSH_INTLIT = 0xB1, /* 177 */
BCODE_PUSH_NEGINTLIT = 0xB2, /* 178 */
/* UNUSED - 0xB1 */
BCODE_PUSH_INTLIT = 0xB2, /* 178 */
BCODE_PUSH_NEGINTLIT = 0xB3, /* 179 */
BCODE_PUSH_CHARLIT = 0xB4, /* 180 */
/* UNUSED 0xE8 - 0xF7 */