*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-07 16:32:37 +00:00
parent 5cb1474848
commit 839ca4a16c
6 changed files with 64 additions and 50 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bytecode.c,v 1.1 2005-07-07 07:45:05 bacon Exp $ * $Id: bytecode.c,v 1.2 2005-07-07 16:32:37 bacon Exp $
*/ */
#include <xp/stx/bytecode.h> #include <xp/stx/bytecode.h>
#include <xp/stx/class.h> #include <xp/stx/class.h>
@ -33,6 +33,26 @@ static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data)
__decode2 (stx, data, method_obj); __decode2 (stx, data, method_obj);
} }
static const xp_char_t* opcode_names[] =
{
XP_TEXT("PUSH_VARIABLE"),
XP_TEXT("PUSH_TEMPORARY"),
XP_TEXT("PUSH_LITERAL"),
XP_TEXT("DO_SPECIAL"),
XP_TEXT("DO_PRIMITIVE"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("PUSH_VARIABLE_EXTENDED"),
XP_TEXT("PUSH_TEMPORARY_EXTENDED"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("UNKNOWN"),
XP_TEXT("DO_PRIMITIVE_EXTENDED")
};
static int __decode2 (xp_stx_t* stx, static int __decode2 (xp_stx_t* stx,
xp_stx_class_t* class_obj, xp_stx_method_t* method_obj) xp_stx_class_t* class_obj, xp_stx_method_t* method_obj)
{ {
@ -59,18 +79,8 @@ static int __decode2 (xp_stx_t* stx,
operand |= (code << 4); operand |= (code << 4);
} }
xp_printf (XP_TEXT("opcode = %d, operand = %d\n"), opcode, operand); xp_printf (XP_TEXT("%s(0x%x), operand = %d\n"),
opcode_names[opcode], opcode, operand);
switch (opcode) {
case DO_PRIMITIVE:
xp_printf (XP_TEXT("DO_PRIMITIVE %d\n"), operand);
break;
case DO_PRIMITIVE_EXTENDED:
xp_printf (XP_TEXT("DO_PIRMITIVE_EXTENDED %d\n"), operand);
break;
default:
xp_printf (XP_TEXT("Unknown\n"));
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bytecode.h,v 1.2 2005-07-07 07:45:05 bacon Exp $ * $Id: bytecode.h,v 1.3 2005-07-07 16:32:37 bacon Exp $
*/ */
#ifndef _XP_STX_BYTECODE_H_ #ifndef _XP_STX_BYTECODE_H_
@ -7,13 +7,14 @@
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
#define PUSH_VARIABLE 0x0 #define PUSH_VARIABLE 0x0
#define PUSH_ARGUMENT 0x1 #define PUSH_TEMPORARY 0x1
#define PUSH_TEMPORARY 0x2 #define PUSH_LITERAL 0x2
#define PUSH_LITERAL 0x3 #define DO_SPECIAL 0x3
#define DO_SPECIAL 0x5 #define DO_PRIMITIVE 0x4
#define DO_PRIMITIVE 0x6 #define PUSH_VARIABLE_EXTENDED 0xA
#define DO_PRIMITIVE_EXTENDED 0xF #define PUSH_TEMPORARY_EXTENDED 0xB
#define DO_PRIMITIVE_EXTENDED 0xF
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -1,7 +1,7 @@
SRCS = stx.c memory.c object.c symbol.c class.c \ SRCS = stx.c memory.c object.c symbol.c class.c \
hash.c misc.c context.c name.c token.c parser.c bootstrp.c hash.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c
OBJS = stx.obj memory.obj object.obj symbol.obj class.obj \ OBJS = stx.obj memory.obj object.obj symbol.obj class.obj \
hash.obj misc.obj context.obj name.obj token.obj parser.obj bootstrp.obj hash.obj misc.obj context.obj name.obj token.obj parser.obj bootstrp.obj bytecode.obj
OUT = xpstx.lib OUT = xpstx.lib
CC = lcc CC = lcc

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.h,v 1.12 2005-07-07 07:45:05 bacon Exp $ * $Id: misc.h,v 1.13 2005-07-07 16:32:37 bacon Exp $
*/ */
#ifndef _XP_STX_MISC_H_ #ifndef _XP_STX_MISC_H_
@ -7,6 +7,9 @@
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
/* TODO: remove this header later */
#include <xp/bas/stdio.h>
#ifdef _DOS #ifdef _DOS
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.c,v 1.56 2005-07-07 07:45:05 bacon Exp $ * $Id: parser.c,v 1.57 2005-07-07 16:32:37 bacon Exp $
*/ */
#include <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -86,8 +86,8 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
parser->stx = stx; parser->stx = stx;
parser->error_code = XP_STX_PARSER_ERROR_NONE; parser->error_code = XP_STX_PARSER_ERROR_NONE;
parser->argument_count = 0;
parser->temporary_count = 0; parser->temporary_count = 0;
parser->argument_count = 0;
parser->literal_count = 0; parser->literal_count = 0;
parser->curc = XP_CHAR_EOF; parser->curc = XP_CHAR_EOF;
@ -100,12 +100,10 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
void xp_stx_parser_close (xp_stx_parser_t* parser) void xp_stx_parser_close (xp_stx_parser_t* parser)
{ {
while (parser->argument_count > 0) {
xp_free (parser->argument[--parser->argument_count]);
}
while (parser->temporary_count > 0) { while (parser->temporary_count > 0) {
xp_free (parser->temporary[--parser->temporary_count]); xp_free (parser->temporaries[--parser->temporary_count]);
} }
parser->argument_count = 0;
xp_array_close (&parser->bytecode); xp_array_close (&parser->bytecode);
xp_stx_name_close (&parser->method_name); xp_stx_name_close (&parser->method_name);
@ -290,12 +288,10 @@ static int __parse_method (
xp_stx_name_clear (&parser->method_name); xp_stx_name_clear (&parser->method_name);
xp_array_clear (&parser->bytecode); xp_array_clear (&parser->bytecode);
while (parser->argument_count > 0) {
xp_free (parser->argument[--parser->argument_count]);
}
while (parser->temporary_count > 0) { while (parser->temporary_count > 0) {
xp_free (parser->temporary[--parser->temporary_count]); xp_free (parser->temporaries[--parser->temporary_count]);
} }
parser->argument_count = 0;
parser->literal_count = 0; parser->literal_count = 0;
if (__parse_message_pattern(parser) == -1) return -1; if (__parse_message_pattern(parser) == -1) return -1;
@ -381,6 +377,7 @@ static int __parse_message_pattern (xp_stx_parser_t* parser)
n = -1; n = -1;
} }
parser->temporary_count = parser->argument_count;
return n; return n;
} }
@ -414,15 +411,15 @@ static int __parse_binary_pattern (xp_stx_parser_t* parser)
return -1; return -1;
} }
if (parser->argument_count >= xp_countof(parser->argument)) { if (parser->argument_count >= xp_countof(parser->temporaries)) {
parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS; parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS;
return -1; return -1;
} }
/* TODO: check for duplicate entries...in instvars */ /* TODO: check for duplicate entries...in instvars */
parser->argument[parser->argument_count] = parser->temporaries[parser->argument_count] =
xp_stx_token_yield (&parser->token, 0); xp_stx_token_yield (&parser->token, 0);
if (parser->argument[parser->argument_count] == XP_NULL) { if (parser->temporaries[parser->argument_count] == XP_NULL) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY; parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1; return -1;
} }
@ -452,18 +449,19 @@ static int __parse_keyword_pattern (xp_stx_parser_t* parser)
return -1; return -1;
} }
if (parser->argument_count >= xp_countof(parser->argument)) { if (parser->argument_count >= xp_countof(parser->temporaries)) {
parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS; parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS;
return -1; return -1;
} }
parser->argument[parser->argument_count] = parser->temporaries[parser->argument_count] =
xp_stx_token_yield (&parser->token, 0); xp_stx_token_yield (&parser->token, 0);
if (parser->argument[parser->argument_count] == XP_NULL) { if (parser->temporaries[parser->argument_count] == XP_NULL) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY; parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1; return -1;
} }
/* TODO: check for duplicate entries...in instvars/arguments */
/* TODO: check for duplicate entries...in instvars/arguments */
parser->argument_count++; parser->argument_count++;
GET_TOKEN (parser); GET_TOKEN (parser);
@ -487,7 +485,7 @@ static int __parse_temporaries (xp_stx_parser_t* parser)
GET_TOKEN (parser); GET_TOKEN (parser);
while (parser->token.type == XP_STX_TOKEN_IDENT) { while (parser->token.type == XP_STX_TOKEN_IDENT) {
if (parser->temporary_count >= xp_countof(parser->temporary)) { if (parser->temporary_count >= xp_countof(parser->temporaries)) {
parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES; parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES;
return -1; return -1;
} }
@ -497,14 +495,14 @@ static int __parse_temporaries (xp_stx_parser_t* parser)
return -1; return -1;
} }
parser->temporary[parser->temporary_count] = parser->temporaries[parser->temporary_count] =
xp_stx_token_yield (&parser->token, 0); xp_stx_token_yield (&parser->token, 0);
if (parser->temporary[parser->temporary_count] == XP_NULL) { if (parser->temporaries[parser->temporary_count] == XP_NULL) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY; parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1; return -1;
} }
/* TODO: check for duplicate entries...in instvars/arguments/temporaries */ /* TODO: check for duplicate entries...in instvars/arguments/temporaries */
parser->temporary_count++; parser->temporary_count++;
GET_TOKEN (parser); GET_TOKEN (parser);
@ -554,9 +552,11 @@ static int __parse_primitive (xp_stx_parser_t* parser)
} }
if (prim_no <= 0x0F) { if (prim_no <= 0x0F) {
EMIT_CODE_TEST (parser, XP_TEXT("DO_PRIMITIVE"), parser->token.name.buffer);
EMIT_CODE (parser, (DO_PRIMITIVE << 4) | prim_no); EMIT_CODE (parser, (DO_PRIMITIVE << 4) | prim_no);
} }
else { else {
EMIT_CODE_TEST (parser, XP_TEXT("DO_PRIMITIVE_EXTENDED"), parser->token.name.buffer);
EMIT_CODE (parser, (DO_PRIMITIVE_EXTENDED << 4) | (prim_no & 0x0F)); EMIT_CODE (parser, (DO_PRIMITIVE_EXTENDED << 4) | (prim_no & 0x0F));
EMIT_CODE (parser, prim_no >> 4); EMIT_CODE (parser, prim_no >> 4);
} }
@ -698,8 +698,8 @@ static int __parse_assignment (
xp_word_t i; xp_word_t i;
xp_stx_t* stx = parser->stx; xp_stx_t* stx = parser->stx;
for (i = 0; i < parser->temporary_count; i++) { for (i = parser->argument_count; i < parser->temporary_count; i++) {
if (xp_strcmp (target, parser->temporary[i]) == 0) { if (xp_strcmp (target, parser->temporaries[i]) == 0) {
xp_char_t buf[100]; xp_char_t buf[100];
if (__parse_expression(parser) == -1) return -1; if (__parse_expression(parser) == -1) return -1;
xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i); xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.h,v 1.30 2005-07-07 07:45:05 bacon Exp $ * $Id: parser.h,v 1.31 2005-07-07 16:32:37 bacon Exp $
*/ */
#ifndef _XP_STX_PARSER_H_ #ifndef _XP_STX_PARSER_H_
@ -68,10 +68,10 @@ struct xp_stx_parser_t
xp_word_t method_class; xp_word_t method_class;
xp_stx_name_t method_name; xp_stx_name_t method_name;
xp_char_t* argument[32]; xp_char_t* temporaries[256]; /* TODO: different size? or dynamic? */
xp_word_t argument_count; xp_word_t argument_count;
xp_char_t* temporary[32];
xp_word_t temporary_count; xp_word_t temporary_count;
xp_word_t literals[256]; /* TODO: make it a dynamic array */ xp_word_t literals[256]; /* TODO: make it a dynamic array */
xp_word_t literal_count; xp_word_t literal_count;