fez-lisp 1.5.159 → 1.5.161

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.5.159",
5
+ "version": "1.5.161",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -309,7 +309,22 @@ export const equalTypes = (a, b) => {
309
309
  if (!isSameType) return false
310
310
  return true
311
311
  }
312
-
312
+ const isRedifinedInLambda = (env, name, exp) => {
313
+ if (exp.slice(1, -1).some((x) => x[VALUE] === name)) return true
314
+ else if (
315
+ exp
316
+ .at(-1)
317
+ .some(
318
+ (x) =>
319
+ !isLeaf(x) &&
320
+ x[0][TYPE] === APPLY &&
321
+ x[0][VALUE] === KEYWORDS.DEFINE_VARIABLE &&
322
+ x[1][VALUE] === name
323
+ )
324
+ )
325
+ return true
326
+ else return false
327
+ }
313
328
  export const equalReturns = (a, b) =>
314
329
  isAnyReturn(a) || isAnyReturn(b) || a[RETURNS][0] === b[RETURNS][0]
315
330
  export const equalsTypeWithReturn = (a, b) =>
@@ -523,7 +538,6 @@ const ifExpression = ({ re, env, ref, prop, stack, exp, check }) => {
523
538
  const alt = isLeaf(re[1]) ? re[1] : re[1][0]
524
539
  const concequent = env[conc[VALUE]]
525
540
  const alternative = env[alt[VALUE]]
526
-
527
541
  // TODO make this more simple - it's so many different things just because types are functions or not
528
542
  // WHY not consiter making return types for everything
529
543
  if (concequent)
@@ -608,7 +622,11 @@ const resolveSetter = (first, rest, env, stack) => {
608
622
  : new Set([UNKNOWN])
609
623
  switch (right[TYPE]) {
610
624
  case ATOM:
611
- if (!currentSubType.has(UNKNOWN) && !currentSubType.has(NUMBER))
625
+ if (
626
+ !currentSubType.has(ANY) &&
627
+ !currentSubType.has(UNKNOWN) &&
628
+ !currentSubType.has(NUMBER)
629
+ )
612
630
  throw new TypeError(
613
631
  `Incorrect array type at (${
614
632
  first[VALUE]
@@ -1175,10 +1193,18 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1175
1193
  name,
1176
1194
  check
1177
1195
  })
1196
+ // TODO: remove this as maybe it is not needed
1178
1197
  check(rightHand, env, exp)
1179
1198
  })
1180
1199
  check(rightHand, env, exp)
1181
- } else check(rightHand, env, exp)
1200
+ }
1201
+
1202
+ check(rightHand, env, exp)
1203
+
1204
+ // if (isUnknownReturn(env[name][STATS]))
1205
+ // retry(env[name][STATS], exp, stack, () =>
1206
+ // check(rightHand, env, exp)
1207
+ // )
1182
1208
  } else {
1183
1209
  checkPredicateName(exp, rest)
1184
1210
  const isLeafNode = isLeaf(rightHand)
@@ -1225,19 +1251,24 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1225
1251
  : env[right[VALUE]][STATS][RETURNS][0]
1226
1252
  if (type !== UNKNOWN)
1227
1253
  setTypeToReturn(env[name][STATS], env[right[VALUE]][STATS])
1228
- const body = rightHand
1229
- const rem = hasBlock(body) ? body.at(-1) : body
1230
- const returns = isLeaf(rem) ? rem : rem[0]
1231
- resolveReturnType({
1232
- stack,
1233
- returns,
1234
- rem,
1235
- prop: TYPE_PROP,
1236
- exp,
1237
- env,
1238
- name,
1239
- check
1240
- })
1254
+ const resolve = () => {
1255
+ const body = rightHand
1256
+ const rem = hasBlock(body) ? body.at(-1) : body
1257
+ const returns = isLeaf(rem) ? rem : rem[0]
1258
+ resolveReturnType({
1259
+ stack,
1260
+ returns,
1261
+ rem,
1262
+ prop: TYPE_PROP,
1263
+ exp,
1264
+ env,
1265
+ name,
1266
+ check
1267
+ })
1268
+ }
1269
+ resolve()
1270
+ if (isUnknownType(env[name][STATS]))
1271
+ once(env[name][STATS], exp, stack, () => resolve())
1241
1272
  }
1242
1273
  check(rightHand, env, scope)
1243
1274
  }
@@ -1312,9 +1343,13 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1312
1343
  })
1313
1344
  break
1314
1345
  default:
1315
- if (copy[ret[VALUE]])
1316
- setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
1317
- else
1346
+ if (copy[ret[VALUE]]) {
1347
+ if (isUnknownReturn(copy[ret[VALUE]][STATS])) {
1348
+ once(ref[STATS], [returns, copy], stack, () => {
1349
+ setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
1350
+ })
1351
+ } else setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
1352
+ } else
1318
1353
  stagger(stack, 'append', [ret, copy], () => {
1319
1354
  if (copy[ret[VALUE]])
1320
1355
  setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
package/src/types.js CHANGED
@@ -76,7 +76,8 @@ export const toTypeCodes = (type) => {
76
76
  case 'Unknown':
77
77
  return [UNKNOWN]
78
78
  case 'Unknowns':
79
- return [COLLECTION]
79
+ case 'Collection':
80
+ return [COLLECTION, new Set([ANY])]
80
81
  case 'Numbers':
81
82
  return [COLLECTION, NUMBER_SUBTYPE()]
82
83
  case 'Booleans':
package/src/utils.js CHANGED
@@ -175,10 +175,13 @@ const isDefinition = (x) =>
175
175
  x[TYPE] === APPLY && x[VALUE] === KEYWORDS.DEFINE_VARIABLE
176
176
  // [[, [, libs]]] is because std is wrapped in (apply (lambda (do ...)))
177
177
  const toDeps = ([[, [, libs]]]) =>
178
- libs.reduce(
179
- (a, x, i) => a.set(x.at(1)[VALUE], { value: x, index: i }),
180
- new Map()
181
- )
178
+ // slice 1 so we get rid of do
179
+ libs
180
+ .slice(1)
181
+ .reduce(
182
+ (a, x, i) => a.set(x.at(1)[VALUE], { value: x, index: i }),
183
+ new Map()
184
+ )
182
185
  const deepShake = (tree, deps, visited = new Set(), ignored = new Set()) => {
183
186
  const type = tree[TYPE]
184
187
  const value = tree[VALUE]