Advertisement
VictorCacciari

ASTCG_test_result

Feb 16th, 2012
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. /*
  2. victor@skynet:~/Desktop$ ghci
  3. GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
  4. Loading package ghc-prim ... linking ... done.
  5. Loading package integer-gmp ... linking ... done.
  6. Loading package base ... linking ... done.
  7. Prelude> :a AST_C_Target.hs
  8. [1 of 2] Compiling AST              ( AST.hs, interpreted )
  9. [2 of 2] Compiling AST_C_Target     ( AST_C_Target.hs, interpreted )
  10. Ok, modules loaded: AST_C_Target, AST.
  11. *AST_C_Target> translateProgram myProg
  12. */
  13. #ifndef EXP_TEST_H
  14. #define EXP_TEST_H
  15.  
  16. #include "test.h"
  17.  
  18. typedef struct Exp_st Exp;
  19. typedef struct VarDecl_st VarDecl;
  20.  
  21.  
  22. /* E N U M S */
  23. enum ExpKind_t {
  24.     EXP_BUILTIN,
  25.     EXP_APP,
  26.     EXP_BINOP};
  27.  
  28.  
  29. /* D E C L A R A T I O N S */
  30.  
  31. struct Exp_st {
  32.     enum ExpKind_t kind;
  33.     int line;
  34.     union {
  35.         struct {
  36.             int op;
  37.             Exp* lh;
  38.             Exp* rh;
  39.         } binop;
  40.         Symbol* builtin;
  41.         struct {
  42.             Symbol* f;
  43.             Exp* arg;
  44.         } app;
  45.     } u;
  46. };
  47.  
  48.  
  49. Exp*    exp_binop_new(int line, int op, Exp* lh, Exp* rh);
  50. Exp*    exp_builtin_new(int line, Symbol* builtin);
  51. Exp*    exp_app_new(int line, Symbol* f, Exp* arg);
  52.  
  53.  
  54. struct VarDecl_st {
  55.     int line;
  56.     Symbol* name;
  57. };
  58.  
  59.  
  60. VarDecl*    vardecl_new(int line, Symbol* name);
  61.  
  62.  
  63. #endif
  64.  
  65.  
  66. /* I M P L E M E N T A T I O N */
  67. #include "exp_test.h"
  68. #define ALLOC(type) (type*)my_allocator(sizeof(type))
  69.  
  70. Exp*    exp_binop_new(int line, int op, Exp* lh, Exp* rh)
  71. {
  72. Exp* __a = ALLOC(Exp);
  73.  
  74.     __a->kind = EXP_BINOP;
  75.     __a->line = line;
  76.     __a->u.binop.op = op;
  77.     __a->u.binop.lh = lh;
  78.     __a->u.binop.rh = rh;
  79.  
  80.     return __a;
  81. }
  82.  
  83. Exp*    exp_builtin_new(int line, Symbol* builtin)
  84. {
  85. Exp* __a = ALLOC(Exp);
  86.  
  87.     __a->kind = EXP_BUILTIN;
  88.     __a->line = line;
  89.     __a->u.builtin = builtin;
  90.  
  91.     return __a;
  92. }
  93.  
  94. Exp*    exp_app_new(int line, Symbol* f, Exp* arg)
  95. {
  96. Exp* __a = ALLOC(Exp);
  97.  
  98.     __a->kind = EXP_APP;
  99.     __a->line = line;
  100.     __a->u.app.f = f;
  101.     __a->u.app.arg = arg;
  102.  
  103.     return __a;
  104. }
  105.  
  106. VarDecl*    vardecl_new(int line, Symbol* name)
  107. {
  108. VarDecl* __a = ALLOC(VarDecl);
  109.  
  110.     __a->line = line;
  111.     __a->name = name;
  112.  
  113.     return __a;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement