diff --git a/Makefile b/Makefile index 2e428d5..61e9379 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -OBJS= memory.o util.o error.o convert.o atom.o noun.o function.o verb.o \ - verb-scalar1.o verb-scalar2.o verb-atomic.o primitive.o adverb.o \ +OBJS= memory.o util.o error.o convert.o noun.o function.o verb.o \ + verb-scalar1.o verb-scalar2.o verb-atomic.o primitive.o adverb.o \ conjunction.o lexer.o parser.o test.o anicca.o CFLAGS=-ansi -pedantic -g3 @@ -23,7 +23,6 @@ verb-atomic.o: verb-atomic.c verb-atomic.h primitive.o: primitive.c primitive.h verb.h function.o: function.c function.h noun.o: noun.c noun.h util.h -atom.o: atom.c atom.h noun.h convert.o: convert.c convert.h error.o: error.c error.h util.o: util.c util.h diff --git a/adverb.c b/adverb.c index e1a2778..09a469c 100644 --- a/adverb.c +++ b/adverb.c @@ -13,35 +13,21 @@ MONAD(slash) { ASSERT(AT(y)&VERB, ERDOM); v = VAV(y); z = ADERV(CFWSL, insert, table, y, VLR(v), VMR(v), VRR(v)); - return z; + R z; } -DMONAD(insert) { - A z = tail(y); - I r, n = AN(y), k = n-2; - if (n==1) { return z; } - return z; -} +DMONAD(insert) { A z; R z; } -DDYAD(table) { - A z; - return z; -} +DDYAD(table) { A z; R z; } MONAD(tilde) { V *v; A z; ASSERT(AT(y)&VERB, ERDOM); v = VAV(y); z = ADERV(CTILDE, reflex, passive, y, VLR(v), VMR(v), VRR(v)); - return z; + R z; } -DMONAD(reflex) { DECL_F; - z = df2(y, y, f); - return z; -} +DMONAD(reflex) { DECL_F; z = df2(y, y, f); R z; } -DDYAD(passive) { DECL_F; - z = df2(y, x, f); - return z; -} +DDYAD(passive) { DECL_F; z = df2(y, x, f); R z; } diff --git a/anicca.c b/anicca.c index 013f2fa..0091bb6 100755 --- a/anicca.c +++ b/anicca.c @@ -16,7 +16,8 @@ #include "util.h" I main(I argc, C *argv[]) { + A y, z; a_init(); a_repl(" "); - return 0; + R 0; } diff --git a/anicca.h b/anicca.h index 2f84f02..77073ac 100755 --- a/anicca.h +++ b/anicca.h @@ -19,12 +19,12 @@ typedef double D; typedef void VO; typedef void* VP; -#define ZR(z) ((z).real) -#define ZI(z) ((z).imaginary) +#define ZR(z) ((z).re) +#define ZI(z) ((z).img) typedef struct _complex { - D real; - D imaginary; + D re; + D img; } Z; #define AT(a) ((a)->type) @@ -83,7 +83,7 @@ typedef A(*AF3)(A, A, A); #define DMONAD(name) A name(A y, A self) #define DDYAD(name) A name(A x, A y, A self) -A zero; A one; +A zero; A one; A zone; A mark; A lpar; A rpar; diff --git a/atom.c b/atom.c deleted file mode 100644 index 818935f..0000000 --- a/atom.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -/* -#include "anicca.h" -#include "noun.h" -#include "atom.h" - -ATOMFUNC(base) { - return 1; -} - -ATOMFUNC(pitime) { - return 1; -} - -ATOMFUNC(euler) { - return 1; -} - -ATOMFUNC(cmpx) { - return 1; -} - -ATOMFUNC(angr) { - return 1; -} - -ATOMFUNC(angd) { - return 1; -} - -ATOMFUNC(exp) { */ -/* D d = noun_dval(a); */ /* TODO: it could be an integer */ -/* DO(noun_ival(&b), d *= 10); */ /* TODO: negative exponents */ -/* a->t = FLT; - a->val.d = d; - return 1; -} -*/ diff --git a/atom.h b/atom.h deleted file mode 100644 index 80457b1..0000000 --- a/atom.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _ATOM_H -#define _ATOM_H - -/* - atom functions - input: - a: left parameter - b: right parameter - output: - a: resulting noun - returns 1 on success - */ -#define ATOMFUNC(name) B a ## name(N *a, N b) - -ATOMFUNC(base); -ATOMFUNC(pitime); -ATOMFUNC(euler); -ATOMFUNC(cmpx); -ATOMFUNC(ngr); -ATOMFUNC(ngd); -ATOMFUNC(exp); - -#endif diff --git a/conjunction.c b/conjunction.c index edd6259..ff96a8b 100644 --- a/conjunction.c +++ b/conjunction.c @@ -18,27 +18,16 @@ DYAD(amper) { v = VAV(y); z = CDERV(CAMPR, compose, compose2, x, y, VLR(v), VMR(v), VRR(v)); } - return z; + R z; } -DMONAD(bond) { DECL_FG; - z = AT(f)&NOUN ? df2(f, y, g) : df2(y, g, f); - return z; -} +DMONAD(bond) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(y,g,f); R z; } -DDYAD(bond2) { DECL_FG; - return z; -} +DDYAD(bond2) { DECL_FG; R z; } -DMONAD(compose) { DECL_FG; - z = df1(df1(y, g), f); - return z; -} +DMONAD(compose) { DECL_FG; z = df1(df1(y,g),f); R z; } -DDYAD(compose2) { DECL_FG; - z = df2(df1(x, g), df1(y, g), f); - return z; -} +DDYAD(compose2) { DECL_FG; z = df2(df1(x,g), df1(y,g),f); R z; } DYAD(atsign) { V *v; A z; @@ -46,62 +35,49 @@ DYAD(atsign) { v = VAV(y); z = CDERV(CAT, atop, atop2, x, y, VLR(v), VMR(v), VRR(v)); } - return z; + R z; } -DMONAD(atop) { - A z; - z = compose(y, self); - return z; -} +DMONAD(atop) { A z; z = compose(y,self); R z; } -DDYAD(atop2) { DECL_FG; - z = df1(df2(x, y, g), f); - return z; -} +DDYAD(atop2) { DECL_FG; z = df1(df2(x,y,g),f); R z; } -DMONAD(hook) { DECL_FG; - z = df2(y, df1(y, g), f); - return z; -} +DMONAD(hook) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(y,df1(y,g),f); R z; } -DDYAD(hook2) { DECL_FG; - z = df2(x, df1(y, g), f); - return z; -} +DDYAD(hook2) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(x,df1(y,g),f); R z; } DMONAD(forrk) { DECL_FGH; z = (AT(f)&VERB && VID(VAV(f))==CCAP) ? df1(df1(y, h), g) : AT(f)&NOUN ? df2(f, df1(y, h), g) : df2(df1(y, f), df1(y, h), g); - return z; + R z; } DDYAD(forrk2) { DECL_FGH; z = (AT(f)&VERB && VID(VAV(f))==CCAP) ? df1(df2(x, y, h), g) : AT(f)&NOUN ? df2(f, df2(x, y, h), g) : df2(df2(x, y, f), df2(x, y, h), g); - return z; + R z; } DYAD(cartcol) { V *v; A z; I xt = AT(x), yt = AT(y); ASSERT(xt&VERB && yt&INT, ERDOM); v = VAV(xt&VERB ? x : y); - z = CDERV(CPOWR, power, power2, x, y, VLR(v), VMR(v), VRR(v)); - return z; + z = CDERV(CPOWR, cpower, cpower2, x, y, VLR(v), VMR(v), VRR(v)); + R z; } -DMONAD(power) { DECL_FG; +DMONAD(cpower) { DECL_FG; I n = *IAV(g); A temp; DO(n, temp = y; y = df1(temp, f); a_free(temp)); z = y; - return z; + R z; } -DDYAD(power2) { DECL_FG; +DDYAD(cpower2) { DECL_FG; I n = *IAV(g); A temp; DO(n, temp = y; y = df2(x, temp, f); a_free(temp)); z = y; - return z; + R z; } diff --git a/conjunction.h b/conjunction.h index f505039..9fc8a95 100644 --- a/conjunction.h +++ b/conjunction.h @@ -18,8 +18,8 @@ DDYAD(atop2); DMONAD(hook); DDYAD(hook2); DYAD(cartcol); -DMONAD(power); -DDYAD(power2); +DMONAD(cpower); +DDYAD(cpower2); DMONAD(forrk); DDYAD(forrk2); diff --git a/convert.c b/convert.c index b6e3923..e3bbe9e 100644 --- a/convert.c +++ b/convert.c @@ -5,16 +5,22 @@ #include "memory.h" #include "convert.h" -B cbTi(I n, I *iv, B *bv) { DO(n, iv[i] = (I)bv[i]); R 1; } -B cbTd(I n, D *dv, B *bv) { DO(n, dv[i] = (D)bv[i]); R 1; } -B ciTd(I n, D *dv, I *iv) { DO(n, dv[i] = (D)iv[i]); R 1; } +B cbTi(I n, I *iv, B *bv) { DO(n, iv[i]=(I)bv[i]); R 1; } +B cbTd(I n, D *dv, B *bv) { DO(n, dv[i]=(D)bv[i]); R 1; } +B cbTz(I n, Z *zv, B *bv) { DO(n, ZR(zv[i])=(D)bv[i]; ZI(zv[i])=0); R 1; } +B ciTd(I n, D *dv, I *iv) { DO(n, dv[i]=(D)iv[i]); R 1; } +B ciTz(I n, Z *zv, I *iv) { DO(n, ZR(zv[i])=(D)iv[i]; ZI(zv[i])=0); R 1; } +B cdTz(I n, Z *zv, D *dv) { DO(n, ZR(zv[i])=dv[i]; ZI(zv[i])=0); R 1; } B aconv(I cv, I n, VP z, VP y) { - B *bv; I *iv; D *dv; + B *bv; I *iv; D *dv; Z *zv; switch(cv) { case BtI: bv=(B*)y; iv=(I*)z; cbTi(n,iv,bv); break; case BtD: bv=(B*)y; dv=(D*)z; cbTd(n,dv,bv); break; + case BtZ: bv=(B*)y; zv=(Z*)z; cbTz(n,zv,bv); break; case ItD: iv=(I*)y; dv=(D*)z; ciTd(n,dv,iv); break; + case ItZ: iv=(I*)y; zv=(Z*)z; ciTz(n,zv,iv); break; + case DtZ: dv=(D*)y; zv=(Z*)z; cdTz(n,zv,dv); break; } R 1; } diff --git a/convert.h b/convert.h index 357c411..81d3a5f 100644 --- a/convert.h +++ b/convert.h @@ -27,7 +27,10 @@ */ B cbTi(I n, I *iv, B *bv); B cbTd(I n, D *dv, B *bv); +B cbTz(I n, Z *zv, B *bv); B ciTd(I n, D *dv, I *iv); +B ciTz(I n, Z *zv, I *iv); +B cdTz(I n, Z *zv, D *dv); B aconv(I cv, I n, VP z, VP y); A conv(I t, A y); diff --git a/function.c b/function.c index 8044699..9f3b552 100644 --- a/function.c +++ b/function.c @@ -9,23 +9,23 @@ DMONAD(df1) { V *v = VAV(self); A z = VF(v)&&VDF1(v) ? v->df1(y, self) : v->f1(y); - return z; + R z; } DDYAD(df2) { V *v = VAV(self); A z = VF(v)&&VDF2(v) ? v->df2(x, y, self) : v->f2(x, y); - return z; + R z; } DMONAD(dhk) { V *v = VAV(y); - return ddef(CHOOK,VERB,hook,hook2,y,self,NULL,VLR(v),VMR(v),VRR(v),0); + R ddef(CHOOK,VERB,hook,hook2,y,self,NULL,VLR(v),VMR(v),VRR(v),0); } DDYAD(dfrk) { V *v = VAV(x); - return ddef(CFORK,VERB,forrk,forrk2,x,y,self,VLR(v),VMR(v),VRR(v),0); + R ddef(CFORK,VERB,forrk,forrk2,x,y,self,VLR(v),VMR(v),VRR(v),0); } /* @@ -68,7 +68,7 @@ A sex1(A y, I zt, SF f1) { C *yv = CAV(y), *zv = CAV(z); zv -= zk; yv -= k; DO(yn, f1(zv+=zk, yv+=k)); - return z; + R z; } /* @@ -89,7 +89,7 @@ A sex2(A x, A y, I zt, SF f2) { A z = ga(zt, b ? yr : xr, m*n, b ? ys : xs); C *xv = CAV(x), *yv = CAV(y), *zv = CAV(z); ado(b, m, n, k, zk, zv, xv, yv, f2); - return z; + R z; } A fdef(UC id, I t, AF1 f1, AF2 f2, A f, A g, A h, I lr, I mr, I rr, I inv) { @@ -101,12 +101,12 @@ A fdef(UC id, I t, AF1 f1, AF2 f2, A f, A g, A h, I lr, I mr, I rr, I inv) { VLR(v) = lr; VMR(v) = mr; VRR(v) = rr; VIR(v) = inv; VID(v) = id; - return z; + R z; } A ddef(UC id, I t, AF2 df1, AF3 df2, A f, A g, A h, I lr, I mr, I rr, I inv) { A z = fdef(id, t, NULL, NULL, f, g, h, lr, mr, rr, inv); V *v = VAV(z); VDF1(v) = df1; VDF2(v) = df2; - return z; + R z; } diff --git a/lexer.c b/lexer.c index b0f01f9..f52d809 100755 --- a/lexer.c +++ b/lexer.c @@ -20,10 +20,7 @@ input: Length of string, Pointer to string. output: Array of type string with length (n-2). */ -static A parse_literal(I n, C *s) { - A z = gstr(n-=2, s++); - R z; -} +static A parse_literal(I n, C *s) { A z = gstr(n-=2, ++s); R z; } #define DCOL 9 #define DROW 10 @@ -56,11 +53,8 @@ static MONAD(token_index) { A z = ga(INT, 1, n+n, NULL); v = IAV(z); - DO(n, - t = chartype[str[i]]; - pr = dfa[s][t]; - e = pr.effect; - sn = pr.new; + DO(n, t = chartype[str[i]]; pr = dfa[s][t]; + e = pr.effect; sn = pr.new; switch (e) { case EO: break; @@ -70,14 +64,12 @@ static MONAD(token_index) { case EV: { if (!vec) { v[k++] = j; v[k] = i-j; jv = j; } else { v[k] = i-jv; } - j = i; vec = 1; - break; + j = i; vec = 1; break; } case EZ: { if (!vec) { v[k++] = j; v[k] = i-j; jv = j; } else { v[k] = i-jv; } - j = -1; vec = 1; - break; + j = -1; vec = 1; break; } case ES: goto end; break; } @@ -86,9 +78,7 @@ static MONAD(token_index) { s = sn; ); end: - ra(z, INT, k); - AN(z) = k; - R z; + ra(z, INT, k); AN(z) = k; R z; } /* @@ -119,6 +109,5 @@ MONAD(tokens) { else { *av++ = v; } ); - DO(4, *av++ = mark); - R z; + DO(4, *av++ = mark); R z; } diff --git a/memory.c b/memory.c index d435547..d419716 100755 --- a/memory.c +++ b/memory.c @@ -8,11 +8,7 @@ #include "function.h" #include "memory.h" -VP a_malloc(I size) { - V *m = malloc(size); - ASSERT(m, ERALLOC); - return m; -} +VP a_malloc(I size) { V *m = malloc(size); ASSERT(m, ERALLOC); R m; } VO a_free(A y) { if (AN(y)>0) { free(AV(y)); if (AR(y)>0) { free(AS(y)); } } @@ -22,23 +18,32 @@ VO a_free(A y) { I ts(I type) { switch (type) { case BOOL: - case CHAR: return sizeof(C); break; - case INT: return sizeof(I); break; - case FLT: return sizeof(D); break; - case CMPX: return sizeof(Z); break; - case BOX: return sizeof(A); break; + case CHAR: R sizeof(C); break; + case INT: R sizeof(I); break; + case FLT: R sizeof(D); break; + case CMPX: R sizeof(Z); break; + case BOX: R sizeof(A); break; case ADV: case CONJ: - case VERB: return sizeof(V); break; + case VERB: R sizeof(V); break; } - return sizeof(int); + R sizeof(int); } -A schar(C c) { A z; z = ga(CHAR, 0, 1, NULL); *CAV(z) = c; R z; } +A schar(C c) { A z = ga(CHAR,0,1,NULL); *CAV(z) = c; R z; } + +A sbool(B b) { A z = ga(BOOL,0,1,NULL); *BAV(z) = b; R z; } -A sint(I i) { A z; z = ga(INT, 0, 1, NULL); *IAV(z) = i; R z; } +A sint(I i) { A z = ga(INT,0,1,NULL); *IAV(z) = i; R z; } -A sflt(D d) { A z; z = ga(FLT, 0, 1, NULL); *DAV(z) = d; R z; } +A sflt(D d) { A z = ga(FLT,0,1,NULL); *DAV(z) = d; R z; } + +A scmpx(D r, D i) { A z = ga(CMPX,0,1,NULL); Z *zv=ZAV(z); + zv->re=r; zv->img=i; + R z; +} + +A sbox(A y) { A z; z = ga(BOX,0,1,NULL); *AAV(z) = y; R z; } A ga(I t, I r, I n, I *s) { A z = (A)a_malloc(sizeof(struct _array)); @@ -50,7 +55,7 @@ A ga(I t, I r, I n, I *s) { A gstr(I n, const C *str) { A z; - ASSERT(n<=0,ERDOM); + ASSERT(n>0,ERDOM); if (n==1) { z = schar(*str); } else { z = ga(CHAR, 1, n, NULL); strncpy(CAV(z), str, n); } R z; @@ -87,6 +92,4 @@ A ca(A y) { R z; } -VO ra(A y, I t, I n) { - AN(y) = n; AV(y) = realloc(AV(y), ts(t)*n); -} +VO ra(A y, I t, I n) { AN(y) = n; AV(y) = realloc(AV(y), ts(t)*n); } diff --git a/memory.h b/memory.h index 23b23f0..c01e808 100755 --- a/memory.h +++ b/memory.h @@ -6,8 +6,11 @@ VO a_free(A); I ts(I t); A schar(C c); +A sbool(B b); A sint(I i); A sflt(D d); +A scmpx(D r, D i); +A sbox(A y); A gs(I t, I v); A ga(I t, I r, I n, I *s); diff --git a/noun.c b/noun.c index 987399e..41b19b5 100644 --- a/noun.c +++ b/noun.c @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -10,11 +12,9 @@ #include "convert.h" #include "util.h" #include "verb.h" -/*#include "atom.h"*/ #include "lexer.h" #include "noun.h" - #define NCOL 3 #define NROW 5 @@ -41,11 +41,8 @@ static A noun_index(I n, C *s) { ST pr; A z = ga(INT, 1, m, NULL); v = IAV(z); - DO(n, - t = nountype[s[i]]; - pr = noun[st][t]; - e = pr.effect; - st = pr.new; + DO(n, t = nountype[s[i]]; pr = noun[st][t]; + e = pr.effect; st = pr.new; switch (e) { case EO: break; @@ -55,55 +52,64 @@ static A noun_index(I n, C *s) { } ); end_noun: - ra(z, INT, k); - AN(z) = k; - R z; + ra(z, INT, k); AN(z) = k; R z; } -NPARSE(base) { - parse_pieul(n,s,y); - if (*s=='b') { parse_pieul(n,s,y); } +NPARSE(base) { C *s; + parse_pieul(n,sp,y); s=*sp; + if (*s=='b') { parse_pieul(n,sp,y); } R 1; } -NPARSE(pieul) { - parse_cmpx(n,s,y); - if (*s=='p') { parse_cmpx(n,s,y); } - else if (*s=='x') { parse_cmpx(n,s,y); } +NPARSE(pieul) {C *s=*sp, *e; I k; A p, q, x; + parse_cmpx(n,sp,y); e=*sp; + if (*e=='p') { parse_cmpx(n,sp,y); } + else if (*e=='x') { + e++; p=*y; *y=sbool(0); k=n-(I)(e-s); *sp=e; + ASSERT(parse_cmpx(k,sp,y),ERILLNUM); + q=*y; *y=times(p,expntl(q)); + } R 1; } -NPARSE(cmpx) { - parse_exp(n,s,y); - if (*s=='a') { s++; - if (*s=='d') { parse_exp(n,s,y); } - else if (*s=='r') { parse_exp(n,s,y); } +NPARSE(cmpx) { C *s=*sp, *e; I k; A p, q, x; + parse_exp(n,sp,y); e=*sp; + if (*e=='a') { + if (*e=='d') { parse_exp(n,sp,y); } + else if (*e=='r') { parse_exp(n,sp,y); } + } + else if (*e=='j') { + e++; p=*y; *y=sbool(0); k=n-(I)(e-s); *sp=e; + ASSERT(parse_exp(n,sp,y),ERILLNUM); + q=*y; *y=complex(p,q); } - else if (*s=='j') { parse_exp(n,s,y); } R 1; } -NPARSE(exp) { - parse_rat(n,s,y); - if (*s=='e') { - ASSERT(parse_rat(n,s++,y),ERILLNUM); +NPARSE(exp) { C *s=*sp, *e; I k; A p, q, x; + parse_rat(n,sp,y); e=*sp; + if (*e=='e') { + e++; p=*y; *y=sbool(0); k=n-(I)(e-s); *sp=e; + ASSERT(parse_rat(k,sp,y),ERILLNUM); + q=*y; *y=times(p,power(sint(10),q)); } R 1; } -NPARSE(rat) { - parse_num(n,s,y); - if (*s=='r') { parse_num(n,s,y); } +NPARSE(rat) { C *s=*sp; + parse_num(n,sp,y); + if (*s=='r') { parse_num(n,sp,y); } R 1; } NPARSE(num) { - C c = *s, *d=memchr(s,'.',n), *e; - I si = (*s==CUNDS) ? 1 : 0, iv; D dv; A w = *y; + C c=**sp, *s=*sp, *d=memchr(s,'.',n), *e; + I si=1, iv; D dv; A w = *y; + if (c==CUNDS) { si=-1; s++; } if (n==1&&(c==CZERO||c==CONE)) { *BAV(w)=c-CZERO; e=s+1; } - else if (d) { w=conv(FLT,w); dv=strtod(s,&e); *DAV(w)=si ? -(dv) : dv; } - else { w=conv(INT,w); iv=strtol(s,&e,10); *IAV(w)=si ? -(iv) : iv; } - *y=w; s=e; R 1; + else if (d) { w=conv(FLT,w); dv=a_strtod(n,s,&e); *DAV(w)=si*dv; } + else { w=conv(INT,w); iv=a_strtoi(n,s,&e); *IAV(w)=si*iv; } + *y=w; *sp=e; R 1; } A parse_noun(I n, C *s) { @@ -112,8 +118,8 @@ A parse_noun(I n, C *s) { I m=AN(y)/2, t=0, ak, at, j, wi, wl, zk, *indx=IAV(y), *iv; nouns = ga(BOX, 1, m, NULL); nv = AAV(nouns); DO(m, j=i+i; wi=indx[j]; wl=indx[j+1]; ws=&s[wi]; - atm = nv[i] = ga(BOOL, 0, 1, NULL); - ASSERT(parse_num(wl,ws,&atm),ERILLNUM); + atm = nv[i] = sbool(0); + ASSERT(parse_pieul(wl,&ws,&atm),ERILLNUM); t=MAX(at=AT(atm),t); nv[i]=atm; ); diff --git a/noun.h b/noun.h index 332bfa4..386f3cb 100644 --- a/noun.h +++ b/noun.h @@ -1,7 +1,7 @@ #ifndef _NOUN_H #define _NOUN_H -#define NPARSE(name) static B parse_ ## name(I n, C *s, A *y) +#define NPARSE(name) static B parse_ ## name(I n, C **sp, A *y) static A noun_index(I n, C *s); NPARSE(atom); diff --git a/parser.c b/parser.c index b147fcb..39c29fd 100644 --- a/parser.c +++ b/parser.c @@ -7,14 +7,14 @@ #include "function.h" #include "parser.h" -ACTION(monad) { return df1(stack[e], stack[b]); } -ACTION(dyad) { return df2(stack[b], stack[e], stack[b+1]); } -ACTION(adverb) { return df1(stack[b], stack[e]); } -ACTION(conjun) { return df2(stack[b], stack[e], stack[b+1]); } -ACTION(fork) { return dfrk(stack[b], stack[b+1], stack[e]); } -ACTION(bident) { return dhk(stack[b], stack[e]); } -ACTION(is) { A z; return z; } -ACTION(paren) { return stack[b+1]; } +ACTION(monad) { R df1(stack[e], stack[b]); } +ACTION(dyad) { R df2(stack[b], stack[e], stack[b+1]); } +ACTION(adverb) { R df1(stack[b], stack[e]); } +ACTION(conjun) { R df2(stack[b], stack[e], stack[b+1]); } +ACTION(fork) { R dfrk(stack[b],stack[b+1], stack[e]); } +ACTION(bident) { R dhk(stack[b], stack[e]); } +ACTION(is) { A z; R z; } +ACTION(paren) { R stack[b+1]; } #define CASES 9 @@ -64,7 +64,5 @@ A parse(A tokens) { /*printf("m: %d j: %d\n", m, j); println(tokens);*/ if (m>2) { a_signal(ERSYNTX); }; - z = stack[j]; - - return z; + z = stack[j]; R z; } diff --git a/primitive.c b/primitive.c index 6043684..8998548 100644 --- a/primitive.c +++ b/primitive.c @@ -42,18 +42,18 @@ UC verb_name(I n, C *s) { I i, j; switch (n) { - case 1: return *s; + case 1: R *s; case 2: { d = s[1]; i = d==CDOT ? 1 : d==CCOL ? 2 : 0; if (i > 0) { t = memchr(verbname[0], *s, BASE); j = t - verbname[0]; - return verbname[i][j]; + R verbname[i][j]; } } } - return *s; + R *s; } static UC primindx[256] = { @@ -98,7 +98,7 @@ static P primitives[NPRIM+1] = { /* 16 ; 59 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 17 < 60 */ {VERB, box, lthan, 0, 0, 0, 0}, /* 18 = 61 */ {VERB, NULL, equal, 0, 0, 0, 0}, - /* 19 > 62 */ {VERB, NULL, gthan, 0, 0, 0, 0}, + /* 19 > 62 */ {VERB, unbox, gthan, 0, 0, 0, 0}, /* 20 ? 63 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 21 @ 64 */ {CONJ, NULL, atsign, 0, 0, 0, 0}, /* 22 A. 65 */ {VERB, NULL, NULL, 0, 0, 0, 0}, @@ -113,7 +113,7 @@ static P primitives[NPRIM+1] = { /* 31 [ 91 */ {VERB, same, left, 0, 0, 0, 0}, /* 32 \ 92 */ {ADV, NULL, NULL, 0, 0, 0, 0}, /* 33 ] 93 */ {VERB, same, right, 0, 0, 0, 0}, - /* 34 ^ 94 */ {VERB, expntl, NULL, 0, 0, 0, 0}, + /* 34 ^ 94 */ {VERB, expntl, power, 0, 0, 0, 0}, /* 35 ` 96 */ {CONJ, NULL, NULL, 0, 0, 0, 0}, /* 36 a. 97 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 37 b. 98 */ {ADV, NULL, NULL, 0, 0, 0, 0}, @@ -121,7 +121,7 @@ static P primitives[NPRIM+1] = { /* 39 e. 101 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 40 f. 102 */ {ADV, NULL, NULL, 0, 0, 0, 0}, /* 41 i. 105 */ {VERB, iota, NULL, 0, 0, 0, 0}, - /* 42 j. 106 */ {VERB, NULL, NULL, 0, 0, 0, 0}, + /* 42 j. 106 */ {VERB, imaginary, complex, 0, 0, 0, 0}, /* 43 o. 111 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 44 p. 112 */ {VERB, NULL, NULL, 0, 0, 0, 0}, /* 45 q. 113 */ {VERB, NULL, NULL, 0, 0, 0, 0}, @@ -206,12 +206,11 @@ A primitive_lookup(UC id) { case NOUN: break; case ADV: case VERB: - case CONJ: return fdef(id, t, p->f1, p->f2, NULL, NULL, NULL, \ - p->lr, p->mr, p->rr, p->inv); - case LPAR: return lpar; - case RPAR: return rpar; - default: return mark; + case CONJ: R fdef(id,t,p->f1,p->f2,NULL,NULL,NULL,p->lr,p->mr,p->rr,p->inv); + case LPAR: R lpar; + case RPAR: R rpar; + default: R mark; } - return mark; + R mark; } diff --git a/test.c b/test.c index b86a98c..1fe947e 100644 --- a/test.c +++ b/test.c @@ -6,39 +6,39 @@ #include "util.h" B eq_shape(A x, A y) { - if (AR(x) != AR(y)) return 0; - if (AS(x) == AS(y)) return 1; - if (AS(x) == NULL || AS(y) == NULL) return 0; - DO(AR(x), if (AS(x)[i] != AS(y)[i]) return 0); + if (AR(x) != AR(y)) R 0; + if (AS(x) == AS(y)) R 1; + if (AS(x) == NULL || AS(y) == NULL) R 0; + DO(AR(x), if (AS(x)[i] != AS(y)[i]) R 0); - return 1; + R 1; } B eq(A x, A y) { - if (x == y) return 1; - if (x == NULL || y == NULL) return 0; + if (x == y) R 1; + if (x == NULL || y == NULL) R 0; if (AT(x) != AT(y) || AN(x) != AN(y) || !eq_shape(x, y)) - return 0; + R 0; /* TODO: make it work for rank > 1 */ NOUN_SWITCH(AT(x), DO(AN(x), B *xbv = AV(x); B *ybv = AV(y); - if (xbv[i] != ybv[i]) return 0), + if (xbv[i] != ybv[i]) R 0), DO(AN(x), C *xcv = AV(x); C *ycv = AV(y); - if (xcv[i] != ycv[i]) return 0), + if (xcv[i] != ycv[i]) R 0), DO(AN(x), I *xiv = AV(x); I *yiv = AV(y); - if (xiv[i] != yiv[i]) return 0), + if (xiv[i] != yiv[i]) R 0), DO(AN(x), D *xfv = AV(x); D *yfv = AV(y); - if (xfv[i] != yfv[i]) return 0), + if (xfv[i] != yfv[i]) R 0), DO(AN(x), Z *xzv = AV(x); Z *yzv = AV(y); if (ZR(xzv[i]) != ZR(yzv[i]) || - ZI(xzv[i]) != ZI(yzv[i])) return 0), + ZI(xzv[i]) != ZI(yzv[i])) R 0), DO(AN(x), A *xbv = AV(x); A *ybv = AV(y); - if (!eq(xbv[i], ybv[i])) return 0), - return 1, /* MARK, no value */ - return 1, /* LPAR, no value */ - return 1, /* RPAR, no value */ - return 0); /* unknown type, shouldn't happen */ - return 1; + if (!eq(xbv[i], ybv[i])) R 0), + R 1, /* MARK, no value */ + R 1, /* LPAR, no value */ + R 1, /* RPAR, no value */ + R 0); /* unknown type, shouldn't happen */ + R 1; } @@ -50,9 +50,9 @@ B run_test(const C *input, A expected) { println(z); printf(" expected: "); println(expected); - return 0; + R 0; } - return 1; + R 1; } VO testcases_init(VO) { diff --git a/util.c b/util.c index cc30af8..f595926 100644 --- a/util.c +++ b/util.c @@ -11,15 +11,18 @@ #include "util.h" VO print(A y) { - C *cv; I *iv; D *fv; V *vv; A *bv; + C *cv; I yn=AN(y), *iv; D *dv; Z *zv; V *vv; A *bv; - if (!y) { printf("NULL"); return; } + if (!y) { printf("NULL"); R; } switch (AT(y)) { - case BOOL: { cv = BAV(y); DO(AN(y), printf("%d ", (I)cv[i])); break; } - case CHAR: { cv = CAV(y); DO(AN(y), printf("%c", cv[i])); break; } - case INT: { iv = IAV(y); DO(AN(y), printf("%d ", iv[i])); break; } - case FLT: { fv = DAV(y); DO(AN(y), printf("%lf ", fv[i])); break; } + case BOOL: { cv=BAV(y); DO(yn, printf("%d ", (I)cv[i])); break; } + case CHAR: { cv=CAV(y); DO(yn, printf("%c", cv[i])); break; } + case INT: { iv=IAV(y); DO(yn, printf("%d ", iv[i])); break; } + case FLT: { dv=DAV(y); DO(yn, printf("%lf ",dv[i])); break; } + case CMPX: { + zv=ZAV(y); DO(yn, printf("%lfj%lf ",ZR(zv[i]),ZI(zv[i]))); break; + } /* TODO?: fancy line drawings */ case BOX: { bv = AAV(y); @@ -52,19 +55,32 @@ VO println(A y) { } VO a_init(VO) { - zero = sint(0); one = sint(1); + zero=sbool(0); one=sbool(1); zone=scmpx(0,1); mark = ga(MARK, 0, 0, NULL); lpar = ga(LPAR, 0, 0, NULL); rpar = ga(RPAR, 0, 0, NULL); } +I a_strtoi(I n, C *s, C **e) { I v=0, i; + for (i=0;isdigit(*s)&&(i?*/ /*4*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*@ABCDEFGHIJKLMNO*/ - /*5*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*PQRSTUVWXYZ[\]^_*/ + /*5*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0, /*PQRSTUVWXYZ[\]^_*/ /*6*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*`abcdefghijklmno*/ /*7*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*pqrstuvwxyz{|}~ */ /*8*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -29,32 +29,34 @@ static UC vaindx[256] = { /*0 1 2 3 4 5 6 7 8 9 a b c d e f*/ }; -#define NVA 6 +#define NVA 7 static VA verbatm[NVA] = { - {{ {NULL, 0}, {NULL, 0}, {NULL, 0}, - {NULL, 0}, {NULL, 0}, {NULL, 0} }}, + {{ {NULL, 0 }, {NULL, 0 }, {NULL, 0 }, + {NULL, 0 }, {NULL, 0 }, {NULL, 0 } }}, {{ {bdivide, VAB|VRD}, {idivide, VAI|VRD}, {ddivide, VAD|VRD}, - {ddivide, VAD|VRD}, {ddivide, VAD|VRD}, {ddivide, VAZ|VRZ} }}, + {jdivide, VAZ|VRZ}, {ddivide, VAD|VRD}, {ddivide, VAZ|VRZ} }}, - {{ {btimes, VAB|VRB}, {itimes, VAI|VRI}, {dtimes, VAD|VRD}, - {dtimes, VAD+VRD}, {dtimes, VAD|VRD}, {dtimes, VAZ|VRZ} }}, + {{ {btimes, VAB|VRB}, {itimes, VAI|VRI}, {dtimes, VAD|VRD}, + {jtimes, VAZ+VRZ}, {dtimes, VAD|VRD}, {dtimes, VAZ|VRZ} }}, - {{ {bplus, VAB|VRI}, {iplus, VAI|VRI}, {dplus, VAD|VRD}, - {dplus, VAD|VRD}, {dplus, VAD|VRD}, {dplus, VAZ|VRZ} }}, + {{ {bplus, VAB|VRI}, {iplus, VAI|VRI}, {dplus, VAD|VRD}, + {jplus, VAZ|VRZ}, {dplus, VAD|VRD}, {dplus, VAZ|VRZ} }}, - {{ {bminus, VAB|VRI}, {iminus, VAI|VRI}, {dminus, VAD|VRD}, - {dminus, VAD|VRD}, {dminus, VAD|VRD}, {dminus, VAZ|VRZ} }}, + {{ {bminus, VAB|VRI}, {iminus, VAI|VRI}, {dminus, VAD|VRD}, + {dminus, VAD|VRD}, {dminus, VAD|VRD}, {dminus, VAZ|VRZ} }}, - {{ {blthan, VAB|VRB}, {ilthan, VAI|VRB}, {dlthan, VAD|VRB}, - {dlthan, VAD|VRD}, {dlthan, VAD|VRD}, {dlthan, VAZ|VRZ} }}, + {{ {blthan, VAB|VRB}, {ilthan, VAI|VRB}, {dlthan, VAD|VRB}, + {dlthan, VAD|VRD}, {dlthan, VAD|VRD}, {dlthan, VAZ|VRZ} }}, + {{ {bpower, VAB|VRB}, {ipower, VAI|VRI}, {dpower, VAD|VRD}, + {dpower, VAD|VRD}, {dlthan, VAD|VRD}, {dlthan, VAZ|VRZ} }} }; -I atype(I cv) { return cv&VAB ? BOOL : cv&VAI ? INT : cv&VAD ? FLT : CMPX; } +I atype(I cv) { R cv&VAB ? BOOL : cv&VAI ? INT : cv&VAD ? FLT : CMPX; } -I rtype(I cv) { return cv&VRB ? BOOL : cv&VRI ? INT : cv&VRD ? FLT : CMPX; } +I rtype(I cv) { R cv&VRB ? BOOL : cv&VRI ? INT : cv&VRD ? FLT : CMPX; } /* va2: Execute dyadic atomic verb. @@ -72,6 +74,6 @@ A va2(C id, A x, A y) { SF f2 = vd->f; A z; ASSERT(xt&NUMERIC&&yt&NUMERIC, ERDOM); cv = vd->cv; at = atype(cv); rt = rtype(cv); - z = sex2(xt==at ? x : conv(at, x), yt==at ? y : conv(at, y), rt, f2); - return z; + z = sex2(xt==at ? x : conv(at,x), yt==at ? y : conv(at,y), rt, f2); + R z; } diff --git a/verb-scalar2.c b/verb-scalar2.c index d7d09ff..1bebbea 100644 --- a/verb-scalar2.c +++ b/verb-scalar2.c @@ -1,42 +1,54 @@ +#include + #include "anicca.h" #include "verb-scalar2.h" -SF2(bdivide, D, B, *x / (D)*y) -SF2(idivide, D, I, *x / (D)*y) -SF2(ddivide, D, D, *x / *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(btimes, B, B, *x * *y) -SF2(itimes, I, I, *x * *y) -SF2(dtimes, D, D, *x * *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(bplus, I, B, *x + *y) -SF2(iplus, I, I, *x + *y) -SF2(dplus, D, D, *x + *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(bminus, I, B, *x - *y) -SF2(iminus, I, I, *x - *y) -SF2(dminus, D, D, *x - *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(blthan, B, B, *x < *y) -SF2(ilthan, B, I, *x < *y) -SF2(dlthan, B, D, *x < *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(bequal, B, B, *x == *y) -SF2(iequal, B, I, *x == *y) -SF2(dequal, B, D, *x == *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(bgthan, B, B, *x > *y) -SF2(igthan, B, I, *x > *y) -SF2(dgthan, B, D, *x > *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ - -SF2(bresidue, B, B, *x % *y) -SF2(iresidue, I, I, *x % *y) -SF2(dresidue, D, D, *x + *y) -/*SF2(jplus, Z, Z, zplus(x,y))*/ +SF2(bdivide, D, B, *x / (D)*y) +SF2(idivide, D, I, *x / (D)*y) +SF2(ddivide, D, D, *x / *y) +static Z zdivide(Z x, Z y) { Z z; ZR(z)=ZR(x)/ZR(y); ZI(z)=ZI(x)/ZI(y); R z; } +SF2(jdivide, Z, Z, zdivide(*x,*y)) + +SF2(btimes, B, B, *x * *y) +SF2(itimes, I, I, *x * *y) +SF2(dtimes, D, D, *x * *y) +static Z ztimes(Z x, Z y) { D a=ZR(x),b=ZR(y),c=ZI(x),d=ZI(y); Z z; + ZR(z)=a*c-b*d; ZI(z)=b*c+a*d; + R z; +} +SF2(jtimes, Z, Z, ztimes(*x,*y)) + +SF2(bplus, I, B, *x + *y) +SF2(iplus, I, I, *x + *y) +SF2(dplus, D, D, *x + *y) +static Z zplus(Z x, Z y) { Z z; ZR(z)=ZR(x)+ZR(y); ZI(z)=ZI(x)+ZI(y); R z; } +SF2(jplus, Z, Z, zplus(*x,*y)) + +SF2(bminus, I, B, *x - *y) +SF2(iminus, I, I, *x - *y) +SF2(dminus, D, D, *x - *y) +/*SF2(jplus, Z, Z, zplus(x,y))*/ + +SF2(blthan, B, B, *x < *y) +SF2(ilthan, B, I, *x < *y) +SF2(dlthan, B, D, *x < *y) +/*SF2(jplus, Z, Z, zplus(x,y))*/ + +SF2(bequal, B, B, *x == *y) +SF2(iequal, B, I, *x == *y) +SF2(dequal, B, D, *x == *y) +/*SF2(jplus, Z, Z, zplus(x,y))*/ + +SF2(bgthan, B, B, *x > *y) +SF2(igthan, B, I, *x > *y) +SF2(dgthan, B, D, *x > *y) +/*SF2(jplus, Z, Z, zplus(x,y))*/ + +SF2(bpower, B, B, *x >= *y) +SF2(ipower, I, I, (I)pow(*x,*y)) +SF2(dpower, D, D, pow(*x,*y)) + +SF2(bresidue, B, B, *x % *y) +SF2(iresidue, I, I, *x % *y) +SF2(dresidue, D, D, *x + *y) +/*SF2(jplus, Z, Z, zplus(x,y))*/ diff --git a/verb-scalar2.h b/verb-scalar2.h index 753a59d..e75f56e 100644 --- a/verb-scalar2.h +++ b/verb-scalar2.h @@ -7,24 +7,31 @@ #define DECL_SF2(name, zt, yt) \ VO name(zt *z, yt *x, yt* y) -DECL_SF2(bdivide, D, B); -DECL_SF2(idivide, D, I); -DECL_SF2(ddivide, D, D); - -DECL_SF2(btimes, B, B); -DECL_SF2(itimes, I, I); -DECL_SF2(dtimes, D, D); - -DECL_SF2(bplus, I, B); -DECL_SF2(iplus, I, I); -DECL_SF2(dplus, D, D); - -DECL_SF2(bminus, I, B); -DECL_SF2(iminus, I, I); -DECL_SF2(dminus, D, D); - -DECL_SF2(blthan, B, B); -DECL_SF2(ilthan, B, I); -DECL_SF2(dlthan, B, D); +DECL_SF2(bdivide, D, B); +DECL_SF2(idivide, D, I); +DECL_SF2(ddivide, D, D); +DECL_SF2(jdivide, Z, Z); + +DECL_SF2(btimes, B, B); +DECL_SF2(itimes, I, I); +DECL_SF2(dtimes, D, D); +DECL_SF2(jtimes, Z, Z); + +DECL_SF2(bplus, I, B); +DECL_SF2(iplus, I, I); +DECL_SF2(dplus, D, D); +DECL_SF2(jplus, Z, Z); + +DECL_SF2(bminus, I, B); +DECL_SF2(iminus, I, I); +DECL_SF2(dminus, D, D); + +DECL_SF2(blthan, B, B); +DECL_SF2(ilthan, B, I); +DECL_SF2(dlthan, B, D); + +DECL_SF2(bpower, B, B); +DECL_SF2(ipower, I, I); +DECL_SF2(dpower, D, D); #endif diff --git a/verb.c b/verb.c index daf76bd..1f3101e 100755 --- a/verb.c +++ b/verb.c @@ -23,15 +23,12 @@ MONAD(fact) { MONAD_PROLOG; DO(temp, r *= temp--); v[i] = r; ); - return z; + R z; } -DYAD(outof) { A z; - z = divide(fact(y), times(fact(x), fact(minus(y, x)))); - return z; -} +DYAD(outof) { A z; z = divide(fact(y),times(fact(x),fact(minus(y,x)))); R z; } -MONAD(tally) { A z; z = sint(AN(y)); return z; } +MONAD(tally) { A z; z = sint(AN(y)); R z; } DYAD(copy) { DYAD_PROLOG; I n = 0, itm, cnt; @@ -42,12 +39,12 @@ DYAD(copy) { DYAD_PROLOG; DO(xn, cnt = xv[i]; itm = yv[i]; if (cnt>0) { DO(cnt, *v++ = itm); } ); - return z; + R z; } -MONAD(reciprocal) { A z = divide(one, y); return z; } +MONAD(reciprocal) { A z = divide(one, y); R z; } -DYAD(divide) { A z = va2(CPERC, x, y); return z; } +DYAD(divide) { A z = va2(CPERC,x,y); R z; } MONAD(signum) { A z; switch (AT(y)) { @@ -55,20 +52,18 @@ MONAD(signum) { A z; case INT: z = sex1(y, INT, isignum); break; case FLT: z = sex1(y, INT, dsignum); break; } - return z; + R z; } -DYAD(times) { A z = va2(CSTAR, x, y); return z; } +DYAD(times) { A z = va2(CSTAR,x,y); R z; } -MONAD(square) { A z = times(y, y); return z; } +MONAD(square) { A z = times(y,y); R z; } -MONAD(conjugate) { MONAD_PROLOG; - return z; -} +MONAD(conjugate) { A z; R z; } -DYAD(plus) { A z = va2(CPLUS, x, y); return z; } +DYAD(plus) { A z = va2(CPLUS,x,y); R z; } -MONAD(duble) { A z = plus(y, y); return z; } +MONAD(duble) { A z = plus(y, y); R z; } DYAD(append) { I xt=AT(x), yt=AT(y), xr=AR(x), yr=AR(y); @@ -87,74 +82,68 @@ DYAD(append) { v += k*xn; memcpy(v, yv, k*yn); } else { a_signal(ERDOM); } - return z; + R z; } -MONAD(negate) { A z = minus(zero, y); return z; } +MONAD(negate) { A z = minus(zero, y); R z; } -DYAD(minus) { A z = va2(CSUBT, x, y); return z; } +DYAD(minus) { A z = va2(CSUBT,x,y); R z; } -MONAD(not) { A z = minus(one, y); return z; } +MONAD(not) { A z = minus(one, y); R z; } -DYAD(link) { - A z; return z; -} +DYAD(link) { A z; R z; } -MONAD(box) { A z = ga(BOX, 0, 1, NULL); *AAV(z) = y; return z; } +MONAD(box) { A z = sbox(y); R z; } -DYAD(lthan) { A z = va2(CLT, x, y); return z; } +DYAD(lthan) { A z = va2(CLT,x,y); R z; } -MONAD(decrement) { A z = minus(y, one); return z; } +MONAD(decrement) { A z = minus(y, one); R z; } -DYAD(equal) { A z = va2(CEQ, x, y); return z; } +DYAD(equal) { A z = va2(CEQ,x,y); R z; } -MONAD(unbox) { A z; - return z; -} +MONAD(unbox) { A z = ca(*AAV(y)); R z; } -DYAD(gthan) { A z = va2(CGT, x, y); return z; } +DYAD(gthan) { A z = va2(CGT,x,y); R z; } -MONAD(increment) { A z = plus(y, one); return z; } +MONAD(increment) { A z = plus(y, one); R z; } -MONAD(roll) { - A z; return z; -} +MONAD(roll) { A z; R z; } -DYAD(deal) { - A z; return z; -} +DYAD(deal) { A z; R z; } MONAD(indices) { MONAD_PROLOG; z = ga(INT, AR(y), yn, AS(y)); v = IAV(z); - return z; + R z; } MONAD(expntl) { I yn = AN(y), *yv = IAV(y); A z = ga(FLT, AR(y), yn, AS(y)); D *v = DAV(z); DO(yn, v[i] = exp((D)yv[i])); - return z; + R z; } +MONAD(same) { A z = ca(y); R z; } + +DYAD(left) { A z = ca(x); R z; } + +DYAD(right) { A z = ca(y); R z; } + +DYAD(power) { A z = va2(CPOW,x,y); R z; } + MONAD(iota) { A z; I yr = AR(y), n = *IAV(y), *v; z = ga(INT, 1, n, AS(y)); v = IAV(z); DO(n, v[i] = i); - return z; + R z; } -MONAD(same) { A z = ca(y); return z; } +MONAD(imaginary) { A z = times(zone,y); R z; } -DYAD(left) { A z = ca(x); return z; } +DYAD(complex) { A z = plus(x,imaginary(y)); R z; } -DYAD(right) { A z = ca(y); return z; } +DYAD(residue) { A z; R z; } -DYAD(residue) { - A z; return z; -} - -MONAD(tail) { A z; - return z; -} +MONAD(tail) { A z; R z; } diff --git a/verb.h b/verb.h index 1639bc9..7a431ef 100755 --- a/verb.h +++ b/verb.h @@ -29,13 +29,18 @@ MONAD(box); DYAD(lthan); MONAD(decrement); DYAD(equal); +MONAD(unbox); DYAD(gthan); MONAD(increment); -MONAD(iota); MONAD(expntl); +DYAD(power); MONAD(same); DYAD(left); DYAD(right); +DYAD(power); +MONAD(iota); +MONAD(imaginary); +DYAD(complex); DYAD(residue); MONAD(tail);