

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Handling Cycles
incomplete
2: Pros and Cons
incomplete
3: Stack Frames
incomplete
4: Tracking Objects
incomplete
5: Free
incomplete
6: Frame References
incomplete
7: Mark and Sweep
incomplete
8: Mark
incomplete
9: Trace
incomplete
10: Sweep
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Think back to the warnings I gave you about working with void* data types. It's easy to push the wrong kinds of data onto our stack_t because, like Starbucks Wi-Fi, it will let anything in.
So, to prevent us from shooting ourselves in the foot, we will create some functions that are more type safe and make it much more difficult to do the wrong thing when interacting with our vm_t. Wrong things like:
// The C compiler won't stop us :'(
stack_push(vm->frames, (void *)7);
stack_push(vm->frames, (void *)"uh oh");
But we want to make it easier on ourselves to only push frame_t * types onto vm->frames, so we'll write some wrapper functions to help us out.
Take a look at the frame_t type in vm.h. It's a simple struct that holds a stack_t of snek_object_t * pointers that represent the object references in the frame.