diff --git a/ase/awk/Makefile.bcc b/ase/awk/Makefile.bcc new file mode 100644 index 00000000..a23bf9cf --- /dev/null +++ b/ase/awk/Makefile.bcc @@ -0,0 +1,21 @@ +SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c array.c \ + name.c token.c parser.c bootstrp.c bytecode.c interp.c +OBJS = $(SRCS:.c=.obj) +OUT = xpstx.lib + +CC = bcc32 +CFLAGS = -O2 -WM -w -w-inl -w-sig -w-spa -w-hid -RT- -I../.. + +all: $(OBJS) + tlib $(OUT) @&&! ++-$(**: = &^ ++-) +! + +clean: + del $(OBJS) $(OUT) *.obj + +.SUFFIXES: .c .obj +.c.obj: + $(CC) $(CFLAGS) -c $< + diff --git a/ase/awk/Makefile.cl b/ase/awk/Makefile.cl new file mode 100644 index 00000000..6f6b7511 --- /dev/null +++ b/ase/awk/Makefile.cl @@ -0,0 +1,23 @@ +SRCS = \ + stx.c memory.c object.c symbol.c class.c array.c \ + dict.c misc.c name.c token.c parser.c bootstrp.c \ + bytecode.c interp.c +OBJS = $(SRCS:.c=.obj) +OUT = xpstx.lib + +CC = cl +CFLAGS = /nologo /MT /GX /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. + +all: $(OBJS) + link -lib @<< +/nologo /out:$(OUT) $(OBJS) +<< + + +clean: + del $(OBJS) $(OUT) *.obj + +.SUFFIXES: .c .obj +.c.obj: + $(CC) $(CFLAGS) /c $< + diff --git a/ase/awk/Makefile.lcc b/ase/awk/Makefile.lcc new file mode 100644 index 00000000..0d1eff6d --- /dev/null +++ b/ase/awk/Makefile.lcc @@ -0,0 +1,20 @@ +SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c array.c \ + context.c name.c token.c parser.c bootstrp.c bytecode.c interp.c +OBJS = stx.obj memory.obj object.obj symbol.obj class.obj dict.obj misc.obj array.obj \ + context.obj name.obj token.obj parser.obj bootstrp.obj bytecode.obj interp.obj +OUT = xpstx.lib + +CC = lcc +CFLAGS = -I../.. -A -ansic -libcdll +LDFLAGS = +LIBS = + +all: $(OBJS) + lcclib $(OUT) $(OBJS) + +clean: + del $(OBJS) $(OUT) *.obj + +.SUFFIXES: .c .obj +.c.obj: + $(CC) $(CFLAGS) -c $< diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in new file mode 100644 index 00000000..db09f6f1 --- /dev/null +++ b/ase/awk/makefile.in @@ -0,0 +1,23 @@ +SRCS = sce.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 interp.c +OBJS = $(SRCS:.c=.o) +OUT = libxpsce.a + +CC = @CC@ +RANLIB = @RANLIB@ +CFLAGS = @CFLAGS@ -I@abs_top_builddir@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ + +all: $(OBJS) + ar cr $(OUT) $(OBJS) + ranlib $(OUT) + +clean: + rm -rf $(OBJS) $(OUT) *.o + +.SUFFIXES: .c .o +.c.o: + $(CC) $(CFLAGS) -c $< diff --git a/ase/awk/mem.c b/ase/awk/mem.c new file mode 100644 index 00000000..e1e0d908 --- /dev/null +++ b/ase/awk/mem.c @@ -0,0 +1,98 @@ +/* + * $Id: mem.c,v 1.1 2005-09-30 09:40:15 bacon Exp $ + */ + +#include +#include + +xp_sce_mem_t* xp_sce_mem_open ( + xp_sce_mem_t* mem, xp_word_t capacity) +{ + xp_sce_obj_t** slots; + xp_word_t n; + + xp_assert (capacity > 0); + if (mem == XP_NULL) { + mem = (xp_sce_mem_t*)xp_malloc(xp_sizeof(xp_sce_mem_t)); + if (mem == XP_NULL) return XP_NULL; + mem->__malloced = xp_true; + } + else mem->__malloced = xp_false; + + slots = (xp_sce_obj_t**)xp_malloc ( + capacity * xp_sizeof(xp_sce_obj_t*)); + if (slots == XP_NULL) { + if (mem->__malloced) xp_free (mem); + mem = XP_NULL; + } + + mem->capacity = capacity; + mem->slots = slots; + + /* weave the free slot list */ + mem->free = &slots[0]; + for (n = 0; n < capacity - 1; n++) { + mem->slots[n] = (xp_sce_obj_t*)&mem->slots[n + 1]; + } + mem->slots[n] = XP_NULL; + + return mem; +} + +void xp_sce_mem_close (xp_sce_mem_t* mem) +{ + /* TODO: free all linked objs... */ + + xp_free (mem->slots); + mem->capacity = 0; + mem->slots = XP_NULL; + mem->free = XP_NULL; + if (mem->__malloced) xp_free (mem); +} + +void xp_sce_mem_gc (xp_sce_mem_t* mem) +{ + /* TODO: implement this function */ +} + +xp_word_t xp_sce_mem_alloc (xp_sce_mem_t* mem, xp_word_t nbytes) +{ + xp_sce_obj_t** slot; + xp_sce_obj_t* obj; + + /* find the free obj slot */ + if (mem->free == XP_NULL) { + xp_sce_mem_gc (mem); + if (mem->free == XP_NULL) return mem->capacity;; + } + + obj = (xp_sce_obj_t*)xp_malloc (nbytes); + if (obj == XP_NULL) { + xp_sce_mem_gc (mem); + obj = (xp_sce_obj_t*)xp_malloc (nbytes); + /*if (obj == XP_NULL) return mem->capacity;*/ +if (obj == XP_NULL) { +xp_assert (XP_TEXT("MEMORY ALLOCATION ERROR\n") == XP_NULL); +exit (1); +} + } + + slot = mem->free; + mem->free = (xp_sce_obj_t**)*slot; + *slot = obj; + + return (xp_word_t)(slot - mem->slots); +} + +void xp_sce_mem_dealloc (xp_sce_mem_t* mem, xp_word_t obj_index) +{ + /* + * THIS IS PRIMITIVE LOW-LEVEL DEALLOC. THIS WILL NOT + * DEALLOCATE MEMORY ALLOCATED FOR ITS INSTANCE VARIABLES. + */ + + xp_free (mem->slots[obj_index]); + mem->slots[obj_index] = (xp_sce_obj_t*)mem->free; + mem->free = &mem->slots[obj_index]; +} + diff --git a/ase/awk/mem.h b/ase/awk/mem.h new file mode 100644 index 00000000..9f843aef --- /dev/null +++ b/ase/awk/mem.h @@ -0,0 +1,26 @@ +/* + * $Id: mem.h,v 1.1 2005-09-30 09:40:15 bacon Exp $ + */ + +#ifndef _XP_SCE_MEM_H_ +#define _XP_SCE_MEM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +xp_sce_mem_t* xp_sce_mem_open ( + xp_sce_mem_t* mem, xp_word_t capacity); +void xp_sce_mem_close (xp_sce_mem_t* mem); + +void xp_sce_mem_gc (xp_sce_mem_t* mem); +xp_word_t xp_sce_mem_alloc (xp_sce_mem_t* mem, xp_word_t size); +void xp_sce_mem_dealloc (xp_sce_mem_t* mem, xp_word_t object_index); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ase/awk/sce.c b/ase/awk/sce.c new file mode 100644 index 00000000..6ac5d6c4 --- /dev/null +++ b/ase/awk/sce.c @@ -0,0 +1,31 @@ +/* + * $Id: sce.c,v 1.1 2005-09-30 09:40:15 bacon Exp $ + */ + +#include +#include +#include + +xp_sce_t* xp_sce_open (xp_sce_t* sce, xp_word_t capacity) +{ + if (sce == XP_NULL) { + sce = (xp_sce_t*)xp_malloc (xp_sizeof(sce)); + if (sce == XP_NULL) return XP_NULL; + sce->__malloced = xp_true; + } + else sce->__malloced = xp_false; + + if (xp_sce_mem_open (&sce->mem, capacity) == XP_NULL) { + if (sce->__malloced) xp_free (sce); + return XP_NULL; + } + + return sce; +} + +void xp_sce_close (xp_sce_t* sce) +{ + xp_sce_mem_close (&sce->mem); + if (sce->__malloced) xp_free (sce); +} + diff --git a/ase/awk/sce.h b/ase/awk/sce.h new file mode 100644 index 00000000..d6897085 --- /dev/null +++ b/ase/awk/sce.h @@ -0,0 +1,152 @@ +/* + * $Id: sce.h,v 1.1 2005-09-30 09:40:15 bacon Exp $ + */ + +#ifndef _XP_SCE_SCE_H_ +#define _XP_SCE_SCE_H_ + +#include +#include + +typedef struct xp_sce_objhdr_t xp_sce_objhdr_t; +typedef struct xp_sce_obj_t xp_sce_obj_t; +typedef struct xp_sce_word_obj_t xp_sce_word_obj_t; +typedef struct xp_sce_byte_obj_t xp_sce_byte_obj_t; +typedef struct xp_sce_char_obj_t xp_sce_char_obj_t; +typedef struct xp_sce_int_obj_t xp_sce_int_obj_t; +typedef struct xp_sce_real_obj_t xp_sce_real_obj_t; +typedef struct xp_sce_mem_t xp_sce_mem_t; +typedef struct xp_sce_t xp_sce_t; + +/* common obj structure */ +struct xp_sce_objhdr_t +{ + /* + * lower 4 bytes: atomic types... + * CHAR + * INT + * REAL + * + * the rest of the bytes: number of elements in the array. + * this value will be 1 for atomic types + * + * // array types + * ARRAY OF ATTOMIC TYPES + */ + xp_word_t access; +}; + +struct xp_sce_obj_t +{ + xp_sce_objhdr_t hdr; +}; + +struct xp_sce_word_obj_t +{ + xp_sce_objhdr_t hdr; + xp_word_t data[1]; +}; + +struct xp_sce_byte_obj_t +{ + xp_sce_objhdr_t hdr; + xp_byte_t data[1]; +}; + +struct xp_sce_char_obj_t +{ + xp_sce_objhdr_t hdr; + xp_char_t data[1]; +}; + +struct xp_sce_int_obj_t +{ + xp_sce_objhdr_t hdr; + xp_long_t data[1]; +}; + +struct xp_sce_real_obj_t +{ + xp_sce_objhdr_t hdr; + xp_real_t data[1]; +}; + +struct xp_sce_mem_t +{ + xp_word_t capacity; + xp_sce_obj_t** slots; + xp_sce_obj_t** free; + xp_bool_t __malloced; +}; + +struct xp_sce_t +{ + xp_sce_mem_t mem; + xp_bool_t __malloced; +}; + +#define XP_SCE_IS_SMALLINT(x) (((x) & 0x01) == 0x01) +#define XP_SCE_TO_SMALLINT(x) (((x) << 1) | 0x01) +#define XP_SCE_FROM_SMALLINT(x) ((x) >> 1) + +#define XP_SCE_IS_OINDEX(x) (((x) & 0x01) == 0x00) +#define XP_SCE_TO_OINDEX(x) (((x) << 1) | 0x00) +#define XP_SCE_FROM_OINDEX(x) ((x) >> 1) + +#define XP_SCE_NIL XP_SCE_TO_OINDEX(0) +#define XP_SCE_TRUE XP_SCE_TO_OINDEX(1) +#define XP_SCE_FALSE XP_SCE_TO_OINDEX(2) + +#define XP_SCE_OBJ(sce,idx) (((sce)->mem).slots[XP_SCE_FROM_OINDEX(idx)]) +#define XP_SCE_ACCESS(sce,idx) (XP_SCE_OBJ(sce,(idx))->hdr.access) +#define XP_SCE_DATA(sce,idx) ((void*)(XP_SCE_OBJ(sce,idx) + 1)) + +#define XP_SCE_TYPE(sce,idx) (XP_SCE_ACCESS(sce,idx) & 0x0F) +#define XP_SCE_SIZE(sce,idx) (XP_SCE_ACCESS(sce,idx) >> 0x04) + +#define XP_SCE_WORD_INDEXED (0x00) +#define XP_SCE_BYTE_INDEXED (0x01) +#define XP_SCE_CHAR_INDEXED (0x02) +#define XP_SCE_INT_INDEXED (0x03) +#define XP_SCE_REAL_INDEXED (0x04) + +#define XP_SCE_IS_WORD_OBJ(sce,idx) \ + (XP_SCE_TYPE(sce,idx) == XP_SCE_WORD_INDEXED) +#define XP_SCE_IS_BYTE_OBJ(sce,idx) \ + (XP_SCE_TYPE(sce,idx) == XP_SCE_BYTE_INDEXED) +#define XP_SCE_IS_CHAR_OBJ(sce,idx) \ + (XP_SCE_TYPE(sce,idx) == XP_SCE_CHAR_INDEXED) +#define XP_SCE_IS_INT_OBJ(sce,idx) \ + (XP_SCE_TYPE(sce,idx) == XP_SCE_INT_INDEXED) +#define XP_SCE_IS_REAL_OBJ(sce,idx) \ + (XP_SCE_TYPE(sce,idx) == XP_SCE_REAL_INDEXED) + +#define XP_SCE_WORD_OBJ(sce,idx) \ + ((xp_sce_word_obj_t*)XP_SCE_OBJ(sce,idx)) +#define XP_SCE_BYTE_OBJ(sce,idx) \ + ((xp_sce_byte_obj_t*)XP_SCE_OBJ(sce,idx)) +#define XP_SCE_CHAR_OBJ(sce,idx) \ + ((xp_sce_char_obj_t*)XP_SCE_OBJ(sce,idx)) +#define XP_SCE_INT_OBJ(sce,idx) \ + ((xp_sce_int_obj_t*)XP_SCE_OBJ(sce,idx)) +#define XP_SCE_REAL_OBJ(sce,idx) \ + ((xp_sce_real_obj_t*)XP_SCE_OBJ(sce,idx)) + +#define XP_SCE_WORD_AT(sce,idx,n) (XP_SCE_WORD_OBJ(sce,idx)->data[n]) +#define XP_SCE_BYTE_AT(sce,idx,n) (XP_SCE_BYTE_OBJ(sce,idx)->data[n]) +#define XP_SCE_CHAR_AT(sce,idx,n) (XP_SCE_CHAR_OBJ(sce,idx)->data[n]) +#define XP_SCE_INT_AT(sce,idx,n) (XP_SCE_INT_OBJ(sce,idx)->data[n]) +#define XP_SCE_REAL_AT(sce,idx,n) (XP_SCE_REAL_OBJ(sce,idx)->data[n]) + +#ifdef __cplusplus +extern "C" { +#endif + +xp_sce_t* xp_sce_open (xp_sce_t* sce, xp_word_t capacity); +void xp_sce_close (xp_sce_t* sce); + +#ifdef __cplusplus +} +#endif + +#endif