Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
aafa284
use cargo commands directly from pre-commit config
lk16 Sep 29, 2024
f0ffe88
fix clippy errors in aaa
lk16 Sep 29, 2024
c7bd55b
fix clippy errors in aaa-stdlib
lk16 Sep 29, 2024
ef944b1
remove python implementation of Aaa transpiler and runner
lk16 Sep 29, 2024
1f72544
Merge pull request #235 from lk16/234-remove-python-code
lk16 Sep 29, 2024
b14083a
improve readme and update TODO comments
lk16 Sep 29, 2024
92bbb31
Merge pull request #240 from lk16/236-improve-readme
lk16 Sep 29, 2024
faa4227
support using Option and Result without import
lk16 Sep 29, 2024
7c5e080
Merge pull request #242 from lk16/208-builtin-option-and-result
lk16 Sep 30, 2024
fc91b00
update TODO comments
lk16 Sep 29, 2024
eb01467
require brackets for builtin structs
lk16 Sep 29, 2024
a1b99c8
parse interfaces
lk16 Sep 30, 2024
f2f012d
cross reference interfaces
lk16 Oct 1, 2024
e2f8e44
wip: implement Showable interface for builtin types
lk16 Oct 2, 2024
293acf0
wip: start implementing build_interface_implementors_table()
lk16 Oct 2, 2024
9de2b38
build interface mapping table in type checker
lk16 Oct 2, 2024
644d1c1
generate interface mapping in transpiler
lk16 Oct 2, 2024
e6d0636
move interface mapping into Stack type
lk16 Oct 2, 2024
b62a722
implement and run Show successfully with interface table
lk16 Oct 2, 2024
fffbb1b
update todo comments
lk16 Oct 2, 2024
5c87ecd
stop depending on Display trait for user types in generated code
lk16 Oct 4, 2024
26fa165
support using builtin interfaces from user types
lk16 Oct 4, 2024
8c62814
rename Showable to Show
lk16 Oct 4, 2024
c3fa370
remove old TODO
lk16 Oct 4, 2024
6ad993f
update TODO comments
lk16 Oct 4, 2024
2b90737
add interface Debug and remove generating Debug impl in transpiler
lk16 Oct 5, 2024
98adfd2
support action directive in doctests
lk16 Oct 5, 2024
6bc8f4f
add some tests for interfaces
lk16 Oct 5, 2024
1341331
remove dead code and update TODO comment
lk16 Oct 5, 2024
a5fc741
move interface mapping behind Arc
lk16 Oct 5, 2024
bdae7b6
support calling interface functions explicitly
lk16 Oct 5, 2024
52378ae
update TODO comments
lk16 Oct 5, 2024
de6a176
support using interface values as a function argument type
lk16 Oct 5, 2024
4238b1b
fix Show for vec, set and map
lk16 Oct 5, 2024
c4ff24e
add skipped and failing doctest
lk16 Oct 5, 2024
249c513
support using interface as type parameter
lk16 Oct 6, 2024
b78effa
support using using vec[int] as vec[Show]
lk16 Oct 6, 2024
459b0df
add more interface tests
lk16 Oct 6, 2024
5f0a48c
update TODO comments
lk16 Oct 6, 2024
85dc3b0
update TODO comments
lk16 Oct 6, 2024
f401551
build interfaces table as vector in type checker
lk16 Oct 6, 2024
b1227a9
generate interface mapping as one-layer hashtable
lk16 Oct 6, 2024
17ef14a
handle errors validating function self argument
lk16 Oct 6, 2024
9693dc6
add failing and skipped test
lk16 Oct 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
name: Python package
name: Build

on: [push, pull_request]
env:
CARGO_TERM_COLOR: always

jobs:
build-python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12.1
uses: actions/setup-python@v2
with:
python-version: "3.12.1"
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: "3.12.1" # Version range or exact version of a Python version to use, the same as actions/setup-python
architecture: x64 # The target architecture (x86, x64) of the Python interpreter. the same as actions/setup-python
version: head
prerelease: false # Allow prerelease versions of PDM to be installed
enable-pep582: false # Enable PEP 582 package loading globally
allow-python-prereleases: false # Allow prerelease versions of Python to be installed. For example if only 3.12-dev is available, 3.12 will fallback to 3.12-dev
- name: Install dependencies
run: |
cd python
pdm install
- name: Run linters
run: |
cd python
pdm add pre-commit
pdm run pre-commit run --all-files
- name: Run Python tests
run: |
cd python
pdm install --production
export AAA_STDLIB_PATH=$(pwd)/../stdlib
pdm run pytest --color=yes --cov=aaa --cov-report=term-missing -x -vv
build-rust:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run linters
run: |
pip install pre-commit
pre-commit run --all-files
- name: Build
run: |
export AAA_STDLIB_PATH=$(pwd)/stdlib
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.python-version
__pycache__
.coverage
*.code-workspace
.envrc
Expand Down
62 changes: 23 additions & 39 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ repos:
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: check-yaml
- id: check-json
exclude: "aaa-vscode-extension/.*"
Expand All @@ -14,48 +13,33 @@ repos:

- repo: local
hooks:
- id: mypy
name: run mypy
- id: cargo-check-aaa
name: aaa cargo check
language: system
entry: mypy --strict
types: [python]

- repo: https://github.com/lk16/detect-missing-init
rev: v0.1.6
hooks:
- id: detect-missing-init
args:
["--create", "--track", "--python-folders", "python/aaa,python/tests"]

- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
entry: cargo check --manifest-path aaa/Cargo.toml
pass_filenames: false
args: [--manifest-path, aaa-stdlib/Cargo.toml]
- id: cargo-check
- id: cargo-fmt-aaa
name: aaa cargo fmt
language: system
entry: cargo check --manifest-path aaa/Cargo.toml
pass_filenames: false
args: [--manifest-path, aaa-stdlib/Cargo.toml]
- id: clippy
- id: cargo-clippy-aaa
name: aaa cargo clippy
language: system
entry: cargo clippy --manifest-path aaa/Cargo.toml -- -Dwarnings
pass_filenames: false
args: [--manifest-path, aaa-stdlib/Cargo.toml]

- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: cargo-check-aaa-stdlib
name: aaa-stdlib cargo check
language: system
entry: cargo check --manifest-path aaa-stdlib/Cargo.toml
pass_filenames: false
args: [--manifest-path, aaa/Cargo.toml]
- id: cargo-check
- id: cargo-fmt-aaa-stdlib
name: aaa-stdlib cargo fmt
language: system
entry: cargo check --manifest-path aaa-stdlib/Cargo.toml
pass_filenames: false
args: [--manifest-path, aaa/Cargo.toml]
- id: clippy
- id: cargo-clippy-aaa-stdlib
name: aaa-stdlib cargo clippy
language: system
entry: cargo clippy --manifest-path aaa-stdlib/Cargo.toml -- -Dwarnings
pass_filenames: false
args: [--manifest-path, aaa/Cargo.toml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
79 changes: 22 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
# Aaa
Stack-based language, like forth.

### Contents
The following tools for the Aaa language can be found is this repo
* A [parser](./python/aaa/parser/) for Aaa.
* A [type checker](./python/aaa/type_checker/)
* A [transpiler to Rust](./python/aaa/transpiler/)
* A [VS Code extension](./aaa-vscode-extension/README.md) for the Aaa language.
* A lot of tests, written both in python and Aaa
This project implements tools for working with the Aaa programming language.

### Examples
The language is stack-based and is inspired by [Forth](https://en.wikipedia.org/wiki/Forth_(programming_language)) and [Porth](https://gitlab.com/tsoding/porth).


### Installation
```sh
cd python
# Install aaa transpiler and runner tool. Run from repository root.
cargo install --path aaa
```


### Examples

<!-- TODO #237 add tests for examples -->

```sh
# Run the obligatory hello world example
pdm run ./manage.py run 'fn main { "Hello world\n" . }'
aaa run 'fn main { "Hello world\n" . }'

# Run code from a file. Implements the famous fizzbuzz interview question.
pdm run ./manage.py run examples/fizzbuzz.aaa
aaa run examples/fizzbuzz.aaa

# Run bare-bones HTTP server in Aaa
pdm run ./manage.py run examples/http_server.aaa
aaa run examples/http_server.aaa

# Send request from different shell
curl http://localhost:8080
```

### Running tests

<!-- TODO #218 Add command for running tests and make sure the below example works. -->

```sh
# Run tests written in Aaa
pdm run ./manage.py test .
aaa test .

# Run tests written in Python
pdm run pytest
# Run tests written in Rust
cargo test --manifest-path aaa/Cargo.toml
```


### Aaa features
- elementary types (`int`, `bool`, `str`)
- container types (`vec`, `map`)
Expand All @@ -48,45 +53,5 @@ pdm run pytest
### Name
The name of this language is just the first letter of the Latin alphabet repeated three times. When code in this language doesn't work, its meaning becomes an [abbreviation](https://en.uncyclopedia.co/wiki/AAAAAAAAA!).

### Setup
All these commands should be run from the root of this repository.

This project requires python 3.12.1 or newer. Consider using [pyenv](https://github.com/pyenv/pyenv).

```sh
# Download python 3.12.1
pyenv install 3.12.1

# Use it in this project
pyenv local 3.12.1
```

This project also requires rust, see instructions [here](https://www.rust-lang.org/tools/install) on how to install.

After you setup rust and python, run the following commands.

```sh
# Install dependencies
pdm install

# Tell Aaa where the standard library lives
export AAA_STDLIB_PATH=$(pwd)/stdlib

# Run hello world program
pdm run ./manage.py run 'fn main { "Hello world\n" . }'

# Run tests
pdm run pytest
pdm run ./manage.py test .

# Setup pre-commit hooks
pdm run pre-commit install
```

Now you can start running code in Aaa or develop the language!

To enable syntax highlighting for VS Code, enable the [Aaa language extension](./aaa-vscode-extension/README.md)


### Aaa and porth
After watching part of the [Youtube series](https://www.youtube.com/playlist?list=PLpM-Dvs8t0VbMZA7wW9aR3EtBqe2kinu4) on [porth](https://gitlab.com/tsoding/porth), I wanted to make my own stack-based language. Aaa and porth have some similarities, but obviously are not compatible with each other. No code was copied over from the porth repo.
7 changes: 7 additions & 0 deletions aaa-stdlib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aaa-stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lazy_static = "1.5.0"
nix = "0.26.2"
regex = "1.8.4"
22 changes: 22 additions & 0 deletions aaa-stdlib/src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::stack::InterfaceMappingType;

fn call_interface_function<T>(
interface_mapping: &InterfaceMappingType<T>,
interface_name: &str,
function_name: &str,
) {
let top = self.top();
let top_type_id = top.type_id();

let interface_name = format!("builtins:{}", interface_name);

let first_key = &(interface_name.as_str(), top_type_id.as_str());

let function = interface_mapping
.get(first_key)
.unwrap()
.get(function_name)
.unwrap();

function(self);
}
27 changes: 0 additions & 27 deletions aaa-stdlib/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
cell::RefCell,
collections::hash_map::DefaultHasher,
fmt::{Display, Formatter, Result},
hash::{Hash, Hasher},
rc::Rc,
};
Expand Down Expand Up @@ -149,16 +148,6 @@ where
);
}
}

pub fn fmt_as_set(&self) -> String {
let mut parts = vec![];
for bucket in self.buckets.borrow().iter() {
for (k, _) in bucket.iter() {
parts.push(format!("{k:?}"));
}
}
format!("{{{}}}", parts.join(","))
}
}

impl<K, V> PartialEq for Map<K, V>
Expand Down Expand Up @@ -193,22 +182,6 @@ where
{
}

impl<K, V> Display for Map<K, V>
where
K: UserType,
V: UserType,
{
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let mut parts = vec![];
for bucket in self.buckets.borrow().iter() {
for (k, v) in bucket.iter() {
parts.push(format!("{k:?}: {v:?}"));
}
}
write!(f, "{{{}}}", parts.join(", "))
}
}

impl<K, V> Clone for Map<K, V>
where
K: UserType,
Expand Down
2 changes: 1 addition & 1 deletion aaa-stdlib/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Display for SetValue {
}

impl UserType for SetValue {
fn kind(&self) -> String {
fn type_id(&self) -> String {
String::from("SetValue")
}

Expand Down
Loading