From f02ef2760c05976eef80c0bf0e866a5778e877d6 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Mon, 11 Mar 2024 14:48:40 +0800 Subject: [PATCH] set nya as 0 --- .gitignore | 1 + README.md | 2 +- elementary.go | 3 +++ eval.go | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1853290..900d03c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +main.wasm diff --git a/README.md b/README.md index 57bfb21..8642175 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ sada * `da` True in boolean * `nye` False in boolean -* `nya` null, nil +* `nya` null, nil, 0 * `unu` one, 1 * `du` two, 2 * `unudu` three, 3 diff --git a/elementary.go b/elementary.go index f796c97..46322bb 100644 --- a/elementary.go +++ b/elementary.go @@ -94,6 +94,9 @@ func truthExpr(t bool) *Expr { } func (c *Context) getNumber(expr *Expr) int { + if expr.isNya() { + return 0 + } if !expr.isNumber() { errorf("expect number; got %v", expr) } diff --git a/eval.go b/eval.go index 49a3829..0729035 100644 --- a/eval.go +++ b/eval.go @@ -344,6 +344,10 @@ func (e *Expr) isTrue() bool { return e != nil && e.sada == tokDa } +func (e *Expr) isNya() bool { + return e == nil || e.sada == tokNya +} + func (e *Expr) length() int { if e == nil { return 0