jplus-0.4.7
|
Interface to dynamically loaded J engine. More...
#include <src/jengine.h>
Public Types | |
typedef jarray(* | monad) (jarray y) |
Pointer to function, implementing monadic variant of a verb. | |
typedef jarray(* | dyad) (jarray x, jarray y) |
Pointer to function, implementing dyadic variant of a verb. | |
typedef jarray(* | amonad) (monad um, dyad ud, jarray y) |
Pointer to function, implementing monadic variant of an adverb. | |
typedef jarray(* | adyad) (monad um, dyad ud, jarray x, jarray y) |
Pointer to function, implementing dyadic variant of an adverb. | |
Public Member Functions | |
jengine () | |
Initializes J engine. | |
~jengine () | |
Frees J engine memory. | |
bool | doJ (const std::string s) |
Executes J sentence. | |
const jarray | get (const std::string name) |
Retrieves a named array from J. | |
bool | set (const std::string name, jarray &value) |
Assigns J name to the specified array. | |
int | getError () |
J error code for the last unsuccessful operation. | |
bool | ok () |
Conveniently check that there was no error. | |
bool | defVerb (std::string name, monad mf, dyad df, int mr=RMAX, int lr=RMAX, int rr=RMAX) |
Defines J verb, calling one (or both) of specified C++ functions. | |
bool | defAdverb (std::string name, amonad mf, adyad df) |
defines J adverb, calling one (or both) of specified C++ functions. | |
bool | defScript (std::string name, int type, std::string code, int mr=jengine::RMAX, int lr=jengine::RMAX, int rr=jengine::RMAX) |
Defines a J script, given by a (possibly multi-line) string. | |
bool | isBuiltin (std::string name) const |
Checks if given name was defined via defScript. | |
std::set< std::string > | getBuiltins () const |
Returns set of all names defined via defScript. | |
jarray::I | PROLOG () |
Returns the top of J garbage collection stack. | |
jarray::I | EPILOG (jarray::I oldtop) |
Frees all memory, allocated since ttop was recorded. | |
void * | EPILOG (jarray::I oldtop, void *hdr) |
Frees all memory, allocated since ttop was recorded. | |
Static Public Member Functions | |
static void | initJlibrary (std::ostream &) |
Loads and links J dynamic library, must be called once before this class is instantiated. | |
Static Public Attributes | |
static const int | RMAX =10000 |
Constant to denote the infinite rank. | |
Protected Member Functions | |
void * | GA (const jarray::I t, const jarray::I n, const jarray::I r, const jarray::I *s) |
Allocates J array. | |
void | FR (void *hdr) |
Frees J array memory. | |
Friends | |
class | jarray |
Interface to dynamically loaded J engine.
Pointer to function, implementing dyadic variant of an adverb.
Pointer to function, implementing monadic variant of an adverb.
Pointer to function, implementing dyadic variant of a verb.
Pointer to function, implementing monadic variant of a verb.
jengine::jengine | ( | ) |
Initializes J engine.
jengine::~jengine | ( | ) |
Frees J engine memory.
defines J adverb, calling one (or both) of specified C++ functions.
Works similarly to verb definition, except the functions may now call the verb argument of an adverb monadically or dyadically. Adverbs always have infinite ranks.
name | name of the new adverb (may already be defined). |
mf | function to be called when adverb is invoked monadically. |
df | function to be called when adverb is invoked dyadically. |
bool jengine::defScript | ( | std::string | name, |
int | type, | ||
std::string | code, | ||
int | mr = jengine::RMAX , |
||
int | lr = jengine::RMAX , |
||
int | rr = jengine::RMAX |
||
) |
Defines a J script, given by a (possibly multi-line) string.
name | name of the script. |
type | type of the script (the left argument of ":" conjunction). |
code | code of the script (possibly multi-line). |
mr | monadic rank (infinite by default). |
lr | left rank (infinite by default). |
rr | right rank (infinite by default). |
bool jengine::defVerb | ( | std::string | name, |
monad | mf, | ||
dyad | df, | ||
int | mr = RMAX , |
||
int | lr = RMAX , |
||
int | rr = RMAX |
||
) |
Defines J verb, calling one (or both) of specified C++ functions.
Either of mf or df can be NULL, meaning the absence of corresponding (monadic/dyadic) case. Ranks, equal to RMAX denote "infinite" rank.
name | name of the new verb (may already be defined). |
mf | function to be called when verb is invoked monadically. |
df | function to be called when verb is invoked dyadically. |
mr | monadic rank (infinite by default). |
lr | left rank (infinite by default). |
rr | right rank (infinite by default). |
Executes J sentence.
s | sentence to execute, must be single line. |
Frees all memory, allocated since ttop was recorded.
This function, together with PROLOG allows for more explicit J memory management. Be careful that all jarrays, allocated between prolog and epilog are out of scope (so that their destructors have already been called), otherwise this function has potential to mess things up considerably.
oldtop | the top of J garbage collection stack, recorded by PROLOG. |
Frees all memory, allocated since ttop was recorded.
This function, together with PROLOG allows for more explicit J memory management. Be careful that all jarrays, allocated between prolog and epilog are out of scope (so that their destructors have already been called), otherwise this function has potential to mess things up considerably.
oldtop | the top of J garbage collection stack, recorded by PROLOG. |
hdr | pointer to the array header (already in the temp stack), which should not be freed, but lifted to the top of new stack (this array usually contains the result of a verb). |
Frees J array memory.
hdr | pointer to the array header. |
|
protected |
Allocates J array.
t | type of the array. |
n | number of elements in the array. |
r | rank of the array. |
s | shape of the array. |
Retrieves a named array from J.
name | name of the array to retrieve |
std::set< std::string > jengine::getBuiltins | ( | ) | const |
Returns set of all names defined via defScript.
int jengine::getError | ( | ) |
J error code for the last unsuccessful operation.
Referenced by ok().
Loads and links J dynamic library, must be called once before this class is instantiated.
bool jengine::isBuiltin | ( | std::string | name | ) | const |
Checks if given name was defined via defScript.
name | name to check |
|
inline |
Conveniently check that there was no error.
References getError().
jarray::I jengine::PROLOG | ( | ) |
Returns the top of J garbage collection stack.
bool jengine::set | ( | const std::string | name, |
jarray & | value | ||
) |
Assigns J name to the specified array.
name | is the name for the array (may already be defined). |
value | is the array to be known under the specified name. |