Skip to content

Commit

Permalink
Start revision plans
Browse files Browse the repository at this point in the history
  • Loading branch information
DustTheory committed Aug 29, 2024
1 parent 278bbc4 commit 6de5ef7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
96 changes: 96 additions & 0 deletions revision_docs/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# VecM Language Revision 1.0 - Current state
## Current state of the language, and plans for it's improvement
So far development of the language has entirely been an exercise in compiler development. No thought was put into the design. Now that I have a pretty good idea how to build a compiler, I can start thinking about the language itself.

### Syntax
I came up with the syntax as I went, I did not much care about anything except implementing individual features. The syntax is a mess, and I need to clean it up.

Misc syntax issues:

- `;` is the statement terminator - it is not defined if it's mandatory or when. The parser is the judge of that, don't make it angry.

#### Types
The language has the following types:
- `int8` or `char` - 8-bit signed integer
- `int16` - 16-bit signed integer
- `int32` or `int` - 32-bit signed integer
- `int64` - 64-bit signed integer
- `uint8` - 8-bit unsigned integer
- `uint16` - 16-bit unsigned integer
- `uint32` - 32-bit unsigned integer
- `uint64` - 64-bit unsigned integer
- `float32` - 32-bit floating point number
- `float64` - 64-bit floating point number
- `bool` - boolean
- `string` - string
- `array` - array
- `hash` - hash
- `null` - null
- `void` - void
- Named types (structs, enums, etc.) were planned but aren't implemented yet.

Issues with types:
- `int` is a 32-bit signed integer, but `int32` is also a 32-bit signed integer. I need to decide which one to keep.
- `int8` and `char` are the same thing, I need to decide which one to keep.
- `string` is a type, but it's not clear how it's implemented. I need to decide if it's a primitive type or a class.
- `array` and `hash` are types, but it's not clear how they're implemented. I need to decide if they're primitive types or classes.
- `null` - I'm not even sure if this is a usable type, I think it's just there cause I invented it

Additional notes on types:
- I think I like shorter type names so `i8` instead of `int8`, `i16` instead of `int16`, etc.

Type annotations are done in several ways, and can be implicit:
- `const int a = 1;`
- `const a: int = 1;`
- `const a = 1;`
- `let a = 1;`
- `a := 1`

### Memory model
The language started with an interpreter, written in go, using Go's garbage collector. The compiler currently only manages local variables on the stack, and doesn't support arrays, strings, hashes, heap allocation, etc. I need to decide on a memory model for my compiler and implement it. It cannot remain as it is now with the interpreter.

### Errors
Parser errors are impossible to understant. They need to be human readable. The issue isn't in just pretty-printing and nicer error messages. The issue is errors like:

```
parser error: Parser error at line 1, column 1:
export const main = fn() -> void {
^
invalid token in declaration statement. expected="=" got="fibSize"
```

Can you guess what the issue here is?
```
export const main = fn() -> void {
[] // <-- This random token is the issue
const int fibSize = 50;
```
The message is correct `invalid token` although I'd like to change that to `Unexpected Token`, but the line and column are wrong, and I have no idea why `=` is expected here.


Compiler errors are in a similar state.

New rule: Every time an error is bad, add it to a .md file in this directory, and fix those later.

### Compiler Logs
No compiler logs are generated - this sucks, as it would ease development significantly.

TODO: Add logging system - with different log levels
New rule: every new method has to consider logging

### Standard Library
There is no standard library or ability to call external functions. This is a must-have feature.

### Module/Packages system
A module/package system exists partly in the system but isn't implemented yet.

### Documentation
There is no documentation, and the code is not well commented.

TODO: Enforce documentation with a linter.

### Code style
There is no coding standards, no linter, and no formatter.

TODO: Add linter and formatter, and apply to entire codebase.

26 changes: 26 additions & 0 deletions revision_docs/new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# VecM Language Revision 1.0 - New Syntax

the [current state](current.md) of the language is relevant to this document.

## Types

### Primitive types
The language has the following primitive types:
- `i8` - 8-bit signed integer
- `i16` - 16-bit signed integer
- `i32` - 32-bit signed integer
- `i64` - 64-bit signed integer
- `u8` - 8-bit unsigned integer
- `u16` - 16-bit unsigned integer
- `u32` - 32-bit unsigned integer
- `u64` - 64-bit unsigned integer
- `f32` - 32-bit floating point number
- `f64` - 64-bit floating point number
- `bool` - boolean.

Default values for arrays are 0 for numbers, false for bools, and null for pointers.

### Named types
Structs and enums are not planned in revision 1.0.
They may get partially implemented if I so choose

0 comments on commit 6de5ef7

Please sign in to comment.