![Logo](https://raw.githubusercontent.com/AnonymousAAArdvark/qi/master/docs/assets/images/logo.png)
Qi is a lightweight, fast, and open source Chinese programming language.
qilang.tk »
English |
中文
After reading an article on how programming languages are created, I was inspired to create an interpreter myself. I took a look at how several languages were implemented, and realized that all of them were based on english. I wanted to make a programming language based on a "foreign" natural language, such as Chinese, and see what drawbacks it might lead to. I started simple by referencing various resources posted online (most notably Crafting Interpreters), and then slowly began implementing concepts mostly on my own. Turns out that creating an entire programming language from scratch is pretty tough, but that was what made it fun.
Why name it Qi? Qi was derived from the pinyin of the Chinese character "气", which means "air" in English. I wanted this language to be quick and lightweight, as well as fully transparent, just like air!
打印行("你好,世界")
-
Qi is Chinese-based. Us English-speaking people don't often take for granted the fact that the programming languages we learn are all based on native tongues we're already fluent in. A native English speaker can reasonably infer what a piece of Python code does just from reading the keywords ("if", "int", "while", etc.). Making this language foreign-based allows programming to be more accessible to more people around the globe.
-
Qi is fast. Qi utilizes a single-pass compiler that compiles to efficient bytecode that runs exceptionally down to the metal. Along with various optimizations such as Nan Boxing and hash table probing, Qi's speed squares up to competing dynamic languages.
-
Qi is light. With less than 5000 lines of code, the entire project could be read in a day. Although the code is short, everything is well-formatted and easy to understand. The final executable is only about 140 kb in size, allowing you to run it on nearly any device imaginable.
-
Qi is object-oriented. Placing classes front and center, object-oriented programming provides a clear modular structure that is significantly better at handling complexity than functional programming though concepts such as abstraction and encapsulation.
Although a couple of benchmarks aren't that good at judging performance, they're pretty cool to look at... so here's a couple.
Each benchmark was run 5 times, and the average time was taken for each language.
These tests were run on my Macbook Air 2017 with a Dual-Core i5 CPU and 8 GB RAM.
The code for the benchmarks can be found in the test folder.
- make
- macOS
brew install make
- Windows
choco install make
- Linux
- Should be built into the system
- macOS
- Clone or download zip of git repo.
- Open terminal, and
cd
to/src/cmake-build-release
- Run
make
. - All done!
Unit testing is so important (especially for a programming language) that I have included a full Qi test suite to make sure that every aspect of the interpreter does what it's supposed to do. The test programs can be found in the /test
directory here. To automate the testing procedure, the Go program /utils/test.go
provided here runs each test program with the inputted interpreter, captures the output, and validates the result.
To run the tests, you'll need to have Go installed onto your system. Download and install it from here.
Executing the Go program is fairly easy. Simply run go run test.go
and pass the path to the desired interpreter into the -interpreter=
argument.
go run test.go -interpreter=PATH_TO_INTERPRETER_HERE
Here is the output of the testing program if you forget to implement the negate operator:
$ go run test.go -interpreter=PATH
FAIL ../test/array/indexing.qi
Expected output '假' on line 7 and got 'b'.
FAIL ../test/array/methods.qi
Expected output '【零,1,2,3】' on line 9 and got '【零,2,3,4】'.
FAIL ../test/for/scope.qi
Expected output '-1' on line 10 and got '1'.
FAIL ../test/number/literals.qi
Expected output '-0' on line 4 and got '0'.
Expected output '-0.001' on line 7 and got '0.001'.
FAIL ../test/operator/negate.qi
Expected output '-3' on line 1 and got '3'.
FAIL ../test/string/indexing.qi
Expected output 'g' on line 7 and got 't'.
268 tests passed. 6 tests failed.
exit status 1
And here is the output if all tests pass:
$ go run test.go -interpreter=PATH
All 274 tests passed (641 expectations).
The Quick Start page is a great guide to install and set up the language.
For code examples, please refer to the Tests.
For a more extensive look into Qi, go to the Language Guide.
- Classes
- Inheritance
- Lists
- Increment/decrement operators
- Switch/Case statements
- Optimization
- Translate everything to Chinese
- Make a logo
- Finish Readme
- Translate Readme to Chinese
- Create Website
- Front Page
- Quick Start
- Language Guide
- Escape Sequences
- Bitwise operators
- Remove semicolons
- Support scientific notation, binary, etc. numbers
- More string methods
- More list methods
- Modules system
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Andrew Yang - @anonymousaaardvark - andrewhuiyang0830@gmail.com
Project Link: https://github.com/anonymousaaardvark/qi