fez-lisp 1.5.31 → 1.5.32

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.31",
5
+ "version": "1.5.32",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -376,8 +376,7 @@ export const typeCheck = (ast) => {
376
376
  }
377
377
  }
378
378
  const errorStack = new Map()
379
- const withScope = (name, env) =>
380
- `${env[SCOPE_NAME] ?? root[SCOPE_NAME]}_${name}`
379
+ const withScope = (name, scope) => `${scope[SCOPE_NAME]}_${name}`
381
380
 
382
381
  const stack = []
383
382
  const check = (exp, env, scope) => {
@@ -402,48 +401,58 @@ export const typeCheck = (ast) => {
402
401
  switch (first[VALUE]) {
403
402
  case KEYWORDS.DEFINE_VARIABLE:
404
403
  {
405
- if (
406
- rest.length &&
407
- rest.at(-1).length &&
408
- rest.at(-1)[0][TYPE] === APPLY &&
409
- rest.at(-1)[0][VALUE] === KEYWORDS.ANONYMOUS_FUNCTION
410
- ) {
411
- const name = rest[0][VALUE]
412
- const n = rest.at(-1).length
413
- env[name] = {
414
- [STATS]: {
415
- type: APPLY,
416
- [ARGS_COUNT]: n - 2,
417
- [ARGS]: []
418
- }
419
- }
420
- if (name[name.length - 1] === PREDICATE_SUFFIX)
421
- env[name][STATS][SUBTYPE] = PREDICATE
422
-
423
- scope = exp
424
- if (env[SCOPE_NAME]) {
425
- const key = withScope(name, scope)
426
- if (errorStack.has(key)) errorStack.delete(key)
427
- }
428
- check(rest.at(-1), env, scope)
404
+ if (rest.length !== 2) {
405
+ throw new TypeError(
406
+ `Incorrect number of arguments for (${
407
+ first[VALUE]
408
+ }). Expected (= 2) but got ${rest.length} (${stringifyArgs(
409
+ exp
410
+ )}) (check #10)`
411
+ )
429
412
  } else {
430
- const name = rest[0][VALUE]
431
- if (!(name in env)) {
432
- if (rest[1][TYPE] === WORD) env[name] = env[rest[1][VALUE]]
433
- else
434
- env[name] = {
435
- [STATS]: {
436
- type: isLeaf(rest.at(-1))
437
- ? rest.at(-1)[TYPE]
438
- : env[rest.at(-1)[0]?.[VALUE]]?.[STATS]?.[
439
- RETURNS
440
- ] ?? UNKNOWN
441
- }
413
+ if (
414
+ rest.at(-1).length &&
415
+ rest.at(-1)[0][TYPE] === APPLY &&
416
+ rest.at(-1)[0][VALUE] === KEYWORDS.ANONYMOUS_FUNCTION
417
+ ) {
418
+ const name = rest[0][VALUE]
419
+ const n = rest.at(-1).length
420
+ env[name] = {
421
+ [STATS]: {
422
+ type: APPLY,
423
+ [ARGS_COUNT]: n - 2,
424
+ [ARGS]: []
442
425
  }
443
- }
444
- if (env[SCOPE_NAME]) {
426
+ }
427
+ if (name[name.length - 1] === PREDICATE_SUFFIX)
428
+ env[name][STATS][SUBTYPE] = PREDICATE
445
429
  const key = withScope(name, scope)
446
430
  if (errorStack.has(key)) errorStack.delete(key)
431
+ scope = exp
432
+ } else {
433
+ const name = rest[0][VALUE]
434
+ if (!(name in env)) {
435
+ if (rest[1][TYPE] === WORD)
436
+ env[name] = env[rest[1][VALUE]]
437
+ else
438
+ env[name] = {
439
+ [STATS]: {
440
+ type: isLeaf(rest.at(-1))
441
+ ? rest.at(-1)[TYPE]
442
+ : env[rest.at(-1)[0]?.[VALUE]]?.[STATS]?.[
443
+ RETURNS
444
+ ] ?? UNKNOWN
445
+ }
446
+ }
447
+ }
448
+ // if (name === 'math:decimal-scaling') {
449
+ // const key = withScope(name, scope)
450
+ // if (errorStack.has(key)) errorStack.delete(key)
451
+ // }
452
+ // if (scope[SCOPE_NAME]) {
453
+ // const key = withScope(name, scope)
454
+ // if (errorStack.has(key)) errorStack.delete(key)
455
+ // }
447
456
  }
448
457
  check(rest.at(-1), env, scope)
449
458
  }
@@ -464,11 +473,13 @@ export const typeCheck = (ast) => {
464
473
  const copy = Object.create(env)
465
474
  if (isLeaf(scope[1])) {
466
475
  copy[SCOPE_NAME] = scope[1][VALUE]
467
- } else
476
+ } else {
468
477
  copy[SCOPE_NAME] = performance
469
478
  .now()
470
479
  .toString()
471
480
  .replace('.', 0)
481
+ }
482
+
472
483
  for (const param of params) {
473
484
  copy[param[VALUE]] = { [STATS]: { type: UNKNOWN } }
474
485
  if (env[copy[SCOPE_NAME]])
package/src/macros.js CHANGED
@@ -619,7 +619,6 @@ export const deSuggarAst = (ast, scope) => {
619
619
  ]
620
620
  deSuggarAst(exp[exp.length - 1])
621
621
  } else if (prefix === OPTIMIZATIONS.CACHE) {
622
- // TODO: Make this
623
622
  const args = last.slice(1, -1)
624
623
  const newName = `*${performance
625
624
  .now()
@@ -810,7 +809,7 @@ export const deSuggarAst = (ast, scope) => {
810
809
  export const replaceStrings = (source) => {
811
810
  // const quotes = source.match(/"(.*?)"/g)
812
811
  const quotes = source.match(/"(?:.*?(\n|\r))*?.*?"/g)
813
- // TODO handle escaping
812
+ // TODO: handle escaping
814
813
  if (quotes)
815
814
  for (const q of quotes)
816
815
  source = source.replaceAll(
package/src/utils.js CHANGED
@@ -195,8 +195,34 @@ const extractDeps = (visited, deps) =>
195
195
  .map((x) => deps.get(x))
196
196
  .sort((a, b) => a.index - b.index)
197
197
  .map((x) => x.value)
198
- const toIgnore = (ast) =>
199
- ast.filter(([x]) => isDefinition(x)).map(([_, x]) => x[VALUE])
198
+ const toIgnore = (ast) => {
199
+ const out = []
200
+ const dfs = (exp) => {
201
+ const [head, ...tail] = isLeaf(exp) ? [exp] : exp
202
+ if (head == undefined) return []
203
+ switch (head[TYPE]) {
204
+ case WORD:
205
+ break
206
+ case ATOM:
207
+ break
208
+ case APPLY:
209
+ {
210
+ switch (head[VALUE]) {
211
+ case KEYWORDS.DEFINE_VARIABLE:
212
+ out.push(tail[0][VALUE])
213
+ break
214
+ default:
215
+ for (const r of tail) dfs(r)
216
+ break
217
+ }
218
+ }
219
+ break
220
+ }
221
+ }
222
+ dfs(ast[0])
223
+ return out
224
+ // ast.filter(([x]) => isDefinition(x)).map(([_, x]) => x[VALUE])
225
+ }
200
226
  export const treeShake = (ast, libs) => {
201
227
  const deps = toDeps(libs)
202
228
  const visited = new Set()