From: Wolfgang (Blub) Bumiller Date: Sat, 11 Aug 2012 14:10:33 +0000 (+0200) Subject: ast macros to create a field, generating fields in ast-test X-Git-Tag: 0.1-rc1~349^2~20 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=805c08e91475489453a80135f2157eb3a0f52a01 ast macros to create a field, generating fields in ast-test --- diff --git a/test/ast-macros.h b/test/ast-macros.h index ebb3a5b..56df82e 100644 --- a/test/ast-macros.h +++ b/test/ast-macros.h @@ -21,6 +21,17 @@ name = ast_value_new(ctx, #varname, type) #define MKGLOBAL(name) \ assert(globals_add(name) >= 0) +#define FIELD(type, name) \ +name = ast_value_new(ctx, #name, TYPE_FIELD); \ +do { \ + ast_value *field_##name = ast_value_new(ctx, #name, type); \ + name->expression.next = (ast_expression*)field_##name; \ + MKFIELD(name); \ +} while (0) + +#define MKFIELD(name) \ +assert(fields_add(name) >= 0) + #define MKCONSTFLOAT(name, value) \ do { \ name->isconst = true; \ diff --git a/test/ast-test.c b/test/ast-test.c index 3862144..de01d89 100644 --- a/test/ast-test.c +++ b/test/ast-test.c @@ -10,6 +10,7 @@ #define assert(x) do { if ( !(x) ) { printf("Assertion failed: %s\n", #x); abort(); } } while(0) VECTOR_MAKE(ast_value*, globals); +VECTOR_MAKE(ast_value*, fields); VECTOR_MAKE(ast_function*, functions); uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; @@ -39,6 +40,8 @@ int main() DEFVAR(sHello); DEFVAR(print); + DEFVAR(mema); + /* opts_debug = true; */ BUILTIN(print, TYPE_VOID, -1); @@ -50,6 +53,7 @@ VAR(TYPE_FLOAT, f0); VAR(TYPE_FLOAT, f1); VAR(TYPE_FLOAT, f5); VAR(TYPE_STRING, sHello); +FIELD(TYPE_FLOAT, mema); MKCONSTFLOAT(f0, 0.0); MKCONSTFLOAT(f1, 1.0); MKCONSTFLOAT(f5, 5.0); @@ -81,6 +85,12 @@ ENDFUNCTION(main); ir = ir_builder_new("ast_test"); assert(ir); + /* gen fields */ + for (i = 0; i < fields_elements; ++i) { + if (!ast_global_codegen(fields_data[i], ir)) { + assert(!"failed to generate field"); + } + } /* gen globals */ for (i = 0; i < globals_elements; ++i) { if (!ast_global_codegen(globals_data[i], ir)) {