*** empty log message ***

This commit is contained in:
hyung-hwan 2005-09-30 12:19:00 +00:00
parent 3d3c41e083
commit 215b487cef
8 changed files with 119 additions and 57 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: bytecode.c,v 1.13 2005-09-13 11:15:41 bacon Exp $
* $Id: bytecode.c,v 1.14 2005-09-30 12:19:00 bacon Exp $
*/
#include <xp/stx/bytecode.h>
#include <xp/stx/class.h>
@ -121,7 +121,8 @@ static int __decode2 (xp_stx_t* stx,
XP_TEXT("push_active_context"),
XP_TEXT("push_nil"),
XP_TEXT("push_true"),
XP_TEXT("push_false")
XP_TEXT("push_false"),
XP_TEXT("push_receiver")
};
static const xp_char_t* return_opcode_names[] =
@ -151,7 +152,7 @@ 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) {
else if (code >= 0x67 && code <= 0x6D) {
/* stack special */
xp_printf (XP_TEXT("%s\n"),
stack_special_opcode_names[code - 0x67]);

View File

@ -1,5 +1,5 @@
/*
* $Id: bytecode.h,v 1.10 2005-08-18 15:28:18 bacon Exp $
* $Id: bytecode.h,v 1.11 2005-09-30 12:19:00 bacon Exp $
*/
#ifndef _XP_STX_BYTECODE_H_
@ -27,6 +27,7 @@
#define PUSH_NIL 0x6A
#define PUSH_TRUE 0x6B
#define PUSH_FALSE 0x6C
#define PUSH_RECEIVER 0x6D
#define SEND_TO_SELF 0x70
#define SEND_TO_SUPER 0x71

View File

@ -1,5 +1,5 @@
/*
* $Id: interp.c,v 1.15 2005-09-13 15:56:23 bacon Exp $
* $Id: interp.c,v 1.16 2005-09-30 12:19:00 bacon Exp $
*/
#include <xp/stx/interp.h>
@ -42,6 +42,7 @@ struct process_t
xp_word_t stack_base;
xp_word_t stack_top;
xp_word_t receiver;
xp_word_t method;
xp_word_t pc;
@ -93,6 +94,7 @@ xp_printf (XP_TEXT("out of memory in xp_stx_interp\n"));
proc.argcount = XP_STX_FROM_SMALLINT(mthobj->argcount);
proc.tmpcount = XP_STX_FROM_SMALLINT(mthobj->tmpcount);
proc.receiver = receiver;
proc.method = method;
proc.pc = 0;
@ -143,10 +145,25 @@ static int __run_process (xp_stx_t* stx, process_t* proc)
int what = code >> 4;
int index = code & 0x0F;
__store_from_stack (stx, proc, code >> 4, code & 0x0F);
}
/* more here .... */
/* TODO: more here .... */
else if (code == 0x6A) {
proc->stack[proc->stack_top++] = stx->nil;
}
else if (code == 0x6B) {
proc->stack[proc->stack_top++] = stx->true;
}
else if (code == 0x6C) {
proc->stack[proc->stack_top++] = stx->false;
}
else if (code == 0x6D) {
/* push receiver */
proc->stack[proc->stack_top++] = proc->receiver;
}
/* TODO: more here .... */
else if (code == 0x70) {
next = proc->bytecodes[proc->pc++];
@ -267,6 +284,7 @@ xp_printf (XP_TEXT("cannot find the method....\n"));
proc->stack_base = proc->stack_top - 3 - tmpcount - argcount - 1;
xp_assert (proc->stack_base > 0);
proc->receiver = receiver;
proc->method = method;
proc->pc = 0;
@ -293,13 +311,17 @@ static int __return_from_message (xp_stx_t* stx, process_t* proc)
method = proc->stack[proc->stack_base + 1 + proc->tmpcount + proc->argcount + 1];
pc = proc->stack[proc->stack_base + 1 + proc->tmpcount + proc->argcount];
mthobj = (xp_stx_method_t*)XP_STX_OBJECT(stx,method);
xp_assert (mthobj != XP_NULL);
/* return value is located on top of the previous stack */
proc->stack[proc->stack_base - 1] = proc->stack[proc->stack_top - 1];
/* restore the stack pointers */
proc->stack_top = proc->stack_base;
proc->stack_base = stack_base;
proc->receiver = proc->stack[stack_base];
proc->method = method;
proc->pc = pc;

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.c,v 1.72 2005-09-13 11:15:41 bacon Exp $
* $Id: parser.c,v 1.73 2005-09-30 12:19:00 bacon Exp $
*/
#include <xp/stx/parser.h>
@ -33,15 +33,19 @@ static int __parse_assignment (
static int __parse_basic_expression (
xp_stx_parser_t* parser, const xp_char_t* ident);
static int __parse_primary (
xp_stx_parser_t* parser, const xp_char_t* ident);
xp_stx_parser_t* parser, const xp_char_t* ident, xp_bool_t* is_super);
static int __parse_primary_ident (
xp_stx_parser_t* parser, const xp_char_t* ident);
xp_stx_parser_t* parser, const xp_char_t* ident, xp_bool_t* is_super);
static int __parse_block_constructor (xp_stx_parser_t* parser);
static int __parse_message_continuation (xp_stx_parser_t* parser);
static int __parse_keyword_message (xp_stx_parser_t* parser);
static int __parse_binary_message (xp_stx_parser_t* parser);
static int __parse_unary_message (xp_stx_parser_t* parser);
static int __parse_message_continuation (
xp_stx_parser_t* parser, xp_bool_t is_super);
static int __parse_keyword_message (
xp_stx_parser_t* parser, xp_bool_t is_super);
static int __parse_binary_message (
xp_stx_parser_t* parser, xp_bool_t is_super);
static int __parse_unary_message (
xp_stx_parser_t* parser, xp_bool_t is_super);
static int __get_token (xp_stx_parser_t* parser);
static int __get_ident (xp_stx_parser_t* parser);
@ -860,11 +864,12 @@ static int __parse_basic_expression (
/*
* <basic expression> ::= <primary> [<messages> <cascaded messages>]
*/
xp_bool_t is_super;
if (__parse_primary(parser, ident) == -1) return -1;
if (__parse_primary(parser, ident, &is_super) == -1) return -1;
if (parser->token.type != XP_STX_TOKEN_END &&
parser->token.type != XP_STX_TOKEN_PERIOD) {
if (__parse_message_continuation(parser) == -1) return -1;
if (__parse_message_continuation(parser, is_super) == -1) return -1;
}
return 0;
}
@ -912,7 +917,8 @@ static int __parse_assignment (
return -1;
}
static int __parse_primary (xp_stx_parser_t* parser, const xp_char_t* ident)
static int __parse_primary (
xp_stx_parser_t* parser, const xp_char_t* ident, xp_bool_t* is_super)
{
/*
* <primary> ::=
@ -927,7 +933,8 @@ static int __parse_primary (xp_stx_parser_t* parser, const xp_char_t* ident)
xp_word_t literal;
if (parser->token.type == XP_STX_TOKEN_IDENT) {
if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1;
if (__parse_primary_ident(parser,
parser->token.name.buffer, is_super) == -1) return -1;
GET_TOKEN (parser);
}
else if (parser->token.type == XP_STX_TOKEN_CHARLIT) {
@ -984,26 +991,30 @@ 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, ident) == -1) return -1;
if (__parse_primary_ident(parser, ident, is_super) == -1) return -1;
}
return 0;
}
static int __parse_primary_ident (xp_stx_parser_t* parser, const xp_char_t* ident)
static int __parse_primary_ident (
xp_stx_parser_t* parser, const xp_char_t* ident, xp_bool_t* is_super)
{
xp_word_t i;
xp_stx_t* stx = parser->stx;
/*
if (xp_strcmp(token->name.buffer, XP_TEXT("self")) == 0) {
EMIT_CODE (parser, PUSH_SELF);
*is_super = xp_false;
if (xp_strcmp(ident, XP_TEXT("self")) == 0) {
EMIT_CODE (parser, PUSH_RECEIVER);
return 0;
}
else if (xp_strcmp(token->name.buffer, XP_TEXT("super")) == 0) {
EMIT_CODE (parser, PUSH_SUPER);
else if (xp_strcmp(ident, XP_TEXT("super")) == 0) {
*is_super = xp_true;
EMIT_CODE (parser, PUSH_RECEIVER);
return 0;
}
*/
if (xp_strcmp(ident, XP_TEXT("nil")) == 0) {
else if (xp_strcmp(ident, XP_TEXT("nil")) == 0) {
EMIT_CODE (parser, PUSH_NIL);
return 0;
}
@ -1097,7 +1108,8 @@ static int __parse_block_constructor (xp_stx_parser_t* parser)
return 0;
}
static int __parse_message_continuation (xp_stx_parser_t* parser)
static int __parse_message_continuation (
xp_stx_parser_t* parser, xp_bool_t is_super)
{
/*
* <messages> ::=
@ -1106,21 +1118,22 @@ static int __parse_message_continuation (xp_stx_parser_t* parser)
* <keyword message>
* <cascaded messages> ::= (';' <messages>)*
*/
xp_bool_t dummy;
if (__parse_keyword_message(parser) == -1) return -1;
if (__parse_keyword_message(parser, is_super) == -1) return -1;
while (parser->token.type == XP_STX_TOKEN_SEMICOLON) {
EMIT_CODE_TEST (parser, XP_TEXT("DoSpecial(DUP_RECEIVER(CASCADE))"), XP_TEXT(""));
GET_TOKEN (parser);
if (__parse_keyword_message (parser) == -1) return -1;
if (__parse_keyword_message (parser, &dummy) == -1) return -1;
EMIT_CODE_TEST (parser, XP_TEXT("DoSpecial(POP_TOP)"), XP_TEXT(""));
}
return 0;
}
static int __parse_keyword_message (xp_stx_parser_t* parser)
static int __parse_keyword_message (xp_stx_parser_t* parser, xp_bool_t is_super)
{
/*
* <keyword message> ::= (keyword <keyword argument> )+
@ -1129,9 +1142,10 @@ static int __parse_keyword_message (xp_stx_parser_t* parser)
xp_stx_name_t name;
xp_word_t pos;
int nargs = 0;
xp_bool_t is_super2;
int nargs = 0, n;
if (__parse_binary_message (parser) == -1) return -1;
if (__parse_binary_message (parser, is_super) == -1) return -1;
if (parser->token.type != XP_STX_TOKEN_KEYWORD) return 0;
if (xp_stx_name_open(&name, 0) == XP_NULL) {
@ -1147,12 +1161,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, &is_super2) == -1) {
xp_stx_name_close (&name);
return -1;
}
if (__parse_binary_message(parser) == -1) {
if (__parse_binary_message(parser, is_super2) == -1) {
xp_stx_name_close (&name);
return -1;
}
@ -1161,32 +1175,35 @@ static int __parse_keyword_message (xp_stx_parser_t* parser)
/* TODO: check if it has too many arguments.. */
} while (parser->token.type == XP_STX_TOKEN_KEYWORD);
/* TODO: SEND_TO_SUPER */
pos = __add_symbol_literal (parser, name.buffer, name.size);
if (pos == -1) {
xp_stx_name_close (&name);
return -1;
}
/*EMIT_SEND_TO_SELF (parser, nargs, pos);*/
if (__emit_send_to_self(parser,nargs,pos) == -1) {
n = (is_super)?
__emit_send_to_super(parser,nargs,pos):
__emit_send_to_self(parser,nargs,pos);
if (n == -1) {
xp_stx_name_close (&name);
return -1;
}
xp_stx_name_close (&name);
return 0;
}
static int __parse_binary_message (xp_stx_parser_t* parser)
static int __parse_binary_message (xp_stx_parser_t* parser, xp_bool_t is_super)
{
/*
* <binary message> ::= binarySelector <binary argument>
* <binary argument> ::= <primary> <unary message>*
*/
xp_word_t pos;
xp_bool_t is_super2;
int n;
if (__parse_unary_message (parser) == -1) return -1;
if (__parse_unary_message (parser, is_super) == -1) return -1;
while (parser->token.type == XP_STX_TOKEN_BINARY) {
xp_char_t* op = xp_stx_token_yield (&parser->token, 0);
@ -1196,24 +1213,26 @@ 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, &is_super2) == -1) {
xp_free (op);
return -1;
}
if (__parse_unary_message(parser) == -1) {
if (__parse_unary_message(parser, is_super2) == -1) {
xp_free (op);
return -1;
}
/* TODO: SEND_TO_SUPER */
pos = __add_symbol_literal (parser, op, xp_strlen(op));
if (pos == -1) {
xp_free (op);
return -1;
}
/*EMIT_SEND_TO_SELF (parser, 2, pos);*/
if (__emit_send_to_self(parser,2,pos) == -1) {
n = (is_super)?
__emit_send_to_super(parser,2,pos):
__emit_send_to_self(parser,2,pos);
if (n == -1) {
xp_free (op);
return -1;
}
@ -1224,21 +1243,23 @@ static int __parse_binary_message (xp_stx_parser_t* parser)
return 0;
}
static int __parse_unary_message (xp_stx_parser_t* parser)
static int __parse_unary_message (xp_stx_parser_t* parser, xp_bool_t is_super)
{
/* <unary message> ::= unarySelector */
xp_word_t pos;
int n;
while (parser->token.type == XP_STX_TOKEN_IDENT) {
/* TODO: SEND_TO_SUPER */
/*EMIT_SEND_TO_SELF (parser, 0, index of parser->token.name.buffer);*/
/*EMIT_SEND_TO_SELF (parser, 0, 0);*/
pos = __add_symbol_literal (parser,
parser->token.name.buffer, parser->token.name.size);
if (pos == -1) return -1;
EMIT_SEND_TO_SELF (parser, 0, pos);
n = (is_super)?
__emit_send_to_super(parser,0,pos):
__emit_send_to_self(parser,0,pos);
if (n == -1) return -1;
GET_TOKEN (parser);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.h,v 1.43 2005-08-18 15:28:18 bacon Exp $
* $Id: stx.h,v 1.44 2005-09-30 12:19:00 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
@ -134,12 +134,20 @@ struct xp_stx_t
#define XP_STX_CHAR_OBJECT(stx,idx) \
((xp_stx_char_object_t*)XP_STX_OBJECT(stx,idx))
/*
#define XP_STX_WORD_AT(stx,idx,n) \
(((xp_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
#define XP_STX_BYTE_AT(stx,idx,n) \
(((xp_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
#define XP_STX_CHAR_AT(stx,idx,n) \
(((xp_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
*/
#define XP_STX_WORD_AT(stx,idx,n) \
(XP_STX_WORD_OBJECT(stx,idx)->data[n])
#define XP_STX_BYTE_AT(stx,idx,n) \
(XP_STX_BYTE_OBJECT(stx,idx)->data[n])
#define XP_STX_CHAR_AT(stx,idx,n) \
(XP_STX_CHAR_OBJECT(stx,idx)->data[n])
#ifdef __cplusplus
extern "C" {

View File

@ -171,12 +171,18 @@ int xp_main (int argc, xp_char_t* argv[])
xp_stx_parser_error_string (&parser));
}
xp_printf (XP_TEXT("== Decoded Methods ==\n"));
xp_printf (XP_TEXT("\n== Decoded Methods ==\n"));
if (xp_stx_decode(&stx, n) == -1) {
xp_printf (XP_TEXT("parser error <%s>\n"),
xp_stx_parser_error_string (&parser));
}
xp_printf (XP_TEXT("\n== Decoded Methods for Symbol ==\n"));
if (xp_stx_decode(&stx, stx.class_symbol) == -1) {
xp_printf (XP_TEXT("parser error <%s>\n"),
xp_stx_parser_error_string (&parser));
}
xp_printf (XP_TEXT("== Running the main method ==\n"));
m = xp_stx_lookup_method (&stx, n, XP_TEXT("main"));
if (m == stx.nil) {
@ -196,6 +202,7 @@ exit_program:
muntrace ();
#endif
/*
#ifdef __linux
{
char buf[1000];
@ -203,6 +210,7 @@ exit_program:
system (buf);
}
#endif
*/
return 0;
}

View File

@ -10,4 +10,4 @@ main
a := #abc print: 123 and: 2345.
#abc print: a and: a.
1234567.
^nil
^nil.

View File

@ -4,4 +4,5 @@ print: a1 and: a2
t1 := #abcdefg.
"a1 := 2341 arguments are not assignable"
t1 prim2: a2.
^9999.
self prim2: 2189.
^67891.