Skip to content

Commit

Permalink
add reusable boolean constants
Browse files Browse the repository at this point in the history
This will save us having to reconstruct these repeatedly when we just want to
ask the question "is the expression I have the literal true or false?"

Github: related to #130 "interact with SMT solver"
Github: related to #139 "avoid calling SMT solver for "true" and "false""
  • Loading branch information
Smattr committed Jun 26, 2019
1 parent 4145340 commit 4138714
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions librumur/include/rumur/Boolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include <cstddef>
#include <memory>
#include <rumur/Expr.h>
#include <rumur/Ptr.h>
#include <rumur/TypeExpr.h>

namespace rumur {

extern const Ptr<Enum> Boolean;

extern const Ptr<Expr> False;
extern const Ptr<Expr> True;

}
14 changes: 14 additions & 0 deletions librumur/src/Boolean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "location.hh"
#include <memory>
#include <rumur/Boolean.h>
#include <rumur/Decl.h>
#include <rumur/Expr.h>
#include <rumur/Number.h>
#include <rumur/Ptr.h>
#include <rumur/TypeExpr.h>
#include <string>
Expand All @@ -15,4 +17,16 @@ const Ptr<Enum> Boolean = Ptr<Enum>::make(
std::vector<std::pair<std::string, location>>(
{ {"false", location()}, {"true", location()} }), location());

const Ptr<Expr> False = Ptr<ExprID>::make("false",
Ptr<ConstDecl>::make("boolean",
Ptr<Number>::make(0, location()),
Boolean, location()),
location());

const Ptr<Expr> True = Ptr<ExprID>::make("true",
Ptr<ConstDecl>::make("boolean",
Ptr<Number>::make(1, location()),
Boolean, location()),
location());

}

0 comments on commit 4138714

Please sign in to comment.