From a6ab58929fbcdee3bcb062f589f985f200236128 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 30 Nov 2020 22:00:57 +0100 Subject: [PATCH] :art: Update --- ast | 2 +- examples/ptr_cast.gw | 2 +- include/env/context.h | 1 - include/env/value.h | 1 - include/gwi.h | 2 -- src/env/context.c | 2 -- src/env/value.c | 2 -- src/import/import_internals.c | 7 ------- src/lib/engine.c | 10 ++++++++++ src/lib/lib_func.c | 2 +- src/lib/object_op.c | 3 +-- src/lib/opfunc.c | 1 - src/lib/prim.c | 3 +-- src/lib/ptr.c | 1 - src/parse/check.c | 8 +++----- src/parse/scan2.c | 18 ------------------ tests/error/func_non.gw | 2 +- tests/error/non_function_template.gw | 2 +- tests/tree/docstr.gw | 15 +++++++++++++++ util | 2 +- 20 files changed, 36 insertions(+), 50 deletions(-) create mode 100644 tests/tree/docstr.gw diff --git a/ast b/ast index ba9550c1..31bfb80a 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit ba9550c1d998f0ddf81b901e633c901ebc92cb18 +Subproject commit 31bfb80acafe4235a0446cde7c93b0e3687d503c diff --git a/examples/ptr_cast.gw b/examples/ptr_cast.gw index 5a653f44..a9324924 100644 --- a/examples/ptr_cast.gw +++ b/examples/ptr_cast.gw @@ -1,2 +1,2 @@ 12 => var int i; -<<>>; +<<>>; diff --git a/include/env/context.h b/include/env/context.h index 1810e04d..0fea1b74 100644 --- a/include/env/context.h +++ b/include/env/context.h @@ -6,7 +6,6 @@ struct Context_ { Ast tree; Nspc nspc; struct Map_ lbls; - GwText *docstr; m_bool error; m_bool global; uint16_t ref; diff --git a/include/env/value.h b/include/env/value.h index 7adb5dcc..c87da142 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -30,7 +30,6 @@ struct Value_ { m_uint* ptr; Func func_ref; } d; - GwText *docstr; uint16_t ref; ae_flag flag; enum vflag vflag; diff --git a/include/gwi.h b/include/gwi.h index 0d7f8937..d20124fd 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -17,6 +17,4 @@ static inline Tmpl* gwi_tmpl(const Gwi gwi) { } ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)); - -ANN m_bool gwi_doc(const Gwi gwi, const m_str name, const m_str doc); #endif diff --git a/src/env/context.c b/src/env/context.c index 1ba288c7..c78d522e 100644 --- a/src/env/context.c +++ b/src/env/context.c @@ -7,8 +7,6 @@ ANN void free_context(const Context a, Gwion gwion) { nspc_remref(a->nspc, gwion); free_mstr(gwion->mp, a->name); - if(a->docstr) - free_text(a->docstr); mp_free(gwion->mp, Context, a); } diff --git a/src/env/value.c b/src/env/value.c index 86dfa6b7..dfbf80b8 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -14,8 +14,6 @@ ANN void free_value(Value a, Gwion gwion) { xfree(a->d.ptr); if(is_class(gwion, t)) type_remref(t, gwion); - if(a->docstr) - free_text(a->docstr); mp_free(gwion->mp, ValueFrom, a->from); mp_free(gwion->mp, Value, a); } diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 2d997661..a4fbefdf 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -39,10 +39,3 @@ ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { gwion->env->name = name; return ret; } - -ANN m_bool gwi_doc(const Gwi gwi, const m_str name, const m_str doc) { - DECL_OB(const Value, v, = nspc_lookup_value0(gwi->gwion->env->curr, insert_symbol(gwi->gwion->st, name))) - v->docstr = new_text(gwi->gwion->mp); - text_add(v->docstr, doc); - return GW_OK; -} diff --git a/src/lib/engine.c b/src/lib/engine.c index 3688593f..b58b7b3b 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -71,6 +71,12 @@ mk_class_instr(lt, r, l, && l != r) OP_CHECK(opck_object_dot); OP_EMIT(opem_object_dot); + +static OP_CHECK(opck_basic_ctor) { + const Exp_Call* call = (Exp_Call*)data; + ERR_N(exp_self(call)->pos, _("can't call a non-callable value")) +} + ANN static m_bool import_core_libs(const Gwi gwi) { const Type t_class = gwi_mk_type(gwi, "@Class", SZ_INT, NULL); set_tflag(t_class, tflag_infer); @@ -159,6 +165,10 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(gwi_oper_end(gwi, ">", instr_class_gt)) GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) + + GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) + GWI_BB(gwi_oper_add(gwi, opck_basic_ctor)) + GWI_BB(gwi_oper_end(gwi, "@ctor", NULL)) return GW_OK; } diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 4f33ccef..e73a1de8 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -267,7 +267,7 @@ static OP_CHECK(opck_fptr_impl) { struct FptrInfo info = { impl->e->info->type->info->func, impl->t->info->func, impl->e, impl->e->pos }; CHECK_BO(fptr_do(env, &info)) - return ((Exp)impl->e)->info->cast_to = impl->t; + return impl->t; } static OP_EMIT(opem_fptr_impl) { diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 3269f890..343a154c 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -98,7 +98,6 @@ static OP_CHECK(opck_implicit_null2obj) { const Type r = imp->t; if(check_nonnull(env, l, r, "implicitly cast", imp->e->pos) == env->gwion->type[et_null]) return env->gwion->type[et_null]; - imp->e->info->cast_to = r; return imp->t; } @@ -114,7 +113,7 @@ static OP_EMIT(opem_implicit_null2obj) { ANN /*static*/ Type scan_class(const Env env, const Type t, const Type_Decl* td); static Type opck_object_scan(const Env env, const struct TemplateScan *ts) { - if(ts->t->info->cdef && ts->t->info->cdef->base.tmpl->call) + if(ts->td->types) return scan_class(env, ts->t, ts->td) ?: env->gwion->type[et_null]; ERR_N(td_pos(ts->td), _("you must provide template types for type '%s'"), ts->t->name) } diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 4acfaff4..439bbc05 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -18,7 +18,6 @@ OP_CHECK(opck_basic_cast) { OP_CHECK(opck_usr_implicit) { struct Implicit* imp = (struct Implicit*)data; - imp->e->info->cast_to = imp->t; return imp->t; } diff --git a/src/lib/prim.c b/src/lib/prim.c index 442aaf13..947dc1bf 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -146,8 +146,7 @@ static OP_CHECK(opck_cast_i2f) { } static OP_CHECK(opck_implicit_i2f) { - struct Implicit* imp = (struct Implicit*)data; - return imp->e->info->cast_to = env->gwion->type[et_float]; + return env->gwion->type[et_float]; } #define CHECK_FF(op, check, func) _CHECK_OP(op, check, float_##func) diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 32f61142..4e5d2f3d 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -95,7 +95,6 @@ static OP_CHECK(opck_ptr_implicit) { const m_str access = exp_access(e); if(access) ERR_N(e->pos, _("can't cast %s value to Ptr"), access); - e->info->cast_to = imp->t; exp_setvar(e, 1); const Type t = get_type(imp->t); if(!tflag(t, tflag_check)) diff --git a/src/parse/check.c b/src/parse/check.c index 8bd67cbd..9caac831 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -17,21 +17,19 @@ ANN static m_bool check_stmt_list(const Env env, Stmt_List list); ANN m_bool check_class_def(const Env env, const Class_Def class_def); -ANN static m_bool check_internal(const Env env, const Symbol sym, +ANN static Type check_internal(const Env env, const Symbol sym, const Exp e, const Type t) { struct Implicit imp = { .e=e, .t=t, .pos=e->pos }; struct Op_Import opi = { .op=sym, .lhs=e->info->type, .rhs=t, .data=(uintptr_t)&imp, .pos=e->pos, .op_type=op_implicit }; - CHECK_OB(op_check(env, &opi)) - assert(e->info->nspc); - return GW_OK; + return op_check(env, &opi); } ANN m_bool check_implicit(const Env env, const Exp e, const Type t) { if(e->info->type == t) return GW_OK; const Symbol sym = insert_symbol("@implicit"); - return info->cast_to = check_internal(env, sym, e, t); + return (e->info->cast_to = check_internal(env, sym, e, t)) ? GW_OK : GW_ERROR; } ANN m_bool check_subscripts(Env env, const Array_Sub array, const m_bool is_decl) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 20cb1ac3..ccaeb95e 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -286,27 +286,9 @@ ANN m_bool scan2_union_def(const Env env, const Union_Def udef) { #define scan2_stmt_break (void*)dummy_func #define scan2_stmt_return scan2_stmt_exp -#define DOCSTRING(name, value, prefix) \ -ANN static inline GwText* name##_docstr(const Env env) { \ - prefix \ - if(!(value)) \ - (value) = new_text(env->gwion->mp); \ - return value; \ -} -DOCSTRING(context, env->context->docstr,) -DOCSTRING(func, env->func->value_ref->docstr,) -DOCSTRING(class, v->docstr, const Value v = nspc_lookup_value0(env->curr->parent, insert_symbol(env->class_def->name));) -typedef GwText* (*docfunc)(Env); - ANN static m_bool scan2_stmt_pp(const Env env, const Stmt_PP stmt) { if(stmt->pp_type == ae_pp_include) env->name = stmt->data; - else if(stmt->pp_type == ae_pp_docstr) { - const docfunc df = env->func ? func_docstr : env->class_def ? class_docstr : context_docstr; - GwText *docstr = df(env); - text_add(docstr, stmt->data); - - } return GW_OK; } diff --git a/tests/error/func_non.gw b/tests/error/func_non.gw index 6e848c96..cf68a27d 100644 --- a/tests/error/func_non.gw +++ b/tests/error/func_non.gw @@ -1,2 +1,2 @@ -#! [contains] function call using a non-function value +#! [contains] non-callable value null(); diff --git a/tests/error/non_function_template.gw b/tests/error/non_function_template.gw index 8840211d..4cdc5eb8 100644 --- a/tests/error/non_function_template.gw +++ b/tests/error/non_function_template.gw @@ -1,3 +1,3 @@ -#! [contains] template call of non-function value +#! [contains] tests/error/non_function_template.gw var int test; test:[int](); diff --git a/tests/tree/docstr.gw b/tests/tree/docstr.gw new file mode 100644 index 00000000..dd205943 --- /dev/null +++ b/tests/tree/docstr.gw @@ -0,0 +1,15 @@ +#!! document file + +fun void test() { + #!! Document file level function +} + +class C { + #!! document class + + fun void test() { + #!! Document member function + } +} + +<<< "Ensuring it parses: declaring a variable:", var C c >>>; diff --git a/util b/util index 011948c5..18330ebb 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit 011948c5a80f49af50d6e6a35aacd8e70eb53ec6 +Subproject commit 18330ebb0d167c9f1e30cdc97bfc0c86fa329dc0 -- 2.43.0