Skip to content

Commit 74b2999

Browse files
committed
Fix ascii values for negative and overflowing numbers
1 parent 939288e commit 74b2999

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/aux/aux_compile_line.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ void compile_line(vector<string> &tokens, compiler_state &state)
792792
// Optimization for appending
793793
state.add_code(get_c_variable(state, tokens[5]) + " += " + get_c_string(state, tokens[3]) + ";", state.where);
794794
}else{
795-
state.add_code(get_c_variable(state, tokens[5]) + " = " + get_c_string(state, tokens[1]) + " + " + get_c_string(state, tokens[3]) + ";", state.where);
795+
state.add_code("join(" + get_c_string(state, tokens[1]) + ", " + get_c_string(state, tokens[3]) + ", " + get_c_string(state, tokens[5]) + ");", state.where);
796796
}
797797
return;
798798
}
@@ -824,7 +824,7 @@ void compile_line(vector<string> &tokens, compiler_state &state)
824824
badcode("GET ASCII CHARACTER statement outside PROCEDURE section",
825825
state.where);
826826
// C++ Code
827-
state.add_code(get_c_variable(state, tokens[5]) + " = (char)(" +
827+
state.add_code(get_c_variable(state, tokens[5]) + " = getAsciiChar(" +
828828
get_c_expression(state, tokens[3]) + ");",
829829
state.where);
830830
return;

src/ldpl_lib/ldpl_lib.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ string graphemedText::operator[](size_t i)
295295
cout << "Out-of-bounds index access." << endl;
296296
exit(1);
297297
}
298-
return stringRep.substr(graphemeIndexMap[i], graphemeIndexMap[i+1] - graphemeIndexMap[i]);
298+
return stringRep.substr(graphemeIndexMap[i], graphemeIndexMap[i + 1] - graphemeIndexMap[i]);
299299
}
300300
// [] for setting
301301
/*string graphemedText::operator[](int i)
@@ -568,6 +568,7 @@ ofstream file_writing_stream;
568568
string file_loading_line;
569569
ldpl_number VAR_ERRORCODE = 0;
570570
graphemedText VAR_ERRORTEXT = "";
571+
graphemedText joinvar = ""; // Generic temporary use text variable (used by join but can be used by any other statement as well)
571572

572573
// Forward declarations
573574
graphemedText to_ldpl_string(ldpl_number x);
@@ -758,6 +759,20 @@ ldpl_number get_char_num(graphemedText chr)
758759
return ord;
759760
}
760761

762+
graphemedText getAsciiChar(ldpl_number value)
763+
{
764+
if (value < 0)
765+
return "?";
766+
if (value > 127)
767+
return "?";
768+
return (char)value;
769+
}
770+
771+
void join(const graphemedText &a, const graphemedText &b, graphemedText &c)
772+
{
773+
c = a + b;
774+
}
775+
761776
graphemedText charat(graphemedText &s, ldpl_number pos)
762777
{
763778
size_t _pos = floor(pos);

0 commit comments

Comments
 (0)