Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 関数同士の比較の実装 #537

Merged
merged 4 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **Breaking Change** パースの都合によりmatch文の構文を変更。パターンの前に`case`キーワードが必要となり、`*`は`default`に変更。
- **Breaking Change** 多くの予約語を追加。これまで変数名等に使えていた名前に影響が出る可能性があります。
- **Breaking Change** 配列及び関数の引数において、空白区切りが使用できなくなりました。`,`または改行が必要です。
- **Breaking Change** 関数同士の比較の実装
- **Breaking Change** `+`や`!`などの演算子の優先順位に変更があります。新しい順序は[syntax.md](docs/syntax.md#%E6%BC%94%E7%AE%97%E5%AD%90)を参照して下さい。
- **Breaking Change** 組み込み関数`Num:to_hex`は組み込みプロパティ`num#to_hex`に移動しました。

Expand Down
1 change: 1 addition & 0 deletions src/interpreter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function isArray(val: Value): val is VArr {
}

export function eq(a: Value, b: Value): boolean {
if (a.type === 'fn' && b.type === 'fn') return a.native && b.native ? a.native === b.native : a === b;
if (a.type === 'fn' || b.type === 'fn') return false;
if (a.type === 'null' && b.type === 'null') return true;
if (a.type === 'null' || b.type === 'null') return false;
Expand Down
10 changes: 10 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ describe('ops', () => {
test.concurrent('==', async () => {
eq(await exe('<: (1 == 1)'), BOOL(true));
eq(await exe('<: (1 == 2)'), BOOL(false));
eq(await exe('<: (Core:type == Core:type)'), BOOL(true));
eq(await exe('<: (Core:type == Core:gt)'), BOOL(false));
eq(await exe('<: (@(){} == @(){})'), BOOL(false));
eq(await exe('<: (Core:eq == @(){})'), BOOL(false));
eq(await exe(`
let f = @(){}
let g = f

<: (f == g)
`), BOOL(true));
});

test.concurrent('!=', async () => {
Expand Down
Loading