coy
所属分类:编译器/解释器
开发工具:Haskell
文件大小:51KB
下载次数:0
上传日期:2023-06-18 12:12:09
上 传 者:
sh-1993
说明: 编译为LLVM-IR的小型编程语言
(A small programming language that compiles to LLVM IR)
文件列表:
.stylish-haskell.yaml (151, 2023-07-22)
app (0, 2023-07-22)
app\Main.hs (5080, 2023-07-22)
clang.nix (140, 2023-07-22)
examples (0, 2023-07-22)
examples\lux.coy (13179, 2023-07-22)
golden (0, 2023-07-22)
golden\Main.hs (3339, 2023-07-22)
golden\data (0, 2023-07-22)
golden\data\boolean_algebra.coy (139, 2023-07-22)
golden\data\boolean_algebra.stdout (9, 2023-07-22)
golden\data\comments.coy (185, 2023-07-22)
golden\data\comments.stdout (9, 2023-07-22)
golden\data\composite_scrutinee.coy (131, 2023-07-22)
golden\data\composite_scrutinee.stdout (9, 2023-07-22)
golden\data\constants.coy (100, 2023-07-22)
golden\data\constants.stdout (19, 2023-07-22)
golden\data\conversion.coy (85, 2023-07-22)
golden\data\conversion.stdout (15, 2023-07-22)
golden\data\enum_with_no_variants.coy (98, 2023-07-22)
golden\data\enum_with_no_variants.stdout (9, 2023-07-22)
golden\data\if.coy (75, 2023-07-22)
golden\data\if.stdout (9, 2023-07-22)
golden\data\intrinsics.coy (147, 2023-07-22)
golden\data\intrinsics.stdout (64, 2023-07-22)
golden\data\linear_feedback_shift_register.coy (441, 2023-07-22)
golden\data\linear_feedback_shift_register.stdout (900, 2023-07-22)
golden\data\match.coy (81, 2023-07-22)
golden\data\match.stdout (9, 2023-07-22)
golden\data\maybe_f64.coy (331, 2023-07-22)
golden\data\maybe_f64.stdout (19, 2023-07-22)
golden\data\ppm.coy (524, 2023-07-22)
golden\data\ppm.stdout (53, 2023-07-22)
golden\data\print_braces.coy (108, 2023-07-22)
golden\data\print_braces.stdout (66, 2023-07-22)
golden\data\print_double_quotes.coy (104, 2023-07-22)
golden\data\print_double_quotes.stdout (67, 2023-07-22)
... ...
# coy
Coy is a small programming language with algebraic data types and pattern
matching; it has a Rust-like syntax and compiles to [LLVM IR].
[LLVM IR]: https://llvm.org/docs/LangRef.html
## Example
An extensive example is available at [`examples/lux.coy`](https://github.com/zuqq/coy/blob/master/examples/lux.coy),
containing a partial implementation of [Ray Tracing in One Weekend][Shirley].
This example shows off most of Coy's features; it has no arrays, first-class
functions, mutable variables, references, etc.
[Shirley]: https://raytracing.github.io/books/RayTracingInOneWeekend.html
## Installation
Coy uses [`stack`] to manage its build process.
[`stack`]: https://www.haskellstack.org
## Usage
Coy compiles its input to LLVM IR, relying on Clang for code generation. It
targets LLVM 9, because that's what [`llvm-hs-pretty`] supports. The provided
[`clang.nix`](https://github.com/zuqq/coy/blob/master/clang.nix) Nix expression is a convenient way of setting up an
environment with a compatible Clang version through [`nix-shell`].
An an example, let's compile [`examples/lux.coy`](https://github.com/zuqq/coy/blob/master/examples/lux.coy).
First, build and run Coy:
$ stack run -- --output=lux.ll examples/lux.coy
This produces a `lux.ll` file that contains the LLVM IR generated by Coy.
Now, open a shell that contains Clang:
$ nix-shell clang.nix
... compile the LLVM IR generated by Coy:
[nix-shell]$ clang -O3 -o lux lux.ll
... and run the generated executable:
[nix-shell]$ ./lux > lux.ppm
This produces an image in [plain PPM format] that you can open in your favorite
image viewer.
[`llvm-hs-pretty`]: https://hackage.haskell.org/package/llvm-hs-pretty
[`nix-shell`]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html
[plain PPM format]: http://netpbm.sourceforge.net/doc/ppm.html
近期下载者:
相关文件:
收藏者: