aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
diff options
context:
space:
mode:
authorEduardo Julian2022-06-14 14:34:30 -0400
committerEduardo Julian2022-06-14 14:34:30 -0400
commit3530dc17c5dc836c826b4a29cff2f3408dc8590d (patch)
treebc09b06a93f7b8f988b7fe1667dff34a7e1b85f1 /stdlib/source/library
parent9a835bde8908e4ebd1c8972211acadc5895d720a (diff)
Better syntax for JVM class field imports.
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/ffi.jvm.lux113
-rw-r--r--stdlib/source/library/lux/ffi.old.lux8
-rw-r--r--stdlib/source/library/lux/target/jvm/loader.lux2
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux4
-rw-r--r--stdlib/source/library/lux/world/console.lux4
-rw-r--r--stdlib/source/library/lux/world/file.lux2
-rw-r--r--stdlib/source/library/lux/world/file/watch.lux6
7 files changed, 79 insertions, 60 deletions
diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux
index 32b5410ee..f5ae643ad 100644
--- a/stdlib/source/library/lux/ffi.jvm.lux
+++ b/stdlib/source/library/lux/ffi.jvm.lux
@@ -988,17 +988,17 @@
[#import_method_name name
#import_method_return return]]})))
(<code>.form (do <>.monad
- [static? (<>.parses? (<code>.this (' "static")))
+ [read_only? (<>.parses? (<code>.this (' "read_only")))
+ static? (<>.parses? (<code>.this (' "static")))
name <code>.local
?prim_mode (<>.maybe primitive_mode^)
- gtype (..type^ owner_vars)
maybe? (<>.parses? (<code>.this (' "?")))
- setter? (<>.parses? (<code>.this (' #!)))]
+ gtype (..type^ owner_vars)]
(in {#FieldAccessDecl [#import_field_mode (maybe.else {#AutoPrM} ?prim_mode)
#import_field_name name
#import_field_static? static?
#import_field_maybe? maybe?
- #import_field_setter? setter?
+ #import_field_setter? (not read_only?)
#import_field_type gtype]})))
))
@@ -1500,6 +1500,12 @@
(list name (` (~! <code>.any)))))
list#conjoint))
+(exception: .public (cannot_write_to_field [class Text
+ field Text])
+ (exception.report
+ "Class" (%.text class)
+ "Field" (%.text field)))
+
(def: (member_def_interop vars kind class [arg_function_inputs input_jvm_types arg_types] member method_prefix import_format)
(-> (List (Type Var)) Class_Kind (Type Declaration) [(List [Bit Code]) (List (Type Value)) (List Code)] Import_Member_Declaration Text Text (Meta (List Code)))
(let [[full_name class_tvars] (parser.declaration class)]
@@ -1603,49 +1609,62 @@
{#FieldAccessDecl fad}
(do meta.monad
[.let [(open "_[0]") fad
- getter_name (code.symbol ["" (..import_name import_format method_prefix _#import_field_name)])
- setter_name (code.symbol ["" (..import_name import_format method_prefix (format _#import_field_name "!"))])]
- getter_interop (with_symbols [g!obj]
- (let [getter_call (if _#import_field_static?
- (` ((~ getter_name) []))
- (` ((~ getter_name) [(~ g!obj) (~! <code>.any)])))
- getter_body (<| (with_automatic_output_conversion _#import_field_mode)
- [_#import_field_type
- (if _#import_field_static?
- (get_static_field full_name _#import_field_name)
- (get_virtual_field full_name _#import_field_name (..un_quoted g!obj)))])
- getter_body (if _#import_field_maybe?
- (` ((~! ???) (~ getter_body)))
- getter_body)
- getter_body (if _#import_field_setter?
- (` ((~! io.io) (~ getter_body)))
- getter_body)]
- (in (` (def: (~ getter_name)
- ((~! syntax) (~ getter_call)
- ((~' in) (.list (.` (~ getter_body))))))))))
- setter_interop (.is (Meta (List Code))
- (if _#import_field_setter?
- (with_symbols [g!obj g!value]
- (let [setter_call (if _#import_field_static?
- (` ((~ setter_name) [(~ g!value) (~! <code>.any)]))
- (` ((~ setter_name) [(~ g!value) (~! <code>.any)
- (~ g!obj) (~! <code>.any)])))
- setter_value (|> [_#import_field_type (..un_quoted g!value)]
- (with_automatic_input_conversion _#import_field_mode))
- setter_value (if _#import_field_maybe?
- (` ((~! !!!) (~ setter_value)))
- setter_value)
- setter_command (format (if _#import_field_static? "jvm putstatic" "jvm putfield")
- ":" full_name ":" _#import_field_name)
- g!obj+ (.is (List Code)
- (if _#import_field_static?
- (list)
- (list (..un_quoted g!obj))))]
- (in (list (` (def: (~ setter_name)
- ((~! syntax) (~ setter_call)
- ((~' in) (.list (.` ((~! io.io) ((~ (code.text setter_command)) (~+ g!obj+) (~ setter_value)))))))))))))
- (in (list))))]
- (in (list.partial getter_interop setter_interop)))
+ g!name (code.symbol ["" (..import_name import_format method_prefix _#import_field_name)])]]
+ (with_symbols [g!obj g!value write|read]
+ (in (let [getter_body (<| (with_automatic_output_conversion _#import_field_mode)
+ [_#import_field_type
+ (if _#import_field_static?
+ (get_static_field full_name _#import_field_name)
+ (get_virtual_field full_name _#import_field_name (..un_quoted g!obj)))])
+ getter_body (if _#import_field_maybe?
+ (` ((~! ???) (~ getter_body)))
+ getter_body)
+ getter_body (if _#import_field_setter?
+ (` ((~! io.io) (~ getter_body)))
+ getter_body)
+
+ setter_value (|> [_#import_field_type (..un_quoted g!value)]
+ (with_automatic_input_conversion _#import_field_mode))
+ setter_value (if _#import_field_maybe?
+ (` ((~! !!!) (~ setter_value)))
+ setter_value)
+ setter_command (if _#import_field_static? "jvm member put static" "jvm member put virtual")
+ g!obj+ (.is (List Code)
+ (if _#import_field_static?
+ (list)
+ (list (..un_quoted g!obj))))
+
+ parser (let [write (if _#import_field_static?
+ (` (~! <code>.any))
+ (` ((~! <>.and)
+ (~! <code>.any)
+ (~! <code>.any))))
+ read (if _#import_field_static?
+ (` (~! <code>.end))
+ (` (~! <code>.any)))]
+ (` ((~! <>.or) (~ write) (~ read))))
+ write (list (if _#import_field_static?
+ (` {.#Left [(~ g!value)]})
+ (` {.#Left [(~ g!value) (~ g!obj)]}))
+ (if _#import_field_setter?
+ (` ((~' in) (.list (.` ((~! io.io) ((~ (code.text setter_command))
+ (~ (code.text full_name))
+ (~ (code.text _#import_field_name))
+ (~ setter_value)
+ (~+ g!obj+)))))))
+ (` ((~! meta.failure) (~ (code.text (exception.error ..cannot_write_to_field [full_name _#import_field_name])))))))
+ read (list (if _#import_field_static?
+ (` {.#Right []})
+ (` {.#Right [(~ g!obj)]}))
+ (` ((~' in) (.list (.` (~ getter_body))))))
+
+ it (` (def: (~ g!name)
+ ((~! syntax) ((~ g!name) [(~ write|read) (~ parser)])
+ (case (~ write|read)
+ (~+ write)
+ (~+ read)))))
+ _ ("lux io log" (%.format "[!] " (%.code it)))]
+ (list it)))))
)))
(def: (member_import$ vars kind class [import_format member])
diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux
index 1933ba032..92d7322fd 100644
--- a/stdlib/source/library/lux/ffi.old.lux
+++ b/stdlib/source/library/lux/ffi.old.lux
@@ -959,17 +959,17 @@
[#import_method_name name
#import_method_return return]]})))
(<code>.form (do <>.monad
- [static? (<>.parses? (<code>.this (' "static")))
+ [read_only? (<>.parses? (<code>.this (' "read_only")))
+ static? (<>.parses? (<code>.this (' "static")))
name <code>.local
?prim_mode (<>.maybe primitive_mode^)
gtype (..generic_type^ owner_vars)
- maybe? (<>.parses? (<code>.this (' "?")))
- setter? (<>.parses? (<code>.this (' "!")))]
+ maybe? (<>.parses? (<code>.this (' "?")))]
(in {#FieldAccessDecl [#import_field_mode (maybe.else {#AutoPrM} ?prim_mode)
#import_field_name name
#import_field_static? static?
#import_field_maybe? maybe?
- #import_field_setter? setter?
+ #import_field_setter? (not read_only?)
#import_field_type gtype]})))
))
diff --git a/stdlib/source/library/lux/target/jvm/loader.lux b/stdlib/source/library/lux/target/jvm/loader.lux
index f582d2140..ee54b8aef 100644
--- a/stdlib/source/library/lux/target/jvm/loader.lux
+++ b/stdlib/source/library/lux/target/jvm/loader.lux
@@ -53,7 +53,7 @@
(import java/lang/Integer
"[1]::[0]"
- ("static" TYPE (java/lang/Class java/lang/Integer)))
+ ("read_only" "static" TYPE (java/lang/Class java/lang/Integer)))
(import java/lang/reflect/AccessibleObject
"[1]::[0]"
diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
index c19c7ed00..47fb81088 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
@@ -60,8 +60,8 @@
(import java/util/jar/Attributes$Name
"[1]::[0]"
- ("static" MAIN_CLASS java/util/jar/Attributes$Name)
- ("static" MANIFEST_VERSION java/util/jar/Attributes$Name))
+ ("read_only" "static" MAIN_CLASS java/util/jar/Attributes$Name)
+ ("read_only" "static" MANIFEST_VERSION java/util/jar/Attributes$Name))
(import java/util/jar/Manifest
"[1]::[0]"
diff --git a/stdlib/source/library/lux/world/console.lux b/stdlib/source/library/lux/world/console.lux
index f7fee43da..4112af8f4 100644
--- a/stdlib/source/library/lux/world/console.lux
+++ b/stdlib/source/library/lux/world/console.lux
@@ -60,8 +60,8 @@
(import java/lang/System
"[1]::[0]"
("static" console [] "io" "?" java/io/Console)
- ("static" in java/io/InputStream)
- ("static" out java/io/PrintStream))
+ ("read_only" "static" in java/io/InputStream)
+ ("read_only" "static" out java/io/PrintStream))
(exception: .public cannot_open)
diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux
index 51abe0483..420fd0bde 100644
--- a/stdlib/source/library/lux/world/file.lux
+++ b/stdlib/source/library/lux/world/file.lux
@@ -177,7 +177,7 @@
(renameTo [java/io/File] "io" "try" boolean)
(lastModified [] "io" "try" long)
(setLastModified [long] "io" "try" boolean)
- ("static" separator java/lang/String)))
+ ("read_only" "static" separator java/lang/String)))
(ffi.import java/lang/AutoCloseable
"[1]::[0]"
diff --git a/stdlib/source/library/lux/world/file/watch.lux b/stdlib/source/library/lux/world/file/watch.lux
index d9b982faf..84f9cae1d 100644
--- a/stdlib/source/library/lux/world/file/watch.lux
+++ b/stdlib/source/library/lux/world/file/watch.lux
@@ -301,9 +301,9 @@
(import java/nio/file/StandardWatchEventKinds
"[1]::[0]"
- ("static" ENTRY_CREATE (java/nio/file/WatchEvent$Kind java/nio/file/Path))
- ("static" ENTRY_MODIFY (java/nio/file/WatchEvent$Kind java/nio/file/Path))
- ("static" ENTRY_DELETE (java/nio/file/WatchEvent$Kind java/nio/file/Path)))
+ ("read_only" "static" ENTRY_CREATE (java/nio/file/WatchEvent$Kind java/nio/file/Path))
+ ("read_only" "static" ENTRY_MODIFY (java/nio/file/WatchEvent$Kind java/nio/file/Path))
+ ("read_only" "static" ENTRY_DELETE (java/nio/file/WatchEvent$Kind java/nio/file/Path)))
(def: (default_event_concern event)
(All (_ a)