-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1716117
Showing
27 changed files
with
2,441 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: ultimaweapon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "deps/llvm"] | ||
path = deps/llvm | ||
url = https://github.com/llvm/llvm-project.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Stage 0 (std)", | ||
"type": "lldb", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/stage0/target/debug/pluto", | ||
"args": [ | ||
"${workspaceFolder}/std" | ||
], | ||
"cwd": "${workspaceFolder}", | ||
"env": { | ||
"RUST_BACKTRACE": "1" | ||
}, | ||
"preLaunchTask": "stage0" | ||
} | ||
], | ||
"version": "2.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"editor.rulers": [100], | ||
"files.exclude": { | ||
"deps": true | ||
}, | ||
"files.insertFinalNewline": true, | ||
"files.trimFinalNewlines": true, | ||
"files.trimTrailingWhitespace": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "stage0", | ||
"type": "cargo", | ||
"command": "build", | ||
"group": "build", | ||
"options": { | ||
"cwd": "${workspaceFolder}/stage0" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Redistribution and use in source and binary forms, with or without modification, are permitted | ||
provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions | ||
and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
and the following disclaimer in the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
Subject to the terms and conditions of this license, each copyright holder and contributor hereby | ||
grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, | ||
no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) | ||
patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this | ||
software, where such license applies only to those patent claims, already acquired or hereafter | ||
acquired, licensable by such copyright holder or contributor that are necessarily infringed by: | ||
|
||
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable | ||
additions of contributors, in source or binary form) alone; or | ||
|
||
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) | ||
was added by such copyright holder or contributor, if, at the time the Contribution is added, such | ||
addition causes such combination to be necessarily infringed. The patent license shall not apply to | ||
any other combinations which include the Contribution. | ||
|
||
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is | ||
granted under this license, whether expressly, by implication, estoppel or otherwise. | ||
|
||
DISCLAIMER | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | ||
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Pluto | ||
|
||
Pluto is an experimental OOP language inspired by Rust with the following goals: | ||
|
||
- Compiled to native code. | ||
- [Non-fragile](https://en.wikipedia.org/wiki/Fragile_binary_interface_problem) and stable ABI. | ||
- GC using reference counting. | ||
- Runtime reflection. | ||
- Error handling using exception. | ||
- No null value (except a pointer). | ||
- Option type. | ||
|
||
Pluto borrowed most of the syntax from Rust except: | ||
|
||
- Pluto is an OOP language like Java or C#. | ||
- Easy to learn, especially for people who already know Java, C# or Rust. | ||
- No lifetime, no borrow checker, no const VS mut. | ||
- No borrowed and owned type like `str` and `String`. | ||
- Use exception like Java or C# for error handling (no checked exception). | ||
- Pluto was designed for application programming rather than systems programming. | ||
|
||
The goal of Pluto is to be a modern OOP language with the productivity of Rust syntax. | ||
|
||
## Different from Java or C# | ||
|
||
The main different is Pluto compiled to native code instead of Java bytecode or Common Intermediate | ||
Language, which can be run without a VM. The benefit with this are: | ||
|
||
- Low memory footprint. | ||
- Fast startup. | ||
- Can be run on a client machine directly without a VM. | ||
- Easy to interop with other languages. | ||
|
||
## Current state | ||
|
||
I'm currently writing the stage 0 compiler along side the `std` library. The goal of stage 0 | ||
compiler is to compile the `std` and `cli`. Once the first version of `cli` is fully working Pluto | ||
will become a self-hosted language. | ||
|
||
## Example | ||
|
||
``` | ||
@pub | ||
class Allocator; | ||
impl Allocator { | ||
@pub | ||
fn Alloc(size: usize, align: usize): *u8 { | ||
@cfg(unix) | ||
let ptr = aligned_alloc(align, size); | ||
@cfg(windows) | ||
let ptr = _aligned_malloc(size, align); | ||
if ptr == null { | ||
@cfg(os != "windows") | ||
abort(); | ||
@cfg(os == "windows") | ||
asm("int 0x29", in("ecx") 7, out(!) _); | ||
} | ||
ptr | ||
} | ||
@pub | ||
fn Free(ptr: *u8) { | ||
@cfg(unix) | ||
free(ptr); | ||
@cfg(windows) | ||
_aligned_free(ptr); | ||
} | ||
@cfg(unix) | ||
@ext(C) | ||
fn aligned_alloc(align: usize, size: usize): *u8; | ||
@cfg(unix) | ||
@ext(C) | ||
fn free(ptr: *u8); | ||
@cfg(windows) | ||
@ext(C) | ||
fn _aligned_malloc(size: usize, align: usize): *u8; | ||
@cfg(windows) | ||
@ext(C) | ||
fn _aligned_free(ptr: *u8); | ||
@cfg(unix) | ||
@ext(C) | ||
fn abort(): !; | ||
} | ||
``` | ||
|
||
## Build from source | ||
|
||
### Prerequisites | ||
|
||
- Git | ||
- Rust | ||
- C++ toolchain (e.g. MSVC, XCode, GCC) | ||
- CMake | ||
|
||
### Download the source | ||
|
||
You need to clone this repository with submodules like this: | ||
|
||
```sh | ||
git clone --recurse-submodules https://github.com/ultimaweapon/pluto.git | ||
``` | ||
|
||
### Build dependencies | ||
|
||
#### Linux and macOS | ||
|
||
Run the following command in the root of this repository: | ||
|
||
```sh | ||
CMAKE_BUILD_PARALLEL_LEVEL=2 ./build-deps.sh | ||
``` | ||
|
||
## License | ||
|
||
BSD-2-Clause Plus Patent License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh -e | ||
dir=$(pwd) | ||
|
||
# LLVM | ||
cmake \ | ||
--install-prefix "$dir/lib/llvm" \ | ||
-B "$dir/deps/llvm/build" \ | ||
-Wno-dev \ | ||
-DCMAKE_BUILD_TYPE:STRING=Release \ | ||
-DLLVM_ENABLE_ZSTD:BOOL=OFF \ | ||
-DLLVM_APPEND_VC_REV:BOOL=OFF \ | ||
"$dir/deps/llvm/llvm" | ||
|
||
cmake --build "$dir/deps/llvm/build" --config Release | ||
cmake --install "$dir/deps/llvm/build" --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/Cargo.lock | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "pluto" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
thiserror = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::Expression; | ||
use crate::lexer::{AttributeName, Span}; | ||
|
||
/// An attribute. | ||
pub struct Attribute { | ||
name: AttributeName, | ||
args: Option<Vec<Vec<Expression>>>, | ||
} | ||
|
||
impl Attribute { | ||
pub fn new(name: AttributeName, args: Option<Vec<Vec<Expression>>>) -> Self { | ||
Self { name, args } | ||
} | ||
|
||
pub fn span(&self) -> &Span { | ||
self.name.span() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::Attribute; | ||
use crate::lexer::{ClassKeyword, Identifier, Span}; | ||
|
||
/// A class. | ||
pub struct Class { | ||
attrs: Vec<Attribute>, | ||
def: ClassKeyword, | ||
name: Identifier, | ||
} | ||
|
||
impl Class { | ||
pub fn new(attrs: Vec<Attribute>, def: ClassKeyword, name: Identifier) -> Self { | ||
Self { attrs, def, name } | ||
} | ||
|
||
pub fn span(&self) -> &Span { | ||
self.def.span() | ||
} | ||
|
||
pub fn name(&self) -> &Identifier { | ||
&self.name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use super::Statement; | ||
use crate::lexer::{ | ||
AsmKeyword, Equals, ExclamationMark, Identifier, IfKeyword, NullKeyword, StringLiteral, | ||
UnsignedLiteral, | ||
}; | ||
|
||
/// An expression. | ||
pub enum Expression { | ||
Value(Identifier), | ||
Call(Call), | ||
Equal(Equals, Equals), | ||
NotEqual(ExclamationMark, Equals), | ||
Unsigned(UnsignedLiteral), | ||
String(StringLiteral), | ||
Null(NullKeyword), | ||
Asm(Asm), | ||
If(If), | ||
} | ||
|
||
/// A function call. | ||
pub struct Call { | ||
path: Vec<Identifier>, | ||
name: Identifier, | ||
args: Vec<Vec<Expression>>, | ||
} | ||
|
||
impl Call { | ||
pub fn new(path: Vec<Identifier>, name: Identifier, args: Vec<Vec<Expression>>) -> Self { | ||
Self { path, name, args } | ||
} | ||
} | ||
|
||
/// An inline assembly (e.g. `asm("nop")`). | ||
pub struct Asm { | ||
def: AsmKeyword, | ||
inst: StringLiteral, | ||
inputs: Vec<(AsmIn, Vec<Expression>)>, | ||
outputs: Vec<(AsmOut, Identifier)>, | ||
} | ||
|
||
impl Asm { | ||
pub fn new( | ||
def: AsmKeyword, | ||
inst: StringLiteral, | ||
inputs: Vec<(AsmIn, Vec<Expression>)>, | ||
outputs: Vec<(AsmOut, Identifier)>, | ||
) -> Self { | ||
Self { | ||
def, | ||
inst, | ||
inputs, | ||
outputs, | ||
} | ||
} | ||
} | ||
|
||
/// An input of the inline assembly (e.g. `in("rax")`). | ||
pub enum AsmIn { | ||
Register(StringLiteral), | ||
} | ||
|
||
/// An output of the inline assembly (e.h. `out("rax")`). | ||
pub enum AsmOut { | ||
Never(ExclamationMark), | ||
} | ||
|
||
/// An if expression. | ||
pub struct If { | ||
def: IfKeyword, | ||
cond: Vec<Expression>, | ||
body: Vec<Statement>, | ||
} | ||
|
||
impl If { | ||
pub fn new(def: IfKeyword, cond: Vec<Expression>, body: Vec<Statement>) -> Self { | ||
Self { def, cond, body } | ||
} | ||
} |
Oops, something went wrong.