*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-19 16:41:10 +00:00
parent 716fd0f03d
commit 4f49c6d2db
15 changed files with 154 additions and 60 deletions

17
ase/conf_dos.h Normal file
View File

@ -0,0 +1,17 @@
#define XP_ENDIAN_LITTLE
#define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2
#define SIZEOF_INT 2
#define SIZEOF_LONG 4
#define SIZEOF_LONG_LONG 0
#define SIZEOF___INT8 1
#define SIZEOF___INT16 2
#define SIZEOF___INT32 4
#define SIZEOF___INT64 0
#define SIZEOF___INT128 0
#define SIZEOF_VOID_P 4
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 4
#define SIZEOF_LONG_DOUBLE 0

View File

@ -1,5 +1,5 @@
/*
* $Id: context.c,v 1.3 2005-05-18 04:01:51 bacon Exp $
* $Id: context.c,v 1.4 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/context.h>
@ -48,7 +48,11 @@ int xp_stx_run_context (xp_stx_t* stx, xp_stx_word_t context)
/* check_process_switch (); // hopefully */
byte = __fetch_byte (stx, context);
#ifdef _DOS
printf (XP_TEXT("code: %x\n"), byte);
#else
xp_printf (XP_TEXT("code: %x\n"), byte);
#endif
switch (byte) {
case PUSH_OBJECT:

View File

@ -1,11 +1,10 @@
/*
* $Id: hash.c,v 1.13 2005-05-19 15:04:21 bacon Exp $
* $Id: hash.c,v 1.14 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/hash.h>
#include <xp/stx/object.h>
#include <xp/stx/misc.h>
#include <xp/bas/assert.h>
xp_stx_word_t xp_stx_new_pairlink (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
@ -28,7 +27,7 @@ xp_stx_word_t xp_stx_hash_lookup (
{
xp_stx_word_t link;
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
xp_stx_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,table,hash);
@ -47,7 +46,7 @@ void xp_stx_hash_insert (
{
xp_stx_word_t link, next;
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
xp_stx_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,table,hash);

View File

@ -3,7 +3,7 @@ OBJS = stx.obj memory.obj object.obj symbol.obj hash.obj misc.obj context.obj
OUT = xpstx.lib
CC = lcc
CFLAGS = -I../.. -g2
CFLAGS = -I../.. -A -ansic -libcdll
LDFLAGS =
LIBS =

21
ase/stx/makefile.tcc Normal file
View File

@ -0,0 +1,21 @@
SRCS = \
stx.c memory.c object.c symbol.c hash.c misc.c context.c
OBJS = $(SRCS:.c=.obj)
OUT = xpstx.lib
CC = c:\tc\tcc
CFLAGS = -I..\.. -D_DOS -mh -w
all: $(OBJS)
c:\tc\tlib $(OUT) @&&!
+-$(**: = &^
+-)
!
clean:
del $(OBJS) $(OUT) *.obj
.SUFFIXES: .c .obj
.c.obj:
$(CC) $(CFLAGS) -c $<

View File

@ -1,10 +1,9 @@
/*
* $Id: memory.c,v 1.9 2005-05-19 15:04:21 bacon Exp $
* $Id: memory.c,v 1.10 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/memory.h>
#include <xp/bas/memory.h>
#include <xp/bas/assert.h>
#include <xp/stx/misc.h>
xp_stx_memory_t* xp_stx_memory_open (
xp_stx_memory_t* mem, xp_stx_word_t capacity)
@ -12,18 +11,18 @@ xp_stx_memory_t* xp_stx_memory_open (
xp_stx_object_t** slots;
xp_stx_word_t n;
xp_assert (capacity > 0);
xp_stx_assert (capacity > 0);
if (mem == XP_NULL) {
mem = (xp_stx_memory_t*)xp_malloc(xp_sizeof(xp_stx_memory_t));
mem = (xp_stx_memory_t*)xp_stx_malloc(xp_sizeof(xp_stx_memory_t));
if (mem == XP_NULL) return XP_NULL;
mem->__malloced = xp_true;
}
else mem->__malloced = xp_false;
slots = (xp_stx_object_t**)xp_malloc (
slots = (xp_stx_object_t**)xp_stx_malloc (
capacity * xp_sizeof(xp_stx_object_t*));
if (slots == XP_NULL) {
if (mem->__malloced) xp_free (mem);
if (mem->__malloced) xp_stx_free (mem);
mem = XP_NULL;
}
@ -44,11 +43,11 @@ void xp_stx_memory_close (xp_stx_memory_t* mem)
{
/* TODO: free all linked objects... */
xp_free (mem->slots);
xp_stx_free (mem->slots);
mem->capacity = 0;
mem->slots = XP_NULL;
mem->free = XP_NULL;
if (mem->__malloced) xp_free (mem);
if (mem->__malloced) xp_stx_free (mem);
}
void xp_stx_memory_gc (xp_stx_memory_t* mem)
@ -67,10 +66,10 @@ xp_stx_word_t xp_stx_memory_alloc (xp_stx_memory_t* mem, xp_stx_word_t nbytes)
if (mem->free == XP_NULL) return mem->capacity;;
}
object = (xp_stx_object_t*)xp_malloc (nbytes);
object = (xp_stx_object_t*)xp_stx_malloc (nbytes);
if (object == XP_NULL) {
xp_stx_memory_gc (mem);
object = (xp_stx_object_t*)xp_malloc (nbytes);
object = (xp_stx_object_t*)xp_stx_malloc (nbytes);
if (object == XP_NULL) return mem->capacity;
}
@ -88,7 +87,7 @@ void xp_stx_memory_dealloc (xp_stx_memory_t* mem, xp_stx_word_t object_index)
* DEALLOCATE MEMORY ALLOCATED FOR ITS INSTANCE VARIABLES.
*/
xp_free (mem->slots[object_index]);
xp_stx_free (mem->slots[object_index]);
mem->slots[object_index] = (xp_stx_object_t*)mem->free;
mem->free = &mem->slots[object_index];
}

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.h,v 1.1 2005-05-15 18:37:00 bacon Exp $
* $Id: misc.h,v 1.2 2005-05-19 16:41:10 bacon Exp $
*/
#ifndef _XP_STX_MISC_H_
@ -7,6 +7,34 @@
#include <xp/stx/stx.h>
#ifdef _DOS
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
#define xp_stx_assert assert
#define xp_stx_malloc malloc
#define xp_stx_realloc realloc
#define xp_stx_free free
#define xp_stx_va_list va_list
#define xp_stx_va_start va_start
#define xp_stx_va_end va_end
#define xp_stx_va_arg va_arg
#else
#include <xp/bas/memory.h>
#include <xp/bas/assert.h>
#include <xp/bas/stdarg.h>
#define xp_stx_assert xp_assert
#define xp_stx_malloc xp_malloc
#define xp_stx_realloc xp_realloc
#define xp_stx_free xp_free
#define xp_stx_va_list xp_va_list
#define xp_stx_va_start xp_va_start
#define xp_stx_va_end xp_va_end
#define xp_stx_va_arg xp_va_arg
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: object.c,v 1.16 2005-05-18 16:34:51 bacon Exp $
* $Id: object.c,v 1.17 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/object.h>
@ -7,8 +7,6 @@
#include <xp/stx/symbol.h>
#include <xp/stx/hash.h>
#include <xp/stx/misc.h>
#include <xp/bas/assert.h>
#include <xp/bas/stdarg.h>
/* n: number of instance variables */
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
@ -22,7 +20,7 @@ xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
xp_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->nil == XP_STX_NIL);
XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_INDEXED;
while (n-- > 0) XP_STX_AT(stx,idx,n) = stx->nil;
@ -39,7 +37,7 @@ xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n)
&stx->memory, n + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
xp_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->nil == XP_STX_NIL);
XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_BYTE_INDEXED;
while (n-- > 0) XP_STX_BYTEAT(stx,idx,n) = 0;
@ -57,7 +55,7 @@ xp_stx_word_t xp_stx_alloc_string_object (
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
xp_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->nil == XP_STX_NIL);
XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_CHAR_INDEXED;
XP_STX_CHARAT(stx,idx,n) = XP_STX_CHAR('\0');
@ -70,37 +68,37 @@ xp_stx_word_t xp_stx_allocn_string_object (xp_stx_t* stx, ...)
{
xp_stx_word_t idx, n = 0;
const xp_stx_char_t* p;
xp_va_list ap;
xp_stx_va_list ap;
xp_va_start (ap, stx);
while ((p = xp_va_arg(ap, const xp_stx_char_t*)) != XP_NULL) {
xp_stx_va_start (ap, stx);
while ((p = xp_stx_va_arg(ap, const xp_stx_char_t*)) != XP_NULL) {
n += xp_stx_strlen(p);
}
xp_va_end (ap);
xp_stx_va_end (ap);
idx = xp_stx_memory_alloc (&stx->memory,
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
xp_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->nil == XP_STX_NIL);
XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_CHAR_INDEXED;
XP_STX_CHARAT(stx,idx,n) = XP_STX_CHAR('\0');
xp_va_start (ap, stx);
xp_stx_va_start (ap, stx);
n = 0;
while ((p = xp_va_arg(ap, const xp_stx_char_t*)) != XP_NULL) {
while ((p = xp_stx_va_arg(ap, const xp_stx_char_t*)) != XP_NULL) {
while (*p != XP_STX_CHAR('\0'))
XP_STX_CHARAT(stx,idx,n++) = *p++;
}
xp_va_end (ap);
xp_stx_va_end (ap);
return idx;
}
xp_stx_word_t xp_stx_hash_string_object (xp_stx_t* stx, xp_stx_word_t idx)
{
xp_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED);
xp_stx_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED);
return xp_stx_strxhash (
&XP_STX_CHARAT(stx,idx,0), XP_STX_SIZE(stx,idx));
}
@ -143,8 +141,8 @@ int xp_stx_lookup_global (
{
xp_stx_word_t link;
// TODO: maybe xp_stx_hash_object is required instead of
// xp_stx_hash_string_object.
/* TODO: maybe xp_stx_hash_object is required instead of
xp_stx_hash_string_object. */
link = xp_stx_hash_lookup (stx, stx->smalltalk,
xp_stx_hash_string_object(stx,key), key);
if (link == stx->nil) return -1;

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.c,v 1.20 2005-05-19 15:04:21 bacon Exp $
* $Id: stx.c,v 1.21 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/stx.h>
@ -7,22 +7,21 @@
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/symbol.h>
#include <xp/bas/memory.h>
#include <xp/bas/assert.h>
#include <xp/stx/misc.h>
static void __create_bootstrapping_objects (xp_stx_t* stx);
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
{
if (stx == XP_NULL) {
stx = (xp_stx_t*) xp_malloc (xp_sizeof(stx));
stx = (xp_stx_t*)xp_stx_malloc (xp_sizeof(stx));
if (stx == XP_NULL) return XP_NULL;
stx->__malloced = xp_true;
}
else stx->__malloced = xp_false;
if (xp_stx_memory_open (&stx->memory, capacity) == XP_NULL) {
if (stx->__malloced) xp_free (stx);
if (stx->__malloced) xp_stx_free (stx);
return XP_NULL;
}
@ -48,7 +47,7 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
void xp_stx_close (xp_stx_t* stx)
{
xp_stx_memory_close (&stx->memory);
if (stx->__malloced) xp_free (stx);
if (stx->__malloced) xp_stx_free (stx);
}
int xp_stx_bootstrap (xp_stx_t* stx)
@ -114,12 +113,12 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
stx->true = xp_stx_alloc_object (stx, 0);
stx->false = xp_stx_alloc_object (stx, 0);
xp_assert (stx->nil == XP_STX_NIL);
xp_assert (stx->true == XP_STX_TRUE);
xp_assert (stx->false == XP_STX_FALSE);
xp_stx_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->true == XP_STX_TRUE);
xp_stx_assert (stx->false == XP_STX_FALSE);
/* symbol table & system dictionary */
// TODO: symbol table and dictionary size
/* TODO: symbol table and dictionary size */
stx->symbol_table = xp_stx_alloc_object (stx, 1000);
stx->smalltalk = xp_stx_alloc_object (stx, 2000);

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.h,v 1.14 2005-05-18 04:01:51 bacon Exp $
* $Id: stx.h,v 1.15 2005-05-19 16:41:10 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
@ -82,7 +82,7 @@ struct xp_stx_t
xp_stx_word_t class_context;
xp_bool_t __malloced;
xp_bool_t __wantabort; // TODO: make it a function pointer
xp_bool_t __wantabort; /* TODO: make it a function pointer */
};
#define XP_STX_NIL 0

View File

@ -1,11 +1,10 @@
/*
* $Id: symbol.c,v 1.2 2005-05-18 04:01:51 bacon Exp $
* $Id: symbol.c,v 1.3 2005-05-19 16:41:10 bacon Exp $
*/
#include <xp/stx/symbol.h>
#include <xp/stx/object.h>
#include <xp/stx/misc.h>
#include <xp/bas/assert.h>
#define SYMLINK_SIZE 2
#define SYMLINK_LINK 0
@ -39,7 +38,7 @@ xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name)
else {
do {
x = XP_STX_AT(stx,link,SYMLINK_SYMBOL);
xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_stx_strxcmp (
&XP_STX_CHARAT(stx,x,0),
@ -80,7 +79,7 @@ xp_stx_word_t xp_stx_new_symbol_pp (
else {
do {
x = XP_STX_AT(stx,link,SYMLINK_SYMBOL);
xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_stx_strxcmp (
&XP_STX_CHARAT(stx,x,0),

View File

@ -3,13 +3,14 @@ OBJS = stx.obj
OUT = stx.exe
CC = lcc
CFLAGS = -I../../.. -g2
CFLAGS = -I../../.. -A -ansic -libcdll
#LDFLAGS = -L../../../xp/bas -L../../../xp/stx
#LIBS = -lxpstx -lxpbas
LDFLAGS = -subsystem console -dynamic
LIBS = ..\..\..\xp\bas\xpbas.lib ..\..\..\xp\stx\xpstx.lib
all: $(OBJS)
lcclnk -o $(OUT) $(OBJS) $(LIBS)
lcclnk $(LDFLAGS) -o $(OUT) $(OBJS) $(LIBS)
clean:
del $(OBJS) *.obj $(OUT)

18
ase/test/stx/makefile.tcc Normal file
View File

@ -0,0 +1,18 @@
SRCS = stx.c
OBJS = stx.obj
OUT = stx.exe
CC = \tc\tcc
CFLAGS = -I..\..\.. -mh -D_DOS -w
LIBS = \tc\lib\ch.lib \tc\lib\c0h.obj ..\..\..\xp\stx\xpstx.lib
all: $(OBJS)
\tc\tlink $(OBJS),$(OUT),,$(LIBS)
clean:
del $(OBJS) *.obj $(OUT)
.SUFFIXES: .c .obj
.c.obj:
$(CC) $(CFLAGS) -c $<

View File

@ -1,5 +1,11 @@
#include <xp/stx/stx.h>
#include <xp/bas/stdio.h>
#ifdef _DOS
#include <stdio.h>
#define xp_printf printf
#else
#include <xp/bas/stdio.h>
#endif
#include <xp/stx/object.h>
#include <xp/stx/symbol.h>
@ -26,7 +32,7 @@ int xp_main (int argc, xp_char_t* argv[])
xp_stx_t stx;
xp_stx_word_t i;
if (argc != 2) { // TODO: argument processing
if (argc != 2) { /* TODO: argument processing */
xp_printf (XP_TEXT("Usage: %s [-f imageFile] MainClass\n"), argv[0]);
return -1;
}

View File

@ -1,11 +1,13 @@
/*
* $Id: types.h,v 1.24 2005-05-04 04:33:42 bacon Exp $
* $Id: types.h,v 1.25 2005-05-19 16:41:09 bacon Exp $
*/
#ifndef _XP_TYPES_H_
#define _XP_TYPES_H_
#if defined(_DOS) || defined(_WIN32)
#if defined(_DOS)
#include <xp/conf_dos.h>
#elif defined(_WIN32)
#include <xp/config_win32.h>
#elif defined(__VMS)
#include <xp/config_vms.h>
@ -126,7 +128,10 @@ typedef xp_int_t xp_ssize_t;
typedef char xp_mchar_t;
typedef int xp_mcint_t;
#if defined(_DOS) || defined(_WIN32)
#ifdef _DOS
/* no wchar support */
#define XP_CHAR_IS_MCHAR
#elif defined(_WIN32)
typedef unsigned short xp_wchar_t;
typedef int xp_wcint_t;
#elif SIZEOF_LONG == 4
@ -144,7 +149,7 @@ typedef int xp_mcint_t;
#endif
#if defined(XP_CHAR_IS_MCHAR)
//#define XP_CHAR_IS_MCHAR
/*#define XP_CHAR_IS_MCHAR*/
typedef xp_mchar_t xp_char_t;
typedef xp_mcint_t xp_cint_t;
#elif defined(XP_CHAR_IS_WCHAR)