fez-lisp 1.5.68 → 1.5.70

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.68",
5
+ "version": "1.5.70",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -31,7 +31,9 @@ import {
31
31
  SIGNATURE,
32
32
  PREDICATE,
33
33
  COLLECTION,
34
- MAX_RETRY_DEFINITION
34
+ MAX_RETRY_DEFINITION,
35
+ ORDER,
36
+ VARIABLE_ORDER_INDEX
35
37
  } from './types.js'
36
38
  import {
37
39
  getSuffix,
@@ -114,6 +116,7 @@ const withScope = (name, scope) => {
114
116
  }
115
117
  export const typeCheck = (ast) => {
116
118
  const root = structuredClone(SPECIAL_FORM_TYPES)
119
+ root[ORDER] = 0
117
120
  const errorStack = new Set()
118
121
  const warningStack = new Set()
119
122
  const Types = new Map()
@@ -131,6 +134,7 @@ export const typeCheck = (ast) => {
131
134
  {
132
135
  if (!isSpecial)
133
136
  stack.push(() => {
137
+ // Figure out how to determine if varible is define after it's used
134
138
  if (env[first[VALUE]] === undefined) {
135
139
  errorStack.add(
136
140
  `Trying to access undefined variable ${first[VALUE]} (check #11)`
@@ -376,6 +380,7 @@ export const typeCheck = (ast) => {
376
380
  [STATS]: {
377
381
  [TYPE_PROP]: [APPLY],
378
382
  retried: 0,
383
+ [VARIABLE_ORDER_INDEX]: env[ORDER],
379
384
  [ARGS_COUNT]: n - 2,
380
385
  [ARGUMENTS]: [],
381
386
  [RETURNS]: [UNKNOWN]
@@ -400,8 +405,15 @@ export const typeCheck = (ast) => {
400
405
  const isL = isLeaf(rightHand)
401
406
  // if (!(name in env)) {
402
407
  if (isL && rightHand[TYPE] === WORD) {
408
+ // TODO make sure this prevents the assigment all together
409
+ if (env[rest[1][VALUE]] === undefined) {
410
+ errorStack.add(
411
+ `Trying to access undefined variable ${rest[1][VALUE]} (check #22)`
412
+ )
413
+ }
403
414
  // FULL REFF ASSIGMENT
404
415
  env[name] = env[rest[1][VALUE]]
416
+
405
417
  if (
406
418
  getSuffix(rest[1][VALUE]) === PREDICATE_SUFFIX &&
407
419
  getSuffix(name) !== PREDICATE_SUFFIX
@@ -429,6 +441,7 @@ export const typeCheck = (ast) => {
429
441
  env[name] = {
430
442
  [STATS]: {
431
443
  retried: 0,
444
+ [VARIABLE_ORDER_INDEX]: env[ORDER],
432
445
  [TYPE_PROP]: [ATOM],
433
446
  [RETURNS]: [ATOM]
434
447
  }
@@ -462,6 +475,7 @@ export const typeCheck = (ast) => {
462
475
  env[name] = {
463
476
  [STATS]: {
464
477
  retried: 0,
478
+ [VARIABLE_ORDER_INDEX]: env[ORDER],
465
479
  [TYPE_PROP]: [
466
480
  isL
467
481
  ? right[TYPE]
@@ -522,6 +536,7 @@ export const typeCheck = (ast) => {
522
536
  )}) so ${name} must end in (${PREDICATE_SUFFIX}) (check #23)`
523
537
  )
524
538
  }
539
+
525
540
  // FN assigment
526
541
  env[name][STATS][RETURNS] =
527
542
  env[right[VALUE]][STATS][RETURNS]
@@ -533,6 +548,7 @@ export const typeCheck = (ast) => {
533
548
  }
534
549
  Types.set(withScope(name, env), () => formatType(name, env))
535
550
  }
551
+ root[ORDER]++
536
552
  }
537
553
  break
538
554
  case KEYWORDS.ANONYMOUS_FUNCTION:
@@ -1117,7 +1133,17 @@ export const typeCheck = (ast) => {
1117
1133
  }
1118
1134
  }
1119
1135
  })
1120
- for (const r of rest) check(r, env, scope)
1136
+ for (let i = 0; i < rest.length; ++i) {
1137
+ const r = rest[i]
1138
+ if (isLeaf(r) && r[TYPE] !== ATOM && env[r[VALUE]] == undefined) {
1139
+ errorStack.add(
1140
+ `(${first[VALUE]}) is trying to access undefined variable (${
1141
+ r[VALUE]
1142
+ }) at argument (${i}) (${stringifyArgs(exp)}) (check #20)`
1143
+ )
1144
+ }
1145
+ check(r, env, scope)
1146
+ }
1121
1147
  break
1122
1148
  }
1123
1149
  }
package/src/evaluator.js CHANGED
@@ -13,10 +13,10 @@ export const evaluate = (exp, env = keywords) => {
13
13
  switch (head[TYPE]) {
14
14
  case WORD: {
15
15
  const word = env[value]
16
- if (word == undefined)
17
- throw new ReferenceError(
18
- `Undefined variable ${value} (${stringifyArgs(exp)})`
19
- )
16
+ if (word == undefined) {
17
+ throw new ReferenceError(`Accessing undefined variable ${value}`)
18
+ }
19
+
20
20
  return word
21
21
  }
22
22
  case APPLY: {
package/src/types.js CHANGED
@@ -8,6 +8,8 @@ export const RETURNS = 'returns'
8
8
  export const SCOPE_NAME = '__scope__'
9
9
  export const TYPE_PROP = 'type'
10
10
  export const SIGNATURE = 'name'
11
+ export const ORDER = '__order__'
12
+ export const VARIABLE_ORDER_INDEX = 'index'
11
13
  export const PREDICATE = 3
12
14
  export const COLLECTION = 4
13
15
  export const MAX_RETRY_DEFINITION = 1
@@ -28,7 +30,8 @@ export const toTypeNames = (type) => {
28
30
  }
29
31
  }
30
32
  export const SPECIAL_FORM_TYPES = {
31
- [SCOPE_NAME]: 'root',
33
+ [SCOPE_NAME]: '·',
34
+ [ORDER]: 0,
32
35
  [toTypeNames(APPLY)]: {
33
36
  [STATS]: {
34
37
  [TYPE_PROP]: [APPLY],