*** empty log message ***
This commit is contained in:
parent
a3f36e0c9b
commit
d1c0760ec2
18
ase/stx/array.c
Normal file
18
ase/stx/array.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* $Id: array.c,v 1.1 2005-08-15 16:03:57 bacon Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <xp/stx/array.h>
|
||||||
|
#include <xp/stx/object.h>
|
||||||
|
#include <xp/bas/assert.h>
|
||||||
|
|
||||||
|
xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size)
|
||||||
|
{
|
||||||
|
xp_word_t x;
|
||||||
|
|
||||||
|
xp_assert (stx->class_array != stx->nil);
|
||||||
|
x = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, size);
|
||||||
|
XP_STX_CLASS(stx,x) = stx->class_array;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
21
ase/stx/array.h
Normal file
21
ase/stx/array.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* $Id: array.h,v 1.1 2005-08-15 16:03:57 bacon Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _XP_STX_ARRAY_H_
|
||||||
|
#define _XP_STX_ARRAY_H_
|
||||||
|
|
||||||
|
#include <xp/stx/stx.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: bootstrp.c,v 1.30 2005-08-11 09:57:54 bacon Exp $
|
* $Id: bootstrp.c,v 1.31 2005-08-15 16:03:57 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/bootstrp.h>
|
#include <xp/stx/bootstrp.h>
|
||||||
@ -273,17 +273,6 @@ static class_info_t class_info[] =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xp_word_t INLINE __new_array (xp_stx_t* stx, xp_word_t size)
|
|
||||||
{
|
|
||||||
xp_word_t x;
|
|
||||||
|
|
||||||
xp_assert (stx->class_array != stx->nil);
|
|
||||||
x = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, size);
|
|
||||||
XP_STX_CLASS(stx,x) = stx->class_array;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
xp_word_t INLINE __new_string (xp_stx_t* stx, const xp_char_t* str)
|
xp_word_t INLINE __new_string (xp_stx_t* stx, const xp_char_t* str)
|
||||||
{
|
{
|
||||||
xp_word_t x;
|
xp_word_t x;
|
||||||
@ -310,6 +299,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
|||||||
stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray"));
|
stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray"));
|
||||||
stx->class_string = xp_stx_new_class (stx, XP_TEXT("String"));
|
stx->class_string = xp_stx_new_class (stx, XP_TEXT("String"));
|
||||||
stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character"));
|
stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character"));
|
||||||
|
stx->class_context = xp_stx_new_class (stx, XP_TEXT("Context"));
|
||||||
stx->class_system_dictionary =
|
stx->class_system_dictionary =
|
||||||
xp_stx_new_class (stx, XP_TEXT("SystemDictionary"));
|
xp_stx_new_class (stx, XP_TEXT("SystemDictionary"));
|
||||||
stx->class_method =
|
stx->class_method =
|
||||||
@ -329,7 +319,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
|||||||
/* for some fun here */
|
/* for some fun here */
|
||||||
{
|
{
|
||||||
xp_word_t array;
|
xp_word_t array;
|
||||||
array = __new_array (stx, 1);
|
array = xp_stx_new_array (stx, 1);
|
||||||
XP_STX_WORD_AT(stx,array,0) = object_meta;
|
XP_STX_WORD_AT(stx,array,0) = object_meta;
|
||||||
XP_STX_WORD_AT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
|
XP_STX_WORD_AT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
|
||||||
}
|
}
|
||||||
@ -541,7 +531,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
/* fill subclasses */
|
/* fill subclasses */
|
||||||
for (p = class_info; p->name != XP_NULL; p++) {
|
for (p = class_info; p->name != XP_NULL; p++) {
|
||||||
n = __count_subclasses (p->name);
|
n = __count_subclasses (p->name);
|
||||||
array = __new_array (stx, n);
|
array = xp_stx_new_array (stx, n);
|
||||||
__set_subclasses (stx, XP_STX_DATA(stx,array), p->name);
|
__set_subclasses (stx, XP_STX_DATA(stx,array), p->name);
|
||||||
|
|
||||||
class = xp_stx_lookup_class(stx, p->name);
|
class = xp_stx_lookup_class(stx, p->name);
|
||||||
@ -553,7 +543,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
|
|||||||
/* fill subclasses for metaclasses */
|
/* fill subclasses for metaclasses */
|
||||||
for (p = class_info; p->name != XP_NULL; p++) {
|
for (p = class_info; p->name != XP_NULL; p++) {
|
||||||
n = __count_subclasses (p->name);
|
n = __count_subclasses (p->name);
|
||||||
array = __new_array (stx, n);
|
array = xp_stx_new_array (stx, n);
|
||||||
__set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name);
|
__set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name);
|
||||||
|
|
||||||
class = xp_stx_lookup_class(stx, p->name);
|
class = xp_stx_lookup_class(stx, p->name);
|
||||||
|
141
ase/stx/interp.c
141
ase/stx/interp.c
@ -1,105 +1,94 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: interp.c,v 1.4 2005-06-08 16:00:51 bacon Exp $
|
* $Id: interp.c,v 1.5 2005-08-15 16:03:57 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/interp.h>
|
#include <xp/stx/interp.h>
|
||||||
|
#include <xp/stx/method.h>
|
||||||
|
#include <xp/stx/object.h>
|
||||||
|
#include <xp/stx/array.h>
|
||||||
|
|
||||||
#define XP_STX_PROCESS_SIZE 3
|
#define XP_STX_CONTEXT_SIZE 4
|
||||||
#define XP_STX_PROCESS_STACK 0
|
#define XP_STX_CONTEXT_STACK 0
|
||||||
#define XP_STX_PROCESS_STACK_TOP 1
|
#define XP_STX_CONTEXT_STACK_TOP 1
|
||||||
#define XP_STX_PROCESS_LINK 2
|
#define XP_STX_CONTEXT_METHOD 2
|
||||||
|
#define XP_STX_CONTEXT_IP 3
|
||||||
|
|
||||||
#define XP_STX_CONTEXT_SIZE 6
|
struct xp_stx_context_t
|
||||||
#define XP_STX_PROCESS_LINK 0
|
|
||||||
#define XP_STX_PROCESS_METHOD 1
|
|
||||||
#define XP_STX_PROCESS_ARGUMENTS 2
|
|
||||||
#define XP_STX_PROCESS_TEMPORARIES 3
|
|
||||||
|
|
||||||
typedef int (*byte_code_func_t) (xp_stx_t*
|
|
||||||
|
|
||||||
static byte_code_func_t byte_code_funcs[] =
|
|
||||||
{
|
{
|
||||||
XP_NULL,
|
xp_stx_objhdr_t header;
|
||||||
push_instance,
|
xp_word_t stack;
|
||||||
push_argyment,
|
xp_word_t stack_top;
|
||||||
push_temporary,
|
xp_word_t method;
|
||||||
push_literal,
|
xp_word_t ip;
|
||||||
push_constant,
|
|
||||||
store_instance,
|
|
||||||
store_temporary,
|
|
||||||
send_message,
|
|
||||||
send_unary,
|
|
||||||
send_binary,
|
|
||||||
XP_NULL,
|
|
||||||
do_primitive,
|
|
||||||
XP_NULL,
|
|
||||||
do_special
|
|
||||||
};
|
};
|
||||||
|
|
||||||
xp_word_t xp_stx_new_method (xp_stx_t* stx)
|
typedef struct xp_stx_context_t xp_stx_context_t;
|
||||||
{
|
|
||||||
xp_word_t method;
|
|
||||||
method = xp_stx_alloc_object(XP_STX_METHOD_SIZE);
|
|
||||||
|
|
||||||
return method;
|
xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t method)
|
||||||
}
|
|
||||||
|
|
||||||
xp_word_t xp_stx_new_context (xp_stx_t* stx,
|
|
||||||
xp_word_t method, xp_word_t args, xp_word_t temp)
|
|
||||||
{
|
{
|
||||||
xp_word_t context;
|
xp_word_t context;
|
||||||
|
xp_stx_context_t* ctxobj;
|
||||||
|
|
||||||
context = xp_stx_alloc_object(XP_STX_CONTEXT_SIZE);
|
context = xp_stx_alloc_word_object(
|
||||||
|
stx, XP_NULL, XP_STX_CONTEXT_SIZE, XP_NULL, 0);
|
||||||
XP_STX_CLASS(stx,context) = stx->class_context;
|
XP_STX_CLASS(stx,context) = stx->class_context;
|
||||||
XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD) = method;
|
|
||||||
XP_STX_AT(stx,context,XP_STX_CONTEXT_ARGUMENTS) = args;
|
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
||||||
XP_STX_AT(stx,context,XP_STX_CONTEXT_TEMPORARIES) = temp;
|
ctxobj->stack = xp_stx_new_array (stx, 256); /* TODO: initial stack size */
|
||||||
|
ctxobj->stack_top = XP_STX_TO_SMALLINT(0);
|
||||||
|
ctxobj->method = method;
|
||||||
|
ctxobj->ip = XP_STX_TO_SMALLINT(0);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
xp_word_t xp_stx_new_process (xp_stx_t* stx, xp_word_t method)
|
int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
|
||||||
{
|
{
|
||||||
xp_word_t process, stx;
|
xp_stx_context_t* ctxobj;
|
||||||
|
xp_stx_method_t* mthobj;
|
||||||
|
xp_stx_byte_object_t* bytecodes;
|
||||||
|
xp_word_t bytecode_size;
|
||||||
|
xp_word_t* literals;
|
||||||
|
xp_word_t pc = 0;
|
||||||
|
int code, next, next2;
|
||||||
|
|
||||||
process = xp_stx_alloc_object(XP_STX_PROCESS_SIZE);
|
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
||||||
stack = xp_new_array(stx,50);
|
mthobj = (xp_stx_method_t*)XP_STX_OBJECT(stx, ctxobj->method);
|
||||||
|
|
||||||
XP_STX_CLASS(stx,process) = stx->class_process;
|
literals = mthobj->literals;
|
||||||
XP_STX_AT(stx,process,XP_STX_PROCESS_STACK) = stack;
|
bytecodes = XP_STX_BYTE_OBJECT(stx, mthobj->bytecodes);
|
||||||
XP_STX_AT(stx,process,XP_STX_PROCESS_STACKTOP) = XP_STX_FROM_SMALLINT(6);
|
bytecode_size = XP_STX_SIZE(stx, mthobj->bytecodes);
|
||||||
XP_STX_AT(stx,process,XP_STX_PROCESS_LINK) = XP_STX_FROM_SMALLINT(1);
|
|
||||||
|
|
||||||
XP_STX_AT(stx,stack,0) = stx->nil; /* argument */
|
while (pc < bytecode_size) {
|
||||||
XP_STX_AT(stx,stack,1) = XP_STX_FROM_SMALLINT(0); /* previous link */
|
code = bytecodes->data[pc++];
|
||||||
XP_STX_AT(stx,stack,2) = stx->nil; /* context */
|
|
||||||
XP_STX_AT(stx,stack,3) = XP_STX_FROM_SMALLINT(1); /* return point */
|
|
||||||
XP_STX_AT(stx,stack,4) = method;
|
|
||||||
XP_STX_AT(stx,stack,5) = XP_STX_FROM_SMALLINT(1); /* byte offset */
|
|
||||||
|
|
||||||
return process;
|
if (code >= 0x00 && code <= 0x3F) {
|
||||||
|
/* stack - push */
|
||||||
|
int what = code >> 4;
|
||||||
|
int index = code & 0x0F;
|
||||||
|
|
||||||
|
switch (what) {
|
||||||
|
case 0: /* receiver variable */
|
||||||
|
break;
|
||||||
|
case 1: /* temporary variable */
|
||||||
|
break;
|
||||||
|
case 2: /* literal constant */
|
||||||
|
break;
|
||||||
|
case 3: /* literal variable */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xp_stx_execute (xp_stx_t* stx, xp_word_t process)
|
|
||||||
{
|
|
||||||
int low, high;
|
|
||||||
byte_code_func_t bcfunc;
|
|
||||||
|
|
||||||
stack = XP_STX_AT(stx,process,XP_PROCESS_STACK);
|
|
||||||
stack_top = XP_STX_AT(stx,process,XP_PROCESS_STACK_TOP);
|
|
||||||
link = XP_STX_AT(stx,process,XP_PROCESS_LINK);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
low = (high = nextByte(&es)) & 0x0F;
|
|
||||||
high >>= 4;
|
|
||||||
if(high == 0) {
|
|
||||||
high = low;
|
|
||||||
low = nextByte(&es);
|
|
||||||
}
|
}
|
||||||
|
else if (code >= 0x40 && code <= 0x5F) {
|
||||||
|
/* stack - store */
|
||||||
|
int what = code >> 4;
|
||||||
|
int index = code & 0x0F;
|
||||||
|
|
||||||
bcfunc = byte_code_funcs[high];
|
switch (what) {
|
||||||
if (bcfunc != XP_NULL) {
|
case 4: /* receiver variable */
|
||||||
bcfunc (stx, low);
|
break;
|
||||||
|
case 5: /* temporary location */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
SRCS = \
|
SRCS = \
|
||||||
stx.c memory.c object.c symbol.c class.c \
|
stx.c memory.c object.c symbol.c class.c array.c \
|
||||||
dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c
|
dict.c misc.c context.c name.c token.c parser.c bootstrp.c \
|
||||||
|
bytecode.c interp.c
|
||||||
OBJS = $(SRCS:.c=.obj)
|
OBJS = $(SRCS:.c=.obj)
|
||||||
OUT = xpstx.lib
|
OUT = xpstx.lib
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
SRCS = stx.c memory.c object.c symbol.c class.c \
|
SRCS = stx.c memory.c object.c symbol.c class.c array.c \
|
||||||
dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c
|
dict.c misc.c context.c name.c token.c parser.c bootstrp.c \
|
||||||
|
bytecode.c interp.c
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
OUT = libxpstx.a
|
OUT = libxpstx.a
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parser.c,v 1.67 2005-08-11 16:16:04 bacon Exp $
|
* $Id: parser.c,v 1.68 2005-08-15 16:03:57 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/parser.h>
|
#include <xp/stx/parser.h>
|
||||||
@ -844,7 +844,6 @@ static int __parse_expression (xp_stx_parser_t* parser)
|
|||||||
if (__parse_basic_expression(parser, XP_NULL) == -1) return -1;
|
if (__parse_basic_expression(parser, XP_NULL) == -1) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -988,9 +987,10 @@ static int __parse_primary_ident (xp_stx_parser_t* parser, const xp_char_t* iden
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
if (xp_strcmp(token->name.buffer, XP_TEXT("self")) == 0) {
|
if (xp_strcmp(token->name.buffer, XP_TEXT("self")) == 0) {
|
||||||
EMIT_PUSH_LITERAL (parser, i);
|
EMIT_CODE (parser, PUSH_SELF);
|
||||||
}
|
}
|
||||||
else if (xp_strcmp(token->name.buffer, XP_TEXT("super")) == 0) {
|
else if (xp_strcmp(token->name.buffer, XP_TEXT("super")) == 0) {
|
||||||
|
EMIT_CODE (parser, PUSH_SUPER);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (xp_strcmp(ident, XP_TEXT("nil")) == 0) {
|
if (xp_strcmp(ident, XP_TEXT("nil")) == 0) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: stx.c,v 1.36 2005-08-11 09:57:54 bacon Exp $
|
* $Id: stx.c,v 1.37 2005-08-15 16:03:57 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/stx.h>
|
#include <xp/stx/stx.h>
|
||||||
@ -44,9 +44,11 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity)
|
|||||||
|
|
||||||
stx->class_object = XP_STX_NIL;
|
stx->class_object = XP_STX_NIL;
|
||||||
stx->class_class = XP_STX_NIL;
|
stx->class_class = XP_STX_NIL;
|
||||||
stx->class_bytearray = XP_STX_NIL;
|
|
||||||
stx->class_array = XP_STX_NIL;
|
stx->class_array = XP_STX_NIL;
|
||||||
|
stx->class_bytearray = XP_STX_NIL;
|
||||||
stx->class_string = XP_STX_NIL;
|
stx->class_string = XP_STX_NIL;
|
||||||
|
stx->class_character = XP_STX_NIL;
|
||||||
|
stx->class_context = XP_STX_NIL;
|
||||||
stx->class_system_dictionary = XP_STX_NIL;
|
stx->class_system_dictionary = XP_STX_NIL;
|
||||||
stx->class_method = XP_STX_NIL;
|
stx->class_method = XP_STX_NIL;
|
||||||
stx->class_smallinteger = XP_STX_NIL;
|
stx->class_smallinteger = XP_STX_NIL;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: stx.h,v 1.40 2005-08-11 09:57:54 bacon Exp $
|
* $Id: stx.h,v 1.41 2005-08-15 16:03:57 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_STX_H_
|
#ifndef _XP_STX_STX_H_
|
||||||
@ -87,6 +87,7 @@ struct xp_stx_t
|
|||||||
xp_word_t class_bytearray;
|
xp_word_t class_bytearray;
|
||||||
xp_word_t class_string;
|
xp_word_t class_string;
|
||||||
xp_word_t class_character;
|
xp_word_t class_character;
|
||||||
|
xp_word_t class_context;
|
||||||
xp_word_t class_system_dictionary;
|
xp_word_t class_system_dictionary;
|
||||||
xp_word_t class_method;
|
xp_word_t class_method;
|
||||||
xp_word_t class_smallinteger;
|
xp_word_t class_smallinteger;
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
main
|
main
|
||||||
|
| a |
|
||||||
|
a := nil.
|
||||||
^nil
|
^nil
|
||||||
|
Loading…
Reference in New Issue
Block a user