1+ package hydra .basics
2+
3+ import hydra .core .*
4+
5+ import hydra .lib .lists
6+
7+ import hydra .lib .strings
8+
9+ def floatTypePrecision (v : FloatType ): Precision = v match
10+ case FloatType .bigfloat() => Precision .arbitrary()
11+ case FloatType .float32() => Precision .bits(32 )
12+ case FloatType .float64() => Precision .bits(64 )
13+
14+ val floatTypes = Seq (FloatType .bigfloat(), FloatType .float32(), FloatType .float64())
15+
16+ def floatValueType (v : FloatValue ): FloatType = v match
17+ case FloatValue .bigfloat(y) => FloatType .bigfloat()
18+ case FloatValue .float32(y) => FloatType .float32()
19+ case FloatValue .float64(y) => FloatType .float64()
20+
21+ def functionVariant [a](v : hydra.core.Function [a]): FunctionVariant = v match
22+ case hydra.core.Function .cases(y) => FunctionVariant .cases()
23+ case hydra.core.Function .compareTo(y) => FunctionVariant .compareTo()
24+ case hydra.core.Function .data() => FunctionVariant .data()
25+ case hydra.core.Function .lambda(y) => FunctionVariant .lambda()
26+ case hydra.core.Function .optionalCases(y) => FunctionVariant .optionalCases()
27+ case hydra.core.Function .primitive(y) => FunctionVariant .primitive()
28+ case hydra.core.Function .projection(y) => FunctionVariant .projection()
29+
30+ val functionVariants = Seq (FunctionVariant .cases(), FunctionVariant .compareTo(), FunctionVariant .data(), FunctionVariant .lambda(), FunctionVariant .optionalCases(), FunctionVariant .primitive(), FunctionVariant .projection())
31+
32+ def integerTypeIsSigned (v : IntegerType ): Boolean = v match
33+ case IntegerType .bigint() => true
34+ case IntegerType .int8() => true
35+ case IntegerType .int16() => true
36+ case IntegerType .int32() => true
37+ case IntegerType .int64() => true
38+ case IntegerType .uint8() => false
39+ case IntegerType .uint16() => false
40+ case IntegerType .uint32() => false
41+ case IntegerType .uint64() => false
42+
43+ def integerTypePrecision (v : IntegerType ): Precision = v match
44+ case IntegerType .bigint() => Precision .arbitrary()
45+ case IntegerType .int8() => Precision .bits(8 )
46+ case IntegerType .int16() => Precision .bits(16 )
47+ case IntegerType .int32() => Precision .bits(32 )
48+ case IntegerType .int64() => Precision .bits(64 )
49+ case IntegerType .uint8() => Precision .bits(8 )
50+ case IntegerType .uint16() => Precision .bits(16 )
51+ case IntegerType .uint32() => Precision .bits(32 )
52+ case IntegerType .uint64() => Precision .bits(64 )
53+
54+ val integerTypes = Seq (IntegerType .bigint(), IntegerType .int8(), IntegerType .int16(), IntegerType .int32(), IntegerType .int64(), IntegerType .uint8(), IntegerType .uint16(), IntegerType .uint32(), IntegerType .uint64())
55+
56+ def integerValueType (v : IntegerValue ): IntegerType = v match
57+ case IntegerValue .bigint(y) => IntegerType .bigint()
58+ case IntegerValue .int8(y) => IntegerType .int8()
59+ case IntegerValue .int16(y) => IntegerType .int16()
60+ case IntegerValue .int32(y) => IntegerType .int32()
61+ case IntegerValue .int64(y) => IntegerType .int64()
62+ case IntegerValue .uint8(y) => IntegerType .uint8()
63+ case IntegerValue .uint16(y) => IntegerType .uint16()
64+ case IntegerValue .uint32(y) => IntegerType .uint32()
65+ case IntegerValue .uint64(y) => IntegerType .uint64()
66+
67+ def literalType (v : Literal ): LiteralType = v match
68+ case Literal .binary(y) => LiteralType .binary()
69+ case Literal .boolean(y) => LiteralType .boolean()
70+ case Literal .float(y) => LiteralType .float(floatValueType(y))
71+ case Literal .integer(y) => LiteralType .integer(integerValueType(y))
72+ case Literal .string(y) => LiteralType .string()
73+
74+ def literalTypeVariant (v : LiteralType ): LiteralVariant = v match
75+ case LiteralType .binary() => LiteralVariant .binary()
76+ case LiteralType .boolean() => LiteralVariant .boolean()
77+ case LiteralType .float(y) => LiteralVariant .float()
78+ case LiteralType .integer(y) => LiteralVariant .integer()
79+ case LiteralType .string() => LiteralVariant .string()
80+
81+ def literalVariant (x : Literal ): LiteralVariant = literalTypeVariant(literalType(x))
82+
83+ val literalVariants = Seq (LiteralVariant .binary(), LiteralVariant .boolean(), LiteralVariant .float(), LiteralVariant .integer(), LiteralVariant .string())
84+
85+ def qname (ns : String ): (String => Name ) = (name : String ) => strings.cat(Seq (ns, " ." , name))
86+
87+ def termVariant [a](term : Term [a]): TermVariant = term.data match
88+ case Expression .application(y) => TermVariant .application()
89+ case Expression .element(y) => TermVariant .element()
90+ case Expression .function(y) => TermVariant .function()
91+ case Expression .list(y) => TermVariant .list()
92+ case Expression .literal(y) => TermVariant .literal()
93+ case Expression .map(y) => TermVariant .map()
94+ case Expression .nominal(y) => TermVariant .nominal()
95+ case Expression .optional(y) => TermVariant .optional()
96+ case Expression .record(y) => TermVariant .record()
97+ case Expression .set(y) => TermVariant .set()
98+ case Expression .typeAbstraction(y) => TermVariant .typeAbstraction()
99+ case Expression .typeApplication(y) => TermVariant .typeApplication()
100+ case Expression .union(y) => TermVariant .union()
101+ case Expression .variable(y) => TermVariant .variable()
102+
103+ val termVariants = Seq (TermVariant .application(), TermVariant .literal(), TermVariant .element(), TermVariant .function(), TermVariant .list(), TermVariant .map(), TermVariant .nominal(), TermVariant .optional(), TermVariant .record(), TermVariant .set(), TermVariant .union(), TermVariant .variable())
104+
105+ def testLists [a](els : Seq [Seq [a]]): Int = lists.length(lists.concat(els))
106+
107+ def typeVariant (v : Type ): TypeVariant = v match
108+ case Type .element(y) => TypeVariant .element()
109+ case Type .function(y) => TypeVariant .function()
110+ case Type .list(y) => TypeVariant .list()
111+ case Type .literal(y) => TypeVariant .literal()
112+ case Type .map(y) => TypeVariant .map()
113+ case Type .nominal(y) => TypeVariant .nominal()
114+ case Type .optional(y) => TypeVariant .optional()
115+ case Type .record(y) => TypeVariant .record()
116+ case Type .set(y) => TypeVariant .set()
117+ case Type .union(y) => TypeVariant .union()
118+ case Type .universal(y) => TypeVariant .universal()
119+ case Type .variable(y) => TypeVariant .variable()
120+
121+ val typeVariants = Seq (TypeVariant .literal(), TypeVariant .element(), TypeVariant .function(), TypeVariant .list(), TypeVariant .map(), TypeVariant .nominal(), TypeVariant .optional(), TypeVariant .record(), TypeVariant .set(), TypeVariant .union(), TypeVariant .universal(), TypeVariant .variable())
0 commit comments