Skip to content

Commit 5c2f875

Browse files
build & test on raspberry pi
* no "m32" option for gcc (why?) * valgrind gets really confused by C++ standard library here (it thinks libc has thousands of "uninitialized value" problems)
1 parent d6ce108 commit 5c2f875

File tree

5 files changed

+1241
-35
lines changed

5 files changed

+1241
-35
lines changed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44

55
test: buildtest64 valgrind64 buildtest32 valgrind32 clean checkleaks
66

7+
VALGRINDOPTS = --track-origins=yes --leak-check=full --show-reachable=yes --main-stacksize=1000
8+
9+
ifeq (,$(findstring raspberrypi,$(shell uname -a)))
10+
VALGRINDOPTS += --show-leak-kinds=all
11+
endif
12+
713
buildtest64:
814
g++ --std=c++11 pickle_test.cpp -g -o pickletest64
915

1016
valgrind64: buildtest64
11-
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ./pickletest64 > test/out64.txt 2> test/valgrind64.txt
17+
valgrind $(VALGRINDOPTS) ./pickletest64 > test/out64.txt 2> test/valgrind64.txt
1218

1319
buildtest32:
1420
g++ --std=c++11 -m32 pickle_test.cpp -g -o pickletest32
1521

1622
valgrind32: buildtest32
17-
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ./pickletest32 > test/out32.txt 2> test/valgrind32.txt
23+
valgrind $(VALGRINDOPTS) ./pickletest32 > test/out32.txt 2> test/valgrind32.txt
1824

1925
clean:
2026
rm -f pickletest64

pickle.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
183183
char* b = NULL;
184184
char* b2 = NULL;
185185
object* result = nil;
186-
if (isalpha(c)) {
186+
if (isalpha(c) || c == '_') {
187187
DBG("symbol");
188188
size_t p = pos;
189-
while (!eofp && test(isalpha)) next;
189+
while (!eofp && (test(isalpha) || test(isdigit) || look == '_')) next;
190190
bufcat(&b, at(p), pos - p);
191191
result = vm->sym(b);
192192
}
@@ -206,7 +206,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
206206
}
207207
else if (isspace(c) && c != '\n') {
208208
DBG("small space");
209-
result = vm->sym("SPACE");
209+
result = vm->sym("parse SPACE");
210210
while (test(isspace) && c != '\n') next;
211211
}
212212
else if (c == '#') {
@@ -221,7 +221,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
221221
if (look != '#') {
222222
DBG("line comment");
223223
// it's a line comment
224-
do bufadd(&b, look), next; while (look != '\n');
224+
do bufadd(&b, look), next; while (look != '\n' && !eofp);
225225
result = vm->string(b);
226226
} else {
227227
DBG("block comment");
@@ -274,7 +274,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
274274
}
275275
if (!b2 || !strlen(b2)) {
276276
// no indent
277-
result = vm->sym("NEWLINE");
277+
result = vm->sym("parse NEWLINE");
278278
goto done;
279279
}
280280
// validate indent
@@ -400,10 +400,16 @@ object* parse(pvm* vm, object* cookie, object* inst_type) {
400400
pstate s = { .data = str, .i = 0, .len = strlen(str) };
401401
char special = 0;
402402
object* errors = nil;
403-
object* result = do_parse(vm, &s, &errors, &special);
404-
if (special) {
405-
vm->push(vm->string("unknown syntax error"), errors);
406-
}
403+
object* result = nil;
404+
object** tail = &result;
405+
do {
406+
object* item = do_parse(vm, &s, &errors, &special);
407+
if (special) {
408+
vm->push(vm->string("unopened paren"), errors);
409+
}
410+
*tail = vm->cons(item, nil);
411+
tail = &cdr(*tail);
412+
} while (s.i < s.len);
407413
vm->push_data(errors ? errors : result);
408414
return errors ? vm->sym("error") : nil;
409415
}

pickle_test.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ object* test_test(pvm* vm, object* cookie, object* inst_type) {
1919
return vm->sym(d ? "debug" : "error");
2020
}
2121

22+
const char* test = R"=(
23+
24+
[(+ 1 2)
25+
## #### block comment '
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
foo123]
38+
39+
)=";
40+
2241
int main() {
2342
pvm vm;
2443
vm.defop("parse", pickle::parse);
@@ -36,7 +55,7 @@ int main() {
3655
vm.push_data(vm.integer(42));
3756
vm.push_data(st);
3857
vm.push_data(vm.integer(42));
39-
vm.push_data(vm.string("[(+ 1 2)\n## #### block comment '\n\n ###### \n\n\n foo]"));
58+
vm.push_data(vm.string(test));
4059
printf("\nqueue with data: ");
4160
vm.dump(vm.queue);
4261
putchar('\n');

test/out64.txt

+16-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)