Permalink
Browse files

faster symbol lookup

  • Loading branch information...
1 parent 49941a9 commit 1cf58bc66aca3eb6475f5abbb8bec2edfd14ecf2 conan committed Jan 5, 2009
View
@@ -26,7 +26,9 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntryProperties />
+ </component>
+ <component name="RSpecModuleSettingsStorage">
+ <RSPEC_MODULE_SETTINGS_STORAGE_ID NAME="RSPEC_SUPPORT_TYPE" VALUE="NONE" />
</component>
</module>
View
@@ -116,6 +116,7 @@
<option name="ADDITIONAL_OPTIONS_STRING" value="" />
<option name="MAXIMUM_HEAP_SIZE" value="128" />
</component>
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
@@ -310,13 +311,16 @@
<option name="USE_CLIENT_FILTER" value="true" />
<option name="CLIENT" value="" />
</component>
+ <component name="ProjectDetails">
+ <option name="projectName" value="rainbow" />
+ </component>
<component name="ProjectFileVersion" converted="true" />
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/rainbow.iml" filepath="$PROJECT_DIR$/rainbow.iml" />
</modules>
</component>
- <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="Ruby SDK 1.8.6" project-jdk-type="RUBY_SDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="Ruby SDK 1.8.6" project-jdk-type="RUBY_SDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="RUBY_DOC_SETTINGS">
@@ -382,7 +386,7 @@
<option name="SHOW_FILE_HISTORY_AS_TREE" value="true" />
</component>
<component name="VcsDirectoryMappings">
- <mapping directory="" vcs="" />
+ <mapping directory="" vcs="Git" />
</component>
<component name="WebServicesPlugin" addRequiredLibraries="true" />
<component name="com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable" proportions="" version="1">
View
@@ -0,0 +1,30 @@
+
+(def bm (times fun)
+ (with (mintime 2000000000 maxtime 0 totaltime 0 now nil)
+ (for i 0 (- times 1)
+ (= now (msec))
+ (fun)
+ (let elapsed (- (msec) now)
+ (prn i " . " elapsed)
+ (zap [min _ elapsed] mintime)
+ (zap [max _ elapsed] maxtime)
+ (zap [+ _ elapsed] totaltime)))
+ (prn)
+ (prn "avg " (/ totaltime times 1.0))
+ (prn "min " mintime)
+ (prn "max " maxtime)
+ (/ totaltime times 1.0)))
+
+(set a (load-file "src/arc/rainbow/welder.arc"))
+(bm 10 [index-source a])
+(bm 10 [prime-bench 20000])
+
+; prime-bench:
+; avg 3616.5
+; min 3559
+; max 3725
+
+; index-source
+; avg 4807.9
+; min 4726
+; max 4952
@@ -12,5 +12,3 @@
(def prime-bench (n) (time (primes-under n)))
-
-
@@ -18,4 +18,7 @@
"rainbow/tests/java-interface-test"))
(prn "self-test:")
-(run-all-tests)
+(run-all-tests)
+
+(let func (random-elt:keys help*)
+ (prn "Documentation for " func " " (helpstr func)))
@@ -457,7 +457,7 @@
(on-doc-update tf!getDocument (c)
(search tf!getText))
(sf 'hide)
- (obj sf sf show show hide hide next next prev prev)))
+ (nobj sf show hide next prev)))
(set welder-initialisers nil)
@@ -3,8 +3,10 @@
import rainbow.functions.*;
import rainbow.types.*;
-import java.util.*;
-import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
public class Environment {
private java.util.Set defaults;
@@ -20,7 +22,7 @@ public Environment() { // todo: macex1, pipe-from, complex numbers, threading
Threads.collect(this);
addBuiltin("t", ArcObject.T);
- addBuiltin("nil", ArcObject.NIL);
+// addBuiltin("nil", ArcObject.NIL);
addBuiltin("uniq", new Uniq());
addBuiltin("newstring", new Lists.NewString());
addBuiltin("macex", new Macex());
@@ -30,7 +32,7 @@ public Environment() { // todo: macex1, pipe-from, complex numbers, threading
addBuiltin("err", new Errors.Err());
addBuiltin("on-err", new Errors.OnErr());
addBuiltin("details", new Errors.Details());
-
+
/* lists */
addBuiltin("car", new Lists.Car());
addBuiltin("cdr", new Lists.Cdr());
@@ -85,15 +87,24 @@ public Environment() { // todo: macex1, pipe-from, complex numbers, threading
}
private void addBuiltin(String name, ArcObject o) {
- namespace.put(Symbol.make(name), o);
+// bindingFor((Symbol) Symbol.make(name)).set(o);
+// namespace.put(Symbol.make(name), o);
+ ((Symbol) Symbol.make(name)).setValue(o);
}
public void addToNamespace(Symbol s, ArcObject o) {
- namespace.put(s, o);
+// bindingFor(s).set(o);
+// namespace.put(s, o);
+ s.setValue(o);
}
public ArcObject lookup(Symbol s) {
- return (ArcObject) namespace.get(s);
+// return bindingFor(s).lookup();
+// return (ArcObject) namespace.get(s);
+ if (!s.bound()) {
+ return null;
+ }
+ return s.value();
}
public Output stdOut() {
@@ -121,7 +132,7 @@ protected static String toString(Map objectMap) {
return sb.toString();
}
-
+
protected synchronized void collectKeys(java.util.Set s) {
java.util.Set top = new HashSet(namespace.keySet());
top.removeAll(defaults);
@@ -1,18 +1,19 @@
package rainbow.types;
-import rainbow.types.ArcObject;
-import rainbow.*;
+import rainbow.ArcError;
+import rainbow.Environment;
+import rainbow.Truth;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
public class Symbol extends ArcObject {
private static final Map<String, Symbol> map = new HashMap();
public static final Symbol TYPE = (Symbol) Symbol.make("sym");
public static final Symbol EMPTY_STRING = (Symbol) Symbol.make("||");
- private static int count = 0;
private String name;
private int hash;
+ private ArcObject value;
protected Symbol(String name) {
this.name = name;
@@ -72,17 +73,33 @@ public boolean equals(Object object) {
}
public ArcObject eval(Environment env) {
- ArcObject result = env.lookup(this);
- if (result == null) {
- throw new Unbound(this);
- }
- return result;
+ return value();
+// ArcObject result = env.lookup(this);
+// if (result == null) {
+// throw new Unbound(this);
+// }
+// return result;
}
public static boolean is(String s, ArcObject o) {
return (o instanceof Symbol) && ((Symbol)o).name().equals(s);
}
+ public void setValue(ArcObject value) {
+ this.value = value;
+ }
+
+ public ArcObject value() {
+ if (value == null) {
+ throw new Unbound(this);
+ }
+ return value;
+ }
+
+ public boolean bound() {
+ return value != null;
+ }
+
private class Unbound extends ArcError {
public Unbound(Symbol name) {
super("Symbol " + name + " is not bound");
@@ -1,17 +1,16 @@
package rainbow.vm.compiler;
-import rainbow.vm.ArcThread;
-import rainbow.vm.Continuation;
-import rainbow.vm.BoundSymbol;
-import rainbow.vm.continuations.*;
-import rainbow.vm.compiler.QuasiQuoteCompiler;
import rainbow.Function;
import rainbow.LexicalClosure;
import rainbow.functions.Evaluation;
-import rainbow.types.Pair;
import rainbow.types.ArcObject;
+import rainbow.types.Pair;
import rainbow.types.Symbol;
import rainbow.types.Tagged;
+import rainbow.vm.ArcThread;
+import rainbow.vm.BoundSymbol;
+import rainbow.vm.Continuation;
+import rainbow.vm.continuations.ContinuationSupport;
import java.util.Map;
@@ -40,6 +39,7 @@ public static void compile(ArcThread thread, LexicalClosure lc, Continuation cal
}
}
caller.receive(expression);
+// caller.receive(thread.environment().bindingFor((Symbol) expression));
} else {
caller.receive(expression);
}
@@ -52,6 +52,7 @@ public void start() {
} else {
ArcObject fun = expression.car();
if (Symbol.is("quote", fun)) {
+// caller.receive(Pair.buildFrom(thread.environment().bindingFor((Symbol) fun), expression.cdr()));
caller.receive(expression);
} else if (fun == QuasiQuoteCompiler.QUASIQUOTE) {
Rebuilder rebuilder = new Rebuilder(caller, QuasiQuoteCompiler.QUASIQUOTE);
@@ -1,18 +1,14 @@
package rainbow.vm.continuations;
import rainbow.*;
-import rainbow.functions.Builtin;
-import rainbow.functions.InterpretedFunction;
import rainbow.types.*;
import rainbow.vm.ArcThread;
import rainbow.vm.Continuation;
import rainbow.vm.Interpreter;
-import javax.swing.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
-import java.awt.*;
public class FunctionDispatcher extends ContinuationSupport {
public static final boolean ALLOW_MACRO_EXPANSION = false;
@@ -31,17 +27,6 @@ public FunctionDispatcher(ArcThread thread, LexicalClosure lc, Continuation call
super(thread, lc, caller);
this.args = expression.cdr();
this.functionName = expression.car();
-// if (caller instanceof FunctionDispatcher) {
-// System.out.println("FD trail: " + fdtrail());
-// }
- }
-
- private String fdtrail() {
- if (caller instanceof FunctionDispatcher) {
- return functionName + " " + ((FunctionDispatcher) caller).fdtrail();
- } else {
- return "";
- }
}
public void process() {
@@ -1,7 +1,6 @@
package rainbow.vm.continuations;
import rainbow.LexicalClosure;
-import rainbow.functions.Builtin;
import rainbow.types.ArcObject;
import rainbow.types.Symbol;
import rainbow.vm.ArcThread;

0 comments on commit 1cf58bc

Please sign in to comment.