From eb8e19f2964a2b0803d644c4cc7e15a8201cd46f Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 24 Jan 2022 00:57:08 +0000 Subject: =?UTF-8?q?Special=20case=20assignment=20to=20allow=20assigning=20?= =?UTF-8?q?to=20=E2=8D=BA=20if=20unset,=20and=20throw=20syntax=20error=20o?= =?UTF-8?q?n=20assignment=20to=20=E2=8D=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eval.c | 7 ++++++- lexer.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/eval.c b/eval.c index ee0de84..658dde8 100644 --- a/eval.c +++ b/eval.c @@ -225,7 +225,11 @@ nameis(Datum left, Datum right) Datum assign(Datum left, Datum right) { - if(left.symbol->setfn != nil) + if(runestrcmp(left.symbol->name, L"⍵") == 0) + throwerror(nil, ESyntax); + else if(runestrcmp(left.symbol->name, L"⍺") == 0 && !left.symbol->undefined) + goto end; + else if(left.symbol->setfn != nil) left.symbol->setfn(right); else{ if(left.symbol->undefined == 0 && left.symbol->value.tag == ArrayTag) @@ -237,6 +241,7 @@ assign(Datum left, Datum right) incref(right.array); /* for the binding */ } } +end: right.shy = 1; if(right.tag == ArrayTag) incref(right.array); /* for the returned array */ diff --git a/lexer.c b/lexer.c index 24d7e00..706db23 100644 --- a/lexer.c +++ b/lexer.c @@ -168,7 +168,7 @@ get_digits: }else if(runestrchr(L"⍺⍵", peek)){ Rune name[2] = {peek, 0}; stmt->toks[stmt->ntoks].tag = NameTag; - stmt->toks[stmt->ntoks].symbol = getsym(name, 0); + stmt->toks[stmt->ntoks].symbol = getsym(name, 1); }else if(isalpharune(peek)){ Rune buf[64]; Rune *p = buf; -- cgit v1.2.3