From 9e1f40862ace352a1707ee90858a3b8c321feb2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 18 Apr 2022 10:11:03 +0200 Subject: [PATCH] :wrench: add bot and discord backend update --- .github/workflows/backend.yml | 15 +++++++ .github/workflows/discord_bot.yml | 15 +++++++ .github/workflows/{bot.yml => irc_bot.yml} | 0 include/env/context.h | 1 + src/compile.c | 1 + src/emit/emit.c | 52 +++++++++++++++++----- src/parse/check.c | 4 ++ src/parse/scan1.c | 8 ++++ 8 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/backend.yml create mode 100644 .github/workflows/discord_bot.yml rename .github/workflows/{bot.yml => irc_bot.yml} (100%) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 00000000..b697b0a7 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,15 @@ +name: Update Backend + +on: + push: + branches: + - 'master' + +jobs: + build: + name: Push to bot repo + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + + steps: + - run: curl https://TheGwionPlayground.fennecdjay.repl.co/bumcledyfynaghat diff --git a/.github/workflows/discord_bot.yml b/.github/workflows/discord_bot.yml new file mode 100644 index 00000000..281b7a3c --- /dev/null +++ b/.github/workflows/discord_bot.yml @@ -0,0 +1,15 @@ +name: Discord Bot + +on: + push: + branches: + - 'master' + +jobs: + build: + name: Push to bot repo + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + + steps: + - run: curl https://GwionPLBot.fennecdjay.repl.co/bumcledyfynaghat diff --git a/.github/workflows/bot.yml b/.github/workflows/irc_bot.yml similarity index 100% rename from .github/workflows/bot.yml rename to .github/workflows/irc_bot.yml diff --git a/include/env/context.h b/include/env/context.h index af191283..77b4bb2e 100644 --- a/include/env/context.h +++ b/include/env/context.h @@ -5,6 +5,7 @@ struct Context_ { Nspc nspc; m_str name; Ast tree; + Func locale; uint16_t ref; uint16_t weight; bool error; diff --git a/src/compile.c b/src/compile.c index 2974fdef..8bcfbee6 100644 --- a/src/compile.c +++ b/src/compile.c @@ -103,6 +103,7 @@ ANN static inline m_bool _passes(struct Gwion_ *gwion, struct Compiler *c) { ANN static inline m_bool passes(struct Gwion_ *gwion, struct Compiler *c) { const Env env = gwion->env; const Context ctx = new_context(env->gwion->mp, c->ast, env->name); +ctx->locale = nspc_lookup_value1(gwion->env->global_nspc, insert_symbol(gwion->st, "@DefaultLocale"))->d.func_ref; env_reset(env); load_context(ctx, env); const m_bool ret = _passes(gwion, c); diff --git a/src/emit/emit.c b/src/emit/emit.c index 44c5bf6e..0b6acd14 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -912,6 +912,47 @@ ANN static m_bool emit_prim_interp(const Emitter emit, const Exp *exp) { emit_localx(emit, emit->gwion->type[et_string]); return GW_OK; } +#include "shreduler_private.h" +ANN static m_bool emit_ensure_func(const Emitter emit, const Func f) { + const struct ValueFrom_ *from = f->value_ref->from; + if(from->owner_class) + CHECK_BB(ensure_emit(emit, from->owner_class)); + if(f->code) return GW_OK; + const m_uint scope = emit_push(emit, from->owner_class, from->owner); + const m_bool ret = emit_func_def(emit, f->def); + emit_pop(emit, scope); + return ret; +} + +ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) { + CHECK_BB(emit_ensure_func(emit, emit->env->context->locale)); + emit_push_code(emit, "locale"); // new code { + + // push args + const M_Object string = new_string(emit->gwion, s_name(*id)); + regpushi(emit, (m_uint)string); + + regpushi(emit, (m_uint)emit->env->context->locale->code); + emit_exp_call1(emit, emit->env->context->locale, true); + + regpop(emit, emit->env->context->locale->def->base->ret_type->size); + const VM_Code code = finalyze(emit, EOC); + const VM_Shred shred = new_vm_shred(emit->gwion->mp, code); + vm_add_shred(emit->gwion->vm, shred); + shred->info->me->ref++; + vm_run(emit->gwion->vm); + emit->gwion->vm->bbq->is_running = true; + if(tflag(emit->env->context->locale->def->base->ret_type, tflag_float)) { + const Instr instr = emit_add_instr(emit, RegPushImm2); + instr->f = *(m_float*)shred->reg; + } else if(emit->env->context->locale->def->base->ret_type->size == SZ_INT) + regpushi(emit, *(m_uint*)shred->reg); + else { + // here we would need to deallocate + ERR_B(prim_pos(id), "not implemented atm"); + } + return GW_OK; +} DECL_PRIM_FUNC(emit, m_bool, Emitter); ANN static m_bool emit_prim(const Emitter emit, Exp_Primary *const prim) { @@ -1683,17 +1724,6 @@ ANN static Instr emit_call(const Emitter emit, const Func f, return emit_add_instr(emit, Overflow); } -ANN static m_bool emit_ensure_func(const Emitter emit, const Func f) { - const struct ValueFrom_ *from = f->value_ref->from; - if(from->owner_class) - CHECK_BB(ensure_emit(emit, from->owner_class)); - if(f->code) return GW_OK; - const m_uint scope = emit_push(emit, from->owner_class, from->owner); - const m_bool ret = emit_func_def(emit, f->def); - emit_pop(emit, scope); - return ret; -} - ANN m_bool emit_exp_call1(const Emitter emit, const Func f, const bool is_static) { const m_uint this_offset = emit->this_offset; diff --git a/src/parse/check.c b/src/parse/check.c index da3a0a45..76697b57 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -421,6 +421,10 @@ ANN static Type check_prim_hack(const Env env, const Exp *data) { // return (*data)->type; } +ANN static Type check_prim_locale(const Env env, const Symbol *data NUSED) { + return env->context->locale->def->base->ret_type; +} + #define describe_prim_xxx(name, type) \ ANN static Type check_prim_##name(const Env env NUSED, \ const union prim_data *data NUSED) { \ diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 2a31cf94..9e61a337 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -674,6 +674,14 @@ ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { ERR_B(fdef->base->pos, "file scope function can't be abstract"); const bool global = GET_FLAG(fdef->base, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); + if(fbflag(fdef->base, fbflag_locale) && fdef->base->args) { + Arg_List args = fdef->base->args; + for(uint32_t i = 0; i < args->len; i++) { + const Arg *arg = mp_vector_at(args, Arg, i); + if(!arg->exp) + ERR_B(arg->td->pos, _("all arguments in a locale must have a default value")) + } + } if (fdef->base->td) CHECK_BB(env_storage(env, fdef->base->flag, fdef->base->td->pos)); CHECK_BB(scan1_fdef_defined(env, fdef)); -- 2.43.0