diff --git a/src/ns.c b/src/ns.c index 19856acf..ac6a4388 100644 --- a/src/ns.c +++ b/src/ns.c @@ -1,18 +1,5 @@ #include "ns.h" -typedef struct NSDesc { - struct Value; - B nameList; - i32 varAm; // number of items in expIDs (currently equal to sc->varAm/body->varAm) - i32 expIDs[]; // each item is an index in nameList (or -1), and its position is the corresponding position in sc->vars -} NSDesc; -typedef struct NS { - struct Value; - B nameList; // copy of desc->nameList for quick checking; isn't owned - NSDesc* desc; - Scope* sc; -} NS; - void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported) { // consumes nameList if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information"); diff --git a/src/ns.h b/src/ns.h index 0670470a..d722247f 100644 --- a/src/ns.h +++ b/src/ns.h @@ -1,9 +1,20 @@ #pragma once #include "h.h" -typedef struct Scope Scope; -typedef struct Body Body; -typedef struct NSDesc NSDesc; +#include "vm.h" + +typedef struct NSDesc { + struct Value; + B nameList; + i32 varAm; // number of items in expIDs (currently equal to sc->varAm/body->varAm) + i32 expIDs[]; // each item is an index in nameList (or -1), and its position is the corresponding position in sc->vars +} NSDesc; +typedef struct NS { + struct Value; + B nameList; // copy of desc->nameList for quick checking; isn't owned + NSDesc* desc; + Scope* sc; +} NS; + void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported); // consumes nameList B m_ns(Scope* sc, NSDesc* desc); // consumes both B ns_getU(B ns, B nameList, i32 nameID); // doesn't consume anything, doesn't increment result -B ns_nameList(NSDesc* d); \ No newline at end of file diff --git a/src/vm.c b/src/vm.c index c72d3135..3806fe94 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1,4 +1,4 @@ -#include "h.h" +#include "vm.h" #include "ns.h" // #define GS_REALLOC // whether to dynamically realloc gStack @@ -101,53 +101,6 @@ void printBC(i32* p) { while(len-->0) printf(" "); } -typedef struct Block Block; -typedef struct Body Body; -typedef struct Scope Scope; - -typedef struct Comp { - struct Value; - B bc; - B src; - B indices; - HArr* objs; - u32 blockAm; - Block* blocks[]; -} Comp; - -struct Block { - struct Value; - bool imm; - u8 ty; - Body* body; -}; - -typedef struct NSDesc NSDesc; -struct Body { - struct Value; - Comp* comp; - // B* objs; - i32* bc; // pointer in comp->bc - u32 maxStack; - u16 maxPSC; - u16 varAm; - u32 endStack; - NSDesc* nsDesc; - i32 varIDs[]; - // HArr* vNames; -}; - -struct Scope { - struct Value; - Scope* psc; - Body* body; - u16 varAm; - B vars[]; -}; - -typedef struct FunBlock { struct Fun; Scope* sc; Block* bl; } FunBlock; -typedef struct Md1Block { struct Md1; Scope* sc; Block* bl; } Md1Block; -typedef struct Md2Block { struct Md2; Scope* sc; Block* bl; } Md2Block; Block* compile(B bcq, B objs, B blocksq, B indices, B tokenInfo, B src) { // consumes all @@ -261,7 +214,7 @@ void v_set(Scope* pscs[], B s, B x, bool upd) { // doesn't consume if (!isVar(c)) thrM("Assignment: extracting non-name from namespace"); Scope* sc = pscs[(u16)(c.u>>32)]; i32 nameID = sc->body->varIDs[(u32)c.u]; - v_set(pscs, c, ns_getU(x, ns_nameList(sc->body->nsDesc), nameID), upd); + v_set(pscs, c, ns_getU(x, sc->body->nsDesc->nameList, nameID), upd); } return; } diff --git a/src/vm.h b/src/vm.h new file mode 100644 index 00000000..cc515be7 --- /dev/null +++ b/src/vm.h @@ -0,0 +1,48 @@ +#pragma once +#include "h.h" +typedef struct Block Block; +typedef struct Body Body; +typedef struct Scope Scope; + +typedef struct Comp { + struct Value; + B bc; + B src; + B indices; + HArr* objs; + u32 blockAm; + Block* blocks[]; +} Comp; + +struct Block { + struct Value; + bool imm; + u8 ty; + Body* body; +}; + +typedef struct NSDesc NSDesc; +struct Body { + struct Value; + Comp* comp; + // B* objs; + i32* bc; // pointer in comp->bc + u32 maxStack; + u16 maxPSC; + u16 varAm; + u32 endStack; + NSDesc* nsDesc; + i32 varIDs[]; +}; + +struct Scope { + struct Value; + Scope* psc; + Body* body; + u16 varAm; + B vars[]; +}; + +typedef struct FunBlock { struct Fun; Scope* sc; Block* bl; } FunBlock; +typedef struct Md1Block { struct Md1; Scope* sc; Block* bl; } Md1Block; +typedef struct Md2Block { struct Md2; Scope* sc; Block* bl; } Md2Block;