Skip to content

Commit

Permalink
Merge pull request #1 from tlaceby/symbol-table-refactor
Browse files Browse the repository at this point in the history
Refactor SymbolTable (Scope) For CodeGen
  • Loading branch information
tlaceby authored Apr 24, 2024
2 parents 506654b + 56d47b8 commit f2b9e5b
Show file tree
Hide file tree
Showing 23 changed files with 659 additions and 1,759 deletions.
63 changes: 8 additions & 55 deletions examples/test.br
Original file line number Diff line number Diff line change
@@ -1,58 +1,11 @@
// main.br
// test.br

unsafe {
type println fn (String) -> Void;
type print fn (String) -> Void;
}
const name = "John Doe";
let x = 20;
let y = x + 5;

trait Error {
fn error () -> String;
}
let conversion: Number = @Number("45.3");
let conversion2: String = @String(x * y);

struct FooError {
fn error () -> String {
return "Error: Foo";
}
}

struct CustomError {
message: String;

static fn new(message: String) -> Self {
return Self {
message: message,
};
}

fn error () -> String {
return self.message;
}
}

fn main () {
const errors = []Error{
CustomError::new("Something went wrong"),
FooError{}
};

const customErr = error[0];
match customErr {
case CustomError {
customErr.message = "Custom Error Occured";
println("CustomError: " + customErr.error());
},

case FooError {
println("FooError: " + customErr.error());
},
}

const e1 = errors[0];
const e2 = errors[1];
const message: String = e1.error() + e2.error();

const numStr = @string(45.21); // Converts Data to a String
const customErr = @assert(CustomError, errors[1]); // casts away a type explicitly. No conversion

println(customErr.error());
}
const result = -x + y;
println(result);
64 changes: 55 additions & 9 deletions examples/traits.br
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
// main.br

// impl Number {
// fn to_string() -> String {
// return as_str(self);
// }
// }
unsafe {
type println fn (String) -> Void;
type print fn (String) -> Void;
}

// unsafe {
// type println = fn (String) -> Void;
// type as_str = fn (Any) -> String;
// }
trait Error {
fn error () -> String;
}

struct FooError {
fn error () -> String {
return "Error: Foo";
}
}

struct CustomError {
message: String;

static fn new(message: String) -> Self {
return Self {
message: message,
};
}

fn error () -> String {
return self.message;
}
}

fn main () {
const errors = []Error{
CustomError::new("Something went wrong"),
FooError{}
};

const customErr = error[0];
match customErr {
case CustomError {
customErr.message = "Custom Error Occured";
println("CustomError: " + customErr.error());
},

case FooError {
println("FooError: " + customErr.error());
},
}

const e1 = errors[0];
const e2 = errors[1];
const message: String = e1.error() + e2.error();

const numStr = @string(45.21); // Converts Data to a String
const customErr = @assert(CustomError, errors[1]); // casts away a type explicitly. No conversion

println(customErr.error());
}

trait Error {
fn error () -> String;
Expand Down
Loading

0 comments on commit f2b9e5b

Please sign in to comment.