nibble

所属分类:编程语言基础
开发工具:C
文件大小:0KB
下载次数:0
上传日期:2023-09-28 06:45:00
上 传 者sh-1993
说明:  编程语言,
(Programming language,)

文件列表:
.clang-format (4267, 2024-01-11)
CMakeLists.txt (2862, 2024-01-11)
LICENSE (1073, 2024-01-11)
build_linux.sh (170, 2024-01-11)
ebnf.txt (3412, 2024-01-11)
editor/ (0, 2024-01-11)
editor/nibble.vim (2596, 2024-01-11)
examples/ (0, 2024-01-11)
examples/hello_world/ (0, 2024-01-11)
examples/hello_world/main.nib (130, 2024-01-11)
examples/merge_sort/ (0, 2024-01-11)
examples/merge_sort/main.nib (361, 2024-01-11)
examples/merge_sort/sort.nib (994, 2024-01-11)
examples/snake_game/ (0, 2024-01-11)
examples/snake_game/main.nib (10655, 2024-01-11)
examples/snake_game/snake-game.gif (242793, 2024-01-11)
examples/snake_game/utils.nib (909, 2024-01-11)
run_tests.py (13356, 2024-01-11)
src/ (0, 2024-01-11)
src/all_srcs.h (1404, 2024-01-11)
src/allocator.c (6781, 2024-01-11)
src/allocator.h (1825, 2024-01-11)
src/argv_helper.h (541, 2024-01-11)
src/array.c (2977, 2024-01-11)
src/array.h (2551, 2024-01-11)
src/ast/ (0, 2024-01-11)
src/ast/module.c (53755, 2024-01-11)
src/ast/module.h (28675, 2024-01-11)
src/ast/print_ast.c (27802, 2024-01-11)
src/basics.c (343, 2024-01-11)
src/basics.h (1246, 2024-01-11)
src/bytecode/ (0, 2024-01-11)
src/bytecode/module.c (429, 2024-01-11)
src/bytecode/module.h (8445, 2024-01-11)
src/bytecode/print_ir.c (22586, 2024-01-11)
... ...

**THIS PROGRAMMING LANGUAGE IS A WORK IN PROGRESS. ANYTHING CAN CHANGE AT ANY MOMENT. USE AT YOUR OWN RISK!** # Nibble [![Unit Tests](https://github.com/nibble-language/nibble/actions/workflows/test_nibble_programs.yml/badge.svg)](https://github.com/nibble-language/nibble/actions/workflows/test_nibble_programs.yml) This is an experimental programming language based on C. The goal is to create a compiled, statically-typed programming language that adds the following features to C: - [x] Order-independent declarations - [x] Module import system (based on javascript ES6) - [x] Type inference - [x] Typed enumerations - [x] Multiple return values (return anonymous structure object aka tuples) - [x] Type-safe variadic procedures - [x] Array slices (See [C's Biggest Mistake](https://digitalmars.com/articles/C-biggest-mistake.html)) - [x] Variables initialized to zero by default (use `---` value to leave uninitialized) - [ ] Defer statement (like go) - [ ] Default procedure arguments - [ ] Named procedure arguments - [ ] Generic procedures (like c++ templates) Nibble supports the followng operating systems: - [x] x64 linux - [ ] x64 windows - [ ] x86 linux - [ ] x86 windows - [ ] arm64 macOS Refer to the [language reference document](https://github.com/adrianlizarraga/nibble/wiki/Language-reference) for details. It is very much a work in progress. ## Quickstart ### 1. Build the Nibble compiler The only library required to build the Nibble compiler is the C standard library. #### Linux The following terminal command generates an executable called `nibble` in the root project directory. ```console $ gcc -I./src -O2 -o nibble src/main.c ``` ### 2. Install NASM The Nibble compiler currently generates an assembly file that is assembled with NASM and then linked with your operating system's linker. Therefore, you'll need to install the [NASM assembler](https://nasm.us/) and add it to your system `PATH`. Refer to the wiki page on [How to install NASM](https://github.com/adrianlizarraga/nibble/wiki/How-to-install-NASM) for more detailed instructions. ### 3. Compile a nibble program Here's an example that compiles the ["Hello World" example program](examples/hello_world/main.nib) on linux. ```console $ ./nibble -o hello_world examples/hello_world/main.nib [INFO]: Parsing module examples/hello_world/main.nib ... [INFO]: Resolving/type-checking ... [INFO]: Generating IR ... [INFO]: Generating NASM assembly output: hello_world.s ... [CMD]: nasm -f elf64 hello_world.s -o hello_world.o [CMD]: ld -o hello_world hello_world.o $ ./hello_world Hello, World ``` To compile a Nibble program, the compiler only needs the file (i.e., module) containing your program's `main()` procedure. The compiler can automatically detect any imported or included files. Refer to the [language reference](https://github.com/adrianlizarraga/nibble/wiki/Language-reference#module-importexport-system) to learn more about importing or including other files. ## Command-line options Run `./nibble -h` for available command-line options. ```console $ ./nibble -h Usage: ./nibble [OPTIONS] OPTIONS: -h Print this help message -s Silent mode (no output to stdout) -os [linux | win32 | osx] Target OS -arch [x64 | x86] Target architecture -I Add module (import/include) search path -L Add library search path -o Output binary file name. Defaults to `out` ``` ## Code examples ### Hello, World main.nib: ```c import "std/basic" as std; proc main(argc : int, argv : ^^char) => int { std::print_out("Hello, World!\n"); return 0; } ``` ```console $ ./nibble -s main.nib -o hello $ ./hello Hello, World! ``` ### Snake game This [example game](examples/snake_game/) uses the terminal to display its UI. ```console $ ./nibble -s examples/snake_game/main.nib -o snake $ ./snake ``` ![](examples/snake_game/snake-game.gif) ## Status of the project Nibble does not yet support all basic C features: - [x] Integer types - [x] Floating-point types - [x] Structure types - [x] Union types - [x] Enum types - [x] Typedefs - [x] Procedures - [x] Basic procedures with non-variadic parameters - [x] Varidic parameters - [ ] Statements - [x] static_assert - [x] if/else - [x] while - [x] do while - [x] for loop - [ ] switch - [x] break - [x] continue - [x] return - [x] Expressions - [x] Assignments - [x] Ternary operator - [x] Binary operators - [x] Unary operators ## Language reference [Here it is](https://github.com/adrianlizarraga/nibble/wiki/Language-reference). It is very much a work in progress.

近期下载者

相关文件


收藏者