// File: /workspace/github_c_makefile_star2_O0/adamjedlicka[P]blu/src/vm/compiler/compiler.c
// Function: initCompiler
static void initCompiler(bluCompiler* compiler, bluCompiler* enclosing, int8_t scopeDepth, bluFunctionType type) {
	if (enclosing != NULL) {
		compiler->vm = enclosing->vm;
		compiler->parser = enclosing->parser;

		compiler->classCompiler = enclosing->classCompiler;

		compiler->file = enclosing->file;
	}

	compiler->enclosing = enclosing;
	compiler->scopeDepth = scopeDepth;
	compiler->type = type;
	compiler->function = bluNewFunction(compiler->vm);

	compiler->hadError = false;
	compiler->panicMode = false;

	bluLocalBufferInit(&compiler->locals);
	bluUpvalueBufferInit(&compiler->upvalues);

	switch (type) {

	case TYPE_FUNCTION:
	case TYPE_METHOD:
	case TYPE_INITIALIZER: {
		bluToken previous = compiler->parser->previous;
		compiler->function->name = bluCopyString(compiler->vm, previous.start, previous.length);
		break;
	}

	case TYPE_ANONYMOUS:
	case TYPE_TOP_LEVEL: {
		compiler->function->name = NULL;
		break;
	}
	}

	bluLocal local;
	local.depth = compiler->scopeDepth;
	local.isUpvalue = false;

	if (type == TYPE_METHOD || type == TYPE_INITIALIZER) {
		// In a method, it holds the receiver, "@".
		local.name.start = "@";
		local.name.length = 1;
	} else {
		// In a function, it holds the function, but cannot be references, so has no name.
		local.name.start = "";
		local.name.length = 0;
	}

	bluLocalBufferWrite(&compiler->locals, local);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl %ecx, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x29d0
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movb %cl, 0x58(%rax)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x79a0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x59(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x5a(%rax)
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
callq 0x1be0
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x1d60
movl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
testl %eax, %eax
je 0x2aab
jmp 0x2a3d
movl -0x64(%rbp), %eax
subl $0x1, %eax
je 0x2a5e
jmp 0x2a47
movl -0x64(%rbp), %eax
subl $0x2, %eax
je 0x2aab
jmp 0x2a51
movl -0x64(%rbp), %eax
addl $-0x3, %eax
subl $0x1, %eax
ja 0x2abb
jmp 0x2a5e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x28(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x30(%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
movzbl -0x28(%rbp), %edx
callq 0x75a0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x78(%rax)
jmp 0x2abb
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq $0x0, 0x78(%rax)
movq -0x8(%rbp), %rax
movb 0x58(%rax), %al
movb %al, -0x40(%rbp)
movb $0x0, -0x3f(%rbp)
cmpl $0x3, -0x18(%rbp)
je 0x2ad5
cmpl $0x4, -0x18(%rbp)
jne 0x2ae6
leaq 0xb6e3(%rip), %rax      # 0xe1bf
movq %rax, -0x58(%rbp)
movb $0x1, -0x50(%rbp)
jmp 0x2af5
leaq 0xb53d(%rip), %rax      # 0xe02a
movq %rax, -0x58(%rbp)
movb $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
movq -0x40(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x60(%rbp), %xmm0
movups -0x50(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x1d10
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)