jplus-0.4.7
jengine.h
Go to the documentation of this file.
1/* -*- mode: c++; indent-tabs-mode:nil -*- */
2#ifndef JENGINE_H
3#define JENGINE_H
4
5#include <string>
6#include <vector>
7#include <set>
8
9#include "util.h"
10#include "jarray.h"
11
13class jengine {
14public:
15 friend class jarray;
17 typedef jarray (*monad) (jarray y);
19 typedef jarray (*dyad) (jarray x, jarray y);
21 typedef jarray (*amonad) (monad um, dyad ud, jarray y);
23 typedef jarray (*adyad) (monad um, dyad ud, jarray x, jarray y);
24
29
32 static void initJlibrary(std::ostream &);
33
37 bool doJ(const std::string s);
38
42 const jarray get(const std::string name);
43
48 bool set(const std::string name, jarray &value);
49
52 int getError();
53
56 inline bool ok() {
57 return (getError()==0);
58 };
59
61 const static int RMAX=10000;
62
73 bool defVerb(std::string name, monad mf, dyad df, int mr=RMAX, int lr=RMAX, int rr=RMAX);
74
83 bool defAdverb(std::string name, amonad mf, adyad df);
84
93 bool defScript(std::string name, int type, std::string code,
94 int mr=jengine::RMAX,
95 int lr=jengine::RMAX,
96 int rr=jengine::RMAX);
97
101 bool isBuiltin(std::string name) const;
102
105 std::set<std::string> getBuiltins() const;
106
110
120
133 void* EPILOG(jarray::I oldtop, void *hdr);
134
135protected:
142 void* GA(const jarray::I t, const jarray::I n, const jarray::I r, const jarray::I *s);
146 void FR(void *hdr);
147
148private:
149 // copy disabled
150 jengine(const jengine &);
151 const jengine& operator=(const jengine&);
152
153 class Impl;
154 Impl* pImpl;
155};
156#endif
C++ representation of J array.
Definition jarray.h:25
long I
integer type, equivalent to J
Definition jarray.h:36
Interface to dynamically loaded J engine.
Definition jengine.h:13
jarray::I EPILOG(jarray::I oldtop)
Frees all memory, allocated since ttop was recorded.
bool isBuiltin(std::string name) const
Checks if given name was defined via defScript.
bool defAdverb(std::string name, amonad mf, adyad df)
defines J adverb, calling one (or both) of specified C++ functions.
static const int RMAX
Constant to denote the infinite rank.
Definition jengine.h:61
std::set< std::string > getBuiltins() const
Returns set of all names defined via defScript.
jarray(* adyad)(monad um, dyad ud, jarray x, jarray y)
Pointer to function, implementing dyadic variant of an adverb.
Definition jengine.h:23
static void initJlibrary(std::ostream &)
Loads and links J dynamic library, must be called once before this class is instantiated.
~jengine()
Frees J engine memory.
void * EPILOG(jarray::I oldtop, void *hdr)
Frees all memory, allocated since ttop was recorded.
jengine()
Initializes J engine.
bool doJ(const std::string s)
Executes J sentence.
const jarray get(const std::string name)
Retrieves a named array from J.
void FR(void *hdr)
Frees J array memory.
void * GA(const jarray::I t, const jarray::I n, const jarray::I r, const jarray::I *s)
Allocates J array.
jarray(* dyad)(jarray x, jarray y)
Pointer to function, implementing dyadic variant of a verb.
Definition jengine.h:19
bool set(const std::string name, jarray &value)
Assigns J name to the specified array.
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.
jarray(* amonad)(monad um, dyad ud, jarray y)
Pointer to function, implementing monadic variant of an adverb.
Definition jengine.h:21
jarray::I PROLOG()
Returns the top of J garbage collection stack.
friend class jarray
Definition jengine.h:15
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.
jarray(* monad)(jarray y)
Pointer to function, implementing monadic variant of a verb.
Definition jengine.h:17
int getError()
J error code for the last unsuccessful operation.
bool ok()
Conveniently check that there was no error.
Definition jengine.h:56