From 70fa033b9f3f0514f74ec08f7bbd45dd7cca93a4 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 11 Aug 2005 16:16:04 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/bytecode.c | 36 ++++++++++++++++++++++++++++++++---- ase/stx/bytecode.h | 12 ++++++++---- ase/stx/makefile.cl | 2 +- ase/stx/parser.c | 32 ++++++++++++++++++++------------ ase/test/stx/test.st | 4 +--- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/ase/stx/bytecode.c b/ase/stx/bytecode.c index 66a074cc..ae698e6f 100644 --- a/ase/stx/bytecode.c +++ b/ase/stx/bytecode.c @@ -1,5 +1,5 @@ /* - * $Id: bytecode.c,v 1.8 2005-07-19 12:08:04 bacon Exp $ + * $Id: bytecode.c,v 1.9 2005-08-11 16:16:04 bacon Exp $ */ #include #include @@ -85,7 +85,8 @@ static int __decode2 (xp_stx_t* stx, xp_word_t bytecode_size, pc = 0; int code, next, next2; - static const xp_char_t* stack_opcode_names[] = { + static const xp_char_t* stack_opcode_names[] = + { XP_TEXT("push_receiver_variable"), XP_TEXT("push_temporary_location"), XP_TEXT("push_literal_constant"), @@ -94,11 +95,31 @@ static int __decode2 (xp_stx_t* stx, XP_TEXT("store_temporary_location") }; - static const xp_char_t* send_opcode_names[] = { + static const xp_char_t* send_opcode_names[] = + { XP_TEXT("send_to_self"), XP_TEXT("send_to_super") }; + static const xp_char_t* stack_special_opcode_names[] = + { + XP_TEXT("store_pop_stack_top"), + XP_TEXT("duplicate_pop_stack_top"), + XP_TEXT("push_active_context"), + XP_TEXT("push_nil"), + XP_TEXT("push_true"), + XP_TEXT("push_false") + }; + + static const xp_char_t* return_opcode_names[] = + { + XP_TEXT("return_receiver"), + XP_TEXT("return_true"), + XP_TEXT("return_false"), + XP_TEXT("return_nil"), + XP_TEXT("return_from_message"), + XP_TEXT("return_from_block") + }; bytecodes = XP_STX_BYTE_OBJECT(stx, method_obj->bytecodes); bytecode_size = XP_STX_SIZE(stx, method_obj->bytecodes); @@ -117,6 +138,12 @@ static int __decode2 (xp_stx_t* stx, xp_printf (XP_TEXT("%s %d\n"), stack_opcode_names[code & 0x0F], next); } + else if (code >= 0x67 && code <= 0x6C) { + /* stack special */ + xp_printf (XP_TEXT("%s\n"), + stack_special_opcode_names[code - 0x67]); + } + else if (code >= 0x70 && code <= 0x71 ) { /* send */ next = bytecodes->data[pc++]; @@ -132,7 +159,8 @@ static int __decode2 (xp_stx_t* stx, } else if (code >= 0x78 && code <= 0x7D) { - // return + xp_printf (XP_TEXT("%s\n"), + return_opcode_names[code - 0x78]); } else if (code >= 0x80 && code <= 0x8F) { // jump diff --git a/ase/stx/bytecode.h b/ase/stx/bytecode.h index 4257c50c..34cd394b 100644 --- a/ase/stx/bytecode.h +++ b/ase/stx/bytecode.h @@ -1,5 +1,5 @@ /* - * $Id: bytecode.h,v 1.7 2005-07-10 09:21:46 bacon Exp $ + * $Id: bytecode.h,v 1.8 2005-08-11 16:16:04 bacon Exp $ */ #ifndef _XP_STX_BYTECODE_H_ @@ -20,9 +20,13 @@ #define PUSH_LITERAL_VARIABLE_EXTENDED 0x63 #define STORE_RECEIVER_VARIABLE_EXTENDED 0x64 #define STORE_TEMPORARY_LOCATION_EXTENDED 0x65 -#define STORE_POP_STACK_TOP 0x68 -#define DUPLICATE_POP_STACK_TOP 0x69 -#define PUSH_ACTIVE_CONTEXT 0x6A + +#define STORE_POP_STACK_TOP 0x67 +#define DUPLICATE_POP_STACK_TOP 0x68 +#define PUSH_ACTIVE_CONTEXT 0x69 +#define PUSH_NIL 0x6A +#define PUSH_TRUE 0x6B +#define PUSH_FALSE 0x6C #define SEND_TO_SELF 0x70 #define SEND_TO_SUPER 0x71 diff --git a/ase/stx/makefile.cl b/ase/stx/makefile.cl index 24d949cd..e4ee5125 100644 --- a/ase/stx/makefile.cl +++ b/ase/stx/makefile.cl @@ -1,6 +1,6 @@ SRCS = \ stx.c memory.c object.c symbol.c class.c \ - dict.c misc.c context.c name.c token.c parser.c bootstrp.c + dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c OBJS = $(SRCS:.c=.obj) OUT = xpstx.lib diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 2a256ee3..77393654 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.66 2005-08-11 11:18:30 bacon Exp $ + * $Id: parser.c,v 1.67 2005-08-11 16:16:04 bacon Exp $ */ #include @@ -769,6 +769,7 @@ static int __parse_statements (xp_stx_parser_t* parser) } } + EMIT_RETURN_FROM_MESSAGE (parser); return 0; } @@ -973,7 +974,8 @@ static int __parse_primary (xp_stx_parser_t* parser, const xp_char_t* ident) } } else { - if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1; + /*if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1;*/ + if (__parse_primary_ident(parser, ident) == -1) return -1; } return 0; @@ -990,13 +992,19 @@ static int __parse_primary_ident (xp_stx_parser_t* parser, const xp_char_t* iden } else if (xp_strcmp(token->name.buffer, XP_TEXT("super")) == 0) { } - else if (xp_strcmp(token->name.buffer, XP_TEXT("nil")) == 0) { - } - else if (xp_strcmp(token->name.buffer, XP_TEXT("true")) == 0) { - } - else if (xp_strcmp(token->name.buffer, XP_TEXT("false")) == 0) { - } */ + if (xp_strcmp(ident, XP_TEXT("nil")) == 0) { + EMIT_CODE (parser, PUSH_NIL); + return 0; + } + else if (xp_strcmp(ident, XP_TEXT("true")) == 0) { + EMIT_CODE (parser, PUSH_TRUE); + return 0; + } + else if (xp_strcmp(ident, XP_TEXT("false")) == 0) { + EMIT_CODE (parser, PUSH_FALSE); + return 0; + } /* Refer to __parse_assignment for identifier lookup */ @@ -1128,12 +1136,12 @@ static int __parse_keyword_message (xp_stx_parser_t* parser) } GET_TOKEN (parser); - if (__parse_primary (parser, XP_NULL) == -1) { + if (__parse_primary(parser, XP_NULL) == -1) { xp_stx_name_close (&name); return -1; } - if (__parse_binary_message (parser) == -1) { + if (__parse_binary_message(parser) == -1) { xp_stx_name_close (&name); return -1; } @@ -1167,12 +1175,12 @@ static int __parse_binary_message (xp_stx_parser_t* parser) } GET_TOKEN (parser); - if (__parse_primary (parser, XP_NULL) == -1) { + if (__parse_primary(parser, XP_NULL) == -1) { xp_free (op); return -1; } - if (__parse_unary_message (parser) == -1) { + if (__parse_unary_message(parser) == -1) { xp_free (op); return -1; } diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 9253128e..6195b3c1 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -1,4 +1,2 @@ main - < primitive: 16 > - ^nil. - + ^nil