forked from lix-project/lix
Store Nix integers as longs
So on 64-bit systems, integers are now 64-bit. Fixes #158.
This commit is contained in:
parent
297b762513
commit
d308aeaf53
|
@ -968,7 +968,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
int n = 0;
|
NixInt n = 0;
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
ValueType firstType;
|
ValueType firstType;
|
||||||
|
@ -1021,7 +1021,7 @@ void EvalState::strictForceValue(Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int EvalState::forceInt(Value & v)
|
NixInt EvalState::forceInt(Value & v)
|
||||||
{
|
{
|
||||||
forceValue(v);
|
forceValue(v);
|
||||||
if (v.type != tInt)
|
if (v.type != tInt)
|
||||||
|
|
|
@ -159,7 +159,7 @@ public:
|
||||||
void strictForceValue(Value & v);
|
void strictForceValue(Value & v);
|
||||||
|
|
||||||
/* Force `v', and then verify that it has the expected type. */
|
/* Force `v', and then verify that it has the expected type. */
|
||||||
int forceInt(Value & v);
|
NixInt forceInt(Value & v);
|
||||||
bool forceBool(Value & v);
|
bool forceBool(Value & v);
|
||||||
inline void forceAttrs(Value & v);
|
inline void forceAttrs(Value & v);
|
||||||
inline void forceList(Value & v);
|
inline void forceList(Value & v);
|
||||||
|
|
|
@ -110,8 +110,10 @@ or { return OR_KW; }
|
||||||
\+\+ { return CONCAT; }
|
\+\+ { return CONCAT; }
|
||||||
|
|
||||||
{ID} { yylval->id = strdup(yytext); return ID; }
|
{ID} { yylval->id = strdup(yytext); return ID; }
|
||||||
{INT} { int n = atoi(yytext); /* !!! overflow */
|
{INT} { errno = 0;
|
||||||
yylval->n = n;
|
yylval->n = strtol(yytext, 0, 10);
|
||||||
|
if (errno != 0)
|
||||||
|
throw ParseError(format("invalid integer `%1%'") % yytext);
|
||||||
return INT;
|
return INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ std::ostream & operator << (std::ostream & str, Expr & e);
|
||||||
|
|
||||||
struct ExprInt : Expr
|
struct ExprInt : Expr
|
||||||
{
|
{
|
||||||
int n;
|
NixInt n;
|
||||||
Value v;
|
Value v;
|
||||||
ExprInt(int n) : n(n) { mkInt(v, n); };
|
ExprInt(NixInt n) : n(n) { mkInt(v, n); };
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
Value * maybeThunk(EvalState & state, Env & env);
|
||||||
};
|
};
|
||||||
|
|
|
@ -238,7 +238,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
|
||||||
nix::ExprAttrs * attrs;
|
nix::ExprAttrs * attrs;
|
||||||
nix::Formals * formals;
|
nix::Formals * formals;
|
||||||
nix::Formal * formal;
|
nix::Formal * formal;
|
||||||
int n;
|
nix::NixInt n;
|
||||||
char * id; // !!! -> Symbol
|
char * id; // !!! -> Symbol
|
||||||
char * path;
|
char * path;
|
||||||
char * uri;
|
char * uri;
|
||||||
|
|
|
@ -1024,7 +1024,7 @@ static void prim_mul(EvalState & state, Value * * args, Value & v)
|
||||||
|
|
||||||
static void prim_div(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");
|
if (i2 == 0) throw EvalError("division by zero");
|
||||||
mkInt(v, state.forceInt(*args[0]) / i2);
|
mkInt(v, state.forceInt(*args[0]) / i2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,14 +31,17 @@ struct PrimOp;
|
||||||
struct Symbol;
|
struct Symbol;
|
||||||
|
|
||||||
|
|
||||||
|
typedef long NixInt;
|
||||||
|
|
||||||
|
|
||||||
struct Value
|
struct Value
|
||||||
{
|
{
|
||||||
ValueType type;
|
ValueType type;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int integer;
|
NixInt integer;
|
||||||
bool boolean;
|
bool boolean;
|
||||||
|
|
||||||
/* Strings in the evaluator carry a so-called `context' which
|
/* Strings in the evaluator carry a so-called `context' which
|
||||||
is a list of strings representing store paths. This is to
|
is a list of strings representing store paths. This is to
|
||||||
allow users to write things like
|
allow users to write things like
|
||||||
|
@ -63,7 +66,7 @@ struct Value
|
||||||
const char * s;
|
const char * s;
|
||||||
const char * * context; // must be in sorted order
|
const char * * context; // must be in sorted order
|
||||||
} string;
|
} string;
|
||||||
|
|
||||||
const char * path;
|
const char * path;
|
||||||
Bindings * attrs;
|
Bindings * attrs;
|
||||||
struct {
|
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);
|
clearValue(v);
|
||||||
v.type = tInt;
|
v.type = tInt;
|
||||||
|
|
|
@ -1083,14 +1083,6 @@ bool statusOk(int status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string int2String(int n)
|
|
||||||
{
|
|
||||||
std::ostringstream str;
|
|
||||||
str << n;
|
|
||||||
return str.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool hasSuffix(const string & s, const string & suffix)
|
bool hasSuffix(const string & s, const string & suffix)
|
||||||
{
|
{
|
||||||
return s.size() >= suffix.size() && string(s, s.size() - suffix.size()) == suffix;
|
return s.size() >= suffix.size() && string(s, s.size() - suffix.size()) == suffix;
|
||||||
|
|
|
@ -319,7 +319,12 @@ template<class N> bool string2Int(const string & s, N & n)
|
||||||
return str && str.get() == EOF;
|
return str && str.get() == EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
string int2String(int n);
|
template<class N> string int2String(N n)
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << n;
|
||||||
|
return str.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return true iff `s' ends in `suffix'. */
|
/* Return true iff `s' ends in `suffix'. */
|
||||||
|
|
Loading…
Reference in a new issue