forked from GitHub/gf-core
more functions could now fail with an exception
This commit is contained in:
@@ -12,6 +12,21 @@ pgf_exn_clear(PgfExn* err)
|
|||||||
err->msg = NULL;
|
err->msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PGF_API_BEGIN \
|
||||||
|
pgf_exn_clear(err); \
|
||||||
|
\
|
||||||
|
try \
|
||||||
|
|
||||||
|
#define PGF_API_END \
|
||||||
|
catch (pgf_systemerror& e) { \
|
||||||
|
err->type = PGF_EXN_SYSTEM_ERROR; \
|
||||||
|
err->code = e.code(); \
|
||||||
|
err->msg = e.filepath(); \
|
||||||
|
} catch (pgf_error& e) { \
|
||||||
|
err->type = PGF_EXN_PGF_ERROR; \
|
||||||
|
err->msg = strdup(e.what()); \
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfDB *pgf_read_pgf(const char* fpath,
|
PgfDB *pgf_read_pgf(const char* fpath,
|
||||||
PgfRevision *revision,
|
PgfRevision *revision,
|
||||||
@@ -19,9 +34,7 @@ PgfDB *pgf_read_pgf(const char* fpath,
|
|||||||
{
|
{
|
||||||
PgfDB *db = NULL;
|
PgfDB *db = NULL;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
PGF_API_BEGIN {
|
||||||
|
|
||||||
try {
|
|
||||||
db = new PgfDB(NULL, 0, 0);
|
db = new PgfDB(NULL, 0, 0);
|
||||||
std::ifstream in(fpath, std::ios::binary);
|
std::ifstream in(fpath, std::ios::binary);
|
||||||
if (in.fail()) {
|
if (in.fail()) {
|
||||||
@@ -39,14 +52,7 @@ PgfDB *pgf_read_pgf(const char* fpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
} catch (pgf_systemerror& e) {
|
} PGF_API_END
|
||||||
err->type = PGF_EXN_SYSTEM_ERROR;
|
|
||||||
err->code = e.code();
|
|
||||||
err->msg = e.filepath();
|
|
||||||
} catch (pgf_error& e) {
|
|
||||||
err->type = PGF_EXN_PGF_ERROR;
|
|
||||||
err->msg = strdup(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (db != NULL)
|
if (db != NULL)
|
||||||
@@ -62,9 +68,7 @@ PgfDB *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
|||||||
{
|
{
|
||||||
PgfDB *db = NULL;
|
PgfDB *db = NULL;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
PGF_API_BEGIN {
|
||||||
|
|
||||||
try {
|
|
||||||
db = new PgfDB(ngf_path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
db = new PgfDB(ngf_path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
std::ifstream in(pgf_path, std::ios::binary);
|
std::ifstream in(pgf_path, std::ios::binary);
|
||||||
@@ -85,14 +89,7 @@ PgfDB *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
} catch (pgf_systemerror& e) {
|
} PGF_API_END
|
||||||
err->type = PGF_EXN_SYSTEM_ERROR;
|
|
||||||
err->code = e.code();
|
|
||||||
err->msg = e.filepath();
|
|
||||||
} catch (pgf_error& e) {
|
|
||||||
err->type = PGF_EXN_PGF_ERROR;
|
|
||||||
err->msg = strdup(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db != NULL) {
|
if (db != NULL) {
|
||||||
delete db;
|
delete db;
|
||||||
@@ -109,10 +106,8 @@ PgfDB *pgf_read_ngf(const char *fpath,
|
|||||||
{
|
{
|
||||||
PgfDB *db = NULL;
|
PgfDB *db = NULL;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
|
||||||
|
|
||||||
bool is_new = false;
|
bool is_new = false;
|
||||||
try {
|
PGF_API_BEGIN {
|
||||||
db = new PgfDB(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
db = new PgfDB(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -137,14 +132,7 @@ PgfDB *pgf_read_ngf(const char *fpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
} catch (pgf_systemerror& e) {
|
} PGF_API_END
|
||||||
err->type = PGF_EXN_SYSTEM_ERROR;
|
|
||||||
err->code = e.code();
|
|
||||||
err->msg = e.filepath();
|
|
||||||
} catch (pgf_error& e) {
|
|
||||||
err->type = PGF_EXN_PGF_ERROR;
|
|
||||||
err->msg = strdup(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db != NULL) {
|
if (db != NULL) {
|
||||||
delete db;
|
delete db;
|
||||||
@@ -167,29 +155,37 @@ void pgf_free_revision(PgfDB *pgf, PgfRevision revision)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfText *pgf_abstract_name(PgfDB *db, PgfRevision revision)
|
PgfText *pgf_abstract_name(PgfDB *db, PgfRevision revision,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
return textdup(&(*pgf->abstract.name));
|
return textdup(&(*pgf->abstract.name));
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
void pgf_iter_categories(PgfDB *db, PgfRevision revision,
|
void pgf_iter_categories(PgfDB *db, PgfRevision revision,
|
||||||
PgfItor *itor, PgfExn *err)
|
PgfItor *itor, PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
|
||||||
namespace_iter(pgf->abstract.cats, itor, err);
|
namespace_iter(pgf->abstract.cats, itor, err);
|
||||||
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfType pgf_start_cat(PgfDB *db, PgfRevision revision,
|
PgfType pgf_start_cat(PgfDB *db, PgfRevision revision,
|
||||||
PgfUnmarshaller *u)
|
PgfUnmarshaller *u,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -220,12 +216,17 @@ PgfType pgf_start_cat(PgfDB *db, PgfRevision revision,
|
|||||||
s->text[0] = 'S';
|
s->text[0] = 'S';
|
||||||
s->text[1] = 0;
|
s->text[1] = 0;
|
||||||
return u->dtyp(0,NULL,s,0,NULL);
|
return u->dtyp(0,NULL,s,0,NULL);
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision,
|
PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u)
|
PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -248,12 +249,18 @@ PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision,
|
|||||||
|
|
||||||
*n_hypos = abscat->context->len;
|
*n_hypos = abscat->context->len;
|
||||||
return hypos;
|
return hypos;
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
*n_hypos = 0;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
prob_t pgf_category_prob(PgfDB *db, PgfRevision revision,
|
prob_t pgf_category_prob(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *catname)
|
PgfText *catname,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -264,17 +271,22 @@ prob_t pgf_category_prob(PgfDB *db, PgfRevision revision,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return abscat->prob;
|
return abscat->prob;
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return INFINITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
void pgf_iter_functions(PgfDB *db, PgfRevision revision,
|
void pgf_iter_functions(PgfDB *db, PgfRevision revision,
|
||||||
PgfItor *itor, PgfExn *err)
|
PgfItor *itor, PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
pgf_exn_clear(err);
|
||||||
namespace_iter(pgf->abstract.funs, itor, err);
|
namespace_iter(pgf->abstract.funs, itor, err);
|
||||||
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PgfItorHelper : PgfItor
|
struct PgfItorHelper : PgfItor
|
||||||
@@ -297,6 +309,7 @@ PGF_API
|
|||||||
void pgf_iter_functions_by_cat(PgfDB *db, PgfRevision revision,
|
void pgf_iter_functions_by_cat(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *cat, PgfItor *itor, PgfExn *err)
|
PgfText *cat, PgfItor *itor, PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -305,14 +318,16 @@ void pgf_iter_functions_by_cat(PgfDB *db, PgfRevision revision,
|
|||||||
helper.cat = cat;
|
helper.cat = cat;
|
||||||
helper.itor = itor;
|
helper.itor = itor;
|
||||||
|
|
||||||
pgf_exn_clear(err);
|
|
||||||
namespace_iter(pgf->abstract.funs, &helper, err);
|
namespace_iter(pgf->abstract.funs, &helper, err);
|
||||||
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfType pgf_function_type(PgfDB *db, PgfRevision revision,
|
PgfType pgf_function_type(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname, PgfUnmarshaller *u)
|
PgfText *funname, PgfUnmarshaller *u,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -322,12 +337,17 @@ PgfType pgf_function_type(PgfDB *db, PgfRevision revision,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return PgfDBMarshaller().match_type(u, absfun->type.as_object());
|
return PgfDBMarshaller().match_type(u, absfun->type.as_object());
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
int pgf_function_is_constructor(PgfDB *db, PgfRevision revision,
|
int pgf_function_is_constructor(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname)
|
PgfText *funname,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -337,12 +357,17 @@ int pgf_function_is_constructor(PgfDB *db, PgfRevision revision,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (absfun->defns == 0);
|
return (absfun->defns == 0);
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
prob_t pgf_function_prob(PgfDB *db, PgfRevision revision,
|
prob_t pgf_function_prob(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname)
|
PgfText *funname,
|
||||||
|
PgfExn *err)
|
||||||
{
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = revision;
|
ref<PgfPGF> pgf = revision;
|
||||||
|
|
||||||
@@ -352,6 +377,9 @@ prob_t pgf_function_prob(PgfDB *db, PgfRevision revision,
|
|||||||
return INFINITY;
|
return INFINITY;
|
||||||
|
|
||||||
return absfun->ep.prob;
|
return absfun->ep.prob;
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return INFINITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
|
|||||||
@@ -248,7 +248,8 @@ PGF_API_DECL
|
|||||||
void pgf_free_revision(PgfDB *pgf, PgfRevision revision);
|
void pgf_free_revision(PgfDB *pgf, PgfRevision revision);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfText *pgf_abstract_name(PgfDB *db, PgfRevision revision);
|
PgfText *pgf_abstract_name(PgfDB *db, PgfRevision revision,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_iter_categories(PgfDB *db, PgfRevision revision,
|
void pgf_iter_categories(PgfDB *db, PgfRevision revision,
|
||||||
@@ -256,15 +257,18 @@ void pgf_iter_categories(PgfDB *db, PgfRevision revision,
|
|||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfType pgf_start_cat(PgfDB *db, PgfRevision revision,
|
PgfType pgf_start_cat(PgfDB *db, PgfRevision revision,
|
||||||
PgfUnmarshaller *u);
|
PgfUnmarshaller *u,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision,
|
PgfTypeHypo *pgf_category_context(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u);
|
PgfText *catname, size_t *n_hypos, PgfUnmarshaller *u,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
prob_t pgf_category_prob(PgfDB *db, PgfRevision revision,
|
prob_t pgf_category_prob(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *catname);
|
PgfText *catname,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_iter_functions(PgfDB *db, PgfRevision revision,
|
void pgf_iter_functions(PgfDB *db, PgfRevision revision,
|
||||||
@@ -276,15 +280,18 @@ void pgf_iter_functions_by_cat(PgfDB *db, PgfRevision revision,
|
|||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfType pgf_function_type(PgfDB *db, PgfRevision revision,
|
PgfType pgf_function_type(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname, PgfUnmarshaller *u);
|
PgfText *funname, PgfUnmarshaller *u,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
int pgf_function_is_constructor(PgfDB *db, PgfRevision revision,
|
int pgf_function_is_constructor(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname);
|
PgfText *funname,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
prob_t pgf_function_prob(PgfDB *db, PgfRevision revision,
|
prob_t pgf_function_prob(PgfDB *db, PgfRevision revision,
|
||||||
PgfText *funname);
|
PgfText *funname,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
typedef struct PgfPrintContext PgfPrintContext;
|
typedef struct PgfPrintContext PgfPrintContext;
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ abstractName p =
|
|||||||
unsafePerformIO $
|
unsafePerformIO $
|
||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
bracket (pgf_abstract_name c_db c_revision) free $ \c_text ->
|
bracket (withPgfExn (pgf_abstract_name c_db c_revision)) free $ \c_text ->
|
||||||
peekText c_text
|
peekText c_text
|
||||||
|
|
||||||
-- | The start category is defined in the grammar with
|
-- | The start category is defined in the grammar with
|
||||||
@@ -127,7 +127,7 @@ startCat p =
|
|||||||
withForeignPtr unmarshaller $ \u ->
|
withForeignPtr unmarshaller $ \u ->
|
||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision -> do
|
withForeignPtr (revision p) $ \c_revision -> do
|
||||||
c_typ <- pgf_start_cat c_db c_revision u
|
c_typ <- withPgfExn (pgf_start_cat c_db c_revision u)
|
||||||
typ <- deRefStablePtr c_typ
|
typ <- deRefStablePtr c_typ
|
||||||
freeStablePtr c_typ
|
freeStablePtr c_typ
|
||||||
return typ
|
return typ
|
||||||
@@ -140,7 +140,7 @@ functionType p fn =
|
|||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
withText fn $ \c_fn -> do
|
withText fn $ \c_fn -> do
|
||||||
c_typ <- pgf_function_type c_db c_revision c_fn u
|
c_typ <- withPgfExn (pgf_function_type c_db c_revision c_fn u)
|
||||||
if c_typ == castPtrToStablePtr nullPtr
|
if c_typ == castPtrToStablePtr nullPtr
|
||||||
then return Nothing
|
then return Nothing
|
||||||
else do typ <- deRefStablePtr c_typ
|
else do typ <- deRefStablePtr c_typ
|
||||||
@@ -153,7 +153,7 @@ functionIsConstructor p fun =
|
|||||||
withText fun $ \c_fun ->
|
withText fun $ \c_fun ->
|
||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
do res <- pgf_function_is_constructor c_db c_revision c_fun
|
do res <- withPgfExn (pgf_function_is_constructor c_db c_revision c_fun)
|
||||||
return (res /= 0)
|
return (res /= 0)
|
||||||
|
|
||||||
functionProb :: PGF -> Fun -> Float
|
functionProb :: PGF -> Fun -> Float
|
||||||
@@ -162,8 +162,7 @@ functionProb p fun =
|
|||||||
withText fun $ \c_fun ->
|
withText fun $ \c_fun ->
|
||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
do c_prob <- pgf_function_prob c_db c_revision c_fun
|
withPgfExn (pgf_function_prob c_db c_revision c_fun)
|
||||||
return (realToFrac c_prob)
|
|
||||||
|
|
||||||
-- | List of all functions defined in the abstract syntax
|
-- | List of all functions defined in the abstract syntax
|
||||||
categories :: PGF -> [Cat]
|
categories :: PGF -> [Cat]
|
||||||
@@ -194,7 +193,7 @@ categoryContext p cat =
|
|||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
mask_ $ do
|
mask_ $ do
|
||||||
c_hypos <- pgf_category_context c_db c_revision c_cat p_n_hypos u
|
c_hypos <- withPgfExn (pgf_category_context c_db c_revision c_cat p_n_hypos u)
|
||||||
if c_hypos == nullPtr
|
if c_hypos == nullPtr
|
||||||
then return []
|
then return []
|
||||||
else do n_hypos <- peek p_n_hypos
|
else do n_hypos <- peek p_n_hypos
|
||||||
@@ -221,8 +220,7 @@ categoryProb p cat =
|
|||||||
withText cat $ \c_cat ->
|
withText cat $ \c_cat ->
|
||||||
withForeignPtr (a_db p) $ \c_db ->
|
withForeignPtr (a_db p) $ \c_db ->
|
||||||
withForeignPtr (revision p) $ \c_revision ->
|
withForeignPtr (revision p) $ \c_revision ->
|
||||||
do c_prob <- pgf_category_prob c_db c_revision c_cat
|
withPgfExn (pgf_category_prob c_db c_revision c_cat)
|
||||||
return (realToFrac c_prob)
|
|
||||||
|
|
||||||
-- | List of all functions defined in the abstract syntax
|
-- | List of all functions defined in the abstract syntax
|
||||||
functions :: PGF -> [Fun]
|
functions :: PGF -> [Fun]
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ foreign import ccall "pgf_free_revision"
|
|||||||
pgf_free_revision :: Ptr PgfDB -> Ptr PgfRevision -> IO ()
|
pgf_free_revision :: Ptr PgfDB -> Ptr PgfRevision -> IO ()
|
||||||
|
|
||||||
foreign import ccall "pgf_abstract_name"
|
foreign import ccall "pgf_abstract_name"
|
||||||
pgf_abstract_name :: Ptr PgfDB -> Ptr PgfRevision -> IO (Ptr PgfText)
|
pgf_abstract_name :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||||
|
|
||||||
foreign import ccall "pgf_print_expr"
|
foreign import ccall "pgf_print_expr"
|
||||||
pgf_print_expr :: StablePtr Expr -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
|
pgf_print_expr :: StablePtr Expr -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
|
||||||
@@ -85,13 +85,13 @@ foreign import ccall "pgf_iter_categories"
|
|||||||
pgf_iter_categories :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
pgf_iter_categories :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
foreign import ccall "pgf_start_cat"
|
foreign import ccall "pgf_start_cat"
|
||||||
pgf_start_cat :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfUnmarshaller -> IO (StablePtr Type)
|
pgf_start_cat :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO (StablePtr Type)
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_category_context"
|
foreign import ccall "pgf/pgf.h pgf_category_context"
|
||||||
pgf_category_context :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr CSize -> Ptr PgfUnmarshaller -> IO (Ptr PgfTypeHypo)
|
pgf_category_context :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr CSize -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO (Ptr PgfTypeHypo)
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_category_prob"
|
foreign import ccall "pgf/pgf.h pgf_category_prob"
|
||||||
pgf_category_prob :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> IO (#type prob_t)
|
pgf_category_prob :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfExn -> IO (#type prob_t)
|
||||||
|
|
||||||
foreign import ccall "pgf_iter_functions"
|
foreign import ccall "pgf_iter_functions"
|
||||||
pgf_iter_functions :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
pgf_iter_functions :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||||
@@ -99,14 +99,14 @@ foreign import ccall "pgf_iter_functions"
|
|||||||
foreign import ccall "pgf_iter_functions_by_cat"
|
foreign import ccall "pgf_iter_functions_by_cat"
|
||||||
pgf_iter_functions_by_cat :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
pgf_iter_functions_by_cat :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_function_type"
|
foreign import ccall "pgf_function_type"
|
||||||
pgf_function_type :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Type)
|
pgf_function_type :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO (StablePtr Type)
|
||||||
|
|
||||||
foreign import ccall "pgf/expr.h pgf_function_is_constructor"
|
foreign import ccall "pgf_function_is_constructor"
|
||||||
pgf_function_is_constructor :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> IO (#type int)
|
pgf_function_is_constructor :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfExn -> IO (#type int)
|
||||||
|
|
||||||
foreign import ccall "pgf_function_prob"
|
foreign import ccall "pgf_function_prob"
|
||||||
pgf_function_prob :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> IO (#type prob_t)
|
pgf_function_prob :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfText -> Ptr PgfExn -> IO (#type prob_t)
|
||||||
|
|
||||||
foreign import ccall "pgf_clone_revision"
|
foreign import ccall "pgf_clone_revision"
|
||||||
pgf_clone_revision :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfExn -> IO (Ptr PgfRevision)
|
pgf_clone_revision :: Ptr PgfDB -> Ptr PgfRevision -> Ptr PgfExn -> IO (Ptr PgfRevision)
|
||||||
|
|||||||
Reference in New Issue
Block a user