-
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 05310ce
Showing
51 changed files
with
17,302 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,20 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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,46 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Patrik Svensson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,10 @@ | ||
# Documentation | ||
|
||
This is the documentation for Mew. | ||
|
||
## Running | ||
|
||
```console | ||
$ npm install | ||
$ npx docusaurus start | ||
``` |
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 @@ | ||
module.exports = { | ||
presets: [require.resolve('@docusaurus/core/lib/babel/preset')], | ||
}; |
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 @@ | ||
--- | ||
title: Trying this again | ||
authors: [patrik] | ||
tags: [mew] | ||
--- | ||
|
||
I know it's never a good idea to write things from scratch, but I still intend to do it with Mew. Over the past few months, I've learned various aspects of how a compiler works and contemplated what I want Mew to be. Hopefully, something good will come out of it. Time will tell. |
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,22 @@ | ||
--- | ||
title: A long overdue update | ||
authors: [patrik] | ||
tags: [mew] | ||
--- | ||
|
||
Life got in the way, but I've picked up this project again. | ||
|
||
I've reduced the project scope to get something | ||
that works reliably out the door feasible; this means that Mew will be based on | ||
the .NET runtime, and as a first step, not generate CIL myself but | ||
transpile Mew to (non-optimal) C# code. This will hopefully make it easier | ||
to get something out and experiment with the language. | ||
|
||
I'm focusing on documenting every aspect of the language that I would want | ||
to see in the first version. Once that is done, I will open the repository | ||
and open-source the project. Hopefully other people can learn from all my mistakes. | ||
|
||
:::note | ||
Mew is a learning exercise in compilers and an experiment to see if I | ||
can create something usable, mostly from a scripting perspective. | ||
::: |
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,5 @@ | ||
patrik: | ||
name: Patrik Svensson | ||
title: Maintainer of Mew | ||
url: https://github.com/patriksvensson | ||
image_url: https://github.com/patriksvensson.png |
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,96 @@ | ||
--- | ||
sidebar_position: 5 | ||
--- | ||
|
||
# Compiler | ||
|
||
This page contains a high level breakdown of the different | ||
steps needed to compile Mew code. | ||
|
||
```mermaid | ||
flowchart LR; | ||
subgraph Frontend | ||
AST-->HIR | ||
HIR-->MIR | ||
MIR-->LIR | ||
end | ||
subgraph Backend | ||
LIR-->C# | ||
C#-->CIL | ||
LIR-. Future .->CIL | ||
end | ||
``` | ||
|
||
## 1. AST Parsing | ||
|
||
The parsing step iterates through all source files, and | ||
builds a syntax tree for each of them. | ||
The syntax tree represents the code as it was written, | ||
maintaining the trivia such as white space, comments etc. | ||
|
||
Each node in the AST has a reference to both it's parent | ||
and children. | ||
|
||
Apart from being the basis for `HIR` generation, the AST | ||
is also used to interact with the source code programatically, | ||
i.e. from the LSP server. | ||
|
||
## 2. `HIR` generation | ||
|
||
HIR, short for _High-level Intermediate Representation_, | ||
represents a bound tree, where all types are known. | ||
|
||
The HIR references resolved _symbols_ for the different parts | ||
of Mew (namespaces, types, functions, parameters, variables etc). | ||
For example, two code block that calls a function, will have | ||
the same symbol reference to that function. | ||
|
||
1. Build symbol table | ||
1. Namespaces | ||
1. Types | ||
1. Free functions | ||
1. Type members | ||
1. Binding | ||
1. Types | ||
1. Free functions | ||
1. Top level statements | ||
|
||
:::info | ||
HIR might contain errors, represented as error symbols. | ||
::: | ||
|
||
## 3. `MIR` generation | ||
|
||
MIR, short for _Medium-level Intermediate Representation_, | ||
is a lowered HIR, without constructs such as `while`/`loop`/`if`. | ||
|
||
All higher level constructs such as loops and conditions | ||
been lowered into labels and branches. | ||
|
||
Control flow analysis and some optimizations | ||
are done here as well. | ||
|
||
:::info | ||
MIR might contain errors, represented as error symbols. | ||
::: | ||
|
||
## 4. `LIR` generation | ||
|
||
LIR, short for _Low-level Intermediate Representation_, | ||
is a lowered MIR, resembling the final byte code that will | ||
be emitted. | ||
|
||
:::warning | ||
LIR **MUST NOT** contain any errors. | ||
::: | ||
|
||
## 5. Emitting | ||
|
||
Finally, the LIR is transpiled into C# and compiled to | ||
native assembly code using NativeAOT, which in turn can be executed. | ||
|
||
:::note | ||
There are plans in the future to emit CIL directly. | ||
This was done in the early prototype, but turned out to | ||
be too cumbersome while the language was in active development. | ||
::: |
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,33 @@ | ||
--- | ||
sidebar_position: 120 | ||
--- | ||
|
||
# Directives | ||
|
||
:::info | ||
This functionality is not yet implemented | ||
::: | ||
|
||
### Import source files | ||
|
||
```mew | ||
#load "foo.mew" | ||
#load "stuff/*.mew" | ||
``` | ||
|
||
### Reference Mew projects | ||
|
||
```mew | ||
#reference "../../foo.mewx" | ||
#reference "../../bar.mewx" | ||
``` | ||
|
||
### Executable name | ||
|
||
```mew | ||
#name "MyName" | ||
``` | ||
|
||
:::note | ||
Can only be specified in a `mewx` project file. | ||
::: |
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,46 @@ | ||
--- | ||
sidebar_position: 100 | ||
--- | ||
|
||
# Generics | ||
|
||
:::info | ||
This functionality is not yet implemented | ||
::: | ||
|
||
### Types | ||
|
||
```mew | ||
pub type Smallest<T : Comparable<T>> { | ||
mut field smallest : Optional<T>; | ||
pub static fn new() -> MyList<T> { | ||
smallest = Optional<T>.none; | ||
} | ||
pub fn add_smallest(item: T) { | ||
if item == .none { | ||
return; | ||
} | ||
if self.smallest == null || | ||
item.CompareTo(self.smallest) == -1 | ||
{ | ||
self.smallest = item; | ||
} | ||
} | ||
pub fn GetSmallest() -> Optional<T> { | ||
return smallest; | ||
} | ||
} | ||
``` | ||
|
||
### Unions | ||
|
||
```mew | ||
pub union Result<T, V : Exception> { | ||
Ok(T), | ||
Err(V), | ||
} | ||
``` |
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,5 @@ | ||
--- | ||
sidebar_position: 20 | ||
--- | ||
|
||
# Future |
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,36 @@ | ||
--- | ||
sidebar_position: 90 | ||
--- | ||
|
||
# Interfaces | ||
|
||
:::info | ||
This functionality is not yet implemented | ||
::: | ||
|
||
```mew | ||
use Mew; | ||
interface Distance { | ||
fn get_distance() -> f64; | ||
} | ||
type Point { | ||
pub field x : i32; | ||
pub field y : i32; | ||
}; | ||
impl Distance for Point { | ||
fn get_distance() -> f64 { | ||
return Math::sqrt( | ||
first: self.X * self.X + | ||
second: self.Y * self.Y); | ||
} | ||
} | ||
``` | ||
|
||
```mew | ||
// Usage: | ||
let point = Point(x: 32, y: 40); | ||
let dist = point.get_distance(); | ||
``` |
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,27 @@ | ||
--- | ||
sidebar_position: 140 | ||
--- | ||
|
||
# Project files | ||
|
||
:::info | ||
This functionality is not yet implemented | ||
::: | ||
|
||
A Mew project file has the extension `.mewx`. | ||
|
||
Project files are normal `.mew` files, except that they | ||
can have additional metadata that describes what references | ||
to include, etc. | ||
|
||
### Example | ||
|
||
```mew | ||
#name "Demo" | ||
#reference "../../foo.mewx" | ||
#reference "../../bar.mewx" | ||
#load "utils.mew" | ||
// ... | ||
``` |
Oops, something went wrong.