Skip to content

Commit

Permalink
fix error report who of built-in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 13, 2023
1 parent 155a5aa commit 4a34559
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Empty file added src/lang/builtins/apply.ts
Empty file.
8 changes: 4 additions & 4 deletions src/lang/builtins/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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)}`,
Expand Down
2 changes: 1 addition & 1 deletion src/lang/builtins/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
8 changes: 3 additions & 5 deletions src/lang/builtins/rot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ 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()

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"),
Expand All @@ -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)}`,
Expand Down
4 changes: 2 additions & 2 deletions src/lang/builtins/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 2 additions & 4 deletions src/lang/builtins/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ 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()

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"),
Expand Down

0 comments on commit 4a34559

Please sign in to comment.