cross-program namespace access
This commit is contained in:
parent
0f844b4e09
commit
64e716af6f
20
src/load.c
20
src/load.c
@ -1,15 +1,15 @@
|
|||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
Block* compB(B x) { // consumes
|
Block* load_compObj(B x) { // consumes
|
||||||
BS2B xget = TI(x).get;
|
BS2B xget = TI(x).get;
|
||||||
usz xia = a(x)->ia;
|
usz xia = a(x)->ia;
|
||||||
if (xia!=5 & xia!=3) thrM("compB: bad item count");
|
if (xia!=5 & xia!=3) thrM("load_compObj: bad item count");
|
||||||
Block* r = xia==5? compile(xget(x,0),xget(x,1),xget(x,2),xget(x,3),xget(x,4))
|
Block* r = xia==5? compile(xget(x,0),xget(x,1),xget(x,2),xget(x,3),xget(x,4))
|
||||||
: compile(xget(x,0),xget(x,1),xget(x,2),bi_N,bi_N);
|
: compile(xget(x,0),xget(x,1),xget(x,2),bi_N,bi_N);
|
||||||
dec(x);
|
dec(x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
Block* compile3(B bc, B objs, B blocks) { // consumes all
|
Block* load_compImport(B bc, B objs, B blocks) { // consumes all
|
||||||
return compile(bc, objs, blocks, bi_N, bi_N);
|
return compile(bc, objs, blocks, bi_N, bi_N);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ B bqn_fmt(B x) { // consumes
|
|||||||
|
|
||||||
|
|
||||||
Block* bqn_comp(B str) { // consumes
|
Block* bqn_comp(B str) { // consumes
|
||||||
return compB(c2(load_comp, inc(load_compArg), str));
|
return load_compObj(c2(load_comp, inc(load_compArg), str));
|
||||||
}
|
}
|
||||||
B bqn_exec(B str) { // consumes
|
B bqn_exec(B str) { // consumes
|
||||||
Block* block = bqn_comp(str);
|
Block* block = bqn_comp(str);
|
||||||
@ -33,7 +33,7 @@ B bqn_exec(B str) { // consumes
|
|||||||
ptr_dec(block);
|
ptr_dec(block);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
void bqn_setComp(B comp) {
|
void bqn_setComp(B comp) { // consumes; doesn't unload old comp, but whatever
|
||||||
load_comp = comp;
|
load_comp = comp;
|
||||||
gc_add(load_comp);
|
gc_add(load_comp);
|
||||||
}
|
}
|
||||||
@ -66,14 +66,14 @@ static inline void load_init() {
|
|||||||
#ifndef ALL_R0
|
#ifndef ALL_R0
|
||||||
B runtime_0[] = {bi_floor,bi_ceil,bi_stile,bi_lt,bi_gt,bi_ne,bi_ge,bi_rtack,bi_ltack,bi_join,bi_take,bi_drop,bi_select,bi_const,bi_swap,bi_each,bi_fold,bi_atop,bi_over,bi_before,bi_after,bi_cond,bi_repeat};
|
B runtime_0[] = {bi_floor,bi_ceil,bi_stile,bi_lt,bi_gt,bi_ne,bi_ge,bi_rtack,bi_ltack,bi_join,bi_take,bi_drop,bi_select,bi_const,bi_swap,bi_each,bi_fold,bi_atop,bi_over,bi_before,bi_after,bi_cond,bi_repeat};
|
||||||
#else
|
#else
|
||||||
Block* runtime0_b = compile3(
|
Block* runtime0_b = load_compImport(
|
||||||
#include "runtime0"
|
#include "runtime0"
|
||||||
);
|
);
|
||||||
B r0r = m_funBlock(runtime0_b, 0); ptr_dec(runtime0_b);
|
B r0r = m_funBlock(runtime0_b, 0); ptr_dec(runtime0_b);
|
||||||
B* runtime_0 = toHArr(r0r)->a;
|
B* runtime_0 = toHArr(r0r)->a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Block* runtime_b = compile3(
|
Block* runtime_b = load_compImport(
|
||||||
#include "runtime1"
|
#include "runtime1"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ static inline void load_init() {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef NO_COMP
|
#ifdef NO_COMP
|
||||||
Block* c = compB(
|
Block* c = load_compObj(
|
||||||
#include "interp"
|
#include "interp"
|
||||||
);
|
);
|
||||||
B interp = m_funBlock(c, 0); ptr_dec(c);
|
B interp = m_funBlock(c, 0); ptr_dec(c);
|
||||||
@ -129,7 +129,7 @@ static inline void load_init() {
|
|||||||
dec(interp);
|
dec(interp);
|
||||||
exit(0);
|
exit(0);
|
||||||
#else // use compiler
|
#else // use compiler
|
||||||
Block* comp_b = compile3(
|
Block* comp_b = load_compImport(
|
||||||
#include "compiler"
|
#include "compiler"
|
||||||
);
|
);
|
||||||
load_comp = m_funBlock(comp_b, 0); ptr_dec(comp_b);
|
load_comp = m_funBlock(comp_b, 0); ptr_dec(comp_b);
|
||||||
@ -137,7 +137,7 @@ static inline void load_init() {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef FORMATTER
|
#ifdef FORMATTER
|
||||||
Block* fmt_b = compile3(
|
Block* fmt_b = load_compImport(
|
||||||
#include "formatter"
|
#include "formatter"
|
||||||
);
|
);
|
||||||
B fmtM = m_funBlock(fmt_b, 0); ptr_dec(fmt_b);
|
B fmtM = m_funBlock(fmt_b, 0); ptr_dec(fmt_b);
|
||||||
|
|||||||
19
src/ns.c
19
src/ns.c
@ -50,14 +50,21 @@ B m_ns(Scope* sc, NSDesc* desc) { // consumes both
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
B ns_getU(B ns, B nameList, i32 nameID) {
|
B ns_getU(B ns, B cNL, i32 nameID) {
|
||||||
NS* n = c(NS, ns);
|
NS* n = c(NS, ns);
|
||||||
NSDesc* d = n->desc;
|
NSDesc* d = n->desc;
|
||||||
if (n->nameList.u != nameList.u) thrM("TODO cross-program namespace access");
|
i32 dVarAm = d->varAm;
|
||||||
i32 varAm = d->varAm;
|
assert(nameID<a(cNL)->ia && nameID>=0);
|
||||||
// printf("getting from %p with vam=%d\n", d, d->varAm);
|
B dNL = d->nameList;
|
||||||
assert(nameID<a(nameList)->ia && nameID>=0);
|
if (cNL.u != dNL.u) {
|
||||||
for (i32 i = 0; i < varAm; i++) {
|
B cName = TI(cNL).getU(cNL, nameID);
|
||||||
|
BS2B dNLgetU = TI(dNL).getU;
|
||||||
|
for (i32 i = 0; i < dVarAm; i++) {
|
||||||
|
i32 dID = d->expIDs[i];
|
||||||
|
if (dID>=0 && equal(dNLgetU(dNL, dID), cName)) return n->sc->vars[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i32 i = 0; i < dVarAm; i++) {
|
||||||
if (d->expIDs[i]==nameID) return n->sc->vars[i];
|
if (d->expIDs[i]==nameID) return n->sc->vars[i];
|
||||||
}
|
}
|
||||||
thrM("No key found");
|
thrM("No key found");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user