From fbd27d7c459bab630af56ba0bf608f9d51109a07 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 29 Jul 2017 13:56:45 +0100 Subject: Fix map internal type generation --- src/exact_value.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 3bee3cdb2..6966dbf73 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -565,13 +565,23 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) } return exact_value_complex(real, imag); } break; + + case ExactValue_String: { + if (op != Token_Add) goto error; + + // NOTE(bill): How do you minimize this over allocation? + String sx = x.value_string; + String sy = y.value_string; + isize len = sx.len+sy.len; + u8 *data = gb_alloc_array(heap_allocator(), u8, len); + gb_memmove(data, sx.text, sx.len); + gb_memmove(data+sx.len, sy.text, sy.len); + return exact_value_string(make_string(data, len)); + } break; } -error: - ; // MSVC accepts this??? apparently you cannot declare variables immediately after labels... - ExactValue error_value = {}; - // gb_printf_err("Invalid binary operation: %s\n", token_kind_to_string(op)); - return error_value; +error:; // NOTE(bill): MSVC accepts this??? apparently you cannot declare variables immediately after labels... + return empty_exact_value; } gb_inline ExactValue exact_value_add(ExactValue x, ExactValue y) { return exact_binary_operator_value(Token_Add, x, y); } -- cgit v1.2.3