fez-lisp 1.6.60 → 1.6.62

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.6.60",
5
+ "version": "1.6.62",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  NUMBER_SUBTYPE,
48
48
  UNKNOWN_SUBTYPE,
49
49
  SubType,
50
- GET_ARRAY_INFERENCE
50
+ GET_ARRAY_INFERENCE_SET
51
51
  } from './types.js'
52
52
  import {
53
53
  Brr,
@@ -56,7 +56,9 @@ import {
56
56
  hasBlock,
57
57
  log,
58
58
  logExp,
59
- stringifyArgs
59
+ stringifyArgs,
60
+ wrapInApplyLambda,
61
+ wrapInBlock
60
62
  } from './utils.js'
61
63
 
62
64
  export const identity = (name) => [
@@ -603,7 +605,6 @@ const resolveCondition = ({ rem, name, env, exp, prop, stack, check }) => {
603
605
  const resolveGetter = ({ rem, prop, name, env }) => {
604
606
  const array = isLeaf(rem[1]) ? rem[1] : rem[1][0]
605
607
  if (!env[array[VALUE]] || !env[name]) return true
606
-
607
608
  switch (array[TYPE]) {
608
609
  case APPLY:
609
610
  if (hasSubReturn(env[array[VALUE]][STATS])) {
@@ -851,7 +852,7 @@ const resolveReturnType = ({
851
852
  break
852
853
  default:
853
854
  {
854
- if (returns[VALUE] === GET_ARRAY_INFERENCE)
855
+ if (GET_ARRAY_INFERENCE_SET.has(returns[VALUE]))
855
856
  resolveGetter({ rem, prop, name, env })
856
857
  checkPredicateNameDeep(name, exp, exp.slice(1), returns)
857
858
  // TODO: DRY
@@ -1206,7 +1207,7 @@ export const typeCheck = (
1206
1207
  if (name in env) {
1207
1208
  // Types.set(withScope(name, env), () => formatType(name, env))
1208
1209
  // If current scope is root then these are user defined types
1209
- if (isLambda && !isUnknownReturn(env[name][STATS])) {
1210
+ if (isLambda) {
1210
1211
  const lambdaName = `${PLACEHOLDER}${name}`
1211
1212
  check(
1212
1213
  [
@@ -1261,6 +1262,26 @@ export const typeCheck = (
1261
1262
  }
1262
1263
  checkReturns()
1263
1264
  checkArgs()
1265
+ // Check lambda body with defined types
1266
+ const copy = Object.create(env)
1267
+ for (let i = 0; i < env[name][STATS][ARGUMENTS].length; ++i) {
1268
+ const A = env[lambdaName][STATS][ARGUMENTS][i]
1269
+ const B = env[name][STATS][ARGUMENTS][i]
1270
+ copy[A[STATS][SIGNATURE]] = {
1271
+ [STATS]: {
1272
+ [SIGNATURE]: A[STATS][SIGNATURE],
1273
+ [TYPE_PROP]: B[STATS][TYPE_PROP],
1274
+ [RETURNS]: B[STATS][RETURNS]
1275
+ }
1276
+ }
1277
+ }
1278
+ check(
1279
+ wrapInApplyLambda(exp.at(-1).slice(2)).at(-1),
1280
+ copy,
1281
+ scope
1282
+ )
1283
+ // console.log(exp.at(-1).slice(1))
1284
+ // check(exp.at(-1), env, scope)
1264
1285
  // Types.delete(`; ${rootScopeIndex} ${lambdaName}`)
1265
1286
  }
1266
1287
  typeSet(Types, name, env, exp)
package/src/types.js CHANGED
@@ -36,7 +36,12 @@ export const IS_ARGUMENT = 'is_arg'
36
36
  export const NIL = 'nil'
37
37
  export const TRUE_WORD = 'true'
38
38
  export const FALSE_WORD = 'false'
39
- export const GET_ARRAY_INFERENCE = 'array:get'
39
+ export const GET_ARRAY_INFERENCE_SET = new Set([
40
+ 'array:get',
41
+ 'array:at'
42
+ // 'array:first',
43
+ // 'array:last'
44
+ ])
40
45
  export class SubType {
41
46
  constructor(args) {
42
47
  this.types = []
package/src/utils.js CHANGED
@@ -304,6 +304,10 @@ export const wrapInBlock = (ast) => [
304
304
  [[APPLY, KEYWORDS.BLOCK], ...ast]
305
305
  ]
306
306
  ]
307
+ export const wrapInApplyLambda = (ast) => [
308
+ [APPLY, KEYWORDS.CALL_FUNCTION],
309
+ [[APPLY, KEYWORDS.ANONYMOUS_FUNCTION], ...ast]
310
+ ]
307
311
  export const interpret = (ast, keywords) =>
308
312
  ast.reduce((_, x) => evaluate(x, keywords), 0)
309
313
  export const shake = (parsed, std) => treeShake(parsed, std).concat(parsed)