Skip to content

Commit

Permalink
[builtin] add @ as prefix to all builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 5, 2023
1 parent acb8b4f commit 4f8f3d6
Show file tree
Hide file tree
Showing 97 changed files with 195 additions and 197 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[builtin] add `@` as prefix to all builtins
[builtin] remove `isPrivate` from Definition
[builtin] update readme -- add `@` as prefix to all builtins

# articles

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { ComposeOptions } from "../compose/compose"
import { Env } from "../env"
import { Mod } from "../mod"
import { define } from "../mod/define"

export function defineOperatorPrivate(
export function defineBuiltinOperator(
mod: Mod,
name: string,
options: {
compose: (env: Env, options: ComposeOptions) => void
},
): void {
define(mod, name, {
mod.builtins.set(name, {
"@type": "Definition",
"@kind": "OperatorDefinition",
mod,
name,
compose: options.compose,
isPrivate: true,
})
}
14 changes: 7 additions & 7 deletions src/lang/builtins/defineBuiltinOperators.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Mod } from "../mod"
import * as Type from "./Type"
import * as connect from "./connect"
import { defineOperatorPrivate } from "./defineOperatorPrivate"
import { defineBuiltinOperator } from "./defineBuiltinOperator"
import * as inspect from "./inspect"
import * as rot from "./rot"
import * as run from "./run"
import * as swap from "./swap"

export function defineBuiltinOperators(mod: Mod): void {
defineOperatorPrivate(mod, "swap", swap)
defineOperatorPrivate(mod, "rot", rot)
defineOperatorPrivate(mod, "connect", connect)
defineOperatorPrivate(mod, "inspect", inspect)
defineOperatorPrivate(mod, "run", run)
defineOperatorPrivate(mod, "Type", Type)
defineBuiltinOperator(mod, "swap", swap)
defineBuiltinOperator(mod, "rot", rot)
defineBuiltinOperator(mod, "connect", connect)
defineBuiltinOperator(mod, "inspect", inspect)
defineBuiltinOperator(mod, "run", run)
defineBuiltinOperator(mod, "Type", Type)
}
2 changes: 1 addition & 1 deletion src/lang/present/presentNodeAsNet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { presentNodeAsNet } from "./presentNodeAsNet"
test("presentNodeAsNet", async () => {
const text = `
type Nat -- Type end
type Nat -- @Type end
node add
Nat :target!
Expand Down
2 changes: 1 addition & 1 deletion src/lang/present/presentRuleAsNets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { presentRuleAsNets } from "./presentRuleAsNets"
test("presentRuleAsNets", async () => {
const text = `
type Nat -- Type end
type Nat -- @Type end
node zero
------
Expand Down
2 changes: 1 addition & 1 deletion src/lang/present/presentWordAsEnv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { presentWordAsEnv } from "./presentWordAsEnv"
test("presentWordAsEnv", async () => {
const text = `
type Nat -- Type end
type Nat -- @Type end
node zero
------
Expand Down
4 changes: 2 additions & 2 deletions tests/builtin/connect-args.error.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

sole connect
sole @connect
12 changes: 6 additions & 6 deletions tests/builtin/connect-args.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

[compose] I fail compose word.

word: connect
word: @connect

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole connect
4 |sole @connect
5 |

[Compose.execute] I fail to compose word.

word: connect
word: @connect

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole connect
4 |sole @connect
5 |
2 changes: 1 addition & 1 deletion tests/builtin/inspect-args.error.i
Original file line number Diff line number Diff line change
@@ -1 +1 @@
inspect
@inspect
8 changes: 4 additions & 4 deletions tests/builtin/inspect-args.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

[compose] I fail compose word.

word: inspect
word: @inspect

1 |inspect
1 |@inspect
2 |

[Compose.execute] I fail to compose word.

word: inspect
word: @inspect

1 |inspect
1 |@inspect
2 |
4 changes: 2 additions & 2 deletions tests/builtin/rot-args.error.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

sole sole rot
sole sole @rot
12 changes: 6 additions & 6 deletions tests/builtin/rot-args.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

[compose] I fail compose word.

word: rot
word: @rot

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole sole rot
4 |sole sole @rot
5 |

[Compose.execute] I fail to compose word.

word: rot
word: @rot

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole sole rot
4 |sole sole @rot
5 |
6 changes: 3 additions & 3 deletions tests/builtin/run-only-top-port.i
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ require "../datatype/Nat.i"

one one add
one one add
run inspect
swap inspect
run inspect
@run @inspect
@swap @inspect
@run @inspect
4 changes: 2 additions & 2 deletions tests/builtin/swap-args.error.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

sole swap
sole @swap
12 changes: 6 additions & 6 deletions tests/builtin/swap-args.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

[compose] I fail compose word.

word: swap
word: @swap

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole swap
4 |sole @swap
5 |

[Compose.execute] I fail to compose word.

word: swap
word: @swap

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole swap
4 |sole @swap
5 |
4 changes: 2 additions & 2 deletions tests/checking/begin-sign.error.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

sole sole connect
sole sole @connect
12 changes: 6 additions & 6 deletions tests/checking/begin-sign.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

[compose] I fail compose word.

word: connect
word: @connect

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole sole connect
4 |sole sole @connect
5 |

[Compose.execute] I fail to compose word.

word: connect
word: @connect

1 |type Trivial -- Type end
1 |type Trivial -- @Type end
2 |node sole -- Trivial :value! end
3 |
4 |sole sole connect
4 |sole sole @connect
5 |
4 changes: 2 additions & 2 deletions tests/checking/begin-type-nested.error.i
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

type List Type -- Type end
type List @Type -- @Type end

node null
--------
Expand Down
4 changes: 2 additions & 2 deletions tests/checking/begin-type.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

sole add1
4 changes: 2 additions & 2 deletions tests/checking/begin-type.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

word: add1

5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |sole add1
Expand All @@ -17,7 +17,7 @@

word: add1

5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |sole add1
Expand Down
4 changes: 2 additions & 2 deletions tests/checking/check-input-type.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

check
Expand Down
2 changes: 1 addition & 1 deletion tests/checking/check-input-type.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[Check.execute] I fail to check.

4 |
5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |check
Expand Down
4 changes: 2 additions & 2 deletions tests/checking/claim-input-arity-extra.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

claim add2 Nat Nat -- Nat end
Expand Down
2 changes: 1 addition & 1 deletion tests/checking/claim-input-arity-extra.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

word: add2

5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |claim add2 Nat Nat -- Nat end
Expand Down
4 changes: 2 additions & 2 deletions tests/checking/claim-input-type.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

claim add2 Trivial -- Nat end
Expand Down
2 changes: 1 addition & 1 deletion tests/checking/claim-input-type.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

word: add2

5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |claim add2 Trivial -- Nat end
Expand Down
4 changes: 2 additions & 2 deletions tests/checking/claim-output-arity-extra.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

claim add2 Nat -- Nat Nat end
Expand Down
2 changes: 1 addition & 1 deletion tests/checking/claim-output-arity-extra.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

word: add2

5 |type Trivial -- Type end
5 |type Trivial -- @Type end
6 |node sole -- Trivial :value! end
7 |
8 |claim add2 Nat -- Nat Nat end
Expand Down
2 changes: 1 addition & 1 deletion tests/checking/claim-output-arity-lack.error.i
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
claim swapswap 'A 'B -- 'B end
define swapswap swap swap end
define swapswap @swap @swap end
2 changes: 1 addition & 1 deletion tests/checking/claim-output-arity-lack.error.i.err
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
word: swapswap

1 |claim swapswap 'A 'B -- 'B end
2 |define swapswap swap swap end
2 |define swapswap @swap @swap end
3 |
4 changes: 2 additions & 2 deletions tests/checking/claim-output-type.error.i
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type Nat -- Type end
type Nat -- @Type end
node zero -- Nat :value! end
node add1 Nat :prev -- Nat :value! end

type Trivial -- Type end
type Trivial -- @Type end
node sole -- Trivial :value! end

claim add2 Nat -- Trivial end
Expand Down
Loading

0 comments on commit 4f8f3d6

Please sign in to comment.