diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/ffi.jvm.lux | 151 |
1 files changed, 5 insertions, 146 deletions
diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index bc91e8880..a025b8108 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -56,7 +56,6 @@ (template [<name> <class>] [(`` (def: .public <name> - {#.doc (example (~~ (template.text ["The type of a (boxed) " <name> " object."])))} .Type (#.Primitive <class> #.End)))] @@ -1211,37 +1210,6 @@ annotations ..annotations^ fields (<>.some (..field_decl^ class_vars)) methods (<>.some (..method_def^ class_vars))]) - {#.doc (example "Allows defining JVM classes in Lux code." - "For example:" - (class: #final (TestClass A) [Runnable] - ... Fields - (#private foo boolean) - (#private bar A) - (#private baz java/lang/Object) - ... Methods - (#public [] (new [value A]) [] - (exec - (:= ::foo #1) - (:= ::bar value) - (:= ::baz "") - [])) - (#public (virtual) java/lang/Object - "") - (#public #static (static) java/lang/Object - "") - (Runnable [] (run) void - []) - ) - - "The tuple corresponds to parent interfaces." - "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." - "Fields and methods defined in the class can be used with special syntax." - "For example:" - "::resolved, for accessing the 'resolved' field." - "(:= ::resolved #1) for modifying it." - "(::new! []) for calling the class's constructor." - "(::resolve! container [value]) for calling the 'resolve' method." - )} (do meta.monad [.let [fully_qualified_class_name full_class_name method_parser (: (Parser Code) @@ -1263,9 +1231,6 @@ (<code>.tuple (<>.some (class^ class_vars)))) annotations ..annotations^ members (<>.some (..method_decl^ class_vars))]) - {#.doc (example "Allows defining JVM interfaces." - (interface: TestInterface - ([] foo [boolean String] void #throws [Exception])))} (in (list (` ("jvm class interface" (~ (declaration$ (type.declaration full_class_name class_vars))) [(~+ (list\map class$ supers))] @@ -1279,18 +1244,6 @@ (<code>.tuple (<>.some (class^ class_vars)))) constructor_args (..constructor_args^ class_vars) methods (<>.some ..overriden_method_def^)]) - {#.doc (example "Allows defining anonymous classes." - "The 1st tuple corresponds to class-level type-variables." - "The 2nd tuple corresponds to parent interfaces." - "The 3rd tuple corresponds to arguments to the super class constructor." - "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." - (object [] [Runnable] - [] - (Runnable [] (run self) void - (exec - (do_something some_value) - []))) - )} (in (list (` ("jvm class anonymous" [(~+ (list\map var$ class_vars))] (~ (class$ super)) @@ -1299,25 +1252,13 @@ [(~+ (list\map (method_def$ "" (<>.failure "") super (list)) methods))]))))) (syntax: .public (null []) - {#.doc (example "The null pointer." - (null))} (in (list (` ("jvm object null"))))) (def: .public (null? obj) - {#.doc (example "Test for the null pointer." - (= (null? (null)) - true) - (= (null? "YOLO") - false))} (-> (primitive "java.lang.Object") Bit) ("jvm object null?" obj)) (syntax: .public (??? [expr <code>.any]) - {#.doc (example "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." - (= (??? (: java/lang/String (null))) - #.None) - (= (??? "YOLO") - (#.Some "YOLO")))} (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ expr)] (if ("jvm object null?" (~ g!temp)) @@ -1325,12 +1266,6 @@ (#.Some (~ g!temp))))))))) (syntax: .public (!!! [expr <code>.any]) - {#.doc (example "Takes a (Maybe ObjectType) and returns a ObjectType." - "A #.None would get translated into a (null)." - (= (null) - (!!! (??? (: java/lang/Thread (null))))) - (= "foo" - (!!! (??? "foo"))))} (with_identifiers [g!value] (in (list (` ({(#.Some (~ g!value)) (~ g!value) @@ -1341,11 +1276,6 @@ (syntax: .public (check [class (..type^ (list)) unchecked (<>.maybe <code>.any)]) - {#.doc (example "Checks whether an object is an instance of a particular class." - "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes." - (case (check String "YOLO") - (#.Some value_as_string) - #.None))} (with_identifiers [g!_ g!unchecked] (let [class_name (..reflection class) class_type (` (.primitive (~ (code.text class_name)))) @@ -1368,20 +1298,10 @@ (syntax: .public (synchronized [lock <code>.any body <code>.any]) - {#.doc (example "Evaluates body, while holding a lock on a given object." - (synchronized object_to_be_locked - (exec - (do something) - (dosomething else) - (finish the computation))))} (in (list (` ("jvm object synchronized" (~ lock) (~ body)))))) (syntax: .public (do_to [obj <code>.any methods (<>.some partial_call^)]) - {#.doc (example "Call a variety of methods on an object. Then, return the object." - (do_to object - (ClassName::method1 arg0 arg1 arg2) - (ClassName::method2 arg3 arg4 arg5)))} (with_identifiers [g!obj] (in (list (` (let [(~ g!obj) (~ obj)] (exec (~+ (list\map (complete_call$ g!obj) methods)) @@ -1753,57 +1673,6 @@ (syntax: .public (import: [declaration ..declaration^ .let [[class_name class_type_vars] (parser.declaration declaration)] bundles (<>.some (..bundle class_type_vars))]) - {#.doc (example "Allows importing JVM classes, and using them as types." - "Their methods, fields and enum options can also be imported." - (import: java/lang/Object - ["#::." - (new []) - (equals [java/lang/Object] boolean) - (wait [int] #io #try void)]) - - "Special options can also be given for the return values." - "#? means that the values will be returned inside a Maybe type. That way, null becomes #.None." - "#try means that the computation might throw an exception, and the return value will be wrapped by the Try type." - "#io means the computation has side effects, and will be wrapped by the IO type." - "These options must show up in the following order [#io #try #?] (although, each option can be used independently)." - (import: java/lang/String - ["#::." - (new [[byte]]) - (#static valueOf [char] java/lang/String) - (#static valueOf #as int_valueOf [int] java/lang/String)]) - - (import: (java/util/List e) - ["#::." - (size [] int) - (get [int] e)]) - - (import: (java/util/ArrayList a) - ["#::." - ([T] toArray [[T]] [T])]) - - "The class-type that is generated is of the fully-qualified name." - "This avoids a clash between the java.util.List type, and Lux's own List type." - "All enum options to be imported must be specified." - (import: java/lang/Character$UnicodeScript - ["#::." - (#enum ARABIC CYRILLIC LATIN)]) - - "It should also be noted, the only types that may show up in method arguments or return values may be Java classes, arrays, primitives, void or type-vars." - "Lux types, such as Maybe cannot be named (otherwise, they'd be confused for Java classes)." - (import: (lux/concurrency/async/JvmAsync A) - ["#::." - (resolve [A] boolean) - (poll [] A) - (wasResolved [] boolean) - (waitOn [lux/Function] void) - (#static [A] make [A] (lux/concurrency/async/JvmAsync A))]) - - "Also, the names of the imported members will look like Class::member" - (java/lang/Object::new []) - (java/lang/Object::equals [other_object] my_object) - (java/util/List::size [] my_list) - java/lang/Character$UnicodeScript::LATIN - )} (do {! meta.monad} [kind (class_kind declaration) =members (|> bundles @@ -1815,13 +1684,11 @@ (syntax: .public (array [type (..type^ (list)) size <code>.any]) - {#.doc (example "Create an array of the given type, with the given size." - (array java/lang/Object 10))} - (let [g!size (` (|> (~ size) - (.: .Nat) - (.:as (.primitive (~ (code.text box.long)))) - "jvm object cast" - "jvm conversion long-to-int"))] + (let [g!size (` (|> (~ size) + (.: .Nat) + (.:as (.primitive (~ (code.text box.long)))) + "jvm object cast" + "jvm conversion long-to-int"))] (`` (cond (~~ (template [<primitive> <array_op>] [(\ type.equivalence = <primitive> type) (in (list (` (<array_op> (~ g!size)))))] @@ -1934,8 +1801,6 @@ <failure>)))) (syntax: .public (length [array <code>.any]) - {#.doc (example "Gives the length of an array." - (length my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -1971,8 +1836,6 @@ (syntax: .public (read! [idx <code>.any array <code>.any]) - {#.doc (example "Loads an element from an array." - (read! 10 my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -2011,8 +1874,6 @@ (syntax: .public (write! [idx <code>.any value <code>.any array <code>.any]) - {#.doc (example "Stores an element into an array." - (write! 10 my_object my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -2050,8 +1911,6 @@ (..write! (~ idx) (~ value) (~ g!array))))))))) (syntax: .public (class_for [type (..type^ (list))]) - {#.doc (example "Loads the class as a java.lang.Class object." - (class_for java/lang/String))} (in (list (` ("jvm object class" (~ (code.text (..reflection type)))))))) (syntax: .public (type [type (..type^ (list))]) |