fez-lisp 1.5.99 → 1.5.100

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.99",
5
+ "version": "1.5.100",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -443,117 +443,115 @@ export const typeCheck = (ast, error = true) => {
443
443
  exp
444
444
  )})`
445
445
  )
446
- else {
447
- const name = rest[0][VALUE]
448
- // Predicate name consistency
449
- const rightHand = rest.at(-1)
446
+ const name = rest[0][VALUE]
447
+ // Predicate name consistency
448
+ const rightHand = rest.at(-1)
449
+ if (
450
+ rightHand &&
451
+ rightHand[0] &&
452
+ rightHand[0][TYPE] === APPLY &&
453
+ rightHand[0][VALUE] === KEYWORDS.ANONYMOUS_FUNCTION
454
+ ) {
455
+ validateLambda(rightHand, name)
456
+ const n = rightHand.length
457
+ env[name] = {
458
+ [STATS]: {
459
+ [TYPE_PROP]: [APPLY],
460
+ [SIGNATURE]: name,
461
+ retried: 0,
462
+ counter: 0,
463
+ [ARG_COUNT]: n - 2,
464
+ [ARGUMENTS]: fillUknownArgs(n - 2),
465
+ [RETURNS]: [UNKNOWN]
466
+ }
467
+ }
450
468
  if (
451
- rightHand &&
452
- rightHand[0] &&
453
- rightHand[0][TYPE] === APPLY &&
454
- rightHand[0][VALUE] === KEYWORDS.ANONYMOUS_FUNCTION
469
+ !checkReturnType({
470
+ stack,
471
+ exp,
472
+ env,
473
+ name,
474
+ errors
475
+ }) ||
476
+ (isUnknownReturn(env[name][STATS]) &&
477
+ env[name][STATS].retried < MAX_RETRY_DEFINITION)
455
478
  ) {
456
- validateLambda(rightHand, name)
457
- const n = rightHand.length
458
- env[name] = {
459
- [STATS]: {
460
- [TYPE_PROP]: [APPLY],
461
- [SIGNATURE]: name,
462
- retried: 0,
463
- counter: 0,
464
- [ARG_COUNT]: n - 2,
465
- [ARGUMENTS]: fillUknownArgs(n - 2),
466
- [RETURNS]: [UNKNOWN]
467
- }
468
- }
469
- if (
470
- !checkReturnType({
479
+ env[name][STATS].retried += 1
480
+ stack.unshift(() => {
481
+ checkReturnType({
471
482
  stack,
472
483
  exp,
473
484
  env,
474
485
  name,
475
486
  errors
476
- }) ||
477
- (isUnknownReturn(env[name][STATS]) &&
478
- env[name][STATS].retried < MAX_RETRY_DEFINITION)
479
- ) {
480
- env[name][STATS].retried += 1
481
- stack.unshift(() => {
482
- checkReturnType({
483
- stack,
484
- exp,
485
- env,
486
- name,
487
- errors
488
- })
489
- check(rightHand, env, exp)
490
487
  })
491
488
  check(rightHand, env, exp)
492
- } else check(rightHand, env, exp)
493
- } else {
494
- checkPredicateName(exp, rest, errors)
495
- const isLeafNode = isLeaf(rightHand)
496
- if (isLeafNode && rightHand[TYPE] === WORD) {
497
- // TODO make sure this prevents the assigment all together
498
- if (env[rest[1][VALUE]] === undefined)
499
- errors.add(
500
- `Trying to access undefined variable ${rest[1][VALUE]} (check #22)`
501
- )
489
+ })
490
+ check(rightHand, env, exp)
491
+ } else check(rightHand, env, exp)
492
+ } else {
493
+ checkPredicateName(exp, rest, errors)
494
+ const isLeafNode = isLeaf(rightHand)
495
+ if (isLeafNode && rightHand[TYPE] === WORD) {
496
+ // TODO make sure this prevents the assigment all together
497
+ if (env[rest[1][VALUE]] === undefined)
498
+ errors.add(
499
+ `Trying to access undefined variable ${rest[1][VALUE]} (check #22)`
500
+ )
502
501
 
503
- // Used to be checkin if it's an assigment to a special form
504
- // but this should not cause problems
505
- // env[name] = SPECIAL_FORMS_SET.has(rest[1][VALUE])
506
- // ? structuredClone(env[rest[1][VALUE]])
507
- // : env[rest[1][VALUE]]
508
- // FULL REFF ASSIGMENT
509
- env[name] = env[rest[1][VALUE]]
510
- } else if (isLeafNode && rightHand[TYPE] === ATOM) {
511
- // DECLARATION of ATOM
512
- env[name] = {
513
- [STATS]: {
514
- [SIGNATURE]: name,
515
- retried: 0,
516
- counter: 0,
517
- [TYPE_PROP]: [ATOM],
518
- [RETURNS]: [ATOM]
519
- }
502
+ // Used to be checkin if it's an assigment to a special form
503
+ // but this should not cause problems
504
+ // env[name] = SPECIAL_FORMS_SET.has(rest[1][VALUE])
505
+ // ? structuredClone(env[rest[1][VALUE]])
506
+ // : env[rest[1][VALUE]]
507
+ // FULL REFF ASSIGMENT
508
+ env[name] = env[rest[1][VALUE]]
509
+ } else if (isLeafNode && rightHand[TYPE] === ATOM) {
510
+ // DECLARATION of ATOM
511
+ env[name] = {
512
+ [STATS]: {
513
+ [SIGNATURE]: name,
514
+ retried: 0,
515
+ counter: 0,
516
+ [TYPE_PROP]: [ATOM],
517
+ [RETURNS]: [ATOM]
520
518
  }
521
- } else if (rightHand[0]) {
522
- const right = rightHand[0]
523
- //DECLARATION
524
- env[name] = {
525
- [STATS]: {
526
- retried: 0,
527
- counter: 0,
528
- [SIGNATURE]: name,
529
- [TYPE_PROP]: [
530
- isLeafNode
531
- ? right[TYPE]
532
- : env[right[VALUE]] == undefined
533
- ? UNKNOWN
534
- : env[right[VALUE]][STATS][RETURNS][0]
535
- ],
536
- [RETURNS]: [UNKNOWN]
537
- }
519
+ }
520
+ } else if (rightHand[0]) {
521
+ const right = rightHand[0]
522
+ //DECLARATION
523
+ env[name] = {
524
+ [STATS]: {
525
+ retried: 0,
526
+ counter: 0,
527
+ [SIGNATURE]: name,
528
+ [TYPE_PROP]: [
529
+ isLeafNode
530
+ ? right[TYPE]
531
+ : env[right[VALUE]] == undefined
532
+ ? UNKNOWN
533
+ : env[right[VALUE]][STATS][RETURNS][0]
534
+ ],
535
+ [RETURNS]: [UNKNOWN]
538
536
  }
539
- const body = rightHand
540
- const rem = hasBlock(body) ? body.at(-1) : body
541
- const returns = isLeaf(rem) ? rem : rem[0]
542
- resolveRetunType({
543
- stack,
544
- returns,
545
- rem,
546
- prop: TYPE_PROP,
547
- exp,
548
- env,
549
- name,
550
- errors
551
- })
552
537
  }
553
- check(rightHand, env, scope)
538
+ const body = rightHand
539
+ const rem = hasBlock(body) ? body.at(-1) : body
540
+ const returns = isLeaf(rem) ? rem : rem[0]
541
+ resolveRetunType({
542
+ stack,
543
+ returns,
544
+ rem,
545
+ prop: TYPE_PROP,
546
+ exp,
547
+ env,
548
+ name,
549
+ errors
550
+ })
554
551
  }
555
- Types.set(withScope(name, env), () => formatType(name, env))
552
+ check(rightHand, env, scope)
556
553
  }
554
+ Types.set(withScope(name, env), () => formatType(name, env))
557
555
  break
558
556
  case KEYWORDS.ANONYMOUS_FUNCTION:
559
557
  validateLambda(exp)