// File: /workspace/github_c_makefile_star2_O2/goodpaul6[P]generic/script.c
// Function: resolve_symbols
static void resolve_symbols(script_t* script, expr_t* exp)
{
	switch(exp->type)
	{
		case EXP_ATOMIC:
		{
			resolve_symbols(script, exp->atomx);
		} break;
		
		case EXP_DOT: case EXP_COLON:
		{
			resolve_symbols(script, exp->dotx.value);
		} break;
		
		case EXP_STRUCT_NEW:
		{
			for(int i = 0; i < exp->newx.init.length; ++i)
				resolve_symbols(script, vec_get_value(&exp->newx.init, i, expr_t*));
		} break;
		
		case EXP_STRUCT_DECL:
		{
			for(int i = 0; i < exp->struct_tag->ds.members.length; ++i)
			{
				type_tag_member_t* mem = vec_get(&exp->struct_tag->ds.members, i);
				if(mem->default_value)
					resolve_symbols(script, mem->default_value);
			}
		} break;
		
		case EXP_NULL:
		case EXP_EXTERN:
		case EXP_EXTERN_LIST:
		case EXP_NUMBER:
		case EXP_STRING:
		case EXP_CHAR:
		case EXP_BOOL: break;
	
		case EXP_VAR:
		{
			if(exp->varx.decl) return;
			exp->varx.decl = reference_variable(script, exp->varx.name);
			if(!exp->varx.decl) 
			{
				if(reference_function(script, exp->varx.name)) return;
				if(get_type_tag_from_name(script, exp->varx.name)) return;
				error_defer_e(exp, "Attempted to reference undeclared entity '%s'\n", exp->varx.name);
			}
		} break;
		
		case EXP_UNARY:
		{
			resolve_symbols(script, exp->unaryx.rhs);
		} break;
		
		case EXP_BINARY:
		{
			resolve_symbols(script, exp->binx.lhs);
			resolve_symbols(script, exp->binx.rhs);
		} break;
		
		case EXP_PAREN:
		{
			resolve_symbols(script, exp->paren);
		} break;
		
		case EXP_BLOCK:
		{
			for(int i = 0; i < exp->block.length; ++i)
				resolve_symbols(script, vec_get_value(&exp->block, i, expr_t*));
		} break;
		
		case EXP_ARRAY_INDEX:
		{
			resolve_symbols(script, exp->array_index.array);
			resolve_symbols(script, exp->array_index.index);
		} break;
		
		case EXP_ARRAY_LITERAL:
		{
			for(int i = 0; i < exp->array_literal.values.length; ++i)
				resolve_symbols(script, vec_get_value(&exp->array_literal.values, i, expr_t*));
		} break;
		
		case EXP_IF:
		{
			resolve_symbols(script, exp->ifx.cond);
			resolve_symbols(script, exp->ifx.body);
			if(exp->ifx.alt) resolve_symbols(script, exp->ifx.alt);
		} break;
		
		case EXP_WHILE:
		{
			resolve_symbols(script, exp->whilex.cond);
			resolve_symbols(script, exp->whilex.body);
		} break;
		
		case EXP_FOR:
		{
			resolve_symbols(script, exp->forx.init);
			resolve_symbols(script, exp->forx.cond);
			resolve_symbols(script, exp->forx.step);
			resolve_symbols(script, exp->forx.body);
		} break;

		case EXP_RETURN:
		{
			if(exp->retx.value)
				resolve_symbols(script, exp->retx.value);
		} break;
		
		case EXP_CALL:
		{
			for(int i = 0; i < exp->callx.args.length; ++i)
				resolve_symbols(script, vec_get_value(&exp->callx.args, i, expr_t*));
			resolve_symbols(script, exp->callx.func);
		} break;
		
		case EXP_FUNC:
		{
			resolve_symbols(script, exp->funcx.body);
		} break;
		
		case EXP_WRITE:
		{
			resolve_symbols(script, exp->write);
		} break;
		
		case EXP_LEN:
		{
			resolve_symbols(script, exp->len);
		} break;

		default:
			assert(0);
			break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x38
popq %r15
leaq 0x5758(%rip), %r13      # 0xd258
pushq $0x40
popq %r12
movl 0x28(%rbx), %eax
cmpq $0x1a, %rax
ja 0x7ce3
movslq (%r13,%rax,4), %rcx
addq %r13, %rcx
movq %r15, %rax
jmpq *%rcx
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
movq %r12, %rax
jmp 0x7b91
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
pushq $0x50
popq %rax
jmp 0x7b91
movq 0x40(%rbx), %rbx
jmp 0x7bb6
leaq 0x40(%rbx), %r15
xorl %r12d, %r12d
cmpq %r12, 0x50(%rbx)
jbe 0x7b86
movq %r15, %rdi
movq %r12, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7ae1
incq %r12
jmp 0x7b65
pushq $0x38
popq %r15
movq %r15, %rax
pushq $0x40
popq %r12
movq (%rbx,%rax), %rbx
jmp 0x7b04
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7ae1
movq 0x48(%rbx), %rbx
testq %rbx, %rbx
jne 0x7b04
jmp 0x7c89
leaq 0x40(%rbx), %r15
xorl %r12d, %r12d
cmpq %r12, 0x50(%rbx)
jbe 0x7c89
movq %r15, %rdi
movq %r12, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7ae1
incq %r12
jmp 0x7bcb
leaq 0x40(%rbx), %r15
xorl %r12d, %r12d
cmpq %r12, 0x50(%rbx)
jbe 0x7c89
movq %r15, %rdi
movq %r12, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7ae1
incq %r12
jmp 0x7bf7
xorl %r15d, %r15d
movq 0x38(%rbx), %rdi
cmpq %r15, 0x70(%rdi)
jbe 0x7c89
addq $0x60, %rdi
movq %r15, %rsi
callq 0xc15c
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x7c46
movq %r14, %rdi
callq 0x7ae1
incq %r15
jmp 0x7c1f
cmpq $0x0, 0x40(%rbx)
jne 0x7c89
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x77b1
movq %rax, 0x40(%rbx)
testq %rax, %rax
jne 0x7c89
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x760e
testq %rax, %rax
jne 0x7c89
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7d02
testq %rax, %rax
je 0x7cc0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38(%rbx), %r15
xorl %r12d, %r12d
cmpq %r12, 0x48(%rbx)
jbe 0x7c89
movq %r15, %rdi
movq %r12, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7ae1
incq %r12
jmp 0x7c9f
movq 0x38(%rbx), %rdx
leaq 0x6a19(%rip), %rsi      # 0xe6e4
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7dd4
leaq 0x5eaa(%rip), %rdi      # 0xdb94
leaq 0x5ea5(%rip), %rsi      # 0xdb96
leaq 0x6a1b(%rip), %rcx      # 0xe713
movl $0xc54, %edx            # imm = 0xC54
callq 0x2100