Permalink
Browse files

Cleanup

  • Loading branch information...
LadyCailin committed Jan 18, 2019
1 parent b1e5375 commit 7d9d70f1ba8a4405405fce6836afeac8a20cbbcc
@@ -35,6 +35,8 @@
@Override
public final Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
ParseTree tree;
// TODO: Ultimately, this is not scalable. We need to compile and cache these scripts at Java compile time,
// not at runtime the first time a function is used. This is an easier first step though.
if(!CACHED_SCRIPTS.containsKey(this.getClass())) {
try {

@@ -52,22 +54,15 @@ public final Mixed exec(Target t, Environment environment, Mixed... args) throws
} else {
tree = CACHED_SCRIPTS.get(this.getClass());
}
// It's actually possible that the environment is null, which happens during optimization. If the subclass
// declares that it can be optimized at compile time, then this will occur, and we want to allow it, so
// we need to create a throwaway environment for the "proc".
GlobalEnv env = null;
if(environment != null) {
env = environment.getEnv(GlobalEnv.class);
}
IVariableList oldVariables = env == null ? new IVariableList() : env.GetVarList();

GlobalEnv env = environment.getEnv(GlobalEnv.class);
IVariableList oldVariables = env.GetVarList();
IVariableList newVariables = new IVariableList();
newVariables.set(new IVariable(CArray.TYPE, "@arguments", new CArray(t, args.length, args), t));
if(env != null) {
env.SetVarList(newVariables);
}
env.SetVarList(newVariables);
Mixed ret = CVoid.VOID;
try {
if(env != null && env.GetScript() != null) {
if(env.GetScript() != null) {
env.GetScript().eval(tree, environment);
} else {
// This can happen when the environment is not fully setup during tests, in addition to optimization
@@ -76,9 +71,8 @@ public final Mixed exec(Target t, Environment environment, Mixed... args) throws
} catch (FunctionReturnException ex) {
ret = ex.getReturn();
}
if(env != null) {
env.SetVarList(oldVariables);
}
env.SetVarList(oldVariables);

return ret;
}

@@ -2731,37 +2731,6 @@ protected String script() {
return getBundledCode();
}

// @Override
// public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
// double value = Static.getDouble(args[0], t);
// double min = Static.getDouble(args[1], t);
// double max = Static.getDouble(args[2], t);
// double v;
// if(min == max) {
// v = min;
// } else if(min < max) {
// // Normal mode
// if(value < min) {
// v = min;
// } else if(value > max) {
// v = max;
// } else {
// v = value;
// }
// } else if(value < max) { // Reverse mode
// // Actually min
// v = value;
// } else if(value > min) {
// // Actually max
// v = value;
// } else if(value - max <= min - value) { // Special handling, find the closer value
// v = max;
// } else {
// v = min;
// }
// return new CDouble(v, t);
// }

@Override
public String getName() {
return "clamp";
@@ -296,19 +296,20 @@ public void test12() throws Exception {
.setRequiredAndDefault())
.addDescription("This is the \ndescription");
String expected = "\tThis is the \ndescription\n\n"
+ "Usage:\n\t[-xyz] [--flag] [-a <array, ...>] -i <input> -n <#number> --numbers <#numbers, ...> <arguments, ...>\n\n"
+ "Options:\n\n"
+ "Usage:\n\t[-xyz] [--flag] [-a <array, ...>] [-b <array> (default \"defaultValue\")] -i <input> -n <#number> --numbers <#numbers, ...> <arguments, ...>\n\n"
+ "\t<arguments>: This is the default argument\n"
+ "Flags (Short flags may be combined):\n"
+ "\t-x: Flag x\n"
+ "\t-y: Flag y\n"
+ "\t-z: Flag z\n"
+ "\t--flag: Big flag\n"
+ "\n"
+ "\nOptions:\n"
+ "\t-a: Optional. A list. Array\n"
+ "\t-b: Optional. This is an optional value with a default\n"
+ "\t-i: Required. Input\n"
+ "\t-n: Required. A numeric value. This is a single \n\t\tnumber\n"
+ "\t--array: Alias to -a\n"
+ "\t--array2: Alias to -b\n"
+ "\t--numbers: Required. A list of numbers. A list\n";
String actual = p.getBuiltDescription();
// System.out.println("Expected:\n\n" + expected);

0 comments on commit 7d9d70f

Please sign in to comment.