gofront 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -19
- package/package.json +7 -4
- package/src/codegen/expressions.js +252 -3
- package/src/codegen/statements.js +30 -26
- package/src/codegen.js +68 -5
- package/src/parser.js +0 -10
- package/src/typechecker/expressions.js +38 -9
- package/src/typechecker/stdlib.js +764 -0
- package/src/typechecker/types.js +15 -20
- package/src/typechecker.js +25 -601
package/src/typechecker/types.js
CHANGED
|
@@ -101,13 +101,22 @@ export function isGeneric(t) {
|
|
|
101
101
|
return t?.kind === "generic";
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
function makeBasicPredicate(...names) {
|
|
105
|
+
const set = new Set(names);
|
|
106
|
+
const pred = (t) => {
|
|
107
|
+
if (!t) return false;
|
|
108
|
+
if (t.kind === "untyped") return set.has(t.base);
|
|
109
|
+
if (t.kind === "basic") return set.has(t.name);
|
|
110
|
+
if (t.kind === "named") return pred(t.underlying);
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
113
|
+
return pred;
|
|
110
114
|
}
|
|
115
|
+
|
|
116
|
+
export const isNumeric = makeBasicPredicate("int", "float64");
|
|
117
|
+
export const isString = makeBasicPredicate("string");
|
|
118
|
+
export const isBool = makeBasicPredicate("bool");
|
|
119
|
+
|
|
111
120
|
export function isComplex(t) {
|
|
112
121
|
if (!t) return false;
|
|
113
122
|
if (t.kind === "basic" && (t.name === "complex128" || t.name === "complex64"))
|
|
@@ -119,20 +128,6 @@ export function isComplex(t) {
|
|
|
119
128
|
export function isComplexOrNumeric(t) {
|
|
120
129
|
return isNumeric(t) || isComplex(t);
|
|
121
130
|
}
|
|
122
|
-
export function isString(t) {
|
|
123
|
-
if (!t) return false;
|
|
124
|
-
if (t.kind === "untyped") return t.base === "string";
|
|
125
|
-
if (t.kind === "basic") return t.name === "string";
|
|
126
|
-
if (t.kind === "named") return isString(t.underlying);
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
export function isBool(t) {
|
|
130
|
-
if (!t) return false;
|
|
131
|
-
if (t.kind === "untyped") return t.base === "bool";
|
|
132
|
-
if (t.kind === "basic") return t.name === "bool";
|
|
133
|
-
if (t.kind === "named") return isBool(t.underlying);
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
131
|
export function isAny(t) {
|
|
137
132
|
return t?.kind === "basic" && t.name === "any";
|
|
138
133
|
}
|