diff --git a/ase/conf_dos.h b/ase/conf_dos.h new file mode 100644 index 00000000..6e286109 --- /dev/null +++ b/ase/conf_dos.h @@ -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 diff --git a/ase/stx/context.c b/ase/stx/context.c index a73a88b0..295dbb4c 100644 --- a/ase/stx/context.c +++ b/ase/stx/context.c @@ -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 @@ -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: diff --git a/ase/stx/hash.c b/ase/stx/hash.c index f92d3a16..02141fa0 100644 --- a/ase/stx/hash.c +++ b/ase/stx/hash.c @@ -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 #include #include -#include 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); diff --git a/ase/stx/makefile.lcc b/ase/stx/makefile.lcc index 6a485fe5..6188d7a0 100644 --- a/ase/stx/makefile.lcc +++ b/ase/stx/makefile.lcc @@ -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 = diff --git a/ase/stx/makefile.tcc b/ase/stx/makefile.tcc new file mode 100644 index 00000000..edd64481 --- /dev/null +++ b/ase/stx/makefile.tcc @@ -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 $< + diff --git a/ase/stx/memory.c b/ase/stx/memory.c index ab97ab87..0c0f6ea0 100644 --- a/ase/stx/memory.c +++ b/ase/stx/memory.c @@ -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 -#include -#include +#include 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]; } diff --git a/ase/stx/misc.h b/ase/stx/misc.h index 38f15f31..7dd4fc2e 100644 --- a/ase/stx/misc.h +++ b/ase/stx/misc.h @@ -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 +#ifdef _DOS + #include + #include + #include + + #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 + #include + #include + + #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 diff --git a/ase/stx/object.c b/ase/stx/object.c index 4e8bed0a..6056f9f1 100644 --- a/ase/stx/object.c +++ b/ase/stx/object.c @@ -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 @@ -7,8 +7,6 @@ #include #include #include -#include -#include /* 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; diff --git a/ase/stx/stx.c b/ase/stx/stx.c index 77dc6875..a829eee0 100644 --- a/ase/stx/stx.c +++ b/ase/stx/stx.c @@ -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 @@ -7,22 +7,21 @@ #include #include #include -#include -#include +#include 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); diff --git a/ase/stx/stx.h b/ase/stx/stx.h index e420e13a..af516ce5 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -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 diff --git a/ase/stx/symbol.c b/ase/stx/symbol.c index 9ea865ad..03af45d0 100644 --- a/ase/stx/symbol.c +++ b/ase/stx/symbol.c @@ -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 #include #include -#include #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), diff --git a/ase/test/stx/makefile.lcc b/ase/test/stx/makefile.lcc index 49d12dee..14e97264 100644 --- a/ase/test/stx/makefile.lcc +++ b/ase/test/stx/makefile.lcc @@ -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) diff --git a/ase/test/stx/makefile.tcc b/ase/test/stx/makefile.tcc new file mode 100644 index 00000000..3572bcea --- /dev/null +++ b/ase/test/stx/makefile.tcc @@ -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 $< + diff --git a/ase/test/stx/stx.c b/ase/test/stx/stx.c index a7306c17..3a756aae 100644 --- a/ase/test/stx/stx.c +++ b/ase/test/stx/stx.c @@ -1,5 +1,11 @@ #include -#include + +#ifdef _DOS + #include + #define xp_printf printf +#else + #include +#endif #include #include @@ -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; } diff --git a/ase/types.h b/ase/types.h index 5f47276b..c31cede2 100644 --- a/ase/types.h +++ b/ase/types.h @@ -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 +#elif defined(_WIN32) #include #elif defined(__VMS) #include @@ -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)