diff --git a/src/aux/aux_compile_line.cpp b/src/aux/aux_compile_line.cpp index fa8dca1..af79e9d 100644 --- a/src/aux/aux_compile_line.cpp +++ b/src/aux/aux_compile_line.cpp @@ -792,7 +792,7 @@ void compile_line(vector &tokens, compiler_state &state) // Optimization for appending state.add_code(get_c_variable(state, tokens[5]) + " += " + get_c_string(state, tokens[3]) + ";", state.where); }else{ - state.add_code(get_c_variable(state, tokens[5]) + " = " + get_c_string(state, tokens[1]) + " + " + get_c_string(state, tokens[3]) + ";", state.where); + state.add_code("join(" + get_c_string(state, tokens[1]) + ", " + get_c_string(state, tokens[3]) + ", " + get_c_string(state, tokens[5]) + ");", state.where); } return; } @@ -824,7 +824,7 @@ void compile_line(vector &tokens, compiler_state &state) badcode("GET ASCII CHARACTER statement outside PROCEDURE section", state.where); // C++ Code - state.add_code(get_c_variable(state, tokens[5]) + " = (char)(" + + state.add_code(get_c_variable(state, tokens[5]) + " = getAsciiChar(" + get_c_expression(state, tokens[3]) + ");", state.where); return; diff --git a/src/ldpl_lib/ldpl_lib.cpp b/src/ldpl_lib/ldpl_lib.cpp index 379c6c8..d07fa1d 100644 --- a/src/ldpl_lib/ldpl_lib.cpp +++ b/src/ldpl_lib/ldpl_lib.cpp @@ -295,7 +295,7 @@ string graphemedText::operator[](size_t i) cout << "Out-of-bounds index access." << endl; exit(1); } - return stringRep.substr(graphemeIndexMap[i], graphemeIndexMap[i+1] - graphemeIndexMap[i]); + return stringRep.substr(graphemeIndexMap[i], graphemeIndexMap[i + 1] - graphemeIndexMap[i]); } // [] for setting /*string graphemedText::operator[](int i) @@ -568,6 +568,7 @@ ofstream file_writing_stream; string file_loading_line; ldpl_number VAR_ERRORCODE = 0; graphemedText VAR_ERRORTEXT = ""; +graphemedText joinvar = ""; // Generic temporary use text variable (used by join but can be used by any other statement as well) // Forward declarations graphemedText to_ldpl_string(ldpl_number x); @@ -758,6 +759,20 @@ ldpl_number get_char_num(graphemedText chr) return ord; } +graphemedText getAsciiChar(ldpl_number value) +{ + if (value < 0) + return "?"; + if (value > 127) + return "?"; + return (char)value; +} + +void join(const graphemedText &a, const graphemedText &b, graphemedText &c) +{ + c = a + b; +} + graphemedText charat(graphemedText &s, ldpl_number pos) { size_t _pos = floor(pos);