comparison tools/mb_c_source.m4 @ 210:3fadd2f2742e

M4 macros to generate code for dynamic loading. - Introduce sprite. - Add mb_sprite_t and mb_sprite_lsym_t - mb_sprite_lsym_t is sprite with symbol that searched with linear search. - Add mb_sprite_lsym_t as first member variable of sprite. - Add symbol table to generated C code.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 12 Dec 2008 00:33:54 +0800
parents bcad1ccdf45c
children 5f144bab5de1
comparison
equal deleted inserted replaced
209:6f63aa67ed83 210:3fadd2f2742e
48 define([PATH_HIDE],) 48 define([PATH_HIDE],)
49 define([COORD_TRANSLATE],) 49 define([COORD_TRANSLATE],)
50 define([COORD_MATRIX],) 50 define([COORD_MATRIX],)
51 define([SHAPE_TRANSLATE],) 51 define([SHAPE_TRANSLATE],)
52 define([SHAPE_MATRIX],) 52 define([SHAPE_MATRIX],)
53 define([ADD_SYMBOL],)
53 divert[]]) 54 divert[]])
54 55
55 define([S_ADD_LINEAR_PAINT],[ 56 define([S_ADD_LINEAR_PAINT],[
56 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5); 57 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5);
57 ifelse(COUNT($6),0,,[dnl 58 ifelse(COUNT($6),0,,[dnl
203 SIMPORT([PATH_HIDE]) 204 SIMPORT([PATH_HIDE])
204 SIMPORT([COORD_TRANSLATE]) 205 SIMPORT([COORD_TRANSLATE])
205 SIMPORT([COORD_MATRIX]) 206 SIMPORT([COORD_MATRIX])
206 SIMPORT([SHAPE_TRANSLATE]) 207 SIMPORT([SHAPE_TRANSLATE])
207 SIMPORT([SHAPE_MATRIX]) 208 SIMPORT([SHAPE_MATRIX])
209 define([ADD_SYMBOL],)
208 divert[]]) 210 divert[]])
209 211
210 define([F_ADD_LINEAR_PAINT],[[ 212 define([F_ADD_LINEAR_PAINT],[[
211 stops = paint_linear_stops(obj->$1, 0, NULL); 213 stops = paint_linear_stops(obj->$1, 0, NULL);
212 free(stops); 214 free(stops);
260 define([PATH_HIDE],) 262 define([PATH_HIDE],)
261 define([COORD_TRANSLATE],) 263 define([COORD_TRANSLATE],)
262 define([COORD_MATRIX],) 264 define([COORD_MATRIX],)
263 define([SHAPE_TRANSLATE],) 265 define([SHAPE_TRANSLATE],)
264 define([SHAPE_MATRIX],) 266 define([SHAPE_MATRIX],)
267 define([ADD_SYMBOL],)
265 divert[]]) 268 divert[]])
266 269
267 define([REVERSE_VARS],[divert([-1]) 270 define([REVERSE_VARS],[divert([-1])
268 define([__REV_VAR],[]) 271 define([__REV_VAR],[])
269 define([PUSH_REV], [ 272 define([PUSH_REV], [
295 RIMPORT([PATH_HIDE]) 298 RIMPORT([PATH_HIDE])
296 RIMPORT([COORD_TRANSLATE]) 299 RIMPORT([COORD_TRANSLATE])
297 RIMPORT([COORD_MATRIX]) 300 RIMPORT([COORD_MATRIX])
298 RIMPORT([SHAPE_TRANSLATE]) 301 RIMPORT([SHAPE_TRANSLATE])
299 RIMPORT([SHAPE_MATRIX]) 302 RIMPORT([SHAPE_MATRIX])
303 define([ADD_SYMBOL],)
304 divert[]dnl
305 ])
306
307 define([Y_ADD_SYMBOL],[[{"$1", MB_SPRITE_OFFSET($1)},]])
308
309 define([DECLARE_SYMS], [divert([-1])
310 define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])])
311 define([ADD_LINEAR_PAINT])
312 define([ADD_RADIAL_PAINT])
313 define([COLOR_STOP])
314 define([REF_STOPS_RADIAL])
315 define([REF_STOPS_LINEAR])
316 define([ADD_PATH])
317 define([ADD_RECT])
318 define([ADD_COORD])
319 define([ADD_TEXT],)
320 define([FILL_SHAPE])
321 define([STROKE_SHAPE])
322 define([FILL_SHAPE_WITH_PAINT])
323 define([STROKE_SHAPE_WITH_PAINT])
324 define([STROKE_WIDTH])
325 define([GROUP_HIDE],)
326 define([RECT_HIDE],)
327 define([PATH_HIDE],)
328 define([COORD_TRANSLATE],)
329 define([COORD_MATRIX],)
330 define([SHAPE_TRANSLATE],)
331 define([SHAPE_MATRIX],)
332 YIMPORT([ADD_SYMBOL])
300 divert[]dnl 333 divert[]dnl
301 ]) 334 ])
302 335
303 define([MADBUTTERFLY],[dnl 336 define([MADBUTTERFLY],[dnl
304 [#include <stdio.h> 337 [#include <stdio.h>
308 #include <mb_redraw_man.h> 341 #include <mb_redraw_man.h>
309 #include <mb_shapes.h> 342 #include <mb_shapes.h>
310 #include <mb_paint.h> 343 #include <mb_paint.h>
311 #include "$1.h" 344 #include "$1.h"
312 345
346 #ifdef MB_SPRITE_OFFSET
347 #undef MB_SPRITE_OFFSET
348 #endif
349 #define MB_SPRITE_OFFSET(x) ((int)&((($1_t *)0)->x))
350
351 static
352 mb_sprite_lsym_entry_t $1_symbols[] = {]DECLARE_SYMS
353 $2[
354 };
355
356 #ifndef MB_LSYM_GET_OBJ_WITH_NAME
357 #define MB_LSYM_GET_OBJ_WITH_NAME
358 static
359 mb_obj_t *mb_lsym_get_obj_with_name(mb_sprite_lsym_t *lsym, const char *sym) {
360 int i;
361
362 for(i = 0; i < lsym->num_entries; i++) {
363 if(strcmp(lsym->entries[i].sym, sym) != 0)
364 continue;
365 return (mb_obj_t *)(((void *)lsym) + lsym->entries[i].offset);
366 }
367 return NULL;
368 }
369 #endif /* MB_LSYM_GET_OBJ_WITH_NAME */
370
371 void $1_free($1_t *);
372
313 $1_t *$1_new(redraw_man_t *rdman, coord_t *parent_coord) { 373 $1_t *$1_new(redraw_man_t *rdman, coord_t *parent_coord) {
314 $1_t *obj; 374 $1_t *obj;
315 grad_stop_t *stops = NULL;]DECLARE_VARS 375 grad_stop_t *stops = NULL;]DECLARE_VARS
316 $2[]dnl 376 $2[]dnl
317 [ 377 [
318 obj = ($1_t *)malloc(sizeof($1_t)); 378 obj = ($1_t *)malloc(sizeof($1_t));
319 if(obj == NULL) return NULL; 379 if(obj == NULL) return NULL;
380
381 obj->lsym.sprite.free = (void (*)(mb_sprite_t))$1_free;
382 obj->lsym.sprite.get_obj_with_name =
383 (mb_obj_t *(*)(mb_sprite_t *, const char *))mb_lsym_get_obj_with_name;
384 obj->lsym.num_entries =
385 sizeof($1_symbols) / sizeof(mb_sprite_lsym_entry_t);
386 obj->lsym.entries = $1_symbols;
387
320 obj->rdman = rdman; 388 obj->rdman = rdman;
321 ]SETUP_VARS 389 ]SETUP_VARS[
322 obj->root_coord = rdman_coord_new(rdman, parent_coord); 390 obj->root_coord = rdman_coord_new(rdman, parent_coord);]
323 $2 391 $2
324 [ return obj; 392 [ return obj;
325 } 393 }
326 394
327 void $1_free($1_t *obj) { 395 void $1_free($1_t *obj) {