[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-kawa 47a2956 044/119: Refactor kawageiser.Geiser.ja
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-kawa 47a2956 044/119: Refactor kawageiser.Geiser.java |
Date: |
Sun, 1 Aug 2021 18:30:35 -0400 (EDT) |
branch: elpa/geiser-kawa
commit 47a2956bf75a356dd5f2d21da20127e55f549990
Author: spellcard199 <spellcard199@protonmail.com>
Commit: spellcard199 <spellcard199@protonmail.com>
Refactor kawageiser.Geiser.java
---
src/main/java/kawageiser/Geiser.java | 68 ++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 30 deletions(-)
diff --git a/src/main/java/kawageiser/Geiser.java
b/src/main/java/kawageiser/Geiser.java
index 8b06efb..0599b9c 100644
--- a/src/main/java/kawageiser/Geiser.java
+++ b/src/main/java/kawageiser/Geiser.java
@@ -7,6 +7,9 @@ package kawageiser;
import gnu.expr.Language;
+import java.util.HashMap;
+import java.util.Map;
+
public class Geiser implements Runnable {
private static boolean prettyPrintResult = true;
@@ -29,9 +32,6 @@ public class Geiser implements Runnable {
@Override
public void run() {
-
- Language lang = Language.getDefaultLanguage();
-
// In a previous version, geiser's procedures definitions were like
this:
// lang.defineFunction(new GeiserEval("geiser:eval"));
// That meant you had to extend Procedure1, Procedure2... which can
only have
@@ -41,43 +41,51 @@ public class Geiser implements Runnable {
// - parameter types in autodoc: because their types can be other than
Object
// - type warnings: for the same reason of the previous point
// - less boilerplate for checking argument types
+
+ Language lang = Language.getDefaultLanguage();
+
+ // TODO: find out how to make a new working PrimProcedure from Method
+ // and replace methods paths as string with PrimProcedure. This would
avoid Kawa-specific syntax.
+ HashMap<String, String> procMap = new java.util.HashMap<>();
+ procMap.put("geiser:eval", "kawageiser.GeiserEval:evalStr");
+ procMap.put("geiser:autodoc", "kawageiser.GeiserAutodoc:autodoc");
+ procMap.put("geiser:module-completions",
"kawageiser.GeiserCompleteModule:completeModule");
+ procMap.put("geiser:load-file", "kawageiser.GeiserLoadFile:loadFile");
+ procMap.put("geiser:completions",
"kawageiser.GeiserCompleteSymbol:getCompletions");
+ procMap.put("geiser:no-values", "kawageiser.GeiserNoValues:noValues");
+ procMap.put("geiser:complete-java",
"kawageiser.java.GeiserCompleteJava:completeJava");
+ procMap.put("geiser:manual-epub-unzip-to-tmp-dir",
"kawageiser.geiserDoc.ManualEpubUnzipToTmpDir:unzipToTmpDir");
+ procMap.put("geiser:macroexpand",
"kawageiser.GeiserMacroexpand:expand");
+
try {
if (lang.lookup("geiser:eval") == null) {
// The reason for this if block is that if someone re-imported
this module
// and the following code was executed, this exception would
happen:
// java.lang.IllegalStateException:
// prohibited define/redefine of geiser:eval in
#<environment kawa-environment>
- lang.defineFunction(
- "geiser:eval",
- lang.eval("kawageiser.GeiserEval:evalStr"));
- lang.defineFunction(
- "geiser:autodoc",
- lang.eval("kawageiser.GeiserAutodoc:autodoc"));
- lang.defineFunction(
- "geiser:module-completions",
-
lang.eval("kawageiser.GeiserCompleteModule:completeModule"));
- lang.defineFunction(
- "geiser:load-file",
- lang.eval("kawageiser.GeiserLoadFile:loadFile"));
- lang.defineFunction(
- "geiser:completions",
-
lang.eval("kawageiser.GeiserCompleteSymbol:getCompletions"));
- lang.defineFunction(
- "geiser:no-values",
- lang.eval("kawageiser.GeiserNoValues:noValues"));
- lang.defineFunction(
- "geiser:complete-java",
-
lang.eval("kawageiser.java.GeiserCompleteJava:completeJava"));
- lang.defineFunction(
- "geiser:manual-epub-unzip-to-tmp-dir",
-
lang.eval("kawageiser.geiserDoc.ManualEpubUnzipToTmpDir:unzipToTmpDir"));
- lang.defineFunction(
- "geiser:macroexpand",
- lang.eval("kawageiser.GeiserMacroexpand:expand"));
+ for (Map.Entry<String, String> entry : procMap.entrySet()) {
+ String procName = entry.getKey();
+ String methodPathAsKawaCode = entry.getValue();
+ // Since currently kawaDefineFunction uses lang.eval, lang
can only be
+ // Kawa scheme, because it supports the colon notation we
used in procMap.
+ kawaDefineFunction(lang, procName, methodPathAsKawaCode);
+ }
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
+ public void kawaDefineFunction(Language lang, String procName, String
methodPathAsKawaCode) throws Throwable {
+ // Using lang.eval is a workaround to the fact I don't know
+ // how to create a working PrimProcedure using Kawa's java api.
+ Object proc = lang.eval(methodPathAsKawaCode);
+ if (proc == null) {
+ throw new RuntimeException(String.format(
+ "Provided kawa code for `%s' returns null: %s",
+ procName, methodPathAsKawaCode));
+ }
+ lang.defineFunction(procName, proc);
+ }
+
}
- [nongnu] elpa/geiser-kawa 088654b 033/119: Fix function definition is void: word-at-point, (continued)
- [nongnu] elpa/geiser-kawa 088654b 033/119: Fix function definition is void: word-at-point, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 6d4c6f5 004/119: Update .gitignore, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 274f990 024/119: Use mvnw (maven-wrapper) as default command to compile kawa-geiser, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 55efc48 043/119: Fix non-passing Autodoc test, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa a709cfc 027/119: Small reword in README, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 4938a98 049/119: Update kawa-devutil dep + fix code accordingly, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 5521b28 025/119: Update README after joining of geiser-kawa and kawa-geiser projects, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa b95e191 003/119: README - Add small recap table about difference from geiser-kawa-scheme, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 5549434 005/119: Add Cask file, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 590968e 045/119: Add autodoc support for constructor methods, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 47a2956 044/119: Refactor kawageiser.Geiser.java,
Philip Kaludercic <=
- [nongnu] elpa/geiser-kawa 9f3a057 050/119: README - Add more information about java completion + update kawa-devutil dep, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 34b68ce 052/119: Add check for deps with run-kawa is called. Uses emacs advice on run-kawa., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 0aa42cb 040/119: Fix broken test, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa b8647aa 057/119: Fix error in func name, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 79dec54 061/119: Add support for viewing Expression tree, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 8d6202f 081/119: Refactor + Fix style + Copyright notices, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 1ffe084 097/119: Fixes for windows support + README.org: add instructions, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa ad862b1 090/119: Update README.org, TODO.org, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa d7cb7d9 105/119: Remove advice from "run-kawa" + add "geiser-kawa-run-kawa" function, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa ff93297 112/119: README.org - small changes, Philip Kaludercic, 2021/08/01