// File: iamlouk[P]asbi/src/parser.cc
// Function: asbi::Parser::parse_factor()
ast::Node* Parser::parse_factor() {
	auto node = parse_final();
	auto t = tokenizer.peek().type;
	while (t == tok::LeftBracket || t == tok::Dot || t == tok::Colon || t == tok::DoubleColon) {
		tokenizer.next();
		if (t == tok::LeftBracket) {
			std::vector<ast::Node*> args;
			parse_arglist(args);
			node = new ast::Call(node, args);
		} else if (t == tok::Colon) {
			auto token = tokenizer.next();
			if (token.type != tok::Identifier)
				throw utils::parser_error("expected identifier/symbol after ':'", token);

			node = new ast::Access(node, new ast::Symbol(ctx->new_stringconstant(*token.str)));
			delete token.str;
		} else if (t == tok::DoubleColon) {
			/*auto token = tokenizer.next();
			if (token.type != tok::Identifier)
				throw utils::parser_error("expected identifier/symbol after '::'", token);

			auto acs = new ast::Access(node, new ast::Symbol(token.str));
			expect(tok::LeftBracket);
			std::vector<ast::Node*> args;
			parse_arglist(args);
			node = new ast::OOCall(acs, args);*/
			throw std::runtime_error("unimplemented");
		} else {
			node = new ast::Access(node, parse_final());
		}
		t = tokenizer.peek().type;
	}
	return node;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x10120
movq 0x78(%rsp), %rdi
movq %rax, 0x128(%rsp)
callq 0x92b0
movq %rax, 0x110(%rsp)
movq %rdx, 0x118(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x124(%rsp)
movb $0x1, %al
cmpl $0x17, 0x124(%rsp)
movb %al, 0x77(%rsp)
je 0xfce0
movb $0x1, %al
cmpl $0x20, 0x124(%rsp)
movb %al, 0x77(%rsp)
je 0xfce0
movb $0x1, %al
cmpl $0x1f, 0x124(%rsp)
movb %al, 0x77(%rsp)
je 0xfce0
cmpl $0x21, 0x124(%rsp)
sete %al
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0xfced
jmp 0x100fa
movq 0x78(%rsp), %rdi
callq 0x9340
movq %rax, 0x100(%rsp)
movq %rdx, 0x108(%rsp)
cmpl $0x17, 0x124(%rsp)
jne 0xfe3e
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x11ce0
movq 0x78(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x11330
jmp 0xfd38
movl $0x28, %edi
callq 0x6460
movq %rax, 0x60(%rsp)
jmp 0xfd49
movb $0x1, 0xbf(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x11d60
jmp 0xfd75
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x123a0
jmp 0xfd8e
movq 0x60(%rsp), %rax
movb $0x0, 0xbf(%rsp)
movq %rax, 0x128(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x11ed0
leaq 0xe8(%rsp), %rdi
callq 0x11ed0
jmp 0x100cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0xfe2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0xfe0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x11ed0
testb $0x1, 0xbf(%rsp)
jne 0xfe1b
jmp 0xfe2a
movq 0x60(%rsp), %rdi
movl $0x28, %esi
callq 0x6470
jmp 0xfe2c
leaq 0xe8(%rsp), %rdi
callq 0x11ed0
jmp 0x1010a
cmpl $0x1f, 0x124(%rsp)
jne 0xffea
movq 0x78(%rsp), %rdi
callq 0x9340
movq %rax, 0xa8(%rsp)
movq %rdx, 0xb0(%rsp)
cmpl $0x0, 0xa8(%rsp)
je 0xfeee
movl $0x48, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movups 0xa8(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
leaq 0x28a10(%rip), %rsi     # 0x388bc
callq 0x17350
jmp 0xfeb3
movq 0x50(%rsp), %rdi
leaq 0x3b669(%rip), %rsi     # 0x4b528
leaq 0x1dda(%rip), %rdx      # 0x11ca0
callq 0x6780
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
callq 0x6320
jmp 0x1010a
movl $0x18, %edi
callq 0x6460
movq %rax, 0x38(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x10, %edi
callq 0x6460
movq %rax, 0x48(%rsp)
jmp 0xff1b
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0xb0(%rsp), %rsi
callq 0x260c0
movq %rax, 0x30(%rsp)
jmp 0xff38
movq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x12420
jmp 0xff49
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x12460
jmp 0xff5f
movq 0x38(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0xff98
movq 0x28(%rsp), %rdi
callq 0x6290
movq 0x28(%rsp), %rdi
movl $0x20, %esi
callq 0x6470
jmp 0x100cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0xffd6
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
movl $0x10, %esi
callq 0x6470
movq 0x38(%rsp), %rdi
movl $0x18, %esi
callq 0x6470
jmp 0x1010a
cmpl $0x21, 0x124(%rsp)
jne 0x10052
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
leaq 0x2891d(%rip), %rsi     # 0x3892d
callq 0x6160
jmp 0x10017
movq 0x20(%rsp), %rdi
movq 0x3bfcd(%rip), %rsi     # 0x4bff0
movq 0x3bf76(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
callq 0x6320
jmp 0x1010a
movl $0x18, %edi
callq 0x6460
movq 0x78(%rsp), %rdi
movq %rax, 0x8(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x10120
movq %rax, 0x18(%rsp)
jmp 0x1007f
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x12460
jmp 0x10095
movq 0x8(%rsp), %rax
movq %rax, 0x128(%rsp)
jmp 0x100c9
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
movl $0x18, %esi
callq 0x6470
jmp 0x1010a
jmp 0x100cb
jmp 0x100cd
movq 0x78(%rsp), %rdi
callq 0x92b0
movq %rax, 0x80(%rsp)
movq %rdx, 0x88(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x124(%rsp)
jmp 0xfca1
movq 0x128(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xe0(%rsp), %rdi
callq 0x67a0
nopw (%rax,%rax)