Skip to content

Commit

Permalink
update ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jul 28, 2024
1 parent b4d35d3 commit 720ed64
Show file tree
Hide file tree
Showing 48 changed files with 524 additions and 357 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
Expand All @@ -21,4 +20,4 @@ jobs:
run: bun src/test.ts

- name: Perform tests
run: bun test
run: bun test
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"workbench.iconTheme": "material-icon-theme"
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
v0.0.0-wip</pre></h3>

## Capabilities

- ✅ Tokenizer
- ✅ Scopes

Expand All @@ -19,6 +20,7 @@ v0.0.0-wip</pre></h3>
- ✅ Transpile to AssemblyScript

## Achievements

- ✅ Hello World with all handwritten pieces
- ✅ Simple math operations

Expand Down Expand Up @@ -103,4 +105,4 @@ const instance = new WebAssembly.Instance(module, {
});

instance.exports.main(3,4)
```
```
2 changes: 1 addition & 1 deletion docs/specification/Exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ The syntax in Zep is like so
fn add(a: i32, b: i32) -> i32 {
rt a + b
}
```
```
2 changes: 1 addition & 1 deletion docs/specification/Imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ bar();
baz();
```

If no `as` option is supplied, the exports are attached to the namespace of the file's name.
If no `as` option is supplied, the exports are attached to the namespace of the file's name.
5 changes: 2 additions & 3 deletions docs/specification/Loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

## Design


```rust
#[extern]: env.print
fn print(data: i32) -> void

#[export]: main
fn main() -> void {
print(5)

for i in 0..5 {
print(i)
}
Expand All @@ -21,4 +20,4 @@ fn main() -> void {
print(num)
}
}
```
```
17 changes: 11 additions & 6 deletions src/ast/Range.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Program } from "./Program";
export class RangeData {
public line: number = 0;
public column: number = 0;
}

export class Range {
public line: number;
public start: number;
public end: number;
constructor(line: number, start: number, end: number) {
this.line = line;
public start: RangeData;
public end: RangeData;
// public source: Source;
constructor(start: RangeData, end: RangeData) {
this.start = start;
this.end = end;
}
static from(start: Range, end: Range): Range {
return new Range(start.start, end.end);
}
}
6 changes: 5 additions & 1 deletion src/ast/nodes/BinaryExpression.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range.js";
import { Expression } from "./Expression.js";
import { Statement } from "./Statement.js";

Expand All @@ -10,16 +11,19 @@ export class BinaryExpression extends Expression {
left: Expression | Statement,
operand: Operator,
right: Expression | Statement,
range: Range,
) {
super();
this.left = left;
this.operand = operand;
this.right = right;
this.range = range;
}
}

export enum Operator {
Add = "+",
Sub = "-",
Assign = "="
Assign = "=",
Mod = "%"
}
9 changes: 7 additions & 2 deletions src/ast/nodes/BlockExpression.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Scope } from "../../checker/scope/Scope.js";
import { Range } from "../Range.js";
import { Expression } from "./Expression.js";
import { Statement } from "./Statement.js";

export class BlockExpression extends Expression {
public nameOf: string = "BlockExpression";
public scope: Scope = new Scope();
constructor(public statements: Statement[]) {
public statements: Statement[];
public scope: Scope;
constructor(statements: Statement[], scope: Scope, range: Range) {
super();
this.statements = statements;
this.scope = scope;
this.range = range;
}
}
8 changes: 5 additions & 3 deletions src/ast/nodes/BooleanLiteral.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Range } from "../Range.js";
import { Expression } from "./Expression.js";

export class BooleanLiteral extends Expression {
public nameOf: string = "BooleanLiteral";
constructor(
public value: boolean
) {
public value: boolean;
constructor(value: boolean, range: Range) {
super();
this.value = value;
this.range = range;
}
}
6 changes: 4 additions & 2 deletions src/ast/nodes/BranchStatement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range.js";
import { BlockExpression } from "./BlockExpression.js";
import { Identifier } from "./Identifier.js";
import { Statement } from "./Statement.js";
Expand All @@ -6,9 +7,10 @@ export class BranchStatement extends Statement {
public nameOf: string = "BranchStatement";
public name: Identifier;
public block: BlockExpression;
constructor(name: Identifier, block: BlockExpression) {
constructor(name: Identifier, block: BlockExpression, range: Range) {
super();
this.name = name;
this.block = block;
this.range = range;
}
}
}
6 changes: 4 additions & 2 deletions src/ast/nodes/BranchToStatement.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Range } from "../Range.js";
import { Identifier } from "./Identifier.js";
import { Statement } from "./Statement.js";

export class BranchToStatement extends Statement {
public nameOf: string = "BranchStatement";
public to: Identifier;
constructor(to: Identifier) {
constructor(to: Identifier, range: Range) {
super();
this.to = to;
this.range = range;
}
}
}
11 changes: 7 additions & 4 deletions src/ast/nodes/CallExpression.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Range } from "../Range.js";
import { Expression } from "./Expression.js";
import { Identifier } from "./Identifier.js";

export class CallExpression extends Expression {
public nameOf: string = "CallExpression";
constructor(
public calling: Identifier,
public parameters: Expression[],
) {
public calling: Identifier;
public parameters: Expression[];
constructor(calling: Identifier, parameters: Expression[], range: Range) {
super();
this.calling = calling;
this.parameters = parameters;
this.range = range;
}
}
6 changes: 4 additions & 2 deletions src/ast/nodes/DoStatement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range";
import { BlockExpression } from "./BlockExpression";
import { Expression } from "./Expression.js";
import { Statement } from "./Statement.js";
Expand All @@ -6,9 +7,10 @@ export class DoStatement extends Statement {
public nameOf: string = "DoStatement";
public condition: Expression;
public block: BlockExpression;
constructor(condition: Expression, block: BlockExpression) {
constructor(condition: Expression, block: BlockExpression, range: Range) {
super();
this.condition = condition;
this.block = block;
this.range = range;
}
}
}
4 changes: 3 additions & 1 deletion src/ast/nodes/EnumDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range.js";
import { EnumElement } from "./EnumElement.js";
import { Identifier } from "./Identifier.js";
import { Statement } from "./Statement.js";
Expand All @@ -6,9 +7,10 @@ export class EnumDeclaration extends Statement {
public nameOf: string = "EnumDeclaration";
public name: Identifier;
public elements: EnumElement[];
constructor(name: Identifier, elements: EnumElement[] = []) {
constructor(name: Identifier, elements: EnumElement[] = [], range: Range) {
super();
this.name = name;
this.elements = elements;
this.range = range;
}
}
4 changes: 3 additions & 1 deletion src/ast/nodes/EnumElement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range.js";
import { Identifier } from "./Identifier.js";
import { NumberLiteral } from "./NumberLiteral.js";
import { Statement } from "./Statement.js";
Expand All @@ -6,9 +7,10 @@ export class EnumElement extends Statement {
public nameOf: string = "EnumElement";
public name: Identifier;
public value: NumberLiteral;
constructor(name: Identifier, value: NumberLiteral) {
constructor(name: Identifier, value: NumberLiteral, range: Range) {
super();
this.name = name;
this.value = value;
this.range = range;
}
}
3 changes: 3 additions & 0 deletions src/ast/nodes/Expression.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Range } from "../Range";

export class Expression {
public nameOf: string = "Expression";
public range: Range = new Range(-1, -1, -1);
}
6 changes: 4 additions & 2 deletions src/ast/nodes/Function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Scope } from "../../checker/scope/Scope.js";
import { Range } from "../Range.js";
import { BlockExpression } from "./BlockExpression.js";
import { Identifier } from "./Identifier.js";
import { ParameterExpression } from "./ParameterExpression.js";
Expand All @@ -10,7 +11,6 @@ export class FunctionDeclaration extends Statement {
public name: Identifier;
public parameters: ParameterExpression[];
public returnType: TypeExpression;
//public genericType: TypeExpression | null;
public block: BlockExpression;
public scope: Scope;
public exported: boolean;
Expand All @@ -20,7 +20,8 @@ export class FunctionDeclaration extends Statement {
returnType: TypeExpression,
block: BlockExpression,
scope: Scope,
exported: boolean
exported: boolean,
range: Range,
) {
super();
this.name = name;
Expand All @@ -32,5 +33,6 @@ export class FunctionDeclaration extends Statement {
for (const param of this.parameters) {
this.scope.add(param.name.data, param);
}
this.range = range;
}
}
5 changes: 4 additions & 1 deletion src/ast/nodes/FunctionImport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range.js";
import { Identifier } from "./Identifier.js";
import { ParameterExpression } from "./ParameterExpression.js";
import { Statement } from "./Statement.js";
Expand All @@ -16,13 +17,15 @@ export class FunctionImport extends Statement {
name: Identifier,
parameters: ParameterExpression[],
returnType: TypeExpression,
exported: boolean
exported: boolean,
range: Range,
) {
super();
this.path = path;
this.name = name;
this.parameters = parameters;
this.returnType = returnType;
this.exported = exported;
this.range = range;
}
}
7 changes: 3 additions & 4 deletions src/ast/nodes/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Expression } from "./Expression.js";

export class Identifier extends Expression {
public nameOf: string = "Identifier";
constructor(
public data: string,
public range: Range,
) {
public data: string;
constructor(value: string, range: Range) {
super();
this.data = value;
}
}
6 changes: 4 additions & 2 deletions src/ast/nodes/IfStatement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Range } from "../Range";
import { BlockExpression } from "./BlockExpression";
import { Expression } from "./Expression.js";
import { Statement } from "./Statement.js";
Expand All @@ -6,9 +7,10 @@ export class IfStatement extends Statement {
public nameOf: string = "IfStatement";
public condition: Expression;
public block: BlockExpression;
constructor(condition: Expression, block: BlockExpression) {
constructor(condition: Expression, block: BlockExpression, range: Range) {
super();
this.condition = condition;
this.block = block;
this.range = range;
}
}
}
4 changes: 3 additions & 1 deletion src/ast/nodes/ImportDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Range } from "../Range.js";
import { Identifier } from "./Identifier.js";
import { Statement } from "./Statement.js";

export class ImportDeclaration extends Statement {
public nameOf: string = "ImportDeclaration";
public path: Identifier;
constructor(path: Identifier) {
constructor(path: Identifier, range: Range) {
super();
this.path = path;
this.range = range;
}
}
Loading

0 comments on commit 720ed64

Please sign in to comment.