.vscode
# ignore gwiond for dev
gwiond
+embed
+gwion.config.json
LDFLAGS += -lrt
endif
+ifeq (${USE_CONFIG}, 1)
+config_obj := embed/embed.o
+include embed/embed.mk
+endif
+
ALMOST_LIBS := fmt/libgwion_fmt.a
ALMOST_LIBS += ast/libgwion_ast.a ast/libprettyerr/libprettyerr.a
ALMOST_LIBS += util/libgwion_util.a
all: options-show prg
-prg: ${GWLIBS} src/main.o
+prg: ${GWLIBS} ${config_obj} src/main.o
@$(info link ${PRG})
- @${CC} src/main.o -o ${PRG} ${LDFLAGS} ${LIBS}
+ ${CC} src/main.o -o ${PRG} ${config_obj} ${PLUGLIBS} ${LDFLAGS} ${LIBS}
options-show:
@$(call _options)
@$(info libs: ${GWLIBS})
-embed_gw:
+with_config:
+ bash scripts/embed.bash gwion.config.json
+ touch src/main.c
+ USE_CONFIG=1 CFLAGS="-DGWION_EMBED_GW -Iembed $(eval ${CFLAGS})" ${MAKE}
touch src/main.c
- mkdir -p embed
- bash scripts/gw_embed.sh ${GWION_EMBED_GW} > src/embed.c
- CFLAGS="-DGWION_EMBED_GW -Iembed $(eval ${CFLAGS})" ${MAKE}
- rm -rf embed src/embed.c
almost_gwion: ${almost_obj} ${ALMOST_LIBS}
f_drvdel del;
} DriverData;
-typedef void (*f_bbqset)(struct DriverData_ *);
typedef void (*f_bbqrun)(const struct VM_ *);
typedef struct BBQ_ {
m_float * in;
m_float * out;
struct SoundInfo_ * si;
- f_bbqset func;
+ gwdriver_t func;
f_bbqrun run;
struct DriverData_ *driver;
bool is_running;
gwi_set_loc(gwi, __FILE__, __LINE__); \
(void)(a); \
}
-#define GWION_IMPORT(a) ANN m_bool import_##a(const Gwi gwi)
+#define GWION_IMPORT(a) ANN m_bool gwimport_##a(const Gwi gwi)
#else
#define GWI_BB(a) \
{ \
gwi_set_loc(gwi, (m_str)__FILE__, __LINE__); \
CHECK_OB(a); \
}
-#define GWION_IMPORT(a) ANN m_bool import(const Gwi gwi)
+#define GWION_IMPORT(a) ANN m_bool gwimport_##a(const Gwi gwi)
#endif
#define ALLOC_PTR(p, a, b, c) \
b *a = (b *)_mp_calloc(p, sizeof(b)); \
#ifndef __LANG_PRIVATE
#define __LANG_PRIVATE
-ANN m_bool import_class(const Gwi gwi);
-ANN m_bool import_prim(const Gwi gwi);
-ANN m_bool import_enum(const Gwi gwi);
-ANN m_bool import_object(const Gwi gwi);
-ANN m_bool import_func(const Gwi gwi);
-ANN m_bool import_string(const Gwi gwi);
-ANN m_bool import_shred(const Gwi gwi);
-ANN m_bool import_event(const Gwi gwi);
-ANN m_bool import_ugen(const Gwi gwi);
-ANN m_bool import_array(const Gwi gwi);
-ANN m_bool import_xork(const Gwi gwi);
-ANN m_bool import_modules(const Gwi gwi);
-ANN m_bool import_object_op(const Gwi gwi);
-ANN m_bool import_values(const Gwi gwi);
-ANN m_bool import_union(const Gwi gwi);
-ANN m_bool import_ref(const Gwi gwi);
-ANN m_bool import_deep_equal(const Gwi gwi);
-ANN m_bool import_dict(const Gwi gwi);
-ANN m_bool import_gack(const Gwi gwi);
-ANN m_bool import_sift(const Gwi gwi);
-ANN m_bool import_locale(const Gwi gwi);
+ANN m_bool gwimport_class(const Gwi gwi);
+ANN m_bool gwimport_prim(const Gwi gwi);
+ANN m_bool gwimport_enum(const Gwi gwi);
+ANN m_bool gwimport_object(const Gwi gwi);
+ANN m_bool gwimport_func(const Gwi gwi);
+ANN m_bool gwimport_string(const Gwi gwi);
+ANN m_bool gwimport_shred(const Gwi gwi);
+ANN m_bool gwimport_event(const Gwi gwi);
+ANN m_bool gwimport_ugen(const Gwi gwi);
+ANN m_bool gwimport_array(const Gwi gwi);
+ANN m_bool gwimport_xork(const Gwi gwi);
+ANN m_bool gwimport_modules(const Gwi gwi);
+ANN m_bool gwimport_object_op(const Gwi gwi);
+ANN m_bool gwimport_values(const Gwi gwi);
+ANN m_bool gwimport_union(const Gwi gwi);
+ANN m_bool gwimport_ref(const Gwi gwi);
+ANN m_bool gwimport_deep_equal(const Gwi gwi);
+ANN m_bool gwimport_dict(const Gwi gwi);
+ANN m_bool gwimport_gack(const Gwi gwi);
+ANN m_bool gwimport_sift(const Gwi gwi);
+ANN m_bool gwimport_locale(const Gwi gwi);
#endif
#ifndef __PLUG
#define __PLUG
+struct DriverData_;
+struct Gwi_;
+typedef m_bool (*gwplugin_t) (struct Gwi_*);
+typedef void* (*gwmodini_t) (struct Gwion_ const* gwion, const Vector args);
+typedef void* (*gwmodend_t) (struct Gwion_ const* gwion, void *self);
+typedef void (*gwdriver_t) (struct DriverData_ *);
+typedef m_str* (*gwdepend_t) (void);
+
+typedef struct Plug_ {
+ void *dl;
+ void *self;
+ Nspc nspc;
+ gwplugin_t plugin;
+ gwdriver_t driver;
+ gwmodini_t modini;
+ gwmodend_t modend;
+ gwdepend_t depend;
+} * Plug;
+
+ANN static inline Plug new_plug(MemPool p) {
+ return (Plug)mp_calloc(p, Plug);
+}
+
ANN m_bool plug_ini(const struct Gwion_ *, const Vector);
ANN m_bool driver_ini(const struct Gwion_ *);
ANN m_bool plug_run(const struct Gwion_ *, const Map);
ANN void free_plug(const Gwion);
ANN void * get_module(const struct Gwion_ *, const m_str);
-ANN void set_module(const struct Gwion_ *gwion, const m_str name,
+ANN m_bool set_module(const struct Gwion_ *gwion, const m_str name,
void *const ptr);
ANN m_bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t);
-struct DriverData_;
-struct Gwi_;
-typedef m_bool (*gwplugin_t) (struct Gwi_*);
-typedef void* (*gwmodini_t) (struct Gwion_ const* gwion, const Vector args);
-typedef void* (*gwmodend_t) (struct Gwion_ const* gwion, void *self);
-typedef void* (*gwdriver_t) (struct DriverData_ *);
-typedef m_str* (*gwdepend_t) (void);
-#define GWIMPORT_NAME import
-#define GWMODINI_NAME gwmodini
-#define GWMODEND_NAME gwmodend
-#define GWDRIVER_NAME gwdriver
-#define GWDEPEND_NAME gwdepend
+#define GWIMPORT_NAME(a) gwimport_##a
+#define GWMODINI_NAME(a) gwmodini_##a
+#define GWMODEND_NAME(a) gwmodend_##a
+#define GWDRIVER_NAME(a) gwdriver_##a
+#define GWDEPEND_NAME(a) gwdepend_##a
-#ifndef GWION_BUILTIN
-#define GWMODINI(a) \
- ANN2(1) \
- void *GWMODINI_NAME(struct Gwion_ *const gwion NUSED, const Vector args NUSED)
-#define GWMODEND(a) \
- ANN void GWMODEND_NAME(struct Gwion_ *const gwion NUSED, void *self NUSED)
-#define GWDRIVER(a) ANN void GWDRIVER_NAME(DriverData *d)
-#define GWDEPEND(a) ANN m_str const *GWDEPEND_NAME(void)
-#else
-#define GWIMODINI(a) \
+#define GWMODINI(a) \
ANN2(1) \
void *gwmodini_##a(struct Gwion_ *const gwion NUSED, const Vector args NUSED)
#define GWMODEND(a) \
ANN void gwmodend_##a(struct Gwion_ *const gwion NUSED, void *self NUSED)
-#define GWDRIVER(a) gwdriver_##a(a) ANN void GWDRIVER_NAME(DriverData *d)
-#define GWDEPEND(a) gwdepend_##a ANN m_str const *GWDEPEND_NAME(void)
-#endif
+#define GWDRIVER(a) ANN void gwdriver_##a(DriverData *d)
+#define GWDEPEND(a) ANN m_str const *gwdepend_##a(void)
#endif
--- /dev/null
+#!/usr/bin/bash
+mkdir -p embed
+rm -f embed/*
+
+#json=$(jq -c '.' "$1")
+json=$(cat "$1")
+
+cat << EOF >> embed/embed_head
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "gwion_env.h"
+#include "vm.h"
+#include "instr.h"
+#include "emit.h"
+#include "compile.h"
+#include "gwion.h"
+#include "object.h"
+#include "operator.h"
+#include "import.h"
+#include "gwi.h"
+
+EOF
+
+header() {
+ echo "$1" >> embed/embed_head
+}
+
+config() {
+ echo "$1" >> embed/embed.mk
+}
+
+has_func() {
+ nm "$2" | grep "${1}_${3}" > /dev/null
+}
+plugin() {
+ has_func "gwimport" "$1" "$2" && {
+ header "extern m_bool gwimport_${2}(const Gwi);"
+ echo " plug->plugin = gwimport_${2};"
+ }
+}
+driver() {
+ has_func "gwdriver" "$1" "$2" && {
+ header "extern void *gwdriver_$2(struct DriverData_*);"
+ echo " plug->driver = gwdriver_$2;"
+ }
+}
+modini() {
+ has_func "gwmodini" "$1" "$2" && {
+ header "extern m_bool gwmodini_${2}(gwion);"
+ echo " plug->modini = gwmodini_${2};"
+ }
+}
+modend() {
+ has_func "gwmodend" "$1" "$2" && {
+ header "extern m_bool gwmodend_${2}(gwion);"
+ echo " plug->modend = gwmodend_${2};"
+ }
+}
+
+handle_lib() {
+ cat << EOF >> embed/embed_body
+ANN static void embed_${name}(const Gwion gwion) {
+ Plug plug = new_plug(gwion->mp);
+$(modini "$1" "$2")$(modend "$1" "$2")$(plugin "$1" "$2")$(driver "$1" "$2")
+ map_set(&gwion->data->plugs->map, (vtype)strdup("${2}"), (vtype)plug);
+}
+
+EOF
+}
+
+cat << EOF >> embed/embed_foot
+ANN static void compile_script(const Gwion gwion, const m_str filename,
+ const m_str content, const size_t sz) {
+ const m_str str = mp_malloc2(gwion->mp, sz + 1);
+ memcpy(str, content, sz);
+ str[sz] = 0;
+ compile_string(gwion, filename, str);
+ mp_free2(gwion->mp, sz + 1, str);
+}
+
+EOF
+
+echo "ANN void gwion_embed(const Gwion gwion) {" >> embed/embed_foot
+jq -rc '.libraries|.[]' <<< "$json" |
+ while read -r lib
+ do
+ path=$(jq -c '.path' <<< "$lib" | sed -e 's/^"//' -e 's/"$//')
+ names=$(jq -c '.names' <<< "$lib")
+ config "LDFLAGS += $path"
+ if [ "$names" != "null" ]
+ then
+ jq -c '.[]' <<< "$names" | sed -e 's/^"//' -e 's/"$//' |
+ while read -r name
+ do
+ echo " embed_${name}(gwion);" >> embed/embed_foot
+ handle_lib "$path" "$name"
+ done
+ fi
+ done
+
+handle_script() {
+ name="script$2"
+ xxd -name "$name" -i "$1" > "embed/${name}.h"
+ header "#include \"${name}.h\""
+ echo " compile_script(gwion, \"$name\", ${name}, ${name}_len);"
+}
+
+handle_scripts() {
+ i=0
+ jq -r '.scripts|.[]' <<< "$json" |
+ while read -r name;
+ do handle_script "$name" "$i"; i=$((i+1));
+ done
+}
+
+handle_scripts >> embed/embed_foot
+echo "}" >> embed/embed_foot
+
+cat embed/embed_head embed/embed_body embed/embed_foot > embed/embed.c
+rm embed/embed_head embed/embed_body embed/embed_foot
+
+++ /dev/null
-#!/bin/sh
-header_name() {
- echo "$1" | sed 's/\./_/' | sed 's#/#_#g'
-}
-
-cat << EOF
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "gwion_env.h"
-#include "vm.h"
-#include "instr.h"
-#include "emit.h"
-#include "compile.h"
-#include "gwion.h"
-
-static void compile_embed_gw(const Gwion gwion, const m_str filename,
- const m_str content, const size_t sz) {
- const m_str str = mp_malloc2(gwion->mp, sz + 1);
- memcpy(str, content, sz);
- str[sz] = 0;
- compile_string(gwion, filename, str);
- mp_free2(gwion->mp, sz + 1, str);
-}
-
-EOF
-
-for file in $GWION_EMBED_GW
-do
- name=$(header_name "$file")
- xxd -i "$file" > embed/"${name}.h"
- echo "#include \"${name}.h\""
-done
-
-
-
-echo "void embed_gw(const Gwion gwion) {"
-
-for file in $GWION_EMBED_GW
-do
- name=$(header_name "$file")
- xxd -i "$file" > "${name}.h"
- echo " compile_embed_gw(gwion, \"$file\", ${name}, ${name}_len);"
-
-done
-
-echo "}"
#include "vm.h"
#include "instr.h"
#include "emit.h"
-#include "driver.h"
#include "gwion.h"
+#include "plug.h"
+#include "driver.h"
#include "engine.h"
#include "arg.h"
#include "compile.h"
if (gwion_audio(gwion) > 0) {
CHECK_BB(plug_run(gwion, &arg->mod));
if (type_engine_init(gwion)) {
- // embed_plug(gwion);
vector_add(&gwion->data->plugs->vec, (m_uint)gwion->env->global_nspc);
gwion->vm->cleaner_shred = gwion_cleaner(gwion);
gwion->emit->locale = gwion_locale(gwion);
- // (void)arg_compile(gwion, arg);
return GW_OK;
}
}
gwidoc(gwi, "internal base of all objects and structures.");
- GWI_BB(import_enum(gwi));
+ GWI_BB(gwimport_enum(gwi));
const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL);
GWI_BB(gwi_gack(gwi, t_compound, gack_compound))
GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound))
- GWI_BB(import_object(gwi))
+ GWI_BB(gwimport_object(gwi))
- GWI_BB(import_prim(gwi))
- GWI_BB(import_func(gwi))
- GWI_BB(import_object_op(gwi))
- GWI_BB(import_values(gwi))
- GWI_BB(import_union(gwi))
+ GWI_BB(gwimport_prim(gwi))
+ GWI_BB(gwimport_func(gwi))
+ GWI_BB(gwimport_object_op(gwi))
+ GWI_BB(gwimport_values(gwi))
+ GWI_BB(gwimport_union(gwi))
- GWI_BB(import_array(gwi))
- GWI_BB(import_event(gwi))
- GWI_BB(import_ugen(gwi))
- GWI_BB(import_xork(gwi))
+ GWI_BB(gwimport_array(gwi))
+ GWI_BB(gwimport_event(gwi))
+ GWI_BB(gwimport_ugen(gwi))
+ GWI_BB(gwimport_xork(gwi))
GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL))
GWI_BB(gwi_oper_add(gwi, opck_new))
GWI_BB(gwi_oper_emi(gwi, opem_new))
GWI_BB(gwi_oper_end(gwi, "new", NULL))
- GWI_BB(import_ref(gwi))
- GWI_BB(import_string(gwi))
- GWI_BB(import_shred(gwi))
- GWI_BB(import_modules(gwi))
+ GWI_BB(gwimport_ref(gwi))
+ GWI_BB(gwimport_string(gwi))
+ GWI_BB(gwimport_shred(gwi))
+ GWI_BB(gwimport_modules(gwi))
gwidoc(gwi, "allow member access.");
GWI_BB(gwi_oper_ini(gwi, "@Compound", (m_str)OP_ANY_TYPE, NULL))
GWI_BB(gwi_oper_emi(gwi, opem_object_dot))
GWI_BB(gwi_oper_end(gwi, ".", NULL))
- GWI_BB(import_class(gwi))
+ GWI_BB(gwimport_class(gwi))
gwidoc(gwi, "allow static access.");
GWI_BB(gwi_oper_ini(gwi, "Class", (m_str)OP_ANY_TYPE, NULL))
GWI_BB(gwi_oper_add(gwi, opck_object_dot))
GWI_BB(gwi_oper_emi(gwi, opem_object_dot))
GWI_BB(gwi_oper_end(gwi, ".", NULL))
- GWI_BB(import_deep_equal(gwi));
+ GWI_BB(gwimport_deep_equal(gwi));
- GWI_BB(import_dict(gwi));
- GWI_BB(import_gack(gwi));
- GWI_BB(import_sift(gwi));
- GWI_BB(import_locale(gwi));
+ GWI_BB(gwimport_dict(gwi));
+ GWI_BB(gwimport_gack(gwi));
+ GWI_BB(gwimport_sift(gwi));
+ GWI_BB(gwimport_locale(gwi));
// seemed need at a point to ease liking
}
GWION_IMPORT(modules) {
- GWI_BB(import_gain(gwi))
- GWI_BB(import_impulse(gwi))
- GWI_BB(import_fullrect(gwi))
- GWI_BB(import_halfrect(gwi))
- GWI_BB(import_step(gwi))
- GWI_BB(import_zerox(gwi))
- return import_usrugen(gwi);
+ GWI_BB(gwimport_gain(gwi))
+ GWI_BB(gwimport_impulse(gwi))
+ GWI_BB(gwimport_fullrect(gwi))
+ GWI_BB(gwimport_halfrect(gwi))
+ GWI_BB(gwimport_step(gwi))
+ GWI_BB(gwimport_zerox(gwi))
+ return gwimport_usrugen(gwi);
}
}
static GWION_IMPORT(int) {
- GWI_BB(import_int_values(gwi))
+ GWI_BB(gwimport_int_values(gwi))
GWI_BB(gwi_oper_cond(gwi, "int", BranchEqInt, BranchNeqInt))
GWI_BB(gwi_oper_ini(gwi, "int", "int", "int"))
- GWI_BB(import_int_op(gwi))
- GWI_BB(import_int_logical(gwi))
- GWI_BB(import_int_r(gwi))
- GWI_BB(import_int_unary(gwi))
+ GWI_BB(gwimport_int_op(gwi))
+ GWI_BB(gwimport_int_logical(gwi))
+ GWI_BB(gwimport_int_r(gwi))
+ GWI_BB(gwimport_int_unary(gwi))
return GW_OK;
}
return GW_OK;
}
-ANN static m_bool import_ux(const Gwi gwi) {
+ANN static GWION_IMPORT(ux) {
char c[8] = { 'u' };
const Env env = gwi->gwion->env;
for(uint i = 1; i <= SZ_INT; i *= 2) {
}
GWION_IMPORT(prim) {
- GWI_BB(import_int(gwi))
- GWI_BB(import_ux(gwi));
- GWI_BB(import_float(gwi)) // const folded
- GWI_BB(import_intfloat(gwi)) // const folded
- GWI_BB(import_floatint(gwi)) // const folded
- GWI_BB(import_dur(gwi))
- return import_time(gwi);
+ GWI_BB(gwimport_int(gwi))
+ GWI_BB(gwimport_ux(gwi));
+ GWI_BB(gwimport_float(gwi)) // const folded
+ GWI_BB(gwimport_intfloat(gwi)) // const folded
+ GWI_BB(gwimport_floatint(gwi)) // const folded
+ GWI_BB(gwimport_dur(gwi))
+ return gwimport_time(gwi);
}
_CHECK_OP(":~>", chuck_ugen, TrigAUConnect)
_CHECK_OP(":~<", chuck_ugen, TrigAUDisconnect)
- return import_global_ugens(gwi);
+ return gwimport_global_ugens(gwi);
}
#else
#ifdef GWION_EMBED_GW
-void embed_gw(const Gwion);
+void gwion_embed(const Gwion);
#endif
int main(int argc, char **argv) {
signal(SIGINT, sig);
signal(SIGTERM, sig);
const m_bool ini = gwion_ini(&gwion, &arg);
-// embed_plug(&gwion);
-gwion_embed(&gwion);
- arg_compile(&gwion, &arg);
- arg_release(&arg);
#ifdef GWION_EMBED_GW
-// embed_gw(&gwion);
+ gwion_embed(&gwion);
#endif
+ arg_compile(&gwion, &arg);
+ arg_release(&arg);
if (ini > 0) gwion_run(&gwion);
gwion_end(&gwion);
gwion.vm = NULL;
#include "import.h"
#include "gwi.h"
-typedef m_bool (*plugin)(Gwi);
-
struct PlugHandle {
MemPool mp;
Map map;
size_t len;
};
-typedef struct Plug_ {
- void *dl;
- void *self;
- Nspc nspc;
- gwplugin_t plugin;
- gwdriver_t driver;
- gwmodini_t modini;
- gwmodend_t modend;
- gwdepend_t depend;
-} * Plug;
-
-ANN static struct Plug_ *new_plug(MemPool p, void *dl) {
- struct Plug_ *plug = mp_calloc(p, Plug);
- plug->dl = dl;
- plug->plugin = DLSYM(plug->dl, gwplugin_t, GWIMPORT_NAME);
- plug->modini = DLSYM(plug->dl, gwmodini_t, GWMODINI_NAME);
- plug->modend = DLSYM(plug->dl, gwmodend_t, GWMODEND_NAME);
- plug->depend = DLSYM(plug->dl, gwdepend_t, GWDEPEND_NAME);
+ANN static struct Plug_ *new_dl_plug(MemPool p, void *dl, const char *name) {
+ Plug plug = new_plug(p);
+ plug->dl = dl;
+ char s[256] = { [0] = 'g', [1] = 'w', [8] = '_' };
+ strcpy(s + 9, name);
+ memcpy(s + 2, "import", 6);
+ plug->plugin = DLSYM(plug->dl, gwplugin_t, s);
+ memcpy(s + 2, "modini", 6);
+ plug->modini = DLSYM(plug->dl, gwmodini_t, s);
+ memcpy(s + 2, "modend", 6);
+ plug->modend = DLSYM(plug->dl, gwmodend_t, s);
+ memcpy(s + 2, "driver", 6);
+ plug->driver = DLSYM(plug->dl, gwdriver_t, s);
+ memcpy(s + 2, "depend", 6);
+ plug->depend = DLSYM(plug->dl, gwdepend_t, s);
return plug;
}
memcpy(name, pname, sz);
name[sz] = '\0';
if (dl) {
- Plug plug = new_plug(h->mp, dl);
+ Plug plug = new_dl_plug(h->mp, dl, name);
map_set(h->map, (vtype)strdup(name), (vtype)plug);
} else
gw_err(_("{+R}error{0} in {/+}%s{0}."), DLERROR());
const m_str dir = (m_str)vector_at(list, i - 1);
h.len = strlen(dir);
char name[PATH_MAX];
- sprintf(name, "%s/*.so" /**/, dir);
+ sprintf(name, "%s/*.so", dir);
plug_get_all(&h, name);
}
return GW_OK;
const gwmodend_t end = plug->modend;
if (end && plug->self) end(gwion, plug->self);
free((m_str)VKEY(map, i));
- DLCLOSE(plug->dl);
+ if(plug->dl) DLCLOSE(plug->dl);
}
map_release(map);
mp_free2(gwion->mp, sizeof(Plugs), gwion->data->plugs);
free_vector(p, v);
}
-ANN void set_module(const struct Gwion_ *gwion, const m_str name,
+ANN m_bool set_module(const struct Gwion_ *gwion, const m_str name,
void *const ptr) {
const Map map = &gwion->data->plugs->map;
for (m_uint j = 0; j < map_size(map); ++j) {
if (!strcmp(name, (m_str)VKEY(map, j))) {
Plug plug = (Plug)VVAL(map, j);
plug->self = ptr;
- return;
+ return GW_OK;
}
}
- const Plug plug = new_plug(gwion->mp, name);
- plug->self = ptr;
- map_set(map, (m_uint)name, (m_uint)plug);
+ gw_err("module %s not found\n", name);
+ return GW_ERROR;
}
ANN m_bool plug_run(const struct Gwion_ *gwion, const Map mod) {
if (opt) *opt = '\0';
for (m_uint i = 0; i < map_size(map); ++i) {
const m_str name = (m_str)VKEY(map, i);
+ printf("%s %s\n", name, dname);
if (!strcmp(name, dname)) {
+ puts("hey");
const Plug plug = (Plug)VVAL(map, i);
- const f_bbqset drv = DLSYM(plug->dl, f_bbqset, GWDRIVER_NAME);
+ const gwdriver_t drv = plug->driver;
if (!drv) break;
gwion->vm->bbq->func = drv;
if (opt) *opt = c;
#include "instr.h"
#include "import.h"
-GWION_IMPORT(end_class) {
+GWION_IMPORT(non_driver) {
(void)gwi;
return GW_OK;
}
#include "gwion_ast.h"
#include "gwion_env.h"
#include "vm.h"
+#include "plug.h"
#include "driver.h"
#include "gwion.h"
-#include "plug.h"
static DRVRUN(simple_driver_run) {
while (di->is_running) {
#include "gwion_ast.h"
#include "gwion_env.h"
#include "vm.h"
-#include "driver.h"
#include "gwion.h"
#include "object.h"
#include "instr.h"
#include "import.h"
#include "gwi.h"
#include "plug.h"
+#include "driver.h"
GWMODINI(get_module) {
puts(__func__);
GWMODEND(get_module) { puts(__func__); }
-GWION_IMPORT(dummy_module) {
- set_module(gwi->gwion, "get_module", (void *)1);
+GWION_IMPORT(get_module) {
+ CHECK_BB(set_module(gwi->gwion, "get_module", (void *)1));
GWI_OB(get_module(gwi->gwion, "get_module"))
puts("test passed");
get_module(gwi->gwion, "non_existant_module");
#include "gwion_ast.h"
#include "gwion_env.h"
#include "vm.h"
+#include "plug.h"
#include "driver.h"
#include "gwion.h"
-#include "plug.h"
GWMODINI(dummy_module) {
puts(__func__);
MFUN(test_mfun) {}
-GWION_IMPORT(array_test) {
+GWION_IMPORT(array) {
GWI_OB(gwi_class_ini(gwi, "ArrayTest", NULL))
GWI_BB(gwi_item_ini(gwi, "int[]", "int_array"))
GWI_BB(gwi_item_end(gwi, 0, obj, NULL)) // import array var
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(checker) {
+GWION_IMPORT(array_in_var_name) {
gwi_item_ini(gwi, "int", "array[2][3]");
return GW_OK;
}
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(checker) {
+GWION_IMPORT(array_in_var_name_fail) {
GWI_BB(gwi_union_ini(gwi, "U"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
return GW_OK;
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(checker) {
+GWION_IMPORT(array_incoherent_in_var_name) {
gwi_item_ini(gwi, "int", "array[2][3][]");
return GW_OK;
}
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(checker) {
+GWION_IMPORT(array_invalid_in_var_name) {
gwi_item_ini(gwi, "int", "array[.]");
return GW_OK;
}
#define MAP_KEY(a) *((M_Object *)(a->data + o_map_key))
#define MAP_VAL(a) *((M_Object *)(a->data + o_map_value))
-GWION_IMPORT(class_template) {
+GWION_IMPORT(class_template_invalid) {
GWI_OB(gwi_class_ini(gwi, "ClassTemplate:[A,B]", NULL))
GWI_BB(gwi_item_ini(gwi, "A[]", "key"))
GWI_BB((o_map_key = gwi_item_end(gwi, ae_flag_none, obj, NULL)))
#define _XOPEN_SOURCE 500
#include <string.h>
-GWION_IMPORT(compile_string) {
+GWION_IMPORT(compile_file) {
DECL_OB(FILE *, file, = fopen("rm_me.gw", "w+"));
fprintf(file, "1;");
rewind(file);
}
static const m_str deps[] = {"array", NULL};
-GWDEPEND { return deps; }
+GWDEPEND(deps) { return deps; }
#include "operator.h"
#include "import.h"
-GWION_IMPORT(empty_union_test) {
+GWION_IMPORT(empty_union) {
GWI_BB(gwi_union_ini(gwi, "U"))
GWI_OB(gwi_union_end(gwi, 0))
return GW_OK;
#include "operator.h"
#include "import.h"
-GWION_IMPORT(enum_test) {
+GWION_IMPORT(enum) {
GWI_BB(gwi_enum_ini(gwi, "test"))
GWI_BB(gwi_enum_add(gwi, "TYPED_ENUM0", 0))
GWI_BB(gwi_enum_add(gwi, "TYPED_ENUM1", 1))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(enum_test) {
+GWION_IMPORT(enum_fail) {
GWI_BB(gwi_enum_ini(gwi, "int"))
GWI_BB(gwi_enum_add(gwi, "zero", 0))
GWI_OB(gwi_enum_end(gwi))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(enum_test) {
+GWION_IMPORT(enum_fail2) {
GWI_BB(gwi_enum_ini(gwi, "tmp"))
GWI_BB(gwi_enum_add(gwi, "adc", 0))
GWI_OB(gwi_enum_end(gwi))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(enum_test) {
+GWION_IMPORT(enum_fail3) {
GWI_BB(gwi_enum_ini(gwi, "test"))
GWI_BB(gwi_enum_add(gwi, "adc", 0))
GWI_BB(gwi_enum_ini(gwi, "error"))
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(extend_array_test) {
+GWION_IMPORT(extend_array) {
GWI_OB(gwi_class_ini(gwi, "ArrayExt", "float[1]"))
GWI_BB(gwi_class_end(gwi))
return GW_OK;
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(fail_on_next_arg) {
+GWION_IMPORT(fail_on_next_arg2) {
GWI_BB(gwi_func_ini(gwi, "void", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i"))
GWI_BB(gwi_func_arg(gwi, "i;t", "j"))
#include "import.h"
static MFUN(test_func) { puts("test"); }
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(fptr) {
GWI_BB(gwi_fptr_ini(gwi, "void", "PtrType"))
GWI_OB(gwi_fptr_end(gwi, 0))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(fptr_tmpl) {
Type t_func_typedef;
GWI_OB((t_func_typedef = gwi_mk_type(gwi, "FuncTypedef", SZ_INT, NULL)))
GWI_BB(gwi_fptr_ini(gwi, "int", "test:[test]"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(fptr_tmpl_fail) {
GWI_BB(gwi_fptr_ini(gwi, "int~", "test:[A]"))
GWI_OB(gwi_fptr_end(gwi, 0))
return GW_OK;
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_fail) {
GWI_BB(gwi_func_ini(gwi, "int", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i[][]"))
GWI_BB(gwi_func_arg(gwi, "Int", "i"))
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_fail2) {
GWI_BB(gwi_func_ini(gwi, ":[int]Ptr", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i[][]"))
GWI_BB(gwi_func_arg(gwi, "int", "me"))
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_fail3) {
GWI_BB(gwi_func_ini(gwi, "Ptr:[int]", "test:[A]"))
GWI_BB(gwi_func_ini(gwi, "int", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i[][]"))
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_fail4) {
GWI_BB(gwi_func_ini(gwi, "Ptr:[int]", "test:[A]"))
GWI_BB(gwi_func_arg(gwi, "int", "i[][]"))
GWI_BB(gwi_item_end(gwi, ae_flag_none, num, 0))
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_subscript_not_empty) {
GWI_BB(gwi_func_ini(gwi, "int[]", "test"))
GWI_BB(gwi_func_end(gwi, (f_xfun)1, ae_flag_none))
return GW_OK;
static SFUN(func_tmpl_xfun) {}
-GWION_IMPORT(func_tmpl) {
+GWION_IMPORT(func_tmpl_fail) {
GWI_BB(gwi_func_ini(gwi, "voit", "test:[A]"))
GWI_BB(gwi_func_end(gwi, func_tmpl_xfun, ae_flag_none))
return GW_OK;
#include "import.h"
#include "instr.h"
-GWION_IMPORT(too_many_args) {
+GWION_IMPORT(func_too_many_arg) {
GWI_BB(gwi_func_ini(gwi, "int", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i"))
GWI_BB(gwi_func_arg(gwi, "int", "j"))
*(m_int *)RETURN = *(m_int *)MEM(0);
}
-GWION_IMPORT(global_func_test) {
+GWION_IMPORT(global_func) {
GWI_BB(gwi_func_ini(gwi, "int", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i"))
GWI_BB(gwi_func_end(gwi, coverage_int, ae_flag_none))
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(global_var_test) {
+GWION_IMPORT(global_var) {
const M_Object o =
new_object(gwi->gwion->mp, gwi->gwion->type[et_string]);
STRING(o) = s_name(insert_symbol(gwi->gwion->st, "test"));
#include "import.h"
static MFUN(test_mfun) {}
-GWION_IMPORT(invalid_arg_test) {
+GWION_IMPORT(invalid_arg) {
GWI_OB(gwi_class_ini(gwi, "InvalidArg", NULL))
GWI_BB(gwi_func_ini(gwi, "int[]", "func"))
GWI_BB(gwi_func_arg(gwi, ".int", "i"))
#include "import.h"
static MFUN(test_mfun) {}
-GWION_IMPORT(invalid_array_test) {
+GWION_IMPORT(invalid_array) {
GWI_OB(gwi_class_ini(gwi, "InvalidArray", NULL))
GWI_BB(gwi_func_ini(gwi, "int[]", "func"))
GWI_BB(gwi_func_arg(gwi, "int[][]", "i"))
#include "import.h"
static MFUN(test_mfun) {}
-GWION_IMPORT(invalid_func_test) {
+GWION_IMPORT(invalid_func) {
GWI_OB(gwi_class_ini(gwi, "t_invalid_var_type", NULL))
GWI_BB(gwi_func_ini(gwi, ".int", "i"))
GWI_BB(gwi_func_end(gwi, test_mfun, ae_flag_static))
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(trig) {
+GWION_IMPORT(invalid_names) {
DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T~", SZ_INT, NULL));
gwi_add_type(gwi, t0);
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(trig) {
+GWION_IMPORT(invalid_names0) {
DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T~", SZ_INT, NULL));
gwi_add_type(gwi, t0);
return GW_OK;
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(trig) {
+GWION_IMPORT(invalid_names1) {
DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T,", SZ_INT, NULL));
gwi_add_type(gwi, t0);
return GW_OK;
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(trig) {
+GWION_IMPORT(invalid_names2) {
DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T<a>", SZ_INT, NULL));
gwi_add_type(gwi, t0);
return GW_OK;
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(trig) {
+GWION_IMPORT(invalid_names3) {
DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T:[a]", SZ_INT, NULL));
gwi_add_type(gwi, t0);
return GW_OK;
#include "operator.h"
#include "import.h"
-GWION_IMPORT(invalid_type1_test) {
+GWION_IMPORT(invalid_type1) {
GWI_OB(gwi_class_ini(gwi, "invalid_var_type", NULL))
GWI_BB(gwi_item_ini(gwi, "i|nt", "test"))
GWI_BB(gwi_item_end(gwi, 0, num, 0))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(invalid_type2_test) {
+GWION_IMPORT(invalid_type2) {
GWI_OB(gwi_class_ini(gwi, "invalid_var_type", NULL))
GWI_BB(gwi_item_ini(gwi, ".int", "test"))
GWI_BB(gwi_item_end(gwi, 0, num, 0))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(invalid_type3_test) {
+GWION_IMPORT(invalid_type3) {
GWI_OB(gwi_class_ini(gwi, "InvalidVarType", NULL))
GWI_BB(gwi_item_ini(gwi, ".int", "test"))
GWI_BB(gwi_item_end(gwi, 0, num, 0))
#include "gwi.h"
MFUN(test_mfun) {}
-GWION_IMPORT(begin_class) {
+GWION_IMPORT(mk_type_array) {
Type t_invalid_var_name;
GWI_OB((t_invalid_var_name =
gwi_mk_type(gwi, "invalid_var_name", SZ_INT, "Object[]")))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(enum_test) {
+GWION_IMPORT(not_importing) {
GWI_BB(gwi_enum_add(gwi, "adc", 0))
return GW_OK;
}
ANN static m_bool pass(Env nv NUSED, Ast *ast NUSED) { return GW_OK; }
-GWION_IMPORT(array_test) {
+GWION_IMPORT(pass) {
gwi_register_pass(gwi, "dummy", pass);
return GW_OK;
}
return GW_OK;
}
-GWION_IMPORT(spid_test) {
+GWION_IMPORT(specialid_emit) {
struct SpecialId_ spid = {
.type = gwi->gwion->type[et_int], .em = spidem, .is_const = 1};
gwi_specialid(gwi, "testid", &spid);
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(static_string_test) {
+GWION_IMPORT(static_string) {
const M_Object o =
new_object(gwi->gwion->mp, gwi->gwion->type[et_string]);
STRING(o) = s_name(insert_symbol(gwi->gwion->st, "test static string"));
#include "ugen.h"
#include "gwi.h"
-GWION_IMPORT(str2td) {
+GWION_IMPORT(str2decl) {
GWI_OB(gwi_class_ini(gwi, "Test", NULL))
GWI_OB(gwi_class_ini(gwi, "Child", NULL))
GWI_BB(gwi_class_end(gwi))
#include "import.h"
#include "gwi.h"
-GWION_IMPORT(global_var_test) {
+GWION_IMPORT(str2list_fail) {
GWI_BB(gwi_item_ini(gwi, "SoemClass.child", "i"))
GWI_BB(gwi_item_end(gwi, ae_flag_none, num, 0))
return GW_OK;
SFUN(coverage_int) { *(m_uint *)RETURN = 0; }
SFUN(coverage_float) { *(m_float *)RETURN = 0; }
-GWION_IMPORT(coverage) {
+GWION_IMPORT(struct) {
GWI_OB(gwi_struct_ini(gwi, "Struct"))
GWI_BB(gwi_func_ini(gwi, "int", "i"))
GWI_BB(gwi_func_end(gwi, coverage_int, ae_flag_static))
#include "import.h"
static MFUN(template_arg_fun) {}
-GWION_IMPORT(template_arg_test) {
+GWION_IMPORT(template_arg) {
GWI_OB(gwi_class_ini(gwi, "TemplateArg", NULL))
GWI_BB(gwi_func_ini(gwi, "int", "set"))
GWI_BB(gwi_func_arg(gwi, "Pair<Ptr<int>,float>", "test"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(typedef) {
GWI_OB(gwi_typedef_ini(gwi, "int", "Typedef"))
GWI_OB(gwi_typedef_end(gwi, ae_flag_none))
return GW_OK;
#include "operator.h"
#include "import.h"
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(typedef_fail) {
GWI_BB(gwi_typedef_ini(gwi, "int", "Typedef:[A]"))
GWI_BB(gwi_typedef_ini(gwi, "int", "Typedef:[A]"))
return GW_OK;
#include "operator.h"
#include "import.h"
-GWION_IMPORT(typedef_test) {
+GWION_IMPORT(typedef_tmpl) {
GWI_BB(gwi_typedef_ini(gwi, "Ptr:[A]", "Typedef:[A]"))
GWI_OB(gwi_typedef_end(gwi, ae_flag_none))
return GW_OK;
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union) {
GWI_BB(gwi_union_ini(gwi, "U"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_fail_exp) {
GWI_BB(gwi_union_ini(gwi, "U"))
GWI_BB(gwi_union_add(gwi, "Float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_name) {
GWI_BB(gwi_union_ini(gwi, "my_union"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_tmpl) {
GWI_BB(gwi_union_ini(gwi, "U:[A]"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_tmpl_fail) {
GWI_BB(gwi_union_ini(gwi, "U:[A]"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_tmpl_fail2) {
GWI_BB(gwi_union_ini(gwi, "U:[A]"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
#include "operator.h"
#include "import.h"
-GWION_IMPORT(union_test) {
+GWION_IMPORT(union_tmpl_fail3) {
GWI_BB(gwi_union_ini(gwi, "U:[A]"))
GWI_BB(gwi_union_add(gwi, "float", "f"))
GWI_BB(gwi_union_add(gwi, "int", "i"))
SFUN(coverage_int) { vm_remove(shred->info->vm, *(m_int *)MEM(0)); }
-GWION_IMPORT(gwion_remove_test) {
+GWION_IMPORT(vm_remove) {
GWI_BB(gwi_func_ini(gwi, "int", "test"))
GWI_BB(gwi_func_arg(gwi, "int", "i"))
GWI_BB(gwi_func_end(gwi, coverage_int, ae_flag_none))
#!/bin/bash
-# [test] #24
+# [test] #23
n=0
[ "$1" ] && n="$1"
[ "$n" -eq 0 ] && n=1
source tests/sh/common.sh
-run "$n" "test arguments" "examples/shred.gw:12" "file"
+run "$n" "test arguments" "examples/array_lit:12" "file"
n=$((n+1))
-N=$(printf "% 4i" "$n")
run "$n" "simple run" "" "file"
# help
n=$((n+1))
run "$n" "option needs argument" "-p" "file"
-# option needs argument
-n=$((n+1))
-echo "<<< __file__ >>>;" | run "$n" "stdin" "-" "file"
-
# invalid global type
n=$((n+1))
run "$n" "invalid global type" "examples/complex/invalid_type0.gw examples/complex/invalid_type1.gw" "file"
-Subproject commit 3779cb727cf3bf1dd379702b7f3665a1432041a2
+Subproject commit d12448118cc4366fb8871f1f149626969fad775a