mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
throw away the long obsolete runtime type information in the C runtime
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "data.h"
|
||||
#include <gu/type.h>
|
||||
#include <gu/variant.h>
|
||||
#include <gu/assert.h>
|
||||
#include <math.h>
|
||||
@@ -22,18 +21,6 @@ pgf_tokens_equal(PgfTokens* t1, PgfTokens* t2)
|
||||
return true;
|
||||
}
|
||||
|
||||
GU_DEFINE_TYPE(PgfCId, typedef, gu_type(GuString));
|
||||
|
||||
#define gu_type__PgfCIdMap gu_type__GuStringMap
|
||||
typedef GuType_GuStringMap GuType_PgfCIdMap;
|
||||
#define GU_TYPE_INIT_PgfCIdMap GU_TYPE_INIT_GuStringMap
|
||||
|
||||
GU_DEFINE_TYPE(PgfCCat, abstract);
|
||||
|
||||
GU_DEFINE_TYPE(PgfCncCat, abstract);
|
||||
|
||||
GU_DEFINE_TYPE(PgfDummyVariant, GuVariant);
|
||||
|
||||
static int
|
||||
pgf_flag_cmp_fn(GuOrder* self, const void* p1, const void* p2)
|
||||
{
|
||||
@@ -43,20 +30,6 @@ pgf_flag_cmp_fn(GuOrder* self, const void* p1, const void* p2)
|
||||
|
||||
GuOrder pgf_flag_order[1] = { { pgf_flag_cmp_fn } };
|
||||
|
||||
|
||||
GU_DEFINE_TYPE(PgfProductionSeq, abstract);
|
||||
GU_DEFINE_TYPE(PgfProductionBuf, abstract);
|
||||
|
||||
static prob_t inf_prob = INFINITY;
|
||||
|
||||
GU_DEFINE_TYPE(prob_t, GuFloating, _);
|
||||
|
||||
GU_DEFINE_TYPE(PgfMetaChildMap, GuMap,
|
||||
gu_type(PgfAbsCat), NULL,
|
||||
gu_type(prob_t), &inf_prob);
|
||||
|
||||
GU_DEFINE_TYPE(PgfAbsCat, abstract);
|
||||
|
||||
static int
|
||||
pgf_abscat_cmp_fn(GuOrder* self, const void* p1, const void* p2)
|
||||
{
|
||||
@@ -75,12 +48,6 @@ pgf_absfun_cmp_fn(GuOrder* self, const void* p1, const void* p2)
|
||||
|
||||
GuOrder pgf_absfun_order[1] = { { pgf_absfun_cmp_fn } };
|
||||
|
||||
|
||||
static GuString empty_string = "";
|
||||
|
||||
GU_DEFINE_TYPE(
|
||||
PgfPrintNames, PgfCIdMap, gu_type(GuString), &empty_string);
|
||||
|
||||
static int
|
||||
pgf_concr_cmp_fn(GuOrder* self, const void* p1, const void* p2)
|
||||
{
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
#include <gu/variant.h>
|
||||
#include <gu/map.h>
|
||||
#include <gu/string.h>
|
||||
#include <gu/type.h>
|
||||
#include <gu/seq.h>
|
||||
#include <pgf/pgf.h>
|
||||
|
||||
typedef struct PgfCCat PgfCCat;
|
||||
extern GU_DECLARE_TYPE(PgfCCat, abstract);
|
||||
|
||||
typedef GuSeq PgfCCats;
|
||||
|
||||
@@ -41,7 +39,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
PgfCId ctor;
|
||||
GuLength n_args;
|
||||
size_t n_args;
|
||||
PgfPatt args[];
|
||||
} PgfPattApp;
|
||||
|
||||
@@ -70,7 +68,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
PgfExpr body;
|
||||
GuLength n_patts;
|
||||
size_t n_patts;
|
||||
PgfPatt patts[];
|
||||
} PgfEquation;
|
||||
|
||||
@@ -99,7 +97,6 @@ typedef GuSeq PgfAbsFuns;
|
||||
extern GuOrder pgf_absfun_order[1];
|
||||
|
||||
typedef GuMap PgfMetaChildMap;
|
||||
extern GU_DECLARE_TYPE(PgfMetaChildMap, GuMap);
|
||||
|
||||
typedef struct {
|
||||
PgfCId name;
|
||||
@@ -110,8 +107,6 @@ typedef struct {
|
||||
void* predicate;
|
||||
} PgfAbsCat;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfAbsCat, abstract);
|
||||
|
||||
typedef GuSeq PgfAbsCats;
|
||||
|
||||
extern GuOrder pgf_abscat_order[1];
|
||||
@@ -171,8 +166,6 @@ typedef struct {
|
||||
* represents. */
|
||||
} PgfCncCat;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfCncCat, abstract);
|
||||
|
||||
typedef GuSeq PgfTokens;
|
||||
|
||||
bool
|
||||
@@ -192,18 +185,14 @@ typedef struct {
|
||||
typedef struct PgfItemConts PgfItemConts;
|
||||
|
||||
typedef PgfCIdMap PgfPrintNames;
|
||||
extern GU_DECLARE_TYPE(PgfPrintNames, GuStringMap);
|
||||
|
||||
typedef GuStringMap PgfCncFunOverloadMap;
|
||||
extern GU_DECLARE_TYPE(PgfCncFunOverloadMap, GuStringMap);
|
||||
|
||||
typedef GuMap PgfCncOverloadMap;
|
||||
extern GU_DECLARE_TYPE(PgfCncOverloadMap, GuMap);
|
||||
|
||||
typedef struct PgfItem PgfItem;
|
||||
|
||||
typedef GuMap PgfCallbacksMap;
|
||||
extern GU_DECLARE_TYPE(PgfCallbacksMap, GuMap);
|
||||
|
||||
typedef GuVariant PgfSymbol;
|
||||
|
||||
@@ -237,7 +226,7 @@ typedef struct PgfSymbolKP
|
||||
/**< Default form that this symbol takes if none of of the
|
||||
* variant forms is triggered. */
|
||||
|
||||
GuLength n_forms;
|
||||
size_t n_forms;
|
||||
PgfAlternative forms[];
|
||||
/**< Variant forms whose choise depends on the following
|
||||
* symbol. */
|
||||
@@ -262,7 +251,7 @@ typedef struct {
|
||||
PgfAbsFun* absfun;
|
||||
PgfExprProb *ep;
|
||||
int funid;
|
||||
GuLength n_lins;
|
||||
size_t n_lins;
|
||||
PgfSequence* lins[];
|
||||
} PgfCncFun;
|
||||
|
||||
@@ -331,7 +320,6 @@ typedef struct {
|
||||
} PgfProductionMeta;
|
||||
|
||||
typedef GuSeq PgfProductionSeq;
|
||||
extern GU_DECLARE_TYPE(PgfProductionSeq, abstract);
|
||||
|
||||
typedef struct {
|
||||
PgfCCat* ccat;
|
||||
|
||||
@@ -73,57 +73,6 @@ pgf_expr_unapply(PgfExpr expr, GuPool* pool)
|
||||
return appl;
|
||||
}
|
||||
|
||||
GU_DEFINE_TYPE(PgfBindType, enum,
|
||||
GU_ENUM_C(PgfBindType, PGF_BIND_TYPE_EXPLICIT),
|
||||
GU_ENUM_C(PgfBindType, PGF_BIND_TYPE_IMPLICIT));
|
||||
|
||||
GU_DEFINE_TYPE(PgfLiteral, GuVariant,
|
||||
GU_CONSTRUCTOR_S(PGF_LITERAL_STR, PgfLiteralStr,
|
||||
GU_MEMBER(PgfLiteralStr, val, GuString)),
|
||||
GU_CONSTRUCTOR_S(PGF_LITERAL_INT, PgfLiteralInt,
|
||||
GU_MEMBER(PgfLiteralInt, val, int)),
|
||||
GU_CONSTRUCTOR_S(PGF_LITERAL_FLT, PgfLiteralFlt,
|
||||
GU_MEMBER(PgfLiteralFlt, val, double)));
|
||||
|
||||
GU_DECLARE_TYPE(PgfType, struct);
|
||||
|
||||
GU_DEFINE_TYPE(PgfHypo, struct,
|
||||
GU_MEMBER(PgfHypo, bind_type, PgfBindType),
|
||||
GU_MEMBER(PgfHypo, cid, PgfCId),
|
||||
GU_MEMBER_P(PgfHypo, type, PgfType));
|
||||
|
||||
GU_DEFINE_TYPE(
|
||||
PgfExpr, GuVariant,
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_ABS, PgfExprAbs,
|
||||
GU_MEMBER(PgfExprAbs, bind_type, PgfBindType),
|
||||
GU_MEMBER(PgfExprAbs, id, GuString),
|
||||
GU_MEMBER(PgfExprAbs, body, PgfExpr)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_APP, PgfExprApp,
|
||||
GU_MEMBER(PgfExprApp, fun, PgfExpr),
|
||||
GU_MEMBER(PgfExprApp, arg, PgfExpr)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_LIT, PgfExprLit,
|
||||
GU_MEMBER(PgfExprLit, lit, PgfLiteral)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_META, PgfExprMeta,
|
||||
GU_MEMBER(PgfExprMeta, id, int)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_FUN, PgfExprFun,
|
||||
GU_MEMBER(PgfExprFun, fun, GuString)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_VAR, PgfExprVar,
|
||||
GU_MEMBER(PgfExprVar, var, int)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_TYPED, PgfExprTyped,
|
||||
GU_MEMBER(PgfExprTyped, expr, PgfExpr),
|
||||
GU_MEMBER_P(PgfExprTyped, type, PgfType)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_IMPL_ARG, PgfExprImplArg,
|
||||
GU_MEMBER(PgfExprImplArg, expr, PgfExpr)));
|
||||
|
||||
|
||||
typedef struct PgfExprParser PgfExprParser;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
/// An abstract syntax tree
|
||||
typedef GuVariant PgfExpr;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfExpr, GuVariant);
|
||||
|
||||
typedef struct PgfHypo PgfHypo;
|
||||
typedef struct PgfType PgfType;
|
||||
|
||||
@@ -128,8 +126,6 @@ typedef struct {
|
||||
PgfExpr expr;
|
||||
} PgfExprProb;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfExprProb, struct);
|
||||
|
||||
int
|
||||
pgf_expr_arity(PgfExpr expr);
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ pgf_jit_predicate(PgfReader* rdr, PgfAbstr* abstr,
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
gu_string_write(abscat->name, out, err);
|
||||
gu_puts(":\n", out, err);
|
||||
@@ -637,7 +637,7 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr,
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
gu_string_write(absfun->name, out, err);
|
||||
gu_puts(":\n", out, err);
|
||||
@@ -873,7 +873,7 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr,
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
GuLength len = pgf_read_len(rdr);
|
||||
size_t len = pgf_read_len(rdr);
|
||||
uint8_t* buf = alloca(len*6+1);
|
||||
uint8_t* p = buf;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
|
||||
@@ -13,13 +13,6 @@
|
||||
|
||||
//#define PGF_LINEARIZER_DEBUG
|
||||
|
||||
GU_DEFINE_TYPE(PgfCncOverloadMap, GuMap,
|
||||
gu_type(PgfCCat), NULL,
|
||||
gu_ptr_type(GuBuf), &gu_null_struct);
|
||||
|
||||
GU_DEFINE_TYPE(PgfCncFunOverloadMap, GuStringMap, gu_ptr_type(PgfCncOverloadMap),
|
||||
&gu_null_struct);
|
||||
|
||||
static void
|
||||
pgf_lzr_add_overl_entry(PgfCncOverloadMap* overl_table,
|
||||
PgfCCat* ccat, void* entry,
|
||||
@@ -48,7 +41,7 @@ pgf_lzr_index(PgfConcr* concr,
|
||||
gu_map_get(concr->fun_indices, papply->fun->absfun->name,
|
||||
PgfCncOverloadMap*);
|
||||
if (!overl_table) {
|
||||
overl_table = gu_map_type_new(PgfCncOverloadMap, pool);
|
||||
overl_table = gu_new_addr_map(PgfCCat*, GuBuf*, &gu_null_struct, pool);
|
||||
gu_map_put(concr->fun_indices,
|
||||
papply->fun->absfun->name, PgfCncOverloadMap*, overl_table);
|
||||
}
|
||||
@@ -100,7 +93,7 @@ typedef struct {
|
||||
size_t n_vars;
|
||||
PgfPrintContext* context;
|
||||
|
||||
GuLength n_args;
|
||||
size_t n_args;
|
||||
PgfCncTree args[];
|
||||
} PgfCncTreeChunks;
|
||||
|
||||
@@ -463,7 +456,7 @@ pgf_cnc_resolve(PgfCnc* cnc,
|
||||
}
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
|
||||
GuExn* err = gu_new_exn(tmp_pool);
|
||||
GuStringBuf* sbuf = gu_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
|
||||
@@ -600,7 +593,7 @@ pgf_cnc_tree_enum_next(GuEnum* self, void* to, GuPool* pool)
|
||||
#ifdef PGF_LINEARIZER_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
if (gu_variant_is_null(*toc))
|
||||
gu_puts("*nil*\n", out, err);
|
||||
else {
|
||||
@@ -1034,8 +1027,6 @@ struct PgfSimpleLin {
|
||||
GuExn* err;
|
||||
};
|
||||
|
||||
GU_DEFINE_TYPE(PgfLinNonExist, abstract, _);
|
||||
|
||||
static void
|
||||
pgf_file_lzn_put_space(PgfSimpleLin* flin)
|
||||
{
|
||||
@@ -1145,7 +1136,7 @@ GuString
|
||||
pgf_get_tokens(PgfSymbols* syms, uint16_t sym_idx, GuPool* pool)
|
||||
{
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
|
||||
GuExn* err = gu_new_exn(tmp_pool);
|
||||
GuStringBuf* sbuf = gu_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef PGF_LINEARIZER_H_
|
||||
#define PGF_LINEARIZER_H_
|
||||
|
||||
#include <gu/type.h>
|
||||
#include <gu/enum.h>
|
||||
|
||||
/// Linearization of abstract syntax trees.
|
||||
@@ -32,8 +31,6 @@ pgf_lzr_concretize(PgfConcr* concr, PgfExpr expr, GuExn* err, GuPool* pool);
|
||||
typedef struct {
|
||||
} PgfLinNonExist;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfLinNonExist, abstract);
|
||||
|
||||
PgfCncTree
|
||||
pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool);
|
||||
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
#include <pgf/literals.h>
|
||||
#include <wctype.h>
|
||||
|
||||
GU_DEFINE_TYPE(PgfLiteralCallback, struct);
|
||||
|
||||
GU_DEFINE_TYPE(PgfCallbacksMap, GuMap,
|
||||
gu_type(PgfCncCat), NULL,
|
||||
gu_ptr_type(PgfLiteralCallback), &gu_null_struct);
|
||||
|
||||
|
||||
static PgfExprProb*
|
||||
pgf_match_string_lit(PgfLiteralCallback* self,
|
||||
@@ -185,7 +179,7 @@ pgf_match_name_lit(PgfLiteralCallback* self,
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuStringBuf *sbuf = gu_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
|
||||
GuExn* err = gu_new_exn(tmp_pool);
|
||||
|
||||
size_t offset = *poffset;
|
||||
|
||||
@@ -258,8 +252,8 @@ pgf_new_callbacks_map(PgfConcr* concr, GuPool *pool)
|
||||
PgfCCat* ccat;
|
||||
|
||||
PgfCallbacksMap* callbacks =
|
||||
gu_map_type_new(PgfCallbacksMap, pool);
|
||||
|
||||
gu_new_addr_map(PgfCncCat*, PgfLiteralCallback*, &gu_null_struct, pool);
|
||||
|
||||
fid = -1;
|
||||
ccat = gu_map_get(concr->ccats, &fid, PgfCCat*);
|
||||
if (ccat != NULL)
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
//#define PGF_RESULT_DEBUG
|
||||
|
||||
typedef GuBuf PgfItemBuf;
|
||||
static GU_DEFINE_TYPE(PgfItemBuf, abstract, _);
|
||||
|
||||
typedef struct PgfParseState PgfParseState;
|
||||
|
||||
@@ -26,20 +25,9 @@ struct PgfItemConts {
|
||||
int ref_count; // how many items point to this cont?
|
||||
};
|
||||
|
||||
static GU_DEFINE_TYPE(PgfItemConts, abstract, _);
|
||||
|
||||
typedef GuSeq PgfItemContss;
|
||||
static GU_DEFINE_TYPE(PgfItemContss, abstract);
|
||||
|
||||
typedef GuMap PgfContsMap;
|
||||
static GU_DEFINE_TYPE(PgfContsMap, GuMap,
|
||||
gu_type(PgfCCat), NULL,
|
||||
gu_ptr_type(PgfItemContss), &gu_null_struct);
|
||||
|
||||
typedef GuMap PgfGenCatMap;
|
||||
static GU_DEFINE_TYPE(PgfGenCatMap, GuMap,
|
||||
gu_type(PgfItemConts), NULL,
|
||||
gu_ptr_type(PgfCCat), &gu_null_struct);
|
||||
|
||||
typedef GuBuf PgfCCatBuf;
|
||||
|
||||
@@ -1045,7 +1033,7 @@ pgf_parsing_complete(PgfParsing* ps, PgfItem* item, PgfExprProb *ep)
|
||||
#ifdef PGF_PARSER_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
if (tmp_ccat == NULL) {
|
||||
gu_printf(out, err, "[");
|
||||
pgf_print_range(item->conts->state, ps->before, out, err);
|
||||
@@ -1293,8 +1281,8 @@ pgf_new_parse_state(PgfParsing* ps, size_t start_offset, BIND_TYPE bind_type)
|
||||
state->next = *pstate;
|
||||
state->agenda = gu_new_buf(PgfItem*, ps->pool);
|
||||
state->meta_item = NULL;
|
||||
state->generated_cats = gu_map_type_new(PgfGenCatMap, ps->pool);
|
||||
state->conts_map = gu_map_type_new(PgfContsMap, ps->pool);
|
||||
state->generated_cats = gu_new_addr_map(PgfItemConts*, PgfCCat*, &gu_null_struct, ps->pool);
|
||||
state->conts_map = gu_new_addr_map(PgfCCat*, PgfItemContss*, &gu_null_struct, ps->pool);
|
||||
state->needs_bind = (bind_type == BIND_NONE) &&
|
||||
(start_offset == end_offset);
|
||||
state->start_offset = start_offset;
|
||||
@@ -1742,7 +1730,7 @@ pgf_parsing_item(PgfParsing* ps, PgfItem* item)
|
||||
#ifdef PGF_PARSER_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
pgf_print_item(item, ps->before, out, err, tmp_pool);
|
||||
gu_pool_free(tmp_pool);
|
||||
#endif
|
||||
@@ -2230,7 +2218,7 @@ pgf_parse_result_next(PgfParsing* ps)
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuWriter* wtr = gu_new_utf8_writer(out, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
pgf_print_expr_state0(st, wtr, err, tmp_pool);
|
||||
gu_pool_free(tmp_pool);
|
||||
#endif
|
||||
@@ -2316,8 +2304,6 @@ pgf_parsing_last_token(PgfParsing* ps, GuPool* pool)
|
||||
return tok;
|
||||
}
|
||||
|
||||
GU_DEFINE_TYPE(PgfParseError, abstract, _);
|
||||
|
||||
GuEnum*
|
||||
pgf_parse(PgfConcr* concr, PgfCId cat, GuString sentence,
|
||||
GuExn* err,
|
||||
|
||||
@@ -132,7 +132,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
||||
{
|
||||
GuPool* pool = gu_new_pool();
|
||||
|
||||
GuExn* err = gu_new_exn(NULL, gu_kind(type), pool);
|
||||
GuExn* err = gu_new_exn(pool);
|
||||
|
||||
GuEnum* en_lins1 =
|
||||
pgf_lzr_concretize(concr, expr, err, pool);
|
||||
@@ -153,7 +153,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
||||
PgfMetricsLznState state;
|
||||
state.bind = true;
|
||||
state.out = gu_string_buf_out(sbuf);
|
||||
state.err = gu_new_exn(NULL, gu_kind(type), pool);
|
||||
state.err = gu_new_exn(pool);
|
||||
state.funcs = &pgf_metrics_lin_funcs1;
|
||||
state.pos = 0;
|
||||
state.marks = gu_new_buf(int, pool);
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
GU_DEFINE_TYPE(PgfExn, abstract, _);
|
||||
|
||||
PgfPGF*
|
||||
pgf_read(const char* fpath,
|
||||
GuPool* pool, GuExn* err)
|
||||
@@ -47,7 +45,7 @@ pgf_iter_languages(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
|
||||
size_t n_concrs = gu_seq_length(pgf->concretes);
|
||||
for (size_t i = 0; i < n_concrs; i++) {
|
||||
PgfConcr* concr = gu_seq_index(pgf->concretes, PgfConcr, i);
|
||||
itor->fn(itor, concr->name, concr, err);
|
||||
itor->fn(itor, concr->name, &concr, err);
|
||||
if (!gu_ok(err))
|
||||
break;
|
||||
}
|
||||
@@ -71,7 +69,7 @@ pgf_iter_categories(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
|
||||
size_t n_cats = gu_seq_length(pgf->abstract.cats);
|
||||
for (size_t i = 0; i < n_cats; i++) {
|
||||
PgfAbsCat* cat = gu_seq_index(pgf->abstract.cats, PgfAbsCat, i);
|
||||
itor->fn(itor, cat->name, cat, err);
|
||||
itor->fn(itor, cat->name, &cat, err);
|
||||
if (!gu_ok(err))
|
||||
break;
|
||||
}
|
||||
@@ -123,7 +121,7 @@ pgf_iter_functions(PgfPGF* pgf, GuMapItor* itor, GuExn* err)
|
||||
size_t n_funs = gu_seq_length(pgf->abstract.funs);
|
||||
for (size_t i = 0; i < n_funs; i++) {
|
||||
PgfAbsFun* fun = gu_seq_index(pgf->abstract.funs, PgfAbsFun, i);
|
||||
itor->fn(itor, fun->name, fun, err);
|
||||
itor->fn(itor, fun->name, &fun, err);
|
||||
if (!gu_ok(err))
|
||||
break;
|
||||
}
|
||||
@@ -138,7 +136,7 @@ pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
|
||||
PgfAbsFun* fun = gu_seq_index(pgf->abstract.funs, PgfAbsFun, i);
|
||||
|
||||
if (strcmp(fun->type->cid, catname) == 0) {
|
||||
itor->fn(itor, fun->name, fun, err);
|
||||
itor->fn(itor, fun->name, &fun, err);
|
||||
if (!gu_ok(err))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,9 @@
|
||||
|
||||
|
||||
typedef GuString PgfCId;
|
||||
extern GU_DECLARE_TYPE(PgfCId, typedef);
|
||||
|
||||
typedef GuString PgfToken;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfExn, abstract);
|
||||
extern GU_DECLARE_TYPE(PgfParseError, abstract);
|
||||
extern GU_DECLARE_TYPE(PgfTypeError, abstract);
|
||||
|
||||
typedef struct PgfPGF PgfPGF;
|
||||
|
||||
typedef struct PgfConcr PgfConcr;
|
||||
|
||||
@@ -25,14 +25,9 @@
|
||||
typedef struct PgfReadTagExn PgfReadTagExn;
|
||||
|
||||
struct PgfReadTagExn {
|
||||
GuType* type;
|
||||
int tag;
|
||||
};
|
||||
|
||||
static GU_DEFINE_TYPE(PgfReadTagExn, abstract, _);
|
||||
|
||||
static GU_DEFINE_TYPE(PgfReadExn, abstract, _);
|
||||
|
||||
uint8_t
|
||||
pgf_read_tag(PgfReader* rdr)
|
||||
{
|
||||
@@ -73,7 +68,6 @@ pgf_read_len(PgfReader* rdr)
|
||||
GuExnData* err_data = gu_raise(rdr->err, PgfReadTagExn);
|
||||
if (err_data) {
|
||||
PgfReadTagExn* rtag = gu_new(PgfReadTagExn, err_data->pool);
|
||||
rtag->type = gu_type(GuLength);
|
||||
rtag->tag = len;
|
||||
err_data->data = rtag;
|
||||
}
|
||||
@@ -93,7 +87,7 @@ pgf_read_cid(PgfReader* rdr, GuPool* pool)
|
||||
GuString
|
||||
pgf_read_string(PgfReader* rdr)
|
||||
{
|
||||
GuLength len = pgf_read_len(rdr);
|
||||
size_t len = pgf_read_len(rdr);
|
||||
return gu_string_read(len, rdr->opool, rdr->in, rdr->err);
|
||||
}
|
||||
|
||||
@@ -117,7 +111,7 @@ pgf_read_literal(PgfReader* rdr)
|
||||
uint8_t tag = pgf_read_tag(rdr);
|
||||
switch (tag) {
|
||||
case PGF_LITERAL_STR: {
|
||||
GuLength len = pgf_read_len(rdr);
|
||||
size_t len = pgf_read_len(rdr);
|
||||
uint8_t* buf = alloca(len*6+1);
|
||||
uint8_t* p = buf;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@@ -159,7 +153,7 @@ pgf_read_literal(PgfReader* rdr)
|
||||
static PgfFlags*
|
||||
pgf_read_flags(PgfReader* rdr)
|
||||
{
|
||||
GuLength n_flags = pgf_read_len(rdr);
|
||||
size_t n_flags = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfFlags* flags = gu_new_seq(PgfFlag, n_flags, rdr->opool);
|
||||
@@ -447,20 +441,20 @@ pgf_read_absfun(PgfReader* rdr, PgfAbstr* abstr, PgfAbsFun* absfun)
|
||||
}
|
||||
break;
|
||||
case 1: {
|
||||
GuLength length = pgf_read_len(rdr);
|
||||
size_t length = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
absfun->defns = gu_new_seq(PgfEquation*, length, rdr->opool);
|
||||
PgfEquation** data = gu_seq_data(absfun->defns);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
GuLength n_patts = pgf_read_len(rdr);
|
||||
size_t n_patts = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfEquation *equ =
|
||||
gu_malloc(rdr->opool,
|
||||
sizeof(PgfEquation)+sizeof(PgfPatt)*n_patts);
|
||||
equ->n_patts = n_patts;
|
||||
for (GuLength j = 0; j < n_patts; j++) {
|
||||
for (size_t j = 0; j < n_patts; j++) {
|
||||
equ->patts[j] = pgf_read_patt(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
}
|
||||
@@ -470,7 +464,7 @@ pgf_read_absfun(PgfReader* rdr, PgfAbstr* abstr, PgfAbsFun* absfun)
|
||||
data[i] = equ;
|
||||
}
|
||||
|
||||
// pgf_jit_function(rdr, abstr, absfun);
|
||||
// pgf_jit_function(rdr, abstr, absfun);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -571,11 +565,7 @@ pgf_read_abstract(PgfReader* rdr, PgfAbstr* abstract)
|
||||
static PgfCIdMap*
|
||||
pgf_read_printnames(PgfReader* rdr)
|
||||
{
|
||||
GuMapType* map_type = (GuMapType*)
|
||||
GU_TYPE_LIT(GuStringMap, _,
|
||||
gu_type(GuString),
|
||||
&"");
|
||||
PgfCIdMap* printnames = gu_map_type_make(map_type, rdr->opool);
|
||||
PgfCIdMap* printnames = gu_new_string_map(GuString, &"", rdr->opool);
|
||||
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
@@ -661,7 +651,7 @@ pgf_read_symbol(PgfReader* rdr)
|
||||
break;
|
||||
}
|
||||
case PGF_SYMBOL_KS: {
|
||||
GuLength len = pgf_read_len(rdr);
|
||||
size_t len = pgf_read_len(rdr);
|
||||
uint8_t* buf = alloca(len*6+1);
|
||||
uint8_t* p = buf;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@@ -990,7 +980,7 @@ pgf_read_ccats(PgfReader* rdr, PgfConcr* concr)
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfCCat* ccat = pgf_read_fid(rdr, concr);
|
||||
|
||||
GuLength n_prods = pgf_read_len(rdr);
|
||||
size_t n_prods = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err,);
|
||||
|
||||
ccat->prods = gu_new_seq(PgfProduction, n_prods, rdr->opool);
|
||||
@@ -1056,11 +1046,7 @@ pgf_read_cnccat(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, PgfCId name)
|
||||
static PgfCIdMap*
|
||||
pgf_read_cnccats(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr)
|
||||
{
|
||||
GuMapType* map_type = (GuMapType*)
|
||||
GU_TYPE_LIT(GuStringMap, _,
|
||||
gu_ptr_type(PgfCncCat),
|
||||
&gu_null_struct);
|
||||
PgfCIdMap* cnccats = gu_map_type_make(map_type, rdr->opool);
|
||||
PgfCIdMap* cnccats = gu_new_string_map(PgfCncCat, &gu_null_struct, rdr->opool);
|
||||
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
@@ -1149,8 +1135,8 @@ pgf_read_concrete_content(PgfReader* rdr, PgfConcr* concr)
|
||||
|
||||
concr->ccats =
|
||||
gu_new_int_map(PgfCCat*, &gu_null_struct, rdr->opool);
|
||||
concr->fun_indices = gu_map_type_new(PgfCncFunOverloadMap, rdr->opool);
|
||||
concr->coerce_idx = gu_map_type_new(PgfCncOverloadMap, rdr->opool);
|
||||
concr->fun_indices = gu_new_string_map(PgfCncOverloadMap*, &gu_null_struct, rdr->opool);
|
||||
concr->coerce_idx = gu_new_addr_map(PgfCCat*, GuBuf*, &gu_null_struct, rdr->opool);
|
||||
pgf_read_lindefs(rdr, concr);
|
||||
pgf_read_linrefs(rdr, concr);
|
||||
pgf_read_ccats(rdr, concr);
|
||||
|
||||
@@ -58,11 +58,7 @@ typedef struct {
|
||||
size_t choice;
|
||||
} PgfCombine2State;
|
||||
|
||||
static GU_DEFINE_TYPE(PgfAnswers, abstract);
|
||||
|
||||
typedef GuStringMap PgfAbswersMap;
|
||||
static GU_DEFINE_TYPE(PgfAbswersMap, GuStringMap, gu_ptr_type(PgfAnswers),
|
||||
&gu_null_struct);
|
||||
|
||||
struct PgfReasoner {
|
||||
GuPool* pool;
|
||||
@@ -355,7 +351,7 @@ pgf_reasoner_next(PgfReasoner* rs)
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
GuOut* out = gu_file_out(stderr, tmp_pool);
|
||||
GuWriter* wtr = gu_new_utf8_writer(out, tmp_pool);
|
||||
GuExn* err = gu_exn(NULL, type, tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
st->print(st, wtr, err, tmp_pool);
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
@@ -388,7 +384,8 @@ pgf_generate_all(PgfPGF* pgf, PgfCId cat, GuPool* pool)
|
||||
rs->pool = pool;
|
||||
rs->tmp_pool = gu_new_pool(),
|
||||
rs->abstract = &pgf->abstract,
|
||||
rs->table = gu_map_type_new(PgfAbswersMap, rs->tmp_pool),
|
||||
rs->table = gu_new_string_map(PgfAnswers*, &gu_null_struct, rs->tmp_pool),
|
||||
|
||||
rs->pqueue = gu_new_buf(PgfReasonerState*, rs->tmp_pool);
|
||||
rs->exprs = gu_new_buf(PgfExprProb*, rs->tmp_pool);
|
||||
rs->en.next = pgf_reasoner_enum_next;
|
||||
|
||||
@@ -76,8 +76,6 @@ pgf_cfty2ty(PgfTypeChecker* checker, PgfCFType cf_ty)
|
||||
return ty;
|
||||
}
|
||||
|
||||
GU_DEFINE_TYPE(PgfTypeError, abstract, _);
|
||||
|
||||
static PgfPrintContext*
|
||||
pgf_tc_mk_print_context(PgfTypeChecker* checker, PgfContext* ctxt)
|
||||
{
|
||||
@@ -104,7 +102,7 @@ pgf_tc_err_cannot_infer(PgfTypeChecker* checker, PgfContext* ctxt, PgfExpr e)
|
||||
{
|
||||
GuStringBuf* sbuf = gu_string_buf(checker->tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_exn(NULL, type, checker->tmp_pool);
|
||||
GuExn* err = gu_exn(checker->tmp_pool);
|
||||
|
||||
gu_puts("Cannot infer the type of expression ", out, err);
|
||||
pgf_print_expr(e, pgf_tc_mk_print_context(checker, ctxt), 0, out, err);
|
||||
@@ -120,7 +118,7 @@ pgf_tc_err_exp_fun_type_1(PgfTypeChecker* checker, PgfContext* ctxt,
|
||||
{
|
||||
GuStringBuf* sbuf = gu_string_buf(checker->tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_exn(NULL, type, checker->tmp_pool);
|
||||
GuExn* err = gu_exn(checker->tmp_pool);
|
||||
|
||||
PgfPrintContext* pctxt = pgf_tc_mk_print_context(checker, ctxt);
|
||||
gu_puts("The expression ", out, err);
|
||||
@@ -140,7 +138,7 @@ pgf_tc_err_exp_fun_type_2(PgfTypeChecker* checker, PgfContext* ctxt,
|
||||
{
|
||||
GuStringBuf* sbuf = gu_string_buf(checker->tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_exn(NULL, type, checker->tmp_pool);
|
||||
GuExn* err = gu_exn(checker->tmp_pool);
|
||||
|
||||
PgfPrintContext* pctxt = pgf_tc_mk_print_context(checker, ctxt);
|
||||
gu_puts("A function type is expected for the expression ", out, err);
|
||||
@@ -173,7 +171,7 @@ pgf_tc_err_type_mismatch(PgfTypeChecker* checker,
|
||||
{
|
||||
GuStringBuf* sbuf = gu_string_buf(checker->tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_exn(NULL, type, checker->tmp_pool);
|
||||
GuExn* err = gu_exn(checker->tmp_pool);
|
||||
|
||||
PgfPrintContext* pctxt = pgf_tc_mk_print_context(checker, ctxt);
|
||||
gu_puts("The expected type of the expression ", out, err);
|
||||
|
||||
Reference in New Issue
Block a user