diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | license.txt | 253 | ||||
-rw-r--r-- | new-luxc/project.clj | 33 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/r.lux | 5 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/r/eval.jvm.lux | 154 | ||||
-rw-r--r-- | stdlib/project.clj | 1 | ||||
-rw-r--r-- | stdlib/source/lux/math/random.lux | 21 | ||||
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 73 | ||||
-rw-r--r-- | stdlib/test/test/lux/math/random.lux | 11 | ||||
-rw-r--r-- | stdlib/test/test/lux/time/duration.lux | 28 |
10 files changed, 256 insertions, 327 deletions
@@ -39,7 +39,9 @@ The `luxdoc` program was actually used to generate the documentation for the sta ### What's the license? -[MIT](license.txt) +[Custom License](license.txt) + +Read carefully before using this project, as the license disallows commercial use, and has other conditions which may be undesirable for some. ## What's interesting about the language? diff --git a/license.txt b/license.txt index 4dfeb9c31..e12f6d586 100644 --- a/license.txt +++ b/license.txt @@ -1,19 +1,234 @@ -Copyright (c) 2014-2017 Eduardo Emilio Julian Pereyra - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Lux License +0.1 + +Copyright (C) 2014-2018 Eduardo Emilio Julián Pereyra + +Definitions + +"This License": the terms and conditions defined in this document. + +"Licensable": having the right to grant any and all of the rights conveyed by This License. + +"Legal Entity": any human or non-human entity that is recognized as having privileges and obligations, such as having the ability to enter into contracts, and to sue, and to be sued. + +"Recipient": a Legal Entity exercising permissions by This License. + +"The Licensor": the copyright owner granting This License, or a Legal Entity authorized by the copyright owner. + +"Source Code Form": the preferred form of the work of authorship in order to make modifications to it. + +"Object Form": any form produced by transforming a Source Code Form, including but not limited to compiled code and transpiled code. + +"The Work": the work of authorship, whether in a Source Code Form or in an Object Form, made available under This License, as indicated by a copyright notice that is included in or attached to the work of authorship. + +"Derivative Work": any work, whether in a Source Code Form or in an Object Form, that is based on (or derived from) The Work and which represents an original work of authorship. + +"Submission": any form of electronic, or verbal, or written communication sent to The Licensor, or its representatives, for the purpose of discussing and improving The Work, but excluding communication that is designated in writing by the copyright owner as "Not a Contribution". + +"Modification": any addition to, or deletion from, the substance or structure of a file or other storage contained in The Work, or any new file or other storage that contains any part of The Work, or any file or other storage which replaces or otherwise alters the original functionality of The Work at runtime. + +"Required Component": any text, or program, or script, or schema, or interface definition, or control file, or other work created by Recipient which is required by a third party to successfully install and run a Derivative Work by Recipient. + +"Extension": any Modification, or Derivative Work, or Required Component. + +"Contribution": any work of authorship, including the original version of The Work and any Extension to The Work, that is intentionally communicated as a Submission to The Licensor for inclusion in The Work by the copyright owner, or by a Legal Entity authorized to submit on behalf of the copyright owner. + +"Contributor": The Licensor or any Legal Entity on behalf of whom a Contribution has been received by The Licensor, and subsequently incorporated within The Work. + +"Patent Claim Of A Contributor": any patent claim(s), including without limitation method, and process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of This License, to make, or have made, or use, or offer to sell, or sell, or import, or transfer its Contribution. + +"Secondary License": any license for which compliance does not imply or require violating the terms of This License. + +"Sell": practicing any or all of the rights granted to Recipient under This License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting services, or consulting services, or support services related to The Work), a product or service whose value derives, entirely or substantially, from the functionality of The Work. + +"Personal Use": use of The Work by an individual solely for his or her personal, and private, and non-commercial purposes. +An individual's use of The Work in his or her capacity as an officer, or employee, or member, or independent contractor, or agent of a corporation, business or organization (commercial or non-commercial) does not qualify. + +"Serve": to deliver The Work and/or any Extension by means of a computer network to one or more computers for purposes of execution of The Work, and/or the Extension. + +"Research": investigation or experimentation for the purpose of understanding the nature and limits of The Work and its potential uses. + +"Deploy": to use, or Serve, or sublicense, or distribute The Work other than for internal Research and/or Personal Use by Recipient, and includes without limitation, any and all internal use or distribution of The Work within a business or organization in which Recipient participates, other than for Research and/or Personal Use, as well as direct sublicensing, or indirect sublicensing, or distribution of The Work by Recipient to any third party in any form or manner. + +"Electronic Distribution Mechanism": a mechanism generally accepted in the software development community for the electronic transfer of data, such as download from an FTP server or web site, where such mechanism is publicly accessible. + +Acceptance of This License + +Recipient is not required to accept This License since Recipient has not signed it. +However, nothing else grants Recipient permission to use, or copy, or distribute, or modify, or create an Extension of either The Work or any Extension created by a Contributor. +These actions are prohibited by law if Recipient does not accept This License. +Therefore, by performing any of these actions, Recipient indicates that Recipient accepts This License, and Recipient agrees to be bound by all its terms and conditions. +If Recipient does not agree with all the terms and conditions of This License, Recipient can not use, or copy, or distribute, or modify, or create an Extension of either The Work or any Extension created by a Contributor. +If it is impossible for Recipient to comply with all the terms and conditions of This License, then Recipient can not use, or copy, or distribute, or modify, or create an Extension of either The Work or any Extension created by a Contributor. + +Grant of Copyright License + +Subject to the terms and conditions of This License, each Contributor hereby grants to Recipient a perpetual, and world-wide, and non-exclusive, and no-charge, and royalty-free, and irrevocable copyright license to use, or reproduce, or display, or perform, or modify, or create an Extension of, or sublicense, or distribute The Work and such an Extension in a Source Code Form or an Object Form. + +Grant of Patent License + +Subject to the terms and conditions of This License, each Contributor hereby grants to Recipient a perpetual, and world-wide, and non-exclusive, and no-charge, and royalty-free, and irrevocable patent license to make, or have made, or use, or offer to sell, or sell, or import, or transfer The Work, where such license applies only to any Patent Claim Of A Contributor that is necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with The Work. +If Recipient institutes patent litigation against any Legal Entity (including a cross-claim or counterclaim in a lawsuit) alleging that The Work or a Contribution incorporated within The Work constitutes direct or contributory patent infringement, then any patent licenses granted to Recipient under This License for The Work shall terminate as of the date such litigation is filed. + +Effective Date for the Grants + +The licenses granted in This License with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. + +Grant Termination + +The rights granted under This License will terminate automatically if Recipient fails to comply with any of its terms. +However, if Recipient becomes compliant, then the rights granted under This License from a particular Contributor are reinstated provisionally, unless and until such Contributor explicitly and finally terminates the grants to Recipient, and on an ongoing basis, if such Contributor fails to notify Recipient of the non-compliance by some reasonable means prior to 60 day(s) after Recipient has come back into compliance. +Moreover, grants to Recipient from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies Recipient of the non-compliance by some reasonable means, and this is the first time Recipient has received notice of non-compliance with This License from such Contributor, and Recipient becomes compliant prior to 30 day(s) after reception of the notice. + +No Retroactive Effect of Termination + +In the event of termination, all end user license agreements (excluding licenses to distributors and resellers) that have been validly granted by Recipient or any distributor hereunder prior to termination shall survive termination. + +Limitations on Grant Scope + +The licenses granted in this document are the only rights granted under This License. +No additional rights or licenses will be implied from the distribution or licensing of The Work under This License. +No patent license is granted by a Contributor for any code that the Contributor has removed from The Work. + +Limitations on Trademarks + +This License does not grant any permission to use the trade names, or trademarks, or service marks, or product names, or logos of any Contributor; except as required for reasonable and customary use in describing the origin of The Work. + +Limitations on Secondary License(s) + +No Contributor makes additional grants as a result of a choice by Recipient to distribute The Work under a under the terms of a Secondary License. + +Representation + +Each Contributor represents that the Contributor believes its Contribution(s) are its original creation(s) or it has sufficient rights to grant the rights to its Contribution(s) conveyed by This License. + +Fair Use + +This License is not intended to limit any rights Recipient has under applicable copyright doctrines of fair use, or fair dealing, or other equivalents. + +Submission of Contribution(s) + +Unless Recipient explicitly states otherwise, any intentional Submission of a Contribution for inclusion in The Work by Recipient to The Licensor shall be under the terms and conditions of This License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement Recipient may have executed with The Licensor regarding such Contribution. + +Disclaimer of Warranty + +Unless required by applicable law or agreed to in writing, The Licensor provides The Work, and each Contributor provides its Contribution(s) under This License on an "as is" basis, without warranty or condition of any kind, either expressed, or implied, or statutory including, without limitation, any warranties or conditions that The Work is free of defects, or merchantable, or fit for a particular purpose, or non-infringing. +Recipient is solely responsible for determining the appropriateness of using or redistributing The Work. +The entire risk as to the quality and performance of The Work is with Recipient. +Should The Work prove defective in any respect, Recipient, not any Contributor, assumes the cost of any necessary servicing, or repair, or correction. +This disclaimer of warranty constitutes an essential part of This License. +No use of The Work is authorized under This License except under this disclaimer. + +Limitation of Liability + +Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to Recipient for any direct, or indirect, or special, or incidental, or consequential damages of any character including without limitation damages for lost profits, or loss of goodwill, or work stoppage, or computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. +This limitation of liability shall not apply to liability for death or personal injury resulting from such party’s negligence to the extent applicable law prohibits such limitation. +Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to Recipient. + +Litigation + +Any litigation relating to This License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business. +Such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this section shall prevent a party’s ability to bring cross-claims or counter-claims. + +High Risk Activities + +The Work is not fault tolerant, and is not designed, or manufactured, or intended for use or distribution as on-line control equipment in hazardous environments requiring fail-safe performance, such as in the operation of nuclear facilities, or aircraft navigation, or communications systems, or air traffic control, or direct life support machines, or weapons systems, in which the failure of The Work could lead directly to death, or personal injury, or severe physical damage, or environmental damage. +The Licensor and every Contributor specifically disclaim any express or implied warranty of fitness for high risk activities. + +Distribution of a Source Code Form + +All distribution of The Work in Source Code Form, including any Contribution(s) that Recipient creates, must be under the terms of This License. +Recipient must inform recipients that the Source Code Form of The Work is governed by the terms of This License, and how they can obtain a copy of This License. +Recipient may not attempt to alter or restrict the recipients’ rights in the Source Code Form, as specified in This License. +Recipient must retain, in the Source Code Form of any Extension that Recipient distributes, all copyright notices, and patent notices, and trademark notices, and attribution notices, and disclaimer of warranty notices, and limitation of liability notices, and other notices from the Source Code Form of The Work, excluding those notices that do not pertain to any part of the Extension, or those notices that contain known factual inaccuracies. +Recipient may add additional copyright notices, and patent notices, and trademark notices, and attribution notices, and disclaimer of warranty notices, and limitation of liability notices, and other notices within an Extension that Recipient distributes, provided that such additional copyright notices, and patent notices, and trademark notices, and attribution notices, and disclaimer of warranty notices, and limitation of liability notices, and other notices cannot be construed as modifying This License. + +Distribution of an Object Form + +If Recipient distributes The Work in Object Form then The Work must also be made available in Source Code Form, and Recipient must inform recipients of the Object Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient. +Recipient may distribute such Object Form under the terms of This License. + +Non-Commerciality + +Without limiting other conditions in This License, the grant of rights under This License will not include, and This License does not grant to Recipient, the right to Sell The Work. + +Contributor Attribution + +All advertising materials mentioning features or use of The Work must include an acknowledgement of the authorship of every Contributor. + +Contributor Endorsement + +The name of no Contributor may be used to endorse or promote products derived from any Extension without specific prior written permission. + +License Retention + +In consideration of, and as an express condition to, the licenses granted to Recipient under This License, Recipient hereby agrees that any Extension that Recipient creates or to which Recipient contributes are governed by the terms of This License. +Recipient may only Deploy an Extension that Recipient creates under the terms of This License. +Recipient hereby grant to The Licensor and all third parties a perpetual, and world-wide, and non-exclusive, and no-charge, and royalty-free, and irrevocable license under those intellectual property rights Recipient owns or controls to use, or reproduce, or display, or perform, or modify, or create an Extension of, or sublicense, or distribute The Work in any form. +Recipient must include a copy of This License or directions on how to obtain a copy with every copy of an Extension Recipient distributes. +Recipient agrees not to offer or impose any terms on any Source Code Form or Object Form of the The Work, or its Extension that alter or restrict the applicable version of This License or the recipients' rights hereunder. +Where any portion of an Extension created by Recipient fall under the terms of another license, the terms of that license should be honored. +However Recipient must also make the Extension available under This License. +If the terms of This License continue to conflict with the terms of the other license, Recipient may write The Licensor for permission to resolve the conflict in a fashion that remains consistent with the intent of This License. +Such permission will be granted at the sole discretion of The Licensor. + +Extension Distinctness + +Any Extension Recipient does make and Deploy must have a distinct title so as to readily tell any subsequent user or Contributor that the Extension is by Recipient. + +Source Code Form Availability + +Recipient must notify the software community of the availability of the Source Code Form to any Extension created by Recipient within 1 month(s) of the date Recipient initially does Deploy, and include in such notification a description of the Extension, and instructions on how to acquire the Source Code Form via an Electronic Distribution Mechanism. +The Source Code Form must remain available via an Electronic Distribution Mechanism for no less than 12 month(s) after the date Recipient ceases to Deploy. +Recipient is responsible for ensuring that the Source Code Form to each Extension Recipient does Deploy remains available even if the Electronic Distribution Mechanism is maintained by a third party. +Recipient may not charge a fee for any copy of the Source Code Form in excess of the actual cost of duplication and distribution of said copy that Recipient incurs. +Should such instructions change, Recipient must notify the software community of revised instructions within 1 month(s) of the date of change. +Recipient must provide notification by posting to appropriate news groups, or mailing lists, or weblogs, or other sites where a publicly accessible search engine would reasonably be expected to index a post in relationship to queries regarding The Work and/or an Extension created by Recipient. + +Description of Modification(s) + +Recipient must cause any Modification that Recipient creates, or to which Recipient contributes, to be documented in the Source Code Form, clearly describing the additions, and changes, and deletions that Recipient made. +Recipient must include a prominent statement that the Modification is derived, directly or indirectly, from The Work and include the names of The Licensor and any Contributor to The Work in the Source Code Form, and in any notice displayed by The Work Recipient distributes, and in related documentation in which Recipient describes the origin or ownership of The Work. +Recipient may not modify or delete any pre-existing copyright notices, change notices or the text of This License in The Work without written permission of The Licensor or the respective Contributor. + +Attribution Information + +Attribution Copyright Notice: Made by Eduardo Emilio Julián Pereyra +Attribution URL: https://github.com/LuxLang/lux + +Entire Agreement + +This License constitutes the entire agreement between the parties with respect to the subject matter hereof. + +Relationship of Parties + +This License will not be construed as creating an agency, or a partnership, or a joint venture, or any other form of legal association between or among Recipient, The Licensor or any Contributor, and Recipient will not represent to the contrary, whether expressly, or by implication, or by appearance, or otherwise. + +Independent Development + +Nothing in This License will impair the right of The Licensor to acquire, or license, or develop, or subcontract, or market, or distribute, or produce technology or products that perform the same or similar functions as, or otherwise compete with, any Extension that Recipient may acquire, or license, or develop, or subcontract, or market, or distribute, or produce. + +Consent To Breach Not Waiver + +Failure by The Licensor or any Contributor to enforce any provision of This License will not be deemed a waiver of future enforcement of that or any other provision. + +Severability + +If any provision of This License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. +Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe This License against a Contributor. + +Export Restrictions + +Recipient may be restricted with respect to downloading, or acquiring, or exporting, or reexporting The Work or any underlying information or technology by applicable laws and regulations. +By downloading, or acquiring, or exporting, or reexporting The Work, Recipient is agreeing to be responsible for compliance with all applicable laws and regulations. + +Versions of This License + +The Licensor may publish, from time to time, revised versions of This License. +Once The Work has been published under a particular version of This License, Recipient may always continue to use it under the terms of that version. +Recipient may also choose to use The Work under the terms of any subsequent version of This License published by The Licensor. +No one other than The Licensor has the right to modify the terms applicable to The Work created under This License. + +END OF TERMS AND CONDITIONS. diff --git a/new-luxc/project.clj b/new-luxc/project.clj index b92276a50..5cf1e9a4e 100644 --- a/new-luxc/project.clj +++ b/new-luxc/project.clj @@ -20,23 +20,22 @@ :dependencies [;; JVM Bytecode [org.ow2.asm/asm-all "5.0.3"] - ;; Lua - [net.sandius.rembulan/rembulan-runtime "0.1-SNAPSHOT"] - [net.sandius.rembulan/rembulan-stdlib "0.1-SNAPSHOT"] - [net.sandius.rembulan/rembulan-compiler "0.1-SNAPSHOT"] - ;; Ruby - [org.jruby/jruby-complete "9.1.16.0"] - ;; Python - [org.python/jython-standalone "2.7.1"] - ;; R - [org.renjin/renjin-script-engine "0.8.2527"] - ;; Scheme - [kawa-scheme/kawa-core "2.4"] - ;; Common Lisp - [org.abcl/abcl "1.5.0"] - ;; PHP 5 - [org.develnext.jphp/jphp-core "0.9.2"] - [org.develnext.jphp/jphp-scripting "0.9.2"]] + ;; ;; Lua + ;; [net.sandius.rembulan/rembulan-runtime "0.1-SNAPSHOT"] + ;; [net.sandius.rembulan/rembulan-stdlib "0.1-SNAPSHOT"] + ;; [net.sandius.rembulan/rembulan-compiler "0.1-SNAPSHOT"] + ;; ;; Ruby + ;; [org.jruby/jruby-complete "9.1.16.0"] + ;; ;; Python + ;; [org.python/jython-standalone "2.7.1"] + ;; ;; Scheme + ;; [kawa-scheme/kawa-core "2.4"] + ;; ;; Common Lisp + ;; [org.abcl/abcl "1.5.0"] + ;; ;; PHP 5 + ;; [org.develnext.jphp/jphp-core "0.9.2"] + ;; [org.develnext.jphp/jphp-scripting "0.9.2"] + ] :source-paths ["source"] :test-paths ["test"] diff --git a/new-luxc/source/luxc/lang/translation/r.lux b/new-luxc/source/luxc/lang/translation/r.lux index 7dc84700f..a013bfd1c 100644 --- a/new-luxc/source/luxc/lang/translation/r.lux +++ b/new-luxc/source/luxc/lang/translation/r.lux @@ -48,9 +48,6 @@ (host.import: javax/script/ScriptEngineFactory (getScriptEngine [] ScriptEngine)) -(host.import: org/renjin/script/RenjinScriptEngineFactory - (new [])) - (type: #export Anchor [Text Register]) (type: #export Host @@ -63,7 +60,7 @@ (def: #export init (IO Host) - (io (let [interpreter (|> (RenjinScriptEngineFactory::new []) + (io (let [interpreter (|> (undefined) (ScriptEngineFactory::getScriptEngine []))] {#context ["" +0] #anchor #.None diff --git a/new-luxc/source/luxc/lang/translation/r/eval.jvm.lux b/new-luxc/source/luxc/lang/translation/r/eval.jvm.lux deleted file mode 100644 index 0bfd50aa8..000000000 --- a/new-luxc/source/luxc/lang/translation/r/eval.jvm.lux +++ /dev/null @@ -1,154 +0,0 @@ -(.module: - lux - (lux (control ["ex" exception #+ exception:] - [monad #+ do]) - (data [bit] - [maybe] - ["e" error #+ Error] - text/format - (coll [array])) - [host]) - (luxc [lang] - (lang (host [r #+ Expression]))) - [//]) - -(do-template [<name>] - [(exception: #export (<name> {message Text}) - message)] - - [Unknown-Kind-Of-Host-Object] - [Null-Has-No-Lux-Representation] - [Cannot-Evaluate] - ) - -(host.import: java/lang/Object - (toString [] String) - (getClass [] (Class Object))) - -(host.import: java/lang/Long - (intValue [] Integer)) - -(host.import: org/renjin/sexp/SEXP) - -(host.import: org/renjin/sexp/StringArrayVector - (getElementAsString [int] String)) - -(host.import: org/renjin/sexp/LogicalArrayVector - (getElementAsRawLogical [int] int)) - -(host.import: org/renjin/sexp/IntArrayVector - (getElementAsInt [int] int)) - -(host.import: org/renjin/sexp/DoubleArrayVector - (getElementAsDouble [int] double)) - -(host.import: org/renjin/sexp/ListVector - (length [] int) - (getElementAsSEXP [int] #try SEXP) - (getElementAsSEXP #as get-field-sexp [String] #try SEXP)) - -(host.import: org/renjin/sexp/Null) - -(def: (parse-tuple lux-object host-object) - (-> (-> Object (Error Any)) ListVector (Error Any)) - (let [size (:coerce Nat (ListVector::length [] host-object))] - (loop [idx +0 - output (:coerce (Array Any) (array.new size))] - (if (n/< size idx) - (case (ListVector::getElementAsSEXP [(:coerce Int idx)] host-object) - (#e.Error error) - (#e.Error error) - - (#e.Success value) - (case (lux-object (:coerce Object value)) - (#e.Error error) - (#e.Error error) - - (#e.Success lux-value) - (recur (inc idx) (array.write idx (:coerce Any lux-value) output)))) - (#e.Success output))))) - -(def: (parse-variant lux-object host-object) - (-> (-> Object (Error Any)) ListVector (Error Any)) - (do e.Monad<Error> - [tag (ListVector::get-field-sexp [//.variant-tag-field] host-object) - flag (ListVector::get-field-sexp [//.variant-flag-field] host-object) - value (ListVector::get-field-sexp [//.variant-value-field] host-object) - value (lux-object (:coerce Object value))] - (wrap [(|> tag - (:coerce IntArrayVector) - (IntArrayVector::getElementAsInt [0]) - (Long::intValue [])) - (: Any - (if (host.instance? Null flag) - (host.null) - //.unit)) - value]))) - -(def: (parse-int host-object) - (-> ListVector (Error Int)) - (do e.Monad<Error> - [high (ListVector::get-field-sexp [//.int-high-field] host-object) - low (ListVector::get-field-sexp [//.int-low-field] host-object) - #let [get-int-32 (|>> (IntArrayVector::getElementAsInt [0]) (:coerce Nat)) - high (get-int-32 (:coerce IntArrayVector high)) - low (get-int-32 (:coerce IntArrayVector low))]] - (wrap (:coerce Int - (n/+ (|> high (bit.left-shift +32)) - (if (i/< 0 (:coerce Int low)) - (|> low (bit.left-shift +32) (bit.logical-right-shift +32)) - low)))))) - -(def: (lux-object host-object) - (-> Object (Error Any)) - (cond (host.instance? StringArrayVector host-object) - (#e.Success (StringArrayVector::getElementAsString [0] (:coerce StringArrayVector host-object))) - - (host.instance? LogicalArrayVector host-object) - (#e.Success (i/= 1 (LogicalArrayVector::getElementAsRawLogical [0] (:coerce LogicalArrayVector host-object)))) - - (host.instance? IntArrayVector host-object) - (#e.Success (IntArrayVector::getElementAsInt [0] (:coerce IntArrayVector host-object))) - - (host.instance? DoubleArrayVector host-object) - (#e.Success (DoubleArrayVector::getElementAsDouble [0] (:coerce DoubleArrayVector host-object))) - - (host.instance? ListVector host-object) - (case (parse-int (:coerce ListVector host-object)) - (#e.Error error) - (case (parse-variant lux-object (:coerce ListVector host-object)) - (#e.Error error) - (parse-tuple lux-object (:coerce ListVector host-object)) - - output - output) - - output - output) - - ## else - (let [object-class (:coerce Text (Object::toString [] (Object::getClass [] (:coerce Object host-object)))) - text-representation (:coerce Text (Object::toString [] (:coerce Object host-object)))] - (ex.throw Unknown-Kind-Of-Host-Object (format object-class " --- " text-representation))))) - -(def: #export (eval code) - (-> Expression (Meta Any)) - (function (_ compiler) - (let [interpreter (|> compiler (get@ #.host) (:coerce //.Host) (get@ #//.interpreter))] - (case (interpreter code) - (#e.Error error) - (exec (log! (format "eval #e.Error\n" - "<< " (r.expression code) "\n" - error)) - ((lang.throw Cannot-Evaluate error) compiler)) - - (#e.Success output) - (case (lux-object output) - (#e.Success parsed-output) - (#e.Success [compiler parsed-output]) - - (#e.Error error) - (exec (log! (format "eval #e.Error\n" - "<< " (r.expression code) "\n" - error)) - ((lang.throw Cannot-Evaluate error) compiler))))))) diff --git a/stdlib/project.clj b/stdlib/project.clj index 4d01ffed4..53ad8718c 100644 --- a/stdlib/project.clj +++ b/stdlib/project.clj @@ -16,7 +16,6 @@ :scm {:name "git" :url "https://github.com/LuxLang/lux.git"} - :jvm-opts ["-Xss4m"] :dependencies [] :source-paths ["source"] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index ffb7bc592..b73e7df02 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -293,24 +293,3 @@ (i64.xor (i64.left-shift 14 s01))) (i64.rotate-left 36 s01)])) ("lux i64 +" s0 s1)])) - -(def: (swap from to vec) - (All [a] (-> Nat Nat (Row a) (Row a))) - (|> vec - (row.put to (maybe.assume (row.nth from vec))) - (row.put from (maybe.assume (row.nth to vec))))) - -(def: #export (shuffle seed row) - {#.doc "Shuffle a row randomly based on a seed value."} - (All [a] (-> Nat (Row a) (Row a))) - (let [_size (row.size row) - _shuffle (monad.fold Monad<Random> - (function (_ idx vec) - (do Monad<Random> - [rand nat] - (wrap (swap idx (n/% _size rand) vec)))) - row - (list.indices _size))] - (|> _shuffle - (run (pcg-32 [123 seed])) - product.right))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 20ef20c8c..a39e6f9ed 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -108,76 +108,3 @@ (structure: #export _ (Monoid Duration) (def: identity empty) (def: compose merge)) - -(def: (encode duration) - (-> Duration Text) - (if (:: Equivalence<Duration> = empty duration) - "+0ms" - (let [signed? (negative? duration) - [days time-left] [(query day duration) (frame day duration)] - days (if signed? - (int/abs days) - days) - time-left (if signed? - (scale-up -1 time-left) - time-left) - [hours time-left] [(query hour time-left) (frame hour time-left)] - [minutes time-left] [(query minute time-left) (frame minute time-left)] - [seconds time-left] [(query second time-left) (frame second time-left)] - millis (to-millis time-left)] - ($_ text/compose - (if signed? "-" "+") - (if (i/= +0 days) "" (text/compose (nat/encode (.nat days)) "D")) - (if (i/= +0 hours) "" (text/compose (nat/encode (.nat hours)) "h")) - (if (i/= +0 minutes) "" (text/compose (nat/encode (.nat minutes)) "m")) - (if (i/= +0 seconds) "" (text/compose (nat/encode (.nat seconds)) "s")) - (if (i/= +0 millis) "" (text/compose (nat/encode (.nat millis)) "ms")) - )))) - -(def: (lex-section suffix) - (-> Text (l.Lexer Int)) - (|> (p.codec number.Codec<Text,Int> (l.many l.decimal)) - (p.before (p.and (l.this suffix) (p.not l.alpha))) - (p.default +0))) - -(def: lex-duration - (l.Lexer Duration) - (do p.Monad<Parser> - [signed? (p.or (l.this? "-") (l.this? "+")) - #let [sign (function (_ raw) - (case signed? - (#.Left _) - (i/* -1 raw) - - (#.Right _) - raw))] - utc-day (lex-section "D") - utc-hour (lex-section "h") - utc-minute (lex-section "m") - _ (p.assert "Invalid minute." - (and (i/>= +0 utc-minute) - (i/<= +59 utc-minute))) - utc-second (lex-section "s") - _ (p.assert "Invalid second." - (and (i/>= +0 utc-second) - (i/<= +59 utc-second))) - utc-millis (lex-section "ms") - _ (p.assert "Invalid milli-seconds." - (and (i/>= +0 utc-millis) - (i/<= +999 utc-millis)))] - (wrap (|> empty - (merge (scale-up (sign utc-day) day)) - (merge (scale-up (sign utc-hour) hour)) - (merge (scale-up (sign utc-minute) minute)) - (merge (scale-up (sign utc-second) second)) - (merge (scale-up (sign utc-millis) milli)))))) - -(def: (decode input) - (-> Text (e.Error Duration)) - (l.run input lex-duration)) - -(structure: #export _ - {#.doc "For example: +15D21h14m51s827ms"} - (Codec Text Duration) - (def: encode encode) - (def: decode decode)) diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux index f3f118c90..a7f126ef3 100644 --- a/stdlib/test/test/lux/math/random.lux +++ b/stdlib/test/test/lux/math/random.lux @@ -28,11 +28,7 @@ _set (r.set number.Hash<Nat> size r.nat) _dict (r.dictionary number.Hash<Nat> size r.nat r.nat) top r.nat - filtered (|> r.nat (r.filter (n/<= top))) - shuffle-seed r.nat - #let [sorted (|> _row row.to-list (list.sort n/<)) - shuffled (|> sorted row.from-list (r.shuffle shuffle-seed)) - re-sorted (|> shuffled row.to-list (list.sort n/<))]] + filtered (|> r.nat (r.filter (n/<= top)))] ($_ seq (test "Can produce lists." (n/= size (list.size _list))) @@ -50,9 +46,4 @@ (n/= size (dict.size _dict))) (test "Can filter values." (n/<= top filtered)) - (test "Can shuffle rows." - (let [(^open "v/.") (row.Equivalence<Row> number.Equivalence<Nat>) - sorted (row.from-list sorted)] - (and (not (v/= sorted shuffled)) - (v/= sorted (row.from-list re-sorted))))) )))) diff --git a/stdlib/test/test/lux/time/duration.lux b/stdlib/test/test/lux/time/duration.lux index 669af6b4c..8bf00b88b 100644 --- a/stdlib/test/test/lux/time/duration.lux +++ b/stdlib/test/test/lux/time/duration.lux @@ -57,30 +57,4 @@ (test "Merging with the empty duration changes nothing." (|> sample (@.merge @.empty) (@/= sample))) (test "Merging a duration with it's opposite yields an empty duration." - (|> sample (@.merge (@.scale-up -1 sample)) (@/= @.empty))) - (test "Can frame a duration in terms of another." - (cond (and (@.positive? frame) (@.positive? sample)) - (|> sample (@.frame frame) (@/< frame)) - - (and (@.negative? frame) (@.negative? sample)) - (|> sample (@.frame frame) (@/> frame)) - - (or (or (@.neutral? frame) (@.neutral? sample)) - (|> sample - (@.frame frame) - (@.scale-up -1) - (@/< (if (@.negative? frame) - (@.scale-up -1 frame) - frame)))))))))) - -(context: "Codec" - (<| (times 100) - (do @ - [sample duration - #let [(^open "@/.") @.Equivalence<Duration> - (^open "@/.") @.Codec<Text,Duration>]] - (test "Can encode/decode durations." - (E.default #0 - (do E.Monad<Error> - [decoded (|> sample @/encode @/decode)] - (wrap (@/= sample decoded)))))))) + (|> sample (@.merge (@.scale-up -1 sample)) (@/= @.empty))))))) |