From: bdemsky Date: Sat, 17 Jun 2017 06:34:50 +0000 (-0700) Subject: Implement CPython strategy X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=5ee472f382b0d0dc077c316d116f2540540caea8;ds=sidebyside Implement CPython strategy --- diff --git a/src/AST/boolean.c b/src/AST/boolean.c index aaebba7..d452b1a 100644 --- a/src/AST/boolean.c +++ b/src/AST/boolean.c @@ -1,19 +1,19 @@ #include "boolean.h" Boolean* allocBoolean(VarType t) { - Boolean* tmp=(Boolean*) ourmalloc(sizeof (Boolean)); - tmp->btype=BOOLEANVAR; - tmp->var.vtype=t; - return tmp; + BooleanVar* tmp=(BooleanVar *) ourmalloc(sizeof (BooleanVar)); + tmp->base.btype=BOOLEANVAR; + tmp->vtype=t; + return & tmp->base; } Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t second) { - Boolean* tmp=(Boolean*) ourmalloc(sizeof (Boolean)); - tmp->btype=ORDERCONST; - tmp->order.order=order; - tmp->order.first=first; - tmp->order.second=second; - return tmp; + BooleanOrder* tmp=(BooleanOrder *) ourmalloc(sizeof (BooleanOrder)); + tmp->base.btype=ORDERCONST; + tmp->order=order; + tmp->first=first; + tmp->second=second; + return & tmp -> base; } void deleteBoolean(Boolean * this) { diff --git a/src/AST/boolean.h b/src/AST/boolean.h index 87d7a49..065ba4a 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -4,37 +4,41 @@ #include "mymemory.h" #include "ops.h" +/** + This is a little sketchy, but apparently legit. + https://www.python.org/dev/peps/pep-3123/ */ + +struct Boolean { + BooleanType btype; +}; + struct BooleanOrder { + Boolean base; Order* order; uint64_t first; uint64_t second; }; struct BooleanVar { + Boolean base; VarType vtype; }; struct BooleanLogic { + Boolean base; LogicOp op; Boolean * left; Boolean * right; }; struct BooleanComp { + Boolean base; CompOp op; Boolean * left; Boolean * right; }; -struct Boolean { - BooleanType btype; - union { - BooleanOrder order; - BooleanVar var; - BooleanLogic logic; - BooleanComp comp; - }; -}; + Boolean * allocBoolean(VarType t); Boolean * allocBooleanOrder(Order * order, uint64_t first, uint64_t second);