Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finalize implementation of reload loading in ikj

  • Loading branch information...
commit cff067156bc85bcce28cc29ae3ce4602677b44a8 1 parent cf95dbf
@olabini olabini authored
View
5 src/builtin/A01_use.ik
@@ -0,0 +1,5 @@
+
+DefaultBehavior use = method("takes one or more evaluated string argument. will import the files corresponding to each of the strings named based on the Ioke loading behavior that can be found in the documentation for the loadBehavior cell on System.", module nil,
+ unless(module,
+ return(DefaultBehavior cell(:use)),
+ System lowLevelLoad!(module, false)))
View
5 src/builtin/O05_misc.ik
@@ -35,6 +35,9 @@ DefaultBehavior FlowControl sap = dmacro(
self
)
+
+
cell(:use) reload = method("will take the same kind of arguments as use, but will make sure that the code will be reloaded every time called.",
filename,
- use(filename))
+ System lowLevelLoad!(filename, true)
+)
View
28 src/ikj/main/ioke/lang/DefaultBehavior.java
@@ -99,33 +99,5 @@ public static void init(IokeObject obj) throws ControlFlow {
aspects.setKind("DefaultBehavior Aspects");
obj.mimicsWithoutCheck(aspects);
obj.registerCell("Aspects", aspects);
-
- obj.registerMethod(runtime.newNativeMethod("takes one or more evaluated string argument. will import the files corresponding to each of the strings named based on the Ioke loading behavior that can be found in the documentation for the loadBehavior cell on System.", new NativeMethod("use") {
- private final DefaultArgumentsDefinition ARGUMENTS = DefaultArgumentsDefinition
- .builder()
- .withOptionalPositional("module", "false")
- .getArguments();
-
- @Override
- public DefaultArgumentsDefinition getArguments() {
- return ARGUMENTS;
- }
-
- @Override
- public Object activate(IokeObject method, IokeObject context, IokeObject message, Object on) throws ControlFlow {
- List<Object> args = new ArrayList<Object>();
- getArguments().getEvaluatedArguments(context, message, on, args, new HashMap<String, Object>());
- if(args.size() == 0) {
- return method;
- }
-
- String name = Text.getText(((Message)IokeObject.data(runtime.asText)).sendTo(runtime.asText, context, args.get(0)));
- if(((IokeSystem)IokeObject.data(runtime.system)).use(IokeObject.as(on, context), context, message, name)) {
- return runtime._true;
- } else {
- return runtime._false;
- }
- }
- }));
}
}// DefaultBehavior
View
62 src/ikj/main/ioke/lang/IokeSystem.java
@@ -104,16 +104,18 @@ public static boolean isAbsoluteFileName(String name) {
}
}
- public boolean use(IokeObject self, IokeObject context, IokeObject message, String name) throws ControlFlow {
+ public boolean use(IokeObject self, IokeObject context, IokeObject message, String name, boolean forceReload) throws ControlFlow {
final Runtime runtime = context.runtime;
Builtin b = context.runtime.getBuiltin(name);
if(b != null) {
- if(loaded.contains(name)) {
+ if(!forceReload && loaded.contains(name)) {
return false;
} else {
try {
b.load(context.runtime, context, message);
- loaded.add(name);
+ if(!forceReload) {
+ loaded.add(name);
+ }
return true;
} catch(Throwable e) {
final IokeObject condition = IokeObject.as(IokeObject.getCellChain(runtime.condition,
@@ -184,7 +186,7 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
File f = new File(name + suffix);
if(f.exists() && f.isFile()) {
- if(loaded.contains(f.getCanonicalPath())) {
+ if(!forceReload && loaded.contains(f.getCanonicalPath())) {
return false;
} else {
if(f.getCanonicalPath().endsWith(".jar")) {
@@ -193,13 +195,15 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
context.runtime.evaluateFile(f, message, context);
}
- loaded.add(f.getCanonicalPath());
+ if(!forceReload) {
+ loaded.add(f.getCanonicalPath());
+ }
return true;
}
}
if(null != is) {
- if(loaded.contains(name+suffix)) {
+ if(!forceReload && loaded.contains(name+suffix)) {
return false;
} else {
if((name+suffix).endsWith(".jar")) {
@@ -207,7 +211,9 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
} else {
context.runtime.evaluateStream(name+suffix, new InputStreamReader(is, "UTF-8"), message, context);
}
- loaded.add(name+suffix);
+ if(!forceReload) {
+ loaded.add(name+suffix);
+ }
return true;
}
}
@@ -288,7 +294,7 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
// System.err.println("trying: " + f);
if(f.exists() && f.isFile()) {
- if(loaded.contains(f.getCanonicalPath())) {
+ if(!forceReload && loaded.contains(f.getCanonicalPath())) {
return false;
} else {
if(f.getCanonicalPath().endsWith(".jar")) {
@@ -297,13 +303,16 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
context.runtime.evaluateFile(f, message, context);
}
- loaded.add(f.getCanonicalPath());
+ if(!forceReload) {
+ loaded.add(f.getCanonicalPath());
+ }
+
return true;
}
}
if(null != is) {
- if(loaded.contains(name+suffix)) {
+ if(!forceReload && loaded.contains(name+suffix)) {
return false;
} else {
if((name+suffix).endsWith(".jar")) {
@@ -311,7 +320,11 @@ public IokeObject invoke(IokeObject context, List<Object> arguments) throws Cont
} else {
context.runtime.evaluateStream(name+suffix, new InputStreamReader(is, "UTF-8"), message, context);
}
- loaded.add(name+suffix);
+
+ if(!forceReload) {
+ loaded.add(name+suffix);
+ }
+
return true;
}
}
@@ -582,6 +595,33 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
return context.runtime.nil;
}
}));
+
+ obj.registerMethod(runtime.newNativeMethod("takes one evaluated string argument and a boolean of whether loading should be forced or not. will import the file corresponding to the string based on the Ioke loading behavior", new NativeMethod("lowLevelLoad!") {
+ private final DefaultArgumentsDefinition ARGUMENTS = DefaultArgumentsDefinition
+ .builder()
+ .withRequiredPositional("module")
+ .withRequiredPositional("forceReload")
+ .getArguments();
+
+ @Override
+ public DefaultArgumentsDefinition getArguments() {
+ return ARGUMENTS;
+ }
+
+ @Override
+ public Object activate(IokeObject method, IokeObject context, IokeObject message, Object on) throws ControlFlow {
+ List<Object> args = new ArrayList<Object>();
+ getArguments().getEvaluatedArguments(context, message, on, args, new HashMap<String, Object>());
+ boolean forceReload = IokeObject.isTrue(args.get(1));
+
+ String name = Text.getText(((Message)IokeObject.data(runtime.asText)).sendTo(runtime.asText, context, args.get(0)));
+ if(((IokeSystem)IokeObject.data(runtime.system)).use(IokeObject.as(on, context), context, message, name, forceReload)) {
+ return runtime._true;
+ } else {
+ return runtime._false;
+ }
+ }
+ }));
}
public String toString() {
View
1  src/ikj/main/ioke/lang/Runtime.java
@@ -338,6 +338,7 @@ public IokeObject load(Runtime runtime, IokeObject context, IokeObject message)
});
try {
+ evaluateString("System lowLevelLoad!(\"builtin/A01_use\", false)", message, ground);
evaluateString("use(\"builtin/A05_conditions\")", message, ground);
evaluateString("use(\"builtin/A10_defaultBehavior\")", message, ground);
evaluateString("use(\"builtin/A15_dmacro\")", message, ground);
View
27 test/default_behavior_use_spec.ik
@@ -39,7 +39,7 @@ describe(DefaultBehavior,
)
it("should just return a use object if called without arguments",
- cell(:use) should == use()
+ cell(:use) should be same(use())
)
describe("reload",
@@ -71,9 +71,28 @@ describe(DefaultBehavior,
fn(use reload("blarg")) should signal(Condition Error Load)
)
- it("should be possible to load something that has been loaded by use")
- it("should be possible to load something that has been loaded by reload before")
- it("should be possible to load something that hasn't been loaded before")
+ it("should be possible to load something that has been loaded by use",
+ use("test/reload_x")
+ Ground reload_count_x should == 0
+ use reload("test/reload_x")
+ Ground reload_count_x should == 1
+ )
+
+ it("should be possible to load something that has been loaded by reload before",
+ use("test/reload_y")
+ Ground reload_count_y should == 0
+ use reload("test/reload_y")
+ Ground reload_count_x should == 1
+ use reload("test/reload_y")
+ Ground reload_count_y should == 2
+ )
+
+ it("should be possible to load something that hasn't been loaded before",
+ use reload("test/reload_z")
+ Ground reload_count_z should == 0
+ use reload("test/reload_z")
+ Ground reload_count_z should == 1
+ )
)
)
)
View
4 test/reload_x.ik
@@ -0,0 +1,4 @@
+
+if(cell?(:reload_count_x),
+ Ground reload_count_x++,
+ Ground reload_count_x = 0)
View
4 test/reload_y.ik
@@ -0,0 +1,4 @@
+
+if(cell?(:reload_count_y),
+ Ground reload_count_y++,
+ Ground reload_count_y = 0)
View
4 test/reload_z.ik
@@ -0,0 +1,4 @@
+
+if(cell?(:reload_count_z),
+ Ground reload_count_z++,
+ Ground reload_count_z = 0)
Please sign in to comment.
Something went wrong with that request. Please try again.