// File: pranavmodx[P]modlang/test/parser_test.cpp
// Function: TestReturnStatement()
void TestReturnStatement()
{
	std::string input =
		"return 5;"
		"return 10;"
		"return 838383;";

	Lexer lexer;
	lexer.New(input);

	Parser parser;
	parser.New(lexer);

	Program *program = parser.ParseProgram();

	checkParserErrors(parser);

	if (program == nullptr)
		std::cout << "ParseProgram() returned null" << std::endl;

	if (program->statements.size() != 3)
		std::cout << "program->statements does not contain 3 statements, got " << program->statements.size() << std::endl;

	Statement *stmt;
	for (int i = 0; i < program->statements.size(); i++)
	{
		stmt = program->statements[i];

		if (((ReturnStatement *)stmt)->tokenLiteral() != "return")
			std::cout << "stmt->tokenLiteral() not 'return'"
					  << ", got " << stmt->tokenLiteral() << std::endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
leaq -0x21(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x5470
movq -0x238(%rbp), %rdx
leaq 0x1968d(%rip), %rsi     # 0x261a6
leaq -0x20(%rbp), %rdi
callq 0xdb60
jmp 0xcb24
leaq -0x21(%rbp), %rdi
callq 0x52c0
leaq -0x68(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0xde70
movq -0x240(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x12480
jmp 0xcb4f
leaq -0x1d8(%rbp), %rdi
callq 0x197b0
jmp 0xcb5d
leaq -0x1d8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x19c70
jmp 0xcb6f
leaq -0x1d8(%rbp), %rdi
callq 0x1c280
movq %rax, -0x248(%rbp)
jmp 0xcb84
movq -0x248(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xd720
jmp 0xcba0
cmpq $0x0, -0x1e0(%rbp)
jne 0xcc19
movq 0x2b41f(%rip), %rdi     # 0x37fd0
leaq 0x19541(%rip), %rsi     # 0x260f9
callq 0x5260
movq %rax, -0x250(%rbp)
jmp 0xcbc6
movq -0x250(%rbp), %rdi
movq 0x2b3d4(%rip), %rsi     # 0x37fa8
callq 0x52a0
jmp 0xcbdb
jmp 0xcc19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0x52c0
jmp 0xce52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xce40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xce34
movq -0x1e0(%rbp), %rdi
addq $0x8, %rdi
callq 0xde90
cmpq $0x3, %rax
je 0xcc8a
movq 0x2b39a(%rip), %rdi     # 0x37fd0
leaq 0x194d9(%rip), %rsi     # 0x26116
callq 0x5260
movq %rax, -0x258(%rbp)
jmp 0xcc4b
movq -0x1e0(%rbp), %rdi
addq $0x8, %rdi
callq 0xde90
movq -0x258(%rbp), %rdi
movq %rax, %rsi
callq 0x50a0
movq %rax, -0x260(%rbp)
jmp 0xcc73
movq -0x260(%rbp), %rdi
movq 0x2b327(%rip), %rsi     # 0x37fa8
callq 0x52a0
jmp 0xcc88
jmp 0xcc8a
movl $0x0, -0x1ec(%rbp)
movslq -0x1ec(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x1e0(%rbp), %rdi
addq $0x8, %rdi
callq 0xde90
movq %rax, %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
jae 0xce0d
movq -0x1e0(%rbp), %rdi
addq $0x8, %rdi
movslq -0x1ec(%rbp), %rsi
callq 0xdeb0
movq (%rax), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x210(%rbp), %rdi
callq *%rax
jmp 0xccfe
leaq 0x194c3(%rip), %rsi     # 0x261c8
leaq -0x210(%rbp), %rdi
callq 0xdf90
movb %al, -0x269(%rbp)
jmp 0xcd19
leaq -0x210(%rbp), %rdi
callq 0x54d8
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0xcd34
jmp 0xcdf7
movq 0x2b295(%rip), %rdi     # 0x37fd0
leaq 0x1948d(%rip), %rsi     # 0x261cf
callq 0x5260
movq %rax, -0x278(%rbp)
jmp 0xcd50
movq -0x278(%rbp), %rdi
leaq 0x194cc(%rip), %rsi     # 0x2622a
callq 0x5260
movq %rax, -0x280(%rbp)
jmp 0xcd6c
movq -0x1e8(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x230(%rbp), %rdi
callq *%rax
jmp 0xcd84
movq -0x280(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x5230
movq %rax, -0x288(%rbp)
jmp 0xcda0
movq -0x288(%rbp), %rdi
movq 0x2b1fa(%rip), %rsi     # 0x37fa8
callq 0x52a0
jmp 0xcdb5
leaq -0x230(%rbp), %rdi
callq 0x54d8
jmp 0xcdf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x54d8
jmp 0xce34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x54d8
jmp 0xce34
jmp 0xcdf9
movl -0x1ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ec(%rbp)
jmp 0xcc94
leaq -0x1d8(%rbp), %rdi
callq 0xdef0
leaq -0x68(%rbp), %rdi
callq 0xdf70
leaq -0x20(%rbp), %rdi
callq 0x54d8
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x1d8(%rbp), %rdi
callq 0xdef0
leaq -0x68(%rbp), %rdi
callq 0xdf70
leaq -0x20(%rbp), %rdi
callq 0x54d8
movq -0x30(%rbp), %rdi
callq 0x5460
nopl (%rax,%rax)