forked from ground/ground
Add a prefix for imported libraries
This commit is contained in:
15
src/main.cpp
15
src/main.cpp
@@ -39,6 +39,7 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
@@ -486,6 +487,9 @@ string procFnName = "";
|
||||
|
||||
bool inFunction = false;
|
||||
|
||||
// Stack of strings for keeping track of which thing we're importing
|
||||
stack<string> importing;
|
||||
|
||||
// Forward declaration for the call instruction and use instruction
|
||||
Literal exec(vector<Instruction> in);
|
||||
|
||||
@@ -1630,6 +1634,10 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
error("Second argument of function must be a function reference");
|
||||
}
|
||||
|
||||
if (importing.size() > 0) {
|
||||
fnName = importing.top() + ":" + fnName;
|
||||
}
|
||||
|
||||
// Parse function arguments (type-direct pairs)
|
||||
if ((l.args.size() - 2) % 2 != 0) {
|
||||
error("Function arguments must be in type-direct pairs");
|
||||
@@ -1821,7 +1829,10 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
while (getline(file, lns)) {
|
||||
in += lns += "\n";
|
||||
}
|
||||
Literal ret = exec(parser(lexer(in)), false); }
|
||||
importing.push(get<string>(get<Literal>(l.args[0]).val));
|
||||
Literal ret = exec(parser(lexer(in)), false);
|
||||
importing.pop();
|
||||
}
|
||||
break;
|
||||
case Instructions::Extern:
|
||||
if (l.args.size() < 1) {
|
||||
@@ -1911,7 +1922,7 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
for (int i = 0; functionNames[i] != nullptr; i++) {
|
||||
void* funcPtr = getFunction(functionNames[i]);
|
||||
if (funcPtr) {
|
||||
externalFunctions[string(functionNames[i])] = funcPtr;
|
||||
externalFunctions[libName + ":" + string(functionNames[i])] = funcPtr;
|
||||
functionCount++;
|
||||
} else {
|
||||
error("Failed to get function pointer for: " + string(functionNames[i]));
|
||||
|
Reference in New Issue
Block a user