From b8dae9206f15b71e872c60831b7a67f4e5a3b3e1 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 12 May 2014 11:54:15 -0700 Subject: [PATCH] Interpreter - Incremental API changes * Pass the run-time context through the call chain and remove the IContext global. * I ultimately intend to make the run-time context a pass-and-return entity, which C compilers can optimize to avoid register saves and restores, and to move the break/continue count into the runctx. --- dllx11/defs.h | 58 +++---- dllx11/draw.c | 18 +-- dllx11/fill.c | 6 +- dllx11/pen.c | 24 +-- dllx11/text.c | 42 +++--- dllx11/xevent.c | 4 +- dllx11/xwin.c | 78 +++++----- libi/cast.c | 17 ++- libi/clangdll.c | 12 +- libi/context.c | 65 ++++---- libi/defs.h | 43 +++--- libi/exp.c | 373 ++++++++++++++++++++++++---------------------- libi/export.h | 4 +- libi/iframe.c | 1 - libi/iframe.h | 4 - libi/oper.c | 111 +++++++------- libi/refstor.c | 54 ++++--- libi/stmt.c | 297 ++++++++++++++++++------------------ libi/stor.c | 32 ++-- libi/stor.h | 22 +-- libi/syscalls.c | 67 +++++---- libi/thread.c | 11 +- librune/context.h | 1 + librune/exp.h | 2 +- librune/export.h | 2 + librune/stmt.h | 2 +- 26 files changed, 691 insertions(+), 659 deletions(-) diff --git a/dllx11/defs.h b/dllx11/defs.h index d4a479f..8a87439 100644 --- a/dllx11/defs.h +++ b/dllx11/defs.h @@ -39,32 +39,32 @@ extern Type EventType; extern Type EventPtrType; void initXDisplay(void); -void *isys_XDrawPoint(Exp *exp, RefStor **prs); -void *isys_XDrawLine(Exp *exp, RefStor **prs); -void *isys_XDrawRect(Exp *exp, RefStor **prs); -void *isys_XFillRect(Exp *exp, RefStor **prs); -void *isys_XSetForeground(Exp *exp, RefStor **prs); -void *isys_XSetBackground(Exp *exp, RefStor **prs); -void *isys_XAllocColor(Exp *exp, RefStor **prs); -void *isys_XFreeColor(Exp *exp, RefStor **prs); -void *isys_XDrawString(Exp *exp, RefStor **prs); -void *isys_XDrawImageString(Exp *exp, RefStor **prs); -void *isys_XTextWidth(Exp *exp, RefStor **prs); -void *isys_XTextHeight(Exp *exp, RefStor **prs); -void *isys_XTextDescent(Exp *exp, RefStor **prs); -void *isys_XLoadFont(Exp *exp, RefStor **prs); -void *isys_XUnloadFont(Exp *exp, RefStor **prs); -void *isys_XEvent(Exp *exp, RefStor **prs); -void *isys_XCreateWindow(Exp *exp, RefStor **prs); -void *isys_XMoveResizeWindow(Exp *exp, RefStor **prs); -void *isys_XCreateGC(Exp *exp, RefStor **prs); -void *isys_XDestroyWindow(Exp *exp, RefStor **prs); -void *isys_XMapWindow(Exp *exp, RefStor **prs); -void *isys_XUnmapWindow(Exp *exp, RefStor **prs); -void *isys_XClearWindow(Exp *exp, RefStor **prs); -void *isys_XClearArea(Exp *exp, RefStor **prs); -void *isys_XMoveWindow(Exp *exp, RefStor **prs); -void *isys_XResizeWindow(Exp *exp, RefStor **prs); -void *isys_XFreeGC(Exp *exp, RefStor **prs); -void *isys_XFlush(Exp *exp, RefStor **prs); -void *isys_XSync(Exp *exp, RefStor **prs); +void *isys_XDrawPoint(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XDrawLine(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XDrawRect(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XFillRect(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XSetForeground(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XSetBackground(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XAllocColor(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XFreeColor(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XDrawString(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XDrawImageString(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XTextWidth(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XTextHeight(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XTextDescent(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XLoadFont(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XUnloadFont(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XEvent(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XCreateWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XMoveResizeWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XCreateGC(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XDestroyWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XMapWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XUnmapWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XClearWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XClearArea(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XMoveWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XResizeWindow(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XFreeGC(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XFlush(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_XSync(runctx_p ct, Exp *exp, RefStor **prs); diff --git a/dllx11/draw.c b/dllx11/draw.c index 1e91088..a474629 100644 --- a/dllx11/draw.c +++ b/dllx11/draw.c @@ -5,7 +5,7 @@ #include "defs.h" void * -isys_XDrawPoint(Exp *exp, RefStor **prs) +isys_XDrawPoint(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -15,8 +15,8 @@ isys_XDrawPoint(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDrawPoint(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->x, rhs->y); @@ -24,7 +24,7 @@ isys_XDrawPoint(Exp *exp, RefStor **prs) } void * -isys_XDrawLine(Exp *exp, RefStor **prs) +isys_XDrawLine(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -36,8 +36,8 @@ isys_XDrawLine(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDrawLine(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->sx, rhs->sy, @@ -46,7 +46,7 @@ isys_XDrawLine(Exp *exp, RefStor **prs) } void * -isys_XDrawRect(Exp *exp, RefStor **prs) +isys_XDrawRect(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -58,7 +58,7 @@ isys_XDrawRect(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); if (rhs->w < 0) { rhs->sx += rhs->w; rhs->w = -rhs->w; @@ -67,7 +67,7 @@ isys_XDrawRect(Exp *exp, RefStor **prs) rhs->sy += rhs->h; rhs->h = -rhs->h; } - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDrawRectangle(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->sx, rhs->sy, rhs->w, rhs->h); diff --git a/dllx11/fill.c b/dllx11/fill.c index ea10582..35c98ae 100644 --- a/dllx11/fill.c +++ b/dllx11/fill.c @@ -5,7 +5,7 @@ #include "defs.h" void * -isys_XFillRect(Exp *exp, RefStor **prs) +isys_XFillRect(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -17,7 +17,7 @@ isys_XFillRect(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); if (rhs->w < 0) { rhs->sx += rhs->w; rhs->w = -rhs->w; @@ -26,7 +26,7 @@ isys_XFillRect(Exp *exp, RefStor **prs) rhs->sy += rhs->h; rhs->h = -rhs->h; } - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XFillRectangle(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->sx, rhs->sy, rhs->w, rhs->h); diff --git a/dllx11/pen.c b/dllx11/pen.c index c16e3b3..9f0d0af 100644 --- a/dllx11/pen.c +++ b/dllx11/pen.c @@ -5,7 +5,7 @@ #include "defs.h" void * -isys_XSetForeground(Exp *exp, RefStor **prs) +isys_XSetForeground(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t gcid; @@ -13,8 +13,8 @@ isys_XSetForeground(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XSetForeground(SaveDisplay, hashLookup(rhs->gcid, HASH_GC), rhs->color); @@ -22,7 +22,7 @@ isys_XSetForeground(Exp *exp, RefStor **prs) } void * -isys_XSetBackground(Exp *exp, RefStor **prs) +isys_XSetBackground(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t gcid; @@ -30,8 +30,8 @@ isys_XSetBackground(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XSetBackground(SaveDisplay, hashLookup(rhs->gcid, HASH_GC), rhs->color); @@ -42,7 +42,7 @@ isys_XSetBackground(Exp *exp, RefStor **prs) #define COLORMAP DefaultColormap(SaveDisplay, DefaultScreen(SaveDisplay)) void * -isys_XAllocColor(Exp *exp, RefStor **prs) +isys_XAllocColor(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t r; @@ -52,8 +52,8 @@ isys_XAllocColor(Exp *exp, RefStor **prs) TmpStor *ts; XColor color = { 0 }; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); color.red = rhs->r; color.green = rhs->g; color.blue = rhs->b; @@ -63,7 +63,7 @@ isys_XAllocColor(Exp *exp, RefStor **prs) } void * -isys_XFreeColor(Exp *exp, RefStor **prs) +isys_XFreeColor(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t pixel; @@ -71,8 +71,8 @@ isys_XFreeColor(Exp *exp, RefStor **prs) TmpStor *ts; unsigned long pixel; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); pixel = rhs->pixel; ts->ts_Int32 = XFreeColors(SaveDisplay, COLORMAP, &pixel, 1, 0); return(&ts->ts_Int32); diff --git a/dllx11/text.c b/dllx11/text.c index c0074c9..de286e7 100644 --- a/dllx11/text.c +++ b/dllx11/text.c @@ -19,7 +19,7 @@ getFontInfo(int32_t fontid) } void * -isys_XDrawString(Exp *exp, RefStor **prs __unused) +isys_XDrawString(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t xid; @@ -32,8 +32,8 @@ isys_XDrawString(Exp *exp, RefStor **prs __unused) TmpStor *ts; RefStor *rs = NULL; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDrawString(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->x, rhs->y, @@ -43,7 +43,7 @@ isys_XDrawString(Exp *exp, RefStor **prs __unused) } void * -isys_XDrawImageString(Exp *exp, RefStor **prs __unused) +isys_XDrawImageString(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t xid; @@ -56,8 +56,8 @@ isys_XDrawImageString(Exp *exp, RefStor **prs __unused) TmpStor *ts; RefStor *rs = NULL; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDrawImageString(SaveDisplay, rhs->xid, hashLookup(rhs->gcid, HASH_GC), rhs->x, rhs->y, @@ -67,7 +67,7 @@ isys_XDrawImageString(Exp *exp, RefStor **prs __unused) } void * -isys_XTextWidth(Exp *exp, RefStor **prs __unused) +isys_XTextWidth(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t fontid; @@ -78,17 +78,17 @@ isys_XTextWidth(Exp *exp, RefStor **prs __unused) RefStor *rs = NULL; XFontStruct *fs; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); fs = getFontInfo(rhs->fontid); dassert(fs != NULL); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XTextWidth(fs, rhs->buf.s_Addr, rhs->len); relsRefStor(rs); return(&ts->ts_Int32); } void * -isys_XTextHeight(Exp *exp, RefStor **prs __unused) +isys_XTextHeight(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t fontid; @@ -97,17 +97,17 @@ isys_XTextHeight(Exp *exp, RefStor **prs __unused) RefStor *rs = NULL; XFontStruct *fs; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); fs = getFontInfo(rhs->fontid); dassert(fs != NULL); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = fs->ascent + fs->descent; relsRefStor(rs); return(&ts->ts_Int32); } void * -isys_XTextDescent(Exp *exp, RefStor **prs __unused) +isys_XTextDescent(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t fontid; @@ -116,17 +116,17 @@ isys_XTextDescent(Exp *exp, RefStor **prs __unused) RefStor *rs = NULL; XFontStruct *fs; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); fs = getFontInfo(rhs->fontid); dassert(fs != NULL); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = fs->descent; relsRefStor(rs); return(&ts->ts_Int32); } void * -isys_XLoadFont(Exp *exp, RefStor **prs __unused) +isys_XLoadFont(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { PointerStor buf; @@ -137,15 +137,15 @@ isys_XLoadFont(Exp *exp, RefStor **prs __unused) if (SaveDisplay == NULL) initXDisplay(); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XLoadFont(SaveDisplay, rhs->buf.s_Addr); relsRefStor(rs); return(&ts->ts_Int32); } void * -isys_XUnloadFont(Exp *exp, RefStor **prs __unused) +isys_XUnloadFont(runctx_p ct, Exp *exp, RefStor **prs __unused) { struct { int32_t fontid; @@ -154,10 +154,10 @@ isys_XUnloadFont(Exp *exp, RefStor **prs __unused) RefStor *rs = NULL; XFontStruct *fs; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); if ((fs = hashRemove(rhs->fontid, HASH_FONTINFO)) != NULL) XFreeFontInfo(NULL, fs, 1); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XUnloadFont(SaveDisplay, rhs->fontid); relsRefStor(rs); return(&ts->ts_Int32); diff --git a/dllx11/xevent.c b/dllx11/xevent.c index a385273..7ff1fb2 100644 --- a/dllx11/xevent.c +++ b/dllx11/xevent.c @@ -8,9 +8,9 @@ #include "defs.h" void * -isys_XEvent(Exp *exp, RefStor **prs) +isys_XEvent(runctx_p ct, Exp *exp, RefStor **prs) { - TmpStor *ts = getExpTmpData(exp); + TmpStor *ts = getExpTmpData(ct, exp); XEvent xevent; static XEvent xsave; Event *event; diff --git a/dllx11/xwin.c b/dllx11/xwin.c index 8a5e7a3..d47f1b8 100644 --- a/dllx11/xwin.c +++ b/dllx11/xwin.c @@ -5,7 +5,7 @@ #include "defs.h" void * -isys_XCreateWindow(Exp *exp, RefStor **prs) +isys_XCreateWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t parent; @@ -21,7 +21,7 @@ isys_XCreateWindow(Exp *exp, RefStor **prs) if (SaveDisplay == NULL) initXDisplay(); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); if (rhs->parent == 0) { w = DefaultRootWindow(SaveDisplay); bw = 1; @@ -51,13 +51,13 @@ isys_XCreateWindow(Exp *exp, RefStor **prs) FocusChangeMask|OwnerGrabButtonMask; /* data.colormap = XDefaultColormap(SaveDisplay, 0);*/ XChangeWindowAttributes(SaveDisplay, w, CWEventMask, &data); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = w; return(&ts->ts_Int32); } void * -isys_XCreateGC(Exp *exp, RefStor **prs) +isys_XCreateGC(runctx_p ct, Exp *exp, RefStor **prs) { XGCValues data; Window w; @@ -71,7 +71,7 @@ isys_XCreateGC(Exp *exp, RefStor **prs) if (SaveDisplay == NULL) initXDisplay(); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); if ((w = rhs->w) == 0) w = DefaultRootWindow(SaveDisplay); @@ -86,7 +86,7 @@ isys_XCreateGC(Exp *exp, RefStor **prs) GCBackground|GCFont|GCFillStyle, &data); - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); if (gc) { ts->ts_Int32 = hashEnter(gc, HASH_GC, -1); } else { @@ -96,63 +96,63 @@ isys_XCreateGC(Exp *exp, RefStor **prs) } void * -isys_XDestroyWindow(Exp *exp, RefStor **prs) +isys_XDestroyWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XDestroyWindow(SaveDisplay, rhs->xid); return(&ts->ts_Int32); } void * -isys_XMapWindow(Exp *exp, RefStor **prs) +isys_XMapWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XMapWindow(SaveDisplay, rhs->xid); return(&ts->ts_Int32); } void * -isys_XUnmapWindow(Exp *exp, RefStor **prs) +isys_XUnmapWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XUnmapWindow(SaveDisplay, rhs->xid); return(&ts->ts_Int32); } void * -isys_XClearWindow(Exp *exp, RefStor **prs) +isys_XClearWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XClearWindow(SaveDisplay, rhs->xid); return(&ts->ts_Int32); } void * -isys_XClearArea(Exp *exp, RefStor **prs) +isys_XClearArea(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -163,8 +163,8 @@ isys_XClearArea(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XClearArea(SaveDisplay, rhs->xid, rhs->x, rhs->y, rhs->w, rhs->h, True); @@ -172,7 +172,7 @@ isys_XClearArea(Exp *exp, RefStor **prs) } void * -isys_XMoveWindow(Exp *exp, RefStor **prs) +isys_XMoveWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -181,8 +181,8 @@ isys_XMoveWindow(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XMoveWindow(SaveDisplay, rhs->xid, rhs->x, rhs->y); XFlush(SaveDisplay); /*XClearWindow(SaveDisplay, rhs->xid);*/ @@ -190,7 +190,7 @@ isys_XMoveWindow(Exp *exp, RefStor **prs) } void * -isys_XResizeWindow(Exp *exp, RefStor **prs) +isys_XResizeWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -199,8 +199,8 @@ isys_XResizeWindow(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XResizeWindow(SaveDisplay, rhs->xid, rhs->w, rhs->h); XFlush(SaveDisplay); /*XClearWindow(SaveDisplay, rhs->xid);*/ @@ -208,7 +208,7 @@ isys_XResizeWindow(Exp *exp, RefStor **prs) } void * -isys_XMoveResizeWindow(Exp *exp, RefStor **prs) +isys_XMoveResizeWindow(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -219,8 +219,8 @@ isys_XMoveResizeWindow(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XMoveResizeWindow(SaveDisplay, rhs->xid, rhs->x, rhs->y, rhs->w, rhs->h); @@ -230,7 +230,7 @@ isys_XMoveResizeWindow(Exp *exp, RefStor **prs) } void * -isys_XFreeGC(Exp *exp, RefStor **prs) +isys_XFreeGC(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t gcid; @@ -238,8 +238,8 @@ isys_XFreeGC(Exp *exp, RefStor **prs) TmpStor *ts; GC gc; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); if ((gc = hashRemove(rhs->gcid, HASH_GC)) != NULL) ts->ts_Int32 = XFreeGC(SaveDisplay, gc); else @@ -248,7 +248,7 @@ isys_XFreeGC(Exp *exp, RefStor **prs) } void * -isys_XFlush(Exp *exp, RefStor **prs) +isys_XFlush(runctx_p ct, Exp *exp, RefStor **prs) { #if 0 struct { @@ -257,14 +257,14 @@ isys_XFlush(Exp *exp, RefStor **prs) #endif TmpStor *ts; - /*rhs =*/ exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + /*rhs =*/ exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XFlush(SaveDisplay); return(&ts->ts_Int32); } void * -isys_XSync(Exp *exp, RefStor **prs) +isys_XSync(runctx_p ct, Exp *exp, RefStor **prs) { struct { int32_t xid; @@ -272,8 +272,8 @@ isys_XSync(Exp *exp, RefStor **prs) } *rhs; TmpStor *ts; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - ts = getExpTmpData(exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = XSync(SaveDisplay, rhs->bool); return(&ts->ts_Int32); } diff --git a/libi/cast.c b/libi/cast.c index 1b58e58..2035c8d 100644 --- a/libi/cast.c +++ b/libi/cast.c @@ -40,21 +40,22 @@ typedef long double Float128; */ #define CAST_OP(name, ltype, rtype) \ static void * \ -Cast ## name ## ltype ## rtype(Exp *exp, RefStor **prs) \ +Cast ## name ## ltype ## rtype(runctx_p ct, Exp *exp, RefStor **prs) \ { \ - TmpStor *ts = getExpTmpData(exp); \ + TmpStor *ts = getExpTmpData(ct, exp); \ \ - ts->ts_ ## ltype = *(rtype *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs);\ + ts->ts_ ## ltype = \ + *(rtype *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ return(&ts->ts_ ## ltype); \ } #define BOOL_CAST_BOOL_OP(name, rtype) \ static void * \ -Cast ## name ## Bool ## rtype(Exp *exp, RefStor **prs) \ +Cast ## name ## Bool ## rtype(runctx_p ct, Exp *exp, RefStor **prs) \ { \ - TmpStor *ts = getExpTmpData(exp); \ + TmpStor *ts = getExpTmpData(ct, exp); \ \ - if (*(rtype *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs)) \ + if (*(rtype *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs)) \ ts->ts_Bool = 1; \ else \ ts->ts_Bool = 0; \ @@ -122,7 +123,7 @@ BOOL_CAST_BOOL_OP_TYPES(cast_bool) CAST_OP_TYPES() static void * -Castcast_intNumericNumeric(Exp *exp, RefStor **prs) +Castcast_intNumericNumeric(runctx_p ct, Exp *exp, RefStor **prs) { if (exp->ex_Type->ty_Bytes == 0) { /* @@ -185,7 +186,7 @@ Castcast_intNumericNumeric(Exp *exp, RefStor **prs) fprintf(stderr, "Unable to interpret numeric cast\n"); dassert_exp(exp, 0); } - return(exp->ex_Func(exp, prs)); + return(exp->ex_Func(ct, exp, prs)); } static InternalCast IOpAry[] = { diff --git a/libi/clangdll.c b/libi/clangdll.c index ca267b3..5d1b722 100644 --- a/libi/clangdll.c +++ b/libi/clangdll.c @@ -8,7 +8,7 @@ #include "defs.h" typedef void *void_ptr; -typedef void_ptr (*isys_generic_c_call_t)(Exp *exp, RefStor **prs); +typedef void_ptr (*isys_generic_c_call_t)(runctx_p ct, Exp *exp, RefStor **prs); /* * isys_generic_c_call() @@ -18,7 +18,7 @@ typedef void_ptr (*isys_generic_c_call_t)(Exp *exp, RefStor **prs); * number of arguments and the size of the return value. */ static __inline void * -isys_call(Exp *exp, RefStor **prs __unused, const int asize, const int rsize) +isys_call(runctx_p ct, Exp *exp, RefStor **prs __unused, const int asize, const int rsize) { TmpStor *ts; RefStor *rs = NULL; @@ -37,8 +37,8 @@ isys_call(Exp *exp, RefStor **prs __unused, const int asize, const int rsize) struct my_lhs (*funcX)(struct my_rhs rhs); } func; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); func.func0 = exp->ex_Lhs->ex_Decl->d_ProcDecl.ed_DLLFunc; switch(exp->ex_Type->ty_Bytes) { @@ -68,9 +68,9 @@ isys_call(Exp *exp, RefStor **prs __unused, const int asize, const int rsize) #define ISYS_CALL(asize,rsize) \ static void * \ -isys_call_ ## asize ## _ ## rsize(Exp *exp, RefStor **prs) \ +isys_call_ ## asize ## _ ## rsize(runctx_p ct, Exp *exp, RefStor **prs) \ { \ - return(isys_call(exp, prs, 0x ## asize, 0x ## rsize)); \ + return(isys_call(ct, exp, prs, 0x ## asize, 0x ## rsize));\ } \ #define ISYS_CALLGROUP(asize) \ diff --git a/libi/context.c b/libi/context.c index b02a392..3031a8c 100644 --- a/libi/context.c +++ b/libi/context.c @@ -12,7 +12,8 @@ * to making a procedure call. */ void -BuildArgsContext(Declaration *d, Context *ct, Type *varType, void *dataBuf) +BuildArgsContext(runctx_p oct, runctx_p nct, Declaration *d, + Type *varType, void *dataBuf) { Type *procType = d->d_ProcDecl.ed_Type; Type *argsType = procType->ty_ProcType.et_ArgsType; @@ -20,14 +21,15 @@ BuildArgsContext(Declaration *d, Context *ct, Type *varType, void *dataBuf) dassert_decl(d, procType->ty_Op == TY_PROC); dassert_decl(d, argsType->ty_Op == TY_ARGS); - bzero(ct, sizeof(Context)); - ct->ct_Data = dataBuf; - ct->ct_Bytes = varType->ty_Bytes; - ct->ct_RetType = procType->ty_ProcType.et_RetType; - ct->ct_ArgsType = varType; - ct->ct_ArgsCtx = ct; - ct->ct_RefStor.rs_Refs = 1; - ct->ct_RefStor.rs_Op = RSOP_ARGSCTX; + bzero(nct, sizeof(*nct)); + nct->ct_Data = dataBuf; + nct->ct_Bytes = varType->ty_Bytes; + nct->ct_RetType = procType->ty_ProcType.et_RetType; + nct->ct_ArgsType = varType; + nct->ct_ArgsCtx = nct; + nct->ct_RefStor.rs_Refs = 1; + nct->ct_RefStor.rs_Op = RSOP_ARGSCTX; + nct->ct_CallCtx = oct; /* * XXX the arguments could have come from an idealized superclass in @@ -53,10 +55,10 @@ FreeArgsContext(Context *ct) * WARNING! RetRefStor is only associated with the argument context */ void -PushProcContext(Context *argsct, Context *ct, SemGroup *sg, - void *dataBuf, void *tmpBuf) +PushProcContext(runctx_p argsct, runctx_p ct, runctx_p parent_ctx, + SemGroup *sg, void *dataBuf, void *tmpBuf) { - bzero(ct, sizeof(Context)); + bzero(ct, sizeof(*ct)); ct->ct_Data = dataBuf; ct->ct_Bytes = sg->sg_Bytes; ct->ct_TmpData = tmpBuf; @@ -66,21 +68,18 @@ PushProcContext(Context *argsct, Context *ct, SemGroup *sg, ct->ct_RetType = argsct->ct_RetType; ct->ct_ArgsType = argsct->ct_ArgsType; ct->ct_ArgsCtx = argsct; - ct->ct_Parent = IContext; + ct->ct_Parent = parent_ctx; ct->ct_SchedPreempt = 0; ct->ct_RefStor.rs_Refs = 1; ct->ct_RefStor.rs_Op = RSOP_PROCCTX; ct->ct_NestLevel = sg->sg_NestLevel; ct->ct_NestSize = sg->sg_NestSize; - IContext = ct; } void PopProcContext(Context *ct, SemGroup *sg __unused) { - dassert(IContext == ct); dassert(ct->ct_RefStor.rs_Refs == 1); - IContext = ct->ct_Parent; } Context * @@ -105,10 +104,6 @@ BuildSemGroupContext(SemGroup *sg, int isglobal) void FreeSemGroupContext(Context *ct, SemGroup *sg __unused) { -#if 0 - dassert(IContext == ct); - IContext = ct->ct_Parent; -#endif dassert(ct->ct_RefStor.rs_Refs == 1); zfree(ct->ct_Data, ct->ct_Bytes); zfree_wipe(ct, sizeof(Context)); @@ -119,34 +114,32 @@ FreeSemGroupContext(Context *ct, SemGroup *sg __unused) * avoid calling this to initialize every single little SemGroup. */ void -PushTmpDefaultContext(Context *ct, int tmpBytes, void *tmpBuf) +PushTmpDefaultContext(runctx_p oct, runctx_p nct, int tmpBytes, void *tmpBuf) { - bzero(ct, sizeof(Context)); - ct->ct_Parent = IContext; - ct->ct_TmpData = tmpBuf; - ct->ct_TmpBytes = tmpBytes; - ct->ct_RefStor.rs_Refs = 1; - ct->ct_RefStor.rs_Op = RSOP_TMPDEFCTX; - IContext = ct; + bzero(nct, sizeof(*nct)); + nct->ct_Parent = oct; + nct->ct_TmpData = tmpBuf; + nct->ct_TmpBytes = tmpBytes; + nct->ct_RefStor.rs_Refs = 1; + nct->ct_RefStor.rs_Op = RSOP_TMPDEFCTX; } void -PopTmpDefaultContext(Context *ct, int tmpBytes __unused) +PopTmpDefaultContext(runctx_p ct, int tmpBytes __unused) { dassert(ct->ct_RefStor.rs_Refs == 1); - IContext = ct->ct_Parent; } void -PushObjectContext(char *data, int bytes) +PushObjectContext(runctx_p ct, char *data, int bytes) { - IContext->ct_ObjData = data; - IContext->ct_ObjBytes = bytes; + ct->ct_ObjData = data; + ct->ct_ObjBytes = bytes; } void -PopObjectContext(void) +PopObjectContext(runctx_p ct) { - IContext->ct_ObjData = NULL; - IContext->ct_ObjBytes = 0; + ct->ct_ObjData = NULL; + ct->ct_ObjBytes = 0; } diff --git a/libi/defs.h b/libi/defs.h index 9fab8f8..03912ed 100644 --- a/libi/defs.h +++ b/libi/defs.h @@ -44,23 +44,25 @@ ic_func_t InternalConstructorDestructorLookup(string_t id, Type *type); /* * context.c */ -void BuildArgsContext(Declaration *d, Context *ct, Type *argsType, void *data); -void FreeArgsContext(Context *ct); -void PushProcContext(Context *argsct, Context *ct, SemGroup *sg, - void *dataBuf, void *tmpBuf); -void PopProcContext(Context *ct, SemGroup *sg); +void BuildArgsContext(runctx_p oct, runctx_p nct, Declaration *d, + Type *argsType, void *data); +void FreeArgsContext(runctx_p ct); +void PushProcContext(runctx_p argsct, runctx_p ct, runctx_p parent_ct, + SemGroup *sg, void *dataBuf, void *tmpBuf); +void PopProcContext(runctx_p ct, SemGroup *sg); /*Context *BuildSemGroupContext(SemGroup *sg, int flags);*/ -void FreeSemGroupContext(Context *ct, SemGroup *sg); -void PushTmpDefaultContext(Context *ct, int tmpBytes, void *tmpBuf); -void PopTmpDefaultContext(Context *ct, int tmpBytes); -void PushObjectContext(char *data, int bytes); -void PopObjectContext(void); +void FreeSemGroupContext(runctx_p ct, SemGroup *sg); +void PushTmpDefaultContext(runctx_p oct, runctx_p nct, + int tmpBytes, void *tmpBuf); +void PopTmpDefaultContext(runctx_p ct, int tmpBytes); +void PushObjectContext(runctx_p ct, char *data, int bytes); +void PopObjectContext(runctx_p ct); /* * exp.c */ -void *interpCastExpInteger(Exp *exp, RefStor **prs); -void *interpCastExpVoid(Exp *exp, RefStor **prs); +void *interpCastExpInteger(runctx_p ct, Exp *exp, RefStor **prs); +void *interpCastExpVoid(runctx_p ct, Exp *exp, RefStor **prs); /* * oper.c @@ -78,15 +80,15 @@ void dropContent(char *data, Type *type); void dropContentGroup(char *data, SemGroup *sg, int dop); void refContent(char *data, Type *type); void refContentGroup(char *data, SemGroup *sg, int dop); -void callContent(RefStor *rs, char *data, Type *type, int flags); -void callContentGroup(RefStor *rs, char *data, +void callContent(runctx_p ct, RefStor *rs, char *data, Type *type, int flags); +void callContentGroup(runctx_p oct, RefStor *rs, char *data, SemGroup *sg, int flags, int dop); /* * stmt.c */ -void InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, - Type *type); +void InterpTypeDefaultInit(runctx_p oct, RefStor *rs, char *data, + runesize_t bytes, Type *type); /*void InterpSemGroupDefaultInit(RefStor *rs, char *data, int bytes, SemGroup *sg, int isglobal);*/ @@ -95,7 +97,8 @@ void InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, */ int StorCompareSame (void *s1, void *s2, Type *type); int SameTypeSize(Type *t1, Type *t2); -void *getDeclarationData(Declaration *d, int dop, RefStor **prs, int doPRS); +void *getDeclarationData(runctx_p ct, Declaration *d, int dop, + RefStor **prs, int doPRS); /* * syscalls.c @@ -106,8 +109,8 @@ ex_func_t InternalSyscallLookup(string_t id, Type *type); /* * thread.c */ -void *isys_waitThreads(Exp *exp, RefStor **prs); -void *isys_wakeup(Exp *exp, RefStor **prs); -void *isys_sleep(Exp *exp, RefStor **prs); +void *isys_waitThreads(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_wakeup(runctx_p ct, Exp *exp, RefStor **prs); +void *isys_sleep(runctx_p ct, Exp *exp, RefStor **prs); void ic_thread_construct(Declaration *d, LValueStor *lvs); void ic_thread_destruct(Declaration *d, LValueStor *lvs); diff --git a/libi/exp.c b/libi/exp.c index 9499962..19c860a 100644 --- a/libi/exp.c +++ b/libi/exp.c @@ -7,43 +7,43 @@ #include "defs.h" -static void *InterpUnknownExp(Exp *exp, RefStor **prs); -static void *InterpAssExp(Exp *exp, RefStor **prs); -static void *InterpAndAndExp(Exp *exp, RefStor **prs); -static void *InterpOrOrExp(Exp *exp, RefStor **prs); -static void *InterpDotExp(Exp *exp, RefStor **prs); -static void *InterpDotAliasExp(Exp *exp, RefStor **prs); -static void *InterpStrIndExp(Exp *exp, RefStor **prs); -static void *InterpStrIndAliasExp(Exp *exp, RefStor **prs); -static void *InterpSemGrpIdExp(Exp *exp, RefStor **prs); -static void *InterpPtrIndExp(Exp *exp, RefStor **prs); -static void *InterpAryExp(Exp *exp, RefStor **prs); -static void *InterpAddrAryExp(Exp *exp, RefStor **prs); -static void *InterpAddrExp(Exp *exp, RefStor **prs); -static void *InterpBinaryOperExp(Exp *exp, RefStor **prs); -static void *InterpUnaryOperExp(Exp *exp, RefStor **prs); -static void *InterpCastExp(Exp *exp, RefStor **prs); -static void *InterpCallExp(Exp *exp, RefStor **prs); -static void *InterpIdExp(Exp *exp, RefStor **prs); -static void *InterpIdTypeExp(Exp *exp, RefStor **prs); -static void *InterpVoidExp(Exp *exp, RefStor **prs); -static void *InterpTypeofExp(Exp *exp, RefStor **prs); -static void *InterpSelfExp(Exp *exp, RefStor **prs); - -static void *InterpCachedConstantExp(Exp *exp, RefStor **prs); -static void *InterpDirect1CachedConstantExp(Exp *exp, RefStor **prs); -static void *InterpDirect2CachedConstantExp(Exp *exp, RefStor **prs); -static void *InterpDirect4CachedConstantExp(Exp *exp, RefStor **prs); -static void *InterpDirect8CachedConstantExp(Exp *exp, RefStor **prs); -static void *InterpDStringExp(Exp *exp, RefStor **prs); -static void *InterpSStringExp(Exp *exp, RefStor **prs); -static void *InterpCompoundExp(Exp *exp, RefStor **prs); +static void *InterpUnknownExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpAssExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpAndAndExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpOrOrExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDotExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDotAliasExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpStrIndExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpStrIndAliasExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpSemGrpIdExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpPtrIndExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpAryExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpAddrAryExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpAddrExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpBinaryOperExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpUnaryOperExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpCastExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpCallExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdTypeExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpVoidExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpTypeofExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpSelfExp(runctx_p ct, Exp *exp, RefStor **prs); + +static void *InterpCachedConstantExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDirect1CachedConstantExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDirect2CachedConstantExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDirect4CachedConstantExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDirect8CachedConstantExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpDStringExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpSStringExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpCompoundExp(runctx_p ct, Exp *exp, RefStor **prs); /* * InterpUnresolvedExp() - Do on-the-fly resolution of an expression */ void * -InterpUnresolvedExp(Exp *exp, RefStor **prs) +InterpUnresolvedExp(runctx_p ct, Exp *exp, RefStor **prs) { switch(exp->ex_Token) { case TOK_ASS: @@ -275,11 +275,11 @@ InterpUnresolvedExp(Exp *exp, RefStor **prs) exp->ex_Func = InterpUnknownExp; break; } - return(exp->ex_Func(exp, prs)); + return(exp->ex_Func(ct, exp, prs)); } static void * -InterpVoidExp(Exp *exp __unused, RefStor **prs __unused) +InterpVoidExp(runctx_p ct __unused, Exp *exp __unused, RefStor **prs __unused) { return(NULL); } @@ -292,11 +292,11 @@ InterpVoidExp(Exp *exp __unused, RefStor **prs __unused) * The ex_Func had better not need temporary storage in this case. */ static void * -InterpTypeofExp(Exp *exp, RefStor **prs __unused) +InterpTypeofExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { if (exp->ex_Lhs && exp->ex_Lhs->ex_Type->ty_Op == TY_DYNAMIC) { RefStor *rs = NULL; - Type *type = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + Type *type = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); if (exp->ex_AuxFlags[0] || exp->ex_AuxFlags[1]) { type = TypeToQualType(type, NULL, (type->ty_SQFlags & @@ -314,15 +314,15 @@ InterpTypeofExp(Exp *exp, RefStor **prs __unused) } static void * -InterpSelfExp(Exp *exp __unused, RefStor **prs __unused) +InterpSelfExp(runctx_p ct, Exp *exp __unused, RefStor **prs __unused) { - return(IContext->ct_ArgsCtx->ct_Data); + return(ct->ct_ArgsCtx->ct_Data); /* XXX assert not a dynamic type */ return(NULL); } static void * -InterpUnknownExp(Exp *exp, RefStor **prs __unused) +InterpUnknownExp(runctx_p ct __unused, Exp *exp, RefStor **prs __unused) { printf("Unknown Expression: %08x %s\n", exp->ex_Token, exp->ex_Id); dassert_exp(exp, 0); @@ -341,7 +341,7 @@ InterpUnknownExp(Exp *exp, RefStor **prs __unused) * back to the caller unless the caller requested temporary storage. */ static void * -InterpAssExp(Exp *exp, RefStor **prs) +InterpAssExp(runctx_p ct, Exp *exp, RefStor **prs) { void *lhs; void *rhs; @@ -352,8 +352,8 @@ InterpAssExp(Exp *exp, RefStor **prs) * We must always resolve the lhs before the rhs due to overlapping * temporary storage. */ - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs1); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs1); dassert_exp(exp, SameTypeSize(exp->ex_Lhs->ex_Type, exp->ex_Rhs->ex_Type)); if (exp->ex_Lhs->ex_Type->ty_Flags & TF_HASLVPTR) @@ -378,17 +378,17 @@ InterpAssExp(Exp *exp, RefStor **prs) * returned pointer. */ static void * -InterpAndAndExp(Exp *exp, RefStor **prs) +InterpAndAndExp(runctx_p ct, Exp *exp, RefStor **prs) { - TmpStor *ts = getExpTmpData(exp); + TmpStor *ts = getExpTmpData(ct, exp); Exp *lhs; Exp *rhs; lhs = exp->ex_Lhs; - ts->ts_Bool = *(d_bool_t *)lhs->ex_Func(lhs, prs); + ts->ts_Bool = *(d_bool_t *)lhs->ex_Func(ct, lhs, prs); if (ts->ts_Bool) { rhs = exp->ex_Rhs; - ts->ts_Bool = *(d_bool_t *)rhs->ex_Func(rhs, prs); + ts->ts_Bool = *(d_bool_t *)rhs->ex_Func(ct, rhs, prs); } return(&ts->ts_Bool); } @@ -401,18 +401,18 @@ InterpAndAndExp(Exp *exp, RefStor **prs) * returned pointer. */ static void * -InterpOrOrExp(Exp *exp, RefStor **prs) +InterpOrOrExp(runctx_p ct, Exp *exp, RefStor **prs) { TmpStor *ts; Exp *lhs; Exp *rhs; - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); lhs = exp->ex_Lhs; - ts->ts_Bool = *(d_bool_t *)lhs->ex_Func(lhs, prs); + ts->ts_Bool = *(d_bool_t *)lhs->ex_Func(ct, lhs, prs); if (ts->ts_Bool == 0) { rhs = exp->ex_Rhs; - ts->ts_Bool = *(d_bool_t *)rhs->ex_Func(rhs, prs); + ts->ts_Bool = *(d_bool_t *)rhs->ex_Func(ct, rhs, prs); } return(&ts->ts_Bool); } @@ -432,7 +432,7 @@ InterpOrOrExp(Exp *exp, RefStor **prs) * XXX procedural return? */ static void * -InterpDotExp(Exp *exp, RefStor **prs) +InterpDotExp(runctx_p ct, Exp *exp, RefStor **prs) { char *data; Declaration *d; @@ -445,16 +445,17 @@ InterpDotExp(Exp *exp, RefStor **prs) if (d->d_ScopeFlags & SCOPE_GLOBAL) { if (exp->ex_Flags & EXF_REQ_QUICK) - return(getDeclarationData(d, d->d_Op, NULL, 0)); + return(getDeclarationData(ct, d, d->d_Op, NULL, 0)); else - return(getDeclarationData(d, d->d_Op, prs, 1)); + return(getDeclarationData(ct, d, d->d_Op, prs, 1)); } - data = (char *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs) + d->d_Offset; + data = (char *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs) + + d->d_Offset; return(data); } static void * -InterpDotAliasExp(Exp *exp, RefStor **prs) +InterpDotAliasExp(runctx_p ct, Exp *exp, RefStor **prs) { Declaration *d; Exp *assexp; @@ -463,18 +464,18 @@ InterpDotAliasExp(Exp *exp, RefStor **prs) d = exp->ex_Decl; if (d->d_ScopeFlags & SCOPE_GLOBAL) { assexp = d->d_AliasDecl.ed_AssExp; - data = assexp->ex_Func(assexp, prs); + data = assexp->ex_Func(ct, assexp, prs); } else { - data = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); - PushObjectContext(data, exp->ex_Lhs->ex_Type->ty_Bytes); + data = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); + PushObjectContext(ct, data, exp->ex_Lhs->ex_Type->ty_Bytes); assexp = d->d_AliasDecl.ed_AssExp; - data = assexp->ex_Func(assexp, prs); + data = assexp->ex_Func(ct, assexp, prs); /* * warning: tail recursion if multiple aliases, on return the * context may not point to our object. */ - PopObjectContext(); + PopObjectContext(ct); } return(data); } @@ -486,7 +487,7 @@ InterpDotAliasExp(Exp *exp, RefStor **prs) * XXX procedures are special cased by TOK_CALL. */ static void * -InterpStrIndExp(Exp *exp, RefStor **prs) +InterpStrIndExp(runctx_p ct, Exp *exp, RefStor **prs) { char *data; PointerStor *s; @@ -502,9 +503,8 @@ InterpStrIndExp(Exp *exp, RefStor **prs) } /* XXX set prs */ /* XXX reference type? */ - data = getDeclarationData(exp->ex_Decl, - exp->ex_Decl->d_Op, - prs, 1); + data = getDeclarationData(ct, exp->ex_Decl, + exp->ex_Decl->d_Op, prs, 1); return data; } @@ -519,7 +519,7 @@ InterpStrIndExp(Exp *exp, RefStor **prs) * pointer type, in which case we have to evaluate the method procedure * at run-time and cannot use 'd'. XXX YYY this needs work! */ - s = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + s = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); if (exp->ex_Lhs->ex_Type->ty_Op == TY_REFTO || (exp->ex_Lhs->ex_Flags & EXF_INDREF) ) { @@ -588,7 +588,7 @@ InterpStrIndExp(Exp *exp, RefStor **prs) * XXX procedures are special cased by TOK_CALL. */ static void * -InterpStrIndAliasExp(Exp *exp, RefStor **prs) +InterpStrIndAliasExp(runctx_p ct, Exp *exp, RefStor **prs) { Declaration *d; Exp *assexp; @@ -597,10 +597,10 @@ InterpStrIndAliasExp(Exp *exp, RefStor **prs) d = exp->ex_Decl; if (d->d_ScopeFlags & SCOPE_GLOBAL) { assexp = d->d_AliasDecl.ed_AssExp; - data = assexp->ex_Func(assexp, prs); + data = assexp->ex_Func(ct, assexp, prs); } else { RefStor *rs = NULL; - PointerStor *s = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + PointerStor *s = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); data = s->s_Addr; if (data < s->s_Beg || data >= s->s_End) { @@ -612,21 +612,21 @@ InterpStrIndAliasExp(Exp *exp, RefStor **prs) } updateRefStor(prs, s->s_RefStor); relsRefStor(rs); - PushObjectContext(data, s->s_RefStor->rs_Type->ty_Bytes); + PushObjectContext(ct, data, s->s_RefStor->rs_Type->ty_Bytes); assexp = d->d_AliasDecl.ed_AssExp; - data = assexp->ex_Func(assexp, prs); + data = assexp->ex_Func(ct, assexp, prs); /* * warning: tail recursion if multiple aliases, on return the * context may not point to our object. */ - PopObjectContext(); + PopObjectContext(ct); } return(data); } void * -InterpSemGrpIdExp(Exp *exp, RefStor **prs) +InterpSemGrpIdExp(runctx_p ct, Exp *exp, RefStor **prs) { void *data = NULL; Type *type; @@ -641,7 +641,7 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) * XXX 'self' is really a dynamic/bound type XXX */ if (exp->ex_Lhs->ex_Token == TOK_SELF) { - type = IContext->ct_ArgsType; + type = ct->ct_ArgsType; } else { type = exp->ex_Lhs->ex_Type; } @@ -681,12 +681,12 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) dassert_exp(exp, 0); break; case SPECIAL_COUNT: - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = sg->sg_DeclCount; data = &ts->ts_Int32; break; case SPECIAL_VAR_COUNT: - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = sg->sg_VarCount; data = &ts->ts_Int32; break; @@ -702,7 +702,7 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) Exp *auxexp; auxexp = exp->ex_AuxExp; - idata = auxexp->ex_Func(auxexp, prs); + idata = auxexp->ex_Func(ct, auxexp, prs); d = FindDeclByIndex(sg, sg->sg_DeclCount - sg->sg_VarCount + *idata); @@ -734,7 +734,8 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) if (SimilarType(type2, exp->ex_Type)) { /* XXX set rs */ data = getDeclarationData( - d, d->d_Op, &rs, 1); + ct, d, d->d_Op, + &rs, 1); } else { fprintf(stderr, "Datatype mismatch " @@ -788,12 +789,12 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) data = &exp->u; break; case SPECIAL_COUNT: - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = -1; data = &ts->ts_Int32; break; case SPECIAL_VAR_COUNT: - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Int32 = -1; data = &ts->ts_Int32; break; @@ -809,13 +810,13 @@ InterpSemGrpIdExp(Exp *exp, RefStor **prs) * */ static void * -InterpPtrIndExp(Exp *exp, RefStor **prs) +InterpPtrIndExp(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *s; char *data; RefStor *rs = NULL; - s = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + s = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); if (exp->ex_Lhs->ex_Type->ty_Op == TY_REFTO) dassert_exp(exp, s->s_RefStor != NULL); if (s->s_Addr < s->s_Beg || s->s_Addr >= s->s_End) { @@ -840,15 +841,15 @@ InterpPtrIndExp(Exp *exp, RefStor **prs) * */ static void * -InterpAryExp(Exp *exp, RefStor **prs) +InterpAryExp(runctx_p ct, Exp *exp, RefStor **prs) { RefStor *rs = NULL; int32_t i; char *data; char *lhs; - i = *(int32_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + i = *(int32_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); if (exp->ex_Lhs->ex_Type->ty_Op == TY_PTRTO) { data = ((PointerStor *)lhs)->s_Addr; @@ -898,16 +899,16 @@ InterpAryExp(Exp *exp, RefStor **prs) } static void * -InterpAddrAryExp(Exp *exp, RefStor **prs) +InterpAddrAryExp(runctx_p ct, Exp *exp, RefStor **prs) { RefStor *rs = NULL; int32_t i; TmpStor *ts; char *lhs; - ts = getExpTmpData(exp); - i = *(int32_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + ts = getExpTmpData(ct, exp); + i = *(int32_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); if (exp->ex_Lhs->ex_Type->ty_Op == TY_PTRTO) { ts->ts_Pointer.s_Beg = ((PointerStor *)lhs)->s_Beg; @@ -952,7 +953,7 @@ InterpAddrAryExp(Exp *exp, RefStor **prs) } static void * -InterpAddrExp(Exp *exp, RefStor **prs) +InterpAddrExp(runctx_p ct, Exp *exp, RefStor **prs) { char *data; TmpStor *ts; @@ -964,8 +965,8 @@ InterpAddrExp(Exp *exp, RefStor **prs) * cannot be a reference type. */ dassert_exp(exp, exp->ex_Type->ty_Op != TY_REFTO); - ts = getExpTmpData(exp); - data = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + ts = getExpTmpData(ct, exp); + data = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); ts->ts_Pointer.s_Addr = data; ts->ts_Pointer.s_Beg = data; ts->ts_Pointer.s_End = data + exp->ex_Lhs->ex_Type->ty_Bytes; @@ -974,7 +975,7 @@ InterpAddrExp(Exp *exp, RefStor **prs) } static void * -InterpUnaryOperExp(Exp *exp, RefStor **prs) +InterpUnaryOperExp(runctx_p ct, Exp *exp, RefStor **prs) { void *data; Declaration *d; @@ -1006,7 +1007,7 @@ InterpUnaryOperExp(Exp *exp, RefStor **prs) * Execute the operator for the first time (later executions will run * directly through ex_Func) */ - data = exp->ex_Func(exp, prs); + data = exp->ex_Func(ct, exp, prs); /* * If the lhs converts to TOK_CONSTEXP, and the operator is declared @@ -1029,7 +1030,7 @@ InterpUnaryOperExp(Exp *exp, RefStor **prs) } static void * -InterpBinaryOperExp(Exp *exp, RefStor **prs) +InterpBinaryOperExp(runctx_p ct, Exp *exp, RefStor **prs) { void *data; Declaration *d; @@ -1065,7 +1066,7 @@ InterpBinaryOperExp(Exp *exp, RefStor **prs) * Execute the operator for the first time (later executions will run * directly through ex_Func) */ - data = exp->ex_Func(exp, prs); + data = exp->ex_Func(ct, exp, prs); /* * If the lhs and rhs sides convert to TOK_CONSTEXP, and the operator @@ -1103,31 +1104,36 @@ InterpBinaryOperExp(Exp *exp, RefStor **prs) } static void * -InterpCachedConstantExp(Exp *exp, RefStor **prs __unused) +InterpCachedConstantExp(runctx_p ct __unused, Exp *exp, + RefStor **prs __unused) { return(&exp->u); } static void * -InterpDirect1CachedConstantExp(Exp *exp, RefStor **prs __unused) +InterpDirect1CachedConstantExp(runctx_p ct __unused, Exp *exp, + RefStor **prs __unused) { return(&exp->ex_Int8); } static void * -InterpDirect2CachedConstantExp(Exp *exp, RefStor **prs __unused) +InterpDirect2CachedConstantExp(runctx_p ct __unused, Exp *exp, + RefStor **prs __unused) { return(&exp->ex_Int16); } static void * -InterpDirect4CachedConstantExp(Exp *exp, RefStor **prs __unused) +InterpDirect4CachedConstantExp(runctx_p ct __unused, Exp *exp, + RefStor **prs __unused) { return(&exp->ex_Int32); } static void * -InterpDirect8CachedConstantExp(Exp *exp, RefStor **prs __unused) +InterpDirect8CachedConstantExp(runctx_p ct __unused, Exp *exp, + RefStor **prs __unused) { return(&exp->ex_Int64); } @@ -1136,21 +1142,21 @@ InterpDirect8CachedConstantExp(Exp *exp, RefStor **prs __unused) * InterpDStringExp() - returns a pointer to a string */ static void * -InterpDStringExp(Exp *exp, RefStor **prs __unused) +InterpDStringExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); ts->ts_Pointer.s_Addr = __DECONST(char *, exp->ex_Id); ts->ts_Pointer.s_Beg = __DECONST(char *, exp->ex_Id); ts->ts_Pointer.s_End = __DECONST(char *, - exp->ex_Id + StrTableLen(exp->ex_Id)); + exp->ex_Id + StrTableLen(exp->ex_Id)); ts->ts_Pointer.s_RefStor = NULL; return(&ts->ts_Pointer); } static void * -InterpSStringExp(Exp *exp, RefStor **prs __unused) +InterpSStringExp(runctx_p ct __unused, Exp *exp, RefStor **prs __unused) { exp->ex_Func = InterpCachedConstantExp; exp->ex_Token = TOK_CONSTEXP; @@ -1170,7 +1176,7 @@ InterpSStringExp(Exp *exp, RefStor **prs __unused) * the object with its defaults. */ static void * -InterpCompoundExp(Exp *exp, RefStor **prs) +InterpCompoundExp(runctx_p ct, Exp *exp, RefStor **prs) { char *cdata; Exp *scan; @@ -1235,7 +1241,7 @@ InterpCompoundExp(Exp *exp, RefStor **prs) } else { dassert_exp(scan, d != NULL); while ((d->d_Op & DOPF_STORAGE) == 0 || - d->d_Op == DOP_GLOBAL_STORAGE + d->d_Op == DOP_GLOBAL_STORAGE ) { d = getSucc(&sg->sg_DeclList, &d->d_Node); dassert_exp(scan, d != NULL); @@ -1255,13 +1261,12 @@ InterpCompoundExp(Exp *exp, RefStor **prs) * assignments and type defaults are not reloaded (they've * already been loaded once). */ - cdata = getExpTmpData(exp); + cdata = getExpTmpData(ct, exp); - for ( - d = getHead(&sg->sg_DeclList); - d; - d = getSucc(&sg->sg_DeclList, &d->d_Node) - ) { + for (d = getHead(&sg->sg_DeclList); + d; + d = getSucc(&sg->sg_DeclList, &d->d_Node)) + { char *data; Type *dtype; @@ -1283,7 +1288,8 @@ InterpCompoundExp(Exp *exp, RefStor **prs) * constant-optimized. * * (and, later on, if the expression does not resolve to - * a constant-flagged return we cannot constant-optimize either). + * a constant-flagged return we cannot constant-optimize + * either). */ if (d->d_Op == DOP_GLOBAL_STORAGE && (d->d_StorDecl.ed_Type->ty_SQFlags & SF_CONST) == 0 @@ -1297,25 +1303,28 @@ InterpCompoundExp(Exp *exp, RefStor **prs) * non-lvalue case. */ if ((d->d_ScopeFlags & SCOPE_LVALUE) && - d->d_Op == DOP_ARGS_STORAGE + d->d_Op == DOP_ARGS_STORAGE ) { RefStor *rs = NULL; - data = scan->ex_Func(scan, &rs); + data = scan->ex_Func(ct, scan, &rs); dassert_exp(scan, d->d_Bytes == sizeof(LValueStor)); ((LValueStor *)(cdata + d->d_Offset))->s_Addr = data; ((LValueStor *)(cdata + d->d_Offset))->s_RefStor = rs; + if (((PointerStor *)data)->s_RefStor == (void *)(intptr_t)0x100000000fL) { + dassert_exp(scan, 0); + } /* reference transfered to lvalue storage */ } else if (dtype->ty_Bytes) { RefStor *rs = NULL; - data = scan->ex_Func(scan, &rs); + data = scan->ex_Func(ct, scan, &rs); dassert_exp(scan, (scan->ex_Flags & EXF_REQ_DSTORE) && - IContext != NULL && + ct != NULL && dtype->ty_Bytes == d->d_Bytes); switch(dtype->ty_Bytes) { case 1: @@ -1352,12 +1361,13 @@ InterpCompoundExp(Exp *exp, RefStor **prs) RefStor *rs = NULL; dassert_decl(d, (d->d_ScopeFlags & SCOPE_LVALUE) == 0); - data = d->d_StorDecl.ed_AssExp->ex_Func(d->d_StorDecl.ed_AssExp, &rs); + data = d->d_StorDecl.ed_AssExp->ex_Func( + ct, d->d_StorDecl.ed_AssExp, &rs); if ((d->d_StorDecl.ed_AssExp->ex_Flags & EXF_CONST) == 0) { isConst = 0; } - dassert_exp(exp, IContext != NULL); + dassert_exp(exp, ct != NULL); if (dtype->ty_Bytes) { bcopy(data, cdata + d->d_Offset, dtype->ty_Bytes); @@ -1367,7 +1377,7 @@ InterpCompoundExp(Exp *exp, RefStor **prs) relsRefStor(rs); } else if (d->d_Op != DOP_GLOBAL_STORAGE) { dassert_decl(d, (d->d_ScopeFlags & SCOPE_LVALUE) == 0); - InterpTypeDefaultInit(&IContext->ct_RefStor, + InterpTypeDefaultInit(ct, &ct->ct_RefStor, cdata + d->d_Offset, dtype->ty_Bytes, dtype); @@ -1412,13 +1422,13 @@ InterpCompoundExp(Exp *exp, RefStor **prs) /* * CAST */ -static void *interpCastExpSame(Exp *exp, RefStor **prs); -static void *interpCastExpPtrToCPtr(Exp *exp, RefStor **prs); -static void *interpCastExpPtrToRef(Exp *exp, RefStor **prs); -static void *interpCastExpAryToRef(Exp *exp, RefStor **prs); +static void *interpCastExpSame(runctx_p ct, Exp *exp, RefStor **prs); +static void *interpCastExpPtrToCPtr(runctx_p ct, Exp *exp, RefStor **prs); +static void *interpCastExpPtrToRef(runctx_p ct, Exp *exp, RefStor **prs); +static void *interpCastExpAryToRef(runctx_p ct, Exp *exp, RefStor **prs); static void * -InterpCastExp(Exp *exp, RefStor **prs) +InterpCastExp(runctx_p ct, Exp *exp, RefStor **prs) { void *data; int constOpt = 1; @@ -1527,7 +1537,7 @@ InterpCastExp(Exp *exp, RefStor **prs) exp->ex_Func = interpCastExpSame; } - data = exp->ex_Func(exp, prs); + data = exp->ex_Func(ct, exp, prs); /* * If the lhs converts to TOK_CONSTEXP, and the operator is declared @@ -1549,9 +1559,9 @@ InterpCastExp(Exp *exp, RefStor **prs) } static void * -interpCastExpSame(Exp *exp, RefStor **prs) +interpCastExpSame(runctx_p ct, Exp *exp, RefStor **prs) { - return(exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs)); + return(exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs)); } /* @@ -1561,9 +1571,9 @@ interpCastExpSame(Exp *exp, RefStor **prs) * out of band, through prs. */ static void * -interpCastExpPtrToCPtr(Exp *exp, RefStor **prs) +interpCastExpPtrToCPtr(runctx_p ct, Exp *exp, RefStor **prs) { - return(exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs)); + return(exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs)); } /* @@ -1579,13 +1589,13 @@ interpCastExpPtrToCPtr(Exp *exp, RefStor **prs) * the reference type. In that case we just use the reference type. */ void * -interpCastExpPtrToRef(Exp *exp, RefStor **prs) +interpCastExpPtrToRef(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *ps; dassert_exp(exp, exp->ex_Type->ty_Op == TY_REFTO); - ps = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + ps = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); if (ps->s_RefStor->rs_Type != exp->ex_Lhs->ex_Type) { if (exp->ex_Flags & EXF_CAST_VOIDP) ps->s_RefStor = &exp->ex_Type->ty_RefType.et_RefNull; @@ -1598,26 +1608,26 @@ interpCastExpPtrToRef(Exp *exp, RefStor **prs) } void * -interpCastExpAryToRef(Exp *exp, RefStor **prs __unused) +interpCastExpAryToRef(runctx_p ct __unused, Exp *exp, RefStor **prs __unused) { dassert_exp(exp, 0); return(NULL); } void * -interpCastExpVoid(Exp *exp, RefStor **prs __unused) +interpCastExpVoid(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; - exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); relsRefStor(rs); return(NULL); } void * -interpCastExpInteger(Exp *exp, RefStor **prs) +interpCastExpInteger(runctx_p ct, Exp *exp, RefStor **prs) { - void *data = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + void *data = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); int64_t v = 0; TmpStor *ts; @@ -1651,7 +1661,7 @@ interpCastExpInteger(Exp *exp, RefStor **prs) break; } - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); switch(exp->ex_AuxFlags[0]) { case 1: /* cast from signed 8 bit */ @@ -1694,7 +1704,7 @@ interpCastExpInteger(Exp *exp, RefStor **prs) * to lookup the real declaration at run-time. */ static void * -InterpCallExp(Exp *exp, RefStor **prs) +InterpCallExp(runctx_p oct, Exp *exp, RefStor **prs) { void *rhs; char *data; @@ -1715,9 +1725,9 @@ InterpCallExp(Exp *exp, RefStor **prs) if (ltype->ty_SQFlags & SF_METHOD) { d = exp->ex_Lhs->ex_Decl; } else { - d = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs1); + d = exp->ex_Lhs->ex_Func(oct, exp->ex_Lhs, &rs1); } - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs2); + rhs = exp->ex_Rhs->ex_Func(oct, exp->ex_Rhs, &rs2); /* * When calling through a procedure the resolver collapses TOK_STRIND @@ -1779,7 +1789,7 @@ InterpCallExp(Exp *exp, RefStor **prs) if (exp->ex_Type->ty_SQFlags & SF_LVALUE) { data = NULL; } else { - data = getExpTmpData(exp); + data = getExpTmpData(oct, exp); switch(exp->ex_Type->ty_Bytes) { case 4: *(int32_t *)data = 0; @@ -1792,7 +1802,7 @@ InterpCallExp(Exp *exp, RefStor **prs) } } - BuildArgsContext(d, &ct, exp->ex_Rhs->ex_Type, rhs); + BuildArgsContext(oct, &ct, d, exp->ex_Rhs->ex_Type, rhs); ct.ct_RetData = &data; ct.ct_RetRefStor = &ret; @@ -1831,21 +1841,21 @@ InterpCallExp(Exp *exp, RefStor **prs) return(data); } -static void *InterpIdStackExp(Exp *exp, RefStor **prs); -static void *InterpIdArgsExp(Exp *exp, RefStor **prs); -static void *InterpIdGlobalExp(Exp *exp, RefStor **prs); -static void *InterpIdGroupExp(Exp *exp, RefStor **prs); -static void *InterpIdAliasExp(Exp *exp, RefStor **prs); -static void *InterpIdProcExp(Exp *exp, RefStor **prs); -static void *InterpIdStackQuickExp(Exp *exp, RefStor **prs); -static void *InterpIdArgsQuickExp(Exp *exp, RefStor **prs); -static void *InterpIdGlobalQuickExp(Exp *exp, RefStor **prs); -static void *InterpIdGroupQuickExp(Exp *exp, RefStor **prs); +static void *InterpIdStackExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdArgsExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdGlobalExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdGroupExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdAliasExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdProcExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdStackQuickExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdArgsQuickExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdGlobalQuickExp(runctx_p ct, Exp *exp, RefStor **prs); +static void *InterpIdGroupQuickExp(runctx_p ct, Exp *exp, RefStor **prs); /* * ID (unoptimized) */ static void * -InterpIdExp(Exp *exp, RefStor **prs) +InterpIdExp(runctx_p ct, Exp *exp, RefStor **prs) { dassert_exp(exp, exp->ex_Decl != NULL); dassert_exp(exp, (exp->ex_Decl->d_Op & DOPF_STORAGE) || @@ -1888,9 +1898,10 @@ InterpIdExp(Exp *exp, RefStor **prs) default: break; } - return(exp->ex_Func(exp, prs)); + return(exp->ex_Func(ct, exp, prs)); #if 0 - return(getDeclarationData(exp->ex_Decl, exp->ex_Decl->d_Op, prs, 1)); + return(getDeclarationData(ct, exp->ex_Decl, + exp->ex_Decl->d_Op, prs, 1)); #endif } @@ -1898,36 +1909,40 @@ InterpIdExp(Exp *exp, RefStor **prs) * ID (DOP_STACK_STORAGE optimized) */ static void * -InterpIdStackExp(Exp *exp, RefStor **prs) +InterpIdStackExp(runctx_p ct, Exp *exp, RefStor **prs) { - return(getDeclarationData(exp->ex_Decl, DOP_STACK_STORAGE, prs, 1)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_STACK_STORAGE, + prs, 1)); } /* * ID (DOP_ARGS_STORAGE optimized) */ static void * -InterpIdArgsExp(Exp *exp, RefStor **prs) +InterpIdArgsExp(runctx_p ct, Exp *exp, RefStor **prs) { - return(getDeclarationData(exp->ex_Decl, DOP_ARGS_STORAGE, prs, 1)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_ARGS_STORAGE, + prs, 1)); } /* * ID (DOP_GLOBAL_STORAGE optimized) */ static void * -InterpIdGlobalExp(Exp *exp, RefStor **prs) +InterpIdGlobalExp(runctx_p ct, Exp *exp, RefStor **prs) { - return(getDeclarationData(exp->ex_Decl, DOP_GLOBAL_STORAGE, prs, 1)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_GLOBAL_STORAGE, + prs, 1)); } /* * ID (DOP_GROUP_STORAGE optimized) */ static void * -InterpIdGroupExp(Exp *exp, RefStor **prs) +InterpIdGroupExp(runctx_p ct, Exp *exp, RefStor **prs) { - return(getDeclarationData(exp->ex_Decl, DOP_GROUP_STORAGE, prs, 1)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_GROUP_STORAGE, + prs, 1)); } /* @@ -1937,14 +1952,14 @@ InterpIdGroupExp(Exp *exp, RefStor **prs) * evaluate the expression. */ static void * -InterpIdAliasExp(Exp *exp, RefStor **prs) +InterpIdAliasExp(runctx_p ct, Exp *exp, RefStor **prs) { char *data; Declaration *d; d = exp->ex_Decl; data = d->d_AliasDecl.ed_AssExp->ex_Func( - d->d_AliasDecl.ed_AssExp, prs); + ct, d->d_AliasDecl.ed_AssExp, prs); return(data); } @@ -1952,36 +1967,40 @@ InterpIdAliasExp(Exp *exp, RefStor **prs) * ID (DOP_STACK_STORAGE optimized) */ static void * -InterpIdStackQuickExp(Exp *exp, RefStor **prs __unused) +InterpIdStackQuickExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { - return(getDeclarationData(exp->ex_Decl, DOP_STACK_STORAGE, NULL, 0)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_STACK_STORAGE, + NULL, 0)); } /* * ID (DOP_ARGS_STORAGE optimized) */ static void * -InterpIdArgsQuickExp(Exp *exp, RefStor **prs __unused) +InterpIdArgsQuickExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { - return(getDeclarationData(exp->ex_Decl, DOP_ARGS_STORAGE, NULL, 0)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_ARGS_STORAGE, + NULL, 0)); } /* * ID (DOP_GLOBAL_STORAGE optimized) */ static void * -InterpIdGlobalQuickExp(Exp *exp, RefStor **prs __unused) +InterpIdGlobalQuickExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { - return(getDeclarationData(exp->ex_Decl, DOP_GLOBAL_STORAGE, NULL, 0)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_GLOBAL_STORAGE, + NULL, 0)); } /* * ID (DOP_GROUP_STORAGE optimized) */ static void * -InterpIdGroupQuickExp(Exp *exp, RefStor **prs __unused) +InterpIdGroupQuickExp(runctx_p ct, Exp *exp, RefStor **prs __unused) { - return(getDeclarationData(exp->ex_Decl, DOP_GROUP_STORAGE, NULL, 0)); + return(getDeclarationData(ct, exp->ex_Decl, DOP_GROUP_STORAGE, + NULL, 0)); } /* @@ -1990,9 +2009,9 @@ InterpIdGroupQuickExp(Exp *exp, RefStor **prs __unused) * Direct procedure reference XXX */ static void * -InterpIdProcExp(Exp *exp, RefStor **prs __unused) +InterpIdProcExp(runctx_p ct __unused, Exp *exp, RefStor **prs __unused) { - /*return(getDeclarationData(exp->ex_Decl, DOP_PROC));*/ + /*return(getDeclarationData(ct, exp->ex_Decl, DOP_PROC));*/ return(exp->ex_Decl); } @@ -2000,7 +2019,7 @@ InterpIdProcExp(Exp *exp, RefStor **prs __unused) * ID */ static void * -InterpIdTypeExp(Exp *exp __unused, RefStor **prs __unused) +InterpIdTypeExp(runctx_p ct __unused, Exp *exp __unused, RefStor **prs __unused) { return(NULL); } diff --git a/libi/export.h b/libi/export.h index c01a251..40a552c 100644 --- a/libi/export.h +++ b/libi/export.h @@ -14,8 +14,8 @@ extern string_t String_Main; void InternalConstructorDestructorAdd(InternalConstructor *ic); void IStmtError(Stmt *st, int err); -void *InterpUnresolvedExp(Exp *exp, RefStor **prs); +void *InterpUnresolvedExp(runctx_p ct, Exp *exp, RefStor **prs); void *heapAlloc(PointerStor *ps, Type *type, RefStor **prs); void LibIInit(void); -int InterpUnresolvedStmt(Context *ct, Stmt *st); +int InterpUnresolvedStmt(runctx_p ct, Stmt *st); void InternalSyscallAdd(InternalSyscall *sc); diff --git a/libi/iframe.c b/libi/iframe.c index f78beee..581fb50 100644 --- a/libi/iframe.c +++ b/libi/iframe.c @@ -7,5 +7,4 @@ #include "defs.h" -Context *IContext; int ICount; diff --git a/libi/iframe.h b/libi/iframe.h index 7a66405..60b7f24 100644 --- a/libi/iframe.h +++ b/libi/iframe.h @@ -6,21 +6,17 @@ */ typedef struct IFrame { - Context *if_SaveCtx; int if_SaveCount; } IFrame; static __inline void saveIFrame(IFrame *frame) { - frame->if_SaveCtx = IContext; frame->if_SaveCount = ICount; - IContext = NULL; } static __inline void restoreIFrame(IFrame *frame) { - IContext = frame->if_SaveCtx; ICount = frame->if_SaveCount; } diff --git a/libi/oper.c b/libi/oper.c index 840d36f..b71455d 100644 --- a/libi/oper.c +++ b/libi/oper.c @@ -47,53 +47,56 @@ typedef float Float32; typedef double Float64; typedef long double Float128; -#define GETDECLARATIONDATA(d) getDeclarationData((d), (d)->d_Op, NULL, 0) +#define GETDECLARATIONDATA(ct, d) \ + getDeclarationData((ct), (d), (d)->d_Op, NULL, 0) #define UNARY_OP(name, type, op) \ static void * \ -Oper ## name ## type(Exp *exp, RefStor **prs) \ +Oper ## name ## type(runctx_p ct, Exp *exp, RefStor **prs) \ { \ TmpStor *ts; \ \ - ts = getExpTmpData(exp); \ - ts->ts_ ## type = op *(type *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs);\ + ts = getExpTmpData(ct, exp); \ + ts->ts_ ## type = \ + op *(type *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ return(&ts->ts_ ## type); \ } \ #define UNARY_LVALUE_OP(name, type, op) \ static void * \ -Oper ## name ## type(Exp *exp, RefStor **prs) \ +Oper ## name ## type(runctx_p ct, Exp *exp, RefStor **prs) \ { \ void *s1; \ \ - s1 = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); \ + s1 = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ op *(type *)s1; \ return(s1); \ } \ #define BINARY_OP(name, ltype, rtype, op) \ static void * \ -Oper ## name ## ltype ## rtype(Exp *exp, RefStor **prs) \ +Oper ## name ## ltype ## rtype(runctx_p ct, Exp *exp, RefStor **prs) \ { \ ltype s1; \ TmpStor *ts; \ \ - ts = getExpTmpData(exp); \ - s1 = *(ltype *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); \ - ts->ts_ ## ltype = s1 op *(rtype *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs);\ + ts = getExpTmpData(ct, exp); \ + s1 = *(ltype *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ + ts->ts_ ## ltype = \ + s1 op *(rtype *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); \ return(&ts->ts_ ## ltype); \ } \ #define BINARY_LVALUE_OP(name, ltype, rtype, op) \ static void * \ -Oper ## name ## ltype ## rtype(Exp *exp, RefStor **prs) \ +Oper ## name ## ltype ## rtype(runctx_p ct, Exp *exp, RefStor **prs) \ { \ void *s1; \ rtype s2; \ RefStor *rs = NULL; \ \ - s1 = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); \ - s2 = *(rtype *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); \ + s1 = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ + s2 = *(rtype *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); \ *(ltype *)s1 op s2; \ relsRefStor(rs); \ return(s1); \ @@ -101,13 +104,14 @@ Oper ## name ## ltype ## rtype(Exp *exp, RefStor **prs) \ #define DCCONST_OP(name, ltype, rtype, op) \ static void * \ -Oper ## name ## ltype ## rtype ## _DC(Exp *exp, RefStor **prs __unused) \ +Oper ## name ## ltype ## rtype ## _DC(runctx_p ct, Exp *exp, \ + RefStor **prs __unused) \ { \ TmpStor *ts; \ \ - ts = getExpTmpData(exp); \ + ts = getExpTmpData(ct, exp); \ ts->ts_ ## ltype = \ - *(ltype *)GETDECLARATIONDATA(exp->ex_Lhs->ex_Decl) op \ + *(ltype *)GETDECLARATIONDATA(ct, exp->ex_Lhs->ex_Decl) op \ *(rtype *)&exp->ex_Rhs->u; \ return(&ts->ts_ ## ltype); \ } \ @@ -119,27 +123,28 @@ Oper ## name ## ltype ## rtype ## _DC(Exp *exp, RefStor **prs __unused) \ */ #define BOOL_BINARY_OP(name, ltype, rtype, op) \ static void * \ -Oper ## name ## ltype ## rtype(Exp *exp, RefStor **prs) \ +Oper ## name ## ltype ## rtype(runctx_p ct, Exp *exp, RefStor **prs) \ { \ TmpStor *ts; \ ltype s1; \ \ - ts = getExpTmpData(exp); \ - s1 = *(ltype *)exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); \ - ts->ts_Bool = s1 op \ - *(rtype *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); \ + ts = getExpTmpData(ct, exp); \ + s1 = *(ltype *)exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ + ts->ts_Bool = \ + s1 op *(rtype *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); \ return(&ts->ts_Bool); \ } #define BOOL_DCCONST_OP(name, ltype, rtype, op) \ static void * \ -Oper ## name ## ltype ## rtype ## _DC(Exp *exp, RefStor **prs __unused) \ +Oper ## name ## ltype ## rtype ## _DC(runctx_p ct, Exp *exp, \ + RefStor **prs __unused) \ { \ TmpStor *ts; \ \ - ts = getExpTmpData(exp); \ + ts = getExpTmpData(ct, exp); \ ts->ts_Bool = \ - *(ltype *)GETDECLARATIONDATA(exp->ex_Lhs->ex_Decl) op \ + *(ltype *)GETDECLARATIONDATA(ct, exp->ex_Lhs->ex_Decl) op \ *(rtype *)&exp->ex_Rhs->u; \ return(&ts->ts_Bool); \ } \ @@ -846,12 +851,12 @@ BOOL_DCCONST_OP_TYPES(noteq, !=) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_plplVoidPtr(Exp *exp, RefStor **prs) +Operptr_plplVoidPtr(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; Type *type; - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); /* * NOTE! due to void optimization ex_Type may not be what we want. * use the lhs type. @@ -873,12 +878,12 @@ Operptr_plplVoidPtr(Exp *exp, RefStor **prs) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_mimiVoidPtr(Exp *exp, RefStor **prs) +Operptr_mimiVoidPtr(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; Type *type; - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); /* * NOTE! due to void optimization ex_Type may not be what we want. * use the lhs type. @@ -902,27 +907,27 @@ Operptr_mimiVoidPtr(Exp *exp, RefStor **prs) * away overlapping temporary space. */ static void * -Operptr_addVoidPtrInt32(Exp *exp, RefStor **prs) +Operptr_addVoidPtrInt32(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; Type *type; TmpStor *ts; intptr_t count; - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); switch(exp->ex_Rhs->ex_Type->ty_Bytes) { case sizeof(int32_t): - count = *(int32_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + count = *(int32_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); break; case sizeof(int64_t): - count = *(int64_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + count = *(int64_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); break; default: dassert_exp(exp, 0); count = 0; break; } - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); type = exp->ex_Lhs->ex_Type; dassert_exp(exp, type->ty_Op == TY_PTRTO); type = type->ty_PtrType.et_Type; @@ -945,27 +950,27 @@ Operptr_addVoidPtrInt32(Exp *exp, RefStor **prs) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_subVoidPtrInt32(Exp *exp, RefStor **prs) +Operptr_subVoidPtrInt32(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; intptr_t count; Type *type; TmpStor *ts; - ts = getExpTmpData(exp); + ts = getExpTmpData(ct, exp); switch(exp->ex_Rhs->ex_Type->ty_Bytes) { case sizeof(int32_t): - count = *(int32_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + count = *(int32_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); break; case sizeof(int64_t): - count = *(int64_t *)exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); + count = *(int64_t *)exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); break; default: dassert_exp(exp, 0); count = 0; break; } - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); type = exp->ex_Lhs->ex_Type; dassert_exp(exp, type->ty_Op == TY_PTRTO); type = type->ty_PtrType.et_Type; @@ -978,7 +983,7 @@ Operptr_subVoidPtrInt32(Exp *exp, RefStor **prs) } /* - * Operptr_subVoidPtrInt32(): ptr + N + * Operptr_addVoidPtrInt32(): ptr + N * * Since our lhs is also our return storage we can simply pass the * reference through without messing with it. However, we must still @@ -988,14 +993,14 @@ Operptr_subVoidPtrInt32(Exp *exp, RefStor **prs) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_addVoidPtrInt32_DC(Exp *exp, RefStor **prs) +Operptr_addVoidPtrInt32_DC(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; Type *type; TmpStor *ts; - ts = getExpTmpData(exp); - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + ts = getExpTmpData(ct, exp); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); type = exp->ex_Lhs->ex_Type; dassert_exp(exp, type->ty_Op == TY_PTRTO); type = type->ty_PtrType.et_Type; @@ -1030,14 +1035,14 @@ Operptr_addVoidPtrInt32_DC(Exp *exp, RefStor **prs) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_subVoidPtrInt32_DC(Exp *exp, RefStor **prs) +Operptr_subVoidPtrInt32_DC(runctx_p ct, Exp *exp, RefStor **prs) { PointerStor *lhs; Type *type; TmpStor *ts; - ts = getExpTmpData(exp); - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); + ts = getExpTmpData(ct, exp); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); /* * NOTE! due to void optimization ex_Type may not be what we want. * use the lhs type. @@ -1076,7 +1081,7 @@ Operptr_subVoidPtrInt32_DC(Exp *exp, RefStor **prs) * Note that ex_Type may be void due to void optimizations. */ static void * -Operptr_ptr_subVoidPtrVoidPtr(Exp *exp, RefStor **prs __unused) +Operptr_ptr_subVoidPtrVoidPtr(runctx_p ct, Exp *exp, RefStor **prs __unused) { PointerStor *lhs; PointerStor *rhs; @@ -1088,10 +1093,10 @@ Operptr_ptr_subVoidPtrVoidPtr(Exp *exp, RefStor **prs __unused) * lhs becomes invalid when we resolve rhs, but we are not accessing * the contents of the pointers so it doesn't matter. */ - ts = getExpTmpData(exp); - lhs = exp->ex_Lhs->ex_Func(exp->ex_Lhs, &rs); + ts = getExpTmpData(ct, exp); + lhs = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, &rs); lhs = (void *)lhs->s_Addr; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); rhs = (void *)rhs->s_Addr; relsRefStor(rs); @@ -1130,18 +1135,18 @@ Operptr_ptr_subVoidPtrVoidPtr(Exp *exp, RefStor **prs __unused) */ #define BINARY_PTR_CMP(name, op) \ static void * \ -Oper ## name ## VoidRefVoidRef(Exp *exp, RefStor **prs) \ +Oper ## name ## VoidRefVoidRef(runctx_p ct, Exp *exp, RefStor **prs) \ { \ PointerStor *s1; \ PointerStor *s2; \ TmpStor *ts; \ \ - s1 = exp->ex_Lhs->ex_Func(exp->ex_Lhs, prs); \ + s1 = exp->ex_Lhs->ex_Func(ct, exp->ex_Lhs, prs); \ s1 = (void *)s1->s_Addr; \ - s2 = exp->ex_Rhs->ex_Func(exp->ex_Rhs, prs); \ + s2 = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, prs); \ s2 = (void *)s2->s_Addr; \ \ - ts = getExpTmpData(exp); \ + ts = getExpTmpData(ct, exp); \ ts->ts_Bool = (char *)s1 op (char *)s2; \ return(&ts->ts_Bool); \ } \ diff --git a/libi/refstor.c b/libi/refstor.c index f314414..8860f2c 100644 --- a/libi/refstor.c +++ b/libi/refstor.c @@ -7,8 +7,8 @@ #include "defs.h" -static void callConstructorDestructor(RefStor *rs, Declaration *d, - char *data, int flags); +static void callConstructorDestructor(runctx_p oct, RefStor *rs, + Declaration *d, char *data, int flags); static RefStor *rsCache; @@ -55,7 +55,8 @@ freeRefStor(RefStor *rs) rs->rs_Refs = 1; for (i = 0; i < rs->rs_Count; ++i) { if (type->ty_Flags & TF_HASDESTRUCT) { - callContent(rs, base, type, TF_HASDESTRUCT); + callContent(NULL, rs, base, + type, TF_HASDESTRUCT); if (rs->rs_Refs > 1) { --rs->rs_Refs; return; @@ -211,7 +212,7 @@ refContentGroup(char *data, SemGroup *sg, int dop) * */ void -callContent(RefStor *rs, char *data, Type *type, int flags) +callContent(runctx_p ct, RefStor *rs, char *data, Type *type, int flags) { dassert (type->ty_Flags & flags); @@ -225,19 +226,19 @@ callContent(RefStor *rs, char *data, Type *type, int flags) case TY_REFTO: break; case TY_CLASS: - callContentGroup(rs, data, type->ty_ClassType.et_SemGroup, + callContentGroup(ct, rs, data, type->ty_ClassType.et_SemGroup, flags, DOP_CLASS); break; case TY_ARGS: - callContentGroup(rs, data, type->ty_ArgsType.et_SemGroup, + callContentGroup(ct, rs, data, type->ty_ArgsType.et_SemGroup, flags, DOP_ARGS_STORAGE); break; case TY_COMPOUND: - callContentGroup(rs, data, type->ty_CompType.et_SemGroup, + callContentGroup(ct, rs, data, type->ty_CompType.et_SemGroup, flags, DOP_GROUP_STORAGE); break; case TY_VAR: - callContentGroup(rs, data, type->ty_VarType.et_SemGroup, + callContentGroup(ct, rs, data, type->ty_VarType.et_SemGroup, flags, DOP_ARGS_STORAGE); break; case TY_ARYOF: @@ -248,11 +249,11 @@ callContent(RefStor *rs, char *data, Type *type, int flags) } void -callContentGroup(RefStor *rs, char *data, SemGroup *sg, +callContentGroup(runctx_p oct, RefStor *rs, char *data, SemGroup *sg, int flags, int dop __unused) { Declaration *d; - Context *ct; + runctx_p ct; /* * If we are constructing a normal group and the group's global @@ -260,24 +261,25 @@ callContentGroup(RefStor *rs, char *data, SemGroup *sg, * first. */ if ((flags & TF_HASCONSTRUCT) && - (ct = sg->sg_GlobalContext) == NULL + (ct = sg->sg_GlobalContext) == NULL ) { ct = BuildSemGroupContext(sg, 1); sg->sg_GlobalContext = ct; - InterpSemGroupDefaultInit(&ct->ct_RefStor, ct->ct_Data, - ct->ct_Bytes, sg, 1); - callContentGroup(&ct->ct_RefStor, ct->ct_Data, sg, + InterpSemGroupDefaultInit(oct, &ct->ct_RefStor, + ct->ct_Data, ct->ct_Bytes, sg, 1); + callContentGroup(oct, &ct->ct_RefStor, ct->ct_Data, sg, TF_HASGCONSTRUCT, DOP_CLASS); } if (flags & TF_HASDESTRUCT) { for (d = sg->sg_DBase; d; d = d->d_DNext) { if (d->d_Op == DOP_PROC) { - callConstructorDestructor(rs, d, data, flags); + callConstructorDestructor(oct, rs, d, + data, flags); } else if (flags & TF_CONDESDATA) { dassert_decl(d, d->d_Op & DOPF_STORAGE); if (d->d_StorDecl.ed_Type->ty_Flags & flags) { - callContent(rs, + callContent(oct, rs, data + d->d_Offset, d->d_StorDecl.ed_Type, flags); @@ -288,11 +290,12 @@ callContentGroup(RefStor *rs, char *data, SemGroup *sg, if (flags & TF_HASCONSTRUCT) { for (d = sg->sg_CBase; d; d = d->d_CNext) { if (d->d_Op == DOP_PROC) { - callConstructorDestructor(rs, d, data, flags); + callConstructorDestructor(oct, rs, d, + data, flags); } else if (flags & TF_CONDESDATA) { dassert_decl(d, d->d_Op & DOPF_STORAGE); if (d->d_StorDecl.ed_Type->ty_Flags & flags) { - callContent(rs, + callContent(oct, rs, data + d->d_Offset, d->d_StorDecl.ed_Type, flags); @@ -304,11 +307,12 @@ callContentGroup(RefStor *rs, char *data, SemGroup *sg, for (d = sg->sg_GBase; d; d = d->d_GNext) { if (d->d_Op == DOP_PROC && (d->d_ScopeFlags & SCOPE_DESTRUCTOR)) { - callConstructorDestructor(rs, d, data, flags); + callConstructorDestructor(oct, rs, d, + data, flags); } else if (flags & TF_CONDESDATA) { dassert_decl(d, d->d_Op & DOPF_STORAGE); if (d->d_StorDecl.ed_Type->ty_Flags & flags) { - callContent(rs, + callContent(oct, rs, data + d->d_Offset, d->d_StorDecl.ed_Type, flags); @@ -320,11 +324,12 @@ callContentGroup(RefStor *rs, char *data, SemGroup *sg, for (d = sg->sg_GBase; d; d = d->d_GNext) { if (d->d_Op == DOP_PROC && (d->d_ScopeFlags & SCOPE_CONSTRUCTOR)) { - callConstructorDestructor(rs, d, data, flags); + callConstructorDestructor(oct, rs, d, + data, flags); } else if (flags & TF_CONDESDATA) { dassert_decl(d, d->d_Op & DOPF_STORAGE); if (d->d_StorDecl.ed_Type->ty_Flags & flags) { - callContent(rs, + callContent(oct, rs, data + d->d_Offset, d->d_StorDecl.ed_Type, flags); @@ -339,7 +344,8 @@ callContentGroup(RefStor *rs, char *data, SemGroup *sg, * create a new context to hold our 'arguments'. */ static void -callConstructorDestructor(RefStor *rs, Declaration *d, char *data, int flags) +callConstructorDestructor(runctx_p oct, RefStor *rs, Declaration *d, + char *data, int flags) { Context ct; LValueStor lvs; /* our argument storage */ @@ -371,7 +377,7 @@ callConstructorDestructor(RefStor *rs, Declaration *d, char *data, int flags) } d->d_ProcDecl.ed_IFunc(d, &lvs); } else { - BuildArgsContext(d, &ct, + BuildArgsContext(oct, &ct, d, d->d_ProcDecl.ed_Type->ty_ProcType.et_ArgsType, &lvs); ct.ct_RetData = NULL; ct.ct_RetRefStor = &ret; diff --git a/libi/stmt.c b/libi/stmt.c index 2278aca..65be15c 100644 --- a/libi/stmt.c +++ b/libi/stmt.c @@ -25,29 +25,29 @@ #include "defs.h" -static int InterpImportStmt(Context *ct, Stmt *st); -static int InterpUnknownStmt(Context *ct, Stmt *st); -static int InterpDeclStmt(Context *ct, Stmt *st); -static int InterpBlockStmt(Context *ct, Stmt *st); -static int InterpProcStmt(Context *ct, Stmt *st); -static int InterpThreadedProcStmt(Context *ct, Stmt *st); -static int InterpNopStmt(Context *ct, Stmt *st); -static int InterpLoopStmt(Context *ct, Stmt *st); -static int InterpBreakContStmt(Context *ct, Stmt *st); -static int InterpIfElseStmt(Context *ct, Stmt *st); -static int InterpReturnStmt(Context *ct, Stmt *st); -static int InterpResultStmt(Context *ct, Stmt *st); -static int InterpThreadScheduleStmt(Context *dummy, Stmt *st); -static int InterpSwitchExpStmt(Context *ct, Stmt *st); -static int InterpSwitchTypeStmt(Context *ct, Stmt *st); -static int InterpCaseStmt(Context *ct, Stmt *st); -static int InterpExpStmt(Context *ct, Stmt *st); +static int InterpImportStmt(runctx_p ct, Stmt *st); +static int InterpUnknownStmt(runctx_p ct, Stmt *st); +static int InterpDeclStmt(runctx_p ct, Stmt *st); +static int InterpBlockStmt(runctx_p ct, Stmt *st); +static int InterpProcStmt(runctx_p ct, Stmt *st); +static int InterpThreadedProcStmt(runctx_p ct, Stmt *st); +static int InterpNopStmt(runctx_p ct, Stmt *st); +static int InterpLoopStmt(runctx_p ct, Stmt *st); +static int InterpBreakContStmt(runctx_p ct, Stmt *st); +static int InterpIfElseStmt(runctx_p ct, Stmt *st); +static int InterpReturnStmt(runctx_p ct, Stmt *st); +static int InterpResultStmt(runctx_p ct, Stmt *st); +static int InterpThreadScheduleStmt(runctx_p dummy, Stmt *st); +static int InterpSwitchExpStmt(runctx_p ct, Stmt *st); +static int InterpSwitchTypeStmt(runctx_p ct, Stmt *st); +static int InterpCaseStmt(runctx_p ct, Stmt *st); +static int InterpExpStmt(runctx_p ct, Stmt *st); static __inline -void ICOUNT(void) +void ICOUNT(runctx_p ct) { ++ICount; - if (IContext->ct_SchedPreempt && ICount > 5000) { + if (ct->ct_SchedPreempt && ICount > 5000) { IFrame frame; saveIFrame(&frame); @@ -66,13 +66,13 @@ void ICOUNT(void) */ static __inline void -interpSemanticEnter(Stmt *st) +interpSemanticEnter(runctx_p ct, Stmt *st) { SemGroup *sg; dassert_stmt(st, st->st_Flags & STF_SEMANTIC); sg = st->st_MyGroup; - bzero(IContext->ct_Data + sg->sg_BlkOffset, sg->sg_BlkBytes); + bzero(ct->ct_Data + sg->sg_BlkOffset, sg->sg_BlkBytes); } /* @@ -83,7 +83,7 @@ interpSemanticEnter(Stmt *st) */ static __inline void -interpSemanticExit(Stmt *st) +interpSemanticExit(runctx_p ct, Stmt *st) { SemGroup *sg = st->st_MyGroup; int dop; @@ -93,11 +93,12 @@ interpSemanticExit(Stmt *st) else dop = DOP_GROUP_STORAGE; if (sg->sg_DBase != NULL) { - callContentGroup(&IContext->ct_RefStor, IContext->ct_Data, + callContentGroup(ct, &ct->ct_RefStor, ct->ct_Data, sg, TF_HASDESTRUCT|TF_CONDESDATA, dop); } - if (sg->sg_SRBase != NULL) - dropContentGroup(IContext->ct_Data, sg, dop); + if (sg->sg_SRBase != NULL) { + dropContentGroup(ct->ct_Data, sg, dop); + } } /* @@ -112,7 +113,7 @@ interpSemanticExit(Stmt *st) * up a new empty Stmt. */ int -InterpUnresolvedStmt(Context *ct, Stmt *st) +InterpUnresolvedStmt(runctx_p ct, Stmt *st) { switch(st->st_Op) { case ST_Import: @@ -199,7 +200,7 @@ InterpUnresolvedStmt(Context *ct, Stmt *st) } static int -InterpUnknownStmt(Context *ct __unused, Stmt *st) +InterpUnknownStmt(runctx_p ct __unused, Stmt *st) { IStmtError(st, STMT_ERR_UNSUPPORTED); return(0); @@ -208,11 +209,11 @@ InterpUnknownStmt(Context *ct __unused, Stmt *st) /* * InterpImportStmt() - locate the 'main' function and execute it. * - * This is the only Interp function for which IContext may be + * This is the only Interp function for which ct may be * NULL on entry. */ static int -InterpImportStmt(Context *dummy __unused, Stmt *st) +InterpImportStmt(runctx_p oct, Stmt *st) { Declaration *d; Type *argsType; @@ -256,10 +257,10 @@ InterpImportStmt(Context *dummy __unused, Stmt *st) * The passed context simply exists to allow us to backtrace * the subroutine stack. * - * XXX IContext must be set for storage initialization but do - * we want the procedure args to be in the IContext stack? + * XXX ct must be set for storage initialization but do + * we want the procedure args to be in the ct stack? */ - BuildArgsContext(d, &ct, argsType, args); + BuildArgsContext(NULL, &ct, d, argsType, args); data = (void *)&p->p_RetVal; ct.ct_RetData = &data; ct.ct_RetRefStor = &ret; @@ -279,7 +280,7 @@ InterpImportStmt(Context *dummy __unused, Stmt *st) * type defaults are handled here. */ if ((sg->sg_Flags & SGF_NOINIT) == 0) { - InterpSemGroupDefaultInit(&ct.ct_RefStor, ct.ct_Data, + InterpSemGroupDefaultInit(oct, &ct.ct_RefStor, ct.ct_Data, ct.ct_Bytes, sg, 0); } @@ -351,7 +352,7 @@ InterpImportStmt(Context *dummy __unused, Stmt *st) /* * Call the procedure body. Ignore the break/continue result code. * - * NOTE! There is no IContext, do not call ICOUNT() here. + * NOTE! There is no current ct, do not call ICOUNT() here. */ (void)body->st_Func(&ct, body); @@ -378,7 +379,7 @@ InterpImportStmt(Context *dummy __unused, Stmt *st) * class heirarchy. */ static int -InterpDeclStmt(Context *dummy __unused, Stmt *st) +InterpDeclStmt(runctx_p ct, Stmt *st) { Declaration *d = st->st_DeclStmt.es_Decl; Exp *assexp; @@ -393,36 +394,36 @@ InterpDeclStmt(Context *dummy __unused, Stmt *st) rs = NULL; assexp = d->d_StorDecl.ed_AssExp; - ptr = assexp->ex_Func(assexp, &rs); + ptr = assexp->ex_Func(ct, assexp, &rs); dassert_decl(d, d->d_Offset + d->d_StorDecl.ed_Type->ty_Bytes - <= IContext->ct_Bytes); + <= ct->ct_Bytes); /* * note: no prior content to drop */ - bcopy(ptr, IContext->ct_Data + d->d_Offset, + bcopy(ptr, ct->ct_Data + d->d_Offset, d->d_StorDecl.ed_Type->ty_Bytes); if (d->d_StorDecl.ed_Type->ty_Flags & TF_HASLVPTR) { refContent( - IContext->ct_Data + d->d_Offset, + ct->ct_Data + d->d_Offset, d->d_StorDecl.ed_Type); } relsRefStor(rs); if (d->d_StorDecl.ed_Type->ty_Flags & TF_HASCONSTRUCT) { - callContent( - &IContext->ct_RefStor, - IContext->ct_Data + d->d_Offset, + callContent(ct, &ct->ct_RefStor, + ct->ct_Data + d->d_Offset, d->d_StorDecl.ed_Type, TF_HASCONSTRUCT); } } else if ((d->d_StorDecl.ed_Type->ty_Flags & TF_NOINIT) == 0) { InterpTypeDefaultInit( - &IContext->ct_RefStor, - IContext->ct_Data + d->d_Offset, - IContext->ct_Bytes - d->d_Offset, + ct, + &ct->ct_RefStor, + ct->ct_Data + d->d_Offset, + ct->ct_Bytes - d->d_Offset, d->d_StorDecl.ed_Type); } break; @@ -447,20 +448,20 @@ InterpDeclStmt(Context *dummy __unused, Stmt *st) * InterpBlockStmt() - interpret a Block statement */ static int -InterpBlockStmt(Context *dummy __unused, Stmt *st) +InterpBlockStmt(runctx_p ct, Stmt *st) { Stmt *scan; int r; again: r = 0; - interpSemanticEnter(st); + interpSemanticEnter(ct, st); for (scan = getHead(&st->st_List); scan; scan = getSucc(&st->st_List, &scan->st_Node)) { - ICOUNT(); - if ((r = scan->st_Func(NULL, scan)) != 0) + ICOUNT(ct); + if ((r = scan->st_Func(ct, scan)) != 0) break; } if (r > 0) { @@ -469,7 +470,7 @@ again: if (++r == 0) /* CONTINUE-1 */ goto again; } - interpSemanticExit(st); + interpSemanticExit(ct, st); return(r); } @@ -479,7 +480,7 @@ again: * The passed ct represents the procedure's arguments. */ static int -InterpProcStmt(Context *argsct, Stmt *st) +InterpProcStmt(runctx_p argsct, Stmt *st) { Stmt *scan; Context ct; @@ -488,7 +489,8 @@ InterpProcStmt(Context *argsct, Stmt *st) int64_t data[(st->st_MyGroup->sg_Bytes + isize) / isize]; int64_t tmpdata[(st->st_MyGroup->sg_TmpBytes + isize) / isize]; - PushProcContext(argsct, &ct, st->st_MyGroup, data, tmpdata); + PushProcContext(argsct, &ct, argsct->ct_CallCtx, + st->st_MyGroup, data, tmpdata); if (st->st_ProcStmt.es_Decl->d_ScopeFlags & SCOPE_PREEMPT) ct.ct_SchedPreempt = 1; @@ -496,14 +498,14 @@ InterpProcStmt(Context *argsct, Stmt *st) * Execute the procedure body */ again: - interpSemanticEnter(st); + interpSemanticEnter(&ct, st); for (scan = getHead(&st->st_List); scan; scan = getSucc(&st->st_List, &scan->st_Node)) { - ICOUNT(); - if ((r = scan->st_Func(NULL, scan)) != 0) + ICOUNT(argsct); + if ((r = scan->st_Func(&ct, scan)) != 0) break; } @@ -511,7 +513,7 @@ again: --r; /* BREAK-1 */ } else if (r < 0) { if (++r == 0) { /* CONTINUE-1 */ - interpSemanticExit(st); + interpSemanticExit(&ct, st); goto again; } } @@ -533,7 +535,7 @@ again: ct.ct_Parent = NULL; threadWakeup1(&tc->tc_List); } - interpSemanticExit(st); + interpSemanticExit(&ct, st); PopProcContext(&ct, st->st_MyGroup); return(r); } @@ -551,19 +553,24 @@ again: static void startInterpProcStmt(void *data); static int -InterpThreadedProcStmt(Context *argsct, Stmt *st) +InterpThreadedProcStmt(runctx_p argsct, Stmt *st) { + runctx_p savectx; ThreadCall tc; IFrame frame; + /*assert(argsct->ct_CallCtx == IContext);*/ tc.tc_ArgsCtx = argsct; tc.tc_Stmt = st; initList(&tc.tc_List); argsct->ct_ThreadData = &tc; + savectx = argsct->ct_CallCtx; + argsct->ct_CallCtx = NULL; /* hack */ threadCreate(startInterpProcStmt, &tc); saveIFrame(&frame); threadStop(&tc.tc_List, 0); restoreIFrame(&frame); + argsct->ct_CallCtx = savectx; return(0); } @@ -588,7 +595,7 @@ startInterpProcStmt(void *data) * InterpNopStmt() - interpret a NOP */ static int -InterpNopStmt(Context *dummy __unused, Stmt *st __unused) +InterpNopStmt(runctx_p dummy __unused, Stmt *st __unused) { return(0); } @@ -607,16 +614,16 @@ InterpNopStmt(Context *dummy __unused, Stmt *st __unused) * */ static int -InterpLoopStmt(Context *dummy __unused, Stmt *st) +InterpLoopStmt(runctx_p ct, Stmt *st) { int r; RefStor *rs = NULL; - interpSemanticEnter(st); + interpSemanticEnter(ct, st); if (st->st_LoopStmt.es_Init && st->st_LoopStmt.es_Init->st_Op != ST_Nop) { - ICOUNT(); - r = st->st_LoopStmt.es_Init->st_Func(NULL, + ICOUNT(ct); + r = st->st_LoopStmt.es_Init->st_Func(ct, st->st_LoopStmt.es_Init); if (r) { IStmtError(st, STMT_ERR_UNSUPPORTED); @@ -629,28 +636,28 @@ InterpLoopStmt(Context *dummy __unused, Stmt *st) Exp *exp; Stmt *body; - ICOUNT(); + ICOUNT(ct); if ((exp = st->st_LoopStmt.es_BCond) != NULL) { - if (*(d_bool_t *)exp->ex_Func(exp, &rs) == 0) + if (*(d_bool_t *)exp->ex_Func(ct, exp, &rs) == 0) break; relsRefStor(rs); rs = NULL; } body = st->st_LoopStmt.es_Body; if (body->st_Op != ST_Nop) { - if ((r = body->st_Func(NULL, body)) != 0) { + if ((r = body->st_Func(ct, body)) != 0) { if (r != -1) break; r = 0; /* continue */ } } if ((exp = st->st_LoopStmt.es_AExp) != NULL) { - exp->ex_Func(exp, &rs); + exp->ex_Func(ct, exp, &rs); relsRefStor(rs); rs = NULL; } if ((exp = st->st_LoopStmt.es_ACond) != NULL) { - if (*(d_bool_t *)exp->ex_Func(exp, &rs) == 0) + if (*(d_bool_t *)exp->ex_Func(ct, exp, &rs) == 0) break; relsRefStor(rs); rs = NULL; @@ -661,7 +668,7 @@ InterpLoopStmt(Context *dummy __unused, Stmt *st) --r; /* break-N */ else if (r < 0) ++r; /* continue-N */ - interpSemanticExit(st); + interpSemanticExit(ct, st); return(r); } @@ -672,7 +679,7 @@ InterpLoopStmt(Context *dummy __unused, Stmt *st) * count so we simply return it. */ static int -InterpBreakContStmt(Context *dummy __unused, Stmt *st) +InterpBreakContStmt(runctx_p dummy __unused, Stmt *st) { return(st->st_BreakStmt.es_Count); } @@ -689,7 +696,7 @@ InterpBreakContStmt(Context *dummy __unused, Stmt *st) * our boolean cast code returns it directly. */ static int -InterpIfElseStmt(Context *dummy __unused, Stmt *st) +InterpIfElseStmt(runctx_p ct, Stmt *st) { int r; Exp *exp; @@ -697,18 +704,18 @@ InterpIfElseStmt(Context *dummy __unused, Stmt *st) RefStor *rs = NULL; again_if: - ICOUNT(); + ICOUNT(ct); exp = st->st_IfStmt.es_Exp; - cond = *(d_bool_t *)exp->ex_Func(exp, &rs); + cond = *(d_bool_t *)exp->ex_Func(ct, exp, &rs); relsRefStor(rs); if (cond) { r = st->st_IfStmt.es_TrueStmt->st_Func( - NULL, st->st_IfStmt.es_TrueStmt); + ct, st->st_IfStmt.es_TrueStmt); } else if (st->st_IfStmt.es_FalseStmt) { again_else: - ICOUNT(); + ICOUNT(ct); r = st->st_IfStmt.es_FalseStmt->st_Func( - NULL, st->st_IfStmt.es_FalseStmt); + ct, st->st_IfStmt.es_FalseStmt); } else { r = 0; } @@ -738,7 +745,7 @@ again_else: * now rather then when the procedure was called. */ static int -InterpReturnStmt(Context *dummy __unused, Stmt *st) +InterpReturnStmt(runctx_p ct, Stmt *st) { Exp *exp; @@ -746,26 +753,24 @@ InterpReturnStmt(Context *dummy __unused, Stmt *st) void *s1 = NULL; RefStor *rs = NULL; - s1 = exp->ex_Func(exp, &rs); + s1 = exp->ex_Func(ct, exp, &rs); if (st->st_RetStmt.es_ProcRetType->ty_SQFlags & SF_LVALUE) { - replaceRefStor(IContext->ct_RetRefStor, rs); - *IContext->ct_RetData = s1; + replaceRefStor(ct->ct_RetRefStor, rs); + *ct->ct_RetData = s1; } else if (exp->ex_Type->ty_Flags & TF_HASLVPTR) { - bcopy(s1, *IContext->ct_RetData, - exp->ex_Type->ty_Bytes); - refContent(*IContext->ct_RetData, exp->ex_Type); + bcopy(s1, *ct->ct_RetData, exp->ex_Type->ty_Bytes); + refContent(*ct->ct_RetData, exp->ex_Type); relsRefStor(rs); rs = allocRefStor(RSOP_TMPSPACE); rs->rs_Refs = 1; - rs->rs_Base = *IContext->ct_RetData; + rs->rs_Base = *ct->ct_RetData; rs->rs_Type = exp->ex_Type; - relsRefStor(*IContext->ct_RetRefStor); + relsRefStor(*ct->ct_RetRefStor); /* update without bumping rs_Refs further */ - *IContext->ct_RetRefStor = rs; + *ct->ct_RetRefStor = rs; } else { - bcopy(s1, *IContext->ct_RetData, - exp->ex_Type->ty_Bytes); - updateRefStor(IContext->ct_RetRefStor, NULL); + bcopy(s1, *ct->ct_RetData, exp->ex_Type->ty_Bytes); + updateRefStor(ct->ct_RetRefStor, NULL); relsRefStor(rs); } } @@ -781,7 +786,7 @@ InterpReturnStmt(Context *dummy __unused, Stmt *st) * running. XXX */ static int -InterpResultStmt(Context *dummy __unused, Stmt *st) +InterpResultStmt(runctx_p ct, Stmt *st) { Exp *exp; @@ -789,26 +794,24 @@ InterpResultStmt(Context *dummy __unused, Stmt *st) void *s1 = NULL; RefStor *rs = NULL; - s1 = exp->ex_Func(exp, &rs); + s1 = exp->ex_Func(ct, exp, &rs); if (st->st_RetStmt.es_ProcRetType->ty_SQFlags & SF_LVALUE) { - replaceRefStor(IContext->ct_RetRefStor, rs); - *IContext->ct_RetData = s1; + replaceRefStor(ct->ct_RetRefStor, rs); + *ct->ct_RetData = s1; } else if (exp->ex_Type->ty_Flags & TF_HASLVPTR) { - bcopy(s1, *IContext->ct_RetData, - exp->ex_Type->ty_Bytes); - refContent(*IContext->ct_RetData, exp->ex_Type); + bcopy(s1, *ct->ct_RetData, exp->ex_Type->ty_Bytes); + refContent(*ct->ct_RetData, exp->ex_Type); relsRefStor(rs); rs = allocRefStor(RSOP_TMPSPACE); rs->rs_Refs = 1; - rs->rs_Base = *IContext->ct_RetData; + rs->rs_Base = *ct->ct_RetData; rs->rs_Type = exp->ex_Type; - relsRefStor(*IContext->ct_RetRefStor); + relsRefStor(*ct->ct_RetRefStor); /* update without bumping rs_Refs further */ - *IContext->ct_RetRefStor = rs; + *ct->ct_RetRefStor = rs; } else { - bcopy(s1, *IContext->ct_RetData, - exp->ex_Type->ty_Bytes); - updateRefStor(IContext->ct_RetRefStor, NULL); + bcopy(s1, *ct->ct_RetData, exp->ex_Type->ty_Bytes); + updateRefStor(ct->ct_RetRefStor, NULL); relsRefStor(rs); } } @@ -817,13 +820,13 @@ InterpResultStmt(Context *dummy __unused, Stmt *st) * If we are a threaded procedure we have to detach the arguments * and return storage and wake-up the caller. */ - if (IContext->ct_ArgsCtx->ct_ThreadData) { - ThreadCall *tc = IContext->ct_ArgsCtx->ct_ThreadData; + if (ct->ct_ArgsCtx->ct_ThreadData) { + ThreadCall *tc = ct->ct_ArgsCtx->ct_ThreadData; - IContext->ct_ArgsCtx->ct_ThreadData = NULL; - IContext->ct_ArgsCtx = NULL; - IContext->ct_RetData = NULL; - IContext->ct_Parent = NULL; + ct->ct_ArgsCtx->ct_ThreadData = NULL; + ct->ct_ArgsCtx = NULL; + ct->ct_RetData = NULL; + ct->ct_Parent = NULL; threadWakeup1(&tc->tc_List); } return(0); @@ -838,7 +841,7 @@ InterpResultStmt(Context *dummy __unused, Stmt *st) * reasonable. This value should really be programmable. */ static int -InterpThreadScheduleStmt(Context *dummy __unused, Stmt *st) +InterpThreadScheduleStmt(runctx_p ct, Stmt *st) { IFrame frame; @@ -850,10 +853,10 @@ InterpThreadScheduleStmt(Context *dummy __unused, Stmt *st) ICount = 0; break; case SPECIAL_AUX_NOPREEMPT: - IContext->ct_SchedPreempt = 0; + ct->ct_SchedPreempt = 0; break; case SPECIAL_AUX_PREEMPT: - IContext->ct_SchedPreempt = 1; + ct->ct_SchedPreempt = 1; /* fall through */ default: if (ICount > 5000) { @@ -878,7 +881,7 @@ InterpThreadScheduleStmt(Context *dummy __unused, Stmt *st) * return. */ static int -InterpSwitchExpStmt(Context *dummy __unused, Stmt *st) +InterpSwitchExpStmt(runctx_p ct, Stmt *st) { Stmt *scan; Stmt *firstCase; @@ -894,7 +897,7 @@ again: */ swrs = NULL; crs = NULL; - s1 = st->st_SwStmt.es_Exp->ex_Func(st->st_SwStmt.es_Exp, &swrs); + s1 = st->st_SwStmt.es_Exp->ex_Func(ct, st->st_SwStmt.es_Exp, &swrs); swtype = st->st_SwStmt.es_Exp->ex_Type; /* @@ -912,7 +915,7 @@ again: if (scan == st->st_SwStmt.es_Default) /* skip default */ continue; casexp = scan->st_CaseStmt.es_Exp; - s2 = casexp->ex_Func(casexp, &crs); + s2 = casexp->ex_Func(ct, casexp, &crs); casexp = scan->st_CaseStmt.es_Exp; dassert_stmt(scan, SameTypeSize(swtype, casexp->ex_Type)); if (StorCompareSame(s1, s2, swtype)) @@ -935,8 +938,8 @@ again: scan = firstCase; while (scan) { - ICOUNT(); - if ((r = scan->st_Func(NULL, scan)) != 0) { + ICOUNT(ct); + if ((r = scan->st_Func(ct, scan)) != 0) { if (r > 0) { if (--r == 0) { /* @@ -976,7 +979,7 @@ again: * return. */ static int -InterpSwitchTypeStmt(Context *dummy __unused, Stmt *st) +InterpSwitchTypeStmt(runctx_p ct, Stmt *st) { Stmt *scan; Stmt *firstCase; @@ -996,11 +999,11 @@ again: exp = st->st_SwStmt.es_Exp; rs = NULL; if (exp->ex_Type->ty_Op == TY_DYNAMIC) { - swtype = exp->ex_Func(exp, &rs); - dassert(IContext->ct_TmpOffset == 0); + swtype = exp->ex_Func(ct, exp, &rs); + dassert(ct->ct_TmpOffset == 0); dassert(swtype != NULL); } else { - /*exp->ex_Func(st->st_SwStmt.es_Exp);*/ + /*exp->ex_Func(ct, st->st_SwStmt.es_Exp);*/ swtype = st->st_SwStmt.es_Exp->ex_Type; } @@ -1019,10 +1022,10 @@ again: continue; exp = scan->st_CaseStmt.es_Exp; if (exp->ex_Type->ty_Op == TY_DYNAMIC) { - ctype = exp->ex_Func(exp, NULL); - dassert(IContext->ct_TmpOffset == 0); + ctype = exp->ex_Func(ct, exp, NULL); + dassert(ct->ct_TmpOffset == 0); } else { - /*exp->ex_Func(scan->st_CaseStmt.es_Exp);*/ + /*exp->ex_Func(ct, scan->st_CaseStmt.es_Exp);*/ ctype = exp->ex_Type; } if (SameType(swtype, ctype, ctype->ty_SQFlags)) @@ -1044,8 +1047,8 @@ again: */ scan = firstCase; while (scan) { - ICOUNT(); - if ((r = scan->st_Func(NULL, scan)) != 0) { + ICOUNT(ct); + if ((r = scan->st_Func(ct, scan)) != 0) { if (r > 0) { if (--r == 0) { /* @@ -1084,21 +1087,21 @@ again: * a break/continue/return/whatever. */ static int -InterpCaseStmt(Context *dummy __unused, Stmt *st) +InterpCaseStmt(runctx_p ct, Stmt *st) { Stmt *scan; int r = 0; - interpSemanticEnter(st); + interpSemanticEnter(ct, st); for (scan = getHead(&st->st_List); scan; scan = getSucc(&st->st_List, &scan->st_Node)) { - ICOUNT(); - if ((r = scan->st_Func(NULL, scan)) != 0) + ICOUNT(ct); + if ((r = scan->st_Func(ct, scan)) != 0) break; } - interpSemanticExit(st); + interpSemanticExit(ct, st); return(r); } @@ -1118,11 +1121,11 @@ InterpCaseStmt(Context *dummy __unused, Stmt *st) * be passed as NULL. */ static int -InterpExpStmt(Context *dummy __unused, Stmt *st) +InterpExpStmt(runctx_p ct, Stmt *st) { RefStor *rs = NULL; - st->st_ExpStmt.es_Exp->ex_Func(st->st_ExpStmt.es_Exp, &rs); + st->st_ExpStmt.es_Exp->ex_Func(ct, st->st_ExpStmt.es_Exp, &rs); relsRefStor(rs); return(0); } @@ -1137,7 +1140,8 @@ InterpExpStmt(Context *dummy __unused, Stmt *st) * on it. */ void -InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) +InterpTypeDefaultInit(runctx_p oct, RefStor *rs, char *data, + runesize_t bytes, Type *type) { int didSomething = 0; SemGroup *sg; @@ -1153,9 +1157,9 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) /* * note: no need to save/restore ExpTmpOffset() */ - PushTmpDefaultContext(&ct, type->ty_TmpBytes, tmpBuf); + PushTmpDefaultContext(oct, &ct, type->ty_TmpBytes, tmpBuf); - ptr = type->ty_AssExp->ex_Func(type->ty_AssExp, &rs2); + ptr = type->ty_AssExp->ex_Func(&ct, type->ty_AssExp, &rs2); dassert_type(type, type->ty_Bytes <= bytes); bcopy(ptr, data, type->ty_Bytes); if (type->ty_Flags & TF_HASLVPTR) @@ -1163,7 +1167,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) relsRefStor(rs2); PopTmpDefaultContext(&ct, type->ty_TmpBytes); if (type->ty_Flags & TF_HASCONSTRUCT) - callContent(rs, data, type, TF_HASCONSTRUCT); + callContent(oct, rs, data, type, TF_HASCONSTRUCT); /* didSomething = 1 */ return; } @@ -1171,7 +1175,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) case TY_CLASS: sg = type->ty_ClassType.et_SemGroup; if ((sg->sg_Flags & SGF_NOINIT) == 0) { - InterpSemGroupDefaultInit(rs, data, bytes, sg, 0); + InterpSemGroupDefaultInit(oct, rs, data, bytes, sg, 0); didSomething = 1; } break; @@ -1205,6 +1209,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) subtype = type->ty_AryType.et_Type; for (i = 0; i < type->ty_AryType.et_Count; ++i) { InterpTypeDefaultInit( + oct, rs, data + i * subtype->ty_Bytes, bytes - i * subtype->ty_Bytes, @@ -1216,7 +1221,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) case TY_COMPOUND: sg = type->ty_CompType.et_SemGroup; if ((sg->sg_Flags & SGF_NOINIT) == 0) { - InterpSemGroupDefaultInit(rs, data, bytes, sg, 0); + InterpSemGroupDefaultInit(oct, rs, data, bytes, sg, 0); didSomething = 1; } break; @@ -1226,7 +1231,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) case TY_ARGS: /* procedure arguments */ sg = type->ty_ArgsType.et_SemGroup; if ((sg->sg_Flags & SGF_NOINIT) == 0) { - InterpSemGroupDefaultInit(rs, data, bytes, sg, 0); + InterpSemGroupDefaultInit(oct, rs, data, bytes, sg, 0); didSomething = 1; } break; @@ -1235,7 +1240,7 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) dassert_type(type, 0); } if (type->ty_Flags & TF_HASCONSTRUCT) { - callContent(rs, data, type, TF_HASCONSTRUCT); + callContent(oct, rs, data, type, TF_HASCONSTRUCT); didSomething = 1; } if (didSomething == 0) { @@ -1260,8 +1265,8 @@ InterpTypeDefaultInit(RefStor *rs, char *data, runesize_t bytes, Type *type) * this might cause a misoptimization of the non-global case. */ void -InterpSemGroupDefaultInit(RefStor *rs, char *data, runesize_t bytes, - SemGroup *sg, int isglobal) +InterpSemGroupDefaultInit(runctx_p oct, RefStor *rs, char *data, + runesize_t bytes, SemGroup *sg, int isglobal) { Declaration *d; int didSomething = 0; @@ -1269,7 +1274,7 @@ InterpSemGroupDefaultInit(RefStor *rs, char *data, runesize_t bytes, int64_t tmpBuf[(tmpBytes + sizeof(int64_t)) / sizeof(int64_t)]; Context ct; - PushTmpDefaultContext(&ct, tmpBytes, tmpBuf); + PushTmpDefaultContext(oct, &ct, tmpBytes, tmpBuf); /* * Setup ct_Data and ct_Bytes in case the defaults reference other @@ -1324,7 +1329,7 @@ InterpSemGroupDefaultInit(RefStor *rs, char *data, runesize_t bytes, assexp = d->d_StorDecl.ed_AssExp; - ptr = assexp->ex_Func(assexp, &rs2); + ptr = assexp->ex_Func(&ct, assexp, &rs2); type = d->d_StorDecl.ed_Type; dassert_decl(d, d->d_Offset + type->ty_Bytes <= bytes); bcopy(ptr, data + d->d_Offset, type->ty_Bytes); @@ -1332,12 +1337,12 @@ InterpSemGroupDefaultInit(RefStor *rs, char *data, runesize_t bytes, refContent(data + d->d_Offset, type); relsRefStor(rs2); if (type->ty_Flags & TF_HASCONSTRUCT) { - callContent(rs, data + d->d_Offset, + callContent(&ct, rs, data + d->d_Offset, type, TF_HASCONSTRUCT); } didSomething = 1; } else if ((type->ty_Flags & TF_NOINIT) == 0) { - InterpTypeDefaultInit(rs, data + d->d_Offset, + InterpTypeDefaultInit(&ct, rs, data + d->d_Offset, bytes - d->d_Offset, type); didSomething = 1; } diff --git a/libi/stor.c b/libi/stor.c index d277616..51c860b 100644 --- a/libi/stor.c +++ b/libi/stor.c @@ -44,9 +44,10 @@ SameTypeSize(Type *t1, Type *t2) * pass prs as NULL as an optimization and we have to deal with it here. */ void * -getDeclarationData(Declaration *d, int dop, RefStor **prs, int doPRS) +getDeclarationData(runctx_p ct, Declaration *d, int dop, + RefStor **prs, int doPRS) { - Context *ct = IContext; + runctx_p gct; switch(dop) { case DOP_ARGS_STORAGE: @@ -54,7 +55,6 @@ getDeclarationData(Declaration *d, int dop, RefStor **prs, int doPRS) * Storage relative to procedure arguments (XXX doesn't handle * nesting cases) */ - dassert((d->d_Scope.s_Flags & SCOPE_GLOBAL) == 0); while (d->d_MyGroup->sg_NestLevel != ct->ct_NestLevel) { dassert(ct->ct_NestLevel != 0); @@ -105,30 +105,30 @@ getDeclarationData(Declaration *d, int dop, RefStor **prs, int doPRS) * shouldn't do this. */ dassert(d->d_Scope.s_Flags & SCOPE_GLOBAL); - if ((ct = d->d_MyGroup->sg_GlobalContext) == NULL) { - ct = BuildSemGroupContext(d->d_MyGroup, 1); - d->d_MyGroup->sg_GlobalContext = ct; - InterpSemGroupDefaultInit(&ct->ct_RefStor, - ct->ct_Data, - ct->ct_Bytes, + if ((gct = d->d_MyGroup->sg_GlobalContext) == NULL) { + gct = BuildSemGroupContext(d->d_MyGroup, 1); + d->d_MyGroup->sg_GlobalContext = gct; + InterpSemGroupDefaultInit(ct, &gct->ct_RefStor, + gct->ct_Data, + gct->ct_Bytes, d->d_MyGroup, 1); - callContentGroup(&ct->ct_RefStor, - ct->ct_Data, + callContentGroup(ct, &gct->ct_RefStor, + gct->ct_Data, d->d_MyGroup, TF_HASGCONSTRUCT, DOP_CLASS); } - dassert(ct && d->d_Offset + d->d_Bytes <= ct->ct_Bytes); + dassert(gct && d->d_Offset + d->d_Bytes <= gct->ct_Bytes); #if USE_CONTEXT_REFSTOR if (doPRS) - updateRefStor(prs, &ct->ct_RefStor); + updateRefStor(prs, &gct->ct_RefStor); #endif - return(ct->ct_Data + d->d_Offset); + return(gct->ct_Data + d->d_Offset); case DOP_GROUP_STORAGE: /* * Storage relative to a class or compound object. This occurs * when we are initializing the defaults for an object and one - * element references another. e.g. 'int a; int b; int c = a + b' - * within a class. + * element references another. e.g. 'int a; int b; + * int c = a + b' within a class. */ dassert((d->d_Scope.s_Flags & SCOPE_GLOBAL) == 0); dassert(d->d_Offset + d->d_Bytes <= ct->ct_ObjBytes); diff --git a/libi/stor.h b/libi/stor.h index 5e66f41..86eb086 100644 --- a/libi/stor.h +++ b/libi/stor.h @@ -5,7 +5,6 @@ * COPYRIGHT file at the base of the distribution. */ -extern Context *IContext; extern int ICount; typedef struct ThreadCall { @@ -28,8 +27,8 @@ typedef struct ThreadCall { */ Context *BuildSemGroupContext(SemGroup *sg, int isglobal); -void InterpSemGroupDefaultInit(RefStor *rs, char *data, runesize_t bytes, - SemGroup *sg, int isglobal); +void InterpSemGroupDefaultInit(runctx_p ct, RefStor *rs, char *data, + runesize_t bytes, SemGroup *sg, int isglobal); void freeRefStor(RefStor *rs); #define REFSTOR_DEBUG 0 @@ -38,11 +37,13 @@ void freeRefStor(RefStor *rs); #if REFSTOR_DEBUG #define REFSTOR_DEBUG_ARGS , const char *file, int line #define REFSTOR_DEBUG_CALL , file, line -#define allocRefStor(op) allocRefStor_debug(op, __FILE__, __LINE__) -#define refsRefStor(rs) _refsRefStor(rs, __FILE__, __LINE__) -#define relsRefStor(rs) _relsRefStor(rs, __FILE__, __LINE__) -#define updateRefStor(prs, rs) _updateRefStor(prs, rs, __FILE__, __LINE__) -#define replaceRefStor(prs, rs) _replaceRefStor(prs, rs, __FILE__, __LINE__) +#define allocRefStor(op) allocRefStor_debug(op, __FILE__, __LINE__) +#define refsRefStor(rs) _refsRefStor(rs, __FILE__, __LINE__) +#define relsRefStor(rs) _relsRefStor(rs, __FILE__, __LINE__) +#define updateRefStor(prs, rs) \ + _updateRefStor(prs, rs, __FILE__, __LINE__) +#define replaceRefStor(prs, rs) \ + _replaceRefStor(prs, rs, __FILE__, __LINE__) #else #define REFSTOR_DEBUG_ARGS #define REFSTOR_DEBUG_CALL @@ -101,11 +102,10 @@ _replaceRefStor(RefStor **prs, RefStor *rs REFSTOR_DEBUG_ARGS) static __inline void * -getExpTmpData(Exp *exp) +getExpTmpData(runctx_p ct, Exp *exp) { - Context *ct = IContext; runesize_t offset = exp->ex_TmpOffset; -#if 0 +#if 1 dassert_exp(exp, (exp->ex_Flags & EXF_TMP_OK) && offset + exp->ex_Type->ty_Bytes <= ct->ct_TmpBytes); #endif diff --git a/libi/syscalls.c b/libi/syscalls.c index c7dc26e..0404282 100644 --- a/libi/syscalls.c +++ b/libi/syscalls.c @@ -10,15 +10,15 @@ #define IHSIZE 64 #define IHMASK (IHSIZE - 1) -static void *isys_iowait_rd(Exp *exp, RefStor **prs); -static void *isys_iowait_wr(Exp *exp, RefStor **prs); -static void *isys_read(Exp *exp, RefStor **prs); -static void *isys_write(Exp *exp, RefStor **prs); -static void *isys_open(Exp *exp, RefStor **prs); -static void *isys_close(Exp *exp, RefStor **prs); -static void *isys_lseek(Exp *exp, RefStor **prs); -static void *isys_bcopy(Exp *exp, RefStor **prs); -static void *isys_new(Exp *exp, RefStor **prs); +static void *isys_iowait_rd(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_iowait_wr(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_read(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_write(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_open(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_close(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_lseek(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_bcopy(runctx_p ct, Exp *exp, RefStor **prs); +static void *isys_new(runctx_p ct, Exp *exp, RefStor **prs); static InternalSyscall SysOpAry[] = { { .sc_Name = "iowait_rd", @@ -143,7 +143,7 @@ InternalSyscallLookup(string_t id, Type *type __unused) } static void * -isys_read(Exp *exp, RefStor **prs __unused) +isys_read(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; RefStor *rs = NULL; @@ -153,8 +153,8 @@ isys_read(Exp *exp, RefStor **prs __unused) int32_t bytes; } *rhs; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); dassert_exp(exp, rhs->buf.s_Addr >= rhs->buf.s_Beg && rhs->buf.s_Addr + rhs->bytes <= rhs->buf.s_End && @@ -166,7 +166,7 @@ isys_read(Exp *exp, RefStor **prs __unused) } static void * -isys_write(Exp *exp, RefStor **prs __unused) +isys_write(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; RefStor *rs = NULL; @@ -176,8 +176,8 @@ isys_write(Exp *exp, RefStor **prs __unused) int32_t bytes; } *rhs; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); dassert_exp(exp, rhs->buf.s_Addr >= rhs->buf.s_Beg && @@ -190,7 +190,7 @@ isys_write(Exp *exp, RefStor **prs __unused) } static void * -isys_open(Exp *exp, RefStor **prs __unused) +isys_open(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; RefStor *rs = NULL; @@ -201,8 +201,8 @@ isys_open(Exp *exp, RefStor **prs __unused) } *rhs; int bytes; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); bytes = strlen(rhs->path.s_Addr); /* XXX bounds check */ dassert_exp(exp, rhs->path.s_Addr >= rhs->path.s_Beg && @@ -216,7 +216,7 @@ isys_open(Exp *exp, RefStor **prs __unused) } static void * -isys_close(Exp *exp, RefStor **prs __unused) +isys_close(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; RefStor *rs = NULL; @@ -224,15 +224,15 @@ isys_close(Exp *exp, RefStor **prs __unused) int32_t fd; } *rhs; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); ts->ts_Int32 = close(rhs->fd); relsRefStor(rs); return(&ts->ts_Int32); } static void * -isys_lseek(Exp *exp, RefStor **prs __unused) +isys_lseek(runctx_p ct, Exp *exp, RefStor **prs __unused) { TmpStor *ts; RefStor *rs = NULL; @@ -243,15 +243,15 @@ isys_lseek(Exp *exp, RefStor **prs __unused) int32_t how; } *rhs; - ts = getExpTmpData(exp); - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + ts = getExpTmpData(ct, exp); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); ts->ts_Off = lseek(rhs->fd, rhs->off, rhs->how); relsRefStor(rs); return(&ts->ts_Off); } static void * -isys_iowait_rd(Exp *exp, RefStor **prs __unused) +isys_iowait_rd(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; struct { @@ -259,7 +259,7 @@ isys_iowait_rd(Exp *exp, RefStor **prs __unused) } *rhs; IFrame frame; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); saveIFrame(&frame); threadWaitEvent(rhs->fd, THWAIT_READ); restoreIFrame(&frame); @@ -269,7 +269,7 @@ isys_iowait_rd(Exp *exp, RefStor **prs __unused) } static void * -isys_iowait_wr(Exp *exp, RefStor **prs __unused) +isys_iowait_wr(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; struct { @@ -277,7 +277,7 @@ isys_iowait_wr(Exp *exp, RefStor **prs __unused) } *rhs; IFrame frame; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); saveIFrame(&frame); threadWaitEvent(rhs->fd, THWAIT_WRITE); restoreIFrame(&frame); @@ -287,7 +287,7 @@ isys_iowait_wr(Exp *exp, RefStor **prs __unused) } static void * -isys_bcopy(Exp *exp, RefStor **prs __unused) +isys_bcopy(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; struct { @@ -296,7 +296,7 @@ isys_bcopy(Exp *exp, RefStor **prs __unused) int32_t bytes; } *rhs; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); if (rhs->bytes > 0) { dassert_exp(exp, rhs->s.s_Addr >= rhs->s.s_Beg && @@ -313,7 +313,7 @@ isys_bcopy(Exp *exp, RefStor **prs __unused) } static void * -isys_new(Exp *exp, RefStor **prs __unused) +isys_new(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs2 = NULL; struct { @@ -325,7 +325,7 @@ isys_new(Exp *exp, RefStor **prs __unused) Type *type; char *base; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs2); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs2); ps = rhs->s.s_Addr; dassert_exp(exp, exp->ex_Rhs->ex_Lhs); dassert(rhs->count >= 0); @@ -368,7 +368,8 @@ isys_new(Exp *exp, RefStor **prs __unused) rs->rs_Base = base; rs->rs_Type = type; while (rhs->count) { - InterpTypeDefaultInit(rs, rs->rs_Base, type->ty_Bytes, type); + InterpTypeDefaultInit(ct, rs, rs->rs_Base, + type->ty_Bytes, type); --rhs->count; base += type->ty_Bytes; } diff --git a/libi/thread.c b/libi/thread.c index 2311f20..e7e61f4 100644 --- a/libi/thread.c +++ b/libi/thread.c @@ -16,7 +16,8 @@ typedef struct ThreadWait { } ThreadWait; void * -isys_waitThreads(Exp *exp __unused, RefStor **prs __unused) +isys_waitThreads(runctx_p ct __unused, Exp *exp __unused, + RefStor **prs __unused) { IFrame frame; @@ -27,7 +28,7 @@ isys_waitThreads(Exp *exp __unused, RefStor **prs __unused) } void * -isys_wakeup(Exp *exp, RefStor **prs __unused) +isys_wakeup(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; struct { @@ -36,7 +37,7 @@ isys_wakeup(Exp *exp, RefStor **prs __unused) ThreadClass *tc; ThreadWait *tw; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); tc = rhs->s.s_Addr; if ((tw = hashLookup(tc->tc_Wid, HASH_THREADWAIT)) == NULL) { fprintf(stderr, @@ -50,7 +51,7 @@ isys_wakeup(Exp *exp, RefStor **prs __unused) } void * -isys_sleep(Exp *exp, RefStor **prs __unused) +isys_sleep(runctx_p ct, Exp *exp, RefStor **prs __unused) { RefStor *rs = NULL; struct { @@ -61,7 +62,7 @@ isys_sleep(Exp *exp, RefStor **prs __unused) ThreadWait *tw; IFrame frame; - rhs = exp->ex_Rhs->ex_Func(exp->ex_Rhs, &rs); + rhs = exp->ex_Rhs->ex_Func(ct, exp->ex_Rhs, &rs); tc = rhs->s.s_Addr; if ((tw = hashLookup(tc->tc_Wid, HASH_THREADWAIT)) == NULL) { fprintf(stderr, diff --git a/librune/context.h b/librune/context.h index fc0ce75..2554461 100644 --- a/librune/context.h +++ b/librune/context.h @@ -38,6 +38,7 @@ typedef struct Context { runesize_t ct_TmpBytes; /* size of global temporary space */ runesize_t ct_TmpOffset; /* track temporary storage use */ int ct_Flags; /* CTF flags */ + struct Context *ct_CallCtx; /* parent context (backtrace) */ struct Context *ct_Parent; /* parent context (backtrace) */ char **ct_RetData; /* storage for return data */ RefStor **ct_RetRefStor; diff --git a/librune/exp.h b/librune/exp.h index 405d3b4..022acaf 100644 --- a/librune/exp.h +++ b/librune/exp.h @@ -31,7 +31,7 @@ typedef union TmpStor { void *ts_CPtr; } TmpStor; -typedef void * (*ex_func_t)(struct Exp *exp, RefStor **prs); +typedef void * (*ex_func_t)(runctx_p ctx, struct Exp *exp, RefStor **prs); /* * Exp - expression node diff --git a/librune/export.h b/librune/export.h index 44db03f..aacba4d 100644 --- a/librune/export.h +++ b/librune/export.h @@ -5,6 +5,8 @@ * COPYRIGHT file at the base of the distribution. */ +typedef struct Context *runctx_p; + #include "lex.h" #include "sym.h" #include "strtable.h" diff --git a/librune/stmt.h b/librune/stmt.h index dc8e50a..dabe802 100644 --- a/librune/stmt.h +++ b/librune/stmt.h @@ -12,7 +12,7 @@ struct Parse; * interpreter to deal with break/continue, and even though we do not * have exceptions we can theoretically use it to deal with those too. */ -typedef int (*st_func_t)(Context *ct, struct Stmt *st); +typedef int (*st_func_t)(runctx_p ct, struct Stmt *st); typedef struct Stmt { Node st_Node; /* node in list */ -- 2.41.0