fez-lisp 1.3.4 → 1.3.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/interpreter.js +16 -10
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.3.4",
5
+ "version": "1.3.6",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
@@ -147,20 +147,26 @@ export const keywords = {
147
147
  return a % b
148
148
  },
149
149
  [KEYWORDS.BITWISE_AND]: (args, env) => {
150
- if (args.length < 2)
150
+ if (args.length !== 2)
151
151
  throw new RangeError(
152
152
  `Invalid number of arguments to (${
153
153
  KEYWORDS.BITWISE_AND
154
154
  }) (= 2 required). (${KEYWORDS.BITWISE_AND} ${stringifyArgs(args)})`
155
155
  )
156
- const operands = args.map((a) => evaluate(a, env))
157
- if (operands.some((x) => typeof x !== 'number'))
156
+ if (typeof a !== 'number')
157
+ throw new TypeError(
158
+ `First arguments of (${KEYWORDS.BITWISE_AND}) is not a (${
159
+ RUNTIME_TYPES.NUMBER
160
+ }) (${KEYWORDS.BITWISE_AND} ${stringifyArgs(args)})`
161
+ )
162
+ const b = evaluate(args[1], env)
163
+ if (typeof b !== 'number')
158
164
  throw new TypeError(
159
- `Not all arguments of (${KEYWORDS.BITWISE_AND}) are ${
165
+ `Second arguments of (${KEYWORDS.BITWISE_AND}) is not a (${
160
166
  RUNTIME_TYPES.NUMBER
161
- } (${KEYWORDS.BITWISE_AND} ${stringifyArgs(args)})`
167
+ }) (${KEYWORDS.BITWISE_AND} ${stringifyArgs(args)})`
162
168
  )
163
- return operands.reduce((acc, x) => acc & x)
169
+ return a & b
164
170
  },
165
171
  [KEYWORDS.BITWISE_NOT]: (args, env) => {
166
172
  if (args.length !== 1)
@@ -393,7 +399,7 @@ export const keywords = {
393
399
  ? evaluate(args[1], env)
394
400
  : args.length === 3
395
401
  ? evaluate(args[2], env)
396
- : 0
402
+ : FALSE
397
403
  },
398
404
  [KEYWORDS.NOT]: (args, env) => {
399
405
  if (args.length !== 1)
@@ -547,7 +553,7 @@ export const keywords = {
547
553
  KEYWORDS.OR
548
554
  } ${stringifyArgs(args)})`
549
555
  )
550
- if (!a) return 0
556
+ if (!a) return FALSE
551
557
  const b = evaluate(args[1], env)
552
558
  if (b !== FALSE && b !== TRUE)
553
559
  throw new TypeError(
@@ -571,7 +577,7 @@ export const keywords = {
571
577
  KEYWORDS.OR
572
578
  } ${stringifyArgs(args)})`
573
579
  )
574
- if (a) return 1
580
+ if (a) return TRUE
575
581
  const b = evaluate(args[1], env)
576
582
  if (b !== FALSE && b !== TRUE)
577
583
  throw new TypeError(
@@ -668,7 +674,7 @@ export const keywords = {
668
674
  KEYWORDS.BLOCK
669
675
  } ${stringifyArgs(args)})`
670
676
  )
671
- return args.reduce((_, x) => evaluate(x, env), 0)
677
+ return args.reduce((_, x) => evaluate(x, env), FALSE)
672
678
  },
673
679
  [KEYWORDS.IS_ATOM]: (args, env) => {
674
680
  if (args.length !== 1)