fez-lisp 1.5.85 → 1.5.86

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.85",
5
+ "version": "1.5.86",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  ATOM,
4
4
  KEYWORDS,
5
5
  PLACEHOLDER,
6
+ PREDICATES_SET,
6
7
  SPECIAL_FORMS_SET,
7
8
  STATIC_TYPES,
8
9
  STATIC_TYPES_SET,
@@ -176,6 +177,7 @@ export const typeCheck = (ast) => {
176
177
  if (re[0][TYPE] === ATOM || re[1][TYPE] === ATOM) {
177
178
  // ATOM ASSIGMENT
178
179
  env[name][STATS][prop][0] = ATOM
180
+ // TODO maybe delete this
179
181
  env[name][STATS][RETURNS][0] = ATOM
180
182
  } else if (
181
183
  !isLeaf(re[0]) &&
@@ -235,55 +237,43 @@ export const typeCheck = (ast) => {
235
237
  }
236
238
  break
237
239
  default:
238
- if (env[returns[VALUE]]) {
239
- if (
240
- env[returns[VALUE]][STATS][TYPE_PROP][0] === APPLY
241
- ) {
242
- if (returns[VALUE] === KEYWORDS.CALL_FUNCTION) {
243
- if (isLeaf(rest.at(-1).at(-1).at(-1))) {
244
- const fnName = rest.at(-1).at(-1).at(-1)[VALUE]
245
- const fn = env[fnName]
246
- env[name][STATS][TYPE_PROP][0] =
247
- fn[STATS][RETURNS][0]
248
- } else {
249
- const [returns, rem] = drillReturnType(
250
- rest.at(-1).at(-1).at(-1),
251
- (returns) =>
252
- returns[VALUE] === KEYWORDS.CALL_FUNCTION
253
- )
254
- resolveRetunType(returns, rem, TYPE_PROP)
255
- }
256
- }
257
- // ALWAYS APPLY
258
- // rest.at(-1)[0][TYPE] === APPLY
259
- // Here is upon application to store the result in the variable
260
- if (env[name][STATS][TYPE_PROP][0] === UNKNOWN)
261
- stack.unshift(() => {
262
- env[name][STATS][TYPE_PROP][0] =
263
- env[returns[VALUE]][STATS][RETURNS][0]
264
- env[name][STATS][TYPE_PROP][1] =
265
- env[returns[VALUE]][STATS][RETURNS][1]
266
- })
267
- env[name][STATS][RETURNS] =
268
- env[returns[VALUE]][STATS][RETURNS]
269
- } else {
270
- // Enclose function with it's own scope
271
- const args = env[name][STATS][ARGUMENTS] ?? []
272
- const fnScope = args.length
273
- ? Object.create(env)
274
- : env
275
- for (const arg of args)
276
- fnScope[arg[STATS][SIGNATURE]] = arg
277
- // RETURN TYPE OF FUNCTION ASSIGGMENT
278
- fnScope[name][STATS][RETURNS] =
279
- fnScope[returns[VALUE]][STATS][RETURNS]
280
- // assign(env[name][STATS][RETURNS],env[returns[VALUE]][STATS][RETURNS], 0)
281
- fnScope[name][STATS][RETURNS][0] =
282
- fnScope[returns[VALUE]][STATS][TYPE_PROP][0]
283
- }
284
- } else {
240
+ if (!env[returns[VALUE]])
285
241
  env[name][STATS][RETURNS] = [UNKNOWN]
286
- // env[name][STATS][RETURNS] = APPLY
242
+ // env[name][STATS][RETURNS] = APPLY
243
+ else if (
244
+ env[returns[VALUE]][STATS][TYPE_PROP][0] === APPLY
245
+ ) {
246
+ // TODO This seems to be able to be deleted
247
+ // FOR NOT IT CAN BE
248
+ // if (returns[VALUE] === KEYWORDS.CALL_FUNCTION) {
249
+ // if (isLeaf(rest.at(-1).at(-1).at(-1))) {
250
+ // const fnName = rest.at(-1).at(-1).at(-1)[VALUE]
251
+ // const fn = env[fnName]
252
+ // env[name][STATS][TYPE_PROP][0] =
253
+ // fn[STATS][RETURNS][0]
254
+ // } else {
255
+ // const [returns, rem] = drillReturnType(
256
+ // rest.at(-1).at(-1).at(-1),
257
+ // (returns) =>
258
+ // returns[VALUE] === KEYWORDS.CALL_FUNCTION
259
+ // )
260
+ // resolveRetunType(returns, rem, TYPE_PROP)
261
+ // }
262
+ // }
263
+
264
+ // ALWAYS APPLY
265
+ // rest.at(-1)[0][TYPE] === APPLY
266
+ // Here is upon application to store the result in the variable
267
+ if (env[name][STATS][TYPE_PROP][0] === UNKNOWN)
268
+ stack.unshift(() => {
269
+ env[name][STATS][TYPE_PROP][0] =
270
+ env[returns[VALUE]][STATS][RETURNS][0]
271
+ // this seems to be able to be deleted
272
+ // env[name][STATS][TYPE_PROP][1] =
273
+ // env[returns[VALUE]][STATS][RETURNS][1]
274
+ })
275
+ env[name][STATS][RETURNS] =
276
+ env[returns[VALUE]][STATS][RETURNS]
287
277
  }
288
278
  break
289
279
  }
@@ -335,7 +325,6 @@ export const typeCheck = (ast) => {
335
325
  }
336
326
  } else {
337
327
  const isL = isLeaf(rightHand)
338
- // if (!(name in env)) {
339
328
  if (isL && rightHand[TYPE] === WORD) {
340
329
  // TODO make sure this prevents the assigment all together
341
330
  if (env[rest[1][VALUE]] === undefined) {
@@ -359,7 +348,7 @@ export const typeCheck = (ast) => {
359
348
  [RETURNS]: [ATOM]
360
349
  }
361
350
  }
362
- } else {
351
+ } else if (rightHand[0]) {
363
352
  const right = rightHand[0]
364
353
  //DECLARATION
365
354
  env[name] = {
@@ -371,35 +360,27 @@ export const typeCheck = (ast) => {
371
360
  [TYPE_PROP]: [
372
361
  isL
373
362
  ? right[TYPE]
374
- : env[right?.[VALUE]]?.[STATS]?.[RETURNS]?.[0] ??
375
- UNKNOWN
363
+ : env[right[VALUE]] == undefined
364
+ ? UNKNOWN
365
+ : env[right[VALUE]][STATS][RETURNS][0]
376
366
  ],
377
367
  [RETURNS]: [UNKNOWN]
378
368
  }
379
369
  }
380
- if (right && right[VALUE]) {
381
- if (right[VALUE] === KEYWORDS.CALL_FUNCTION) {
382
- if (isLeaf(rightHand.at(-1))) {
383
- const fnName = rightHand.at(-1)[VALUE]
384
- const fn = env[fnName]
385
- // FB assigment
386
- env[name][STATS][TYPE_PROP] = fn[STATS][RETURNS]
387
- env[name][STATS][RETURNS] = fn[STATS][RETURNS]
388
- } else {
389
- const body = rightHand.at(-1).at(-1)
390
- const rem = hasBlock(body) ? body.at(-1) : body
391
- const returns = isLeaf(rem) ? rem : rem[0]
392
- resolveRetunType(returns, rem, TYPE_PROP)
393
- }
394
- } else {
395
- const body = rightHand
370
+ if (right[VALUE] === KEYWORDS.CALL_FUNCTION) {
371
+ if (!isLeaf(rightHand.at(-1))) {
372
+ const body = rightHand.at(-1).at(-1)
396
373
  const rem = hasBlock(body) ? body.at(-1) : body
397
374
  const returns = isLeaf(rem) ? rem : rem[0]
398
375
  resolveRetunType(returns, rem, TYPE_PROP)
399
376
  }
377
+ } else {
378
+ const body = rightHand
379
+ const rem = hasBlock(body) ? body.at(-1) : body
380
+ const returns = isLeaf(rem) ? rem : rem[0]
381
+ resolveRetunType(returns, rem, TYPE_PROP)
400
382
  }
401
383
  }
402
- // }
403
384
  check(rightHand, env, scope)
404
385
  }
405
386
  Types.set(withScope(name, env), () => formatType(name, env))
@@ -511,7 +492,6 @@ export const typeCheck = (ast) => {
511
492
  ref[STATS][RETURNS] = concequent[STATS][TYPE_PROP]
512
493
  }
513
494
  }
514
-
515
495
  break
516
496
  default:
517
497
  if (copy[ret[VALUE]])
@@ -599,63 +579,64 @@ export const typeCheck = (ast) => {
599
579
  const args = env[first[VALUE]][STATS][ARGUMENTS] ?? []
600
580
  for (let i = 0; i < args.length; ++i) {
601
581
  // type check
602
- const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
582
+ // TODO get rof pred type
583
+ // const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
603
584
  const MAIN_TYPE = args[i][STATS][TYPE_PROP][0]
604
- if (PRED_TYPE != undefined && !isLeaf(rest[i])) {
605
- const current = rest[i][0]
606
- if (current[TYPE] === APPLY) {
607
- if (current[VALUE] == KEYWORDS.CALL_FUNCTION) {
608
- if (isLeaf(rest[i].at(-1))) {
609
- const fnName = rest[i].at(-1)[VALUE]
610
- const fn = env[fnName]
611
- if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
585
+ if (first[TYPE] === APPLY && isSpecial) {
586
+ if (
587
+ MAIN_TYPE === ATOM &&
588
+ PREDICATES_SET.has(first[VALUE]) &&
589
+ !isLeaf(rest[i]) &&
590
+ rest[i][0][TYPE] === APPLY &&
591
+ rest[i][0][VALUE] === KEYWORDS.CALL_FUNCTION
592
+ ) {
593
+ if (isLeaf(rest[i].at(-1))) {
594
+ const fnName = rest[i].at(-1)[VALUE]
595
+ const fn = env[fnName]
596
+ if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
597
+ errorStack.add(
598
+ `Incorrect type of argument (${i}) for (${
599
+ first[VALUE]
600
+ }). Expected (${toTypeNames(
601
+ MAIN_TYPE
602
+ )}) but got an (${toTypeNames(
603
+ fn[STATS][RETURNS][0]
604
+ )}) (${stringifyArgs(exp)}) (check #26)`
605
+ )
606
+ }
607
+ } else {
608
+ const body = rest[i].at(-1).at(-1)
609
+ const rem = hasBlock(body) ? body.at(-1) : body
610
+ const returns = isLeaf(rem) ? rem : rem[0]
611
+ if (returns[TYPE] === ATOM) {
612
+ if (MAIN_TYPE !== ATOM) {
612
613
  errorStack.add(
613
- `Incorrect type of argument (${i}) for (${
614
+ `Incorrect type of argument ${i} for (${
614
615
  first[VALUE]
615
616
  }). Expected (${toTypeNames(
616
617
  MAIN_TYPE
617
618
  )}) but got an (${toTypeNames(
618
- fn[STATS][RETURNS][0]
619
- )}) (${stringifyArgs(exp)}) (check #26)`
619
+ ATOM
620
+ )}) (${stringifyArgs(exp)}) (check #27)`
620
621
  )
621
622
  }
622
- } else {
623
- const body = rest[i].at(-1).at(-1)
624
- const rem = hasBlock(body) ? body.at(-1) : body
625
- const returns = isLeaf(rem) ? rem : rem[0]
626
- if (returns[TYPE] === ATOM) {
627
- if (MAIN_TYPE !== ATOM) {
628
- errorStack.add(
629
- `Incorrect type of argument ${i} for (${
630
- first[VALUE]
631
- }). Expected (${toTypeNames(
632
- MAIN_TYPE
633
- )}) but got an (${toTypeNames(
634
- ATOM
635
- )}) (${stringifyArgs(exp)}) (check #27)`
636
- )
637
- }
638
- } else if (env[returns[VALUE]]) {
639
- if (
640
- MAIN_TYPE !==
641
- env[returns[VALUE]][STATS][RETURNS][0]
642
- ) {
643
- errorStack.add(
644
- `Incorrect type of argument ${i} for (${
645
- first[VALUE]
646
- }). Expected (${toTypeNames(
647
- MAIN_TYPE
648
- )}) but got (${toTypeNames(
649
- env[returns[VALUE]][STATS][TYPE_PROP]
650
- )}) (${stringifyArgs(exp)}) (check #29)`
651
- )
652
- }
623
+ } else if (env[returns[VALUE]]) {
624
+ if (
625
+ MAIN_TYPE !== env[returns[VALUE]][STATS][RETURNS][0]
626
+ ) {
627
+ errorStack.add(
628
+ `Incorrect type of argument ${i} for (${
629
+ first[VALUE]
630
+ }). Expected (${toTypeNames(
631
+ MAIN_TYPE
632
+ )}) but got (${toTypeNames(
633
+ env[returns[VALUE]][STATS][TYPE_PROP]
634
+ )}) (${stringifyArgs(exp)}) (check #29)`
635
+ )
653
636
  }
654
637
  }
655
638
  }
656
639
  }
657
- }
658
- if (first[TYPE] === APPLY && isSpecial) {
659
640
  const isCast = STATIC_TYPES_SET.has(first[VALUE])
660
641
  const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
661
642
  for (let i = 0; i < rest.length; ++i) {
@@ -706,17 +687,17 @@ export const typeCheck = (ast) => {
706
687
  )}) (${stringifyArgs(exp)}) (check #3)`
707
688
  )
708
689
  }
709
- } else if (env[rest[i][VALUE]]) {
690
+ } else if (env[CAR]) {
710
691
  if (isCast) {
711
692
  // CAST assigment
712
- env[rest[i][VALUE]][STATS][TYPE_PROP] =
713
- root[first[VALUE]][STATS][RETURNS]
714
- root[first[VALUE]][STATS][RETURNS] =
715
- root[first[VALUE]][STATS][RETURNS]
693
+ env[rest[i][VALUE]][STATS][TYPE_PROP][0] =
694
+ root[first[VALUE]][STATS][RETURNS][0]
695
+
696
+ // root[first[VALUE]][STATS][RETURNS] =
697
+ // root[first[VALUE]][STATS][RETURNS]
716
698
  } else {
717
699
  // VALUE assigment
718
- env[rest[i][VALUE]][STATS][TYPE_PROP][0] =
719
- MAIN_TYPE
700
+ env[CAR][STATS][TYPE_PROP][0] = MAIN_TYPE
720
701
  }
721
702
  }
722
703
  }
package/src/keywords.js CHANGED
@@ -15,7 +15,6 @@ export const STATIC_TYPES = {
15
15
  COLLECTION: 'Collection',
16
16
  PREDICATE: 'Predicate'
17
17
  }
18
- export const STATIC_TYPES_SET = new Set(Object.values(STATIC_TYPES))
19
18
  export const KEYWORDS = {
20
19
  LOOP: 'loop',
21
20
  CREATE_ARRAY: 'array',
@@ -77,3 +76,11 @@ export const DEBUG = {
77
76
  export const SPECIAL_FORMS_SET = new Set(
78
77
  Object.values(KEYWORDS).concat(Object.values(STATIC_TYPES))
79
78
  )
79
+ export const STATIC_TYPES_SET = new Set(Object.values(STATIC_TYPES))
80
+ export const PREDICATES_SET = new Set([
81
+ KEYWORDS.IF,
82
+ KEYWORDS.AND,
83
+ KEYWORDS.OR,
84
+ KEYWORDS.NOT,
85
+ KEYWORDS.LOOP
86
+ ])