fez-lisp 1.6.35 → 1.6.37

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.35",
5
+ "version": "1.6.37",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/debugger.js CHANGED
@@ -13,10 +13,17 @@ 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
- import { definedTypes, filteredDefinedTypes, withCtxTypes } from './types.js'
20
+ import {
21
+ definedTypes,
22
+ filteredDefinedTypes,
23
+ formatType,
24
+ SPECIAL_FORM_TYPES,
25
+ withCtxTypes
26
+ } from './types.js'
20
27
  import {
21
28
  isForbiddenVariableName,
22
29
  removeNoCode,
@@ -848,6 +855,7 @@ const keywords = {
848
855
  [DEBUG.LOG]: (args, env) => evaluate(args[0], env)
849
856
  }
850
857
  const debugStack = []
858
+ let isDebugging = false
851
859
  const evaluate = (exp, env = keywords) => {
852
860
  const [head, ...tail] = isLeaf(exp) ? [exp] : exp
853
861
  if (head == undefined) return []
@@ -861,16 +869,12 @@ const evaluate = (exp, env = keywords) => {
861
869
  case APPLY:
862
870
  res = env[value](tail, env)
863
871
  if (
872
+ isDebugging &&
864
873
  value !== KEYWORDS.BLOCK &&
865
874
  value !== KEYWORDS.CALL_FUNCTION &&
866
875
  value !== KEYWORDS.ANONYMOUS_FUNCTION &&
867
876
  value !== KEYWORDS.DEFINE_VARIABLE
868
877
  ) {
869
- // debugStack.push(
870
- // `\x1b[31m${LISP.source(exp)}\x1b[32m\n${
871
- // typeof res === 'function' ? '(lambda)' : serialise(res)
872
- // }\x1b[0m`
873
- // )
874
878
  const out = typeof res === 'function' ? '(lambda)' : LISP.serialise(res)
875
879
  if (debugStack.at(-1)?.result !== out)
876
880
  debugStack.push({
@@ -888,13 +892,17 @@ const evaluate = (exp, env = keywords) => {
888
892
  }
889
893
  export const debugStackToString = (stack) =>
890
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
+ }
891
900
  export const startDebug = (ast, speed = 250, start, end) => {
892
901
  debugStack.length = 0
902
+ isDebugging = true
893
903
  try {
894
904
  evaluate(enhance(ast))
895
- start = start ? debugStack.findIndex(start) : 0
896
- end = end ? debugStack.findIndex(end) + 1 : debugStack.length
897
- const stack = debugStack.slice(start, end)
905
+ const stack = sliceStack(debugStack, start, end)
898
906
  if (speed !== 0) {
899
907
  stack.reverse()
900
908
  const rec = () => {
@@ -908,9 +916,11 @@ export const startDebug = (ast, speed = 250, start, end) => {
908
916
  }
909
917
  rec()
910
918
  }
919
+ isDebugging = false
911
920
  return [stack, null]
912
921
  } catch (error) {
913
- return [null, error]
922
+ isDebugging = false
923
+ return [sliceStack(debugStack, start, end), error]
914
924
  }
915
925
  }
916
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)