Skip to content

Commit

Permalink
build & test on raspberry pi
Browse files Browse the repository at this point in the history
* no "m32" option for gcc (why?)
* valgrind gets really confused by C++ standard library here (it thinks  libc has thousands of "uninitialized value" problems)
  • Loading branch information
dragoncoder047 committed Mar 28, 2024
1 parent d6ce108 commit 5c2f875
Show file tree
Hide file tree
Showing 5 changed files with 1,241 additions and 35 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

test: buildtest64 valgrind64 buildtest32 valgrind32 clean checkleaks

VALGRINDOPTS = --track-origins=yes --leak-check=full --show-reachable=yes --main-stacksize=1000

ifeq (,$(findstring raspberrypi,$(shell uname -a)))
VALGRINDOPTS += --show-leak-kinds=all
endif

buildtest64:
g++ --std=c++11 pickle_test.cpp -g -o pickletest64

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

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

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

clean:
rm -f pickletest64
Expand Down
24 changes: 15 additions & 9 deletions pickle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
char* b = NULL;
char* b2 = NULL;
object* result = nil;
if (isalpha(c)) {
if (isalpha(c) || c == '_') {
DBG("symbol");
size_t p = pos;
while (!eofp && test(isalpha)) next;
while (!eofp && (test(isalpha) || test(isdigit) || look == '_')) next;
bufcat(&b, at(p), pos - p);
result = vm->sym(b);
}
Expand All @@ -206,7 +206,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
}
else if (isspace(c) && c != '\n') {
DBG("small space");
result = vm->sym("SPACE");
result = vm->sym("parse SPACE");
while (test(isspace) && c != '\n') next;
}
else if (c == '#') {
Expand All @@ -221,7 +221,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
if (look != '#') {
DBG("line comment");
// it's a line comment
do bufadd(&b, look), next; while (look != '\n');
do bufadd(&b, look), next; while (look != '\n' && !eofp);
result = vm->string(b);
} else {
DBG("block comment");
Expand Down Expand Up @@ -274,7 +274,7 @@ static object* do_parse(pvm* vm, pstate* s, object** errors, char* special) {
}
if (!b2 || !strlen(b2)) {
// no indent
result = vm->sym("NEWLINE");
result = vm->sym("parse NEWLINE");
goto done;
}
// validate indent
Expand Down Expand Up @@ -400,10 +400,16 @@ object* parse(pvm* vm, object* cookie, object* inst_type) {
pstate s = { .data = str, .i = 0, .len = strlen(str) };
char special = 0;
object* errors = nil;
object* result = do_parse(vm, &s, &errors, &special);
if (special) {
vm->push(vm->string("unknown syntax error"), errors);
}
object* result = nil;
object** tail = &result;
do {
object* item = do_parse(vm, &s, &errors, &special);
if (special) {
vm->push(vm->string("unopened paren"), errors);
}
*tail = vm->cons(item, nil);
tail = &cdr(*tail);
} while (s.i < s.len);
vm->push_data(errors ? errors : result);
return errors ? vm->sym("error") : nil;
}
Expand Down
21 changes: 20 additions & 1 deletion pickle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ object* test_test(pvm* vm, object* cookie, object* inst_type) {
return vm->sym(d ? "debug" : "error");
}

const char* test = R"=(
[(+ 1 2)
## #### block comment '
foo123]
)=";

int main() {
pvm vm;
vm.defop("parse", pickle::parse);
Expand All @@ -36,7 +55,7 @@ int main() {
vm.push_data(vm.integer(42));
vm.push_data(st);
vm.push_data(vm.integer(42));
vm.push_data(vm.string("[(+ 1 2)\n## #### block comment '\n\n ###### \n\n\n foo]"));
vm.push_data(vm.string(test));
printf("\nqueue with data: ");
vm.dump(vm.queue);
putchar('\n');
Expand Down
25 changes: 16 additions & 9 deletions test/out64.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c2f875

Please sign in to comment.