grimec

所属分类:编译器/解释器
开发工具:C
文件大小:43KB
下载次数:0
上传日期:2021-03-05 18:36:19
上 传 者sh-1993
说明:  Grime编译器
(The Grime Compiler)

文件列表:
CMakeLists.txt (961, 2021-03-06)
LICENSE (35149, 2021-03-06)
build.gm (117, 2021-03-06)
src (0, 2021-03-06)
src\ast.c (4794, 2021-03-06)
src\ast.h (5027, 2021-03-06)
src\code-gen (0, 2021-03-06)
src\code-gen\llvm (0, 2021-03-06)
src\code-gen\llvm\llvm-code-gen.c (31556, 2021-03-06)
src\code-gen\llvm\llvm-code-gen.h (70, 2021-03-06)
src\file (0, 2021-03-06)
src\file\file.c (335, 2021-03-06)
src\file\file.h (52, 2021-03-06)
src\lexer (0, 2021-03-06)
src\lexer\lex.c (17998, 2021-03-06)
src\lexer\lex.h (90, 2021-03-06)
src\lexer\token.c (613, 2021-03-06)
src\lexer\token.h (3090, 2021-03-06)
src\main.c (1291, 2021-03-06)
src\main.gm (872, 2021-03-06)
src\main.s (2149, 2021-03-06)
src\parser (0, 2021-03-06)
src\parser\parser.c (40935, 2021-03-06)
src\parser\parser.h (113, 2021-03-06)
src\resolver (0, 2021-03-06)
src\resolver\type-resolver.c (1772, 2021-03-06)
src\resolver\type-resolver.h (106, 2021-03-06)
src\util (0, 2021-03-06)
src\util\colours.h (239, 2021-03-06)
src\util\log.c (1058, 2021-03-06)
src\util\log.h (597, 2021-03-06)
src\util\mem.c (2899, 2021-03-06)
src\util\mem.gm (0, 2021-03-06)
src\util\mem.h (274, 2021-03-06)
... ...

![Build](https://github.com/Edward-0/grimec/workflows/Build/badge.svg) # Grime Compiler The new static compiler for the grime programming language. ## Building ### Dependencies * LLVM #### Make * CMake ```sh mkdir build cd build cmake -G Ninja .. ninja ``` ## Getting Started ### Hello, World This is the old syntax and what the compiler can currently handle ```grime mod test::helloworld ext def func puts([UByte]) -> Int func main(argc: Int, argv: [[UByte]]) -> Int { var greeting: [UByte] := "Hello, World!" puts(greeting) ret := 0 } ``` The new syntax that needs to be implemented ```grime /* * `!` means always run at comptime * `mod` is a function that tells the compiler * what namespace we're in */ mod!(test::helloworld) /* * `main` is the entry point. I'll probably make it possible to have "swissarmy-knife" type binary * like busybox and toybox * * `env` is the environment; one thing I dislike is globals and this allows one to avoid that. * it contains everything one needs to know from constant file descriptors such as stdin and stderr * to environment variables and cmdline args * the `&` prefixing `env` tells us this is a "borrow checked pointer" that we don't own. * `main` will not drop `env` `_start` is responsible for that. * * `NotZero` returns an integer type that can never ever be 0 * `()` is basically nothing similar to rust * `Result` returns a structure type with a bool and a union of `E` and `T` * but in some cases it can be packed together for example * if one of the type's is a NotZero and the other is () the representation will always be the width * of the original integer so the return type here will always be a u32 and if it's a 0 it means there * is no error. */ pub fn main(env: &std::Env) -> Result!((),NotZero!(u32)) { /* * `stdout` is one of the constant file descriptors * `println` does what it says on the tin and prints with * a new line. should probably change to have a cmptime format */ env.stdout.println("Hello, World!"); /* * like rust this is returning without an error */ Ok(()) } ``` ### Usage ```sh grimec helloworld.gm | clang -x ir ./a.out ``` ``` grimec | clang -x ir - ``` ## TODO - lexer is fundamentally broken and needs a total rewrite (most likely use FSM) - restructure semantic stage - add custom ir - change syntax - change build system to a single POSIX Makefile and a Ninja file or write a very short configure POSIX shell script to generate one of your choice `./configure --ninja` or `./configure --make`

近期下载者

相关文件


收藏者