diff --git a/docs/about/formalities.md b/docs/about/formalities.md index 57871b4..246c2e2 100644 --- a/docs/about/formalities.md +++ b/docs/about/formalities.md @@ -8,7 +8,7 @@ s, t ::= s | t (disjunction, a.k.a. union) | s => t (implication) | s -> t (arrow, a.k.a. function) | forall x . t (forall, polymorphic) - | box t (box, c.f. modular logic) + | box t (box, c.f. modal logic) | a [t..] (type operator application) | x (variable) | n (nominal) @@ -37,23 +37,23 @@ s, γ ⊢ s, δ ---- [false-left] false, γ ⊢ δ -// trace pairs: none +// trace pairs: none? s, t, γ ⊢ δ ---- [conj-left] s & t, γ ⊢ δ -// trace pairs: none +// trace pairs: none? γ ⊢ s, t, δ ---- [disj-right] γ ⊢ s | t, δ -// trace pairs: none +// trace pairs: none? s, γ ⊢ δ t, γ ⊢ δ ---- [disj-left] s | t, γ ⊢ δ -// trace pairs: none +// trace pairs: none? γ ⊢ s, δ γ ⊢ t, δ ---- [conj-right] @@ -61,12 +61,12 @@ s | t, γ ⊢ δ // XXX // remove s => t? always make progress -// trace pairs: none +// trace pairs: none? s => t, s, t, γ ⊢ δ ---- [impl-left] s => t, s, γ ⊢ δ -// trace pairs: none +// trace pairs: none? s, γ ⊢ t, δ ---- [impl-right] γ ⊢ s => t, δ @@ -89,7 +89,7 @@ box t, γ ⊢ δ // to exclude typedefs like // type A = A // Or that our cycle detection excludes paths between "identical" states. -// trace pairs: none +// trace pairs: none? γ ⊢ expand(a[t..]), δ ---- γ ⊢ a[t..], δ @@ -114,6 +114,7 @@ n fresh ---- [forall] γ ⊢ δ +// TODO can we choose a simpler rule instead? // 1 + n! premises // trace pairs: i ∈ [1..(n! + 1)], premise[i] -- conclusion c, γ* ⊢ a_1, ..., a_n, δ* @@ -122,9 +123,10 @@ c, γ* ⊢ a_1, ..., a_n, δ* OR { b_i | i ∈ ¬I }, γ* ⊢ d, δ* ---- [loads-of-fun] -a_1 -> b_1, ..., a_n -> b_n, γ ⊢ c -> d, δ +a_1 -> b_1, ..., a_n -> b_n, γ ⊢ c -> d, δ ``` + ### context operators * box filtering diff --git a/docs/about/progress.md b/docs/about/progress.md index 40c97dc..9b71035 100644 --- a/docs/about/progress.md +++ b/docs/about/progress.md @@ -1,11 +1,9 @@ -# draft of presentation - -## sappho short +# sappho short - sappho types intro - a quick look at msph and spho -### The types +## The types We take a look at the grammar for sappho types @@ -15,7 +13,7 @@ s, t ::= s | t (disjunction, a.k.a. union) | s => t (implication) | s -> t (arrow, a.k.a. function) | forall x . t (forall, polymorphic) - | box t (box, c.f. modular logic) + | box t (box, c.f. modal logic) | a [t..] (type operator application) | x (variable) | n (nominal) @@ -30,7 +28,7 @@ n ∈ nominal a ∈ opname ``` -The type `t <: s` would be expressive sugar for `box (t => s)` +The type `t <: s` would be syntactic sugar for `box (t => s)` ### msph and spho @@ -60,7 +58,7 @@ Thoughts * maybe eventually add a basic term language and interpreter * can we use external software/libraries for proof search? -## interpretation of types +# interpretation of types - example programs in `msph` - unified syntax for types and bounded polymorphism - example: self typing @@ -75,7 +73,8 @@ Check formalities.md. - simple rules - type constructor rules - recursion and cyclic proofs -* next steps? + +# next steps? - formals: - formulate theorems - if we use semantic subtyping, isn't it enough to @@ -85,3 +84,4 @@ Check formalities.md. - simple rules, should be fairly simple - type constructors, straightforward hopefully - recursion and cyclic proofs... `¯\_(ツ)_/¯` + - describe use of language with type system (interpretation of types) diff --git a/include/msph/common.h b/include/msph/msph.h similarity index 85% rename from include/msph/common.h rename to include/msph/msph.h index eb49da4..f34980b 100644 --- a/include/msph/common.h +++ b/include/msph/msph.h @@ -1,5 +1,5 @@ -#ifndef _MSPH_COMMON_H -#define _MSPH_COMMON_H +#ifndef _MSPH_H +#define _MSPH_H #include "msph/err.h" #include "spho/ctx.h" @@ -25,4 +25,4 @@ struct msph_text_pos { unsigned int col; }; -#endif +#endif /* ifndef _MSPH_H */ diff --git a/include/msph/token.h b/include/msph/token.h index 21617eb..18fb7ae 100644 --- a/include/msph/token.h +++ b/include/msph/token.h @@ -3,7 +3,7 @@ #include -#include "msph/common.h" +#include "msph/msph.h" /* * diff --git a/include/msph/tree.h b/include/msph/tree.h index a7567ab..3fffcfc 100644 --- a/include/msph/tree.h +++ b/include/msph/tree.h @@ -3,7 +3,7 @@ #include -#include "msph/common.h" +#include "msph/msph.h" #include "msph/token.h" /* tree decorations */ diff --git a/src/msph/msph.c b/src/msph/msph.c index 1554e61..c9d3afe 100644 --- a/src/msph/msph.c +++ b/src/msph/msph.c @@ -2,23 +2,11 @@ #include #include -#include "msph/err.h" +#include "msph/msph.h" #include "msph/token.h" #include "msph/tree.h" #include "msph/sphophi.h" -struct msph_opts { - int tokenize_only; - int parser; - const char *in_path; - const char *out_path; -} run_opts = { - 0, - MSPH_PARSE_INFIX, - NULL, - NULL -}; - #define USAGE \ "msph: micro sappho\n" \ @@ -35,6 +23,64 @@ print_usage(void) printf("%s", USAGE); } +struct err_info { + int err; + const char *msg; +} errinfo[] = { + { MSPH_ERR_SYS, "system error" }, + { MSPH_ERR_INVAL, "invalid argument" }, + { MSPH_ERR_TOOLONG, "input too long" }, + + { MSPH_ERR_TOKEN_TOOLONG, "token too long" }, + { MSPH_ERR_TOKEN_EOF, "tokenizer reached end of file" }, + { MSPH_ERR_TOKEN_NOMATCH, "no matching token" }, + { MSPH_ERR_TOKEN_INVAL, "token invalid" }, + + { MSPH_ERR_TREE_TOOLONG, "parsed data too long" }, + { MSPH_ERR_TREE_EOF, "parsing reached unexpected end of file" }, + { MSPH_ERR_TREE_NOMATCH, "parser matching failed" }, + + { MSPH_ERR_TYPE_INVAL, "invalid type" }, + + { MSPH_ERR_SPHOPHI, "spho error" }, + { -1, NULL } +}; + +void +print_error(struct msph_ctx *ctx) +{ + size_t i; + const char *err_msg; + + err_msg = NULL; + for (i = 0; errinfo[i].err != -1; i++) { + if (ctx->err == errinfo[i].err) { + err_msg = errinfo[i].msg; + break; + } + } + if (err_msg == NULL) { + err_msg = "unknown error"; + } + + fprintf(stderr, "ERROR(%x, %d):%s\n", ctx->err, ctx->err_info, err_msg); + + if (ctx->err == MSPH_ERR_SPHOPHI) + fprintf(stderr, "\t%s\n", spho_ctx_strerror(ctx->spho)); +} + +struct msph_opts { + int tokenize_only; + int parser; + const char *in_path; + const char *out_path; +} run_opts = { + 0, + MSPH_PARSE_INFIX, + NULL, + NULL +}; + int run(struct msph_opts *); int @@ -98,6 +144,7 @@ run(struct msph_opts *opts) struct msph_tree_root *root; FILE *in, *out; + in = out = NULL; s = NULL; root = NULL; @@ -157,13 +204,7 @@ exit: return (0); err: - if (root != NULL && ctx.err == MSPH_ERR_SPHOPHI) { - fprintf(stderr, "ERROR:%s\n", - spho_ctx_strerror(ctx.spho)); - } else { - fprintf(stderr, "ERROR:msph_err: %x (%d)\n", (ctx).err, - (ctx).err_info); - } + print_error(&ctx); if (in) fclose(in); @@ -173,6 +214,7 @@ err: } + void msph_ctx_init(struct msph_ctx *ctx) { diff --git a/src/msph/token.c b/src/msph/token.c index abe2677..81f61c7 100644 --- a/src/msph/token.c +++ b/src/msph/token.c @@ -7,7 +7,7 @@ #include "spho/spho.h" -#include "msph/err.h" +#include "msph/msph.h" #include "msph/token.h" diff --git a/src/msph/tree.c b/src/msph/tree.c index 87d99d7..2444da6 100644 --- a/src/msph/tree.c +++ b/src/msph/tree.c @@ -1,6 +1,5 @@ #define SPHO_ENABLE_DEBUG_PRINT -#include "msph/common.h" -#include "msph/common.h" + #include @@ -10,6 +9,7 @@ #include "spho/spho.h" +#include "msph/msph.h" #include "msph/tree.h" @@ -130,6 +130,8 @@ msph_tree_makeroot(struct msph_ctx *ctx) return (root); } +#define __POS_FMT "line: %u, col: %u" +#define __POS_ARGS(pos) (pos).line, (pos).col /* * Expect to read next token, otherwise set error and do something @@ -143,6 +145,8 @@ msph_tree_makeroot(struct msph_ctx *ctx) if (((readres) = tree_parse_next_token(parse)) == -1) \ on_err; \ if ((readres) == 0) { \ + fprintf(stderr, "unexpected end-of-file after " \ + __POS_FMT "\n", __POS_ARGS((parse)->s->src.pos)); \ MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_EOF, \ err_info); \ on_err; \ @@ -159,6 +163,8 @@ msph_tree_makeroot(struct msph_ctx *ctx) #define EXPECT_CURR_TOKEN(parse, toktype, err_info, on_err) \ do { \ if (CURR_TOKEN(parse)->type != toktype) { \ + fprintf(stderr, "parser expected token " #toktype \ + "\n"); \ MSPH_ERR_INFO(CTX(parse), MSPH_ERR_TREE_NOMATCH, \ err_info); \ on_err; \ @@ -1062,7 +1068,6 @@ err: struct msph_tree_tpexpr * tree_parse_tpname_or_tpappl(struct tree_parse *p, struct msph_tree *parent) { - int res; struct msph_tree_tpname *tpname; struct msph_tree_tpexpr *ret; struct msph_tree_nameref *nameref; @@ -1074,7 +1079,6 @@ tree_parse_tpname_or_tpappl(struct tree_parse *p, struct msph_tree *parent) return (NULL); if (CURR_TOKEN(p)->type == TOK_LBRAK) { - EXPECT_READ_NEXT(res, p, MSPH_TREE_TPAPPL, goto err); if ((ret = tree_parse_tpapplargs(p, nameref, parent)) == NULL) goto err; return (ret);