fez-lisp 1.4.2 → 1.4.4

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/src/keywords.js CHANGED
@@ -39,7 +39,8 @@ export const KEYWORDS = {
39
39
  CALL_FUNCTION: 'apply',
40
40
  DEFINE_VARIABLE: 'let',
41
41
 
42
- SET_ARRAY: 'set!'
42
+ SET_ARRAY: 'set!',
43
+ ERROR: 'throw'
43
44
  }
44
45
 
45
46
  export const TYPES = {
@@ -53,8 +54,7 @@ export const RUNTIME_TYPES = {
53
54
  }
54
55
  export const DEBUG = {
55
56
  LOG: 'log',
56
- ASSERT: 'assert',
57
- ERROR: 'error'
57
+ ASSERT: 'assert'
58
58
  }
59
59
 
60
60
  export const SPECIAL_FORMS_SET = new Set(Object.values(KEYWORDS))
package/src/utils.js CHANGED
@@ -317,10 +317,10 @@ const identity = (name) => [
317
317
  [1, 'x']
318
318
  ]
319
319
  ]
320
- export const callStack = [KEYWORDS.CALL_FUNCTION]
320
+ export const callStack = [KEYWORDS.BLOCK]
321
321
  export const debug = (ast) => {
322
322
  callStack.length = 0
323
- callStack.push(KEYWORDS.CALL_FUNCTION)
323
+ callStack.push(KEYWORDS.BLOCK)
324
324
  try {
325
325
  const debugEnv = {
326
326
  ...keywords,
@@ -387,22 +387,6 @@ export const debug = (ast) => {
387
387
  } else console.log(expression)
388
388
  return expression
389
389
  },
390
- [DEBUG.ERROR]: (args, env) => {
391
- if (args.length !== 1)
392
- throw new RangeError(
393
- `Invalid number of arguments to (${DEBUG.ERROR}) (= 1 required) (${
394
- DEBUG.ERROR
395
- } ${stringifyArgs(args)})`
396
- )
397
- const expression = evaluate(args[0], env)
398
- if (!Array.isArray(expression))
399
- throw new TypeError(
400
- `Argument of (${DEBUG.ERROR}) must be an (${
401
- DEBUG.ARRAY_TYPE
402
- }) but got (${expression}) (${DEBUG.ERROR} ${stringifyArgs(args)})`
403
- )
404
- throw new Error(expression.map((x) => String.fromCharCode(x)).join(''))
405
- },
406
390
  [DEBUG.ASSERT]: (args, env) => {
407
391
  if (args.length < 2)
408
392
  throw new RangeError(
@@ -432,12 +416,12 @@ export const debug = (ast) => {
432
416
  )
433
417
  if (condition) {
434
418
  const error = args[i + 1]
435
- if (error[0][TYPE] === APPLY && error[0][VALUE] === DEBUG.ERROR)
419
+ if (error[0][TYPE] === APPLY && error[0][VALUE] === KEYWORDS.ERROR)
436
420
  return evaluate(error, env)
437
421
  else
438
422
  throw new TypeError(
439
423
  `Concequence of (${DEBUG.ASSERT}) must be (${
440
- DEBUG.ERROR
424
+ KEYWORDS.ERROR
441
425
  }) but got (${DEBUG.ASSERT} ${stringifyArgs(args)})`
442
426
  )
443
427
  }
@@ -451,17 +435,15 @@ export const debug = (ast) => {
451
435
  error.message.includes('Maximum call stack size exceeded') ||
452
436
  error.message.includes('too much recursion')
453
437
  if (!isMaxCallStack) {
454
- error.message += `\n\nscope:\n(${callStack.at(-1)})`
438
+ error.message += `\n${callStack
439
+ .reverse()
440
+ .map((x, i) => `\x1b[33m${Array(i + 2).join('.')}\x1b[31m(${x} \x1b[39m...\x1b[31m)`)
441
+ .join('\n')}`
455
442
  throw error
456
443
  } else logError(error.message)
457
444
  }
458
445
  const block = ast[1][1]
459
446
  const temp = block.shift()
460
- block.unshift(
461
- temp,
462
- identity(DEBUG.LOG),
463
- identity(DEBUG.ERROR),
464
- identity(DEBUG.ASSERT)
465
- )
447
+ block.unshift(temp, identity(DEBUG.LOG), identity(DEBUG.ASSERT))
466
448
  return compile(ast)
467
449
  }