From 9ce53480b3cc3f85e16fe9cbe4eb3d8df4f6dbdb Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Tue, 22 Feb 2022 11:15:02 +0000 Subject: Also use lexical scoping for operators --- apl9.h | 1 + eval.c | 1 + lexer.c | 1 + 3 files changed, 3 insertions(+) diff --git a/apl9.h b/apl9.h index 2cf0069..d8afcb1 100644 --- a/apl9.h +++ b/apl9.h @@ -133,6 +133,7 @@ struct Operator int code; Rune *dop; }; + DfnFrame *scope; Datum *left; Datum *right; }; diff --git a/eval.c b/eval.c index aa74698..58a745b 100644 --- a/eval.c +++ b/eval.c @@ -336,6 +336,7 @@ monadop(Datum *left, Datum *right) result->func.operator.left = left; incdatumref(left); result->func.left = nil; + result->func.scope = right->operator.scope; return result; } diff --git a/lexer.c b/lexer.c index 93fdb62..974d66e 100644 --- a/lexer.c +++ b/lexer.c @@ -124,6 +124,7 @@ lexline(InputStream *input, int toplevel) stmt->toks[stmt->ntoks]->operator.type = OperatortypeDop; stmt->toks[stmt->ntoks]->operator.dyadic = oplevel == 2; stmt->toks[stmt->ntoks]->operator.dop = runestrdup(buf); + stmt->toks[stmt->ntoks]->operator.scope = getcurrentdfn(); } }else if(peek == '('){ int unclosed = 1; -- cgit v1.2.3