// File: AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ArgumentList(std::vector<scopeValue, std::allocator<scopeValue>>&, scopeValue, int&)
bool Parser::ArgumentList(vector<scopeValue> &list, scopeValue procValue, int &offset){
	//create vector<scopeValue> where all argument list information will be stored and later returned by the function
	list.clear();

	/* argEntry variable will contain argument information about expression type and size. 
	 * All arguments will have an empty arguments vector and have their paramType = TYPE_PARAM_NULL
	 * The procedure call, when checking these arguments, will not compare the paramType value against the declared values */
	scopeValue argEntry;
	argEntry.arguments.clear();
	argEntry.paramType = TYPE_PARAM_NULL;

	//For each comma-separated expression, store the type and size values, in the order encountered, in the 'list' vector
	vector<scopeValue>::iterator it = procValue.arguments.begin();
	if( it != procValue.arguments.end() ){
		if( it->paramType == TYPE_PARAM_OUT) outArg = true;
	}
	
	if( Expression(argEntry.type, argEntry.size) ){
		// GEN: add arguments from register to correct frame
		
		offset = 2;
		generator->pushArgument(offset, it->paramType);
		++it;
		
		list.push_back(argEntry);
		while( CheckToken(T_COMMA) ){
			if( it != procValue.arguments.end() ){
				if( it->paramType == TYPE_PARAM_OUT ){
					outArg = true;
				}
				else outArg = false;
			}
			if( Expression(argEntry.type, argEntry.size) ){
				list.push_back(argEntry);
				// Add arguments from register to correct frame
				generator->pushArgument(offset, it->paramType);
				++it;
			}
			else ReportError("expected another argument after ',' in argument list of procedure call");
		}
	}
	outArg = false;
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdx, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x126e0
leaq -0x68(%rbp), %rdi
callq 0x126b0
leaq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x126e0
movq -0xc0(%rbp), %rdi
movl $0x122, -0x28(%rbp)     # imm = 0x122
addq $0x8, %rdi
callq 0x12850
movq -0xc0(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x8, %rdi
callq 0x128c0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x12880
testb $0x1, %al
jne 0xc80e
jmp 0xc82d
leaq -0x70(%rbp), %rdi
callq 0x128f0
cmpl $0x120, 0x40(%rax)      # imm = 0x120
jne 0xc82b
movq -0xc8(%rbp), %rax
movb $0x1, 0x7c(%rax)
jmp 0xc82d
movq -0xc8(%rbp), %rdi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0xcab0
movb %al, -0xc9(%rbp)
jmp 0xc849
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0xc858
jmp 0xca77
movq -0xc8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl $0x2, (%rcx)
movq 0x98(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x128f0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movl 0x40(%rax), %edx
callq 0x1e9e0
jmp 0xc8a3
leaq -0x70(%rbp), %rdi
callq 0x12910
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x12700
jmp 0xc8bb
jmp 0xc8bd
movq -0xc8(%rbp), %rdi
movl $0x134, %esi            # imm = 0x134
callq 0x9300
movb %al, -0xe1(%rbp)
jmp 0xc8d6
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0xc8e5
jmp 0xca75
movq -0xc0(%rbp), %rdi
addq $0x8, %rdi
callq 0x128c0
movq %rax, -0x90(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x12880
testb $0x1, %al
jne 0xc912
jmp 0xc952
leaq -0x70(%rbp), %rdi
callq 0x128f0
cmpl $0x120, 0x40(%rax)      # imm = 0x120
jne 0xc945
movq -0xc8(%rbp), %rax
movb $0x1, 0x7c(%rax)
jmp 0xc950
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xca98
movq -0xc8(%rbp), %rax
movb $0x0, 0x7c(%rax)
jmp 0xc952
movq -0xc8(%rbp), %rdi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0xcab0
movb %al, -0xe2(%rbp)
jmp 0xc96e
movb -0xe2(%rbp), %al
testb $0x1, %al
jne 0xc97a
jmp 0xc9d8
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x12700
jmp 0xc989
movq -0xc8(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x128f0
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movl 0x40(%rax), %edx
callq 0x1e9e0
jmp 0xc9ca
leaq -0x70(%rbp), %rdi
callq 0x12910
jmp 0xca70
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x3430
movq -0x100(%rbp), %rdx
leaq 0x192ef(%rip), %rsi     # 0x25ce8
leaq -0xb0(%rbp), %rdi
callq 0x62d0
jmp 0xca07
movq -0xc8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x9060
jmp 0xca1c
leaq -0xb0(%rbp), %rdi
callq 0x31a0
leaq -0xb1(%rbp), %rdi
callq 0x32e0
jmp 0xca70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xca62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x31a0
leaq -0xb1(%rbp), %rdi
callq 0x32e0
jmp 0xca98
jmp 0xc8bd
jmp 0xca77
movq -0xc8(%rbp), %rax
movb $0x0, 0x7c(%rax)
leaq -0x68(%rbp), %rdi
callq 0x12800
movb $0x1, %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x12800
movq -0x80(%rbp), %rdi
callq 0x3420
nopw (%rax,%rax)