Refactor Module into a single record type and fix system globals (#1383)
This commit is contained in:
1 parent
d681cb4c54
commit
a60bc386cb
20 files changed
+279
-215
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package carpet.script;
|
||||
|
||||
import carpet.script.bundled.Module;
|
||||
import carpet.script.exception.ExpressionException;
|
||||
import carpet.script.exception.IntegrityException;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
@@ -28,12 +27,12 @@ import java.util.stream.Stream;
|
||||
|
||||
public abstract class ScriptHost
|
||||
{
|
||||
public static Map<Value, Value> systemGlobals = new ConcurrentHashMap<>();
|
||||
private static final Map<Long, Random> randomizers = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
public static Thread mainThread = null;
|
||||
private final Map<Value, ThreadPoolExecutor> executorServices = new HashMap<>();
|
||||
private final Map<Value, Object> locks = new ConcurrentHashMap<>();
|
||||
private final ScriptServer scriptServer;
|
||||
protected boolean inTermination = false;
|
||||
public boolean strict;
|
||||
|
||||
@@ -101,7 +100,7 @@ public abstract class ScriptHost
|
||||
protected boolean perUser;
|
||||
public String user;
|
||||
|
||||
public String getName() {return main ==null?null: main.getName();}
|
||||
public String getName() {return main ==null?null: main.name();}
|
||||
|
||||
public final Module main;
|
||||
|
||||
@@ -112,17 +111,18 @@ public abstract class ScriptHost
|
||||
}
|
||||
public ErrorSnooper errorSnooper = null;
|
||||
|
||||
protected ScriptHost(Module code, boolean perUser, ScriptHost parent)
|
||||
protected ScriptHost(Module code, ScriptServer scriptServer, boolean perUser, ScriptHost parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.main = code;
|
||||
this.perUser = perUser;
|
||||
this.user = null;
|
||||
this.strict = false;
|
||||
this.scriptServer = scriptServer;
|
||||
ModuleData moduleData = new ModuleData(code);
|
||||
initializeModuleGlobals(moduleData);
|
||||
this.moduleData.put(code, moduleData);
|
||||
this.modules.put(code==null?null:code.getName(), code);
|
||||
this.modules.put(code==null?null:code.name(), code);
|
||||
mainThread = Thread.currentThread();
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ public abstract class ScriptHost
|
||||
{
|
||||
if (modules.containsKey(moduleName.toLowerCase(Locale.ROOT))) return; // aready imported
|
||||
Module module = getModuleOrLibraryByName(moduleName);
|
||||
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
||||
modules.put(module.getName(), module);
|
||||
if (modules.containsKey(module.name())) return; // aready imported, once again, in case some discrepancies in names?
|
||||
modules.put(module.name(), module);
|
||||
ModuleData data = new ModuleData(module);
|
||||
initializeModuleGlobals(data);
|
||||
moduleData.put(module, data);
|
||||
@@ -201,7 +201,7 @@ public abstract class ScriptHost
|
||||
if (module == main)
|
||||
throw new InternalExpressionException("Function '"+name+"' is not defined yet");
|
||||
else
|
||||
throw new InternalExpressionException("Function '"+name+"' is not defined nor visible by its name in the imported module '"+module.getName()+"'");
|
||||
throw new InternalExpressionException("Function '"+name+"' is not defined nor visible by its name in the imported module '"+module.name()+"'");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -448,4 +448,9 @@ public abstract class ScriptHost
|
||||
DEPRECATION_LOG.warn("'"+feature+"' is deprecated and soon will be removed. Please consult the docs for their replacement");
|
||||
return true;
|
||||
}
|
||||
|
||||
public ScriptServer scriptServer()
|
||||
{
|
||||
return scriptServer;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user