HoneyPony / jaylox

A compiler/transpiler targetting C, for the Lox language from Crafting Interpreters
0 stars 0 forks source link

Garbage collector: Somehow copying an instance to its own class field, or similar #4

Closed HoneyPony closed 1 week ago

HoneyPony commented 2 weeks ago
gc: trace 000001eb00505328 = instance (-1512 rel to high_ptr)
-- instance->class: 000001eb00504b40 -> 000001eb00505370
    gc: copy 000001eb005050e0 -> 000001eb00505910 (216 bytes)
    gc: copy table
-- instance->table: 000001eb005050e0 -> 000001eb00505910
^^^ return size = 24
gc: trace 000001eb00505340 = instance (-1704 rel to high_ptr)
    gc: copy 000001eb00505340 -> 000001eb005059e8 (24 bytes)
    gc: copy instance
-- instance->class: 000001eb00505340 -> 000001eb005059e8
-- instance->table: 0000000000000000 -> 0000000000000000
runtime error: unknown garbage collection type

This output shows that an instance's ->class is somehow set t the same pointer (ending in 340) and so when it copies that value over, it ends up causing a problem for itself.

Now, strictly speaking, if an object is pointing at itself when we visit it, we shouldn't copy it -- so more than one thing is going wrong here..?

HoneyPony commented 2 weeks ago

One possibility to look into: The generated class code doesn't look GC-safe at the moment.

HoneyPony commented 1 week ago

I'm considering this resolved for now, as the garbage collector appears to work.