#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); \
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); \
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();
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);
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");