summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2022-02-22 21:25:36 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2022-02-22 21:25:36 +0000
commit40af1deff9db7b86532db6957ebdbc0aaff38db1 (patch)
treecb417113744f26a015d36ee6732746c4e808e700 /functions.c
parentae6471f1c94f51df540d95edc09c7749002f44e8 (diff)
Make errors more like dyalog:
* Use the same error numbers * Rename ⎕THROW to ⎕SIGNAL * Implement ⎕EN to inspect the last error code * Implement ⎕EM to get a message from an error code
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/functions.c b/functions.c
index 7e462c3..f73ff29 100644
--- a/functions.c
+++ b/functions.c
@@ -325,7 +325,7 @@ Array *
fnMatrixInverse(Array *right)
{
if(GetType(right) != AtypeInt && GetType(right) != AtypeFloat)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetRank(right) > 2)
throwerror(nil, ERank);
@@ -369,7 +369,7 @@ fnFactorial(Array *right)
}else if(GetType(right) == AtypeFloat)
throwerror(L"Factorial of floating values", ENotImplemented);
else
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
return result;
}
@@ -408,7 +408,7 @@ fnRoll(Array *right)
result->intdata[i] = io + lrand() % right->intdata[i];
}
}else
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
return result;
}
@@ -443,7 +443,7 @@ fnFloor(Array *right)
res->arraydata[i] = fnFloor(right->arraydata[i]);
break;
default:
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
}
return res;
}
@@ -734,7 +734,7 @@ Array *
fnNot(Array *right)
{
if(GetType(right) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
Array *res = duparray(right);
for(int i = 0; i < GetSize(res); i++){
if(res->intdata[i] == 0)
@@ -743,7 +743,7 @@ fnNot(Array *right)
res->intdata[i] = 0;
else{
freearray(res);
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
}
}
return res;
@@ -859,14 +859,14 @@ Array *
fnExecute(Array *right)
{
if(GetType(right) != AtypeRune)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
Rune *code = pparray(right);
Datum *result = evalline(code, nil, 1);
free(code);
if(!result)
throwerror(L"No result produced by ⍎", EDomain);
if(result->tag != ArrayTag)
- throwerror(L"Result of ⍎ must be an array", EType);
+ throwerror(L"Result of ⍎ must be an array", EDomain);
Array *res = result->array;
free(result);
return res;
@@ -936,7 +936,7 @@ Array *name(Array *left, Array *right){\
rightarr = fnSame(right);\
}else{\
if(!commontype(left, right, &leftarr, &rightarr, forcefloat))\
- throwerror(nil, EType);\
+ throwerror(nil, EDomain);\
}\
if(!scalarextend(leftarr, rightarr, &left, &right)) throwerror(L"Scalar extension fail", ERank);\
Array *res;\
@@ -953,7 +953,7 @@ Array *name(Array *left, Array *right){\
res = duparray(left);\
for(int i = 0; i < GetSize(left); i++)\
switch(GetType(left)){\
- default: throwerror(nil, EType); break;\
+ default: throwerror(nil, EDomain); break;\
cases\
}\
}\
@@ -1088,9 +1088,9 @@ Array *
fnDeal(Array *left, Array *right)
{
if(GetType(left) != AtypeInt || GetType(right) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetSize(left) != 1 || GetSize(right) != 1)
- throwerror(nil, EShape);
+ throwerror(nil, ELength);
vlong x = left->intdata[0];
vlong y = right->intdata[0];
if(x < 0 || y < 0 || x > y)
@@ -1140,9 +1140,9 @@ Array *
fnDecode(Array *left, Array *right)
{
if(GetType(left) != AtypeInt && GetType(left) != AtypeFloat)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetType(right) != AtypeInt && GetType(right) != AtypeFloat)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
return rundfn(L"(⌽×\\1,⌽⍵∘{1↓(≢⍺)⍴⍵}⍤1⊢⍺)+.×⍵", nil, nil, left, right);
}
@@ -1150,9 +1150,9 @@ Array *
fnEncode(Array *left, Array *right)
{
if(GetType(left) != AtypeInt && GetType(left) != AtypeFloat)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetType(right) != AtypeInt && GetType(right) != AtypeFloat)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetRank(left) > 1)
return rundfn(L"⍉(⍉⍺) (⊤⍤1) ⍵", nil, nil, left, right);
@@ -1274,9 +1274,9 @@ SCALAR_FUNCTION_2(fnAnd, 0, GetType(left),
SCALAR_FUNCTION_2(fnNand, 0, AtypeInt,
case AtypeInt:
if(left->intdata[i] != 0 && left->intdata[i] != 1)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(right->intdata[i] != 0 && right->intdata[i] != 1)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
res->intdata[i] = !(left->intdata[i] && right->intdata[i]);
break;
)
@@ -1284,9 +1284,9 @@ SCALAR_FUNCTION_2(fnNand, 0, AtypeInt,
SCALAR_FUNCTION_2(fnNor, 0, AtypeInt,
case AtypeInt:
if(left->intdata[i] != 0 && left->intdata[i] != 1)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(right->intdata[i] != 0 && right->intdata[i] != 1)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
res->intdata[i] = !(left->intdata[i] || right->intdata[i]);
break;
)
@@ -1296,7 +1296,7 @@ fnTake(Array *left, Array *right)
{
int i;
if(GetType(left) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetRank(left) > 1)
throwerror(nil, ERank);
@@ -1388,7 +1388,7 @@ fnDrop(Array *left, Array *right)
{
int i;
if(GetType(left) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetRank(left) > 1)
throwerror(nil, ERank);
@@ -1470,7 +1470,7 @@ fnPartition(Array *left, Array *right)
if(GetRank(left) > 2)
throwerror(nil, ERank);
if(GetType(left) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetSize(left) != right->shape[0])
throwerror(nil, ELength);
if(right->shape[0] == 0)
@@ -1523,7 +1523,7 @@ fnIndex(Array *left, Array *right)
if(GetRank(left) > 1)
throwerror(nil, ERank);
if(GetType(left) != AtypeArray && GetType(left) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetSize(left) > GetRank(right))
throwerror(nil, ELength);
@@ -1543,7 +1543,7 @@ fnIndex(Array *left, Array *right)
}else if(GetType(oldleft) == AtypeArray){
Array *sub = oldleft->arraydata[i];
if(GetType(sub) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
for(int j = 0; j < GetSize(sub); j++){
if(sub->intdata[j] < io || sub->intdata[j] >= io + right->shape[i])
throwerror(nil, EIndex);
@@ -1734,7 +1734,7 @@ fnCatenateFirst(Array *left, Array *right)
for(int i = 1; i < GetRank(leftarr); i++)
if(leftarr->shape[i] != rightarr->shape[i])
- throwerror(nil, EShape);
+ throwerror(nil, ELength);
}
int type, rank, leftsize, rightsize;
@@ -1834,7 +1834,7 @@ Array *
fnRotateFirst(Array *left, Array *right)
{
if(GetType(left) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
if(GetRank(right) == 0 || GetSize(right) < 2)
return fnSame(right);
@@ -1854,7 +1854,7 @@ fnRotateFirst(Array *left, Array *right)
throwerror(nil, ERank);
for(i = 0; i < GetRank(left); i++)
if(left->shape[i] != right->shape[i+1])
- throwerror(nil, EShape);
+ throwerror(nil, ELength);
int n = right->shape[0];
for(i = 0; i < GetSize(left); i++)
@@ -1893,7 +1893,7 @@ fnSend(Array *left, Array *right)
if(GetSize(right) != 1)
throwerror(nil, ELength);
if(GetType(right) != AtypeInt)
- throwerror(nil, EType);
+ throwerror(nil, EDomain);
messagesend(left, right->intdata[0]);
return fnSame(left);
}
@@ -1928,7 +1928,7 @@ indexOfHelper(Array *left, Array *right, int interval)
int i, j;
for(i = 0; i < GetRank(left)-1; i++)
if(left->shape[GetRank(left)-1-i] != right->shape[GetRank(right)-1-i])
- throwerror(nil, EShape);
+ throwerror(nil, ELength);
int rank = GetRank(right) + 1 - GetRank(left);
int size = 1;