fez-lisp 1.6.36 → 1.6.38

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.6.36",
5
+ "version": "1.6.38",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/debugger.js CHANGED
@@ -13,7 +13,8 @@ import {
13
13
  FALSE,
14
14
  STATIC_TYPES,
15
15
  DEBUG,
16
- SPECIAL_FORMS_SET
16
+ SPECIAL_FORMS_SET,
17
+ RUNTIME_TYPES
17
18
  } from './keywords.js'
18
19
  import { isLeaf, LISP } from './parser.js'
19
20
  import {
@@ -854,6 +855,7 @@ const keywords = {
854
855
  [DEBUG.LOG]: (args, env) => evaluate(args[0], env)
855
856
  }
856
857
  const debugStack = []
858
+ let isDebugging = false
857
859
  const evaluate = (exp, env = keywords) => {
858
860
  const [head, ...tail] = isLeaf(exp) ? [exp] : exp
859
861
  if (head == undefined) return []
@@ -867,16 +869,12 @@ const evaluate = (exp, env = keywords) => {
867
869
  case APPLY:
868
870
  res = env[value](tail, env)
869
871
  if (
872
+ isDebugging &&
870
873
  value !== KEYWORDS.BLOCK &&
871
874
  value !== KEYWORDS.CALL_FUNCTION &&
872
875
  value !== KEYWORDS.ANONYMOUS_FUNCTION &&
873
876
  value !== KEYWORDS.DEFINE_VARIABLE
874
877
  ) {
875
- // debugStack.push(
876
- // `\x1b[31m${LISP.source(exp)}\x1b[32m\n${
877
- // typeof res === 'function' ? '(lambda)' : serialise(res)
878
- // }\x1b[0m`
879
- // )
880
878
  const out = typeof res === 'function' ? '(lambda)' : LISP.serialise(res)
881
879
  if (debugStack.at(-1)?.result !== out)
882
880
  debugStack.push({
@@ -894,13 +892,17 @@ const evaluate = (exp, env = keywords) => {
894
892
  }
895
893
  export const debugStackToString = (stack) =>
896
894
  stack.map(({ source, result }) => `${source}\n${result}`).join('\n')
895
+ const sliceStack = (debugStack, start, end) => {
896
+ start = start ? debugStack.findIndex(start) : 0
897
+ end = end ? debugStack.findIndex(end) + 1 : debugStack.length
898
+ return debugStack.slice(start, end)
899
+ }
897
900
  export const startDebug = (ast, speed = 250, start, end) => {
898
901
  debugStack.length = 0
902
+ isDebugging = true
899
903
  try {
900
904
  evaluate(enhance(ast))
901
- start = start ? debugStack.findIndex(start) : 0
902
- end = end ? debugStack.findIndex(end) + 1 : debugStack.length
903
- const stack = debugStack.slice(start, end)
905
+ const stack = sliceStack(debugStack, start, end)
904
906
  if (speed !== 0) {
905
907
  stack.reverse()
906
908
  const rec = () => {
@@ -914,9 +916,11 @@ export const startDebug = (ast, speed = 250, start, end) => {
914
916
  }
915
917
  rec()
916
918
  }
919
+ isDebugging = false
917
920
  return [stack, null]
918
921
  } catch (error) {
919
- return [null, error]
922
+ isDebugging = false
923
+ return [sliceStack(debugStack, start, end), error]
920
924
  }
921
925
  }
922
926
 
package/src/macros.js CHANGED
@@ -2,7 +2,8 @@ import { isLeaf } from './parser.js'
2
2
  import {
3
3
  EXPONENTIATION_RAW,
4
4
  INTEGER_DIVISION,
5
- NOT_EQUAL
5
+ NOT_EQUAL,
6
+ EQUAL
6
7
  } from '../lib/baked/macros.js'
7
8
  import {
8
9
  APPLY,
@@ -23,6 +24,7 @@ export const SUGGAR = {
23
24
  STR_LIST: '~~',
24
25
  NOT_EQUAL_1: '!=',
25
26
  NOT_EQUAL_2: '<>',
27
+ EQUAL_1: '==',
26
28
  REMAINDER_OF_DIVISION_1: '%',
27
29
  UNLESS: 'unless',
28
30
  CREATE_LIST: 'list',
@@ -70,6 +72,10 @@ export const deSuggarAst = (ast, scope) => {
70
72
  exp.length = 0
71
73
  exp.push(...NOT_EQUAL)
72
74
  break
75
+ case SUGGAR.EQUAL_1:
76
+ exp.length = 0
77
+ exp.push(...EQUAL)
78
+ break
73
79
  case SUGGAR.POWER:
74
80
  exp.length = 0
75
81
  exp.push(...EXPONENTIATION_RAW)
@@ -525,6 +531,20 @@ export const deSuggarAst = (ast, scope) => {
525
531
  deSuggarAst(exp, scope)
526
532
  }
527
533
  break
534
+ case SUGGAR.EQUAL_1:
535
+ {
536
+ if (rest.length !== 2)
537
+ throw new RangeError(
538
+ `Invalid number of arguments for (${
539
+ exp[0][1]
540
+ }), expected (= 2) but got ${rest.length} (${
541
+ exp[0][1]
542
+ } ${stringifyArgs(rest)})`
543
+ )
544
+ exp[0][VALUE] = KEYWORDS.EQUAL
545
+ deSuggarAst(exp, scope)
546
+ }
547
+ break
528
548
  case KEYWORDS.DEFINE_VARIABLE:
529
549
  {
530
550
  const last = exp.at(-1)