11 * These types are active when dynamically loaded into rune for code
12 * generation or interpretation. However, when loaded as a shared library
13 * in a generated Rune executable, these types should already exist and
14 * be properly initialized in the Rune binary.
16 * We use a weak reference to allow for both cases.
18 Type _PointType = { .ty_Flags = 0 };
19 Type _RectType = { .ty_Flags = 0 };
20 Type _EventType = { .ty_Flags = 0 };
21 Type _EventPtrType = { .ty_Flags = 0 };
23 __weak_reference(_PointType, PointType);
24 __weak_reference(_RectType, RectType);
25 __weak_reference(_EventType, EventType);
26 __weak_reference(_EventPtrType, EventPtrType);
28 #define GENINTERNALCALL(name) \
31 gen_ ## name(genctx_p ct, Exp *exp) \
33 return GenInternalCallWrapper(ct, exp, "RuneSysCall_" #name); \
36 GENINTERNALCALL(xCreateWindow)
37 GENINTERNALCALL(xMoveResizeWindow)
38 GENINTERNALCALL(xCreateGC)
39 GENINTERNALCALL(xDestroyWindow)
40 GENINTERNALCALL(xMapWindow)
41 GENINTERNALCALL(xUnmapWindow)
42 GENINTERNALCALL(xClearWindow)
43 GENINTERNALCALL(xClearArea)
44 GENINTERNALCALL(xMoveWindow)
45 GENINTERNALCALL(xResizeWindow)
46 GENINTERNALCALL(xFreeGC)
47 GENINTERNALCALL(xFlush)
48 GENINTERNALCALL(xSync)
49 GENINTERNALCALL(xEvent)
50 GENINTERNALCALL(xDrawPoint)
51 GENINTERNALCALL(xDrawLine)
52 GENINTERNALCALL(xDrawRect)
53 GENINTERNALCALL(xFillRect)
54 GENINTERNALCALL(xAllocColor)
55 GENINTERNALCALL(xFreeColor)
56 GENINTERNALCALL(xSetForeground)
57 GENINTERNALCALL(xSetBackground)
58 GENINTERNALCALL(xDrawString)
59 GENINTERNALCALL(xDrawImageString)
60 GENINTERNALCALL(xTextWidth)
61 GENINTERNALCALL(xTextHeight)
62 GENINTERNALCALL(xTextDescent)
63 GENINTERNALCALL(xLoadFont)
64 GENINTERNALCALL(xUnloadFont)
66 static Syscall X11OpAry[] = {
67 { .sc_Name = "xCreateWindow",
68 .sc_RunFunc = (sys_run_t)RuneSysCall_xCreateWindow,
69 .sc_GenFunc = gen_xCreateWindow,
72 { .sc_Name = "xMoveResizeWindow",
73 .sc_RunFunc = (sys_run_t)RuneSysCall_xMoveResizeWindow,
74 .sc_GenFunc = gen_xMoveResizeWindow,
77 { .sc_Name = "xCreateGC",
78 .sc_RunFunc = (sys_run_t)RuneSysCall_xCreateGC,
79 .sc_GenFunc = gen_xCreateGC,
82 { .sc_Name = "xDestroyWindow",
83 .sc_RunFunc = (sys_run_t)RuneSysCall_xDestroyWindow,
84 .sc_GenFunc = gen_xDestroyWindow,
87 { .sc_Name = "xMapWindow",
88 .sc_RunFunc = (sys_run_t)RuneSysCall_xMapWindow,
89 .sc_GenFunc = gen_xMapWindow,
92 { .sc_Name = "xUnmapWindow",
93 .sc_RunFunc = (sys_run_t)RuneSysCall_xUnmapWindow,
94 .sc_GenFunc = gen_xUnmapWindow,
97 { .sc_Name = "xClearWindow",
98 .sc_RunFunc = (sys_run_t)RuneSysCall_xClearWindow,
99 .sc_GenFunc = gen_xClearWindow,
102 { .sc_Name = "xClearArea",
103 .sc_RunFunc = (sys_run_t)RuneSysCall_xClearArea,
104 .sc_GenFunc = gen_xClearArea,
107 { .sc_Name = "xMoveWindow",
108 .sc_RunFunc = (sys_run_t)RuneSysCall_xMoveWindow,
109 .sc_GenFunc = gen_xMoveWindow,
112 { .sc_Name = "xResizeWindow",
113 .sc_RunFunc = (sys_run_t)RuneSysCall_xResizeWindow,
114 .sc_GenFunc = gen_xResizeWindow,
117 { .sc_Name = "xFreeGC",
118 .sc_RunFunc = (sys_run_t)RuneSysCall_xFreeGC,
119 .sc_GenFunc = gen_xFreeGC,
122 { .sc_Name = "xFlush",
123 .sc_RunFunc = (sys_run_t)RuneSysCall_xFlush,
124 .sc_GenFunc = gen_xFlush,
127 { .sc_Name = "xSync",
128 .sc_RunFunc = (sys_run_t)RuneSysCall_xSync,
129 .sc_GenFunc = gen_xSync,
132 { .sc_Name = "xEvent",
133 .sc_RunFunc = (sys_run_t)RuneSysCall_xEvent,
134 .sc_GenFunc = gen_xEvent,
137 { .sc_Name = "xDrawPoint",
138 .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawPoint,
139 .sc_GenFunc = gen_xDrawPoint,
142 { .sc_Name = "xDrawLine",
143 .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawLine,
144 .sc_GenFunc = gen_xDrawLine,
147 { .sc_Name = "xDrawRect",
148 .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawRect,
149 .sc_GenFunc = gen_xDrawRect,
152 { .sc_Name = "xFillRect",
153 .sc_RunFunc = (sys_run_t)RuneSysCall_xFillRect,
154 .sc_GenFunc = gen_xFillRect,
157 { .sc_Name = "xAllocColor",
158 .sc_RunFunc = (sys_run_t)RuneSysCall_xAllocColor,
159 .sc_GenFunc = gen_xAllocColor,
162 { .sc_Name = "xFreeColor",
163 .sc_RunFunc = (sys_run_t)RuneSysCall_xFreeColor,
164 .sc_GenFunc = gen_xFreeColor,
167 { .sc_Name = "xSetForeground",
168 .sc_RunFunc = (sys_run_t)RuneSysCall_xSetForeground,
169 .sc_GenFunc = gen_xSetForeground,
172 { .sc_Name = "xSetBackground",
173 .sc_RunFunc = (sys_run_t)RuneSysCall_xSetBackground,
174 .sc_GenFunc = gen_xSetBackground,
177 { .sc_Name = "xDrawString",
178 .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawString,
179 .sc_GenFunc = gen_xDrawString,
182 { .sc_Name = "xDrawImageString",
183 .sc_RunFunc = (sys_run_t)RuneSysCall_xDrawImageString,
184 .sc_GenFunc = gen_xDrawImageString,
187 { .sc_Name = "xTextWidth",
188 .sc_RunFunc = (sys_run_t)RuneSysCall_xTextWidth,
189 .sc_GenFunc = gen_xTextWidth,
192 { .sc_Name = "xTextHeight",
193 .sc_RunFunc = (sys_run_t)RuneSysCall_xTextHeight,
194 .sc_GenFunc = gen_xTextHeight,
197 { .sc_Name = "xTextDescent",
198 .sc_RunFunc = (sys_run_t)RuneSysCall_xTextDescent,
199 .sc_GenFunc = gen_xTextDescent,
202 { .sc_Name = "xLoadFont",
203 .sc_RunFunc = (sys_run_t)RuneSysCall_xLoadFont,
204 .sc_GenFunc = gen_xLoadFont,
207 { .sc_Name = "xUnloadFont",
208 .sc_RunFunc = (sys_run_t)RuneSysCall_xUnloadFont,
209 .sc_GenFunc = gen_xUnloadFont,
214 void resolveClasses(void); /* generation glue */
215 void resolveStorage(void); /* generation glue */
216 void init(void); /* link glue */
224 * This code is only active when libgen is linked in for
225 * compiling or intepretation. It is inactive when a Rune
226 * executable is directly run.
229 initType(&EventType, NULL, TY_UNRESOLVED);
230 initType(&PointType, NULL, TY_UNRESOLVED);
231 initType(&RectType, NULL, TY_UNRESOLVED);
232 initPtrType(&EventPtrType, &EventType, 0);
234 for (i = 0; i < arysize(X11OpAry); ++i) {
235 SyscallAdd(&X11OpAry[i]);
237 InternalRegisterType("__internal_gfx_Point",
238 "PointType", &PointType);
239 InternalRegisterType("__internal_gfx_Rect",
240 "RectType", &RectType);
241 InternalRegisterType("__internal_gfx_Event",
242 "EventType", &EventType);
243 InternalRegisterType("__internal_gfx_EventPtr",
244 "EventPtrType", &EventPtrType);
246 runeaddlib("-lXext");
256 threadMutexLock(&XMtx);
257 if (SaveDisplay == NULL) {
259 SaveDisplay = XOpenDisplay(NULL);
261 threadMutexUnlock(&XMtx);
262 if (SaveDisplay == NULL)
263 fatal("Unable to open display");