// File: kram[P]kram/./src/parser/parser.cpp
// Function: Parser::read_until(std::vector<lexer::Token, std::allocator<lexer::Token>>, std::vector<Instruction*, std::allocator<Instruction*>>, ON)
std::vector<Instruction*> Parser::read_until(std::vector<lexer::Token> until, std::vector<Instruction*> res, ON on) {
	// Everything can end at a EOF
	until.push_back(lexer::Token::T_EOF());

	bool first = true;

	while (true) {

		// First, test the previous token
		lexer::Token* prev = this->get_token();

		if (!first) {
			for (lexer::Token unt : until) {
				if ((unt.type == lexer::Type::T_EOL || unt.type == lexer::Type::T_EOF || (unt.type == lexer::Type::OPERATOR && unt.sub == lexer::Type::OPERATOR_SEMICOLON)) && prev->type == unt.type) {
					return res;
				}
			}
		}

		// Test again
		this->advance();
		lexer::Token* next = this->get_token();

		for (lexer::Token unt : until) {
			if (unt.type == next->type && unt.sub == next->sub) {
				return res;
			}
		}

		Instruction* sym = this->symbol(next, on);

		if (sym->instruction != Ins::IGNORE) {
			res.push_back(sym);	
		}

		first = false;
	}

	return res;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rcx, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movq %rdx, 0x120(%rsp)
movq %rcx, 0x118(%rsp)
movl %r8d, 0x114(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xd4f0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x26b50
jmp 0x20e76
leaq 0xe8(%rsp), %rdi
callq 0xdeb0
movb $0x1, 0xdb(%rsp)
movq 0x20(%rsp), %rdi
callq 0x21200
movq %rax, 0xd0(%rsp)
testb $0x1, 0xdb(%rsp)
jne 0x20fda
movq 0x28(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x26b80
movq %rax, 0xc0(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x26bb0
movq %rax, 0xb8(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x26be0
testb $0x1, %al
jne 0x20f00
jmp 0x20fd8
leaq 0xc0(%rsp), %rdi
callq 0x26c20
movq %rax, %rsi
leaq 0x90(%rsp), %rdi
callq 0x26c30
cmpl $0x1, 0x90(%rsp)
je 0x20f45
cmpl $0x0, 0x90(%rsp)
je 0x20f45
cmpl $0x11, 0x90(%rsp)
jne 0x20f9a
cmpl $0x15, 0x94(%rsp)
jne 0x20f9a
movq 0xd0(%rsp), %rax
movl (%rax), %eax
cmpl 0x90(%rsp), %eax
jne 0x20f9a
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x26c70
movl $0x1, 0x8c(%rsp)
jmp 0x20fa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xdeb0
jmp 0x21113
movl $0x0, 0x8c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xdeb0
movl 0x8c(%rsp), %eax
testl %eax, %eax
je 0x20fc4
jmp 0x20fbf
jmp 0x21106
jmp 0x20fc6
leaq 0xc0(%rsp), %rdi
callq 0x26ca0
jmp 0x20ee2
jmp 0x20fda
movq 0x20(%rsp), %rdi
callq 0x21220
movq 0x20(%rsp), %rdi
callq 0x21200
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x80(%rsp)
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
callq 0x26b80
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rdi
callq 0x26bb0
movq %rax, 0x68(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x26be0
testb $0x1, %al
jne 0x21039
jmp 0x210c2
leaq 0x70(%rsp), %rdi
callq 0x26c20
movq %rax, %rsi
leaq 0x40(%rsp), %rdi
callq 0x26c30
movl 0x40(%rsp), %eax
movq 0x80(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x2108d
movl 0x44(%rsp), %eax
movq 0x80(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x2108d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x26c70
movl $0x1, 0x8c(%rsp)
jmp 0x21098
movl $0x0, 0x8c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xdeb0
movl 0x8c(%rsp), %eax
testl %eax, %eax
je 0x210b1
jmp 0x210af
jmp 0x21106
jmp 0x210b3
leaq 0x70(%rsp), %rdi
callq 0x26ca0
jmp 0x21021
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl 0x114(%rsp), %edx
callq 0x21250
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x6, (%rax)
je 0x210f9
movq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x26cc0
movb $0x0, 0xdb(%rsp)
jmp 0x20e8b
movq 0x18(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xe0(%rsp), %rdi
callq 0x3490