Browse Source

Add the last exercises

master
Riyyi 5 days ago
parent
commit
780996458b
  1. 442
      README.org
  2. 0
      src/04-1-enums/color.h
  3. 0
      src/04-1-enums/main.c
  4. 0
      src/04-2-non-default-values/color.h
  5. 0
      src/04-2-non-default-values/main.c
  6. 0
      src/04-3-switch-case/http.c
  7. 0
      src/04-3-switch-case/http.h
  8. 0
      src/04-3-switch-case/main.c
  9. 0
      src/04-4-sizeof-enum/main.c
  10. 0
      src/05-1-union/exercise.c
  11. 0
      src/05-1-union/exercise.h
  12. 0
      src/05-1-union/main.c
  13. 0
      src/05-2-memory-layout/main.c
  14. 0
      src/05-3-5-4-union-size/main.c
  15. 0
      src/05-5-helper-fields/exercise.h
  16. 0
      src/05-5-helper-fields/main.c
  17. 0
      src/06-1-the-stack/exercise.h
  18. 0
      src/06-1-the-stack/main.c
  19. 0
      src/06-2-why-a-stack/main.c
  20. 0
      src/06-3-stack-overflow/main.c
  21. 0
      src/06-4-pointers-to-the-stack/main.c
  22. 0
      src/06-5-the-heap/exercise.c
  23. 0
      src/06-5-the-heap/exercise.h
  24. 0
      src/06-5-the-heap/main.c
  25. 0
      src/06-6-malloc/exercise.c
  26. 0
      src/06-6-malloc/exercise.h
  27. 0
      src/06-6-malloc/main.c
  28. 0
      src/06-7-free/exercise.c
  29. 0
      src/06-7-free/exercise.h
  30. 0
      src/06-7-free/main.c
  31. 0
      src/06-8-big-endian-little-endian/main.c
  32. 0
      src/07-1-pointer-pointers/exercise.c
  33. 0
      src/07-1-pointer-pointers/exercise.h
  34. 0
      src/07-1-pointer-pointers/main.c
  35. 0
      src/07-2-array-of-pointers/exercise.c
  36. 0
      src/07-2-array-of-pointers/exercise.h
  37. 0
      src/07-2-array-of-pointers/main.c
  38. 0
      src/07-3-void-pointers/exercise.c
  39. 0
      src/07-3-void-pointers/exercise.h
  40. 0
      src/07-3-void-pointers/main.c
  41. 0
      src/07-4-swapping-integers/exercise.c
  42. 0
      src/07-4-swapping-integers/exercise.h
  43. 0
      src/07-4-swapping-integers/main.c
  44. 0
      src/07-5-swapping-strings/exercise.c
  45. 0
      src/07-5-swapping-strings/exercise.h
  46. 0
      src/07-5-swapping-strings/main.c
  47. 0
      src/07-6-generic-swap/exercise.c
  48. 0
      src/07-6-generic-swap/exercise.h
  49. 0
      src/07-6-generic-swap/main.c
  50. 0
      src/08-1-low-level-stack/main.c
  51. 0
      src/08-1-low-level-stack/snekstack.c
  52. 0
      src/08-1-low-level-stack/snekstack.h
  53. 0
      src/08-2-stack-push/main.c
  54. 0
      src/08-2-stack-push/snekstack.c
  55. 0
      src/08-2-stack-push/snekstack.h
  56. 0
      src/08-3-stack-pop/main.c
  57. 0
      src/08-3-stack-pop/snekstack.c
  58. 0
      src/08-3-stack-pop/snekstack.h
  59. 0
      src/08-4-stack-free/main.c
  60. 0
      src/08-4-stack-free/snekstack.c
  61. 0
      src/08-4-stack-free/snekstack.h
  62. 0
      src/08-5-dangerous-push/exercise.c
  63. 0
      src/08-5-dangerous-push/exercise.h
  64. 0
      src/08-5-dangerous-push/main.c
  65. 0
      src/08-5-dangerous-push/snekstack.c
  66. 0
      src/08-5-dangerous-push/snekstack.h
  67. 0
      src/08-6-multiple-types/exercise.c
  68. 0
      src/08-6-multiple-types/exercise.h
  69. 0
      src/08-6-multiple-types/main.c
  70. 0
      src/08-6-multiple-types/snekstack.c
  71. 0
      src/08-6-multiple-types/snekstack.h
  72. 0
      src/09-1-snek-objects/main.c
  73. 0
      src/09-1-snek-objects/snekobject.h
  74. 0
      src/09-2-integer/main.c
  75. 0
      src/09-2-integer/snekobject.c
  76. 0
      src/09-2-integer/snekobject.h
  77. 0
      src/09-3-float/main.c
  78. 0
      src/09-3-float/snekobject.c
  79. 0
      src/09-3-float/snekobject.h
  80. 0
      src/09-4-string/main.c
  81. 0
      src/09-4-string/snekobject.c
  82. 0
      src/09-4-string/snekobject.h
  83. 0
      src/09-5-vector3/main.c
  84. 0
      src/09-5-vector3/snekobject.c
  85. 0
      src/09-5-vector3/snekobject.h
  86. 0
      src/09-6-arrays/main.c
  87. 0
      src/09-6-arrays/snekobject.c
  88. 0
      src/09-6-arrays/snekobject.h
  89. 0
      src/09-7-get-and-set/main.c
  90. 0
      src/09-7-get-and-set/snekobject.c
  91. 0
      src/09-7-get-and-set/snekobject.h
  92. 0
      src/09-8-length/main.c
  93. 0
      src/09-8-length/snekobject.c
  94. 0
      src/09-8-length/snekobject.h
  95. 30
      src/11-01-handling-cycles/main.c
  96. 179
      src/11-01-handling-cycles/snekobject.c
  97. 52
      src/11-01-handling-cycles/snekobject.h
  98. 31
      src/11-02-pros-and-cons/main.c
  99. 38
      src/11-02-pros-and-cons/snekobject.h
  100. 78
      src/11-02-pros-and-cons/stack.c
  101. Some files were not shown because too many files have changed in this diff Show More

442
README.org

@ -6,25 +6,25 @@
Completed course from
[[https://www.boot.dev/courses/learn-memory-management-c][boot.dev]].
The exercises from the course have been worked out in this repo.
This is my way of having the "certificate" for free.
The exercises from the course have been worked out in this repository.
This is my way of obtaining the "certificate" for free.
The first the 3 chapters of the course can be done interactively on the website.
[[./bootdev-c.png]]
If you're reading this with the intention of completing the exercises yourself,
you can find each exercise is in its own directory inside of the =src= directory.
Remove all the files that are not called =main.c= and recreate them from the
exercises on the boot.dev website as you go through them, so you won't get spoiled.
Remove all the files that each exercise mentions you should modify, as you go
through them. Then recreate the files from the exercise, so you won't get spoiled.
Note:
Notes:
- In order to verify allocations in the unit tests, please use the wrapper
functions =boot_malloc=, =boot_calloc=, =boot_realloc= and =boot_free= from
=boot_lib.h= instead of the =stdlib.h= allocation functions
- In chapter 6 exercise 6, macOS malloc will almost never return a NULL pointer
due to virtual memory overcommit, so you should check for
~size == 1024 * 1024 * 100)~ instead of ~array == NULL~
- In chapter 8, I renamed ~stack_t~ to ~my_stack_t~ due to a =std= naming
- In chapter 8 and 11, I renamed ~stack_t~ to ~my_stack_t~ due to a =std= naming
conflict on macOS
** Build instructions
@ -44,72 +44,89 @@ Successful output of all the tests:
#+BEGIN_SRC sh
$ make run 12:25PM
[ 3%] Built target munit
[ 6%] Built target 9-8-length
[ 7%] Built target 4-1-enums
[ 9%] Built target 4-2-non-default-values
[ 12%] Built target 4-3-switch-case
[ 14%] Built target 4-4-sizeof-enum
[ 17%] Built target 5-1-union
[ 19%] Built target 5-2-memory-layout
[ 21%] Built target 5-3-5-4-union-size
[ 23%] Built target 5-5-helper-fields
[ 25%] Built target 6-1-the-stack
[ 27%] Built target 6-2-why-a-stack
[ 29%] Built target 6-3-stack-overflow
[ 31%] Built target 6-4-pointers-to-the-stack
[ 34%] Built target 6-5-the-heap
[ 37%] Built target 6-6-malloc
[ 40%] Built target 6-7-free
[ 42%] Built target 6-8-big-endian-little-endian
[ 45%] Built target 7-1-pointer-pointers
[ 48%] Built target 7-2-array-of-pointers
[ 51%] Built target 7-3-void-pointers
[ 54%] Built target 7-4-swapping-integers
[ 57%] Built target 7-5-swapping-strings
[ 60%] Built target 7-6-generic-swap
[ 63%] Built target 8-1-low-level-stack
[ 66%] Built target 8-2-stack-push
[ 69%] Built target 8-3-stack-pop
[ 72%] Built target 8-4-stack-free
[ 76%] Built target 8-5-dangerous-push
[ 80%] Built target 8-6-multiple-types
[ 82%] Built target 9-1-snek-objects
[ 85%] Built target 9-2-integer
[ 88%] Built target 9-3-float
[ 91%] Built target 9-4-string
[ 94%] Built target 9-5-vector3
[ 97%] Built target 9-6-arrays
[100%] Built target 9-7-get-and-set
Running test suite with seed 0xa13b83c4...
colors/are_defined [ OK ] [ 0.00000100 / 0.00000300 CPU ]
[ 2%] Built target munit
[ 5%] Built target 11-10-sweep
[ 6%] Built target 04-1-enums
[ 7%] Built target 04-2-non-default-values
[ 9%] Built target 04-3-switch-case
[ 10%] Built target 04-4-sizeof-enum
[ 12%] Built target 05-1-union
[ 13%] Built target 05-2-memory-layout
[ 15%] Built target 05-3-5-4-union-size
[ 16%] Built target 05-5-helper-fields
[ 17%] Built target 06-1-the-stack
[ 19%] Built target 06-2-why-a-stack
[ 20%] Built target 06-3-stack-overflow
[ 21%] Built target 06-4-pointers-to-the-stack
[ 23%] Built target 06-5-the-heap
[ 25%] Built target 06-6-malloc
[ 27%] Built target 06-7-free
[ 28%] Built target 06-8-big-endian-little-endian
[ 30%] Built target 07-1-pointer-pointers
[ 32%] Built target 07-2-array-of-pointers
[ 33%] Built target 07-3-void-pointers
[ 35%] Built target 07-4-swapping-integers
[ 37%] Built target 07-5-swapping-strings
[ 39%] Built target 07-6-generic-swap
[ 41%] Built target 08-1-low-level-stack
[ 42%] Built target 08-2-stack-push
[ 44%] Built target 08-3-stack-pop
[ 46%] Built target 08-4-stack-free
[ 48%] Built target 08-5-dangerous-push
[ 50%] Built target 08-6-multiple-types
[ 52%] Built target 09-1-snek-objects
[ 53%] Built target 09-2-integer
[ 55%] Built target 09-3-float
[ 57%] Built target 09-4-string
[ 59%] Built target 09-5-vector3
[ 61%] Built target 09-6-arrays
[ 62%] Built target 09-7-get-and-set
[ 64%] Built target 09-8-length
[ 65%] Built target 10-1-garbage-collector
[ 67%] Built target 10-2-refcounting
[ 69%] Built target 10-3-increment
[ 71%] Built target 10-4-decrement-and-free
[ 73%] Built target 10-5-vectors
[ 74%] Built target 10-6-arrays
[ 76%] Built target 10-7-refcounting-review
[ 77%] Built target 11-01-handling-cycles
[ 80%] Built target 11-02-pros-and-cons
[ 82%] Built target 11-03-stack-frames
[ 85%] Built target 11-04-tracking-objects
[ 88%] Built target 11-05-free
[ 91%] Built target 11-06-frame-references
[ 94%] Built target 11-07-mark-and-sweep
[ 97%] Built target 11-08-mark
[100%] Built target 11-09-trace
Running test suite with seed 0x3d418efb...
colors/are_defined [ OK ] [ 0.00000100 / 0.00000100 CPU ]
colors/are_defined_correctly [ OK ] [ 0.00000100 / 0.00000200 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x9c11f043...
colors/defined [ OK ] [ 0.00000000 / 0.00000000 CPU ]
colors/defined_vscode [ OK ] [ 0.00000000 / 0.00000000 CPU ]
Running test suite with seed 0x1447c343...
colors/defined [ OK ] [ 0.00000000 / 0.00000100 CPU ]
colors/defined_vscode [ OK ] [ 0.00000100 / 0.00000200 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xdac57c79...
Running test suite with seed 0xba550ddb...
http/switch_enum [ OK ] [ 0.00000100 / 0.00000100 CPU ]
http/switch_enum_default [ OK ] [ 0.00000100 / 0.00000100 CPU ]
http/switch_enum_default [ OK ] [ 0.00000100 / 0.00000200 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
The size of BigNumbers is 8 bytes
The size of HttpErrorCode is 4 bytes
Running test suite with seed 0x85251cb1...
format/integer [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0xba8a2b8d...
format/integer [ OK ] [ 0.00000200 / 0.00000300 CPU ]
format/string [ OK ] [ 0.00000100 / 0.00000100 CPU ]
format/integer_nvim [ OK ] [ 0.00000100 / 0.00000200 CPU ]
format/string_nvim [ OK ] [ 0.00000100 / 0.00000100 CPU ]
format/integer_nvim [ OK ] [ 0.00000200 / 0.00000200 CPU ]
format/string_nvim [ OK ] [ 0.00000100 / 0.00000200 CPU ]
4 of 4 (100%) tests successful, 0 (0%) test skipped.
value (set): -420
err (unset): 4294966876
value (unset): -1
err (set): 4294967295
Running test suite with seed 0xb2bd8586...
PacketHeader/test_packet_header_size [ OK ] [ 0.00000100 / 0.00000000 CPU ]
Running test suite with seed 0xa0f30fc8...
PacketHeader/test_packet_header_size [ OK ] [ 0.00000100 / 0.00000100 CPU ]
PacketHeader/test_tcp_header_fields [ OK ] [ 0.00000100 / 0.00000100 CPU ]
PacketHeader/test_field_raw_size [ OK ] [ 0.00000100 / 0.00000100 CPU ]
PacketHeader/test_field_to_raw_consistency[ OK ] [ 0.00000100 / 0.00000200 CPU ]
PacketHeader/test_field_raw_size [ OK ] [ 0.00000100 / 0.00000000 CPU ]
PacketHeader/test_field_to_raw_consistency[ OK ] [ 0.00000100 / 0.00000000 CPU ]
4 of 4 (100%) tests successful, 0 (0%) test skipped.
---------------------------------
Stack pointer offset: 0 bytes
@ -126,141 +143,246 @@ Stack pointer offset: 0 bytes
---------------------------------
dark roast.
Running test suite with seed 0x5ed24c16...
/example/compare [ OK ] [ 0.00000100 / 0.00000200 CPU ]
/example/rand [ OK ] [ 0.00000200 / 0.00000100 CPU ]
Running test suite with seed 0xbd38a5fa...
/example/compare [ OK ] [ 0.00000600 / 0.00000500 CPU ]
/example/rand [ OK ] [ 0.00000300 / 0.00000300 CPU ]
/example/parameters
foo=one, bar=red [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=one, bar=green [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=one, bar=blue [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=two, bar=red [ OK ] [ 0.00000200 / 0.00000100 CPU ]
foo=one, bar=red [ OK ] [ 0.00000300 / 0.00000300 CPU ]
foo=one, bar=green [ OK ] [ 0.00000300 / 0.00000300 CPU ]
foo=one, bar=blue [ OK ] [ 0.00000200 / 0.00000300 CPU ]
foo=two, bar=red [ OK ] [ 0.00000300 / 0.00000200 CPU ]
foo=two, bar=green [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=two, bar=blue [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=three, bar=red [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=three, bar=green [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=three, bar=blue [ OK ] [ 0.00000100 / 0.00000000 CPU ]
foo=three, bar=red [ OK ] [ 0.00000100 / 0.00000200 CPU ]
foo=three, bar=green [ OK ] [ 0.00000300 / 0.00000200 CPU ]
foo=three, bar=blue [ OK ] [ 0.00000200 / 0.00000300 CPU ]
11 of 11 (100%) tests successful, 0 (0%) test skipped.
Size of pool: 10240
Initial string: snek
c1: 10, 20
c2: 30, 40
c3: 50, 60
Running test suite with seed 0x08ecbbe7...
get_full_greeting/test_basic_greeting[ OK ] [ 0.00000200 / 0.00000200 CPU ]
get_full_greeting/test_short_buffer [ OK ] [ 0.00000100 / 0.00000200 CPU ]
Running test suite with seed 0x4e7eb250...
get_full_greeting/test_basic_greeting[ OK ] [ 0.00000500 / 0.00000500 CPU ]
get_full_greeting/test_short_buffer [ OK ] [ 0.00000400 / 0.00000400 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xd953a05a...
allocate_scalar_array/test_allocate_scalar_array_size[ OK ] [ 0.00000100 / 0.00000100 CPU ]
allocate_scalar_array/test_allocate_scalar_array_values[ OK ] [ 0.00000200 / 0.00000100 CPU ]
allocate_scalar_array/test_allocate_scalar_array_zero_multiplier[ OK ] [ 0.00000200 / 0.00000200 CPU ]
allocate_scalar_array/test_allocate_too_much[ OK ] [ 0.00001000 / 0.00000900 CPU ]
Running test suite with seed 0x98ffe6c3...
allocate_scalar_array/test_allocate_scalar_array_size[ OK ] [ 0.00000600 / 0.00000600 CPU ]
allocate_scalar_array/test_allocate_scalar_array_values[ OK ] [ 0.00000300 / 0.00000400 CPU ]
allocate_scalar_array/test_allocate_scalar_array_zero_multiplier[ OK ] [ 0.00000500 / 0.00000500 CPU ]
allocate_scalar_array/test_allocate_too_much[ OK ] [ 0.00001800 / 0.00001800 CPU ]
4 of 4 (100%) tests successful, 0 (0%) test skipped.
Allocated 500 lists
Running test suite with seed 0x026c49ea...
/example/compare [ OK ] [ 0.00000100 / 0.00000200 CPU ]
/example/rand [ OK ] [ 0.00000100 / 0.00000200 CPU ]
Running test suite with seed 0xd142494f...
/example/compare [ OK ] [ 0.00000600 / 0.00000500 CPU ]
/example/rand [ OK ] [ 0.00000500 / 0.00000400 CPU ]
/example/parameters
foo=one, bar=red [ OK ] [ 0.00000200 / 0.00000100 CPU ]
foo=one, bar=green [ OK ] [ 0.00000100 / 0.00000100 CPU ]
foo=one, bar=blue [ OK ] [ 0.00000100 / 0.00000200 CPU ]
foo=two, bar=red [ OK ] [ 0.00000100 / 0.00000200 CPU ]
foo=two, bar=green [ OK ] [ 0.00000100 / 0.00000200 CPU ]
foo=two, bar=blue [ OK ] [ 0.00000200 / 0.00000100 CPU ]
foo=three, bar=red [ OK ] [ 0.00000200 / 0.00000100 CPU ]
foo=three, bar=green [ OK ] [ 0.00000200 / 0.00000100 CPU ]
foo=three, bar=blue [ OK ] [ 0.00000200 / 0.00000200 CPU ]
foo=one, bar=red [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=one, bar=green [ OK ] [ 0.00000600 / 0.00000700 CPU ]
foo=one, bar=blue [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=two, bar=red [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=two, bar=green [ OK ] [ 0.00000400 / 0.00000300 CPU ]
foo=two, bar=blue [ OK ] [ 0.00000500 / 0.00000600 CPU ]
foo=three, bar=red [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=three, bar=green [ OK ] [ 0.00000600 / 0.00000500 CPU ]
foo=three, bar=blue [ OK ] [ 0.00001100 / 0.00001100 CPU ]
11 of 11 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xbb38daad...
allocate_list/create [ OK ] [ 0.00000100 / 0.00000200 CPU ]
allocate_list/overwrite [ OK ] [ 0.00000100 / 0.00000000 CPU ]
Running test suite with seed 0x3b94faee...
allocate_list/create [ OK ] [ 0.00000500 / 0.00000600 CPU ]
allocate_list/overwrite [ OK ] [ 0.00000300 / 0.00000300 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x33807c18...
create_token_pointer_array/test_create_token_pointer_array_single[ OK ] [ 0.00000100 / 0.00000200 CPU ]
create_token_pointer_array/test_create_token_pointer_array_multiple[ OK ] [ 0.00000200 / 0.00000100 CPU ]
create_token_pointer_array/test_create_token_pointer_array_memory_allocation[ OK ] [ 0.00000200 / 0.00000200 CPU ]
Running test suite with seed 0x30623318...
create_token_pointer_array/test_create_token_pointer_array_single[ OK ] [ 0.00000600 / 0.00000500 CPU ]
create_token_pointer_array/test_create_token_pointer_array_multiple[ OK ] [ 0.00000600 / 0.00000700 CPU ]
create_token_pointer_array/test_create_token_pointer_array_memory_allocation[ OK ] [ 0.00000600 / 0.00000600 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x8614a0d1...
snek_zero_out/test_zero_out_integer [ OK ] [ 0.00000100 / 0.00000100 CPU ]
snek_zero_out/test_zero_out_float [ OK ] [ 0.00000100 / 0.00000000 CPU ]
snek_zero_out/test_zero_out_bool [ OK ] [ 0.00000000 / 0.00000000 CPU ]
snek_zero_out/test_zero_out_nonzero_values[ OK ] [ 0.00000100 / 0.00000000 CPU ]
Running test suite with seed 0xdb4dc3bb...
snek_zero_out/test_zero_out_integer [ OK ] [ 0.00000500 / 0.00000500 CPU ]
snek_zero_out/test_zero_out_float [ OK ] [ 0.00000300 / 0.00000300 CPU ]
snek_zero_out/test_zero_out_bool [ OK ] [ 0.00000300 / 0.00000300 CPU ]
snek_zero_out/test_zero_out_nonzero_values[ OK ] [ 0.00000400 / 0.00000400 CPU ]
4 of 4 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x2f6f82cf...
void-pointer/swap_ints [ OK ] [ 0.00000000 / 0.00000000 CPU ]
void-pointer/swap_ints_same [ OK ] [ 0.00000100 / 0.00000200 CPU ]
Running test suite with seed 0x1e23c270...
void-pointer/swap_ints [ OK ] [ 0.00000500 / 0.00000400 CPU ]
void-pointer/swap_ints_same [ OK ] [ 0.00000300 / 0.00000300 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x62099957...
void-pointer/swap_str [ OK ] [ 0.00000100 / 0.00000100 CPU ]
void-pointer/test_swap_str_long [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0x343e18c2...
void-pointer/swap_str [ OK ] [ 0.00000400 / 0.00000500 CPU ]
void-pointer/test_swap_str_long [ OK ] [ 0.00000400 / 0.00000400 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x56ef9f75...
swap/generic_ints [ OK ] [ 0.00000100 / 0.00000200 CPU ]
swap/generic_strings [ OK ] [ 0.00000100 / 0.00000100 CPU ]
swap/generic_struct [ OK ] [ 0.00000200 / 0.00000200 CPU ]
Running test suite with seed 0x349b3cc2...
swap/generic_ints [ OK ] [ 0.00000500 / 0.00000400 CPU ]
swap/generic_strings [ OK ] [ 0.00000500 / 0.00000500 CPU ]
swap/generic_struct [ OK ] [ 0.00000600 / 0.00000600 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xdf070ee5...
snekstack/create_stack_small [ OK ] [ 0.00000200 / 0.00000200 CPU ]
snekstack/create_stack_large [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0xcc7f57e3...
snekstack/create_stack_small [ OK ] [ 0.00000600 / 0.00000600 CPU ]
snekstack/create_stack_large [ OK ] [ 0.00000500 / 0.00000500 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xa0778dac...
snekstack/create_stack [ OK ] [ 0.00000100 / 0.00000200 CPU ]
snekstack/push_stack [ OK ] [ 0.00000100 / 0.00000200 CPU ]
snekstack/push_double_capacity [ OK ] [ 0.00000300 / 0.00000300 CPU ]
Running test suite with seed 0xb54c2f05...
snekstack/create_stack [ OK ] [ 0.00000500 / 0.00000500 CPU ]
snekstack/push_stack [ OK ] [ 0.00000700 / 0.00000600 CPU ]
snekstack/push_double_capacity [ OK ] [ 0.00000900 / 0.00000900 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x1df97623...
snekstack/create_stack [ OK ] [ 0.00000200 / 0.00000200 CPU ]
snekstack/push_stack [ OK ] [ 0.00000200 / 0.00000300 CPU ]
snekstack/pop_stack [ OK ] [ 0.00000100 / 0.00000100 CPU ]
snekstack/pop_stack_empty [ OK ] [ 0.00000200 / 0.00000100 CPU ]
Running test suite with seed 0x986e20e8...
snekstack/create_stack [ OK ] [ 0.00000500 / 0.00000500 CPU ]
snekstack/push_stack [ OK ] [ 0.00000600 / 0.00000600 CPU ]
snekstack/pop_stack [ OK ] [ 0.00000600 / 0.00000700 CPU ]
snekstack/pop_stack_empty [ OK ] [ 0.00000600 / 0.00000600 CPU ]
4 of 4 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xc67f74fb...
snekstack/create_stack [ OK ] [ 0.00000100 / 0.00000100 CPU ]
snekstack/push_stack [ OK ] [ 0.00000200 / 0.00000200 CPU ]
snekstack/pop_stack [ OK ] [ 0.00000100 / 0.00000200 CPU ]
Running test suite with seed 0xf45ae006...
snekstack/create_stack [ OK ] [ 0.00000700 / 0.00000600 CPU ]
snekstack/push_stack [ OK ] [ 0.00000600 / 0.00000500 CPU ]
snekstack/pop_stack [ OK ] [ 0.00000700 / 0.00000700 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xb607698d...
snekstack/heterogenous_stack [ OK ] [ 0.00000200 / 0.00000100 CPU ]
Running test suite with seed 0xf83a103b...
snekstack/heterogenous_stack [ OK ] [ 0.00000600 / 0.00000500 CPU ]
1 of 1 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x4804e928...
snekstack/multiple_types_stack [ OK ] [ 0.00000200 / 0.00000300 CPU ]
Running test suite with seed 0x53a94d13...
snekstack/multiple_types_stack [ OK ] [ 0.00000800 / 0.00000800 CPU ]
1 of 1 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xa5a077a3...
object-integer-def/integer_constant [ OK ] [ 0.00000000 / 0.00000100 CPU ]
object-integer-def/integer_obj [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0xd977a296...
object-integer-def/integer_constant [ OK ] [ 0.00000400 / 0.00000400 CPU ]
object-integer-def/integer_obj [ OK ] [ 0.00000500 / 0.00000500 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x0a7224ef...
object-integer/positive [ OK ] [ 0.00000100 / 0.00000200 CPU ]
object-integer/zero [ OK ] [ 0.00000100 / 0.00000100 CPU ]
object-integer/negative [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0x9850a5b5...
object-integer/positive [ OK ] [ 0.00000600 / 0.00000500 CPU ]
object-integer/zero [ OK ] [ 0.00000400 / 0.00000300 CPU ]
object-integer/negative [ OK ] [ 0.00000400 / 0.00000300 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x748c3598...
object-float/positive [ OK ] [ 0.00000100 / 0.00000200 CPU ]
object-float/zero [ OK ] [ 0.00000100 / 0.00000100 CPU ]
object-float/negative [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0x06edb0c3...
object-float/positive [ OK ] [ 0.00000600 / 0.00000400 CPU ]
object-float/zero [ OK ] [ 0.00002200 / 0.00001700 CPU ]
object-float/negative [ OK ] [ 0.00000300 / 0.00000300 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x4632a6a6...
object-string/copies_value [ OK ] [ 0.00000200 / 0.00000200 CPU ]
Running test suite with seed 0x846fed7d...
object-string/copies_value [ OK ] [ 0.00000600 / 0.00000500 CPU ]
1 of 1 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x386735e2...
object-vector/returns_null [ OK ] [ 0.00000100 / 0.00000200 CPU ]
object-vector/multiple_objects [ OK ] [ 0.00000200 / 0.00000200 CPU ]
object-vector/same_object [ OK ] [ 0.00000100 / 0.00000200 CPU ]
Running test suite with seed 0x53cf4c00...
object-vector/returns_null [ OK ] [ 0.00000600 / 0.00000600 CPU ]
object-vector/multiple_objects [ OK ] [ 0.00000700 / 0.00000700 CPU ]
object-vector/same_object [ OK ] [ 0.00000500 / 0.00000500 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x4e6badf5...
object-array/empty [ OK ] [ 0.00000100 / 0.00000100 CPU ]
object-array/calloc [ OK ] [ 0.00000100 / 0.00000100 CPU ]
Running test suite with seed 0x58fd8016...
object-array/empty [ OK ] [ 0.00000500 / 0.00000500 CPU ]
object-array/calloc [ OK ] [ 0.00000300 / 0.00000400 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xe9625367...
object-array/set_and_get [ OK ] [ 0.00000200 / 0.00000200 CPU ]
object-array/set_outside [ OK ] [ 0.00000200 / 0.00000300 CPU ]
object-array/get_outside [ OK ] [ 0.00000200 / 0.00000200 CPU ]
Running test suite with seed 0x7f5412f2...
object-array/set_and_get [ OK ] [ 0.00000500 / 0.00000500 CPU ]
object-array/set_outside [ OK ] [ 0.00000600 / 0.00000600 CPU ]
object-array/get_outside [ OK ] [ 0.00000500 / 0.00000400 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xa7022b54...
object-length/integer [ OK ] [ 0.00000200 / 0.00000100 CPU ]
object-length/float [ OK ] [ 0.00000200 / 0.00000200 CPU ]
object-length/string [ OK ] [ 0.00000200 / 0.00000200 CPU ]
object-length/vector [ OK ] [ 0.00000200 / 0.00000200 CPU ]
object-length/array [ OK ] [ 0.00000200 / 0.00000100 CPU ]
Running test suite with seed 0xa5a5383d...
object-length/integer [ OK ] [ 0.00000600 / 0.00000600 CPU ]
object-length/float [ OK ] [ 0.00000600 / 0.00000600 CPU ]
object-length/string [ OK ] [ 0.00000600 / 0.00000600 CPU ]
object-length/vector [ OK ] [ 0.00000400 / 0.00000300 CPU ]
object-length/array [ OK ] [ 0.00000500 / 0.00000500 CPU ]
5 of 5 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x2e6f75bf...
/example/compare [ OK ] [ 0.00000600 / 0.00000400 CPU ]
/example/rand [ OK ] [ 0.00000500 / 0.00000500 CPU ]
/example/parameters
foo=one, bar=red [ OK ] [ 0.00000500 / 0.00000500 CPU ]
foo=one, bar=green [ OK ] [ 0.00000500 / 0.00000600 CPU ]
foo=one, bar=blue [ OK ] [ 0.00000900 / 0.00000800 CPU ]
foo=two, bar=red [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=two, bar=green [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=two, bar=blue [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=three, bar=red [ OK ] [ 0.00000300 / 0.00000300 CPU ]
foo=three, bar=green [ OK ] [ 0.00000300 / 0.00000400 CPU ]
foo=three, bar=blue [ OK ] [ 0.00000400 / 0.00000300 CPU ]
11 of 11 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xdf462866...
refcounttest_int_has_refcount [ OK ] [ 0.00000500 / 0.00000400 CPU ]
refcounttest_float_has_refcount [ OK ] [ 0.00000500 / 0.00000400 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x3b906f5c...
refcount/test_inc_refcount [ OK ] [ 0.00000600 / 0.00000600 CPU ]
refcount/test_inc_refcount_more [ OK ] [ 0.00000400 / 0.00000400 CPU ]
refcount/test_null_obj [ OK ] [ 0.00000500 / 0.00000500 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x6b51ea68...
refcount/has_refcount [ OK ] [ 0.00000600 / 0.00000600 CPU ]
refcount/inc_refcount [ OK ] [ 0.00000400 / 0.00000300 CPU ]
refcount/dec_refcount [ OK ] [ 0.00000500 / 0.00000500 CPU ]
refcount/free_refcount [ OK ] [ 0.00000400 / 0.00000500 CPU ]
refcount/string_freed [ OK ] [ 0.00000500 / 0.00000600 CPU ]
5 of 5 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xfcdf2928...
refcount/has_refcount [ OK ] [ 0.00000600 / 0.00000500 CPU ]
refcount/inc_refcount [ OK ] [ 0.00000500 / 0.00000500 CPU ]
refcount/dec_refcount [ OK ] [ 0.00000500 / 0.00000500 CPU ]
refcount/free_refcount [ OK ] [ 0.00000300 / 0.00000300 CPU ]
refcount/string_freed [ OK ] [ 0.00000300 / 0.00000300 CPU ]
refcount/vector3 [ OK ] [ 0.00000400 / 0.00000400 CPU ]
refcount/vector3-same [ OK ] [ 0.00000300 / 0.00000200 CPU ]
7 of 7 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x2df34e21...
refcount/array_set [ OK ] [ 0.00000800 / 0.00000800 CPU ]
refcount/array_free [ OK ] [ 0.00000600 / 0.00000700 CPU ]
refcount/has_refcount [ OK ] [ 0.00000300 / 0.00000300 CPU ]
refcount/inc_refcount [ OK ] [ 0.00000400 / 0.00000400 CPU ]
refcount/dec_refcount [ OK ] [ 0.00000400 / 0.00000300 CPU ]
refcount/free_refcount [ OK ] [ 0.00000500 / 0.00000500 CPU ]
refcount/string_freed [ OK ] [ 0.00000500 / 0.00000500 CPU ]
refcount/vector3 [ OK ] [ 0.00000400 / 0.00000400 CPU ]
8 of 8 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x91892c1e...
/example/compare [ OK ] [ 0.00000500 / 0.00000500 CPU ]
/example/rand [ OK ] [ 0.00000600 / 0.00000500 CPU ]
/example/parameters
foo=one, bar=red [ OK ] [ 0.00000500 / 0.00000400 CPU ]
foo=one, bar=green [ OK ] [ 0.00000500 / 0.00000500 CPU ]
foo=one, bar=blue [ OK ] [ 0.00001100 / 0.00001200 CPU ]
foo=two, bar=red [ OK ] [ 0.00000500 / 0.00000600 CPU ]
foo=two, bar=green [ OK ] [ 0.00000600 / 0.00000600 CPU ]
foo=two, bar=blue [ OK ] [ 0.00000300 / 0.00000400 CPU ]
foo=three, bar=red [ OK ] [ 0.00000300 / 0.00000400 CPU ]
foo=three, bar=green [ OK ] [ 0.00000400 / 0.00000400 CPU ]
foo=three, bar=blue [ OK ] [ 0.00000400 / 0.00000300 CPU ]
11 of 11 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x0dddaf2c...
refcount/correctly_free [ OK ] [ 0.00000700 / 0.00000700 CPU ]
1 of 1 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x435b0c66...
mark-and-sweep/vm [ OK ] [ 0.00000600 / 0.00000700 CPU ]
mark-and-sweep/vm [ OK ] [ 0.00001400 / 0.00000700 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x85af19f7...
mark-and-sweep/test_vm_new [ OK ] [ 0.00000800 / 0.00000700 CPU ]
mark-and-sweep/test_vm_new_frame [ OK ] [ 0.00000700 / 0.00000600 CPU ]
mark-and-sweep/test_frames_are_freed [ OK ] [ 0.00000600 / 0.00000600 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x1cceaa41...
mark-and-sweep/test_vm_new [ OK ] [ 0.00000800 / 0.00000700 CPU ]
mark-and-sweep/test_frames_are_freed [ OK ] [ 0.00000700 / 0.00000700 CPU ]
mark-and-sweep/test_new_object [ OK ] [ 0.00000700 / 0.00000600 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xc169d14b...
mark-and-sweep/test_reference_object [ OK ] [ 0.00000700 / 0.00000700 CPU ]
mark-and-sweep/test_frames_are_freed [ OK ] [ 0.00000700 / 0.00000700 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xac37539a...
mark-and-sweep/test_one_ref [ OK ] [ 0.00000900 / 0.00000900 CPU ]
mark-and-sweep/test_multi_ref [ OK ] [ 0.00000800 / 0.00000800 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0xaa6df145...
mark-and-sweep/test_field_exists [ OK ] [ 0.00000900 / 0.00000800 CPU ]
mark-and-sweep/test_marked_is_false [ OK ] [ 0.00000600 / 0.00000500 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x22d87982...
mark-and-sweep/test_single_frame [ OK ] [ 0.00000900 / 0.00000900 CPU ]
mark-and-sweep/test_multi_frame [ OK ] [ 0.00001000 / 0.00001100 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x147d09b4...
mark-and-sweep/test_trace_vector [ OK ] [ 0.00000900 / 0.00000900 CPU ]
mark-and-sweep/test_trace_array [ OK ] [ 0.00001200 / 0.00001300 CPU ]
mark-and-sweep/test_trace_nested [ OK ] [ 0.00001700 / 0.00001700 CPU ]
3 of 3 (100%) tests successful, 0 (0%) test skipped.
Running test suite with seed 0x93c96b1a...
mark-and-sweep/test_simple [ OK ] [ 0.00000900 / 0.00000800 CPU ]
mark-and-sweep/test_full [ OK ] [ 0.00001900 / 0.00002000 CPU ]
2 of 2 (100%) tests successful, 0 (0%) test skipped.
[100%] Built target run
#+END_SRC

0
src/4-1-enums/color.h → src/04-1-enums/color.h

0
src/4-1-enums/main.c → src/04-1-enums/main.c

0
src/4-2-non-default-values/color.h → src/04-2-non-default-values/color.h

0
src/4-2-non-default-values/main.c → src/04-2-non-default-values/main.c

0
src/4-3-switch-case/http.c → src/04-3-switch-case/http.c

0
src/4-3-switch-case/http.h → src/04-3-switch-case/http.h

0
src/4-3-switch-case/main.c → src/04-3-switch-case/main.c

0
src/4-4-sizeof-enum/main.c → src/04-4-sizeof-enum/main.c

0
src/5-1-union/exercise.c → src/05-1-union/exercise.c

0
src/5-1-union/exercise.h → src/05-1-union/exercise.h

0
src/5-1-union/main.c → src/05-1-union/main.c

0
src/5-2-memory-layout/main.c → src/05-2-memory-layout/main.c

0
src/5-3-5-4-union-size/main.c → src/05-3-5-4-union-size/main.c

0
src/5-5-helper-fields/exercise.h → src/05-5-helper-fields/exercise.h

0
src/5-5-helper-fields/main.c → src/05-5-helper-fields/main.c

0
src/6-1-the-stack/exercise.h → src/06-1-the-stack/exercise.h

0
src/6-1-the-stack/main.c → src/06-1-the-stack/main.c

0
src/6-2-why-a-stack/main.c → src/06-2-why-a-stack/main.c

0
src/6-3-stack-overflow/main.c → src/06-3-stack-overflow/main.c

0
src/6-4-pointers-to-the-stack/main.c → src/06-4-pointers-to-the-stack/main.c

0
src/6-5-the-heap/exercise.c → src/06-5-the-heap/exercise.c

0
src/6-5-the-heap/exercise.h → src/06-5-the-heap/exercise.h

0
src/6-5-the-heap/main.c → src/06-5-the-heap/main.c

0
src/6-6-malloc/exercise.c → src/06-6-malloc/exercise.c

0
src/6-6-malloc/exercise.h → src/06-6-malloc/exercise.h

0
src/6-6-malloc/main.c → src/06-6-malloc/main.c

0
src/6-7-free/exercise.c → src/06-7-free/exercise.c

0
src/6-7-free/exercise.h → src/06-7-free/exercise.h

0
src/6-7-free/main.c → src/06-7-free/main.c

0
src/6-8-big-endian-little-endian/main.c → src/06-8-big-endian-little-endian/main.c

0
src/7-1-pointer-pointers/exercise.c → src/07-1-pointer-pointers/exercise.c

0
src/7-1-pointer-pointers/exercise.h → src/07-1-pointer-pointers/exercise.h

0
src/7-1-pointer-pointers/main.c → src/07-1-pointer-pointers/main.c

0
src/7-2-array-of-pointers/exercise.c → src/07-2-array-of-pointers/exercise.c

0
src/7-2-array-of-pointers/exercise.h → src/07-2-array-of-pointers/exercise.h

0
src/7-2-array-of-pointers/main.c → src/07-2-array-of-pointers/main.c

0
src/7-3-void-pointers/exercise.c → src/07-3-void-pointers/exercise.c

0
src/7-3-void-pointers/exercise.h → src/07-3-void-pointers/exercise.h

0
src/7-3-void-pointers/main.c → src/07-3-void-pointers/main.c

0
src/7-4-swapping-integers/exercise.c → src/07-4-swapping-integers/exercise.c

0
src/7-4-swapping-integers/exercise.h → src/07-4-swapping-integers/exercise.h

0
src/7-4-swapping-integers/main.c → src/07-4-swapping-integers/main.c

0
src/7-5-swapping-strings/exercise.c → src/07-5-swapping-strings/exercise.c

0
src/7-5-swapping-strings/exercise.h → src/07-5-swapping-strings/exercise.h

0
src/7-5-swapping-strings/main.c → src/07-5-swapping-strings/main.c

0
src/7-6-generic-swap/exercise.c → src/07-6-generic-swap/exercise.c

0
src/7-6-generic-swap/exercise.h → src/07-6-generic-swap/exercise.h

0
src/7-6-generic-swap/main.c → src/07-6-generic-swap/main.c

0
src/8-1-low-level-stack/main.c → src/08-1-low-level-stack/main.c

0
src/8-1-low-level-stack/snekstack.c → src/08-1-low-level-stack/snekstack.c

0
src/8-1-low-level-stack/snekstack.h → src/08-1-low-level-stack/snekstack.h

0
src/8-2-stack-push/main.c → src/08-2-stack-push/main.c

0
src/8-2-stack-push/snekstack.c → src/08-2-stack-push/snekstack.c

0
src/8-2-stack-push/snekstack.h → src/08-2-stack-push/snekstack.h

0
src/8-3-stack-pop/main.c → src/08-3-stack-pop/main.c

0
src/8-3-stack-pop/snekstack.c → src/08-3-stack-pop/snekstack.c

0
src/8-3-stack-pop/snekstack.h → src/08-3-stack-pop/snekstack.h

0
src/8-4-stack-free/main.c → src/08-4-stack-free/main.c

0
src/8-4-stack-free/snekstack.c → src/08-4-stack-free/snekstack.c

0
src/8-4-stack-free/snekstack.h → src/08-4-stack-free/snekstack.h

0
src/8-5-dangerous-push/exercise.c → src/08-5-dangerous-push/exercise.c

0
src/8-5-dangerous-push/exercise.h → src/08-5-dangerous-push/exercise.h

0
src/8-5-dangerous-push/main.c → src/08-5-dangerous-push/main.c

0
src/8-5-dangerous-push/snekstack.c → src/08-5-dangerous-push/snekstack.c

0
src/8-5-dangerous-push/snekstack.h → src/08-5-dangerous-push/snekstack.h

0
src/8-6-multiple-types/exercise.c → src/08-6-multiple-types/exercise.c

0
src/8-6-multiple-types/exercise.h → src/08-6-multiple-types/exercise.h

0
src/8-6-multiple-types/main.c → src/08-6-multiple-types/main.c

0
src/8-6-multiple-types/snekstack.c → src/08-6-multiple-types/snekstack.c

0
src/8-6-multiple-types/snekstack.h → src/08-6-multiple-types/snekstack.h

0
src/9-1-snek-objects/main.c → src/09-1-snek-objects/main.c

0
src/9-1-snek-objects/snekobject.h → src/09-1-snek-objects/snekobject.h

0
src/9-2-integer/main.c → src/09-2-integer/main.c

0
src/9-2-integer/snekobject.c → src/09-2-integer/snekobject.c

0
src/9-2-integer/snekobject.h → src/09-2-integer/snekobject.h

0
src/9-3-float/main.c → src/09-3-float/main.c

0
src/9-3-float/snekobject.c → src/09-3-float/snekobject.c

0
src/9-3-float/snekobject.h → src/09-3-float/snekobject.h

0
src/9-4-string/main.c → src/09-4-string/main.c

0
src/9-4-string/snekobject.c → src/09-4-string/snekobject.c

0
src/9-4-string/snekobject.h → src/09-4-string/snekobject.h

0
src/9-5-vector3/main.c → src/09-5-vector3/main.c

0
src/9-5-vector3/snekobject.c → src/09-5-vector3/snekobject.c

0
src/9-5-vector3/snekobject.h → src/09-5-vector3/snekobject.h

0
src/9-6-arrays/main.c → src/09-6-arrays/main.c

0
src/9-6-arrays/snekobject.c → src/09-6-arrays/snekobject.c

0
src/9-6-arrays/snekobject.h → src/09-6-arrays/snekobject.h

0
src/9-7-get-and-set/main.c → src/09-7-get-and-set/main.c

0
src/9-7-get-and-set/snekobject.c → src/09-7-get-and-set/snekobject.c

0
src/9-7-get-and-set/snekobject.h → src/09-7-get-and-set/snekobject.h

0
src/9-8-length/main.c → src/09-8-length/main.c

0
src/9-8-length/snekobject.c → src/09-8-length/snekobject.c

0
src/9-8-length/snekobject.h → src/09-8-length/snekobject.h

30
src/11-01-handling-cycles/main.c

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include "munit.h"
#include "snekobject.h"
munit_case(RUN, correctly_free, {
snek_object_t *first = new_snek_array(1);
snek_object_t *second = new_snek_array(1);
// refcounts: first = 1, second = 1
snek_array_set(first, 0, second);
// refcounts: first = 1, second = 2
snek_array_set(second, 0, first);
// refcounts: first = 2, second = 2
refcount_dec(first);
refcount_dec(second);
assert_int(first->refcount, ==, 1, "Refcount first should be 1");
assert_int(second->refcount, ==, 1, "Refcount second should be 1");
});
int main() {
MunitTest tests[] = {
munit_test("/correctly_free", correctly_free),
munit_null_test,
};
MunitSuite suite = munit_suite("refcount", tests);
return munit_suite_main(&suite, NULL, 0, NULL);
}

179
src/11-01-handling-cycles/snekobject.c

@ -0,0 +1,179 @@
#include "assert.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bootlib.h"
#include "snekobject.h"
bool snek_array_set(snek_object_t *snek_obj, size_t index, snek_object_t *value) {
if (snek_obj == NULL || value == NULL) {
return false;
}
if (snek_obj->kind != ARRAY) {
return false;
}
if (index >= snek_obj->data.v_array.size) {
return false;
}
refcount_inc(value);
if (snek_obj->data.v_array.elements[index] != NULL) {
refcount_dec(snek_obj->data.v_array.elements[index]);
}
snek_obj->data.v_array.elements[index] = value;
return true;
}
void refcount_boot_free(snek_object_t *obj) {
switch (obj->kind) {
case INTEGER:
case FLOAT:
break;
case STRING:
boot_free(obj->data.v_string);
break;
case VECTOR3: {
snek_vector_t vec = obj->data.v_vector3;
refcount_dec(vec.x);
refcount_dec(vec.y);
refcount_dec(vec.z);
break;
}
case ARRAY: {
snek_array_t array = obj->data.v_array;
for (size_t i = 0; i < array.size; i++) {
refcount_dec(array.elements[i]);
}
boot_free(array.elements);
break;
}
default:
assert(false);
}
boot_free(obj);
}
snek_object_t *snek_array_get(snek_object_t *snek_obj, size_t index) {
if (snek_obj == NULL) {
return NULL;
}
if (snek_obj->kind != ARRAY) {
return NULL;
}
if (index >= snek_obj->data.v_array.size) {
return NULL;
}
return snek_obj->data.v_array.elements[index];
}
void refcount_inc(snek_object_t *obj) {
if (obj == NULL) {
return;
}
obj->refcount++;
return;
}
void refcount_dec(snek_object_t *obj) {
if (obj == NULL) {
return;
}
obj->refcount--;
if (obj->refcount == 0) {
return refcount_boot_free(obj);
}
return;
}
snek_object_t *_new_snek_object() {
snek_object_t *obj = boot_calloc(1, sizeof(snek_object_t));
if (obj == NULL) {
return NULL;
}
obj->refcount = 1;
return obj;
}
snek_object_t *new_snek_array(size_t size) {
snek_object_t *obj = _new_snek_object();
if (obj == NULL) {
return NULL;
}
snek_object_t **elements = boot_calloc(size, sizeof(snek_object_t *));
if (elements == NULL) {
boot_free(obj);
return NULL;
}
obj->kind = ARRAY;
obj->data.v_array = (snek_array_t){.size = size, .elements = elements};
return obj;
}
snek_object_t *new_snek_integer(int value) {
snek_object_t *obj = _new_snek_object();
if (obj == NULL) {
return NULL;
}
obj->kind = INTEGER;
obj->data.v_int = value;
return obj;
}
snek_object_t *new_snek_float(float value) {
snek_object_t *obj = _new_snek_object();
if (obj == NULL) {
return NULL;
}
obj->kind = FLOAT;
obj->data.v_float = value;
return obj;
}
snek_object_t *new_snek_string(char *value) {
snek_object_t *obj = _new_snek_object();
if (obj == NULL) {
return NULL;
}
int len = strlen(value);
char *dst = boot_malloc(len + 1);
if (dst == NULL) {
boot_free(obj);
return NULL;
}
strcpy(dst, value);
obj->kind = STRING;
obj->data.v_string = dst;
return obj;
}
snek_object_t *new_snek_vector3(
snek_object_t *x, snek_object_t *y, snek_object_t *z
) {
if (x == NULL || y == NULL || z == NULL) {
return NULL;
}
snek_object_t *obj = _new_snek_object();
if (obj == NULL) {
return NULL;
}
obj->kind = VECTOR3;
obj->data.v_vector3 = (snek_vector_t){.x = x, .y = y, .z = z};
refcount_inc(x);
refcount_inc(y);
refcount_inc(z);
return obj;
}

52
src/11-01-handling-cycles/snekobject.h

@ -0,0 +1,52 @@
#include <stdbool.h>
#include <stddef.h>
typedef struct SnekObject snek_object_t;
typedef struct {
size_t size;
snek_object_t **elements;
} snek_array_t;
typedef struct {
snek_object_t *x;
snek_object_t *y;
snek_object_t *z;
} snek_vector_t;
typedef enum SnekObjectKind {
INTEGER,
FLOAT,
STRING,
VECTOR3,
ARRAY,
} snek_object_kind_t;
typedef union SnekObjectData {
int v_int;
float v_float;
char *v_string;
snek_vector_t v_vector3;
snek_array_t v_array;
} snek_object_data_t;
typedef struct SnekObject {
int refcount;
snek_object_kind_t kind;
snek_object_data_t data;
} snek_object_t;
snek_object_t *new_snek_integer(int value);
snek_object_t *new_snek_float(float value);
snek_object_t *new_snek_string(char *value);
snek_object_t *new_snek_vector3(
snek_object_t *x, snek_object_t *y, snek_object_t *z
);
snek_object_t *new_snek_array(size_t size);
void refcount_inc(snek_object_t *obj);
void refcount_dec(snek_object_t *obj);
void refcount_free(snek_object_t *obj);
bool snek_array_set(snek_object_t *array, size_t index, snek_object_t *value);
snek_object_t *snek_array_get(snek_object_t *snek_obj, size_t index);

31
src/11-02-pros-and-cons/main.c

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include "bootlib.h"
#include "munit.h"
#include "vm.h"
munit_case(RUN, test_vm_new, {
vm_t *vm = vm_new();
assert_int(vm->frames->capacity, ==, 8, "frames should have capacity 8");
assert_int(vm->objects->capacity, ==, 8, "objects should have capacity 8");
vm_free(vm);
});
munit_case(SUBMIT, test_vm_new_free, {
vm_t *vm = vm_new();
vm_free(vm);
assert(boot_all_freed());
});
int main() {
MunitTest tests[] = {
munit_test("/vm", test_vm_new),
munit_test("/vm", test_vm_new_free),
munit_null_test,
};
MunitSuite suite = munit_suite("mark-and-sweep", tests);
return munit_suite_main(&suite, NULL, 0, NULL);
}

38
src/11-02-pros-and-cons/snekobject.h

@ -0,0 +1,38 @@
#include <stdbool.h>
#include <stddef.h>
#include "stack.h"
typedef struct SnekObject snek_object_t;
typedef struct {
size_t size;
snek_object_t **elements;
} snek_array_t;
typedef struct {
snek_object_t *x;
snek_object_t *y;
snek_object_t *z;
} snek_vector_t;
typedef enum SnekObjectKind {
INTEGER,
FLOAT,
STRING,
VECTOR3,
ARRAY,
} snek_object_kind_t;
typedef union SnekObjectData {
int v_int;
float v_float;
char *v_string;
snek_vector_t v_vector3;
snek_array_t v_array;
} snek_object_data_t;
typedef struct SnekObject {
snek_object_kind_t kind;
snek_object_data_t data;
} snek_object_t;

78
src/11-02-pros-and-cons/stack.c

@ -0,0 +1,78 @@
#include <stdio.h>
#include "bootlib.h"
#include "stack.h"
void stack_push(my_stack_t *stack, void *obj) {
if (stack->count == stack->capacity) {
// Double stack capacity to avoid reallocing often
stack->capacity *= 2;
stack->data = boot_realloc(stack->data, stack->capacity * sizeof(void *));
if (stack->data == NULL) {
// Unable to realloc, just exit :) get gud
exit(1);
}
}
stack->data[stack->count] = obj;
stack->count++;
return;
}
void *stack_pop(my_stack_t *stack) {
if (stack->count == 0) {
return NULL;
}
stack->count--;
return stack->data[stack->count];
}
void stack_free(my_stack_t *stack) {
if (stack == NULL) {
return;
}
if (stack->data != NULL) {
boot_free(stack->data);
}
boot_free(stack);
}
void stack_remove_nulls(my_stack_t *stack) {
size_t new_count = 0;
// Iterate through the stack and compact non-NULL pointers.
for (size_t i = 0; i < stack->count; ++i) {
if (stack->data[i] != NULL) {
stack->data[new_count++] = stack->data[i];
}
}
// Update the count to reflect the new number of elements.
stack->count = new_count;
// Optionally, you might want to zero out the remaining slots.
for (size_t i = new_count; i < stack->capacity; ++i) {
stack->data[i] = NULL;
}
}
my_stack_t *stack_new(size_t capacity) {
my_stack_t *stack = boot_malloc(sizeof(my_stack_t));
if (stack == NULL) {
return NULL;
}
stack->count = 0;
stack->capacity = capacity;
stack->data = boot_malloc(stack->capacity * sizeof(void *));
if (stack->data == NULL) {
boot_free(stack);
return NULL;
}
return stack;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save