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{},
|
ParseRule{},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Local = struct {
|
||||||
|
name: tokens.Token,
|
||||||
|
depth: i32,
|
||||||
|
};
|
||||||
|
|
||||||
pub const Compiler = struct {
|
pub const Compiler = struct {
|
||||||
src: []const u8,
|
src: []const u8,
|
||||||
stdout: vm.StdOut,
|
stdout: vm.StdOut,
|
||||||
|
@ -123,6 +128,10 @@ pub const Compiler = struct {
|
||||||
debug_flag: bool = false,
|
debug_flag: bool = false,
|
||||||
vmach: *vm.VM,
|
vmach: *vm.VM,
|
||||||
|
|
||||||
|
locals: [256]Local,
|
||||||
|
localCount: u8 = 0,
|
||||||
|
scopeDepth: u8 = 0,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
allocator: *Allocator,
|
allocator: *Allocator,
|
||||||
chunk: *chunks.Chunk,
|
chunk: *chunks.Chunk,
|
||||||
|
@ -139,6 +148,12 @@ pub const Compiler = struct {
|
||||||
.parser = Parser{},
|
.parser = Parser{},
|
||||||
.debug_flag = debug_flag,
|
.debug_flag = debug_flag,
|
||||||
.vmach = vmach,
|
.vmach = vmach,
|
||||||
|
|
||||||
|
// local variable resolution
|
||||||
|
.locals = []Local{Local{
|
||||||
|
.name = Token{},
|
||||||
|
.depth = -1,
|
||||||
|
}} ** 256,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue