compiler: add local scope basics
This commit is contained in:
parent
69dda36d16
commit
25ee586acb
1 changed files with 15 additions and 0 deletions
|
@ -113,6 +113,11 @@ var rules = []ParseRule{
|
|||
ParseRule{},
|
||||
};
|
||||
|
||||
pub const Local = struct {
|
||||
name: tokens.Token,
|
||||
depth: i32,
|
||||
};
|
||||
|
||||
pub const Compiler = struct {
|
||||
src: []const u8,
|
||||
stdout: vm.StdOut,
|
||||
|
@ -123,6 +128,10 @@ pub const Compiler = struct {
|
|||
debug_flag: bool = false,
|
||||
vmach: *vm.VM,
|
||||
|
||||
locals: [256]Local,
|
||||
localCount: u8 = 0,
|
||||
scopeDepth: u8 = 0,
|
||||
|
||||
pub fn init(
|
||||
allocator: *Allocator,
|
||||
chunk: *chunks.Chunk,
|
||||
|
@ -139,6 +148,12 @@ pub const Compiler = struct {
|
|||
.parser = Parser{},
|
||||
.debug_flag = debug_flag,
|
||||
.vmach = vmach,
|
||||
|
||||
// local variable resolution
|
||||
.locals = []Local{Local{
|
||||
.name = Token{},
|
||||
.depth = -1,
|
||||
}} ** 256,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue