From 1407a1ec99163bf3323fbd223396a124336a861a Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Thu, 5 Feb 2009 19:35:40 +0000 Subject: added primop functions __isBool, __isString, __isInt --- src/libexpr/primops.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/libexpr') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 1413615e3bcc..717f649c4e04 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -125,6 +125,27 @@ static Expr prim_isFunction(EvalState & state, const ATermVector & args) return makeBool(matchFunction(e, pat, body, pos)); } +/* Determine whether the argument is an Int. */ +static Expr prim_isInt(EvalState & state, const ATermVector & args) +{ + int i; + return makeBool(matchInt(evalExpr(state, args[0]), i)); +} + +/* Determine whether the argument is an String. */ +static Expr prim_isString(EvalState & state, const ATermVector & args) +{ + string s; + PathSet l; + return makeBool(matchStr(evalExpr(state, args[0]), s, l)); +} + +/* Determine whether the argument is an Bool. */ +static Expr prim_isBool(EvalState & state, const ATermVector & args) +{ + ATermBool b; + return makeBool(matchBool(evalExpr(state, args[0]), b)); +} static Expr prim_genericClosure(EvalState & state, const ATermVector & args) { @@ -986,12 +1007,16 @@ void EvalState::addPrimOps() addPrimOp("import", 1, prim_import); addPrimOp("isNull", 1, prim_isNull); addPrimOp("__isFunction", 1, prim_isFunction); + addPrimOp("__isString", 1, prim_isString); + addPrimOp("__isInt", 1, prim_isInt); + addPrimOp("__isBool", 1, prim_isBool); addPrimOp("__genericClosure", 1, prim_genericClosure); addPrimOp("abort", 1, prim_abort); addPrimOp("throw", 1, prim_throw); addPrimOp("__addErrorContext", 2, prim_addErrorContext); addPrimOp("__getEnv", 1, prim_getEnv); addPrimOp("__trace", 2, prim_trace); + // Expr <-> String addPrimOp("__exprToString", 1, prim_exprToString); -- cgit 1.4.1