From: Wolfgang (Blub) Bumiller Date: Sat, 11 Aug 2012 14:28:07 +0000 (+0200) Subject: ast macros to use the return value of a call, trying to spawn an entity, setting... X-Git-Tag: 0.1-rc1~349^2~19 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7b36bbf7b26c54541142783250617bd4472a3a13;p=xonotic%2Fgmqcc.git ast macros to use the return value of a call, trying to spawn an entity, setting a member, and reading the member back, using print+ftos to print it then --- diff --git a/test/ast-macros.h b/test/ast-macros.h index 56df82e..e11bd8d 100644 --- a/test/ast-macros.h +++ b/test/ast-macros.h @@ -58,6 +58,9 @@ do { \ #define BIN(op, a, b) \ (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b)) +#define ENTFIELD(a, b) \ +(ast_expression*)ast_entfield_new(ctx, (ast_expression*)(a), (ast_expression*)(b)) + #define CALL(what) \ do { \ ast_call *call = ast_call_new(ctx, (ast_expression*)what); \ @@ -69,6 +72,13 @@ do { \ STATE(call); \ } while(0) +#define ENDCALLWITH(as, where) \ + { \ + ast_expression *as = (ast_expression*)call; \ + where; \ + } \ +} while(0) + #define WHILE(cond) \ do { \ ast_expression *wh_cond = (ast_expression*)(cond); \ diff --git a/test/ast-test.c b/test/ast-test.c index de01d89..0db4a19 100644 --- a/test/ast-test.c +++ b/test/ast-test.c @@ -39,13 +39,23 @@ int main() DEFVAR(f5); DEFVAR(sHello); DEFVAR(print); + DEFVAR(ftos); + DEFVAR(spawn); DEFVAR(mema); + DEFVAR(pawn); /* opts_debug = true; */ BUILTIN(print, TYPE_VOID, -1); PARAM(TYPE_STRING, text); +ENDBUILTIN(); + +BUILTIN(ftos, TYPE_STRING, -2); +PARAM(TYPE_FLOAT, value); +ENDBUILTIN(); + +BUILTIN(spawn, TYPE_ENTITY, -3); ENDBUILTIN(); TESTINIT(); @@ -53,7 +63,10 @@ VAR(TYPE_FLOAT, f0); VAR(TYPE_FLOAT, f1); VAR(TYPE_FLOAT, f5); VAR(TYPE_STRING, sHello); +VAR(TYPE_ENTITY, pawn); + FIELD(TYPE_FLOAT, mema); + MKCONSTFLOAT(f0, 0.0); MKCONSTFLOAT(f1, 1.0); MKCONSTFLOAT(f5, 5.0); @@ -80,6 +93,19 @@ FUNCTION(main, TYPE_VOID); CALLPARAM(sHello) ENDCALL(); + CALL(spawn) + ENDCALLWITH(newent, STATE(ASSIGN(STORE_ENT, pawn, newent))); + + STATE(ASSIGN(STORE_F, ENTFIELD(pawn, mema), f5)); + + CALL(ftos) + CALLPARAM(ENTFIELD(pawn, mema)) + ENDCALLWITH(output, STATE(ASSIGN(STORE_F, vi, output))); + + CALL(print) + CALLPARAM(vi) + ENDCALL(); + ENDFUNCTION(main); ir = ir_builder_new("ast_test");