|
|
2 天之前 | |
|---|---|---|
| examples | 2 天之前 | |
| src | 2 天之前 | |
| .envrc | 1 月之前 | |
| .gitignore | 4 天之前 | |
| LICENSE | 1 月之前 | |
| README.md | 2 天之前 | |
| flake.lock | 1 月之前 | |
| flake.nix | 2 天之前 |
Compiled object-oriented programming language
Lexer --> Preprocessor (unimplemented) --> Parser --> Expander --> Validator --> Codegen (--> Optimizer (LLVM's opt))
#fn name($x: expr, $y: ident) {
... template tokens ...
}
class Parser {
val tokens: Arr<Token>
val cursor: Int
// :: for constructor?, under the hood so vert denne funksjonen kjørt av ein anna der self har blitt laga, allocated, idk, noko sånn. Den hook constructor funksjonen har alle members av classen og returner pointer til objektet i minne
fn::new(self, tokens: Arr<Token>) {
self.tokens = tokens
self.cursor = Int::from(0)
}
}
fn main() -> i64 {
val parser: Parser = Parser::new(etcetc...) // with hooked constructor, also puts reference counting
val parser_manually: &Parser = mem.alloc(mem.sizeof(Parser)) // will not be tracked by reference counter, the pointer address is not added to the GC's pointer track list. GC only counts addresses in it's list
*parser_manually.tokens = ...
*parser_manually.cursor = ...
mem.free(parser_manually)
// Kanskje noko sånn heller?
val allocated: Result<&OtherClass> = mem.alloc(mem.sizeof(OtherClass))
val allocated_real: &OtherClass = allocated.expect("yes!")
mem.free(allocated_real)
// Alternativ, meire generics?
val allocated: Result<&OtherClass> = mem.alloc<OtherClass>()
val allocated_real: &OtherClass = allocated.expect("Couldn't allocate memory")
return 0
}