From: fennecdjay Date: Sat, 30 Jul 2022 05:32:22 +0000 (+0200) Subject: :art: Add compile_values functions X-Git-Tag: nightly~264^2~72 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7a4162980e556ca85bac8785876d2f13469d36ed;p=gwion.git :art: Add compile_values functions --- diff --git a/include/compile.h b/include/compile.h index a59c03de..1ac65032 100644 --- a/include/compile.h +++ b/include/compile.h @@ -1,13 +1,19 @@ #ifndef __COMPILE #define __COMPILE -m_uint compile_filename(struct Gwion_ *vm, const m_str filename); -m_uint compile_string(struct Gwion_ *vm, const m_str filename, - const m_str data); -m_uint compile_file(struct Gwion_ *vm, const m_str filename, FILE *file); -m_uint compile_filename_xid(struct Gwion_ *vm, const m_str filename, - const m_uint xid); -m_uint compile_string_xid(struct Gwion_ *vm, const m_str filename, - const m_str data, const m_uint xid); -m_uint compile_file_xid(struct Gwion_ *vm, const m_str filename, FILE *file, - const m_uint xid); +m_uint compile_filename_values(struct Gwion_ *vm, const m_str filename, MP_Vector*); +m_uint compile_string_values(struct Gwion_ *vm, const m_str filename, + const m_str data, MP_Vector*); +m_uint compile_file_values(struct Gwion_ *vm, const m_str filename, FILE *file, MP_Vector*); +m_uint compile_filename_xid_values(struct Gwion_ *vm, const m_str filename, + const m_uint xid, MP_Vector*); +m_uint compile_string_xid_values(struct Gwion_ *vm, const m_str filename, + const m_str data, const m_uint xid, MP_Vector*); +m_uint compile_file_xid_values(struct Gwion_ *vm, const m_str filename, FILE *file, + const m_uint xid, MP_Vector*); +#define compile_filename(a, b) compile_filename_values(a, b, NULL) +#define compile_string(a, b, c) compile_string_values(a, b, c, NULL) +#define compile_file(a, b, c) compile_file_values(a, b, c, NULL) +#define compile_filename_xid(a, b, c) compile_filename_xid_values(a, b, c, NULL) +#define compile_string_xid(a, b, c, d) compile_string_xid_values(a, b, c, d, NULL) +#define compile_file_xid(a, b, c) compile_file_xid_values(a, b, c, NULL) #endif diff --git a/src/compile.c b/src/compile.c index c9b3ad9e..b017d7e8 100644 --- a/src/compile.c +++ b/src/compile.c @@ -14,11 +14,14 @@ enum compile_type { COMPILE_NAME, COMPILE_MSTR, COMPILE_FILE }; struct Compiler { const m_str base; m_str name; - m_str data; - FILE * file; + union { + m_str data; + FILE * file; + }; Ast ast; struct Vector_ args; VM_Shred shred; + MP_Vector *values; enum compile_type type; }; @@ -106,6 +109,17 @@ ANN static inline m_bool passes(struct Gwion_ *gwion, struct Compiler *c) { const Context ctx = new_context(env->gwion->mp, c->ast, env->name); env_reset(env); load_context(ctx, env); + for(uint32_t i = 0; i < mp_vector_len(c->values); i++) { + const Value v = *mp_vector_at(c->values, Value, i); + set_vflag(v, vflag_builtin); + if(isa(v->type, gwion->type[et_class]) > 0) { + const Type t = (Type)v->d.ptr; + type_addref(t); + mk_class(gwion->env, t, (loc_t) {}); + nspc_add_type(gwion->env->curr, insert_symbol(gwion->st, v->name), t); + } else + valid_value(gwion->env, insert_symbol(gwion->st, v->name), v); + } const m_bool ret = _passes(gwion, c); ctx->tree = c->ast; if (ret > 0) //{ @@ -149,43 +163,43 @@ ANN static m_uint compile(struct Gwion_ *gwion, struct Compiler *c) { return ret; } -ANN m_uint compile_filename(struct Gwion_ *gwion, const m_str filename) { - struct Compiler c = {.base = filename, .type = COMPILE_NAME}; +ANN m_uint compile_filename_values(struct Gwion_ *gwion, const m_str filename, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_NAME, .values=values}; return compile(gwion, &c); } -ANN m_uint compile_string(struct Gwion_ *gwion, const m_str filename, - const m_str data) { - struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data}; +ANN m_uint compile_string_values(struct Gwion_ *gwion, const m_str filename, + const m_str data, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data, .values=values}; return compile(gwion, &c); } -ANN m_uint compile_file(struct Gwion_ *gwion, const m_str filename, - FILE *file) { - struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file}; +ANN m_uint compile_file_values(struct Gwion_ *gwion, const m_str filename, + FILE *file, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file, .values=values}; return compile(gwion, &c); } -ANN m_uint compile_filename_xid(struct Gwion_ *gwion, const m_str filename, - const m_uint xid) { - struct Compiler c = {.base = filename, .type = COMPILE_NAME}; +ANN m_uint compile_filename_xid_values(struct Gwion_ *gwion, const m_str filename, + const m_uint xid, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_NAME, .values=values}; if (!compile(gwion, &c)) return 0; assert(c.shred); return c.shred->tick->xid = xid; } -ANN m_uint compile_string_xid(struct Gwion_ *gwion, const m_str filename, - const m_str data, const m_uint xid) { - struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data}; +ANN m_uint compile_string_xid_values(struct Gwion_ *gwion, const m_str filename, + const m_str data, const m_uint xid, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data, .values=values}; if (!compile(gwion, &c)) return 0; assert(c.shred); gwion->vm->shreduler->shred_ids--; return c.shred->tick->xid = xid; } -ANN m_uint compile_file_xid(struct Gwion_ *gwion, const m_str filename, - FILE *file, const m_uint xid) { - struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file}; +ANN m_uint compile_file_xid_values(struct Gwion_ *gwion, const m_str filename, + FILE *file, const m_uint xid, MP_Vector *values) { + struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file, .values=values}; if (!compile(gwion, &c)) return 0; assert(c.shred); return c.shred->tick->xid = xid;