aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2016-11-03 17:37:47 -0400
committerEduardo Julian2016-11-03 17:37:47 -0400
commit7092911a2a213ea49b51af2d641c369bb09d1918 (patch)
tree0dbf2dfa3daa1ce9c4847e88f966cf1c57de2c1f /src
parent969cfa5f52085de2b92fc47387a9550a07a34452 (diff)
- Made some tentative changes to the compilation process, since not all bytecode that works on the JVM also works properly on Android. Further testing and tweaking is needed.
Diffstat (limited to '')
-rw-r--r--src/lux/compiler.clj25
-rw-r--r--src/lux/compiler/host.clj33
-rw-r--r--src/lux/host.clj4
3 files changed, 36 insertions, 26 deletions
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index 030df1dd6..0f019bcb1 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -213,16 +213,20 @@
defs &a-module/defs
imports &a-module/imports
tag-groups &&module/tag-groups
- :let [_ (doto =class
+ :let [^String defs-value (->> defs
+ (&/|filter (fn [_def]
+ (|let [[?name ?alias] _def]
+ (= "" ?alias))))
+ (&/|map (fn [_def]
+ (|let [[?name ?alias] _def]
+ (str ?name
+ &&/exported-separator
+ ?alias))))
+ (&/|interpose &&/def-separator)
+ (&/fold str ""))
+ _ (doto =class
(-> (.visitField (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) &/defs-field "Ljava/lang/String;" nil
- (->> defs
- (&/|map (fn [_def]
- (|let [[?name ?alias] _def]
- (str ?name
- &&/exported-separator
- ?alias))))
- (&/|interpose &&/def-separator)
- (&/fold str "")))
+ defs-value)
.visitEnd)
(-> (.visitField (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) &/imports-field "Ljava/lang/String;" nil
(->> imports
@@ -240,7 +244,8 @@
(str type &&/type-separator)))))
(&/|interpose &&/tag-group-separator)
(&/fold str "")))
- .visitEnd))]
+ .visitEnd)
+ )]
_ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil)
(|do [^MethodVisitor **writer** &/get-writer
:let [_ (.visitCode **writer**)]
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 6c1646933..211ed018c 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -130,7 +130,9 @@
(defn ^:private compile-method-return [^MethodVisitor writer output]
(|case output
(&/$GenericClass "void" (&/$Nil))
- (.visitInsn writer Opcodes/RETURN)
+ (doto writer
+ (.visitInsn Opcodes/POP)
+ (.visitInsn Opcodes/RETURN))
(&/$GenericClass "boolean" (&/$Nil))
(doto writer
@@ -484,19 +486,22 @@
_
(return nil))
- _ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil)
- (|do [^MethodVisitor =method &/get-writer
- :let [_ (doto =method
- (.visitCode))]
- _ (&/map% (fn [ftriple]
- (|let [[fname fgclass fvalue] ftriple]
- (compile-jvm-putstatic compile (&/|list (&o/optimize fvalue)) (&/|list ?name fname fgclass))))
- (constant-inits ?fields))
- :let [_ (doto =method
- (.visitInsn Opcodes/RETURN)
- (.visitMaxs 0 0)
- (.visitEnd))]]
- (return nil)))]
+ _ (|let [field-inits (constant-inits ?fields)]
+ (if (&/|empty? field-inits)
+ (return nil)
+ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil)
+ (|do [^MethodVisitor =method &/get-writer
+ :let [_ (doto =method
+ (.visitCode))]
+ _ (&/map% (fn [ftriple]
+ (|let [[fname fgclass fvalue] ftriple]
+ (compile-jvm-putstatic compile (&/|list (&o/optimize fvalue)) (&/|list ?name fname fgclass))))
+ field-inits)
+ :let [_ (doto =method
+ (.visitInsn Opcodes/RETURN)
+ (.visitMaxs 0 0)
+ (.visitEnd))]]
+ (return nil)))))]
(&&/save-class! ?name (.toByteArray (doto =class .visitEnd)))))
(defn compile-jvm-interface [interface-decl ?supers ?anns ?methods]
diff --git a/src/lux/host.clj b/src/lux/host.clj
index 26176b840..3c8cef536 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -104,7 +104,7 @@
(do-template [<name> <static?> <method-type>]
(defn <name> [class-loader target method-name args]
(|let [target-class (Class/forName target true class-loader)]
- (if-let [[^Method method ^Class declarer] (first (for [^Method =method (.getMethods target-class)
+ (if-let [[^Method method ^Class declarer] (first (for [^Method =method (.getDeclaredMethods target-class)
:when (and (.equals ^Object method-name (.getName =method))
(.equals ^Object <static?> (Modifier/isStatic (.getModifiers =method)))
(let [param-types (&/->list (seq (.getParameterTypes =method)))]
@@ -394,7 +394,7 @@
(defn use-dummy-class [class-decl super-class interfaces ctor-args fields methods]
(|do [module &/get-module-name
:let [[?name ?params] class-decl
- dummy-name (str ?name "__DUMMY__")
+ dummy-name ?name;; (str ?name "__DUMMY__")
dummy-full-name (str module "/" dummy-name)
real-name (str (&host-generics/->class-name module) "." ?name)
store-name (str (&host-generics/->class-name module) "." dummy-name)