-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tlaceby/symbol-table-refactor
Refactor SymbolTable (Scope) For CodeGen
- Loading branch information
Showing
23 changed files
with
659 additions
and
1,759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.