├── .gitignore ├── LICENSE ├── README.md ├── example ├── .gitignore ├── LICENSE ├── README.md ├── project.clj ├── src │ ├── example │ │ └── core.clj │ └── frege │ │ └── Fibonacci.fr └── test │ └── example │ └── core_test.clj ├── hello ├── .gitignore ├── Hello.fr ├── README.md └── project.clj ├── project.clj ├── src └── leiningen │ └── fregec.clj └── update-version.sh /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | pom.xml.asc 3 | *jar 4 | /lib/ 5 | /classes/ 6 | /target/ 7 | /checkouts/ 8 | .lein-deps-sum 9 | .lein-repl-history 10 | .lein-plugins/ 11 | .lein-failures 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Frege 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of frege-lein-template nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | lein-fregec 2 | =========== 3 | 4 | A Leiningen plugin to compile Frege (http://www.frege-lang.org) code. 5 | 6 | Usage - Simple 7 | ----- 8 | 9 | The easiest way to use Leiningen with Frege (or with Clojure and Frege) is to take advantage of the `frege` template -- 10 | [frege-lein-template](https://github.com/Frege/frege-lein-template) -- to create a new Leiningen project for either a pure Frege project or a mixed Clojure / Frege project (with a Clojure main entry point): 11 | 12 | lein new frege myapp 13 | 14 | This will create a folder called `myapp` containing a Leiningen project with an example of a pure Frege program in it. If you want a mixed Clojure / Frege project: 15 | 16 | lein new frege myapp -- :with-clojure 17 | 18 | The Frege template will always set up a project with the most recent stable version of Frege. If you want to modify the `project.clj` file, read the section below on what settings are available. 19 | 20 | Usage - Manual 21 | ----- 22 | 23 | If you already have a Leiningen project, you can add this plugin as follows: 24 | 25 | Add `[lein-fregec "3.24-7.100"]` to `:plugins` in your `project.clj`. The version of `lein-fregec` matches the version of the Frege compiler it is compatible with and uses. 26 | 27 | Usage - Configuration & Execution 28 | ----- 29 | 30 | Set `:frege-source-paths` to the location(s) of your Frege source files. Default is the current directory but I highly recommend using `src/frege` and structuring your projects that way (although the `hello` example relies on current directory). The template generates projects that either use `src` (pure Frege) or `src/frege` (mixed Clojure / Frege). 31 | 32 | If you created `project.clj` manually, rather than via the `frege` template -- or you are upgrading an older `project.clj` file -- then you must tell the Frege compiler to target Java 7 explicitly, either in `project.clj`: 33 | 34 | ```clojure 35 | :fregec-options ["-target" "1.7"] 36 | ``` 37 | 38 | or via the command line (see below for more about Frege compiler options): 39 | 40 | ```sh 41 | lein fregec :target 1.7 42 | ``` 43 | 44 | That is added to `project.clj` automatically by the 3.24-7.100 version of the `frege` template. 45 | 46 | Run `lein fregec` to compile Frege source files to `.class` files. 47 | 48 | The output of compilation will go to the `:compile-path` directory, which defaults to `target/classes/` in Leiningen. 49 | 50 | You may specify additional Frege compiler options via `:fregec-options` in `project.clj` (as a vector of strings) or via the command line. Note that command line options for Leiningen tasks start with `:` (and are converted to `-` options automatically): 51 | 52 | ```sh 53 | lein fregec :v 54 | ``` 55 | 56 | This will pass `-v` to the Frege compiler (verbose mode). If you want to see the full list of options being passed to the Frege compiler, set the `DEBUG` environment variable to `true`: 57 | 58 | ```sh 59 | DEBUG=true lein fregec 60 | ``` 61 | 62 | This will also display the exact version of the Frege compiler that the plugin is using. 63 | 64 | Run `lein uberjar` to compile Frege source files and create a JAR file in the `target/` folder. You need to ensure that Frege compilation is part of the `:uberjar` profile in `project.clj`: 65 | 66 | ```clojure 67 | :profiles {:uberjar {:aot :all 68 | :prep-tasks ["fregec" "compile"]}} 69 | ``` 70 | 71 | This tells Leiningen to run the `fregec` task and the `compile` task before building the JAR file. That will run the Frege compiler and also compile any Clojure code in the project. 72 | 73 | Also, in order to include the Frege runtime in the resulting JAR file, you will need the following dependency in your `project.clj` file: 74 | 75 | ```clojure 76 | :dependencies [[org.frege-lang/frege "3.24-7.100]] 77 | ``` 78 | 79 | The version here should exactly match that displayed by `lein-fregec` when you use the `DEBUG=true` environment variable! 80 | 81 | This tells Leiningen that your project depends on Frege, and it will package it into the standalone JAR it produces. The standalone JAR can be run as follows: 82 | 83 | ```sh 84 | java -cp target/frege-hello-0.1.0-SNAPSHOT-standalone.jar Hello 85 | ``` 86 | 87 | This assumes your `project.clj` starts out like this: 88 | 89 | ```clojure 90 | (defproject frege-hello "0.1.0-SNAPSHOT" 91 | ...) 92 | ``` 93 | 94 | You can also run your (pure Frege) code by specifying `:run` and the class name (followed by any arguments for your `main` method): 95 | 96 | ```sh 97 | lein fregec :run Hello 98 | ``` 99 | 100 | Arguments to the Frege compiler should come before `:run` (and can use `:` or `-` to introduce them). Arguments to the program being run should come after the class name (and are passed exactly as-is). 101 | 102 | If you have tests, you can run those using `:test`: 103 | 104 | ```sh 105 | lein fregec :test HelloTest 106 | ``` 107 | 108 | This is equivalent to: 109 | 110 | ```sh 111 | lein fregec :run frege.tools.Quick HelloTest 112 | ``` 113 | 114 | You can pass flags to QuickCheck like this: 115 | 116 | ```sh 117 | lein fregec :test -v HelloTest 118 | ``` 119 | 120 | which is equivalent to: 121 | 122 | ```sh 123 | lein fregec :run frege.tools.Quick -v HelloTest 124 | ``` 125 | 126 | There will also be a non-standalone JAR will which does not contain the Frege runtime. 127 | 128 | An example of a pure Frege project can be found in the [hello directory](https://github.com/Frege/frege-lein-plugin/tree/master/hello) which is a self-contained Leiningen project with its own README. 129 | 130 | An example of mixed Clojure / Frege usage can be found in the [example directory](https://github.com/Frege/frege-lein-plugin/tree/master/example) which is also a self-contained project. 131 | 132 | License 133 | ------- 134 | 135 | Copyright (c) 2014-2016 Sean Corfield 136 | 137 | Distributed under the BSD License, the same as Frege. 138 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | -------------------------------------------------------------------------------- /example/LICENSE: -------------------------------------------------------------------------------- 1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and 10 | documentation distributed under this Agreement, and 11 | 12 | b) in the case of each subsequent Contributor: 13 | 14 | i) changes to the Program, and 15 | 16 | ii) additions to the Program; 17 | 18 | where such changes and/or additions to the Program originate from and are 19 | distributed by that particular Contributor. A Contribution 'originates' from 20 | a Contributor if it was added to the Program by such Contributor itself or 21 | anyone acting on such Contributor's behalf. Contributions do not include 22 | additions to the Program which: (i) are separate modules of software 23 | distributed in conjunction with the Program under their own license 24 | agreement, and (ii) are not derivative works of the Program. 25 | 26 | "Contributor" means any person or entity that distributes the Program. 27 | 28 | "Licensed Patents" mean patent claims licensable by a Contributor which are 29 | necessarily infringed by the use or sale of its Contribution alone or when 30 | combined with the Program. 31 | 32 | "Program" means the Contributions distributed in accordance with this 33 | Agreement. 34 | 35 | "Recipient" means anyone who receives the Program under this Agreement, 36 | including all Contributors. 37 | 38 | 2. GRANT OF RIGHTS 39 | 40 | a) Subject to the terms of this Agreement, each Contributor hereby grants 41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 42 | reproduce, prepare derivative works of, publicly display, publicly perform, 43 | distribute and sublicense the Contribution of such Contributor, if any, and 44 | such derivative works, in source code and object code form. 45 | 46 | b) Subject to the terms of this Agreement, each Contributor hereby grants 47 | Recipient a non-exclusive, worldwide, royalty-free patent license under 48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 49 | transfer the Contribution of such Contributor, if any, in source code and 50 | object code form. This patent license shall apply to the combination of the 51 | Contribution and the Program if, at the time the Contribution is added by the 52 | Contributor, such addition of the Contribution causes such combination to be 53 | covered by the Licensed Patents. The patent license shall not apply to any 54 | other combinations which include the Contribution. No hardware per se is 55 | licensed hereunder. 56 | 57 | c) Recipient understands that although each Contributor grants the licenses 58 | to its Contributions set forth herein, no assurances are provided by any 59 | Contributor that the Program does not infringe the patent or other 60 | intellectual property rights of any other entity. Each Contributor disclaims 61 | any liability to Recipient for claims brought by any other entity based on 62 | infringement of intellectual property rights or otherwise. As a condition to 63 | exercising the rights and licenses granted hereunder, each Recipient hereby 64 | assumes sole responsibility to secure any other intellectual property rights 65 | needed, if any. For example, if a third party patent license is required to 66 | allow Recipient to distribute the Program, it is Recipient's responsibility 67 | to acquire that license before distributing the Program. 68 | 69 | d) Each Contributor represents that to its knowledge it has sufficient 70 | copyright rights in its Contribution, if any, to grant the copyright license 71 | set forth in this Agreement. 72 | 73 | 3. REQUIREMENTS 74 | 75 | A Contributor may choose to distribute the Program in object code form under 76 | its own license agreement, provided that: 77 | 78 | a) it complies with the terms and conditions of this Agreement; and 79 | 80 | b) its license agreement: 81 | 82 | i) effectively disclaims on behalf of all Contributors all warranties and 83 | conditions, express and implied, including warranties or conditions of title 84 | and non-infringement, and implied warranties or conditions of merchantability 85 | and fitness for a particular purpose; 86 | 87 | ii) effectively excludes on behalf of all Contributors all liability for 88 | damages, including direct, indirect, special, incidental and consequential 89 | damages, such as lost profits; 90 | 91 | iii) states that any provisions which differ from this Agreement are offered 92 | by that Contributor alone and not by any other party; and 93 | 94 | iv) states that source code for the Program is available from such 95 | Contributor, and informs licensees how to obtain it in a reasonable manner on 96 | or through a medium customarily used for software exchange. 97 | 98 | When the Program is made available in source code form: 99 | 100 | a) it must be made available under this Agreement; and 101 | 102 | b) a copy of this Agreement must be included with each copy of the Program. 103 | 104 | Contributors may not remove or alter any copyright notices contained within 105 | the Program. 106 | 107 | Each Contributor must identify itself as the originator of its Contribution, 108 | if any, in a manner that reasonably allows subsequent Recipients to identify 109 | the originator of the Contribution. 110 | 111 | 4. COMMERCIAL DISTRIBUTION 112 | 113 | Commercial distributors of software may accept certain responsibilities with 114 | respect to end users, business partners and the like. While this license is 115 | intended to facilitate the commercial use of the Program, the Contributor who 116 | includes the Program in a commercial product offering should do so in a 117 | manner which does not create potential liability for other Contributors. 118 | Therefore, if a Contributor includes the Program in a commercial product 119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend 120 | and indemnify every other Contributor ("Indemnified Contributor") against any 121 | losses, damages and costs (collectively "Losses") arising from claims, 122 | lawsuits and other legal actions brought by a third party against the 123 | Indemnified Contributor to the extent caused by the acts or omissions of such 124 | Commercial Contributor in connection with its distribution of the Program in 125 | a commercial product offering. The obligations in this section do not apply 126 | to any claims or Losses relating to any actual or alleged intellectual 127 | property infringement. In order to qualify, an Indemnified Contributor must: 128 | a) promptly notify the Commercial Contributor in writing of such claim, and 129 | b) allow the Commercial Contributor tocontrol, and cooperate with the 130 | Commercial Contributor in, the defense and any related settlement 131 | negotiations. The Indemnified Contributor may participate in any such claim 132 | at its own expense. 133 | 134 | For example, a Contributor might include the Program in a commercial product 135 | offering, Product X. That Contributor is then a Commercial Contributor. If 136 | that Commercial Contributor then makes performance claims, or offers 137 | warranties related to Product X, those performance claims and warranties are 138 | such Commercial Contributor's responsibility alone. Under this section, the 139 | Commercial Contributor would have to defend claims against the other 140 | Contributors related to those performance claims and warranties, and if a 141 | court requires any other Contributor to pay any damages as a result, the 142 | Commercial Contributor must pay those damages. 143 | 144 | 5. NO WARRANTY 145 | 146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON 147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR 149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A 150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the 151 | appropriateness of using and distributing the Program and assumes all risks 152 | associated with its exercise of rights under this Agreement , including but 153 | not limited to the risks and costs of program errors, compliance with 154 | applicable laws, damage to or loss of data, programs or equipment, and 155 | unavailability or interruption of operations. 156 | 157 | 6. DISCLAIMER OF LIABILITY 158 | 159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 166 | OF SUCH DAMAGES. 167 | 168 | 7. GENERAL 169 | 170 | If any provision of this Agreement is invalid or unenforceable under 171 | applicable law, it shall not affect the validity or enforceability of the 172 | remainder of the terms of this Agreement, and without further action by the 173 | parties hereto, such provision shall be reformed to the minimum extent 174 | necessary to make such provision valid and enforceable. 175 | 176 | If Recipient institutes patent litigation against any entity (including a 177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 178 | (excluding combinations of the Program with other software or hardware) 179 | infringes such Recipient's patent(s), then such Recipient's rights granted 180 | under Section 2(b) shall terminate as of the date such litigation is filed. 181 | 182 | All Recipient's rights under this Agreement shall terminate if it fails to 183 | comply with any of the material terms or conditions of this Agreement and 184 | does not cure such failure in a reasonable period of time after becoming 185 | aware of such noncompliance. If all Recipient's rights under this Agreement 186 | terminate, Recipient agrees to cease use and distribution of the Program as 187 | soon as reasonably practicable. However, Recipient's obligations under this 188 | Agreement and any licenses granted by Recipient relating to the Program shall 189 | continue and survive. 190 | 191 | Everyone is permitted to copy and distribute copies of this Agreement, but in 192 | order to avoid inconsistency the Agreement is copyrighted and may only be 193 | modified in the following manner. The Agreement Steward reserves the right to 194 | publish new versions (including revisions) of this Agreement from time to 195 | time. No one other than the Agreement Steward has the right to modify this 196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 197 | Eclipse Foundation may assign the responsibility to serve as the Agreement 198 | Steward to a suitable separate entity. Each new version of the Agreement will 199 | be given a distinguishing version number. The Program (including 200 | Contributions) may always be distributed subject to the version of the 201 | Agreement under which it was received. In addition, after a new version of 202 | the Agreement is published, Contributor may elect to distribute the Program 203 | (including its Contributions) under the new version. Except as expressly 204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 205 | licenses to the intellectual property of any Contributor under this 206 | Agreement, whether expressly, by implication, estoppel or otherwise. All 207 | rights in the Program not expressly granted under this Agreement are 208 | reserved. 209 | 210 | This Agreement is governed by the laws of the State of New York and the 211 | intellectual property laws of the United States of America. No party to this 212 | Agreement will bring a legal action under this Agreement more than one year 213 | after the cause of action arose. Each party waives its rights to a jury trial 214 | in any resulting litigation. 215 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # lein-fregec Clojure / Frege example 2 | 3 | Example of Clojure / Frege mixed language project. Clojure main program calls Frege function. 4 | 5 | ## Installation 6 | 7 | Download from https://github.com/Frege/frege-lein-plugin. 8 | 9 | ## Usage 10 | 11 | Run the Frege compiler and then run the Clojure application: 12 | 13 | lein do fregec, run 14 | 15 | Run the Clojure tests (which exercise the Frege functions): 16 | 17 | lein do fregec, test 18 | 19 | You can also package up all the Clojure and Frege code and their runtimes: 20 | 21 | lein uberjar 22 | 23 | That produces a JAR file which you can run: 24 | 25 | java -jar target/example-0.1.0-SNAPSHOT-standalone.jar 26 | 27 | ## License 28 | 29 | Copyright (c) 2014-2015 Sean Corfield 30 | 31 | Distributed under the BSD 3-clause License, the same as Frege itself. 32 | 33 | -------------------------------------------------------------------------------- /example/project.clj: -------------------------------------------------------------------------------- 1 | (defproject example "0.1.0-SNAPSHOT" 2 | :description "Example Clojure / Frege mixed language application" 3 | :url "http://example.com/FIXME" 4 | :license {:name "BSD 3-clause" 5 | :url "http://opensource.org/licenses/BSD-3-Clause"} 6 | :dependencies [[org.clojure/clojure "1.7.0"] 7 | ;; need to depend on Frege for runtime: 8 | [org.frege-lang/frege "3.24-7.100"]] 9 | :plugins [[lein-fregec "3.24-7.100"]] 10 | :frege-source-paths ["src/frege"] 11 | :main example.core 12 | :profiles {:uberjar {:aot :all 13 | :prep-tasks ["fregec" "compile"]}}) 14 | -------------------------------------------------------------------------------- /example/src/example/core.clj: -------------------------------------------------------------------------------- 1 | (ns example.core 2 | (:import Fibonacci) 3 | (:gen-class)) 4 | 5 | (defn -main 6 | "I don't do a whole lot ... yet." 7 | [& args] 8 | (println "Hello, World!") 9 | (doseq [n (range 10)] 10 | (println "Fibonacci number" n "is" (Fibonacci/fib n)))) 11 | -------------------------------------------------------------------------------- /example/src/frege/Fibonacci.fr: -------------------------------------------------------------------------------- 1 | module Fibonacci where 2 | 3 | -- lazy infinite sequence of Fibonacci numbers starting with a, b: 4 | fibs a b = a : fibs b (a + b) 5 | 6 | -- lazy infinite sequence of Fibonacci numbers (0, 1, 1, 2, 3, ...): 7 | -- using 0L and 1L instead of 0 and 1 ensure type is inferred as [Long] 8 | fibonacci = fibs 0L 1L 9 | 10 | -- exposed API infers type as Long -> Long: 11 | -- drop takes an Int so we need to cast from Long 12 | fib n = head $ drop (Long.int n) $ fibonacci 13 | -------------------------------------------------------------------------------- /example/test/example/core_test.clj: -------------------------------------------------------------------------------- 1 | (ns example.core-test 2 | (:require [clojure.test :refer :all] 3 | [example.core :refer :all]) 4 | (:import Fibonacci)) 5 | 6 | (deftest test-fib 7 | (is (= 0 (Fibonacci/fib 0))) 8 | (is (= 1 (Fibonacci/fib 1))) 9 | (is (= 1 (Fibonacci/fib 2))) 10 | (is (= 55 (Fibonacci/fib 10)))) 11 | -------------------------------------------------------------------------------- /hello/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | -------------------------------------------------------------------------------- /hello/Hello.fr: -------------------------------------------------------------------------------- 1 | module Hello where 2 | 3 | main _ = do 4 | println "Hello World!" 5 | -------------------------------------------------------------------------------- /hello/README.md: -------------------------------------------------------------------------------- 1 | # lein-fregec Frege example 2 | 3 | Example of standalone Frege project. 4 | 5 | ## Installation 6 | 7 | Download from https://github.com/Frege/frege-lein-plugin. 8 | 9 | ## Usage 10 | 11 | Run the Frege compiler to verify the code compiles: 12 | 13 | lein fregec 14 | 15 | Create a JAR file containing the application and the Frege runtime: 16 | 17 | lein uberjar 18 | 19 | Run the application: 20 | 21 | java -cp target/frege-hello-0.1.0-SNAPSHOT-standalone.jar Hello 22 | 23 | Note that you can also run the application without creating a JAR file after `lein fregec` if you specify the classpath that includes the Frege runtime: 24 | 25 | java -cp ~/.m2/repository/org/frege-lang/frege/3.24-7.100/frege-3.24-7.100.jar:target/classes Hello 26 | 27 | A simpler, but slower way to achieve that is to rely on Leiningen to retrieve the necessary classpath: 28 | 29 | java -cp `lein classpath` Hello 30 | 31 | Or you can simply run it using `lein-fregec` itself immediately after the compile: 32 | 33 | lein fregec :run Hello 34 | 35 | ## License 36 | 37 | Copyright (c) 2014-2015 Sean Corfield 38 | 39 | Distributed under the BSD 3-clause License, the same as Frege itself. 40 | 41 | -------------------------------------------------------------------------------- /hello/project.clj: -------------------------------------------------------------------------------- 1 | (defproject frege-hello "0.1.0-SNAPSHOT" 2 | :description "Example standalone Frege application" 3 | :url "http://example.com/FIXME" 4 | :license {:name "BSD 3-clause" 5 | :url "http://opensource.org/licenses/BSD-3-Clause"} 6 | :dependencies [;; need to depend on Frege for uberjar: 7 | [org.frege-lang/frege "3.24-7.100"]] 8 | :plugins [[lein-fregec "3.24-7.100"]] 9 | :fregec-options ["-target" "1.7"] 10 | :profiles {:uberjar {:prep-tasks ["fregec"]}}) 11 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject lein-fregec "3.24-7.100c" 2 | :description "Leiningen plugin to compile Frege source code" 3 | :url "https://github.com/Frege/frege-lein-plugin" 4 | :license {:name "BSD 3-clause" 5 | :url "http://opensource.org/licenses/BSD-3-Clause"} 6 | :eval-in :leiningen) 7 | -------------------------------------------------------------------------------- /src/leiningen/fregec.clj: -------------------------------------------------------------------------------- 1 | ;; copyright (c) 2014-2015 Sean Corfield 2 | 3 | (ns leiningen.fregec 4 | (:require [clojure.string :as str] 5 | [clojure.java.io :as io] 6 | [leiningen.core.classpath :as cp] 7 | [leiningen.core.eval :as eval] 8 | [leiningen.core.project :as project]) 9 | (:import java.io.File 10 | (java.nio.file Files Paths))) 11 | 12 | (def ^:private fregec-version "3.24-7.100") 13 | 14 | (defn- stale-frege-sources 15 | "Returns a lazy seq of file paths: every Frege source file within dirs modified 16 | since it was most recently compiled into compile-path." 17 | [dirs compile-path] 18 | (for [dir dirs 19 | ^File source (filter #(-> ^File % (.getName) (.endsWith ".fr")) 20 | (file-seq (io/file dir))) 21 | :let [rel-source (.substring (.getPath source) (inc (count dir))) 22 | rel-compiled (.replaceFirst rel-source "\\.fr$" ".class") 23 | compiled (io/file compile-path rel-compiled)] 24 | :when (>= (.lastModified source) (.lastModified compiled))] 25 | (.getPath source))) 26 | 27 | (defn- subprocess-compiler-form 28 | "Build a form that can run the Frege compiler in a sub-process." 29 | [fregec-args] 30 | `(binding [*out* *err*] 31 | (when-not (frege.compiler.Main/runCompiler (into-array String ~fregec-args)) 32 | (println "Frege compilation failed!") 33 | (System/exit 1)))) 34 | 35 | (def ^:private subprocess-profile 36 | {:dependencies [^:displace ['org.clojure/clojure (clojure-version)] 37 | ['org.frege-lang/frege fregec-version]] 38 | :eval-in :subprocess}) 39 | 40 | (defn- file-exists 41 | "Given a path, return true if it exists as a file." 42 | [path] 43 | (.exists (io/file path))) 44 | 45 | (defn- additional-fregec-args 46 | "Given command line arguments, convert to Frege compiler arguments." 47 | [args] 48 | (map (fn [^String arg] (if (.startsWith arg ":") 49 | (str "-" (subs arg 1)) 50 | arg)) args)) 51 | 52 | (def ^:private valid-ops 53 | "Valid command line arguments that affect plugin behavior." 54 | #{":run" ":test"}) 55 | 56 | (defn- run-class-args 57 | "Given command line arguments, extract keyword arg and ClassName. 58 | Returns a vector of the keyword arg (or nil), the ClassName (or nil), the args 59 | before the keyword arg, and the args after the ClassName." 60 | [args] 61 | (let [[before & [[kw arg & run-args]]] (split-with (fn [arg] (not (valid-ops arg))) args)] 62 | (if (and kw arg) 63 | [(keyword (subs kw 1)) arg before run-args] 64 | [nil nil args nil]))) 65 | 66 | (defn- run-main-form 67 | "Build a form that can run the main method of the given class." 68 | [class-name args] 69 | `(let [c# (Class/forName ~class-name) 70 | j-args# (into-array String ~args) 71 | m-arg-types# (into-array Class [(class j-args#)]) 72 | main# (.getDeclaredMethod c# "main" m-arg-types#)] 73 | (if main# 74 | (.invoke main# nil (into-array Object [j-args#])) 75 | (println "Unable to find" (str ~class-name "/main") "method")))) 76 | 77 | (defn fregec 78 | "Compile Frege source files in :frege-source-paths to :compile-path 79 | 80 | Set :fregec-options in project.clj to pass options to the Frege compiler. 81 | Additional options may be passed on the command line. 82 | 83 | To display the Frege compiler's help, use: lein fregec :help" 84 | [project & args] 85 | (binding [*out* *err*] 86 | (let [[op class-name args run-args] (run-class-args args) 87 | project (merge {:frege-source-paths ["."]} project) 88 | srcs (:frege-source-paths project) 89 | out (:compile-path project) 90 | flags (:fregec-options project) 91 | files (stale-frege-sources srcs out) 92 | cp (->> (cp/get-classpath project) 93 | ;; only pass directories / files that exist: 94 | (filter file-exists)) 95 | path-sep (System/getProperty "path.separator") 96 | fregec-args (-> ["-d" out ; output directory 97 | "-fp" (str/join path-sep cp) ; imported Frege package paths 98 | "-sp" (str/join path-sep srcs) ; source paths 99 | "-make"] ; let compiler do dependency stuff 100 | (into (additional-fregec-args args)) 101 | (into (concat flags files)))] 102 | (leiningen.core.main/debug "Frege compiler version:" fregec-version) 103 | (apply leiningen.core.main/debug "Frege compiler arguments:" fregec-args) 104 | ;; ensure output directory exists: 105 | (Files/createDirectories (Paths/get out (into-array String [])) 106 | (into-array java.nio.file.attribute.FileAttribute [])) 107 | (binding [eval/*pump-in* false] 108 | (eval/eval-in (project/merge-profiles project [subprocess-profile]) 109 | (subprocess-compiler-form fregec-args))) 110 | (when class-name 111 | (eval/eval-in (project/merge-profiles project [subprocess-profile]) 112 | (case op 113 | :run (run-main-form class-name (vec run-args)) 114 | :test (run-main-form "frege.tools.Quick" (into [class-name] run-args)))))))) 115 | -------------------------------------------------------------------------------- /update-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # usage: update-version.sh new-version 4 | # 5 | # this will update the source code to refer to the new version 6 | # in both the plugin and the template 7 | 8 | if test -d ../frege-lein-plugin 9 | then 10 | echo "Found plugin." 11 | else 12 | echo "error: This should be run in the frege-lein-plugin folder." 13 | exit 1 14 | fi 15 | if test -d ../frege-lein-template 16 | then 17 | echo "Found template." 18 | else 19 | echo "error: frege-lein-template folder not found (should be next to plugin)." 20 | exit 1 21 | fi 22 | 23 | if test "x$1" = "x" 24 | then 25 | echo "usage: update-version.sh new-version" 26 | exit 1 27 | fi 28 | new_version="$1" 29 | new_major=$new_version 30 | new_minor=ignored 31 | if test "x$new_major" != "x" -a "x$new_minor" != "x" -a "x$new_major" != "x$new_minor" 32 | then 33 | echo "Will update to ${new_major}-${new_minor} version." 34 | else 35 | echo "error: new-version does not appear to be x.y.z-sha." 36 | exit 1 37 | fi 38 | 39 | 40 | old_version=`fgrep 'private fregec-version' src/leiningen/fregec.clj | sed 's;.*"\(.*\)".*;\1;'` 41 | if test "x$old_version" = "x" 42 | then 43 | echo "error: Cannot find current Frege version (in src/leiningen/fregec.clj)." 44 | exit 1 45 | else 46 | echo "Found current version: ${old_version}." 47 | fi 48 | 49 | old_major=`echo $old_version | sed 's;-.*;;'` 50 | 51 | files=`find . ../frege-lein-template -type f -exec fgrep -l $old_version {} \;` 52 | for f in $files 53 | do 54 | echo "Updating $f..." 55 | cp $f $f.update_version 56 | sed "s;$old_version;$new_version;g" < $f.update_version > $f 57 | done 58 | find . ../frege-lein-template -name '*.update_version' -delete 59 | 60 | files=`find . ../frege-lein-template -type f -exec fgrep -l $old_major {} \;` 61 | for f in $files 62 | do 63 | echo "Updating $f..." 64 | cp $f $f.update_version 65 | sed "s;$old_major;$new_major;g" < $f.update_version > $f 66 | done 67 | find . ../frege-lein-template -name '*.update_version' -delete 68 | 69 | echo "You should now review and commit the changes." 70 | --------------------------------------------------------------------------------