/* * MAIN.C */ #include "defs.h" Display *SaveDisplay; pthread_mutex_t XMtx; /* * These types are active when dynamically loaded into rune for code * generation or interpretation. However, when loaded as a shared library * in a generated Rune executable, these types should already exist and * be properly initialized in the Rune binary. * * We use a weak reference to allow for both cases. */ Type _PointType = { .ty_Flags = 0 }; Type _RectType = { .ty_Flags = 0 }; Type _EventType = { .ty_Flags = 0 }; Type _EventPtrType = { .ty_Flags = 0 }; __weak_reference(_PointType, PointType); __weak_reference(_RectType, RectType); __weak_reference(_EventType, EventType); __weak_reference(_EventPtrType, EventPtrType); #define GENINTERNALCALL(name) \ \ static gendata_t * \ gen_ ## name(genctx_p ct, Exp *exp) \ { \ return GenInternalCallWrapper(ct, exp, "RuneSysCall_" #name); \ } GENINTERNALCALL(xCreateWindow) GENINTERNALCALL(xMoveResizeWindow) GENINTERNALCALL(xCreateGC) GENINTERNALCALL(xDestroyWindow) GENINTERNALCALL(xMapWindow) GENINTERNALCALL(xUnmapWindow) GENINTERNALCALL(xClearWindow) GENINTERNALCALL(xClearArea) GENINTERNALCALL(xMoveWindow) GENINTERNALCALL(xResizeWindow) GENINTERNALCALL(xFreeGC) GENINTERNALCALL(xFlush) GENINTERNALCALL(xSync) GENINTERNALCALL(xEvent) GENINTERNALCALL(xDrawPoint) GENINTERNALCALL(xDrawLine) GENINTERNALCALL(xDrawRect) GENINTERNALCALL(xFillRect) GENINTERNALCALL(xAllocColor) GENINTERNALCALL(xFreeColor) GENINTERNALCALL(xSetForeground) GENINTERNALCALL(xSetBackground) GENINTERNALCALL(xDrawString) GENINTERNALCALL(xDrawImageString) GENINTERNALCALL(xTextWidth) GENINTERNALCALL(xTextHeight) GENINTERNALCALL(xTextDescent) GENINTERNALCALL(xLoadFont) GENINTERNALCALL(xUnloadFont) static Syscall X11OpAry[] = { { .sc_Name = "xCreateWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xCreateWindow, .sc_GenFunc = gen_xCreateWindow, .sc_Id = NULL }, { .sc_Name = "xMoveResizeWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xMoveResizeWindow, .sc_GenFunc = gen_xMoveResizeWindow, .sc_Id = NULL }, { .sc_Name = "xCreateGC", .sc_RunFunc = (sys_run_t)RuneSysCall_xCreateGC, .sc_GenFunc = gen_xCreateGC, .sc_Id = NULL }, { .sc_Name = "xDestroyWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xDestroyWindow, .sc_GenFunc = gen_xDestroyWindow, .sc_Id = NULL }, { .sc_Name = "xMapWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xMapWindow, .sc_GenFunc = gen_xMapWindow, .sc_Id = NULL }, { .sc_Name = "xUnmapWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xUnmapWindow, .sc_GenFunc = gen_xUnmapWindow, .sc_Id = NULL }, { .sc_Name = "xClearWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xClearWindow, .sc_GenFunc = gen_xClearWindow, .sc_Id = NULL }, { .sc_Name = "xClearArea", .sc_RunFunc = (sys_run_t)RuneSysCall_xClearArea, .sc_GenFunc = gen_xClearArea, .sc_Id = NULL }, { .sc_Name = "xMoveWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xMoveWindow, .sc_GenFunc = gen_xMoveWindow, .sc_Id = NULL }, { .sc_Name = "xResizeWindow", .sc_RunFunc = (sys_run_t)RuneSysCall_xResizeWindow, .sc_GenFunc = gen_xResizeWindow, .sc_Id = NULL }, { .sc_Name = "xFreeGC", .sc_RunFunc = (sys_run_t)RuneSysCall_xFreeGC, .sc_GenFunc = gen_xFreeGC, .sc_Id = NULL }, { .sc_Name = "xFlush", .sc_RunFunc = (sys_run_t)RuneSysCall_xFlush, .sc_GenFunc = gen_xFlush, .sc_Id = NULL }, { .sc_Name = "xSync", .sc_RunFunc = (sys_run_t)RuneSysCall_xSync, .sc_GenFunc = gen_xSync, .sc_Id = NULL }, { .sc_Name = "xEvent", .sc_RunFunc = (sys_run_t)RuneSysCall_xEvent, .sc_GenFunc = gen_xEvent, .sc_Id = NULL }, { .sc_Name = "xDrawPoint", .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawPoint, .sc_GenFunc = gen_xDrawPoint, .sc_Id = NULL }, { .sc_Name = "xDrawLine", .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawLine, .sc_GenFunc = gen_xDrawLine, .sc_Id = NULL }, { .sc_Name = "xDrawRect", .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawRect, .sc_GenFunc = gen_xDrawRect, .sc_Id = NULL }, { .sc_Name = "xFillRect", .sc_RunFunc = (sys_run_t)RuneSysCall_xFillRect, .sc_GenFunc = gen_xFillRect, .sc_Id = NULL }, { .sc_Name = "xAllocColor", .sc_RunFunc = (sys_run_t)RuneSysCall_xAllocColor, .sc_GenFunc = gen_xAllocColor, .sc_Id = NULL }, { .sc_Name = "xFreeColor", .sc_RunFunc = (sys_run_t)RuneSysCall_xFreeColor, .sc_GenFunc = gen_xFreeColor, .sc_Id = NULL }, { .sc_Name = "xSetForeground", .sc_RunFunc = (sys_run_t)RuneSysCall_xSetForeground, .sc_GenFunc = gen_xSetForeground, .sc_Id = NULL }, { .sc_Name = "xSetBackground", .sc_RunFunc = (sys_run_t)RuneSysCall_xSetBackground, .sc_GenFunc = gen_xSetBackground, .sc_Id = NULL }, { .sc_Name = "xDrawString", .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawString, .sc_GenFunc = gen_xDrawString, .sc_Id = NULL }, { .sc_Name = "xDrawImageString", .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawImageString, .sc_GenFunc = gen_xDrawImageString, .sc_Id = NULL }, { .sc_Name = "xTextWidth", .sc_RunFunc = (sys_run_t)RuneSysCall_xTextWidth, .sc_GenFunc = gen_xTextWidth, .sc_Id = NULL }, { .sc_Name = "xTextHeight", .sc_RunFunc = (sys_run_t)RuneSysCall_xTextHeight, .sc_GenFunc = gen_xTextHeight, .sc_Id = NULL }, { .sc_Name = "xTextDescent", .sc_RunFunc = (sys_run_t)RuneSysCall_xTextDescent, .sc_GenFunc = gen_xTextDescent, .sc_Id = NULL }, { .sc_Name = "xLoadFont", .sc_RunFunc = (sys_run_t)RuneSysCall_xLoadFont, .sc_GenFunc = gen_xLoadFont, .sc_Id = NULL }, { .sc_Name = "xUnloadFont", .sc_RunFunc = (sys_run_t)RuneSysCall_xUnloadFont, .sc_GenFunc = gen_xUnloadFont, .sc_Id = NULL } }; void resolveClasses(void); /* generation glue */ void resolveStorage(void); /* generation glue */ void init(void); /* link glue */ void init(void) { size_t i; /* * This code is only active when libgen is linked in for * compiling or intepretation. It is inactive when a Rune * executable is directly run. */ if (LibGenActive) { initType(&EventType, NULL, TY_UNRESOLVED); initType(&PointType, NULL, TY_UNRESOLVED); initType(&RectType, NULL, TY_UNRESOLVED); initPtrType(&EventPtrType, &EventType, 0); for (i = 0; i < arysize(X11OpAry); ++i) { SyscallAdd(&X11OpAry[i]); } InternalRegisterType("__internal_gfx_Point", "PointType", &PointType); InternalRegisterType("__internal_gfx_Rect", "RectType", &RectType); InternalRegisterType("__internal_gfx_Event", "EventType", &EventType); InternalRegisterType("__internal_gfx_EventPtr", "EventPtrType", &EventPtrType); runeaddlib("-lx11"); runeaddlib("-lXext"); runeaddlib("-lX11"); } } void initXDisplay(void) { if (SaveDisplay) return; threadMutexLock(&XMtx); if (SaveDisplay == NULL) { XInitThreads(); SaveDisplay = XOpenDisplay(NULL); } threadMutexUnlock(&XMtx); if (SaveDisplay == NULL) fatal("Unable to open display"); } void resolveClasses(void) { } void resolveStorage(void) { }