started working on awk

This commit is contained in:
hyung-hwan 2005-09-30 09:40:15 +00:00
parent 09ec0a1f10
commit 9682256a55
8 changed files with 394 additions and 0 deletions

21
ase/awk/Makefile.bcc Normal file
View File

@ -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 $<

23
ase/awk/Makefile.cl Normal file
View File

@ -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 $<

20
ase/awk/Makefile.lcc Normal file
View File

@ -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 $<

23
ase/awk/makefile.in Normal file
View File

@ -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 $<

98
ase/awk/mem.c Normal file
View File

@ -0,0 +1,98 @@
/*
* $Id: mem.c,v 1.1 2005-09-30 09:40:15 bacon Exp $
*/
#include <xp/sce/mem.h>
#include <xp/sce/misc.h>
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];
}

26
ase/awk/mem.h Normal file
View File

@ -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 <xp/sce/sce.h>
#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

31
ase/awk/sce.c Normal file
View File

@ -0,0 +1,31 @@
/*
* $Id: sce.c,v 1.1 2005-09-30 09:40:15 bacon Exp $
*/
#include <xp/sce/sce.h>
#include <xp/sce/mem.h>
#include <xp/sce/misc.h>
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);
}

152
ase/awk/sce.h Normal file
View File

@ -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 <xp/types.h>
#include <xp/macros.h>
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