O! It’s base and elementary sample problem.
If i write: (defvar x “test”) or simple “test”.
To debug i added to buildstring() next code:
void buildstring (char ch, object **tail) {
…
(*tail)->chars |= ch;
Serial.print(" ");
Serial.print((int32_t)ch, HEX);
Serial.print(" ");
Serial.println((int32_t)(*tail)->chars, HEX);
return;
…
car(cell) = NULL; cell->chars = ch<<8; *tail = cell;
Serial.print(" ");
Serial.print((int32_t)ch, HEX);
Serial.print(" ");
Serial.println((int32_t)(*tail)->chars, HEX);
}
In result:
1343> (defvar x "t 74 7400
e 65 7465
s 73 7300
t 74 7374
")
x
See that, char is fill a 2 byte word. It’s ok!
But if i write text in UTF-8 i got result, as:
"� FFFFFFD1 D100
FFFFFF82 FF82
� FFFFFFD0 D000
µ FFFFFFB5 FFB5
� FFFFFFD1 D100
… because char greater 0x7F filled FF from left at expand to a word!!!
So the instruction (*tail)->chars |= ch; is not work as good!
To fix this problem i change type of ch from char to chars_t in header:
void buildstring ( chars_t ch , object **tail) {
and than clear a left byte:
ch &= 0xFF;
It’s problem only AVR!
On ESP char type not fill 1 at left with expand:
3927> "⸮ D1 D1000000
⸮ 82 D1820000
⸮ D0 D182D000
⸮ B5 D182D0B5
⸮ D1 D1000000
⸮ 81 D1810000
However i don`t known how its work at another platforms. Therefore the my construction is universal:
void buildstring ( chars_t ch , object **tail) {
ch &= 0xFF;
…
}