/* victor@skynet:~/Desktop$ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :a AST_C_Target.hs [1 of 2] Compiling AST ( AST.hs, interpreted ) [2 of 2] Compiling AST_C_Target ( AST_C_Target.hs, interpreted ) Ok, modules loaded: AST_C_Target, AST. *AST_C_Target> translateProgram myProg */ #ifndef EXP_TEST_H #define EXP_TEST_H #include "test.h" typedef struct Exp_st Exp; typedef struct VarDecl_st VarDecl; /* E N U M S */ enum ExpKind_t { EXP_BUILTIN, EXP_APP, EXP_BINOP}; /* D E C L A R A T I O N S */ struct Exp_st { enum ExpKind_t kind; int line; union { struct { int op; Exp* lh; Exp* rh; } binop; Symbol* builtin; struct { Symbol* f; Exp* arg; } app; } u; }; Exp* exp_binop_new(int line, int op, Exp* lh, Exp* rh); Exp* exp_builtin_new(int line, Symbol* builtin); Exp* exp_app_new(int line, Symbol* f, Exp* arg); struct VarDecl_st { int line; Symbol* name; }; VarDecl* vardecl_new(int line, Symbol* name); #endif /* I M P L E M E N T A T I O N */ #include "exp_test.h" #define ALLOC(type) (type*)my_allocator(sizeof(type)) Exp* exp_binop_new(int line, int op, Exp* lh, Exp* rh) { Exp* __a = ALLOC(Exp); __a->kind = EXP_BINOP; __a->line = line; __a->u.binop.op = op; __a->u.binop.lh = lh; __a->u.binop.rh = rh; return __a; } Exp* exp_builtin_new(int line, Symbol* builtin) { Exp* __a = ALLOC(Exp); __a->kind = EXP_BUILTIN; __a->line = line; __a->u.builtin = builtin; return __a; } Exp* exp_app_new(int line, Symbol* f, Exp* arg) { Exp* __a = ALLOC(Exp); __a->kind = EXP_APP; __a->line = line; __a->u.app.f = f; __a->u.app.arg = arg; return __a; } VarDecl* vardecl_new(int line, Symbol* name) { VarDecl* __a = ALLOC(VarDecl); __a->line = line; __a->name = name; return __a; }