1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 01:11:15 +02:00

Introduce NormalType for the normal type of a Value

This will be useful to abstract over the ValueType implementation
details

Make use of it already to replace the showType(ValueType) function
This commit is contained in:
Silvan Mosberger 2020-12-11 23:32:45 +01:00
parent 9c143c411b
commit fa307875e9
No known key found for this signature in database
GPG key ID: E8F1E9EAD284E17D
5 changed files with 68 additions and 34 deletions

View file

@ -29,6 +29,22 @@ typedef enum {
tFloat
} ValueType;
// This type abstracts over all actual value types in the language,
// grouping together implementation details like tList*, different function
// types, and types in non-normal form (so thunks and co.)
typedef enum {
nThunk,
nInt,
nFloat,
nBool,
nString,
nPath,
nNull,
nAttrs,
nList,
nFunction,
nExternal
} NormalType;
class Bindings;
struct Env;
@ -147,6 +163,26 @@ struct Value
NixFloat fpoint;
};
// Returns the normal type of a Value. This only returns nThunk if the
// Value hasn't been forceValue'd
inline NormalType normalType() const
{
switch (type) {
case tInt: return nInt;
case tBool: return nBool;
case tString: return nString;
case tPath: return nPath;
case tNull: return nNull;
case tAttrs: return nAttrs;
case tList1: case tList2: case tListN: return nList;
case tLambda: case tPrimOp: case tPrimOpApp: return nFunction;
case tExternal: return nExternal;
case tFloat: return nFloat;
case tThunk: case tApp: case tBlackhole: return nThunk;
}
abort();
}
bool isList() const
{
return type == tList1 || type == tList2 || type == tListN;