fez-lisp 1.5.56 → 1.5.57

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.56",
5
+ "version": "1.5.57",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  PLACEHOLDER,
9
9
  PREDICATE_SUFFIX,
10
10
  SPECIAL_FORMS_SET,
11
+ STATIC_TYPES,
11
12
  STATIC_TYPES_SET,
12
13
  TRUE,
13
14
  TYPE,
@@ -80,12 +81,20 @@ const formatType = (name, env) => {
80
81
  ? `${name} (${(stats[ARGUMENTS] ?? [])
81
82
  .map(
82
83
  (x) =>
83
- `${x[STATS][SIGNATURE]} ${toTypeNames(x[STATS][TYPE_PROP][0])}`
84
+ `${x[STATS][SIGNATURE]} ${x[STATS][TYPE_PROP].map(
85
+ toTypeNames
86
+ ).join(' ')}${
87
+ x[STATS][TYPE_PROP][0] === APPLY
88
+ ? ` ${toTypeNames(
89
+ x[STATS][RETURNS][1] ?? x[STATS][RETURNS][0]
90
+ )}`
91
+ : ''
92
+ }`
84
93
  )
85
94
  .join(' ')}) -> ${toTypeNames(
86
95
  stats[RETURNS][1] ?? stats[RETURNS][0]
87
96
  )}`
88
- : `${name} ${toTypeNames(stats[TYPE_PROP][0])}`
97
+ : `${name} ${stats[TYPE_PROP].map(toTypeNames).join(' ')}`
89
98
  : name
90
99
  }
91
100
  const formatTypes = (env) => {
@@ -108,7 +117,9 @@ const getScopeNames = (scope) => {
108
117
  }
109
118
  const withScope = (name, scope) => {
110
119
  const chain = getScopeNames(scope)
111
- return `${chain.join(' ')} ${name}`
120
+ return `${chain
121
+ .map((x) => (Number.isInteger(+x) ? '~' : x))
122
+ .join(' ')} ${name}`
112
123
  }
113
124
  export const typeCheck = (ast) => {
114
125
  const root = {
@@ -1245,6 +1256,32 @@ export const typeCheck = (ast) => {
1245
1256
  errorStack.add(
1246
1257
  `Trying to access undefined variable ${first[VALUE]} (check #11)`
1247
1258
  )
1259
+ } else {
1260
+ const T = env[first[VALUE]][STATS]
1261
+ const isKnown = T[TYPE_PROP][0] !== UNKNOWN
1262
+ switch (first[VALUE]) {
1263
+ case 'xs':
1264
+ if (isKnown && T[TYPE_PROP][0] !== COLLECTION) {
1265
+ warningStack.add(
1266
+ `A variable named xs must be of type (${
1267
+ STATIC_TYPES.COLLECTION
1268
+ }) but got type (${toTypeNames(
1269
+ T[TYPE_PROP][0]
1270
+ )}) (check #32)`
1271
+ )
1272
+ } else T[TYPE_PROP] = [COLLECTION]
1273
+ break
1274
+ default:
1275
+ {
1276
+ const isPredicate =
1277
+ getSuffix(first[VALUE]) === PREDICATE_SUFFIX
1278
+ if (isPredicate) {
1279
+ if (isKnown) T[TYPE_PROP][1] = PREDICATE
1280
+ T[RETURNS] = [ATOM, PREDICATE]
1281
+ }
1282
+ }
1283
+ break
1284
+ }
1248
1285
  }
1249
1286
  })
1250
1287
  }
@@ -1743,6 +1780,7 @@ export const typeCheck = (ast) => {
1743
1780
  if (isLeaf(rest[i])) {
1744
1781
  if (rest[i][TYPE] === WORD) {
1745
1782
  if (
1783
+ !isSpecial &&
1746
1784
  env[rest[i][VALUE]] &&
1747
1785
  PRED_TYPE !==
1748
1786
  env[rest[i][VALUE]][STATS][RETURNS][1]
package/src/compiler.js CHANGED
@@ -264,7 +264,7 @@ const comp = (tree, Drill) => {
264
264
  return `__error(${compile(tail[0], Drill)})`
265
265
  }
266
266
 
267
- case STATIC_TYPES.APPLICATION:
267
+ case STATIC_TYPES.ABSTRACTION:
268
268
  case STATIC_TYPES.COLLECTION:
269
269
  case STATIC_TYPES.UNKNOWN:
270
270
  case STATIC_TYPES.ATOM:
@@ -833,7 +833,7 @@ export const keywords = {
833
833
  throw new Error(expression.map((x) => String.fromCharCode(x)).join(''))
834
834
  },
835
835
 
836
- [STATIC_TYPES.APPLICATION]: (args, env) => evaluate(args[0], env),
836
+ [STATIC_TYPES.ABSTRACTION]: (args, env) => evaluate(args[0], env),
837
837
  [STATIC_TYPES.ATOM]: (args, env) => evaluate(args[0], env),
838
838
  [STATIC_TYPES.COLLECTION]: (args, env) => evaluate(args[0], env),
839
839
  [STATIC_TYPES.PREDICATE]: (args, env) => evaluate(args[0], env),
package/src/keywords.js CHANGED
@@ -9,7 +9,7 @@ export const PLACEHOLDER = '.'
9
9
  export const MUTATION_SUFFIX = '!'
10
10
  export const PREDICATE_SUFFIX = '?'
11
11
  export const STATIC_TYPES = {
12
- APPLICATION: 'Abstraction',
12
+ ABSTRACTION: 'Abstraction',
13
13
  UNKNOWN: 'Unknown',
14
14
  ATOM: 'Atom',
15
15
  COLLECTION: 'Collection',
package/src/utils.js CHANGED
@@ -321,7 +321,7 @@ export const addTypeIdentities = (ast) => {
321
321
  const temp = block.shift()
322
322
  block.unshift(
323
323
  temp,
324
- identity(STATIC_TYPES.APPLICATION),
324
+ identity(STATIC_TYPES.ABSTRACTION),
325
325
  identity(STATIC_TYPES.ATOM),
326
326
  identity(STATIC_TYPES.COLLECTION),
327
327
  identity(STATIC_TYPES.PREDICATE),