From c5b61d2f46ac19bf511197f3a537c4be0f47df33 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 27 Aug 2021 20:59:34 -0400 Subject: Updates to the Ruby compiler. --- stdlib/source/documentation/lux.lux | 16 +- .../documentation/lux/control/concatenative.lux | 8 +- .../documentation/lux/control/security/policy.lux | 2 +- stdlib/source/documentation/lux/ffi.jvm.lux | 336 +++++++++++++++++++++ stdlib/source/documentation/lux/ffi.lux | 336 --------------------- stdlib/source/documentation/lux/ffi.old.lux | 265 ++++++++++++++++ stdlib/source/documentation/lux/ffi.rb.lux | 46 +++ stdlib/source/documentation/lux/type/abstract.lux | 10 +- 8 files changed, 665 insertions(+), 354 deletions(-) create mode 100644 stdlib/source/documentation/lux/ffi.jvm.lux delete mode 100644 stdlib/source/documentation/lux/ffi.lux create mode 100644 stdlib/source/documentation/lux/ffi.old.lux create mode 100644 stdlib/source/documentation/lux/ffi.rb.lux (limited to 'stdlib/source/documentation') diff --git a/stdlib/source/documentation/lux.lux b/stdlib/source/documentation/lux.lux index b1d7ae466..712814250 100644 --- a/stdlib/source/documentation/lux.lux +++ b/stdlib/source/documentation/lux.lux @@ -150,19 +150,19 @@ (documentation: /.All "Universal quantification." - [(All [a] + [(All (_ a) (-> a a))] ["A name can be provided, to specify a recursive type." - (All List [a] + (All (List a) (Or Any [a (List a)]))]) (documentation: /.Ex "Existential quantification." - [(Ex [a] + [(Ex (_ a) [(Codec Text a) a])] ["A name can be provided, to specify a recursive type." - (Ex Self [a] + (Ex (Self a) [(Codec Text a) a (List (Self a))])]) @@ -304,7 +304,7 @@ (documentation: /.type "Takes a type expression and returns its representation as data-structure." - [(type (All [a] + [(type (All (_ a) (Maybe (List a))))]) (documentation: /.: @@ -400,7 +400,7 @@ (documentation: /.function "Syntax for creating functions." - [(: (All [a b] + [(: (All (_ a b) (-> a b a)) (function (_ x y) x))] @@ -533,7 +533,7 @@ (format "Same as the 'open' macro, but meant to be used as a pattern-matching macro for generating local bindings." \n "Takes an 'alias' text for the generated local bindings.") [(def: .public (range enum from to) - (All [a] (-> (Enum a) a a (List a))) + (All (_ a) (-> (Enum a) a a (List a))) (let [(^open ".") enum] (loop [end to output #.End] @@ -777,7 +777,7 @@ "Allows you to refer to the type-variables in a polymorphic function's type, by their index.") ["In the example below, 0 corresponds to the 'a' variable." (def: .public (of_list list) - (All [a] (-> (List a) (Row a))) + (All (_ a) (-> (List a) (Row a))) (list\mix add (: (Row (:parameter 0)) empty) diff --git a/stdlib/source/documentation/lux/control/concatenative.lux b/stdlib/source/documentation/lux/control/concatenative.lux index 6c97e056f..a1163c241 100644 --- a/stdlib/source/documentation/lux/control/concatenative.lux +++ b/stdlib/source/documentation/lux/control/concatenative.lux @@ -21,13 +21,13 @@ (documentation: /.=> "Concatenative function types." [(=> [Nat] [Nat])] - [(All [a] + [(All (_ a) (-> a (=> [] [a])))] - [(All [t] + [(All (_ t) (=> [t] []))] - [(All [a b c] + [(All (_ a b c) (=> [a b c] [b c a]))] - [(All [___a ___z] + [(All (_ ___a ___z) (=> {then (=> ___a ___z) else (=> ___a ___z)} ___a [Bit then else] ___z))]) diff --git a/stdlib/source/documentation/lux/control/security/policy.lux b/stdlib/source/documentation/lux/control/security/policy.lux index 8f7b100b7..37d499014 100644 --- a/stdlib/source/documentation/lux/control/security/policy.lux +++ b/stdlib/source/documentation/lux/control/security/policy.lux @@ -45,7 +45,7 @@ unsafe))) (def: (policy _) - (Ex [%] (-> Any (Policy %))) + (Ex (_ %) (-> Any (Policy %))) (with_policy (: (Context Privacy Policy) (function (_ (^open "%::.")) diff --git a/stdlib/source/documentation/lux/ffi.jvm.lux b/stdlib/source/documentation/lux/ffi.jvm.lux new file mode 100644 index 000000000..a781e10ff --- /dev/null +++ b/stdlib/source/documentation/lux/ffi.jvm.lux @@ -0,0 +1,336 @@ +(.module: + [library + [lux (#- int char type :as) + ["$" documentation (#+ documentation:)] + [data + ["." text (#+ \n) + ["%" format (#+ format)]]] + [macro + ["." template]]]] + [\\library + ["." /]]) + +(template [] + [(`` (documentation: + (format "The type of a (boxed) " (~~ (template.text [])) " object.")))] + + [/.Boolean] + [/.Byte] + [/.Short] + [/.Integer] + [/.Long] + [/.Float] + [/.Double] + [/.Character] + ) + +(template [] + [(`` (documentation: + (format "The type of an (unboxed) " (~~ (template.text [])) " value.")))] + + [/.boolean] + [/.byte] + [/.short] + [/.int] + [/.long] + [/.float] + [/.double] + [/.char] + ) + +(template [ ] + [(`` (documentation: + "Type converter." + [(: + ( (: foo)))]))] + + [/.byte_to_long Byte Long] + + [/.short_to_long Short Long] + + [/.double_to_int Double Integer] + [/.double_to_long Double Long] + [/.double_to_float Double Float] + + [/.float_to_int Float Integer] + [/.float_to_long Float Long] + [/.float_to_double Float Double] + + [/.int_to_byte Integer Byte] + [/.int_to_short Integer Short] + [/.int_to_long Integer Long] + [/.int_to_float Integer Float] + [/.int_to_double Integer Double] + [/.int_to_char Integer Character] + + [/.long_to_byte Long Byte] + [/.long_to_short Long Short] + [/.long_to_int Long Integer] + [/.long_to_float Long Float] + [/.long_to_double Long Double] + + [/.char_to_byte Character Byte] + [/.char_to_short Character Short] + [/.char_to_int Character Integer] + [/.char_to_long Character Long] + + [/.long_to_char Long Character] + [/.byte_to_int Byte Integer] + [/.short_to_int Short Integer] + [/.byte_to_char Byte Character] + [/.short_to_char Short Character] + ) + +(documentation: /.class: + "Allows defining JVM classes in Lux code." + [(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."]) + +(documentation: /.interface: + "Allows defining JVM interfaces." + [(interface: TestInterface + ([] foo [boolean String] void #throws [Exception]))]) + +(documentation: /.object + "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) + [])))]) + +(documentation: /.null + "The null pointer." + [(null)]) + +(documentation: /.null? + "Test for the null pointer." + [(= true + (null? (null)))] + [(= false + (null? "YOLO"))]) + +(documentation: /.??? + "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." + [(= (??? (: java/lang/String (null))) + #.None)] + [(= (??? "YOLO") + (#.Some "YOLO"))]) + +(documentation: /.!!! + (format "Takes a (Maybe ObjectType) and returns a ObjectType." + \n "A #.None would get translated into a (null).") + [(= (null) + (!!! (??? (: java/lang/Thread (null)))))] + [(= "foo" + (!!! (??? "foo")))]) + +(documentation: /.check + (format "Checks whether an object is an instance of a particular class." + \n "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes.") + [(case (check String "YOLO") + (#.Some value_as_string) + #.None)]) + +(documentation: /.synchronized + "Evaluates body, while holding a lock on a given object." + [(synchronized object_to_be_locked + (exec + (do something) + (dosomething else) + (finish the computation)))]) + +(documentation: /.do_to + "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))]) + +(documentation: /.import: + "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]) + +(documentation: /.array + "Create an array of the given type, with the given size." + [(array java/lang/Object 10)]) + +(documentation: /.length + "Gives the length of an array." + [(length my_array)]) + +(documentation: /.read! + "Loads an element from an array." + [(read! 10 my_array)]) + +(documentation: /.write! + "Stores an element into an array." + [(write! 10 my_object my_array)]) + +(documentation: /.class_for + "Loads the class as a java.lang.Class object." + [(class_for java/lang/String)]) + +(documentation: /.type + "" + [(: Type + (type java/lang/String))]) + +(documentation: /.:as + "" + [(:as java/lang/Object + (: java/lang/String + ???))]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + "" + [..Boolean + ..Byte + ..Short + ..Integer + ..Long + ..Float + ..Double + ..Character + + ..boolean + ..byte + ..short + ..int + ..long + ..float + ..double + ..char + + ..byte_to_long + ..short_to_long + ..double_to_int + ..double_to_long + ..double_to_float + ..float_to_int + ..float_to_long + ..float_to_double + ..int_to_byte + ..int_to_short + ..int_to_long + ..int_to_float + ..int_to_double + ..int_to_char + ..long_to_byte + ..long_to_short + ..long_to_int + ..long_to_float + ..long_to_double + ..char_to_byte + ..char_to_short + ..char_to_int + ..char_to_long + ..long_to_char + ..byte_to_int + ..short_to_int + ..byte_to_char + ..short_to_char + + ..class: + ..interface: + ..object + ..null + ..null? + ..??? + ..!!! + ..check + ..synchronized + ..do_to + ..import: + ..array + ..length + ..read! + ..write! + ..class_for + ..type + ..:as + ($.default /.Privacy) + ($.default /.State) + ($.default /.Inheritance) + ($.default /.class_names_cannot_contain_periods) + ($.default /.class_name_cannot_be_a_type_variable) + ($.default /.unexpected_type_variable) + ($.default /.cannot_convert_to_jvm_type) + ($.default /.cannot_cast_to_non_object)] + [])) diff --git a/stdlib/source/documentation/lux/ffi.lux b/stdlib/source/documentation/lux/ffi.lux deleted file mode 100644 index a781e10ff..000000000 --- a/stdlib/source/documentation/lux/ffi.lux +++ /dev/null @@ -1,336 +0,0 @@ -(.module: - [library - [lux (#- int char type :as) - ["$" documentation (#+ documentation:)] - [data - ["." text (#+ \n) - ["%" format (#+ format)]]] - [macro - ["." template]]]] - [\\library - ["." /]]) - -(template [] - [(`` (documentation: - (format "The type of a (boxed) " (~~ (template.text [])) " object.")))] - - [/.Boolean] - [/.Byte] - [/.Short] - [/.Integer] - [/.Long] - [/.Float] - [/.Double] - [/.Character] - ) - -(template [] - [(`` (documentation: - (format "The type of an (unboxed) " (~~ (template.text [])) " value.")))] - - [/.boolean] - [/.byte] - [/.short] - [/.int] - [/.long] - [/.float] - [/.double] - [/.char] - ) - -(template [ ] - [(`` (documentation: - "Type converter." - [(: - ( (: foo)))]))] - - [/.byte_to_long Byte Long] - - [/.short_to_long Short Long] - - [/.double_to_int Double Integer] - [/.double_to_long Double Long] - [/.double_to_float Double Float] - - [/.float_to_int Float Integer] - [/.float_to_long Float Long] - [/.float_to_double Float Double] - - [/.int_to_byte Integer Byte] - [/.int_to_short Integer Short] - [/.int_to_long Integer Long] - [/.int_to_float Integer Float] - [/.int_to_double Integer Double] - [/.int_to_char Integer Character] - - [/.long_to_byte Long Byte] - [/.long_to_short Long Short] - [/.long_to_int Long Integer] - [/.long_to_float Long Float] - [/.long_to_double Long Double] - - [/.char_to_byte Character Byte] - [/.char_to_short Character Short] - [/.char_to_int Character Integer] - [/.char_to_long Character Long] - - [/.long_to_char Long Character] - [/.byte_to_int Byte Integer] - [/.short_to_int Short Integer] - [/.byte_to_char Byte Character] - [/.short_to_char Short Character] - ) - -(documentation: /.class: - "Allows defining JVM classes in Lux code." - [(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."]) - -(documentation: /.interface: - "Allows defining JVM interfaces." - [(interface: TestInterface - ([] foo [boolean String] void #throws [Exception]))]) - -(documentation: /.object - "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) - [])))]) - -(documentation: /.null - "The null pointer." - [(null)]) - -(documentation: /.null? - "Test for the null pointer." - [(= true - (null? (null)))] - [(= false - (null? "YOLO"))]) - -(documentation: /.??? - "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." - [(= (??? (: java/lang/String (null))) - #.None)] - [(= (??? "YOLO") - (#.Some "YOLO"))]) - -(documentation: /.!!! - (format "Takes a (Maybe ObjectType) and returns a ObjectType." - \n "A #.None would get translated into a (null).") - [(= (null) - (!!! (??? (: java/lang/Thread (null)))))] - [(= "foo" - (!!! (??? "foo")))]) - -(documentation: /.check - (format "Checks whether an object is an instance of a particular class." - \n "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes.") - [(case (check String "YOLO") - (#.Some value_as_string) - #.None)]) - -(documentation: /.synchronized - "Evaluates body, while holding a lock on a given object." - [(synchronized object_to_be_locked - (exec - (do something) - (dosomething else) - (finish the computation)))]) - -(documentation: /.do_to - "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))]) - -(documentation: /.import: - "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]) - -(documentation: /.array - "Create an array of the given type, with the given size." - [(array java/lang/Object 10)]) - -(documentation: /.length - "Gives the length of an array." - [(length my_array)]) - -(documentation: /.read! - "Loads an element from an array." - [(read! 10 my_array)]) - -(documentation: /.write! - "Stores an element into an array." - [(write! 10 my_object my_array)]) - -(documentation: /.class_for - "Loads the class as a java.lang.Class object." - [(class_for java/lang/String)]) - -(documentation: /.type - "" - [(: Type - (type java/lang/String))]) - -(documentation: /.:as - "" - [(:as java/lang/Object - (: java/lang/String - ???))]) - -(.def: .public documentation - (.List $.Module) - ($.module /._ - "" - [..Boolean - ..Byte - ..Short - ..Integer - ..Long - ..Float - ..Double - ..Character - - ..boolean - ..byte - ..short - ..int - ..long - ..float - ..double - ..char - - ..byte_to_long - ..short_to_long - ..double_to_int - ..double_to_long - ..double_to_float - ..float_to_int - ..float_to_long - ..float_to_double - ..int_to_byte - ..int_to_short - ..int_to_long - ..int_to_float - ..int_to_double - ..int_to_char - ..long_to_byte - ..long_to_short - ..long_to_int - ..long_to_float - ..long_to_double - ..char_to_byte - ..char_to_short - ..char_to_int - ..char_to_long - ..long_to_char - ..byte_to_int - ..short_to_int - ..byte_to_char - ..short_to_char - - ..class: - ..interface: - ..object - ..null - ..null? - ..??? - ..!!! - ..check - ..synchronized - ..do_to - ..import: - ..array - ..length - ..read! - ..write! - ..class_for - ..type - ..:as - ($.default /.Privacy) - ($.default /.State) - ($.default /.Inheritance) - ($.default /.class_names_cannot_contain_periods) - ($.default /.class_name_cannot_be_a_type_variable) - ($.default /.unexpected_type_variable) - ($.default /.cannot_convert_to_jvm_type) - ($.default /.cannot_cast_to_non_object)] - [])) diff --git a/stdlib/source/documentation/lux/ffi.old.lux b/stdlib/source/documentation/lux/ffi.old.lux new file mode 100644 index 000000000..ac2dd546c --- /dev/null +++ b/stdlib/source/documentation/lux/ffi.old.lux @@ -0,0 +1,265 @@ +(.module: + [library + [lux (#- int char type :as) + ["$" documentation (#+ documentation:)] + [data + ["." text (#+ \n) + ["%" format (#+ format)]]] + [macro + ["." template]]]] + [\\library + ["." /]]) + +(template [ ] + [(documentation: + "Type converter." + [(: (primitive ) + ( (: (primitive ) + it)))])] + + [/.byte_to_long "java.lang.Byte" "java.lang.Long"] + + [/.short_to_long "java.lang.Short" "java.lang.Long"] + + [/.double_to_int "java.lang.Double" "java.lang.Integer"] + [/.double_to_long "java.lang.Double" "java.lang.Long"] + [/.double_to_float "java.lang.Double" "java.lang.Float"] + + [/.float_to_int "java.lang.Float" "java.lang.Integer"] + [/.float_to_long "java.lang.Float" "java.lang.Long"] + [/.float_to_double "java.lang.Float" "java.lang.Double"] + + [/.int_to_byte "java.lang.Integer" "java.lang.Byte"] + [/.int_to_short "java.lang.Integer" "java.lang.Short"] + [/.int_to_long "java.lang.Integer" "java.lang.Long"] + [/.int_to_float "java.lang.Integer" "java.lang.Float"] + [/.int_to_double "java.lang.Integer" "java.lang.Double"] + [/.int_to_char "java.lang.Integer" "java.lang.Character"] + + [/.long_to_byte "java.lang.Long" "java.lang.Byte"] + [/.long_to_short "java.lang.Long" "java.lang.Short"] + [/.long_to_int "java.lang.Long" "java.lang.Integer"] + [/.long_to_float "java.lang.Long" "java.lang.Float"] + [/.long_to_double "java.lang.Long" "java.lang.Double"] + + [/.char_to_byte "java.lang.Character" "java.lang.Byte"] + [/.char_to_short "java.lang.Character" "java.lang.Short"] + [/.char_to_int "java.lang.Character" "java.lang.Integer"] + [/.char_to_long "java.lang.Character" "java.lang.Long"] + ) + +(documentation: /.class: + "Allows defining JVM classes in Lux code." + [(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."]) + +(documentation: /.interface: + "Allows defining JVM interfaces." + [(interface: TestInterface + ([] foo [boolean String] void #throws [Exception]))]) + +(documentation: /.object + "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) + [])))]) + +(documentation: /.null + "Null object reference." + (null)) + +(documentation: /.null? + "Test for null object reference." + [(= (null? (null)) + true)] + [(= (null? "YOLO") + false)]) + +(documentation: /.??? + "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." + [(= (??? (: java/lang/String (null))) + #.None)] + [(= (??? "YOLO") + (#.Some "YOLO"))]) + +(documentation: /.!!! + "Takes a (Maybe ObjectType) and returns a ObjectType." + [(= "foo" + (!!! (??? "foo")))] + ["A #.None would get translated into a (null)." + (= (null) + (!!! (??? (: java/lang/Thread (null)))))]) + +(documentation: /.check + (format "Checks whether an object is an instance of a particular class." + \n "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes.") + [(case (check java/lang/String "YOLO") + (#.Some value_as_string) + #.None)]) + +(documentation: /.synchronized + "Evaluates body, while holding a lock on a given object." + [(synchronized object_to_be_locked + (exec + (do something) + (do_something else) + (finish the computation)))]) + +(documentation: /.do_to + "Call a variety of methods on an object. Then, return the object." + [(do_to object + (ClassName::method0 arg0 arg1 arg2) + (ClassName::method1 arg3 arg4 arg5))]) + +(documentation: /.import: + (format "Allows importing JVM classes, and using them as types." + \n "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-parameters." + "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]) + +(documentation: /.array + "Create an array of the given type, with the given size." + [(array java/lang/Object 10)]) + +(documentation: /.length + "Gives the length of an array." + [(length my_array)]) + +(documentation: /.read! + "Loads an element from an array." + [(read! 10 my_array)]) + +(documentation: /.write! + "Stores an element into an array." + [(write! 10 my_object my_array)]) + +(documentation: /.class_for + "Loads the class as a java.lang.Class object." + [(: (primitive "java.lang.Class" ["java.lang.Object"]) + (class_for java/lang/String))]) + +(documentation: /.type + "" + [(: .Type + (type java/lang/String))]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + "" + [..byte_to_long + ..short_to_long + ..double_to_int + ..double_to_long + ..double_to_float + ..float_to_int + ..float_to_long + ..float_to_double + ..int_to_byte + ..int_to_short + ..int_to_long + ..int_to_float + ..int_to_double + ..int_to_char + ..long_to_byte + ..long_to_short + ..long_to_int + ..long_to_float + ..long_to_double + ..char_to_byte + ..char_to_short + ..char_to_int + ..char_to_long + ..class: + ..interface: + ..object + ..null + ..null? + ..??? + ..!!! + ..check + ..synchronized + ..do_to + ..import: + ..array + ..length + ..read! + ..write! + ..class_for + ..type + ($.default /.Privacy) + ($.default /.State) + ($.default /.Inheritance)] + [])) diff --git a/stdlib/source/documentation/lux/ffi.rb.lux b/stdlib/source/documentation/lux/ffi.rb.lux new file mode 100644 index 000000000..9109e9253 --- /dev/null +++ b/stdlib/source/documentation/lux/ffi.rb.lux @@ -0,0 +1,46 @@ +(.module: + [library + [lux (#- int char type :as) + ["$" documentation (#+ documentation:)] + [data + ["." text (#+ \n) + ["%" format (#+ format)]]] + [macro + ["." template]]]] + [\\library + ["." /]]) + +(documentation: /.import: + "Easily import types, methods, functions and constants." + [(import: Stat + ["#::." + (executable? [] Bit) + (size Int)]) + + (import: File #as RubyFile + ["#::." + (#static SEPARATOR ..String) + (#static open [Path ..String] #io #try RubyFile) + (#static stat [Path] #io #try Stat) + (#static delete [Path] #io #try Int) + (#static file? [Path] #io #try Bit) + (#static directory? [Path] #io #try Bit) + + (read [] #io #try Binary) + (write [Binary] #io #try Int) + (flush [] #io #try #? Any) + (close [] #io #try #? Any)])]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + "" + [..import: + ($.default /.Object) + ($.default /.Nil) + ($.default /.Function) + ($.default /.Function) + ($.default /.Integer) + ($.default /.Float) + ($.default /.String)] + [])) diff --git a/stdlib/source/documentation/lux/type/abstract.lux b/stdlib/source/documentation/lux/type/abstract.lux index 8b1bf10ca..e77660aa0 100644 --- a/stdlib/source/documentation/lux/type/abstract.lux +++ b/stdlib/source/documentation/lux/type/abstract.lux @@ -55,7 +55,7 @@ [a a] (def: (duplicate value) - (All [a] (-> a (Duplicate a))) + (All (_ a) (-> a (Duplicate a))) (:abstraction [value value])))] ["Definitions can be nested." (abstract: (Single a) @@ -64,7 +64,7 @@ a (def: (single value) - (All [a] (-> a (Single a))) + (All (_ a) (-> a (Single a))) (:abstraction value)) (abstract: (Double a) @@ -73,11 +73,11 @@ [a a] (def: (double value) - (All [a] (-> a (Double a))) + (All (_ a) (-> a (Double a))) (:abstraction [value value])) (def: (single' value) - (All [a] (-> a (Single a))) + (All (_ a) (-> a (Single a))) (:abstraction Single [value value])) (let [value 0123] @@ -130,7 +130,7 @@ (documentation: /.^:representation "Pattern-matching macro to easily extract a representation." [(def: (computation abstraction) - (All [a] (-> (Abstract a) ???)) + (All (_ a) (-> (Abstract a) ???)) (let [(^:representation value) abstraction] (foo (bar (baz value)))))]) -- cgit v1.2.3