fez-lisp 1.5.160 → 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.160",
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]
@@ -1132,7 +1150,6 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1132
1150
  exp
1133
1151
  )})`
1134
1152
  )
1135
-
1136
1153
  if (name in env) {
1137
1154
  Types.set(withScope(name, env), () => formatType(name, env))
1138
1155
  break
@@ -1180,7 +1197,14 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1180
1197
  check(rightHand, env, exp)
1181
1198
  })
1182
1199
  check(rightHand, env, exp)
1183
- } 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
+ // )
1184
1208
  } else {
1185
1209
  checkPredicateName(exp, rest)
1186
1210
  const isLeafNode = isLeaf(rightHand)
@@ -1227,19 +1251,24 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1227
1251
  : env[right[VALUE]][STATS][RETURNS][0]
1228
1252
  if (type !== UNKNOWN)
1229
1253
  setTypeToReturn(env[name][STATS], env[right[VALUE]][STATS])
1230
- const body = rightHand
1231
- const rem = hasBlock(body) ? body.at(-1) : body
1232
- const returns = isLeaf(rem) ? rem : rem[0]
1233
- resolveReturnType({
1234
- stack,
1235
- returns,
1236
- rem,
1237
- prop: TYPE_PROP,
1238
- exp,
1239
- env,
1240
- name,
1241
- check
1242
- })
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())
1243
1272
  }
1244
1273
  check(rightHand, env, scope)
1245
1274
  }
@@ -1315,7 +1344,11 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1315
1344
  break
1316
1345
  default:
1317
1346
  if (copy[ret[VALUE]]) {
1318
- setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
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])
1319
1352
  } else
1320
1353
  stagger(stack, 'append', [ret, copy], () => {
1321
1354
  if (copy[ret[VALUE]])
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':