From 4a345598d93df9792995cded766b70972dfaec8d Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Wed, 13 Sep 2023 09:30:47 +0800 Subject: [PATCH] fix error report `who` of built-in functions --- TODO.md | 2 +- src/lang/builtins/apply.ts | 0 src/lang/builtins/connect.ts | 8 ++++---- src/lang/builtins/inspect.ts | 2 +- src/lang/builtins/rot.ts | 8 +++----- src/lang/builtins/run.ts | 4 ++-- src/lang/builtins/swap.ts | 6 ++---- 7 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 src/lang/builtins/apply.ts diff --git a/TODO.md b/TODO.md index 72dfff55..cd9999a3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ `@apply` as built-in to apply a node -`@ports` as built-in to spread ports of a node +`@spread_ports` as built-in to spread ports of a node remove syntax of rearrange update docs about using `@ports` to do rearrange diff --git a/src/lang/builtins/apply.ts b/src/lang/builtins/apply.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/lang/builtins/connect.ts b/src/lang/builtins/connect.ts index d705b27e..4b9c5a41 100644 --- a/src/lang/builtins/connect.ts +++ b/src/lang/builtins/connect.ts @@ -9,14 +9,14 @@ export function compose(env: Env, options: ComposeOptions): void { if (first === undefined) { throw new Error( - [`[connect (builtin)] I expect first value on the stack.`].join("\n"), + [`[@connect] I expect first value on the stack.`].join("\n"), ) } if (first["@kind"] !== "Port") { throw new Error( [ - `[connect (builtin)] I expect the first value on the stack to be a Port.`, + `[@connect] I expect the first value on the stack to be a Port.`, ``, ` first: ${formatValue(first)}`, ].join("\n"), @@ -28,7 +28,7 @@ export function compose(env: Env, options: ComposeOptions): void { if (second === undefined) { throw new Error( [ - `[connect (builtin)] I expect a second value on the stack.`, + `[@connect] I expect a second value on the stack.`, ``, ` first: ${formatValue(first)}`, ].join("\n"), @@ -38,7 +38,7 @@ export function compose(env: Env, options: ComposeOptions): void { if (second["@kind"] !== "Port") { throw new Error( [ - `[connect (builtin)] I expect the second value on the stack to be a Port.`, + `[@connect] I expect the second value on the stack to be a Port.`, ``, ` first: ${formatValue(first)}`, ` second: ${formatValue(first)}`, diff --git a/src/lang/builtins/inspect.ts b/src/lang/builtins/inspect.ts index 18e27a72..d17c195a 100644 --- a/src/lang/builtins/inspect.ts +++ b/src/lang/builtins/inspect.ts @@ -7,7 +7,7 @@ import { formatValue } from "../value/formatValue" export function compose(env: Env): void { const value = env.stack[env.stack.length - 1] if (value === undefined) { - throw new Error(`[inspect (builtin)] I expect a value on the stack.`) + throw new Error(`[@inspect] I expect a value on the stack.`) } if (value["@kind"] === "Port") { diff --git a/src/lang/builtins/rot.ts b/src/lang/builtins/rot.ts index 8e6d6313..729c845b 100644 --- a/src/lang/builtins/rot.ts +++ b/src/lang/builtins/rot.ts @@ -5,9 +5,7 @@ export function compose(env: Env): void { const first = env.stack.pop() if (first === undefined) { - throw new Error( - [`[rot (builtin)] I expect first value on the stack.`].join("\n"), - ) + throw new Error([`[@rot] I expect first value on the stack.`].join("\n")) } const second = env.stack.pop() @@ -15,7 +13,7 @@ export function compose(env: Env): void { if (second === undefined) { throw new Error( [ - `[rot (builtin)] I expect a second value on the stack.`, + `[@rot] I expect a second value on the stack.`, ``, ` first: ${formatValue(first)}`, ].join("\n"), @@ -27,7 +25,7 @@ export function compose(env: Env): void { if (third === undefined) { throw new Error( [ - `[rot (builtin)] I expect a third value on the stack.`, + `[@rot] I expect a third value on the stack.`, ``, ` first: ${formatValue(first)}`, ` second: ${formatValue(second)}`, diff --git a/src/lang/builtins/run.ts b/src/lang/builtins/run.ts index ae077dc0..fb04bb1c 100644 --- a/src/lang/builtins/run.ts +++ b/src/lang/builtins/run.ts @@ -5,13 +5,13 @@ import { formatValue } from "../value/formatValue" export function compose(env: Env): void { const port = env.stack.pop() if (port === undefined) { - throw new Error(`[run] I expect a top value on the stack.`) + throw new Error(`[@run] I expect a top value on the stack.`) } if (port["@kind"] !== "Port") { throw new Error( [ - `[run] I expect the top value on the stack to be a Port.`, + `[@run] I expect the top value on the stack to be a Port.`, ``, ` value: ${formatValue(port)}`, ].join("\n"), diff --git a/src/lang/builtins/swap.ts b/src/lang/builtins/swap.ts index f22e8683..775ad797 100644 --- a/src/lang/builtins/swap.ts +++ b/src/lang/builtins/swap.ts @@ -5,9 +5,7 @@ export function compose(env: Env): void { const first = env.stack.pop() if (first === undefined) { - throw new Error( - [`[swap (builtin)] I expect first value on the stack.`].join("\n"), - ) + throw new Error([`[@swap] I expect first value on the stack.`].join("\n")) } const second = env.stack.pop() @@ -15,7 +13,7 @@ export function compose(env: Env): void { if (second === undefined) { throw new Error( [ - `[swap (builtin)] I expect a second value on the stack.`, + `[@swap] I expect a second value on the stack.`, ``, ` first: ${formatValue(first)}`, ].join("\n"),