Changeset 807
- Timestamp:
- Jul 9, 2012 4:03:20 AM (12 years ago)
- Location:
- trunk/magnolia-eclipse
- Files:
-
- 6 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/magnolia-eclipse/.classpath
r640 r807 5 5 <classpathentry kind="lib" path="lib/annotations.jar"/> 6 6 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> 7 <classpathentry kind="lib" path="lib/jline-0.9.94.jar"/> 7 8 <classpathentry kind="output" path="bin"/> 8 9 </classpath> -
trunk/magnolia-eclipse/.gitignore
r789 r807 9 9 magnolia-tests/ 10 10 .lein-deps-sum 11 clj-bin/ 11 12 clj-lib/ 12 13 .lein-plugins/ -
trunk/magnolia-eclipse/project.clj
r806 r807 11 11 the command 'lein repl'. To launch a REPL under Emacs you may simply 12 12 use M-x clojure-jack-in, provided you have a bleeding edge setup of 13 Emacs with SLIME.13 Emacs with clojure-mode. 14 14 15 15 It is assumed that the Magnolia code base Java code is built … … 40 40 than the one installed as an Eclipse plugin - e.g. 41 41 'bin:lib/*:'$MAGNOLIA_ECLIPSE_HOME'/workspace/rascal/src:ext-lib/*' 42 - any '_DEFAULT_' component is replaced by the default 43 MAGNOLIA_JAVA_CLASSPATH - e.g. 44 $MAGNOLIA_ECLIPSE_HOME/workspace/rascal/src:_DEFAULT_ 42 45 43 46 MAGNOLIA_MODULE_PATH - in PATH env var style manner specifies (for 44 47 the Magnolia compiler) where to look for '.mg' files - e.g. 45 48 magnolia-tests/src 49 50 MAGNOLIA_RASCAL_MODULE_PATH - optional search path for additional 51 '.rsc' files, which allows for making use of Magnolia compiler 52 functionality in other Rascal projects - e.g. 53 /tmp/rascal-tests/src:/tmp/rascal-tools/src 46 54 47 55 After you have set the above env vars, execute 'make update-ext-lib' … … 59 67 60 68 (defn get-extra-classpath-dirs [] 61 (let [ev (System/getenv "MAGNOLIA_JAVA_CLASSPATH")] 62 (if (not ev) 63 [(dir-path "bin") 64 (jar-path "lib") 65 (jar-path "ext-lib")] 66 (map dir-path (seq (.split #":" ev)))))) 69 (let [ev (System/getenv "MAGNOLIA_JAVA_CLASSPATH") 70 de [(dir-path "bin") 71 (jar-path "lib") 72 (jar-path "ext-lib")]] 73 (if-not ev 74 de 75 (let [x (seq (.split #":" ev)) 76 y (mapcat #(if (= % "_DEFAULT_") de [(dir-path %)]) x)] 77 y)))) 67 78 68 79 (defproject org.magnolialang "0.2-SNAPSHOT" … … 71 82 :compile-path "clj-bin" 72 83 :library-path "clj-lib" 73 :repl-init org.magnolialang.core 84 :repl-init org.magnolialang.clojure.core 85 :aot [org.magnolialang.clojure.core 86 org.magnolialang.clojure.rascal-shell] 74 87 ;; Time-consuming, but shows what classes loaded from where. 75 88 ;;:jvm-opts ["-verbose:class"] -
trunk/magnolia-eclipse/src/org/magnolialang/clojure/core.clj
r806 r807 1 (ns org.magnolialang.core 1 ;; E.g. (use 'org.magnolialang.clojure.core :reload-all) 2 (ns org.magnolialang.clojure.core 2 3 (:import 3 4 (org.magnolialang.testutil RascalEval TestUtil) … … 12 13 (def Type_ModuleResource 13 14 org.magnolialang.resources.IResourceManager/Type_ModuleResource) 14 15 (def Type_DefInfo MagnoliaFacts/Type_DefInfo)16 15 17 16 ;; (.getId (magnolia-language)) => "Magnolia" … … 24 23 (org.magnolialang.infra.ConsoleInfra/setInfra)) 25 24 25 (defn get-infra [] 26 (org.magnolialang.infra.ConsoleInfra/getInfra)) 27 28 (defn get-ri [] 29 (RascalEval.)) 30 31 (defn path-env-var-to-list [n] 32 (java.util.ArrayList. 33 (map 34 #(-> % (java.io.File.) (.getAbsolutePath)) 35 (let [ev (System/getenv n)] 36 (if ev (seq (.split #":" ev)) []))))) 37 38 (def MAGNOLIA_RASCAL_MODULE_PATH 39 (path-env-var-to-list "MAGNOLIA_RASCAL_MODULE_PATH")) 40 26 41 (def compiler-op 27 42 (doto (new java.util.HashMap) 28 43 (.put "MAGNOLIA_MODULE_PATH" 29 (java.util.ArrayList. 30 (map 31 #(-> % (java.io.File.) (.getAbsolutePath)) 32 (let [ev (System/getenv "MAGNOLIA_MODULE_PATH")] 33 (if ev (seq (.split #":" ev)) []))))) 34 (.put "a" "A") 35 (.put "b" "B"))) 36 37 (defn init-compiler [] 38 (TestUtil/setInstance compiler-op) 39 (let [state (TestUtil/getInstance) 40 lang (magnolia-language)] 41 (.addFile state 42 "org.magnolialang.magnolia.templates.MagicMain" 43 (java.io.File. "src/org/magnolialang/magnolia/templates/MagicMain.cxx")) 44 (org.magnolialang.resources.LanguageRegistry/registerLanguage lang) 45 (let [parser (.getParser lang)] 46 (.initialize parser)))) 47 48 (defn get-infra [] 49 (org.magnolialang.infra.Infra/get)) 50 51 (defn get-parser [s] 52 (.getParser (get-infra) s)) 53 54 (defn get-magnolia-parser [] 55 (get-parser (.getModuleName (.getParser (magnolia-language))))) 56 57 (defn new-file-fact [l s] 58 (org.magnolialang.testutil.UnmanagedFileFact. l s)) 59 60 (defn new-mg-file-fact [s] 61 (new-file-fact (magnolia-language) (java.io.File. s))) 62 63 ;; for testing only, fixed module 64 (defn add-mg-module-fact [] 65 (let [state (TestUtil/getInstance) 66 lang (magnolia-language)] 67 (.addModuleResource state lang "basic.Basic" (java.io.File. "magnolia-tests/src/basic/Basic.mg")))) 68 69 ;; (find-mg-module-fact "basic.Basic") 70 (defn find-mg-module-fact [s] 71 (.findModuleFact (TestUtil/getInstance) (magnolia-language) s)) 72 73 (defn get-mg-module-fact [s] 74 (.getModuleFact (TestUtil/getInstance) (magnolia-language) s)) 75 76 (defn get-name-ast [s] 77 (.getNameAST (magnolia-language) s)) 78 79 (defn get-parse-tree [s] 80 (let [state (TestUtil/getInstance) 81 lang (magnolia-language) 82 modNameAst (.getNameAST lang s)] 83 (.getParseTree state modNameAst))) 84 85 (defn get-imploded-tree [s] 86 (let [state (TestUtil/getInstance) 87 lang (magnolia-language) 88 modNameAst (.getNameAST lang s)] 89 (.getImplodedTree state modNameAst))) 90 91 (defn rstring [s] 92 (.string org.magnolialang.terms.TermFactory/vf s)) 93 94 (defn get-option-string-fact [s] 95 (let [state (TestUtil/getInstance)] 96 (.getOptionStringFact state (rstring s)))) 44 (path-env-var-to-list "MAGNOLIA_MODULE_PATH")) 45 )) 46 47 (org.magnolialang.infra.ConsoleInfra/setRascalSearchPath 48 MAGNOLIA_RASCAL_MODULE_PATH) 49 (set-infra) 50 51 (def infra (get-infra)) 52 (def rascal-monitor (.getMonitor infra)) 53 54 (TestUtil/setOptions compiler-op) 55 (def tu-state) 56 (def mg-lang) 57 58 ;; The Rascal evaluator instance to use. By replacing this with a 59 ;; fresh copy you can "reload" Rascal modules. Clojure modules can 60 ;; also be reloaded, naturally. However, unless you're running in an 61 ;; controlled environment (such as Eclipse) with custom class loaders, 62 ;; reloading Java classes is not possible, as Java itself does not 63 ;; allow it. 64 (def rsc-evaluator (get-ri)) 97 65 98 66 (defn get-ric [] 99 (let [state (TestUtil/getInstance)67 (let [state tu-state 100 68 compiler (.getCompiler state) 101 69 evaluator (.getEvaluator compiler) … … 103 71 ri)) 104 72 73 ;; Use this to replace the compiler Rascal evaluator with a fresh 74 ;; instance. Note that 'init-compiler' does not do this. 75 (defn refresh-evaluator [] 76 (org.magnolialang.testutil.MagnoliaCompiler/refreshEvaluator) 77 (def rsc-evaluator (get-ric))) 78 79 ;; You can do things like "pure" Rascal use without this, but 80 ;; this (time-consuming) initialization is required (once) to use 81 ;; the Magnolia toolchain proper. 82 (defn init-compiler [] 83 (def tu-state (new TestUtil)) 84 (def mg-lang (magnolia-language)) 85 (.addFile tu-state 86 "org.magnolialang.magnolia.templates.MagicMain" 87 (java.io.File. 88 "src/org/magnolialang/magnolia/templates/MagicMain.cxx")) 89 (org.magnolialang.resources.LanguageRegistry/registerLanguage mg-lang) 90 (let [parser (.getParser mg-lang)] 91 (.initialize parser)) 92 (def rsc-evaluator (get-ric))) 93 94 (defn get-parser [s] 95 (.getParser (get-infra) s)) 96 97 (defn get-magnolia-parser [] 98 (get-parser (.getModuleName (.getParser mg-lang)))) 99 100 (defn new-file-fact [l s] 101 (org.magnolialang.testutil.UnmanagedFileFact. l s)) 102 103 (defn new-mg-file-fact [s] 104 (new-file-fact mg-lang (java.io.File. s))) 105 106 ;; for testing only, fixed module 107 (defn add-mg-module-fact [] 108 (let [state tu-state 109 lang mg-lang] 110 (.addModuleResource state lang "basic.Basic" (java.io.File. "magnolia-tests/src/basic/Basic.mg")))) 111 112 ;; (find-mg-module-fact "basic.Basic") 113 (defn find-mg-module-fact [s] 114 (.findModuleFact tu-state mg-lang s)) 115 116 (defn get-mg-module-fact [s] 117 (.getModuleFact tu-state mg-lang s)) 118 119 (defn get-name-ast [s] 120 (.getNameAST mg-lang s)) 121 122 (defn get-parse-tree [s] 123 (let [state tu-state 124 lang mg-lang 125 modNameAst (.getNameAST lang s)] 126 (.getParseTree state modNameAst))) 127 128 (defn get-imploded-tree [s] 129 (let [state tu-state 130 lang mg-lang 131 modNameAst (.getNameAST lang s)] 132 (.getImplodedTree state modNameAst))) 133 134 (defn rstring [s] 135 (.string org.magnolialang.terms.TermFactory/vf s)) 136 137 (defn get-option-string-fact [s] 138 (let [state tu-state] 139 (.getOptionStringFact state (rstring s)))) 140 105 141 (defn rtostring [r] 106 142 (RascalEval/resultToString r)) 107 143 108 ;; Evaluate in compilerEvaluator.144 ;; Evaluate Rascal expression in an Evaluator. 109 145 ;; E.g. (reval "registerCompiler") 110 146 (defn reval [s] 111 (.eval (get-ric)s))147 (.eval rsc-evaluator s)) 112 148 113 149 (defn reval-str [s] … … 116 152 ;; E.g. (reval-more "import util::tasks::Manager; getFact; 5;") 117 153 (defn reval-more [s] 118 (.evalMore (get-ric)s))154 (.evalMore rsc-evaluator s)) 119 155 120 156 ;; E.g. (rimport "util::tasks::Manager") 121 157 (defn rimport [s] 122 (.doImport (get-ric)s))158 (.doImport rsc-evaluator s)) 123 159 124 160 (defn rcall 125 161 ;; Clojure does not (yet) appear to support optional positional 126 162 ;; arguments with default values, so we do it like this 127 ([s as] (.call (get-ric)s as))163 ([s as] (.call rsc-evaluator s as)) 128 164 ([s] (rcall s []))) 129 165 … … 131 167 (rcall s as)) 132 168 169 ;; For reloading Rascal modules individually. 170 ;; E.g. (rreload "org::magnolialang::pgf::Token") 171 (defn rreload [& s] 172 (let [evaluator (.getEvaluator rsc-evaluator) 173 errorLoc (java.net.URI/create "clojure:///") 174 mods (java.util.HashSet. s)] 175 (.reloadModules evaluator rascal-monitor mods errorLoc))) 176 133 177 (defn get-fact [type name] 134 (.getFact (TestUtil/getInstance)178 (.getFact tu-state 135 179 type name)) 136 180 137 181 (defn get-def-info [s] 138 (get-fact Type_DefInfo182 (get-fact MagnoliaFacts/Type_DefInfo 139 183 (get-name-ast s))) 140 184 … … 158 202 159 203 (defn ctor-get-field [v s] 160 (.ctorGetField (TestUtil/getInstance)v s))204 (.ctorGetField tu-state v s)) 161 205 162 206 (defn ctor-get-val [v] … … 169 213 ;; E.g. (println (get-cxx-code "basic.Basic")) 170 214 (defn get-cxx-code [s] 171 (.getCxxCode (TestUtil/getInstance) (magnolia-language) s)) 172 215 (.getCxxCode tu-state mg-lang s)) 216 217 ;; E.g. (view-flattened-module "basic.Basic") 173 218 (defn view-flattened-module [s] 174 219 (println (.getValue … … 176 221 (ctor-get-val (get-type-checked s)))))) 177 222 178 (defn get-ri []179 (RascalEval.))180 181 (defn peval [s]182 (.eval (get-ri) s))183 184 (defn peval-str [s]185 (RascalEval/resultToString (peval s)))186 187 (defn pcall [s as]188 (.call (get-ri) s as)) -
trunk/magnolia-eclipse/src/org/magnolialang/infra/ConsoleInfra.java
r804 r807 8 8 import java.net.URI; 9 9 import java.util.Arrays; 10 import java.util.Collections; 10 11 import java.util.HashMap; 11 12 import java.util.List; … … 22 23 import org.magnolialang.terms.TermFactory; 23 24 import org.magnolialang.testutil.MagnoliaCompiler; 24 import org.rascalmpl.interpreter.Configuration;25 25 import org.rascalmpl.interpreter.Evaluator; 26 26 import org.rascalmpl.interpreter.IRascalMonitor; … … 40 40 */ 41 41 public final class ConsoleInfra implements IInfra { 42 43 public static List<String> getRascalSearchPath() { 44 return rascalSearchPath; 45 } 46 47 48 /** 49 * @param rascalSearchPath 50 * list of absolute paths from which to look for Rascal modules 51 */ 52 public static void setRascalSearchPath(List<String> rascalSearchPath) { 53 ConsoleInfra.rascalSearchPath = rascalSearchPath; 54 } 55 56 private static List<String> rascalSearchPath = Collections.emptyList(); 57 42 58 43 59 /** … … 76 92 //ClassResourceInputOutput eclipseResolver = new ClassResourceInputOutput(registry, "eclipse-std", RascalScriptInterpreter.class, "/org/rascalmpl/eclipse/library"); 77 93 //registry.registerInput(eclipseResolver); 78 Evaluator eval = new Evaluator(TermFactory.vf, out, err, root, heap, loaders, resolver); // URIResolverRegistry94 Evaluator eval = new Evaluator(TermFactory.vf, err, out, root, heap, loaders, resolver); // URIResolverRegistry 79 95 // specifies one possible mapping to a rascal:// URI 80 96 eval.addRascalSearchPath((new File(".", "src")).toURI()); 97 for(String s : rascalSearchPath) 98 eval.addRascalSearchPath((new File(s)).toURI()); 81 99 82 System.out.println("Rascal Classpath: " + Configuration.getRascalJavaClassPathProperty());83 System.out.println("Magnolia Classpath: " + System.getProperty("magnolia.java.classpath"));100 //System.out.println("Rascal Classpath: " + Configuration.getRascalJavaClassPathProperty()); 101 //System.out.println("Magnolia Classpath: " + System.getProperty("magnolia.java.classpath")); 84 102 //Configuration.setRascalJavaClassPathProperty(System.getProperty("magnolia.java.classpath")); 85 103 … … 110 128 if(parser != null) 111 129 return parser; 112 System.out.println("generating parser for " + moduleName);130 //System.out.println("generating parser for " + moduleName); 113 131 /* 114 132 String moduleBaseName; -
trunk/magnolia-eclipse/src/org/magnolialang/infra/IInfra.java
r804 r807 26 26 27 27 28 /** 29 * Note that the arguments are reversed compared to Evaluator constructor. 30 * 31 * @param out 32 * writer to use as Rascal stdout 33 * @param err 34 * writer to use as Rascel stderr 35 * @return Rascal evaluator 36 */ 28 37 public Evaluator newEvaluator(PrintWriter out, PrintWriter err); 29 38 -
trunk/magnolia-eclipse/src/org/magnolialang/pgf/tests/Makefile
r713 r807 1 dump : 1 mg : 2 rascal-src-with-magnolia DumpMgData.rsc > MgTestData.rsc 3 4 expr : 2 5 rascal-src DumpExprData.rsc > ExprTestData.rsc -
trunk/magnolia-eclipse/src/org/magnolialang/testutil/MagnoliaCompiler.java
r803 r807 7 7 import org.eclipse.imp.pdb.facts.IConstructor; 8 8 import org.eclipse.imp.pdb.facts.IValue; 9 import org.eclipse.imp.pdb.facts.IValueFactory; 9 10 import org.eclipse.imp.pdb.facts.type.Type; 11 import org.eclipse.imp.pdb.facts.type.TypeFactory; 10 12 import org.magnolialang.compiler.ICompiler; 11 13 import org.magnolialang.compiler.IXRefResolver; … … 128 130 129 131 130 private synchronized void reinitialize() { 131 try { 132 for(IIValueTask producer : producers) { 133 registry.unregisterProducer(producer); 134 } 135 } 136 catch(Throwable t) { // NOPMD by anya on 1/5/12 5:39 AM 137 } 138 for(IIValueTask producer : producers) { 139 registry.registerProducer(producer); 140 } 132 public TypeFactory getTf() { 133 return Evaluator.__getTf(); 134 } 135 136 137 public IValueFactory getVf() { 138 return getEvaluator().__getVf(); 141 139 } 142 140 -
trunk/magnolia-eclipse/src/org/magnolialang/testutil/RascalEval.java
r798 r807 16 16 package org.magnolialang.testutil; 17 17 18 import java.io.File; 18 19 import java.io.PrintWriter; 19 20 import java.net.URI; … … 24 25 import org.eclipse.imp.pdb.facts.IValueFactory; 25 26 import org.eclipse.imp.pdb.facts.type.Type; 27 import org.magnolialang.infra.ConsoleInfra; 26 28 import org.rascalmpl.interpreter.Evaluator; 27 29 import org.rascalmpl.interpreter.env.GlobalEnvironment; … … 36 38 private static final String EVAL_MODULE = "$eval$"; 37 39 38 private final Evaluator evaluator; 40 41 public Evaluator getEvaluator() { 42 return evaluator; 43 } 44 45 private final Evaluator evaluator; 39 46 40 47 … … 46 53 IValueFactory vf = ValueFactoryFactory.getValueFactory(); 47 54 evaluator = new Evaluator(vf, stderr, stdout, root, heap); 55 56 evaluator.addRascalSearchPath((new File(".", "src")).toURI()); 57 for(String s : ConsoleInfra.getRascalSearchPath()) 58 evaluator.addRascalSearchPath((new File(s)).toURI()); 48 59 } 49 60 … … 76 87 77 88 89 /** 90 * @param statement 91 * @return 92 * @throws NullPointerException 93 * if there's no actual result produced 94 */ 78 95 public Result<IValue> evalMore(String statement) { 79 96 return evaluator.evalMore(null, statement, URI.create("prompt:///")); -
trunk/magnolia-eclipse/src/org/magnolialang/testutil/TestUtil.java
r804 r807 21 21 public final class TestUtil { 22 22 23 public static TestUtil getInstance() { 24 return instance; 25 } 26 27 /** 28 * The latest set of options passed to setInstance, 29 * whether it succeeded or not. 30 */ 31 private static Map<String, Object> options = null; 23 private static Map<String, Object> options = Collections.emptyMap(); 32 24 33 25 … … 37 29 38 30 39 /** 40 * Clears any existing instance, even on error. 41 * 42 * @param op 43 * options 44 */ 45 public static void setInstance(Map<String, Object> op) { 46 TestUtil.options = op; 47 TestUtil.instance = null; 48 TestUtil.instance = new TestUtil(); 31 public static void setOptions(Map<String, Object> op) { 32 options = op; 49 33 } 50 51 52 public static void setInstance() {53 Map<String, Object> op = Collections.emptyMap();54 setInstance(op);55 }56 57 private static TestUtil instance = null;58 34 59 35 private final MagnoliaCompiler magnoliaCompiler; … … 61 37 62 38 63 p rivateTestUtil() {64 ConsoleInfra.setInfra();39 public TestUtil() { 40 //ConsoleInfra.setInfra(); 65 41 magnoliaCompiler = new MagnoliaCompiler(); 66 42 tr = magnoliaCompiler.getTransaction(); … … 140 116 141 117 118 public IRascalMonitor getMonitor() { 119 IRascalMonitor rm = getInfra().getMonitor(); 120 return rm; 121 } 122 123 142 124 public String getCxxCode(ILanguage lang, String modName) { 143 125 IRascalMonitor rm = getInfra().getMonitor(); -
trunk/magnolia-eclipse/test/org/magnolialang/test/core.clj
r795 r807 1 1 (ns org.magnolialang.test.core 2 (:use [org.magnolialang.c ore])2 (:use [org.magnolialang.clojure.core]) 3 3 (:use [clojure.test])) 4 4 … … 21 21 (get-parse-tree "basic.Basic") 22 22 (get-imploded-tree "basic.Basic")) 23 24 (deftest test-view-flattened-module 25 (view-flattened-module "basic.Basic"))
Note:
See TracChangeset
for help on using the changeset viewer.