summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apl9.h2
-rw-r--r--functions.c12
-rw-r--r--lexer.c14
-rw-r--r--operators.c20
4 files changed, 37 insertions, 11 deletions
diff --git a/apl9.h b/apl9.h
index aaa8d87..092c8ce 100644
--- a/apl9.h
+++ b/apl9.h
@@ -321,11 +321,13 @@ Array *fnSelfRef2(Array *, Array *);
/* Monadic operators from operators.c */
Array *opEach(Datum *, Array *, Array *);
Array *opSwitch(Datum *, Array *, Array *);
+Array *opSelfReference1(Datum *, Array *, Array *);
/* Dyadic operators from operators.c */
Array *opBind(Datum *, Datum *, Array *, Array *);
Array *opAtop(Datum *, Datum *, Array *, Array *);
Array *opOver(Datum *, Datum *, Array *, Array *);
+Array *opSelfReference2(Datum *, Datum *, Array *, Array *);
/* Dyadic functions from hybrids.c */
diff --git a/functions.c b/functions.c
index 094f0f4..bc71fb9 100644
--- a/functions.c
+++ b/functions.c
@@ -118,8 +118,6 @@ fndyad dyadfunctiondefs[] = {
fnSelfRef2, /* ∇ */
};
-DfnFrame *currentdfn; /* a stack of active dnf calls */
-
vlong gcd_int(vlong, vlong);
double gcd_float(double, double);
@@ -697,8 +695,9 @@ fnTranspose(Array *right)
Array *
fnSelfRef1(Array *right)
{
- if(currentdfn != nil)
- return rundfn(currentdfn->code, nil, right);
+ DfnFrame *dfn = getcurrentdfn();
+ if(dfn)
+ return rundfn(dfn->code, nil, right);
else{
throwerror(nil, ESyntax);
return nil;
@@ -1237,8 +1236,9 @@ fnReshape(Array *left, Array *right)
Array *
fnSelfRef2(Array *left, Array *right)
{
- if(currentdfn != nil)
- return rundfn(currentdfn->code, left, right);
+ DfnFrame *dfn = getcurrentdfn();
+ if(dfn)
+ return rundfn(dfn->code, left, right);
else{
throwerror(nil, ESyntax);
return nil;
diff --git a/lexer.c b/lexer.c
index 706db23..4ba0a30 100644
--- a/lexer.c
+++ b/lexer.c
@@ -92,9 +92,14 @@ lexline(InputStream *input, int toplevel)
stmt->ntoks--;
}else if(peek == '{'){
int unclosed = 1;
+ int oplevel = 0; /* 1 = monadic operator, 2 = dyadic operator */
Rune buf[MAX_LINE_LENGTH];
Rune *p = buf;
while(((peek = getrune(input)) != '}' || unclosed > 1) && !inputEOF(input)){
+ if(unclosed == 1 && peek == L'⍶' && oplevel == 0)
+ oplevel = 1;
+ else if(unclosed && peek == L'⍹')
+ oplevel = 2;
if(peek == '{')
unclosed++;
else if(peek == '}')
@@ -104,9 +109,12 @@ lexline(InputStream *input, int toplevel)
if(peek != '}')
goto syntax_error;
*p = 0;
- stmt->toks[stmt->ntoks].tag = FunctionTag;
- stmt->toks[stmt->ntoks].func.type = FunctypeDfn;
- stmt->toks[stmt->ntoks].func.dfn = runestrdup(buf);
+ if(oplevel == 0){
+ stmt->toks[stmt->ntoks].tag = FunctionTag;
+ stmt->toks[stmt->ntoks].func.type = FunctypeDfn;
+ stmt->toks[stmt->ntoks].func.dfn = runestrdup(buf);
+ }else
+ throwerror(L"Dops not implemented yet", ESyntax);
}else if(peek == '('){
int unclosed = 1;
Rune buf[MAX_LINE_LENGTH];
diff --git a/operators.c b/operators.c
index 05eed7d..c46e627 100644
--- a/operators.c
+++ b/operators.c
@@ -4,8 +4,8 @@
#include "apl9.h"
-Rune primmonopnames[] = L"¨⍨⌸⌶&";
-Rune primdyadopnames[] = L"⍣.∘⍤⍥@⍠⌺";
+Rune primmonopnames[] = L"¨⍨⌸⌶&∆";
+Rune primdyadopnames[] = L"⍣.∘⍤⍥@⍠⌺⍙";
opmonad monadoperatordefs[] = {
opEach, /* ¨ */
@@ -13,6 +13,7 @@ opmonad monadoperatordefs[] = {
0, /* ⌸ */
0, /* ⌶ */
0, /* & */
+ opSelfReference1, /* ∆ */
};
opdyad dyadoperatordefs[] = {
@@ -24,6 +25,7 @@ opdyad dyadoperatordefs[] = {
0, /* @ */
0, /* ⍠ */
0, /* ⌺ */
+ opSelfReference2, /* ⍙ */
};
/* Monadic operators */
@@ -74,6 +76,13 @@ opSwitch(Datum *lefto, Array *left, Array *right)
return nil;
}
+Array *
+opSelfReference1(Datum *lefto, Array *left, Array *right)
+{
+ throwerror(L"∆", ESyntax);
+ return nil;
+}
+
/* Dyadic operators */
Array *
opBind(Datum *lefto, Datum *righto, Array *left, Array *right)
@@ -160,4 +169,11 @@ opOver(Datum *lefto, Datum *righto, Array *left, Array *right)
freearray(tmp);
return res;
}
+}
+
+Array *
+opSelfReference2(Datum *lefto, Datum *righto, Array *left, Array *right)
+{
+ throwerror(L"⍙", ESyntax);
+ return nil;
} \ No newline at end of file