Peon is a modern, multi-paradigm, async-first programming language with a focus on correctness and speed
Go to file
Mattia Giambirtone 97698b28af Initial work on fixing lambdas and minor improvements to error reporting 2023-03-04 12:13:19 +01:00
docs Added draft for peon's grammar 2023-01-25 10:20:37 +01:00
src Initial work on fixing lambdas and minor improvements to error reporting 2023-03-04 12:13:19 +01:00
tests Simplified GC implementation by removing unnecessary metadata 2023-02-25 16:17:38 +01:00
.gitignore Updated .gitignore 2022-07-09 13:37:51 +02:00
LICENSE Initial commit from JAPL with some changes 2022-04-04 12:29:23 +02:00
README.md Added choosenim link 2023-03-03 01:02:18 +01:00
nim.cfg Updated nim.cfg with more general import search path 2023-01-24 12:25:01 +01:00

README.md

The peon programming language

Peon is a modern, multi-paradigm, async-first programming language with a focus on correctness and speed.

Go to the Manual

What's peon?

Note: For simplicity reasons, the verbs in this section refer to the present even though part of what's described here is not implemented yet.

Peon is a multi-paradigm, statically-typed programming language inspired by C, Nim, Python, Rust and C++: it supports modern, high-level features such as automatic type inference, parametrically polymorphic generic types, pure functions, closures, interfaces, single inheritance, reference types, templates, coroutines, raw pointers and exceptions.

The memory management model is rather simple: a Mark and Sweep garbage collector is employed to reclaim unused memory.

Peon features a native cooperative concurrency model designed to take advantage of the inherent waiting of typical I/O workloads, without the use of more than one OS thread (wherever possible), allowing for much greater efficiency and a smaller memory footprint. The asynchronous model used forces developers to write code that is both easy to reason about, thanks to the Structured concurrency model that is core to peon's async event loop implementation, and works as expected every time (without dropping signals, exceptions, or task return values).

Other notable features are the ability to define (and overload) custom operators with ease by implementing them as language-level functions, Universal function call syntax, Name stropping and named scopes.

In peon, all objects are first-class (this includes functions, iterators, closures and coroutines).

Disclaimers

Disclaimer 1: The project is still in its very early days: lots of stuff is not implemented, a work in progress or otherwise outright broken. Feel free to report bugs!

Disclaimer 2: Currently the REPL is very basic (it adds your code to previous input plus a newline, as if it was compiling a new file every time), because incremental compilation is designed for modules and it doesn't play well with the interactive nature of a REPL session. To show the current state of the REPL, type #show (this will print all the code that has been typed so far), while to reset everything, type #reset. You can also type #clear if you want a clean slate to type in, but note that it won't reset the REPL state. If adding a new piece of code causes compilation to fail, the REPL will not add the last piece of code to the input so you can type it again and recompile without having to exit the program and start from scratch. You can move through the code using left/right arrows and go to a new line by pressing Ctrl+Enter. Using the up/down keys on your keyboard will move through the input history (which is never reset). Also note that UTF-8 is currently unsupported in the REPL (it will be soon though!)

Disclaimer 3: Currently, the std module has to be always imported explicitly for even the most basic snippets to work. This is because intrinsic types and builtin operators are defined within it: if it is not imported, peon won't even know how to parse 2 + 2 (and even if it could, it would have no idea what the type of the expression would be). You can have a look at the peon standard library to see how the builtins are defined (be aware that they heavily rely on compiler black magic to work) and can even provide your own implementation if you're so inclined.

TODO List

In no particular order, here's a list of stuff that's done/to do (might be incomplete/out of date):

  • User-defined types
  • Function calls
  • Control flow (if-then-else, switch)
  • Looping (while)
  • Iteration (foreach)
  • Type conversions
  • Type casting
  • Intrinsics
  • Type unions
  • Functions
  • Closures
  • Managed references
  • Unmanaged references
  • Named scopes/blocks
  • Inheritance
  • Interfaces
  • Indexing operator
  • Generics
  • Automatic types
  • Iterators/Generators
  • Coroutines
  • Pragmas
  • Attribute resolution
  • Universal Function Call Syntax
  • Import system
  • Exceptions
  • Templates (not like C++ templates)
  • Optimizations (constant folding, branch and dead code elimination, inlining)

Feature wishlist

Here's a random list of high-level features I would like peon to have and that I think are kinda neat (some may have been implemented alredady):

  • Reference types are not nullable by default (must use #pragma[nullable])
  • Easy C/Nim interop via FFI
  • C/C++ backend
  • Nim backend
  • Structured concurrency (must-have!)
  • Simple OOP (with multiple dispatch!)
  • RTTI, with methods that dispatch at runtime based on the true type of a value
  • Limited compile-time evaluation (embed the Peon VM in the C/C++/Nim backend and use that to execute peon code at compile time)

The name

The name for peon comes from Productive2's genius cute brain, and is a result of shortening the name of the fastest animal on earth: the Peregrine Falcon. I guess I wanted this to mean peon will be blazing fast (I certainly hope so!)

Peon needs you.

No, but really. I need help. This project is huge and (IMHO) awesome, but there's a lot of non-trivial work to do and doing it with other people is just plain more fun and rewarding. If you want to get involved, definitely try contacting me or open an issue/PR!

Credits

  • Araq, for creating the amazing language that is Nim (as well as all of its contributors!)
  • Guido Van Rossum, aka the chad who created Python and its awesome community and resources
  • The Nim community and contributors, for making Nim what it is today
  • Bob Nystrom, for his amazing book that inspired me and taught me how to actually make a programming language (kinda, I'm still very dumb)
  • Njsmith, for his awesome articles on structured concurrency
  • All the amazing people in the r/ProgrammingLanguages subreddit and its Discord server
  • Art <3
  • Everyone to listened (and still listens to) me ramble about compilers, programming languages and the likes (and for giving me ideas and testing peon!)
  • ... More? (I'd thank the contributors but it's just me :P)
  • Me! I guess

Ok, cool, how do I use it?

Great question! If this README somehow didn't turn you away already (thanks, by the way), then you may want to try peon out for yourself. Fortunately, the process is quite straightforward:

  • First, you're gonna have to install Nim, the language peon is written in. I highly recommend using choosenim to manage your Nim installations as it makes switching between them and updating them a breeze
  • Once Nim is installed, you should install jale, peon's custom line editor library written by our beloved Art. This is needed for the REPL to work: just clone the repository, cd into it and run nimble install; this will install the library on your system so that the Nim compiler can find it later
  • After jale has been installed, clone this repository and run the REPL with nim r src/main (in the appropriate directory of course). If you want to do more than play around in the REPL, I recommend compiling peon in release mode with nim -d:release --passC:"-flto" -o:peon, which should produce a peon binary ready for you to play with (if your C toolchain doesn't support LTO then you can just omit the --passC option, although that would be pretty weird for a modern linker)
  • If you want to move the executable to a different directory (say, into your PATH), you should copy peon's standard library (found in /src/peon/stdlib) into a known folder and edit the moduleLookupPaths variable inside src/config.nim by adding said folder to it so that the peon compiler knows where to find modules when you import std;. Hopefully I will automate this soon, but as of right now the work is all manual (and it's part of the fun, IMHO ;))

If you've done everything right, you should be able to run peon in your terminal and have it drop you into the REPL. Good luck and have fun!