10. WIP Trig Runt Words

10.1. DONE Runt Loader

CLOSED: [2020-04-19 Sun 18:53] All runt words are loaded with the function trig_runt_loader. It is loaded at init time.

<<trig_function_declarations>>=
static int trig_runt_loader(monolith_d *m);
<<trig_functions>>=
<<trig_runt_functions>>
static int trig_runt_loader(monolith_d *m)
{
<<trig_runt_keywords>>
    monolith_runt_mark_set(m);
    return RUNT_OK;
}
<<trig_runtime_init>>=
trig_runt_loader(m);

10.2. DONE Trigclk Word

CLOSED: [2020-04-19 Sun 18:53]

<<trig_runt_keywords>>=
monolith_runt_keyword(m, "trigclk", 7, rproc_trigclk, m);
<<trig_runt_functions>>=
static runt_int rproc_trigclk(runt_vm *vm, runt_ptr p)
{
    monolith_d *m;
    runt_int rc;
    rgf_param in;
    gf_patch *patch;
    gf_node *node;
    const char *name;
    runt_stacklet *s;
    monolith_page *pg;
    page_trig_d *trig;

    m = runt_to_cptr(p);
    rc = runt_ppop(vm, &s);
    RUNT_ERROR_CHECK(rc);

    name = runt_to_string(s->p);

    rc = rgf_get_param(vm, &in);
    RUNT_ERROR_CHECK(rc);

    rc = runt_monolith_lookup_page(vm, m,
                                   name, "trig",
                                   is_trig, &pg);
    RUNT_ERROR_CHECK(rc);

    trig = monolith_page_data_get(pg);

    patch = monolith_graforge_get(m);
    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);
    node_trigclk(node, trig);

    rgf_set_param(vm, node, &in, 0);
    return RUNT_OK;
}

10.3. Trigex Word

<<trig_runt_keywords>>=
monolith_runt_keyword(m, "trigex", 6, rproc_trigex, m);
<<trig_runt_functions>>=
static runt_int rproc_trigex(runt_vm *vm, runt_ptr p)
{
    monolith_d *m;
    runt_int rc;
    gf_patch *patch;
    gf_node *node;
    const char *name;
    runt_stacklet *s;
    monolith_page *pg;
    page_trig_d *trig;

    m = runt_to_cptr(p);
    rc = runt_ppop(vm, &s);
    RUNT_ERROR_CHECK(rc);

    name = runt_to_string(s->p);

    rc = runt_monolith_lookup_page(vm, m,
                                   name, "trig",
                                   is_trig, &pg);
    RUNT_ERROR_CHECK(rc);

    trig = monolith_page_data_get(pg);

    patch = monolith_graforge_get(m);
    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);
    node_trigex(node, trig);
    return RUNT_OK;
}

10.4. Trigwget Word

<<trig_runt_keywords>>=
monolith_runt_keyword(m, "trigwget", 8, rproc_trigwget, m);
<<trig_runt_functions>>=
static runt_int rproc_trigwget(runt_vm *vm, runt_ptr p)
{
    monolith_d *m;
    runt_int rc;
    gf_patch *patch;
    gf_node *node;
    const char *name;
    runt_stacklet *s;
    monolith_page *pg;
    page_trig_d *trig;
    rgf_param pwire;
    int wire;
    runt_stacklet *out;

    m = runt_to_cptr(p);
    rc = runt_ppop(vm, &s);
    RUNT_ERROR_CHECK(rc);

    name = runt_to_string(s->p);

    rc = runt_monolith_lookup_page(vm, m,
                                   name, "trig",
                                   is_trig, &pg);
    RUNT_ERROR_CHECK(rc);

    rc = rgf_get_param(vm, &pwire);
    RUNT_ERROR_CHECK(rc);

    if (!rgf_param_is_constant(&pwire)) {
        runt_print(vm, "wire must be a constant\n");
        return RUNT_NOT_OK;
    }

    wire = rgf_param_get_constant(&pwire);

    rc = runt_ppush(vm, &out);
    RUNT_ERROR_CHECK(rc);

    trig = monolith_page_data_get(pg);

    patch = monolith_graforge_get(m);
    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);
    rc = node_trigwget(node, trig, wire);
    GF_RUNT_ERROR_CHECK(rc);

    rgf_push_output(vm, node, out, 0);
    return RUNT_OK;
}

10.5. Trigrex Word

<<trig_runt_keywords>>=
monolith_runt_keyword(m, "trigrex", 7, rproc_trigrex, m);
<<trig_runt_functions>>=
static runt_int rproc_trigrex(runt_vm *vm, runt_ptr p)
{
    monolith_d *m;
    runt_int rc;
    gf_patch *patch;
    gf_node *node;
    const char *name;
    runt_stacklet *s;
    monolith_page *pg;
    page_trig_d *trig;
    rgf_param pos;

    m = runt_to_cptr(p);
    rc = runt_ppop(vm, &s);
    RUNT_ERROR_CHECK(rc);

    name = runt_to_string(s->p);

    rc = runt_monolith_lookup_page(vm, m,
                                   name, "trig",
                                   is_trig, &pg);
    RUNT_ERROR_CHECK(rc);

    rc = rgf_get_param(vm, &pos);
    RUNT_ERROR_CHECK(rc);

    trig = monolith_page_data_get(pg);

    if (!rgf_param_is_constant(&pos)) {
        runt_print(vm, "trigrex: pos must be a constant\n");
        return RUNT_NOT_OK;
    }

    patch = monolith_graforge_get(m);
    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);
    node_trigrex(node, trig, rgf_param_get_constant(&pos));
    return RUNT_OK;
}



prev | home | next