Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
ajreynol committed Oct 30, 2024
1 parent 75e4c3f commit 620b150
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmd_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ bool CmdParser::parseNextCommand()
for (std::pair<const ExprValue* const, std::vector<Expr>>& d : dts)
{
Expr dt = Expr(d.first);
Expr ctuple = d_state.mkExpr(Kind::TUPLE, d.second);
Expr ctuple = d_state.mkList(d.second);
d_state.markConstructorKind(dt, attr, ctuple);
}
for (std::pair<const ExprValue* const, std::vector<Expr>>& c : dtcons)
{
Expr cons = Expr(c.first);
Expr stuple = d_state.mkExpr(Kind::TUPLE, c.second);
Expr stuple = d_state.mkList(c.second);
d_state.markConstructorKind(cons, Attr::DATATYPE_CONSTRUCTOR, stuple);
}
d_lex.eatToken(Token::RPAREN);
Expand Down
8 changes: 7 additions & 1 deletion src/kind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ std::ostream& operator<<(std::ostream& o, Kind k)
case Kind::EVAL_TO_RAT: o << "EVAL_TO_RAT"; break;
case Kind::EVAL_TO_BIN: o << "EVAL_TO_BIN"; break;
case Kind::EVAL_TO_STRING: o << "EVAL_TO_STRING"; break;
// datatypes
case Kind::EVAL_DEF_OF: o << "EVAL_DEF_OF"; break;
default: o << "UnknownKind(" << unsigned(k) << ")"; break;
}
return o;
Expand Down Expand Up @@ -167,6 +169,8 @@ std::string kindToTerm(Kind k)
case Kind::EVAL_TO_RAT: ss << "to_q";break;
case Kind::EVAL_TO_BIN: ss << "to_bin";break;
case Kind::EVAL_TO_STRING: ss << "to_str";break;
// datatypes
case Kind::EVAL_DEF_OF: ss << "def_of"; break;
default:ss << "[" << k << "]";break;
}
}
Expand Down Expand Up @@ -256,7 +260,9 @@ bool isLiteralOp(Kind k)
case Kind::EVAL_TO_INT:
case Kind::EVAL_TO_RAT:
case Kind::EVAL_TO_BIN:
case Kind::EVAL_TO_STRING:return true; break;
case Kind::EVAL_TO_STRING:
// datatypes
case Kind::EVAL_DEF_OF: return true; break;
default: break;
}
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ enum class Kind
EVAL_TO_INT,
EVAL_TO_RAT,
EVAL_TO_BIN,
EVAL_TO_STRING
EVAL_TO_STRING,
// datatypes
EVAL_DEF_OF
};

/** Print a kind to the stream, for debugging */
Expand Down
14 changes: 14 additions & 0 deletions src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ State::State(Options& opts, Stats& stats)
bindBuiltinEval("concat", Kind::EVAL_CONCAT);
bindBuiltinEval("extract", Kind::EVAL_EXTRACT);
bindBuiltinEval("find", Kind::EVAL_FIND);
// datatypes
bindBuiltinEval("def_of", Kind::EVAL_DEF_OF);

// as
bindBuiltinEval("as", Kind::AS);
Expand Down Expand Up @@ -972,6 +974,18 @@ Expr State::mkParameterized(const ExprValue* hd, const std::vector<Expr>& params
return mkExpr(Kind::PARAMETERIZED, {mkExpr(Kind::TUPLE, params), Expr(hd)});
}

Expr State::mkList(const std::vector<Expr>& args)
{
if (args.empty())
{
return d_listNil;
}
std::vector<Expr> largs;
largs.push_back(d_listCons);
largs.insert(largs.end(), args.begin(), args.end());
return mkExpr(Kind::APPLY, largs);
}

ExprValue* State::mkLiteralInternal(Literal& l)
{
d_stats.d_mkExprCount++;
Expand Down
3 changes: 3 additions & 0 deletions src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class State
* Make parameterized with given parameters
*/
Expr mkParameterized(const ExprValue* hd, const std::vector<Expr>& params);
/**
*/
Expr mkList(const std::vector<Expr>& args);
//--------------------------------------
/** Get the constructor kind for symbol v */
Attr getConstructorKind(const ExprValue* v) const;
Expand Down
15 changes: 15 additions & 0 deletions src/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ bool TypeChecker::checkArity(Kind k, size_t nargs, std::ostream* out)
case Kind::EVAL_IS_STR:
case Kind::EVAL_IS_BOOL:
case Kind::EVAL_IS_VAR:
case Kind::EVAL_DEF_OF:
ret = (nargs==1);
break;
case Kind::EVAL_NIL:
Expand Down Expand Up @@ -1173,6 +1174,20 @@ Expr TypeChecker::evaluateLiteralOpInternal(
}
}
break;
case Kind::EVAL_DEF_OF:
{
AppInfo* ac = d_state.getAppInfo(args[0]);
if (ac!=nullptr)
{
Assert (args[0]->isGround());
Attr a = ac->d_attrCons;
if (a==Attr::DATATYPE || a==Attr::DATATYPE_CONSTRUCTOR)
{
return ac->d_attrConsTerm;
}
}
}
break;
default:
break;
}
Expand Down

0 comments on commit 620b150

Please sign in to comment.