aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-08-19 12:35:03 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-08-19 12:35:03 +0200
commitd308aeaf53b7324af98dfa949a747526c241ef30 (patch)
treeacae7f07b45d26007e8a6bbc3d6c8bfa1bf5e34c /src/libexpr
parent297b762513ad416582c0850095506f802ff5b1bb (diff)
Store Nix integers as longs
So on 64-bit systems, integers are now 64-bit. Fixes #158.
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc4
-rw-r--r--src/libexpr/eval.hh2
-rw-r--r--src/libexpr/lexer.l6
-rw-r--r--src/libexpr/nixexpr.hh4
-rw-r--r--src/libexpr/parser.y2
-rw-r--r--src/libexpr/primops.cc2
-rw-r--r--src/libexpr/value.hh13
7 files changed, 19 insertions, 14 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index b1100a662..efcb43876 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -968,7 +968,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
{
PathSet context;
std::ostringstream s;
- int n = 0;
+ NixInt n = 0;
bool first = true;
ValueType firstType;
@@ -1021,7 +1021,7 @@ void EvalState::strictForceValue(Value & v)
}
-int EvalState::forceInt(Value & v)
+NixInt EvalState::forceInt(Value & v)
{
forceValue(v);
if (v.type != tInt)
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 5e98f5404..9717fb66d 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -159,7 +159,7 @@ public:
void strictForceValue(Value & v);
/* Force `v', and then verify that it has the expected type. */
- int forceInt(Value & v);
+ NixInt forceInt(Value & v);
bool forceBool(Value & v);
inline void forceAttrs(Value & v);
inline void forceList(Value & v);
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l
index 3b7c6bb57..76cd37201 100644
--- a/src/libexpr/lexer.l
+++ b/src/libexpr/lexer.l
@@ -110,8 +110,10 @@ or { return OR_KW; }
\+\+ { return CONCAT; }
{ID} { yylval->id = strdup(yytext); return ID; }
-{INT} { int n = atoi(yytext); /* !!! overflow */
- yylval->n = n;
+{INT} { errno = 0;
+ yylval->n = strtol(yytext, 0, 10);
+ if (errno != 0)
+ throw ParseError(format("invalid integer `%1%'") % yytext);
return INT;
}
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 8256605b5..f6dcb3935 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -75,9 +75,9 @@ std::ostream & operator << (std::ostream & str, Expr & e);
struct ExprInt : Expr
{
- int n;
+ NixInt n;
Value v;
- ExprInt(int n) : n(n) { mkInt(v, n); };
+ ExprInt(NixInt n) : n(n) { mkInt(v, n); };
COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env);
};
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index cd1b0e21f..7690271a8 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -238,7 +238,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
nix::ExprAttrs * attrs;
nix::Formals * formals;
nix::Formal * formal;
- int n;
+ nix::NixInt n;
char * id; // !!! -> Symbol
char * path;
char * uri;
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 149c7ca39..deb66fd69 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1024,7 +1024,7 @@ static void prim_mul(EvalState & state, Value * * args, Value & v)
static void prim_div(EvalState & state, Value * * args, Value & v)
{
- int i2 = state.forceInt(*args[1]);
+ NixInt i2 = state.forceInt(*args[1]);
if (i2 == 0) throw EvalError("division by zero");
mkInt(v, state.forceInt(*args[0]) / i2);
}
diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh
index d49381a59..ee5c7397b 100644
--- a/src/libexpr/value.hh
+++ b/src/libexpr/value.hh
@@ -31,14 +31,17 @@ struct PrimOp;
struct Symbol;
+typedef long NixInt;
+
+
struct Value
{
ValueType type;
- union
+ union
{
- int integer;
+ NixInt integer;
bool boolean;
-
+
/* Strings in the evaluator carry a so-called `context' which
is a list of strings representing store paths. This is to
allow users to write things like
@@ -63,7 +66,7 @@ struct Value
const char * s;
const char * * context; // must be in sorted order
} string;
-
+
const char * path;
Bindings * attrs;
struct {
@@ -97,7 +100,7 @@ static inline void clearValue(Value & v)
}
-static inline void mkInt(Value & v, int n)
+static inline void mkInt(Value & v, NixInt n)
{
clearValue(v);
v.type = tInt;