aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lux/analyser/host.clj5
-rw-r--r--src/lux/analyser/parser.clj29
-rw-r--r--src/lux/base.clj12
-rw-r--r--src/lux/compiler/host.clj21
-rw-r--r--src/lux/host.clj19
5 files changed, 55 insertions, 31 deletions
diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj
index 25dd1d241..99a1da65f 100644
--- a/src/lux/analyser/host.clj
+++ b/src/lux/analyser/host.clj
@@ -716,7 +716,7 @@
[name [_ (&&/$captured _ _ source)]]
source))
-(let [default-<init> (&/V &/$ConstructorMethodSyntax (&/T [(&/V &/$Public &/unit-tag)
+(let [default-<init> (&/V &/$ConstructorMethodSyntax (&/T [(&/V &/$PublicPM &/unit-tag)
(&/|list)
(&/|list)
(&/|list)
@@ -749,7 +749,8 @@
:let [=fields (&/|map (fn [^objects idx+capt]
(|let [[idx _] idx+capt]
(&/T [(str &c!base/closure-prefix idx)
- (&/V &/$Public &/unit-tag)
+ (&/V &/$PublicPM &/unit-tag)
+ (&/V &/$DefaultSM &/unit-tag)
(&/|list)
captured-slot-type])))
(&/enumerate =captured))]
diff --git a/src/lux/analyser/parser.clj b/src/lux/analyser/parser.clj
index 26b161aba..eebfb6693 100644
--- a/src/lux/analyser/parser.clj
+++ b/src/lux/analyser/parser.clj
@@ -149,20 +149,31 @@
(defn parse-privacy-modifier [ast]
(|case ast
[_ (&/$TextS "default")]
- (return (&/V &/$Default &/unit-tag))
+ (return (&/V &/$DefaultPM &/unit-tag))
[_ (&/$TextS "public")]
- (return (&/V &/$Public &/unit-tag))
+ (return (&/V &/$PublicPM &/unit-tag))
[_ (&/$TextS "protected")]
- (return (&/V &/$Protected &/unit-tag))
+ (return (&/V &/$ProtectedPM &/unit-tag))
[_ (&/$TextS "private")]
- (return (&/V &/$Private &/unit-tag))
+ (return (&/V &/$PrivatePM &/unit-tag))
_
(fail (str "[Analyser Error] Invalid privacy modifier: " (&/show-ast ast)))))
+(defn parse-state-modifier [ast]
+ (|case ast
+ [_ (&/$TextS "default")]
+ (return (&/V &/$DefaultSM &/unit-tag))
+
+ [_ (&/$TextS "volatile")]
+ (return (&/V &/$VolatileSM &/unit-tag))
+
+ _
+ (fail (str "[Analyser Error] Invalid state modifier: " (&/show-ast ast)))))
+
(defn ^:private parse-method-init-def [ast]
(|case ast
[_ (&/$FormS (&/$Cons [_ (&/$TextS "init")]
@@ -263,13 +274,15 @@
(|case ast
[_ (&/$FormS (&/$Cons [_ (&/$TextS ?name)]
(&/$Cons ?privacy-modifier
- (&/$Cons [_ (&/$TupleS ?anns)]
- (&/$Cons ?type
- (&/$Nil))))))]
+ (&/$Cons ?state-modifier
+ (&/$Cons [_ (&/$TupleS ?anns)]
+ (&/$Cons ?type
+ (&/$Nil)))))))]
(|do [=privacy-modifier (parse-privacy-modifier ?privacy-modifier)
+ =state-modifier (parse-state-modifier ?state-modifier)
=anns (&/map% parse-ann ?anns)
=type (parse-gclass ?type)]
- (return (&/T [?name =privacy-modifier =anns =type])))
+ (return (&/T [?name =privacy-modifier =state-modifier =anns =type])))
_
(fail (str "[Analyser Error] Invalid field declaration: " (&/show-ast ast)))))
diff --git a/src/lux/base.clj b/src/lux/base.clj
index dc8dc0081..3a03ddf9a 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -111,10 +111,14 @@
;; Privacy Modifiers
(deftags
- ["Default"
- "Public"
- "Private"
- "Protected"])
+ ["DefaultPM"
+ "PublicPM"
+ "PrivatePM"
+ "ProtectedPM"])
+
+(deftags
+ ["DefaultSM"
+ "VolatileSM"])
;; Methods
(deftags
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index deeb529b5..4fd3b7e0f 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -434,20 +434,11 @@
(.visitEnd))
nil)
-(defn ^:private privacy-modifer->flag [privacy-modifier]
- "(-> PrivacyModifier Int)"
- (|case privacy-modifier
- (&/$Public) Opcodes/ACC_PUBLIC
- (&/$Private) Opcodes/ACC_PRIVATE
- (&/$Protected) Opcodes/ACC_PROTECTED
- (&/$Default) 0
- _ (assert false (println-str (&/adt->text privacy-modifier) (&/adt->text (&/V &/$Public nil))))
- ))
-
(defn ^:private compile-field [^ClassWriter writer field]
- (|let [[=name =privacy-modifier =anns =type] field
+ (|let [[=name =privacy-modifier =state-modifier =anns =type] field
=field (.visitField writer
- (privacy-modifer->flag =privacy-modifier)
+ (+ (&host/privacy-modifier->flag =privacy-modifier)
+ (&host/state-modifier->flag =state-modifier))
=name
(&host-generics/gclass->simple-signature =type)
(&host-generics/gclass->signature =type) nil)]
@@ -510,7 +501,7 @@
=method-decl (&/T [init-method ?anns ?gvars ?exceptions (&/|map &/|second ?inputs) ?output])
[simple-signature generic-signature] (&host-generics/method-signatures =method-decl)]
(&/with-writer (.visitMethod class-writer
- (privacy-modifer->flag ?privacy-modifier)
+ (&host/privacy-modifier->flag ?privacy-modifier)
init-method
simple-signature
generic-signature
@@ -537,7 +528,7 @@
(|let [=method-decl (&/T [?name ?anns ?gvars ?exceptions (&/|map &/|second ?inputs) ?output])
[simple-signature generic-signature] (&host-generics/method-signatures =method-decl)]
(&/with-writer (.visitMethod class-writer
- (privacy-modifer->flag ?privacy-modifier)
+ (&host/privacy-modifier->flag ?privacy-modifier)
?name
simple-signature
generic-signature
@@ -575,7 +566,7 @@
(|let [=method-decl (&/T [?name ?anns ?gvars ?exceptions (&/|map &/|second ?inputs) ?output])
[simple-signature generic-signature] (&host-generics/method-signatures =method-decl)]
(&/with-writer (.visitMethod class-writer
- (+ (privacy-modifer->flag ?privacy-modifier)
+ (+ (&host/privacy-modifier->flag ?privacy-modifier)
Opcodes/ACC_STATIC)
?name
simple-signature
diff --git a/src/lux/host.clj b/src/lux/host.clj
index fe648c8ff..0e39aa6df 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -330,6 +330,21 @@
(assert false (println-str 'compile-dummy-method (&/adt->text method-def)))
))
+(defn state-modifier->flag [state-modifier]
+ "(-> State Int)"
+ (|case state-modifier
+ (&/$DefaultSM) 0
+ (&/$VolatileSM) Opcodes/ACC_VOLATILE))
+
+(defn privacy-modifier->flag [privacy-modifier]
+ "(-> PrivacyModifier Int)"
+ (|case privacy-modifier
+ (&/$PublicPM) Opcodes/ACC_PUBLIC
+ (&/$PrivatePM) Opcodes/ACC_PRIVATE
+ (&/$ProtectedPM) Opcodes/ACC_PROTECTED
+ (&/$DefaultPM) 0
+ ))
+
(defn use-dummy-class [class-decl super-class interfaces ctor-args fields methods]
(|do [module &/get-module-name
:let [[?name ?params] class-decl
@@ -342,8 +357,8 @@
(&host-generics/->bytecode-class-name (&host-generics/super-class-name super-class))
(->> interfaces (&/|map (comp &host-generics/->bytecode-class-name &host-generics/super-class-name)) &/->seq (into-array String))))
_ (&/|map (fn [field]
- (|let [[=name =privacy-modifier =anns =type] field]
- (doto (.visitField =class Opcodes/ACC_PUBLIC =name
+ (|let [[=name =privacy-modifier =state-modifier =anns =type] field]
+ (doto (.visitField =class (+ Opcodes/ACC_PUBLIC (state-modifier->flag =state-modifier)) =name
(&host-generics/gclass->simple-signature =type)
(&host-generics/gclass->signature =type)
nil)