Skip to content

Commit 05310ce

Browse files
Initial commit
0 parents  commit 05310ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+17302
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
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.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
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.
28+
29+
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.
30+
31+
## Scope
32+
33+
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.
34+
35+
## Enforcement
36+
37+
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.
38+
39+
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.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Patrik Svensson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Documentation
2+
3+
This is the documentation for Mew.
4+
5+
## Running
6+
7+
```console
8+
$ npm install
9+
$ npx docusaurus start
10+
```

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};

blog/2023-10-09.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Trying this again
3+
authors: [patrik]
4+
tags: [mew]
5+
---
6+
7+
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.

blog/2024-05-07.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: A long overdue update
3+
authors: [patrik]
4+
tags: [mew]
5+
---
6+
7+
Life got in the way, but I've picked up this project again.
8+
9+
I've reduced the project scope to get something
10+
that works reliably out the door feasible; this means that Mew will be based on
11+
the .NET runtime, and as a first step, not generate CIL myself but
12+
transpile Mew to (non-optimal) C# code. This will hopefully make it easier
13+
to get something out and experiment with the language.
14+
15+
I'm focusing on documenting every aspect of the language that I would want
16+
to see in the first version. Once that is done, I will open the repository
17+
and open-source the project. Hopefully other people can learn from all my mistakes.
18+
19+
:::note
20+
Mew is a learning exercise in compilers and an experiment to see if I
21+
can create something usable, mostly from a scripting perspective.
22+
:::

blog/authors.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
patrik:
2+
name: Patrik Svensson
3+
title: Maintainer of Mew
4+
url: https://github.com/patriksvensson
5+
image_url: https://github.com/patriksvensson.png

docs/compiler/index.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# Compiler
6+
7+
This page contains a high level breakdown of the different
8+
steps needed to compile Mew code.
9+
10+
```mermaid
11+
flowchart LR;
12+
subgraph Frontend
13+
AST-->HIR
14+
HIR-->MIR
15+
MIR-->LIR
16+
end
17+
subgraph Backend
18+
LIR-->C#
19+
C#-->CIL
20+
LIR-. Future .->CIL
21+
end
22+
```
23+
24+
## 1. AST Parsing
25+
26+
The parsing step iterates through all source files, and
27+
builds a syntax tree for each of them.
28+
The syntax tree represents the code as it was written,
29+
maintaining the trivia such as white space, comments etc.
30+
31+
Each node in the AST has a reference to both it's parent
32+
and children.
33+
34+
Apart from being the basis for `HIR` generation, the AST
35+
is also used to interact with the source code programatically,
36+
i.e. from the LSP server.
37+
38+
## 2. `HIR` generation
39+
40+
HIR, short for _High-level Intermediate Representation_,
41+
represents a bound tree, where all types are known.
42+
43+
The HIR references resolved _symbols_ for the different parts
44+
of Mew (namespaces, types, functions, parameters, variables etc).
45+
For example, two code block that calls a function, will have
46+
the same symbol reference to that function.
47+
48+
1. Build symbol table
49+
1. Namespaces
50+
1. Types
51+
1. Free functions
52+
1. Type members
53+
1. Binding
54+
1. Types
55+
1. Free functions
56+
1. Top level statements
57+
58+
:::info
59+
HIR might contain errors, represented as error symbols.
60+
:::
61+
62+
## 3. `MIR` generation
63+
64+
MIR, short for _Medium-level Intermediate Representation_,
65+
is a lowered HIR, without constructs such as `while`/`loop`/`if`.
66+
67+
All higher level constructs such as loops and conditions
68+
been lowered into labels and branches.
69+
70+
Control flow analysis and some optimizations
71+
are done here as well.
72+
73+
:::info
74+
MIR might contain errors, represented as error symbols.
75+
:::
76+
77+
## 4. `LIR` generation
78+
79+
LIR, short for _Low-level Intermediate Representation_,
80+
is a lowered MIR, resembling the final byte code that will
81+
be emitted.
82+
83+
:::warning
84+
LIR **MUST NOT** contain any errors.
85+
:::
86+
87+
## 5. Emitting
88+
89+
Finally, the LIR is transpiled into C# and compiled to
90+
native assembly code using NativeAOT, which in turn can be executed.
91+
92+
:::note
93+
There are plans in the future to emit CIL directly.
94+
This was done in the early prototype, but turned out to
95+
be too cumbersome while the language was in active development.
96+
:::

docs/future/directives.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
sidebar_position: 120
3+
---
4+
5+
# Directives
6+
7+
:::info
8+
This functionality is not yet implemented
9+
:::
10+
11+
### Import source files
12+
13+
```mew
14+
#load "foo.mew"
15+
#load "stuff/*.mew"
16+
```
17+
18+
### Reference Mew projects
19+
20+
```mew
21+
#reference "../../foo.mewx"
22+
#reference "../../bar.mewx"
23+
```
24+
25+
### Executable name
26+
27+
```mew
28+
#name "MyName"
29+
```
30+
31+
:::note
32+
Can only be specified in a `mewx` project file.
33+
:::

docs/future/generics.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
sidebar_position: 100
3+
---
4+
5+
# Generics
6+
7+
:::info
8+
This functionality is not yet implemented
9+
:::
10+
11+
### Types
12+
13+
```mew
14+
pub type Smallest<T : Comparable<T>> {
15+
mut field smallest : Optional<T>;
16+
17+
pub static fn new() -> MyList<T> {
18+
smallest = Optional<T>.none;
19+
}
20+
21+
pub fn add_smallest(item: T) {
22+
if item == .none {
23+
return;
24+
}
25+
26+
if self.smallest == null ||
27+
item.CompareTo(self.smallest) == -1
28+
{
29+
self.smallest = item;
30+
}
31+
}
32+
33+
pub fn GetSmallest() -> Optional<T> {
34+
return smallest;
35+
}
36+
}
37+
```
38+
39+
### Unions
40+
41+
```mew
42+
pub union Result<T, V : Exception> {
43+
Ok(T),
44+
Err(V),
45+
}
46+
```

docs/future/index.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
sidebar_position: 20
3+
---
4+
5+
# Future

docs/future/interfaces.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
sidebar_position: 90
3+
---
4+
5+
# Interfaces
6+
7+
:::info
8+
This functionality is not yet implemented
9+
:::
10+
11+
```mew
12+
use Mew;
13+
14+
interface Distance {
15+
fn get_distance() -> f64;
16+
}
17+
18+
type Point {
19+
pub field x : i32;
20+
pub field y : i32;
21+
};
22+
23+
impl Distance for Point {
24+
fn get_distance() -> f64 {
25+
return Math::sqrt(
26+
first: self.X * self.X +
27+
second: self.Y * self.Y);
28+
}
29+
}
30+
```
31+
32+
```mew
33+
// Usage:
34+
let point = Point(x: 32, y: 40);
35+
let dist = point.get_distance();
36+
```

docs/future/project-file.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
sidebar_position: 140
3+
---
4+
5+
# Project files
6+
7+
:::info
8+
This functionality is not yet implemented
9+
:::
10+
11+
A Mew project file has the extension `.mewx`.
12+
13+
Project files are normal `.mew` files, except that they
14+
can have additional metadata that describes what references
15+
to include, etc.
16+
17+
### Example
18+
19+
```mew
20+
#name "Demo"
21+
22+
#reference "../../foo.mewx"
23+
#reference "../../bar.mewx"
24+
25+
#load "utils.mew"
26+
// ...
27+
```

0 commit comments

Comments
 (0)