diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux.lux | 12 | ||||
-rw-r--r-- | stdlib/source/lux/host.jvm.lux | 387 | ||||
-rw-r--r-- | stdlib/source/lux/type/opaque.lux | 6 | ||||
-rw-r--r-- | stdlib/source/lux/type/unit.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/world/blob.jvm.lux | 46 | ||||
-rw-r--r-- | stdlib/source/lux/world/console.lux | 32 | ||||
-rw-r--r-- | stdlib/source/lux/world/env.jvm.lux | 33 | ||||
-rw-r--r-- | stdlib/source/lux/world/file.lux | 74 | ||||
-rw-r--r-- | stdlib/source/lux/world/net/tcp.jvm.lux | 40 | ||||
-rw-r--r-- | stdlib/source/lux/world/net/udp.jvm.lux | 32 | ||||
-rw-r--r-- | stdlib/test/test/lux/host.jvm.lux | 29 | ||||
-rw-r--r-- | stdlib/test/test/lux/world/blob.lux | 28 |
12 files changed, 350 insertions, 373 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 65167b8e6..6470e5c3b 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1965,17 +1965,11 @@ (macro:' #export (primitive tokens) (list [(tag$ ["lux" "doc"]) (text$ "## Macro to treat define new primitive types. - (primitive java.lang.Object) + (primitive \"java.lang.Object\") - (primitive java.util.List [java.lang.Long])")]) + (primitive \"java.util.List\" [(primitive \"java.lang.Long\")])")]) ("lux case" tokens - {(#Cons [_ (#Symbol "" class-name)] #Nil) - (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (tag$ ["lux" "Nil"]))))) - - (#Cons [_ (#Symbol "" class-name)] (#Cons [_ (#Tuple params)] #Nil)) - (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (untemplate-list params))))) - - (#Cons [_ (#Text class-name)] #Nil) + {(#Cons [_ (#Text class-name)] #Nil) (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (tag$ ["lux" "Nil"]))))) (#Cons [_ (#Text class-name)] (#Cons [_ (#Tuple params)] #Nil)) diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index 76f54d67f..200ae1ec3 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -27,41 +27,41 @@ (-> (primitive <from>) (primitive <to>)) (<op> value))] - [b2l "jvm b2l" java.lang.Byte java.lang.Long] + [b2l "jvm b2l" "java.lang.Byte" "java.lang.Long"] - [s2l "jvm s2l" java.lang.Short java.lang.Long] + [s2l "jvm s2l" "java.lang.Short" "java.lang.Long"] - [d2i "jvm d2i" java.lang.Double java.lang.Integer] - [d2l "jvm d2l" java.lang.Double java.lang.Long] - [d2f "jvm d2f" java.lang.Double java.lang.Float] + [d2i "jvm d2i" "java.lang.Double" "java.lang.Integer"] + [d2l "jvm d2l" "java.lang.Double" "java.lang.Long"] + [d2f "jvm d2f" "java.lang.Double" "java.lang.Float"] - [f2i "jvm f2i" java.lang.Float java.lang.Integer] - [f2l "jvm f2l" java.lang.Float java.lang.Long] - [f2d "jvm f2d" java.lang.Float java.lang.Double] + [f2i "jvm f2i" "java.lang.Float" "java.lang.Integer"] + [f2l "jvm f2l" "java.lang.Float" "java.lang.Long"] + [f2d "jvm f2d" "java.lang.Float" "java.lang.Double"] - [i2b "jvm i2b" java.lang.Integer java.lang.Byte] - [i2s "jvm i2s" java.lang.Integer java.lang.Short] - [i2l "jvm i2l" java.lang.Integer java.lang.Long] - [i2f "jvm i2f" java.lang.Integer java.lang.Float] - [i2d "jvm i2d" java.lang.Integer java.lang.Double] - [i2c "jvm i2c" java.lang.Integer java.lang.Character] - - [l2b "jvm l2b" java.lang.Long java.lang.Byte] - [l2s "jvm l2s" java.lang.Long java.lang.Short] - [l2i "jvm l2i" java.lang.Long java.lang.Integer] - [l2f "jvm l2f" java.lang.Long java.lang.Float] - [l2d "jvm l2d" java.lang.Long java.lang.Double] - - [c2b "jvm c2b" java.lang.Character java.lang.Byte] - [c2s "jvm c2s" java.lang.Character java.lang.Short] - [c2i "jvm c2i" java.lang.Character java.lang.Integer] - [c2l "jvm c2l" java.lang.Character java.lang.Long] + [i2b "jvm i2b" "java.lang.Integer" "java.lang.Byte"] + [i2s "jvm i2s" "java.lang.Integer" "java.lang.Short"] + [i2l "jvm i2l" "java.lang.Integer" "java.lang.Long"] + [i2f "jvm i2f" "java.lang.Integer" "java.lang.Float"] + [i2d "jvm i2d" "java.lang.Integer" "java.lang.Double"] + [i2c "jvm i2c" "java.lang.Integer" "java.lang.Character"] + + [l2b "jvm l2b" "java.lang.Long" "java.lang.Byte"] + [l2s "jvm l2s" "java.lang.Long" "java.lang.Short"] + [l2i "jvm l2i" "java.lang.Long" "java.lang.Integer"] + [l2f "jvm l2f" "java.lang.Long" "java.lang.Float"] + [l2d "jvm l2d" "java.lang.Long" "java.lang.Double"] + + [c2b "jvm c2b" "java.lang.Character" "java.lang.Byte"] + [c2s "jvm c2s" "java.lang.Character" "java.lang.Short"] + [c2i "jvm c2i" "java.lang.Character" "java.lang.Integer"] + [c2l "jvm c2l" "java.lang.Character" "java.lang.Long"] ) ## [Utils] (def: array-type-name "#Array") (def: constructor-method-name "<init>") -(def: member-separator ".") +(def: member-separator "::") ## Types (type: JVM-Code Text) @@ -107,10 +107,10 @@ {#class-name Text #class-params (List TypeParam)}) -(type: StackFrame (primitive java.lang.StackTraceElement)) +(type: StackFrame (primitive "java/lang/StackTraceElement")) (type: StackTrace (Array StackFrame)) -(type: SuperClassDecl +(type: Super-Class-Decl {#super-class-name Text #super-class-params (List GenericType)}) @@ -179,7 +179,7 @@ GenericType (List GenericType)])) -(type: PartialCall +(type: Partial-Call {#pc-method Code #pc-args Code}) @@ -218,13 +218,13 @@ (#MethodDecl [ImportMethodCommons ImportMethodDecl]) (#FieldAccessDecl ImportFieldDecl)) -(type: ClassImports +(type: Class-Imports (List [Text Text])) ## Utils (def: (short-class-name name) (-> Text Text) - (case (list;reverse (text;split-all-with "." name)) + (case (list;reverse (text;split-all-with "/" name)) (#;Cons short-name _) short-name @@ -237,14 +237,14 @@ (^template [<prim> <type>] <prim> (#;Some (' <type>))) - (["boolean" (;^ java.lang.Boolean)] - ["byte" (;^ java.lang.Byte)] - ["short" (;^ java.lang.Short)] - ["int" (;^ java.lang.Integer)] - ["long" (;^ java.lang.Long)] - ["float" (;^ java.lang.Float)] - ["double" (;^ java.lang.Double)] - ["char" (;^ java.lang.Character)] + (["boolean" (primitive "java.lang.Boolean")] + ["byte" (primitive "java.lang.Byte")] + ["short" (primitive "java.lang.Short")] + ["int" (primitive "java.lang.Integer")] + ["long" (primitive "java.lang.Long")] + ["float" (primitive "java.lang.Float")] + ["double" (primitive "java.lang.Double")] + ["char" (primitive "java.lang.Character")] ["void" ;Unit]) _ @@ -268,6 +268,10 @@ _ #;None)) +(def: sanitize + (-> Text Text) + (text;replace-all "/" ".")) + (def: (generic-class->type' mode type-params in-array? name+params class->type') (-> Primitive-Mode (List TypeParam) Bool [Text (List GenericType)] @@ -283,8 +287,9 @@ output [[name params] _ _] - (let [=params (list/map (class->type' mode type-params in-array?) params)] - (` (primitive (~ (code;symbol ["" name])) [(~@ =params)]))))) + (let [name (sanitize name) + =params (list/map (class->type' mode type-params in-array?) params)] + (` (primitive (~ (code;text name)) [(~@ =params)]))))) (def: (class->type' mode type-params in-array? class) (-> Primitive-Mode (List TypeParam) Bool GenericType Code) @@ -334,30 +339,31 @@ (#;Cons bound1 _) (class->type #ManualPrM class-params bound1)))) class-params)] - (` (primitive (~ (code;symbol ["" class-name])) [(~@ =params)])))) + (` (primitive (~ (code;text (sanitize class-name))) + [(~@ =params)])))) (def: empty-imports - ClassImports + Class-Imports (list)) (def: (get-import name imports) - (-> Text ClassImports (Maybe Text)) + (-> Text Class-Imports (Maybe Text)) (:: maybe;Functor<Maybe> map product;right (list;find (|>> product;left (text/= name)) imports))) (def: (add-import short+full imports) - (-> [Text Text] ClassImports ClassImports) + (-> [Text Text] Class-Imports Class-Imports) (#;Cons short+full imports)) (def: (class-imports compiler) - (-> Compiler ClassImports) + (-> Compiler Class-Imports) (case (macro;run compiler - (: (Meta ClassImports) + (: (Meta Class-Imports) (do Monad<Meta> [current-module macro;current-module-name defs (macro;defs current-module)] - (wrap (list/fold (: (-> [Text Def] ClassImports ClassImports) + (wrap (list/fold (: (-> [Text Def] Class-Imports Class-Imports) (function [[short-name [_ meta _]] imports] (case (macro;get-text-ann (ident-for #;;jvm-class) meta) (#;Some full-class-name) @@ -370,7 +376,7 @@ (#;Left _) (list) (#;Right imports) imports)) -(def: java.lang-classes +(def: java/lang/* (List Text) (list ## Interfaces "Appendable" @@ -453,50 +459,41 @@ "SafeVarargs" "SuppressWarnings")) -(def: (fully-qualified-class-name? name) - (-> Text Bool) - (text;contains? "." name)) - -(def: (fully-qualify-class-name imports name) - (-> ClassImports Text Text) - (cond (fully-qualified-class-name? name) - name - - (list;member? text;Eq<Text> java.lang-classes name) - (format "java.lang." name) - - ## else - (maybe;default name (get-import name imports)))) +(def: (qualify imports name) + (-> Class-Imports Text Text) + (if (list;member? text;Eq<Text> java/lang/* name) + (format "java/lang/" name) + (maybe;default name (get-import name imports)))) (def: type-var-class Text "java.lang.Object") -(def: (simple-class$ params class) +(def: (simple-class$ env class) (-> (List TypeParam) GenericType Text) (case class (#GenericTypeVar name) (case (list;find (function [[pname pbounds]] (and (text/= name pname) (not (list;empty? pbounds)))) - params) + env) #;None type-var-class (#;Some [pname pbounds]) - (simple-class$ params (maybe;assume (list;head pbounds)))) + (simple-class$ env (maybe;assume (list;head pbounds)))) (^or (#GenericWildcard #;None) (#GenericWildcard (#;Some [#LowerBound _]))) type-var-class (#GenericWildcard (#;Some [#UpperBound upper-bound])) - (simple-class$ params upper-bound) + (simple-class$ env upper-bound) - (#GenericClass name params) - name + (#GenericClass name env) + (sanitize name) (#GenericArray param') (case param' (#GenericArray param) - (format "[" (simple-class$ params param)) + (format "[" (simple-class$ env param)) (^template [<prim> <class>] (#GenericClass <prim> #;Nil) @@ -511,27 +508,27 @@ ["char" "[C"]) param - (format "[L" (simple-class$ params param) ";")) + (format "[L" (simple-class$ env param) ";")) )) (def: (make-get-const-parser class-name field-name) (-> Text Text (Syntax Code)) (do p;Monad<Parser> - [#let [dotted-name (format "." field-name)] + [#let [dotted-name (format "::" field-name)] _ (s;this (code;symbol ["" dotted-name]))] (wrap (`' ((~ (code;text (format "jvm getstatic" ":" class-name ":" field-name)))))))) (def: (make-get-var-parser class-name field-name) (-> Text Text (Syntax Code)) (do p;Monad<Parser> - [#let [dotted-name (format "." field-name)] + [#let [dotted-name (format "::" field-name)] _ (s;this (code;symbol ["" dotted-name]))] (wrap (`' ((~ (code;text (format "jvm getfield" ":" class-name ":" field-name))) _jvm_this))))) (def: (make-put-var-parser class-name field-name) (-> Text Text (Syntax Code)) (do p;Monad<Parser> - [#let [dotted-name (format "." field-name)] + [#let [dotted-name (format "::" field-name)] [_ _ value] (: (Syntax [Unit Unit Code]) (s;form ($_ p;seq (s;this (' :=)) (s;this (code;symbol ["" dotted-name])) s;any)))] (wrap (`' ((~ (code;text (format "jvm putfield" ":" class-name ":" field-name))) _jvm_this (~ value)))))) @@ -578,7 +575,7 @@ (-> (List TypeParam) Text (List ArgDecl) (Syntax Code)) (do p;Monad<Parser> [[_ args] (: (Syntax [Unit (List Code)]) - (s;form ($_ p;seq (s;this (' .new!)) (s;tuple (p;exactly (list;size arg-decls) s;any))))) + (s;form ($_ p;seq (s;this (' ::new!)) (s;tuple (p;exactly (list;size arg-decls) s;any))))) #let [arg-decls' (: (List Text) (list/map (. (simple-class$ params) product;right) arg-decls))]] (wrap (` ((~ (code;text (format "jvm new" ":" class-name ":" (text;join-with "," arg-decls')))) (~@ args)))))) @@ -586,7 +583,7 @@ (def: (make-static-method-parser params class-name method-name arg-decls) (-> (List TypeParam) Text Text (List ArgDecl) (Syntax Code)) (do p;Monad<Parser> - [#let [dotted-name (format "." method-name "!")] + [#let [dotted-name (format "::" method-name "!")] [_ args] (: (Syntax [Unit (List Code)]) (s;form ($_ p;seq (s;this (code;symbol ["" dotted-name])) (s;tuple (p;exactly (list;size arg-decls) s;any))))) #let [arg-decls' (: (List Text) (list/map (. (simple-class$ params) product;right) arg-decls))]] @@ -597,7 +594,7 @@ [(def: (<name> params class-name method-name arg-decls) (-> (List TypeParam) Text Text (List ArgDecl) (Syntax Code)) (do p;Monad<Parser> - [#let [dotted-name (format "." method-name "!")] + [#let [dotted-name (format "::" method-name "!")] [_ args] (: (Syntax [Unit (List Code)]) (s;form ($_ p;seq (s;this (code;symbol ["" dotted-name])) (s;tuple (p;exactly (list;size arg-decls) s;any))))) #let [arg-decls' (: (List Text) (list/map (. (simple-class$ params) product;right) arg-decls))]] @@ -628,10 +625,10 @@ ## Syntaxs (def: (full-class-name^ imports) - (-> ClassImports (Syntax Text)) + (-> Class-Imports (Syntax Text)) (do p;Monad<Parser> [name s;local-symbol] - (wrap (fully-qualify-class-name imports name)))) + (wrap (qualify imports name)))) (def: privacy-modifier^ (Syntax PrivacyModifier) @@ -655,8 +652,13 @@ (p;alt (s;this (' <)) (s;this (' >)))) +(def: (assert-no-periods name) + (-> Text (Syntax Unit)) + (p;assert "Names in class declarations cannot contain periods." + (not (text;contains? "." name)))) + (def: (generic-type^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax GenericType)) + (-> Class-Imports (List TypeParam) (Syntax GenericType)) ($_ p;either (do p;Monad<Parser> [_ (s;this (' ?))] @@ -667,7 +669,8 @@ bound (generic-type^ imports type-vars)] (wrap (#GenericWildcard (#;Some [bound-kind bound]))))) (do p;Monad<Parser> - [name (full-class-name^ imports)] + [name (full-class-name^ imports) + _ (assert-no-periods name)] (if (list;member? text;Eq<Text> (list/map product;left type-vars) name) (wrap (#GenericTypeVar name)) (wrap (#GenericClass name (list))))) @@ -691,6 +694,7 @@ (wrap (#GenericArray component))))) (s;form (do p;Monad<Parser> [name (full-class-name^ imports) + _ (assert-no-periods name) params (p;some (generic-type^ imports type-vars)) _ (p;assert (format name " cannot be a type-parameter!") (not (list;member? text;Eq<Text> (list/map product;left type-vars) name)))] @@ -698,7 +702,7 @@ )) (def: (type-param^ imports) - (-> ClassImports (Syntax TypeParam)) + (-> Class-Imports (Syntax TypeParam)) (p;either (do p;Monad<Parser> [param-name s;local-symbol] (wrap [param-name (list)])) @@ -709,27 +713,31 @@ (wrap [param-name bounds]))))) (def: (type-params^ imports) - (-> ClassImports (Syntax (List TypeParam))) + (-> Class-Imports (Syntax (List TypeParam))) (s;tuple (p;some (type-param^ imports)))) (def: (class-decl^ imports) - (-> ClassImports (Syntax ClassDecl)) + (-> Class-Imports (Syntax ClassDecl)) (p;either (do p;Monad<Parser> - [name (full-class-name^ imports)] + [name (full-class-name^ imports) + _ (assert-no-periods name)] (wrap [name (list)])) (s;form (do p;Monad<Parser> [name (full-class-name^ imports) + _ (assert-no-periods name) params (p;some (type-param^ imports))] (wrap [name params]))) )) (def: (super-class-decl^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax SuperClassDecl)) + (-> Class-Imports (List TypeParam) (Syntax Super-Class-Decl)) (p;either (do p;Monad<Parser> - [name (full-class-name^ imports)] + [name (full-class-name^ imports) + _ (assert-no-periods name)] (wrap [name (list)])) (s;form (do p;Monad<Parser> [name (full-class-name^ imports) + _ (assert-no-periods name) params (p;some (generic-type^ imports type-vars))] (wrap [name params]))))) @@ -738,7 +746,7 @@ (s;record (p;some (p;seq s;local-tag s;any)))) (def: (annotation^ imports) - (-> ClassImports (Syntax Annotation)) + (-> Class-Imports (Syntax Annotation)) (p;either (do p;Monad<Parser> [ann-name (full-class-name^ imports)] (wrap [ann-name (list)])) @@ -746,31 +754,31 @@ annotation-params^)))) (def: (annotations^' imports) - (-> ClassImports (Syntax (List Annotation))) + (-> Class-Imports (Syntax (List Annotation))) (do p;Monad<Parser> [_ (s;this (' #ann))] (s;tuple (p;some (annotation^ imports))))) (def: (annotations^ imports) - (-> ClassImports (Syntax (List Annotation))) + (-> Class-Imports (Syntax (List Annotation))) (do p;Monad<Parser> [anns?? (p;maybe (annotations^' imports))] (wrap (maybe;default (list) anns??)))) (def: (throws-decl'^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax (List GenericType))) + (-> Class-Imports (List TypeParam) (Syntax (List GenericType))) (do p;Monad<Parser> [_ (s;this (' #throws))] (s;tuple (p;some (generic-type^ imports type-vars))))) (def: (throws-decl^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax (List GenericType))) + (-> Class-Imports (List TypeParam) (Syntax (List GenericType))) (do p;Monad<Parser> [exs? (p;maybe (throws-decl'^ imports type-vars))] (wrap (maybe;default (list) exs?)))) (def: (method-decl^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax [MemberDecl MethodDecl])) + (-> Class-Imports (List TypeParam) (Syntax [MemberDecl MethodDecl])) (s;form (do p;Monad<Parser> [tvars (p;default (list) (type-params^ imports)) name s;local-symbol @@ -791,7 +799,7 @@ (:: p;Monad<Parser> wrap []))) (def: (field-decl^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax [MemberDecl FieldDecl])) + (-> Class-Imports (List TypeParam) (Syntax [MemberDecl FieldDecl])) (p;either (s;form (do p;Monad<Parser> [_ (s;this (' #const)) name s;local-symbol @@ -808,24 +816,24 @@ (wrap [[name pm anns] (#VariableField [sm type])]))))) (def: (arg-decl^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax ArgDecl)) + (-> Class-Imports (List TypeParam) (Syntax ArgDecl)) (s;tuple (p;seq s;local-symbol (generic-type^ imports type-vars)))) (def: (arg-decls^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax (List ArgDecl))) + (-> Class-Imports (List TypeParam) (Syntax (List ArgDecl))) (p;some (arg-decl^ imports type-vars))) (def: (constructor-arg^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax ConstructorArg)) + (-> Class-Imports (List TypeParam) (Syntax ConstructorArg)) (s;tuple (p;seq (generic-type^ imports type-vars) s;any))) (def: (constructor-args^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax (List ConstructorArg))) + (-> Class-Imports (List TypeParam) (Syntax (List ConstructorArg))) (s;tuple (p;some (constructor-arg^ imports type-vars)))) (def: (constructor-method^ imports class-vars) - (-> ClassImports (List TypeParam) (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (List TypeParam) (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [pm privacy-modifier^ strict-fp? (s;this? (' #strict)) @@ -843,7 +851,7 @@ (#ConstructorMethod strict-fp? method-vars arg-decls constructor-args body exs)])))) (def: (virtual-method-def^ imports class-vars) - (-> ClassImports (List TypeParam) (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (List TypeParam) (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [pm privacy-modifier^ strict-fp? (s;this? (' #strict)) @@ -862,7 +870,7 @@ (#VirtualMethod final? strict-fp? method-vars arg-decls return-type body exs)])))) (def: (overriden-method-def^ imports) - (-> ClassImports (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [strict-fp? (s;this? (' #strict)) owner-class (class-decl^ imports) @@ -880,7 +888,7 @@ (#OverridenMethod strict-fp? owner-class method-vars arg-decls return-type body exs)])))) (def: (static-method-def^ imports) - (-> ClassImports (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [pm privacy-modifier^ strict-fp? (s;this? (' #strict)) @@ -899,7 +907,7 @@ (#StaticMethod strict-fp? method-vars arg-decls return-type body exs)])))) (def: (abstract-method-def^ imports) - (-> ClassImports (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [pm privacy-modifier^ _ (s;this (' #abstract)) @@ -916,7 +924,7 @@ (#AbstractMethod method-vars arg-decls return-type exs)])))) (def: (native-method-def^ imports) - (-> ClassImports (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (Syntax [MemberDecl MethodDef])) (s;form (do p;Monad<Parser> [pm privacy-modifier^ _ (s;this (' #native)) @@ -933,7 +941,7 @@ (#NativeMethod method-vars arg-decls return-type exs)])))) (def: (method-def^ imports class-vars) - (-> ClassImports (List TypeParam) (Syntax [MemberDecl MethodDef])) + (-> Class-Imports (List TypeParam) (Syntax [MemberDecl MethodDef])) ($_ p;either (constructor-method^ imports class-vars) (virtual-method-def^ imports class-vars) @@ -943,7 +951,7 @@ (native-method-def^ imports))) (def: partial-call^ - (Syntax PartialCall) + (Syntax Partial-Call) (s;form (p;seq s;any s;any))) (def: class-kind^ @@ -963,7 +971,7 @@ s;local-symbol))) (def: (import-member-args^ imports type-vars) - (-> ClassImports (List TypeParam) (Syntax (List [Bool GenericType]))) + (-> Class-Imports (List TypeParam) (Syntax (List [Bool GenericType]))) (s;tuple (p;some (p;seq (s;this? (' #?)) (generic-type^ imports type-vars))))) (def: import-member-return-flags^ @@ -976,7 +984,7 @@ (s;this (' #auto)))) (def: (import-member-decl^ imports owner-vars) - (-> ClassImports (List TypeParam) (Syntax ImportMemberDecl)) + (-> Class-Imports (List TypeParam) (Syntax ImportMemberDecl)) ($_ p;either (s;form (do p;Monad<Parser> [_ (s;this (' #enum)) @@ -1087,7 +1095,7 @@ name (#GenericClass name params) - (format "(" name " " (spaced (list/map generic-type$ params)) ")") + (format "(" (sanitize name) " " (spaced (list/map generic-type$ params)) ")") (#GenericArray param) (format "(" array-type-name " " (generic-type$ param) ")") @@ -1104,11 +1112,11 @@ (def: (class-decl$ (^open)) (-> ClassDecl JVM-Code) - (format "(" class-name " " (spaced (list/map type-param$ class-params)) ")")) + (format "(" (sanitize class-name) " " (spaced (list/map type-param$ class-params)) ")")) (def: (super-class-decl$ (^slots [#super-class-name #super-class-params])) - (-> SuperClassDecl JVM-Code) - (format "(" super-class-name " " (spaced (list/map generic-type$ super-class-params)) ")")) + (-> Super-Class-Decl JVM-Code) + (format "(" (sanitize super-class-name) " " (spaced (list/map generic-type$ super-class-params)) ")")) (def: (method-decl$ [[name pm anns] method-decl]) (-> [MemberDecl MethodDecl] JVM-Code) @@ -1161,7 +1169,7 @@ (spaced (list (generic-type$ class) (code;to-text term))))) (def: (method-def$ replacer super-class [[name pm anns] method-def]) - (-> (-> Code Code) SuperClassDecl [MemberDecl MethodDef] JVM-Code) + (-> (-> Code Code) Super-Class-Decl [MemberDecl MethodDef] JVM-Code) (case method-def (#ConstructorMethod strict-fp? type-vars arg-decls constructor-args body exs) (with-parens @@ -1192,7 +1200,7 @@ (#OverridenMethod strict-fp? class-decl type-vars arg-decls return-type body exs) (let [super-replacer (parser->replacer (s;form (do p;Monad<Parser> - [_ (s;this (' .super!)) + [_ (s;this (' ::super!)) args (s;tuple (p;exactly (list;size arg-decls) s;any)) #let [arg-decls' (: (List Text) (list/map (. (simple-class$ (list)) product;right) arg-decls))]] @@ -1251,13 +1259,13 @@ )) (def: (complete-call$ obj [method args]) - (-> Code PartialCall Code) + (-> Code Partial-Call Code) (` ((~ method) (~ args) (~ obj)))) ## [Syntax] (def: object-super-class - SuperClassDecl - {#super-class-name "java.lang.Object" + Super-Class-Decl + {#super-class-name "java/lang/Object" #super-class-params (list)}) (syntax: #export (class: [#let [imports (class-imports *compiler*)]] @@ -1280,16 +1288,16 @@ ## Fields (#private foo boolean) (#private bar A) - (#private baz java.lang.Object) + (#private baz java/lang/Object) ## Methods (#public [] (new [value A]) [] - (exec (:= .foo true) - (:= .bar value) - (:= .baz "") + (exec (:= ::foo true) + (:= ::bar value) + (:= ::baz "") [])) - (#public (virtual) java.lang.Object + (#public (virtual) java/lang/Object "") - (#public #static (static) java.lang.Object + (#public #static (static) java/lang/Object "") (Runnable [] (run) void []) @@ -1299,14 +1307,14 @@ "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 true) for modifying it." - "(.new! []) for calling the class's constructor." - "(.resolve! container [value]) for calling the \"resolve\" method." + "::resolved, for accessing the \"resolved\" field." + "(:= ::resolved true) for modifying it." + "(::new! []) for calling the class's constructor." + "(::resolve! container [value]) for calling the \"resolve\" method." )} (do Monad<Meta> [current-module macro;current-module-name - #let [fully-qualified-class-name (format (text;replace-all "/" "." current-module) "." full-class-name) + #let [fully-qualified-class-name (format (sanitize current-module) "." full-class-name) field-parsers (list/map (field->parser fully-qualified-class-name) fields) method-parsers (list/map (method->parser (product;right class-decl) fully-qualified-class-name) methods) replacer (parser->replacer (list/fold p;either @@ -1381,12 +1389,12 @@ (null? "YOLO") "=>" false)} - (-> (primitive java.lang.Object) Bool) + (-> (primitive "java.lang.Object") Bool) ("jvm null?" obj)) (syntax: #export (??? expr) {#;doc (doc "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." - (??? (: java.lang.String (null))) + (??? (: java/lang/String (null))) "=>" #;None (??? "YOLO") @@ -1401,7 +1409,7 @@ (syntax: #export (!!! expr) {#;doc (doc "Takes a (Maybe ObjectType) and returns a ObjectType." "A #;None would get translated into a (null)." - (!!! (??? (: java.lang.Thread (null)))) + (!!! (??? (: java/lang/Thread (null)))) "=>" (null) (!!! (??? "YOLO")) @@ -1436,7 +1444,7 @@ #;None (do @ [g!obj (macro;gensym "obj")] - (wrap (list (` (: (-> (primitive (~' java.lang.Object)) Bool) + (wrap (list (` (: (-> (primitive "java.lang.Object") Bool) (function [(~ g!obj)] ((~ (code;text (format "jvm instanceof" ":" (simple-class$ (list) class)))) (~ g!obj)))))))) )) @@ -1444,16 +1452,16 @@ (syntax: #export (synchronized lock body) {#;doc (doc "Evaluates body, while holding a lock on a given object." (synchronized object-to-be-locked - (exec (do-something ...) - (do-something-else ...) - (finish-the-computation ...))))} + (exec (do-something ___) + (do-something-else ___) + (finish-the-computation ___))))} (wrap (list (` ("jvm synchronized" (~ lock) (~ body)))))) (syntax: #export (do-to obj [methods (p;some partial-call^)]) {#;doc (doc "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])))} + (ClassName::method1 [arg0 arg1 arg2]) + (ClassName::method2 [arg3 arg4 arg5])))} (with-gensyms [g!obj] (wrap (list (` (let [(~ g!obj) (~ obj)] (exec (~@ (list/map (complete-call$ g!obj) methods)) @@ -1463,24 +1471,15 @@ (-> Bool ClassDecl Code) (let [def-name (if long-name? full-name - (short-class-name full-name))] - (case params - #;Nil - (` (def: (~ (code;symbol ["" def-name])) - {#;type? true - #;;jvm-class (~ (code;text full-name))} - Type - (primitive (~ (code;symbol ["" full-name]))))) - - (#;Cons _) - (let [params' (list/map (function [[p _]] (code;symbol ["" p])) params)] - (` (def: (~ (code;symbol ["" def-name])) - {#;type? true - #;;jvm-class (~ (code;text full-name))} - Type - (All [(~@ params')] - (primitive (~ (code;symbol ["" full-name])) - [(~@ params')])))))))) + (short-class-name full-name)) + params' (list/map (|>> product;left code;local-symbol) params)] + (` (def: (~ (code;symbol ["" def-name])) + {#;type? true + #;;jvm-class (~ (code;text full-name))} + Type + (All [(~@ params')] + (primitive (~ (code;text (sanitize full-name))) + [(~@ params')])))))) (def: (member-type-vars class-tvars member) (-> (List TypeParam) ImportMemberDecl (List TypeParam)) @@ -1514,7 +1513,7 @@ arg-name)])))) import-member-args) #let [arg-classes (: (List Text) - (list/map (. (simple-class$ (list/compose type-params import-member-tvars)) product;right) + (list/map (|>> product;right (simple-class$ (list/compose type-params import-member-tvars))) import-member-args)) arg-types (list/map (: (-> [Bool GenericType] Code) (function [[maybe? arg]] @@ -1552,7 +1551,7 @@ [return-type (let [g!temp (code;symbol ["" "Ω"])] (` (let [(~ g!temp) (~ return-term)] - (if (not (null? (:! (primitive (~' java.lang.Object)) + (if (not (null? (:! (primitive "java.lang.Object") (~ g!temp)))) (~ g!temp) (error! "Cannot produce null references from method calls.")))))]) @@ -1670,6 +1669,7 @@ (def: (member-def-interop type-params kind class [arg-function-inputs arg-method-inputs arg-classes arg-types] member method-prefix) (-> (List TypeParam) ClassKind ClassDecl [(List Code) (List Code) (List Text) (List Code)] ImportMemberDecl Text (Meta (List Code))) (let [[full-name class-tvars] class + full-name (sanitize full-name) all-params (|> (member-type-vars class-tvars member) (list;filter free-type-param?) (list/map type-param->type-arg))] @@ -1679,13 +1679,13 @@ [#let [enum-type (: Code (case class-tvars #;Nil - (` (primitive (~ (code;symbol ["" full-name])))) + (` (primitive (~ (code;text full-name)))) _ (let [=class-tvars (|> class-tvars (list;filter free-type-param?) (list/map type-param->type-arg))] - (` (All [(~@ =class-tvars)] (primitive (~ (code;symbol ["" full-name])) [(~@ =class-tvars)])))))) + (` (All [(~@ =class-tvars)] (primitive (~ (code;text full-name)) [(~@ =class-tvars)])))))) getter-interop (: (-> Text Code) (function [name] (let [getter-name (code;symbol ["" (format method-prefix member-separator name)])] @@ -1826,23 +1826,24 @@ (member-def-interop type-params kind class =args member method-prefix)))) (def: (interface? class) - (All [a] (-> (primitive java.lang.Class [a]) Bool)) + (All [a] (-> (primitive "java.lang.Class" [a]) Bool)) ("jvm invokevirtual:java.lang.Class:isInterface:" class)) (def: (load-class class-name) - (-> Text (Either Text (primitive java.lang.Class [(Ex [a] a)]))) + (-> Text (Either Text (primitive "java.lang.Class" [(Ex [a] a)]))) (try ("jvm invokestatic:java.lang.Class:forName:java.lang.String" class-name))) (def: (class-kind [class-name _]) (-> ClassDecl (Meta ClassKind)) - (case (load-class class-name) - (#;Right class) - (:: Monad<Meta> wrap (if (interface? class) - #Interface - #Class)) + (let [class-name (sanitize class-name)] + (case (load-class class-name) + (#;Right class) + (:: Monad<Meta> wrap (if (interface? class) + #Interface + #Class)) - (#;Left _) - (macro;fail (format "Unknown class: " class-name)))) + (#;Left _) + (macro;fail (format "Unknown class: " class-name))))) (syntax: #export (import [#let [imports (class-imports *compiler*)]] [long-name? (s;this? (' #long))] @@ -1855,7 +1856,7 @@ "Their methods, fields and enum options can also be imported." "Also, classes which get imported into a module can also be referred-to with their short names in other macros that require JVM classes." "Examples:" - (import java.lang.Object + (import java/lang/Object (new []) (equals [Object] boolean) (wait [int] #io #try void)) @@ -1864,38 +1865,38 @@ "#try means that the computation might throw an exception, and the return value will be wrapped by the Error 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 + (import java/lang/String (new [(Array byte)]) (#static valueOf [char] String) (#static valueOf #as int-valueOf [int] String)) - (import #long (java.util.List e) + (import #long (java/util/List e) (size [] int) (get [int] e)) - (import (java.util.ArrayList a) + (import (java/util/ArrayList a) ([T] toArray [(Array T)] (Array T))) "#long makes it so the class-type that is generated is of the fully-qualified name." "In this case, it avoids a clash between the java.util.List type, and Lux's own List type." - (import java.lang.Character$UnicodeScript + (import java/lang/Character$UnicodeScript (#enum ARABIC CYRILLIC LATIN)) "All enum options to be imported must be specified." - (import #long (lux.concurrency.promise.JvmPromise A) + (import #long (lux/concurrency/promise/JvmPromise A) (resolve [A] boolean) (poll [] A) (wasResolved [] boolean) - (waitOn [lux.Function] void) + (waitOn [lux/Function] void) (#static [A] make [A] (JvmPromise A))) "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)." "Also, the names of the imported members will look like ClassName.MemberName." "E.g.:" - (Object.new []) - (Object.equals [other-object] my-object) - (java.util.List.size [] my-list) - Character$UnicodeScript.LATIN + (Object::new []) + (Object::equals [other-object] my-object) + (java/util/List::size [] my-list) + Character$UnicodeScript::LATIN )} (do Monad<Meta> [kind (class-kind class-decl) @@ -2017,8 +2018,8 @@ (syntax: #export (with-open [bindings simple-bindings^] body) {#;doc (doc "Creates a local-binding with the desired resources, and runs the body (assumed to be in the IO type)." "Afterwards, closes all resources (assumed to be subclasses of java.io.Closeable), and returns the value resulting from running the body." - (with-open [my-res1 (res1-constructor ...) - my-res2 (res1-constructor ...)] + (with-open [my-res1 (res1-constructor ___) + my-res2 (res1-constructor ___)] (do Monad<IO> [foo (do-something my-res1) bar (do-something-else my-res2)] @@ -2039,7 +2040,7 @@ (syntax: #export (class-for [#let [imports (class-imports *compiler*)]] [type (generic-type^ imports (list))]) {#;doc (doc "Loads the class as a java.lang.Class object." - (class-for java.lang.String))} + (class-for java/lang/String))} (wrap (list (` ("jvm load-class" (~ (code;text (simple-class$ (list) type)))))))) (def: get-compiler @@ -2047,31 +2048,15 @@ (function [compiler] (#;Right [compiler compiler]))) -(def: (fully-qualify-class-name+ imports name) - (-> ClassImports Text (Maybe Text)) - (cond (fully-qualified-class-name? name) - (#;Some name) - - (list;member? text;Eq<Text> java.lang-classes name) - (#;Some (format "java.lang." name)) - - ## else - (get-import name imports))) - -(def: #export (resolve-class class) +(def: #export (resolve class) {#;doc (doc "Given a potentially unqualified class name, qualifies it if necessary." - (resolve-class "String") + (resolve "String") => "java.lang.String")} (-> Text (Meta Text)) (do Monad<Meta> [*compiler* get-compiler] - (case (fully-qualify-class-name+ (class-imports *compiler*) class) - (#;Some fqcn) - (wrap fqcn) - - #;None - (macro;fail (text/compose "Unknown class: " class))))) + (wrap (qualify (class-imports *compiler*) class)))) (syntax: #export (type [#let [imports (class-imports *compiler*)]] [type (generic-type^ imports (list))]) diff --git a/stdlib/source/lux/type/opaque.lux b/stdlib/source/lux/type/opaque.lux index 6bbf4c2a9..8327a851a 100644 --- a/stdlib/source/lux/type/opaque.lux +++ b/stdlib/source/lux/type/opaque.lux @@ -152,13 +152,13 @@ [annotations (p;default cs;empty-annotations csr;annotations)] representation-type [primitives (p;some s;any)]) - (let [hidden-name (code;local-symbol (representation-name name)) + (let [hidden-name (representation-name name) type-varsC (list/map code;local-symbol type-vars) opaque-declaration (` ((~ (code;local-symbol name)) (~@ type-varsC))) - representation-declaration (` ((~ hidden-name) (~@ type-varsC)))] + representation-declaration (` ((~ (code;local-symbol hidden-name)) (~@ type-varsC)))] (wrap (list& (` (type: (~@ (csw;export export)) (~ opaque-declaration) (~ (csw;annotations annotations)) - (primitive (~ hidden-name) [(~@ type-varsC)]))) + (primitive (~ (code;text hidden-name)) [(~@ type-varsC)]))) (` (type: (~@ (csw;export export)) (~ representation-declaration) (~ representation-type))) (` (install-casts (~ (code;local-symbol name)) [(~@ type-varsC)])) diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux index 5bf8e9d48..c124afdaa 100644 --- a/stdlib/source/lux/type/unit.lux +++ b/stdlib/source/lux/type/unit.lux @@ -70,7 +70,7 @@ [annotations (p;default cs;empty-annotations csr;annotations)]) (wrap (list (` (type: (~@ (csw;export export)) (~ (code;local-symbol name)) (~ (csw;annotations annotations)) - (primitive (~ (code;local-symbol (unit-name name)))))) + (primitive (~ (code;text (unit-name name)))))) (` (def: (~@ (csw;export export)) (~ (code;local-symbol (format "@" name))) (~ (code;local-symbol name)) (:!! []))) @@ -94,7 +94,7 @@ (let [g!scale (code;local-symbol name)] (wrap (list (` (type: (~@ (csw;export export)) ((~ g!scale) (~' u)) (~ (csw;annotations annotations)) - (primitive (~ (code;local-symbol (scale-name name))) [(~' u)]))) + (primitive (~ (code;text (scale-name name))) [(~' u)]))) (` (struct: (~@ (csw;export export)) (~ (code;local-symbol (format "@" name))) (;;Scale (~ g!scale)) (def: (~' scale) diff --git a/stdlib/source/lux/world/blob.jvm.lux b/stdlib/source/lux/world/blob.jvm.lux index c0e52379d..bb764dcb3 100644 --- a/stdlib/source/lux/world/blob.jvm.lux +++ b/stdlib/source/lux/world/blob.jvm.lux @@ -5,7 +5,7 @@ [eq]) (data [bit] [maybe] - ["E" error] + ["e" error] text/format) [host])) @@ -14,7 +14,7 @@ (type: #export Blob (host;type (Array byte))) -(host;import java.util.Arrays +(host;import java/util/Arrays (#static copyOfRange [(Array byte) int int] (Array byte)) (#static equals [(Array byte) (Array byte)] boolean)) @@ -23,7 +23,7 @@ (|> +1 (bit;shift-left +8) n/dec)) (def: byte-to-nat - (-> (primitive java.lang.Byte) Nat) + (-> (primitive "java.lang.Byte") Nat) (|>> host;b2l (:! Nat) (bit;and byte-mask))) (def: #export (create size) @@ -31,23 +31,23 @@ (host;array byte size)) (def: #export (read-8 idx blob) - (-> Nat Blob (E;Error Nat)) + (-> Nat Blob (e;Error Nat)) (if (n/< (host;array-length blob) idx) - (|> (host;array-read idx blob) byte-to-nat #E;Success) + (|> (host;array-read idx blob) byte-to-nat #e;Success) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-16 idx blob) - (-> Nat Blob (E;Error Nat)) + (-> Nat Blob (e;Error Nat)) (if (n/< (host;array-length blob) (n/+ +1 idx)) - (#E;Success ($_ bit;or + (#e;Success ($_ bit;or (bit;shift-left +8 (byte-to-nat (host;array-read idx blob))) (byte-to-nat (host;array-read (n/+ +1 idx) blob)))) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-32 idx blob) - (-> Nat Blob (E;Error Nat)) + (-> Nat Blob (e;Error Nat)) (if (n/< (host;array-length blob) (n/+ +3 idx)) - (#E;Success ($_ bit;or + (#e;Success ($_ bit;or (bit;shift-left +24 (byte-to-nat (host;array-read idx blob))) (bit;shift-left +16 (byte-to-nat (host;array-read (n/+ +1 idx) blob))) (bit;shift-left +8 (byte-to-nat (host;array-read (n/+ +2 idx) blob))) @@ -55,9 +55,9 @@ (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (read-64 idx blob) - (-> Nat Blob (E;Error Nat)) + (-> Nat Blob (e;Error Nat)) (if (n/< (host;array-length blob) (n/+ +7 idx)) - (#E;Success ($_ bit;or + (#e;Success ($_ bit;or (bit;shift-left +56 (byte-to-nat (host;array-read idx blob))) (bit;shift-left +48 (byte-to-nat (host;array-read (n/+ +1 idx) blob))) (bit;shift-left +40 (byte-to-nat (host;array-read (n/+ +2 idx) blob))) @@ -69,35 +69,35 @@ (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-8 idx value blob) - (-> Nat Nat Blob (E;Error Unit)) + (-> Nat Nat Blob (e;Error Unit)) (if (n/< (host;array-length blob) idx) (exec (|> blob (host;array-write idx (host;l2b (:! Int value)))) - (#E;Success [])) + (#e;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-16 idx value blob) - (-> Nat Nat Blob (E;Error Unit)) + (-> Nat Nat Blob (e;Error Unit)) (if (n/< (host;array-length blob) (n/+ +1 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n/+ +1 idx) (host;l2b (:! Int value)))) - (#E;Success [])) + (#e;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-32 idx value blob) - (-> Nat Nat Blob (E;Error Unit)) + (-> Nat Nat Blob (e;Error Unit)) (if (n/< (host;array-length blob) (n/+ +3 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +24 value)))) (host;array-write (n/+ +1 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) (host;array-write (n/+ +2 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n/+ +3 idx) (host;l2b (:! Int value)))) - (#E;Success [])) + (#e;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (write-64 idx value blob) - (-> Nat Nat Blob (E;Error Unit)) + (-> Nat Nat Blob (e;Error Unit)) (if (n/< (host;array-length blob) (n/+ +7 idx)) (exec (|> blob (host;array-write idx (host;l2b (:! Int (bit;shift-right +56 value)))) @@ -108,7 +108,7 @@ (host;array-write (n/+ +5 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) (host;array-write (n/+ +6 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n/+ +7 idx) (host;l2b (:! Int value)))) - (#E;Success [])) + (#e;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) (def: #export (size blob) @@ -116,7 +116,7 @@ (host;array-length blob)) (def: #export (slice from to blob) - (-> Nat Nat Blob (E;Error Blob)) + (-> Nat Nat Blob (e;Error Blob)) (with-expansions [<description> (as-is (format "from = " (%n from) " | " "to = " (%n to)))] (let [size (host;array-length blob)] (cond (not (n/<= to from)) @@ -127,12 +127,12 @@ (ex;throw Index-Out-Of-Bounds <description>) ## else - (#E;Success (Arrays.copyOfRange [blob (:! Int from) (:! Int (n/inc to))])))))) + (#e;Success (Arrays::copyOfRange [blob (:! Int from) (:! Int (n/inc to))])))))) (def: #export (slice' from blob) - (-> Nat Blob (E;Error Blob)) + (-> Nat Blob (e;Error Blob)) (slice from (n/dec (host;array-length blob)) blob)) (struct: #export _ (eq;Eq Blob) (def: (= reference sample) - (Arrays.equals [reference sample]))) + (Arrays::equals [reference sample]))) diff --git a/stdlib/source/lux/world/console.lux b/stdlib/source/lux/world/console.lux index 0448637ca..62beffb39 100644 --- a/stdlib/source/lux/world/console.lux +++ b/stdlib/source/lux/world/console.lux @@ -16,27 +16,27 @@ (close [] (Task Unit))) (for {"JVM" - (as-is (host;import java.lang.AutoCloseable + (as-is (host;import java/lang/AutoCloseable (close [] #io #try void)) - (host;import java.io.InputStream) + (host;import java/io/InputStream) - (host;import java.io.Reader) + (host;import java/io/Reader) - (host;import java.io.InputStreamReader + (host;import java/io/InputStreamReader (new [InputStream])) - (host;import java.io.BufferedReader + (host;import java/io/BufferedReader (new [Reader]) (read [] #io #try int) (readLine [] #io #try String)) - (host;import java.io.PrintStream + (host;import java/io/PrintStream (print [String] #io #try void)) - (host;import java.lang.System - (#static in java.io.InputStream) - (#static out java.io.PrintStream)) + (host;import java/lang/System + (#static in java/io/InputStream) + (#static out java/io/PrintStream)) (class: JVM-Console Console {#input BufferedReader @@ -45,30 +45,30 @@ (def: read-char (|>> get@Console (get@ #input) - (BufferedReader.read []) + (BufferedReader::read []) (:: io;Functor<Process> map (|>> int-to-nat text;from-code)) promise;future)) (def: read-line (|>> get@Console (get@ #input) - (BufferedReader.readLine []) + (BufferedReader::readLine []) promise;future)) (def: (write message) (|>> get@Console (get@ #output) - (PrintStream.print [message]) + (PrintStream::print [message]) promise;future)) (def: (close self) (promise;future (do io;Monad<Process> - [_ (AutoCloseable.close [] (|> self get@Console (get@ #input)))] - (AutoCloseable.close [] (|> self get@Console (get@ #output))))))) + [_ (AutoCloseable::close [] (|> self get@Console (get@ #input)))] + (AutoCloseable::close [] (|> self get@Console (get@ #output))))))) (def: #export open (Process Console) - (io (#e;Success (new@JVM-Console {#input (|> System.in InputStreamReader.new BufferedReader.new) - #output System.out}))))) + (io (#e;Success (new@JVM-Console {#input (|> System::in InputStreamReader::new BufferedReader::new) + #output System::out}))))) }) diff --git a/stdlib/source/lux/world/env.jvm.lux b/stdlib/source/lux/world/env.jvm.lux index a3a58bc61..828f6b5da 100644 --- a/stdlib/source/lux/world/env.jvm.lux +++ b/stdlib/source/lux/world/env.jvm.lux @@ -2,46 +2,45 @@ lux (lux (data [text] (format [context #+ Context]) - (coll [list "L/" Functor<List>] - ["d" dict])) + (coll [dict])) [io #- run] [host])) -(host;import java.lang.String) +(host;import java/lang/String) -(host;import (java.util.Map$Entry k v) +(host;import (java/util/Map$Entry k v) (getKey [] k) (getValue [] v)) -(host;import (java.util.Iterator a) +(host;import (java/util/Iterator a) (hasNext [] boolean) (next [] a)) -(host;import (java.util.Set a) +(host;import (java/util/Set a) (iterator [] (Iterator a))) -(host;import (java.util.Map k v) +(host;import (java/util/Map k v) (entrySet [] (Set (Map$Entry k v)))) -(host;import java.lang.System - (#static getenv [] (java.util.Map String String))) +(host;import java/lang/System + (#static getenv [] (java/util/Map String String))) (def: (consume-iterator f iterator) (All [a b] (-> (-> a b) (Iterator a) (List b))) - (if (Iterator.hasNext [] iterator) - (#;Cons (f (Iterator.next [] iterator)) + (if (Iterator::hasNext [] iterator) + (#;Cons (f (Iterator::next [] iterator)) (consume-iterator f iterator)) #;Nil)) (def: (entry-to-kv entry) (All [k v] (-> (Map$Entry k v) [k v])) - [(Map$Entry.getKey [] entry) - (Map$Entry.getValue [] entry)]) + [(Map$Entry::getKey [] entry) + (Map$Entry::getValue [] entry)]) (def: #export read (IO Context) - (io (|> (System.getenv []) - (Map.entrySet []) - (Set.iterator []) + (io (|> (System::getenv []) + (Map::entrySet []) + (Set::iterator []) (consume-iterator entry-to-kv) - (d;from-list text;Hash<Text>)))) + (dict;from-list text;Hash<Text>)))) diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 1e95e7354..0b85068ef 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -16,15 +16,15 @@ (type: #export File Text) -(host;import #long java.io.File +(host;import #long java/io/File (new [String]) (exists [] #io #try boolean) (mkdir [] #io #try boolean) (delete [] #io #try boolean) (length [] #io #try long) - (listFiles [] #io #try (Array java.io.File)) + (listFiles [] #io #try (Array java/io/File)) (getAbsolutePath [] #io #try String) - (renameTo [java.io.File] #io #try boolean) + (renameTo [java/io/File] #io #try boolean) (isFile [] #io #try boolean) (isDirectory [] #io #try boolean) (lastModified [] #io #try long) @@ -33,30 +33,30 @@ (canWrite [] #io #try boolean) (canExecute [] #io #try boolean)) -(host;import java.lang.AutoCloseable +(host;import java/lang/AutoCloseable (close [] #io #try void)) -(host;import java.io.OutputStream +(host;import java/io/OutputStream (write [(Array byte)] #io #try void) (flush [] #io #try void)) -(host;import java.io.FileOutputStream - (new [java.io.File boolean] #io #try)) +(host;import java/io/FileOutputStream + (new [java/io/File boolean] #io #try)) -(host;import java.io.InputStream +(host;import java/io/InputStream (read [(Array byte)] #io #try int)) -(host;import java.io.FileInputStream - (new [java.io.File] #io #try)) +(host;import java/io/FileInputStream + (new [java/io/File] #io #try)) (do-template [<name> <flag>] [(def: #export (<name> data file) (-> Blob File (T;Task Unit)) (P;future (do (E;ErrorT io;Monad<IO>) - [stream (FileOutputStream.new [(java.io.File.new file) <flag>]) - _ (OutputStream.write [data] stream) - _ (OutputStream.flush [] stream)] - (AutoCloseable.close [] stream))))] + [stream (FileOutputStream::new [(java/io/File::new file) <flag>]) + _ (OutputStream::write [data] stream) + _ (OutputStream::flush [] stream)] + (AutoCloseable::close [] stream))))] [append true] [write false] @@ -65,12 +65,12 @@ (def: #export (read file) (-> File (T;Task Blob)) (P;future (do (E;ErrorT io;Monad<IO>) - [#let [file' (java.io.File.new file)] - size (java.io.File.length [] file') + [#let [file' (java/io/File::new file)] + size (java/io/File::length [] file') #let [data (blob;create (int-to-nat size))] - stream (FileInputStream.new [file']) - bytes-read (InputStream.read [data] stream) - _ (AutoCloseable.close [] stream)] + stream (FileInputStream::new [file']) + bytes-read (InputStream::read [data] stream) + _ (AutoCloseable::close [] stream)] (if (i/= size bytes-read) (wrap data) (io;io (ex;throw Could-Not-Read-All-Data file)))))) @@ -78,43 +78,43 @@ (def: #export (size file) (-> File (T;Task Nat)) (P;future (do (E;ErrorT io;Monad<IO>) - [size (java.io.File.length [] (java.io.File.new file))] + [size (java/io/File::length [] (java/io/File::new file))] (wrap (int-to-nat size))))) (def: #export (files dir) (-> File (T;Task (List File))) (P;future (do (E;ErrorT io;Monad<IO>) - [files (java.io.File.listFiles [] (java.io.File.new dir))] - (monad;map @ (java.io.File.getAbsolutePath []) + [files (java/io/File::listFiles [] (java/io/File::new dir))] + (monad;map @ (java/io/File::getAbsolutePath []) (array;to-list files))))) (do-template [<name> <method>] [(def: #export (<name> file) (-> File (T;Task Bool)) - (P;future (<method> [] (java.io.File.new file))))] - - [exists? java.io.File.exists] - [make-dir java.io.File.mkdir] - [delete java.io.File.delete] - [file? java.io.File.isFile] - [directory? java.io.File.isDirectory] - [can-read? java.io.File.canRead] - [can-write? java.io.File.canWrite] - [can-execute? java.io.File.canExecute] + (P;future (<method> [] (java/io/File::new file))))] + + [exists? java/io/File::exists] + [make-dir java/io/File::mkdir] + [delete java/io/File::delete] + [file? java/io/File::isFile] + [directory? java/io/File::isDirectory] + [can-read? java/io/File::canRead] + [can-write? java/io/File::canWrite] + [can-execute? java/io/File::canExecute] ) (def: #export (move target source) (-> File File (T;Task Bool)) - (P;future (java.io.File.renameTo [(java.io.File.new target)] - (java.io.File.new source)))) + (P;future (java/io/File::renameTo [(java/io/File::new target)] + (java/io/File::new source)))) (def: #export (get-last-modified file) (-> File (T;Task i;Instant)) (P;future (do (E;ErrorT io;Monad<IO>) - [millis (java.io.File.lastModified [] (java.io.File.new file))] + [millis (java/io/File::lastModified [] (java/io/File::new file))] (wrap (|> millis d;from-millis i;absolute))))) (def: #export (set-last-modified time file) (-> i;Instant File (T;Task Bool)) - (P;future (java.io.File.setLastModified [(|> time i;relative d;to-millis)] - (java.io.File.new file)))) + (P;future (java/io/File::setLastModified [(|> time i;relative d;to-millis)] + (java/io/File::new file)))) diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux index 0a109d04c..f279a0873 100644 --- a/stdlib/source/lux/world/net/tcp.jvm.lux +++ b/stdlib/source/lux/world/net/tcp.jvm.lux @@ -11,24 +11,24 @@ [host]) [//]) -(host;import java.lang.AutoCloseable +(host;import java/lang/AutoCloseable (close [] #io #try void)) -(host;import java.io.Flushable +(host;import java/io/Flushable (flush [] #io #try void)) -(host;import java.io.InputStream +(host;import java/io/InputStream (read [(Array byte) int int] #io #try int)) -(host;import java.io.OutputStream +(host;import java/io/OutputStream (write [(Array byte) int int] #io #try void)) -(host;import java.net.Socket +(host;import java/net/Socket (new [String int] #io #try) (getInputStream [] #io #try InputStream) (getOutputStream [] #io #try OutputStream)) -(host;import java.net.ServerSocket +(host;import java/net/ServerSocket (new [int] #io #try) (accept [] #io #try Socket)) @@ -45,31 +45,31 @@ (let [in (get@ #in (@repr self))] (P;future (do (e;ErrorT io;Monad<IO>) - [bytes-read (InputStream.read [data (nat-to-int offset) (nat-to-int length)] - in)] + [bytes-read (InputStream::read [data (nat-to-int offset) (nat-to-int length)] + in)] (wrap (int-to-nat bytes-read)))))) (def: #export (write data offset length self) (let [out (get@ #out (@repr self))] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (OutputStream.write [data (nat-to-int offset) (nat-to-int length)] - out)] - (Flushable.flush [] out))))) + [_ (OutputStream::write [data (nat-to-int offset) (nat-to-int length)] + out)] + (Flushable::flush [] out))))) (def: #export (close self) (let [(^open) (@repr self)] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (AutoCloseable.close [] in) - _ (AutoCloseable.close [] out)] - (AutoCloseable.close [] socket))))) + [_ (AutoCloseable::close [] in) + _ (AutoCloseable::close [] out)] + (AutoCloseable::close [] socket))))) (def: (tcp-client socket) (-> Socket (io;IO (e;Error TCP))) (do (e;ErrorT io;Monad<IO>) - [input (Socket.getInputStream [] socket) - output (Socket.getOutputStream [] socket)] + [input (Socket::getInputStream [] socket) + output (Socket::getOutputStream [] socket)] (wrap (@opaque {#socket socket #in input #out output})))) @@ -78,7 +78,7 @@ (-> //;Address //;Port (T;Task TCP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (Socket.new [address (nat-to-int port)])] + [socket (Socket::new [address (nat-to-int port)])] (tcp-client socket)))) (def: (await-server-release client-channel server) @@ -91,7 +91,7 @@ #;None (P;future (do io;Monad<IO> - [_ (AutoCloseable.close [] server)] + [_ (AutoCloseable::close [] server)] (wrap []))) ## A client was generated. @@ -103,14 +103,14 @@ (-> //;Port (T;Task (frp;Channel TCP))) (P;future (do (e;ErrorT io;Monad<IO>) - [server (ServerSocket.new [(nat-to-int port)]) + [server (ServerSocket::new [(nat-to-int port)]) #let [output (frp;channel TCP) _ (: (P;Promise Bool) (P;future (loop [tail output] (do io;Monad<IO> [?client (do (e;ErrorT io;Monad<IO>) - [socket (ServerSocket.accept [] server)] + [socket (ServerSocket::accept [] server)] (tcp-client socket))] (case ?client (#e;Error error) diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux index 139ed4f49..3bb94e112 100644 --- a/stdlib/source/lux/world/net/udp.jvm.lux +++ b/stdlib/source/lux/world/net/udp.jvm.lux @@ -14,24 +14,24 @@ [host]) [//]) -(host;import java.lang.AutoCloseable +(host;import java/lang/AutoCloseable (close [] #io #try void)) -(host;import java.io.Flushable +(host;import java/io/Flushable (flush [] #io #try void)) -(host;import java.net.InetAddress +(host;import java/net/InetAddress (#static getAllByName [String] #io #try (Array InetAddress)) (getHostAddress [] String)) -(host;import java.net.DatagramPacket +(host;import java/net/DatagramPacket (new #as new|send [(Array byte) int int InetAddress int]) (new #as new|receive [(Array byte) int int]) (getAddress [] InetAddress) (getPort [] int) (getLength [] int)) -(host;import java.net.DatagramSocket +(host;import java/net/DatagramSocket (new #as new|client [] #io #try) (new #as new|server [int] #io #try) (receive [DatagramPacket] #io #try void) @@ -47,7 +47,7 @@ (def: (resolve address) (-> //;Address (io;IO (e;Error InetAddress))) (do (e;ErrorT io;Monad<IO>) - [addresses (InetAddress.getAllByName [address])] + [addresses (InetAddress::getAllByName [address])] (: (io;IO (e;Error InetAddress)) (case (array;size addresses) +0 (io;io (ex;throw Cannot-Resolve-Address address)) @@ -60,14 +60,14 @@ (def: #export (read data offset length self) (-> Blob Nat Nat UDP (T;Task [Nat //;Address //;Port])) (let [(^open) (@repr self) - packet (DatagramPacket.new|receive [data (nat-to-int offset) (nat-to-int length)])] + packet (DatagramPacket::new|receive [data (nat-to-int offset) (nat-to-int length)])] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (DatagramSocket.receive [packet] socket) - #let [bytes-read (int-to-nat (DatagramPacket.getLength [] packet))]] + [_ (DatagramSocket::receive [packet] socket) + #let [bytes-read (int-to-nat (DatagramPacket::getLength [] packet))]] (wrap [bytes-read - (|> packet (DatagramPacket.getAddress []) (InetAddress.getHostAddress [])) - (int-to-nat (DatagramPacket.getPort [] packet))]))))) + (|> packet (DatagramPacket::getAddress []) (InetAddress::getHostAddress [])) + (int-to-nat (DatagramPacket::getPort [] packet))]))))) (def: #export (write address port data offset length self) (-> //;Address //;Port Blob Nat Nat UDP (T;Task Unit)) @@ -75,26 +75,26 @@ (do (e;ErrorT io;Monad<IO>) [address (resolve address) #let [(^open) (@repr self)]] - (DatagramSocket.send (DatagramPacket.new|send [data (nat-to-int offset) (nat-to-int length) address (nat-to-int port)]) - socket)))) + (DatagramSocket::send (DatagramPacket::new|send [data (nat-to-int offset) (nat-to-int length) address (nat-to-int port)]) + socket)))) (def: #export (close self) (-> UDP (T;Task Unit)) (let [(^open) (@repr self)] (P;future - (AutoCloseable.close [] socket)))) + (AutoCloseable::close [] socket)))) (def: #export (client _) (-> Unit (T;Task UDP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (DatagramSocket.new|client [])] + [socket (DatagramSocket::new|client [])] (wrap (@opaque (#socket socket)))))) (def: #export (server port) (-> //;Port (T;Task UDP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (DatagramSocket.new|server [(nat-to-int port)])] + [socket (DatagramSocket::new|server [(nat-to-int port)])] (wrap (@opaque (#socket socket)))))) ) diff --git a/stdlib/test/test/lux/host.jvm.lux b/stdlib/test/test/lux/host.jvm.lux index 064b4c360..7025bdc2a 100644 --- a/stdlib/test/test/lux/host.jvm.lux +++ b/stdlib/test/test/lux/host.jvm.lux @@ -11,18 +11,18 @@ ["r" math/random]) lux/test) -(&;import (java.util.concurrent.Callable a)) +(&;import (java/util/concurrent/Callable a)) -(&;import java.lang.Exception +(&;import java/lang/Exception (new [String])) -(&;import java.lang.Object) +(&;import java/lang/Object) -(&;import (java.lang.Class a) +(&;import (java/lang/Class a) (getName [] String)) -(&;import java.lang.System - (#static out java.io.PrintStream) +(&;import java/lang/System + (#static out java/io/PrintStream) (#static currentTimeMillis [] #io long) (#static getenv [String] #io #? String)) @@ -30,20 +30,19 @@ ## Fields (#private foo boolean) (#private bar A) - (#private baz java.lang.Object) + (#private baz java/lang/Object) ## Methods (#public [] (new [value A]) [] - (exec (:= .foo true) - (:= .bar value) - (:= .baz "") + (exec (:= ::foo true) + (:= ::bar value) + (:= ::baz "") [])) - (#public (virtual) java.lang.Object + (#public (virtual) java/lang/Object "") - (#public #static (static) java.lang.Object + (#public #static (static) java/lang/Object "") (Runnable [] (run) void - []) - ) + [])) (def: test-runnable (object [] [Runnable] @@ -94,7 +93,7 @@ (&;synchronized "" true)) (test "Can access Class instances." - (text/= "java.lang.Class" (Class.getName [] (&;class-for java.lang.Class)))) + (text/= "java.lang.Class" (Class::getName [] (&;class-for java/lang/Class)))) (test "Can check if a value is null." (and (&;null? (&;null)) diff --git a/stdlib/test/test/lux/world/blob.lux b/stdlib/test/test/lux/world/blob.lux index 90d2a9af0..c478818c0 100644 --- a/stdlib/test/test/lux/world/blob.lux +++ b/stdlib/test/test/lux/world/blob.lux @@ -4,19 +4,19 @@ (control [monad #+ do] [pipe]) (data [bit] - ["E" error] + ["e" error] (coll [list])) (world ["@" blob]) ["r" math/random]) lux/test) (def: (succeed result) - (-> (E;Error Bool) Bool) + (-> (e;Error Bool) Bool) (case result - (#E;Error _) + (#e;Error _) false - (#E;Success output) + (#e;Success output) output)) (def: #export (blob size) @@ -28,7 +28,7 @@ (if (n/< size idx) (do @ [byte r;nat] - (exec (E;assume (@;write-8 idx byte blob)) + (exec (e;assume (@;write-8 idx byte blob)) (recur (n/inc idx)))) (wrap blob)))))) @@ -54,39 +54,39 @@ value-32 (n/% (bit;shift-left +32 +1) value) value-64 value slice-size (|> to (n/- from) n/inc) - random-slice (E;assume (@;slice from to random-blob))]] + random-slice (e;assume (@;slice from to random-blob))]] ($_ seq (test "Has equality." (and (:: @;Eq<Blob> = clean-blob clean-blob) (:: @;Eq<Blob> = - (E;assume (@;slice from to clean-blob)) - (E;assume (@;slice from to clean-blob))))) + (e;assume (@;slice from to clean-blob)) + (e;assume (@;slice from to clean-blob))))) (test "Can get size of blob." (n/= blob-size size)) (test "Can read/write 8-bit values." (succeed - (do E;Monad<Error> + (do e;Monad<Error> [_ (@;write-8 idx value-8 clean-blob) output-8 (@;read-8 idx clean-blob)] (wrap (n/= value-8 output-8))))) (test "Can read/write 16-bit values." (or (n/>= size (n/+ +1 idx)) (succeed - (do E;Monad<Error> + (do e;Monad<Error> [_ (@;write-16 idx value-16 clean-blob) output-16 (@;read-16 idx clean-blob)] (wrap (n/= value-16 output-16)))))) (test "Can read/write 32-bit values." (or (n/>= size (n/+ +3 idx)) (succeed - (do E;Monad<Error> + (do e;Monad<Error> [_ (@;write-32 idx value-32 clean-blob) output-32 (@;read-32 idx clean-blob)] (wrap (n/= value-32 output-32)))))) (test "Can read/write 64-bit values." (or (n/>= size (n/+ +7 idx)) (succeed - (do E;Monad<Error> + (do e;Monad<Error> [_ (@;write-64 idx value-64 clean-blob) output-64 (@;read-64 idx clean-blob)] (wrap (n/= value-64 output-64)))))) @@ -96,7 +96,7 @@ (let [loop-recur recur] (if (n/< slice-size idx) (and (succeed - (do E;Monad<Error> + (do e;Monad<Error> [reference (@;read-8 (n/+ from idx) random-blob) sample (@;read-8 idx random-slice)] (wrap (n/= reference sample)))) @@ -105,5 +105,5 @@ (test "Slicing the whole blob does not change anything." (:: @;Eq<Blob> = random-blob - (E;assume (@;slice +0 (n/dec blob-size) random-blob)))) + (e;assume (@;slice +0 (n/dec blob-size) random-blob)))) )))) |