*** empty log message ***
This commit is contained in:
parent
e73fb585bd
commit
516fee2ea7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: bootstrp.c,v 1.22 2005-07-05 11:15:51 bacon Exp $
|
* $Id: bootstrp.c,v 1.23 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/bootstrp.h>
|
#include <xp/stx/bootstrp.h>
|
||||||
@ -472,7 +472,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xp_assert (class != stx->nil);
|
xp_assert (class != stx->nil);
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
|
||||||
class_obj->superclass = (p->superclass == XP_NULL)?
|
class_obj->superclass = (p->superclass == XP_NULL)?
|
||||||
stx->nil: xp_stx_lookup_class(stx,p->superclass);
|
stx->nil: xp_stx_lookup_class(stx,p->superclass);
|
||||||
|
|
||||||
@ -485,13 +485,13 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
xp_assert (superclass != stx->nil);
|
xp_assert (superclass != stx->nil);
|
||||||
|
|
||||||
meta = class_obj->header.class;
|
meta = class_obj->header.class;
|
||||||
meta_obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx,meta);
|
meta_obj = (xp_stx_metaclass_t*)XP_STX_OBJECT(stx,meta);
|
||||||
meta_obj->superclass = XP_STX_CLASS(stx,superclass);
|
meta_obj->superclass = XP_STX_CLASS(stx,superclass);
|
||||||
meta_obj->instance_class = class;
|
meta_obj->instance_class = class;
|
||||||
|
|
||||||
while (superclass != stx->nil) {
|
while (superclass != stx->nil) {
|
||||||
superclass_obj = (xp_stx_class_t*)
|
superclass_obj = (xp_stx_class_t*)
|
||||||
XP_STX_WORD_OBJECT(stx,superclass);
|
XP_STX_OBJECT(stx,superclass);
|
||||||
nfields +=
|
nfields +=
|
||||||
XP_STX_FROM_SMALLINT(superclass_obj->spec) >>
|
XP_STX_FROM_SMALLINT(superclass_obj->spec) >>
|
||||||
XP_STX_SPEC_INDEXABLE_BITS;
|
XP_STX_SPEC_INDEXABLE_BITS;
|
||||||
@ -518,7 +518,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
class = xp_stx_lookup_class(stx, p->name);
|
class = xp_stx_lookup_class(stx, p->name);
|
||||||
xp_assert (class != stx->nil);
|
xp_assert (class != stx->nil);
|
||||||
|
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
|
||||||
|
|
||||||
if (p->class_variables != XP_NULL) {
|
if (p->class_variables != XP_NULL) {
|
||||||
class_obj->class_variables =
|
class_obj->class_variables =
|
||||||
@ -542,7 +542,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
|
|
||||||
class = xp_stx_lookup_class(stx, p->name);
|
class = xp_stx_lookup_class(stx, p->name);
|
||||||
xp_assert (class != stx->nil);
|
xp_assert (class != stx->nil);
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
|
||||||
class_obj->subclasses = array;
|
class_obj->subclasses = array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
class = xp_stx_lookup_class(stx, p->name);
|
class = xp_stx_lookup_class(stx, p->name);
|
||||||
xp_assert (class != stx->nil);
|
xp_assert (class != stx->nil);
|
||||||
metaclass = XP_STX_CLASS(stx,class);
|
metaclass = XP_STX_CLASS(stx,class);
|
||||||
metaclass_obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx, metaclass);
|
metaclass_obj = (xp_stx_metaclass_t*)XP_STX_OBJECT(stx, metaclass);
|
||||||
metaclass_obj->subclasses = array;
|
metaclass_obj->subclasses = array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
ase/stx/bytecode.c
Normal file
79
ase/stx/bytecode.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* $Id: bytecode.c,v 1.1 2005-07-07 07:45:05 bacon Exp $
|
||||||
|
*/
|
||||||
|
#include <xp/stx/bytecode.h>
|
||||||
|
#include <xp/stx/class.h>
|
||||||
|
#include <xp/stx/method.h>
|
||||||
|
#include <xp/stx/hash.h>
|
||||||
|
|
||||||
|
static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data);
|
||||||
|
static int __decode2 (xp_stx_t* stx,
|
||||||
|
xp_stx_class_t* class_obj, xp_stx_method_t* method_obj);
|
||||||
|
|
||||||
|
int xp_stx_decode (xp_stx_t* stx, xp_word_t class)
|
||||||
|
{
|
||||||
|
xp_stx_class_t* class_obj;
|
||||||
|
|
||||||
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
|
||||||
|
if (class_obj->methods == stx->nil) return 0;
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
|
xp_stx_hash_traverse (stx, class_obj->methods, __decode1, class_obj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data)
|
||||||
|
{
|
||||||
|
xp_stx_method_t* method_obj;
|
||||||
|
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
|
||||||
|
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
|
||||||
|
|
||||||
|
xp_printf (XP_TEXT("Method: %s\n"), XP_STX_DATA(stx, key));
|
||||||
|
method_obj = (xp_stx_method_t*)XP_STX_OBJECT(stx, value);
|
||||||
|
__decode2 (stx, data, method_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __decode2 (xp_stx_t* stx,
|
||||||
|
xp_stx_class_t* class_obj, xp_stx_method_t* method_obj)
|
||||||
|
{
|
||||||
|
xp_stx_byte_object_t* bytecodes;
|
||||||
|
xp_word_t bytecode_size, pc = 0;
|
||||||
|
xp_byte_t code;
|
||||||
|
int opcode, operand;
|
||||||
|
|
||||||
|
bytecodes = XP_STX_BYTE_OBJECT(stx, method_obj->bytecodes);
|
||||||
|
bytecode_size = XP_STX_SIZE(stx, method_obj->bytecodes);
|
||||||
|
|
||||||
|
while (pc < bytecode_size) {
|
||||||
|
code = bytecodes->data[pc++];
|
||||||
|
|
||||||
|
opcode = (code & 0xF0) >> 4;
|
||||||
|
operand = code & 0x0F;
|
||||||
|
if (opcode > 0x9) {
|
||||||
|
if (pc >= bytecode_size) {
|
||||||
|
/* TODO: */
|
||||||
|
xp_printf (XP_TEXT("error in bytecodes\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
code = bytecodes->data[pc++];
|
||||||
|
operand |= (code << 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
xp_printf (XP_TEXT("opcode = %d, operand = %d\n"), 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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: bytecode.h,v 1.1 2005-07-05 11:38:01 bacon Exp $
|
* $Id: bytecode.h,v 1.2 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_BYTECODE_H_
|
#ifndef _XP_STX_BYTECODE_H_
|
||||||
#define _XP_STX_BYTECODE_H_
|
#define _XP_STX_BYTECODE_H_
|
||||||
|
|
||||||
#define PUSH_VARIABLE 0x1
|
#include <xp/stx/stx.h>
|
||||||
#define PUSH_ARGUMENT 0x2
|
|
||||||
#define PUSH_TEMPORARY 0x3
|
#define PUSH_VARIABLE 0x0
|
||||||
#define PUSH_LITERAL 0x4
|
#define PUSH_ARGUMENT 0x1
|
||||||
#define DO_PRIMITIVE 0xF
|
#define PUSH_TEMPORARY 0x2
|
||||||
|
#define PUSH_LITERAL 0x3
|
||||||
|
#define DO_SPECIAL 0x5
|
||||||
|
#define DO_PRIMITIVE 0x6
|
||||||
|
#define DO_PRIMITIVE_EXTENDED 0xF
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int xp_stx_decode (xp_stx_t* stx, xp_word_t class_idx);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: class.c,v 1.20 2005-07-05 11:15:51 bacon Exp $
|
* $Id: class.c,v 1.21 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/class.h>
|
#include <xp/stx/class.h>
|
||||||
@ -58,7 +58,7 @@ int xp_stx_get_instance_variable_index (
|
|||||||
xp_stx_class_t* class_obj;
|
xp_stx_class_t* class_obj;
|
||||||
xp_stx_char_object_t* string;
|
xp_stx_char_object_t* string;
|
||||||
|
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class_index);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class_index);
|
||||||
xp_assert (class_obj != XP_NULL);
|
xp_assert (class_obj != XP_NULL);
|
||||||
|
|
||||||
if (class_obj->superclass != stx->nil) {
|
if (class_obj->superclass != stx->nil) {
|
||||||
@ -95,7 +95,7 @@ xp_word_t xp_stx_lookup_class_variable (
|
|||||||
{
|
{
|
||||||
xp_stx_class_t* class_obj;
|
xp_stx_class_t* class_obj;
|
||||||
|
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class_index);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class_index);
|
||||||
xp_assert (class_obj != XP_NULL);
|
xp_assert (class_obj != XP_NULL);
|
||||||
|
|
||||||
if (class_obj->superclass != stx->nil) {
|
if (class_obj->superclass != stx->nil) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: hash.c,v 1.24 2005-07-05 15:01:57 bacon Exp $
|
* $Id: hash.c,v 1.25 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/hash.h>
|
#include <xp/stx/hash.h>
|
||||||
@ -14,7 +14,7 @@ xp_word_t xp_stx_new_pairlink (
|
|||||||
|
|
||||||
x = xp_stx_alloc_word_object (
|
x = xp_stx_alloc_word_object (
|
||||||
stx, XP_NULL, XP_STX_PAIRLINK_SIZE, XP_NULL, 0);
|
stx, XP_NULL, XP_STX_PAIRLINK_SIZE, XP_NULL, 0);
|
||||||
obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx, x);
|
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx, x);
|
||||||
obj->header.class = stx->class_pairlink;
|
obj->header.class = stx->class_pairlink;
|
||||||
obj->link = stx->nil;
|
obj->link = stx->nil;
|
||||||
obj->key = key;
|
obj->key = key;
|
||||||
@ -42,7 +42,7 @@ xp_word_t xp_stx_hash_lookup (
|
|||||||
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
|
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx,link);
|
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
|
||||||
if (obj->key == key) return link;
|
if (obj->key == key) return link;
|
||||||
link = obj->link;
|
link = obj->link;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ xp_word_t xp_stx_hash_lookup_symbol (
|
|||||||
link = XP_STX_WORDAT(stx,table,hash);
|
link = XP_STX_WORDAT(stx,table,hash);
|
||||||
|
|
||||||
while (link != stx->nil) {
|
while (link != stx->nil) {
|
||||||
obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx,link);
|
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
|
||||||
tmp = XP_STX_CHAR_OBJECT(stx,obj->key);
|
tmp = XP_STX_CHAR_OBJECT(stx,obj->key);
|
||||||
if (tmp->header.class == stx->class_symbol &&
|
if (tmp->header.class == stx->class_symbol &&
|
||||||
xp_strcmp (tmp->data, name) == 0) return link;
|
xp_strcmp (tmp->data, name) == 0) return link;
|
||||||
@ -110,7 +110,7 @@ void xp_stx_hash_insert (
|
|||||||
|
|
||||||
void xp_stx_hash_traverse (
|
void xp_stx_hash_traverse (
|
||||||
xp_stx_t* stx, xp_word_t table,
|
xp_stx_t* stx, xp_word_t table,
|
||||||
void (*func) (xp_stx_t*,xp_word_t))
|
void (*func) (xp_stx_t*,xp_word_t,void*), void* data)
|
||||||
{
|
{
|
||||||
xp_word_t link;
|
xp_word_t link;
|
||||||
xp_word_t size = XP_STX_SIZE(stx,table);
|
xp_word_t size = XP_STX_SIZE(stx,table);
|
||||||
@ -119,7 +119,7 @@ void xp_stx_hash_traverse (
|
|||||||
link = XP_STX_WORDAT(stx,table,size);
|
link = XP_STX_WORDAT(stx,table,size);
|
||||||
|
|
||||||
while (link != stx->nil) {
|
while (link != stx->nil) {
|
||||||
func (stx,link);
|
func (stx, link, data);
|
||||||
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
|
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: hash.h,v 1.9 2005-06-08 16:00:51 bacon Exp $
|
* $Id: hash.h,v 1.10 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_HASH_H_
|
#ifndef _XP_STX_HASH_H_
|
||||||
@ -39,7 +39,7 @@ void xp_stx_hash_insert (
|
|||||||
xp_word_t hash, xp_word_t key, xp_word_t value);
|
xp_word_t hash, xp_word_t key, xp_word_t value);
|
||||||
void xp_stx_hash_traverse (
|
void xp_stx_hash_traverse (
|
||||||
xp_stx_t* stx, xp_word_t table,
|
xp_stx_t* stx, xp_word_t table,
|
||||||
void (*func) (xp_stx_t*,xp_word_t));
|
void (*func) (xp_stx_t*,xp_word_t,void*), void* data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: interp.h,v 1.1 2005-05-13 16:45:55 bacon Exp $
|
* $Id: interp.h,v 1.2 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_INTERP_H_
|
#ifndef _XP_STX_INTERP_H_
|
||||||
#define _XP_STX_INTERP_H_
|
#define _XP_STX_INTERP_H_
|
||||||
|
|
||||||
|
#include <xp/stx/stx.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
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 method.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 = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
OUT = libxpstx.a
|
OUT = libxpstx.a
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: misc.h,v 1.11 2005-07-05 11:15:51 bacon Exp $
|
* $Id: misc.h,v 1.12 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_MISC_H_
|
#ifndef _XP_STX_MISC_H_
|
||||||
@ -13,6 +13,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define xp_assert assert
|
#define xp_assert assert
|
||||||
#define xp_malloc malloc
|
#define xp_malloc malloc
|
||||||
@ -32,6 +33,7 @@
|
|||||||
#include <xp/bas/stdarg.h>
|
#include <xp/bas/stdarg.h>
|
||||||
#include <xp/bas/ctype.h>
|
#include <xp/bas/ctype.h>
|
||||||
#include <xp/bas/string.h>
|
#include <xp/bas/string.h>
|
||||||
|
#include <xp/bas/stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__BORLANDC__) || defined(_MSC_VER)
|
#if defined(__BORLANDC__) || defined(_MSC_VER)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: object.c,v 1.35 2005-07-05 11:15:51 bacon Exp $
|
* $Id: object.c,v 1.36 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/object.h>
|
#include <xp/stx/object.h>
|
||||||
@ -192,7 +192,7 @@ xp_word_t xp_stx_instantiate (
|
|||||||
xp_word_t spec, nfields, new;
|
xp_word_t spec, nfields, new;
|
||||||
int indexable;
|
int indexable;
|
||||||
|
|
||||||
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class_index);
|
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class_index);
|
||||||
|
|
||||||
/* don't instantiate a metaclass whose instance must be
|
/* don't instantiate a metaclass whose instance must be
|
||||||
created in a different way */
|
created in a different way */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parser.c,v 1.55 2005-07-05 11:38:01 bacon Exp $
|
* $Id: parser.c,v 1.56 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/parser.h>
|
#include <xp/stx/parser.h>
|
||||||
@ -117,11 +117,8 @@ void xp_stx_parser_close (xp_stx_parser_t* parser)
|
|||||||
#define EMIT_CODE_TEST(parser,high,low) \
|
#define EMIT_CODE_TEST(parser,high,low) \
|
||||||
do { if (__emit_code_test(parser,high,low) == -1) return -1; } while (0)
|
do { if (__emit_code_test(parser,high,low) == -1) return -1; } while (0)
|
||||||
|
|
||||||
#define EMIT_CODE(parser,high,low) \
|
#define EMIT_CODE(parser,code) \
|
||||||
do { if (__emit_code(parser,high,low) == -1) { \
|
do { if (__emit_code(parser,code) == -1) return -1; } while(0)
|
||||||
parser->error_code = XP_STX_PARSER_ERROR_MEMORY; \
|
|
||||||
return -1; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define GET_CHAR(parser) \
|
#define GET_CHAR(parser) \
|
||||||
do { if (__get_char(parser) == -1) return -1; } while (0)
|
do { if (__get_char(parser) == -1) return -1; } while (0)
|
||||||
@ -158,6 +155,7 @@ const xp_char_t* xp_stx_parser_error_string (xp_stx_parser_t* parser)
|
|||||||
|
|
||||||
XP_TEXT("invalid primitive type"),
|
XP_TEXT("invalid primitive type"),
|
||||||
XP_TEXT("primitive number expected"),
|
XP_TEXT("primitive number expected"),
|
||||||
|
XP_TEXT("primitive number out of range"),
|
||||||
XP_TEXT("primitive not closed"),
|
XP_TEXT("primitive not closed"),
|
||||||
|
|
||||||
XP_TEXT("temporary list not closed"),
|
XP_TEXT("temporary list not closed"),
|
||||||
@ -251,9 +249,15 @@ static INLINE int __emit_code_test (
|
|||||||
|
|
||||||
static INLINE int __emit_code (xp_stx_parser_t* parser, xp_byte_t code)
|
static INLINE int __emit_code (xp_stx_parser_t* parser, xp_byte_t code)
|
||||||
{
|
{
|
||||||
return (xp_array_add_datum(&parser->bytecode, &code) == XP_NULL)? -1: 0;
|
if (xp_array_add_datum(&parser->bytecode, &code) == XP_NULL) {
|
||||||
|
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xp_stx_parser_parse_method (
|
int xp_stx_parser_parse_method (
|
||||||
xp_stx_parser_t* parser, xp_word_t method_class, void* input)
|
xp_stx_parser_t* parser, xp_word_t method_class, void* input)
|
||||||
{
|
{
|
||||||
@ -313,7 +317,7 @@ static int __finish_method (xp_stx_parser_t* parser)
|
|||||||
xp_assert (parser->bytecode.size != 0);
|
xp_assert (parser->bytecode.size != 0);
|
||||||
|
|
||||||
class_obj = (xp_stx_class_t*)
|
class_obj = (xp_stx_class_t*)
|
||||||
XP_STX_WORD_OBJECT(stx, parser->method_class);
|
XP_STX_OBJECT(stx, parser->method_class);
|
||||||
|
|
||||||
if (class_obj->methods == stx->nil) {
|
if (class_obj->methods == stx->nil) {
|
||||||
/* TODO: reconfigure method dictionary size */
|
/* TODO: reconfigure method dictionary size */
|
||||||
@ -327,7 +331,7 @@ static int __finish_method (xp_stx_parser_t* parser)
|
|||||||
|
|
||||||
method = xp_stx_instantiate(stx, stx->class_method,
|
method = xp_stx_instantiate(stx, stx->class_method,
|
||||||
XP_NULL, parser->literals, parser->literal_count);
|
XP_NULL, parser->literals, parser->literal_count);
|
||||||
method_obj = (xp_stx_method_t*)XP_STX_WORD_OBJECT(stx, method);
|
method_obj = (xp_stx_method_t*)XP_STX_OBJECT(stx, method);
|
||||||
|
|
||||||
/* TODO: text saving must be optional */
|
/* TODO: text saving must be optional */
|
||||||
/*method_obj->text = xp_stx_instantiate (
|
/*method_obj->text = xp_stx_instantiate (
|
||||||
@ -520,6 +524,8 @@ static int __parse_primitive (xp_stx_parser_t* parser)
|
|||||||
* <primitive> ::= '<' 'primitive:' number '>'
|
* <primitive> ::= '<' 'primitive:' number '>'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int prim_no;
|
||||||
|
|
||||||
if (!__is_primitive_opener(&parser->token)) return 0;
|
if (!__is_primitive_opener(&parser->token)) return 0;
|
||||||
GET_TOKEN (parser);
|
GET_TOKEN (parser);
|
||||||
|
|
||||||
@ -534,16 +540,26 @@ static int __parse_primitive (xp_stx_parser_t* parser)
|
|||||||
parser->error_code = XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER;
|
parser->error_code = XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
EMIT_CODE_TEST (parser, XP_TEXT("DO_PRIMITIVE"), parser->token.name.buffer);
|
|
||||||
|
|
||||||
/*
|
/*TODO: more checks the validity of the primitive number */
|
||||||
EMIT_CODE_TEST (parser, DO_PRIMITIVE);
|
if (!xp_stristype(parser->token.name.buffer, xp_isdigit)) {
|
||||||
EMIT_CODE_TEST (parser, parser->token.ivalue);
|
parser->error_code = XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
EMIT_CODE_TEST (parser, DO_PRIMITIVE_EXTENDED);
|
XP_STRTOI (prim_no, parser->token.name.buffer, XP_NULL, 10);
|
||||||
EMIT_CODE_TEST (parser, parser->token.ivalue);
|
if (prim_no < 0 || prim_no > 0x0FFF) {
|
||||||
EMIT_CODE_TEST (parser, parser->token.ivalue);
|
parser->error_code = XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE;
|
||||||
*/
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prim_no <= 0x0F) {
|
||||||
|
EMIT_CODE (parser, (DO_PRIMITIVE << 4) | prim_no);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EMIT_CODE (parser, (DO_PRIMITIVE_EXTENDED << 4) | (prim_no & 0x0F));
|
||||||
|
EMIT_CODE (parser, prim_no >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
GET_TOKEN (parser);
|
GET_TOKEN (parser);
|
||||||
if (!__is_primitive_closer(&parser->token)) {
|
if (!__is_primitive_closer(&parser->token)) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parser.h,v 1.29 2005-07-05 09:02:13 bacon Exp $
|
* $Id: parser.h,v 1.30 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_PARSER_H_
|
#ifndef _XP_STX_PARSER_H_
|
||||||
@ -32,6 +32,7 @@ enum
|
|||||||
|
|
||||||
XP_STX_PARSER_ERROR_PRIMITIVE_KEYWORD,
|
XP_STX_PARSER_ERROR_PRIMITIVE_KEYWORD,
|
||||||
XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER,
|
XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER,
|
||||||
|
XP_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE,
|
||||||
XP_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED,
|
XP_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED,
|
||||||
|
|
||||||
XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED,
|
XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: symbol.c,v 1.13 2005-07-05 09:02:13 bacon Exp $
|
* $Id: symbol.c,v 1.14 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/symbol.h>
|
#include <xp/stx/symbol.h>
|
||||||
@ -138,7 +138,7 @@ xp_word_t xp_stx_new_symbol_pp (
|
|||||||
}
|
}
|
||||||
|
|
||||||
void xp_stx_traverse_symbol_table (
|
void xp_stx_traverse_symbol_table (
|
||||||
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_word_t))
|
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_word_t,void*), void* data)
|
||||||
{
|
{
|
||||||
xp_word_t link;
|
xp_word_t link;
|
||||||
xp_word_t size;
|
xp_word_t size;
|
||||||
@ -151,7 +151,7 @@ void xp_stx_traverse_symbol_table (
|
|||||||
link = XP_STX_WORDAT(stx,table,size);
|
link = XP_STX_WORDAT(stx,table,size);
|
||||||
|
|
||||||
while (link != stx->nil) {
|
while (link != stx->nil) {
|
||||||
func (stx,XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_SYMBOL));
|
func (stx, XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_SYMBOL), data);
|
||||||
link = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK);
|
link = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: symbol.h,v 1.6 2005-06-08 16:00:51 bacon Exp $
|
* $Id: symbol.h,v 1.7 2005-07-07 07:45:05 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_SYMBOL_H_
|
#ifndef _XP_STX_SYMBOL_H_
|
||||||
@ -35,7 +35,7 @@ xp_word_t xp_stx_new_symbol_pp (
|
|||||||
xp_stx_t* stx, const xp_char_t* name,
|
xp_stx_t* stx, const xp_char_t* name,
|
||||||
const xp_char_t* prefix, const xp_char_t* postfix);
|
const xp_char_t* prefix, const xp_char_t* postfix);
|
||||||
void xp_stx_traverse_symbol_table (
|
void xp_stx_traverse_symbol_table (
|
||||||
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_word_t));
|
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_word_t,void*), void* data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <xp/stx/parser.h>
|
#include <xp/stx/parser.h>
|
||||||
#include <xp/stx/bootstrp.h>
|
#include <xp/stx/bootstrp.h>
|
||||||
#include <xp/stx/class.h>
|
#include <xp/stx/class.h>
|
||||||
|
#include <xp/stx/bytecode.h>
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#include <mcheck.h>
|
#include <mcheck.h>
|
||||||
@ -153,7 +154,13 @@ int xp_main (int argc, xp_char_t* argv[])
|
|||||||
if (xp_stx_parser_parse_method (&parser, n,
|
if (xp_stx_parser_parse_method (&parser, n,
|
||||||
(void*)XP_TEXT("test.st")) == -1) {
|
(void*)XP_TEXT("test.st")) == -1) {
|
||||||
xp_printf (XP_TEXT("parser error <%s>\n"),
|
xp_printf (XP_TEXT("parser error <%s>\n"),
|
||||||
xp_stx_parser_error_string (&parser));
|
xp_stx_parser_error_string (&parser));
|
||||||
|
}
|
||||||
|
|
||||||
|
xp_printf (XP_TEXT("== Decoded Methods ==\n"));
|
||||||
|
if (xp_stx_decode(&stx, n) == -1) {
|
||||||
|
xp_printf (XP_TEXT("parser error <%s>\n"),
|
||||||
|
xp_stx_parser_error_string (&parser));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
#include <xp/stx/class.h>
|
#include <xp/stx/class.h>
|
||||||
#include <xp/stx/hash.h>
|
#include <xp/stx/hash.h>
|
||||||
|
|
||||||
void print_symbol_names (xp_stx_t* stx, xp_word_t sym)
|
void print_symbol_names (xp_stx_t* stx, xp_word_t sym, void* unused)
|
||||||
{
|
{
|
||||||
xp_printf (XP_TEXT("%lu [%s]\n"), (unsigned long)sym, &XP_STX_CHARAT(stx,sym,0));
|
xp_printf (XP_TEXT("%lu [%s]\n"), (unsigned long)sym, &XP_STX_CHARAT(stx,sym,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_symbol_names_2 (xp_stx_t* stx, xp_word_t idx)
|
void print_symbol_names_2 (xp_stx_t* stx, xp_word_t idx, void* unused)
|
||||||
{
|
{
|
||||||
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
|
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
|
||||||
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
|
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
|
||||||
@ -167,10 +167,10 @@ int xp_main (int argc, xp_char_t* argv[])
|
|||||||
xp_printf (XP_TEXT("stx.false %lu\n"), (unsigned long)stx.false);
|
xp_printf (XP_TEXT("stx.false %lu\n"), (unsigned long)stx.false);
|
||||||
xp_printf (XP_TEXT("-------------\n"));
|
xp_printf (XP_TEXT("-------------\n"));
|
||||||
|
|
||||||
xp_stx_traverse_symbol_table (&stx, print_symbol_names);
|
xp_stx_traverse_symbol_table (&stx, print_symbol_names, XP_NULL);
|
||||||
xp_printf (XP_TEXT("-------------\n"));
|
xp_printf (XP_TEXT("-------------\n"));
|
||||||
|
|
||||||
xp_stx_hash_traverse (&stx, stx.smalltalk, print_symbol_names_2);
|
xp_stx_hash_traverse (&stx, stx.smalltalk, print_symbol_names_2, XP_NULL);
|
||||||
xp_printf (XP_TEXT("-------------\n"));
|
xp_printf (XP_TEXT("-------------\n"));
|
||||||
|
|
||||||
print_superclasses (&stx, XP_TEXT("Array"));
|
print_superclasses (&stx, XP_TEXT("Array"));
|
||||||
|
@ -3,7 +3,7 @@ perform: method with: x with: y with: z with: a with: b with: c
|
|||||||
|
|
||||||
| a b c d e f g |
|
| a b c d e f g |
|
||||||
|
|
||||||
< primitive: 10 >
|
< primitive: 21 >
|
||||||
"
|
"
|
||||||
a := 'this is ''good'.
|
a := 'this is ''good'.
|
||||||
a := #xxx niceMethod.
|
a := #xxx niceMethod.
|
||||||
|
Loading…
Reference in New Issue
Block a user