Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
Stack-based language, like forth.

### Contents
The following tools for the Aaa language can be found is this repo
The following tools for the Aaa language can be found is this repository:
* A [tokenizer](./aaa/tokenizer/) and [parser](./aaa/parser/) for Aaa.
* A [type checker](./aaa/type_checker/)
* A [transpiler to Rust](./aaa/transpiler/)
* A [VS Code extension](./aaa-vscode-extension/README.md) for the Aaa language.
* A [formatter](./aaa/formatter.py) for Aaa source files.
* A lot of tests, written both in python and Aaa

### Examples
Expand Down Expand Up @@ -85,6 +86,26 @@ 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)

### Setup format on save
For VS Code follow these steps:
* Install the [Run on Save](https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save) extension.
* Merge the JSON configuration below into your `*.code-workspace` JSON file.

```json
{
"settings": {
"runOnSave.commands": [
{
"match": ".*\\.aaa$",
"command": "cd ${workspaceFolder} && pdm run ./manage.py format --stdlib-path ./stdlib ${file} --fix",
"runIn": "backend",
"runningStatusMessage": "Formatting ${fileBasename}",
"finishStatusMessage": "${fileBasename} was formatted"
},
]
}
}
```

### 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.
17 changes: 17 additions & 0 deletions aaa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import secrets
from pathlib import Path
from tempfile import gettempdir
Expand Down Expand Up @@ -64,6 +65,22 @@ class AaaException(Exception):
...


class AaaEnvironmentError(AaaException):
...


def get_stdlib_path() -> Path:
try:
stdlib_folder = os.environ["AAA_STDLIB_PATH"]
except KeyError as e:
raise AaaEnvironmentError(
"Environment variable AAA_STDLIB_PATH is not set.\n"
+ "Cannot find standard library!"
) from e

return Path(stdlib_folder) / "builtins.aaa"


AAA_DEFAULT_OUTPUT_FOLDER_ROOT = Path(gettempdir()) / "aaa/transpiled"
AAA_TEST_OUTPUT_FOLDER_ROOT = Path(gettempdir()) / "aaa/transpiled/tests"

Expand Down
6 changes: 4 additions & 2 deletions aaa/cross_referencer/cross_referencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,9 @@ def run(self) -> FunctionBody:
def _resolve_function_body(self, parsed_body: parser.FunctionBody) -> FunctionBody:
return FunctionBody(
items=[
self._resolve_function_body_item(item) for item in parsed_body.items
self._resolve_function_body_item(item)
for item in parsed_body.items
if type(item) != parser.Comment
],
parsed=parsed_body,
)
Expand Down Expand Up @@ -856,7 +858,7 @@ def _resolve_function_body_item(
parser.WhileLoop: self._resolve_while_loop,
}

assert set(resolve_functions.keys()) == set(parser.FunctionBodyItem.__args__) # type: ignore
assert set(resolve_functions.keys()) == set(parser.FunctionBodyItem.__args__) - {parser.Comment} # type: ignore
return resolve_functions[type(parsed_item)](parsed_item)

def _resolve_function_pointer_literal(
Expand Down
Loading