// File: WayfireWM[P]wf-utils/wayfire/lexer/symbol.cpp
// Function: wf::symbol_t::symbol_t(std::variant<int, char, bool, float, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&)
symbol_t::symbol_t(const variant_t &v) : type(type_t::LITERAL), value(v)
{
    // String literals can also be keywords, comments or identifiers. Check for this.
    if (is_string(value))
    {
        auto literal_value = get_string(value);

        if ((literal_value.front() == '\"') && (literal_value.back() == '\"'))
        {
            value = literal_value.substr(1, literal_value.size() - 2); // Strip quotes here.
        }
        else if (contains(SIGNALS, literal_value))
        {
            type = type_t::SIGNAL;
        }
        else if (contains(KEYWORDS, literal_value))
        {
            type = type_t::KEYWORD;
        }
        else if (contains(STRUCTURES, literal_value))
        {
            type = type_t::STRUCTURAL;
        }
        else if (contains(OPERATORS, literal_value))
        {
            type = type_t::OPERATOR;
        }
        else
        {
            bool first = true;
            for (const auto &c : literal_value)
            {
                auto digit = std::isdigit(c);
                auto letter = std::isalpha(c);
                auto underscore = (c == '_');

                if (first)
                {
                    first = false;
                    if (digit)
                    {
                        std::string error = "Symbol parser error. Identifier should start with _ or letter. text:";
                        error.append(literal_value);
                        throw std::runtime_error(error);
                    }
                }

                if (!(digit | letter | underscore))
                {
                    std::string error = "Symbol parser error. Identifier contains invalid character. text:";
                    error.append(literal_value);
                    throw std::runtime_error(error);
                }
            }
            type = type_t::IDENTIFIER;
        }
    }
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movl $0x2, (%rdi)
addq $0x8, %rdi
movq %rdi, 0x38(%rsp)
movq 0x118(%rsp), %rsi
callq 0x8350
movq 0x38(%rsp), %rdi
callq 0x1bd70
movb %al, 0x46(%rsp)
jmp 0x12260
movb 0x46(%rsp), %al
testb $0x1, %al
jne 0x1226d
jmp 0x1272a
movq 0x30(%rsp), %rsi
addq $0x8, %rsi
leaq 0xe8(%rsp), %rdi
callq 0x1bea0
jmp 0x12285
leaq 0xe8(%rsp), %rdi
callq 0x6090
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x12343
leaq 0xe8(%rsp), %rdi
callq 0x6230
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x12343
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x6200
movq 0x28(%rsp), %rsi
movq %rax, %rcx
addq $-0x2, %rcx
leaq 0xc8(%rsp), %rdi
movl $0x1, %edx
callq 0x6320
jmp 0x122e9
movq 0x30(%rsp), %rdi
addq $0x8, %rdi
leaq 0xc8(%rsp), %rsi
callq 0x12750
leaq 0xc8(%rsp), %rdi
callq 0x61d0
jmp 0x1270c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x12732
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x1271b
leaq 0x1d09e(%rip), %rdi     # 0x2f3e8
leaq 0xe8(%rsp), %rsi
callq 0xcf60
movb %al, 0x27(%rsp)
jmp 0x1235d
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x12367
jmp 0x12377
movq 0x30(%rsp), %rax
movl $0x6, (%rax)
jmp 0x1270a
leaq 0x1d09a(%rip), %rdi     # 0x2f418
leaq 0xe8(%rsp), %rsi
callq 0xcf60
movb %al, 0x26(%rsp)
jmp 0x12391
movb 0x26(%rsp), %al
testb $0x1, %al
jne 0x1239b
jmp 0x123ab
movq 0x30(%rsp), %rax
movl $0x4, (%rax)
jmp 0x12708
leaq 0x1d0c6(%rip), %rdi     # 0x2f478
leaq 0xe8(%rsp), %rsi
callq 0xcf60
movb %al, 0x25(%rsp)
jmp 0x123c5
movb 0x25(%rsp), %al
testb $0x1, %al
jne 0x123cf
jmp 0x123df
movq 0x30(%rsp), %rax
movl $0x5, (%rax)
jmp 0x12706
leaq 0x1d062(%rip), %rdi     # 0x2f448
leaq 0xe8(%rsp), %rsi
callq 0xcf60
movb %al, 0x24(%rsp)
jmp 0x123f9
movb 0x24(%rsp), %al
testb $0x1, %al
jne 0x12403
jmp 0x12413
movq 0x30(%rsp), %rax
movl $0x3, (%rax)
jmp 0x12704
movb $0x1, 0xc7(%rsp)
leaq 0xe8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x6290
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x61a0
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x127d0
testb $0x1, %al
jne 0x12473
jmp 0x126f9
leaq 0xb0(%rsp), %rdi
callq 0x12810
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movsbl (%rax), %edi
callq 0x62c0
movl %eax, 0x9c(%rsp)
movq 0xa0(%rsp), %rax
movsbl (%rax), %edi
callq 0x6490
movl %eax, 0x98(%rsp)
movq 0xa0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x5f, %eax
sete %al
andb $0x1, %al
movb %al, 0x97(%rsp)
testb $0x1, 0xc7(%rsp)
je 0x125df
movb $0x0, 0xc7(%rsp)
cmpl $0x0, 0x9c(%rsp)
je 0x125dd
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x6500
movq 0x18(%rsp), %rdx
leaq 0xd031(%rip), %rsi      # 0x1f540
leaq 0x70(%rsp), %rdi
callq 0x8280
jmp 0x1251b
leaq 0x6f(%rsp), %rdi
callq 0x6360
leaq 0x70(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x6560
jmp 0x12539
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x64a0
jmp 0x1255a
movq 0x10(%rsp), %rdi
movq 0x1ca8a(%rip), %rsi     # 0x2eff0
movq 0x1ca3b(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x12749
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x6f(%rsp), %rdi
callq 0x6360
jmp 0x1271b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x125ce
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x6240
leaq 0x70(%rsp), %rdi
callq 0x61d0
jmp 0x1271b
jmp 0x125df
movl 0x9c(%rsp), %eax
orl 0x98(%rsp), %eax
movb 0x97(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
jne 0x126e5
leaq 0x47(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6500
movq 0x8(%rsp), %rdx
leaq 0xcf65(%rip), %rsi      # 0x1f585
leaq 0x48(%rsp), %rdi
callq 0x8280
jmp 0x1262c
leaq 0x47(%rsp), %rdi
callq 0x6360
leaq 0x48(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x6560
jmp 0x1264a
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, (%rsp)
leaq 0x48(%rsp), %rsi
callq 0x64a0
jmp 0x1266a
movq (%rsp), %rdi
movq 0x1c97b(%rip), %rsi     # 0x2eff0
movq 0x1c92c(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x12749
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x47(%rsp), %rdi
callq 0x6360
jmp 0x1271b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x126d9
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x6240
leaq 0x48(%rsp), %rdi
callq 0x61d0
jmp 0x1271b
jmp 0x126e7
leaq 0xb0(%rsp), %rdi
callq 0x12820
jmp 0x12455
movq 0x30(%rsp), %rax
movl $0x1, (%rax)
jmp 0x12706
jmp 0x12708
jmp 0x1270a
jmp 0x1270c
leaq 0xe8(%rsp), %rdi
callq 0x61d0
jmp 0x1272a
leaq 0xe8(%rsp), %rdi
callq 0x61d0
jmp 0x12732
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x38(%rsp), %rdi
callq 0x99d0
movq 0x110(%rsp), %rdi
callq 0x64f0
nopl (%rax)