compiler: add local scope basics

This commit is contained in:
Luna 2019-06-03 15:10:12 -03:00
parent 69dda36d16
commit 25ee586acb

View file

@ -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,
};
}