Add functions for unit displacements in the siz cardinal directions
This change is the "easy" part of #64, but to reduce the amount of duplicated code, this change also modifies the internals of implementing a function. The function identifier is now passed to the implementation as well, allowing many implementations of similar functions to be collapsed more easily.
This commit is contained in:
parent
9670e8b4a1
commit
7e0ba7370d
5 changed files with 673 additions and 688 deletions
|
@ -513,12 +513,28 @@ Token tmul(Token l, Token r)
|
|||
else result.u.flt = l.u.flt * ((FltT)r.u.integer);
|
||||
}
|
||||
/*}}}*/
|
||||
else if ((l.type == EMPTY && r.type == LOCATION)
|
||||
|| (l.type == LOCATION && r.type == EMPTY))
|
||||
/* result is 0 location */ /*{{{*/
|
||||
{
|
||||
result.type = LOCATION;
|
||||
OLOCATION(result.u.location);
|
||||
}
|
||||
/*}}}*/
|
||||
else if (l.type == LOCATION && r.type == INT)
|
||||
/* result is each component of location times right */ /*{{{*/
|
||||
{
|
||||
result.type = LOCATION;
|
||||
for (size_t len = 0; len < 3; ++len)
|
||||
result.u.location[len] = l.u.location[len] * r.u.integer;
|
||||
for (Dimensions dim = X; dim < HYPER; ++dim)
|
||||
result.u.location[dim] = l.u.location[dim] * r.u.integer;
|
||||
}
|
||||
/*}}}*/
|
||||
else if (l.type == INT && r.type == LOCATION)
|
||||
/* result is each component of right location times left */ /*{{{*/
|
||||
{
|
||||
result.type = LOCATION;
|
||||
for (Dimensions dim = X; dim < HYPER; ++dim)
|
||||
result.u.location[dim] = l.u.integer * r.u.location[dim];
|
||||
}
|
||||
/*}}}*/
|
||||
else if (l.type == LOCATION && r.type == LOCATION)
|
||||
|
@ -526,8 +542,8 @@ Token tmul(Token l, Token r)
|
|||
{
|
||||
result.type = INT;
|
||||
result.u.integer = 0;
|
||||
for (size_t len = 0; len < 3; ++len)
|
||||
result.u.integer += l.u.location[len] * r.u.location[len];
|
||||
for (Dimensions dim = X; dim < HYPER; ++dim)
|
||||
result.u.integer += l.u.location[dim] * r.u.location[dim];
|
||||
}
|
||||
/*}}}*/
|
||||
else if ((l.type == INT && r.type == STRING)
|
||||
|
@ -681,9 +697,9 @@ Token tpow(Token l, Token r)
|
|||
/*}}}*/
|
||||
|
||||
/* tfuncall -- function operator */ /*{{{*/
|
||||
Token tfuncall(int fident, int argc, Token argv[])
|
||||
Token tfuncall(FunctionIdentifier fident, int argc, Token argv[])
|
||||
{
|
||||
return tfunc[fident].func(argc, argv);
|
||||
return tfunc[fident].func(fident, argc, argv);
|
||||
}
|
||||
/*}}}*/
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ Token tadd(Token l, Token r);
|
|||
Token tconcat(Token l, Token r);
|
||||
Token tsub(Token l, Token r);
|
||||
Token tneg(Token x);
|
||||
Token tfuncall(int fident, int argc, Token argv[]);
|
||||
Token tfuncall(FunctionIdentifier fident, int argc, Token argv[]);
|
||||
Token tlt(Token l, Token r);
|
||||
Token tle(Token l, Token r);
|
||||
Token tge(Token l, Token r);
|
||||
|
|
1103
src/common/func.c
1103
src/common/func.c
File diff suppressed because it is too large
Load diff
|
@ -26,7 +26,7 @@ typedef enum
|
|||
FUNC_EQUAL_EQUAL, FUNC_TILDE_EQUAL, FUNC_BANG_EQUAL, FUNC_CARET,
|
||||
FUNC_PER_CENT, FUNC_CONCAT, FUNC_TAU, FUNC_SQRT, FUNC_FLOOR, FUNC_CEIL,
|
||||
FUNC_TRUNC, FUNC_ROUND, FUNC_DECIMAL, FUNC_SCIENTIFIC, FUNC_COMPACT,
|
||||
FUNC_HEXACT,
|
||||
FUNC_HEXACT, FUNC_RIGHT, FUNC_LEFT, FUNC_DOWN, FUNC_UP, FUNC_BELOW, FUNC_ABOVE,
|
||||
|
||||
N_FUNCTION_IDS
|
||||
} FunctionIdentifier;
|
||||
|
@ -45,7 +45,7 @@ typedef enum { FUNCT, MACRO } EvaluationStrategy;
|
|||
typedef struct
|
||||
{
|
||||
const char name[MAX_FUNC_NAME_LENGTH + 1];
|
||||
Token (*func)(int, const Token*);
|
||||
Token (*func)(FunctionIdentifier self, int, const Token*);
|
||||
FunctionPrecedence precedence;
|
||||
EvaluationStrategy eval_as;
|
||||
const char* display_symbol;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue