Skip to content

Commit

Permalink
test inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Apr 8, 2024
1 parent 3e1096a commit b56e0de
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
12 changes: 10 additions & 2 deletions pickle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,22 @@ object* pvm::get_property(object* obj, uint64_t hash, bool recurse) {
// Nil has no properties
if (!obj) return nil;
if (recurse) {
DBG("Inheritance requested get_property() {");
// Try to find it directly.
object* val = this->get_property(obj, hash, false);
if (val) return val;
if (val) {
DBG("Own property. }");
return val;
}
// Not found, traverse prototypes list.
for (object* p = car(obj); p; p = cdr(p)) {
val = this->get_property(car(p), hash, true);
if (val) return val;
if (val) {
DBG("Parent property. }");
return val;
}
}
DBG("Property not found in inheritance tree. }");
return nil;
}
// Check if it is an object-object (primitives have no own properties)
Expand Down
6 changes: 6 additions & 0 deletions pickle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ int main() {
vm.dump(hash0);
putchar('\n');
vm.dump(foo);
printf("\nCreate child object\n");
auto bar = vm.newobject(vm.cons(foo, nil));
vm.dump(bar);
printf("\nGet property 0 with inheritance and without\n");
ASSERT(vm.get_property(bar, 0, false) == nil);
ASSERT(vm.get_property(bar, 0, true) != nil);
SEPARATOR;
printf("all done -- cleaning up\n");
// implicit destruction of vm;
Expand Down
4 changes: 4 additions & 0 deletions test/out32.txt

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

4 changes: 4 additions & 0 deletions test/out64.txt

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

26 changes: 13 additions & 13 deletions test/valgrind32.txt

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

26 changes: 13 additions & 13 deletions test/valgrind64.txt

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

0 comments on commit b56e0de

Please sign in to comment.