#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::Crafting Interpreters::Ch 14 Chunks of Bytecode
#columns:Front	Back	Tags
Crafting Interpreters ch 14, Chunks of Bytecode: what does it cover?	Start of clox: a C project with a dynamic array of bytecode (a chunk), a constant pool, line information, a disassembler and a memory reallocation function used for all allocation.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::about
Crafting Interpreters ch 14, Chunks of Bytecode: why does it matter?	Bytecode is how CPython, Lua, the JVM and many other runtimes execute code. This chapter is also a crash course in writing careful C.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::why
Crafting Interpreters ch 14, Chunks of Bytecode: which part of the book is it in?	clox (bytecode VM, C)	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::part
clox: what is it?	clox is the bytecode virtual machine for the Lox language, written in C in chapters 14 to 30 of Crafting Interpreters.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
clox: Do I need to finish jlox before clox?	The book assumes it, because clox explains its design by contrast with jlox. You could start at chapter 14, but you would miss the reasons.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
clox: How fast is clox compared with jlox?	Much faster on the book's benchmarks, because it runs compact bytecode in a tight loop instead of walking Java objects. The exact factor depends on the program.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
Bytecode virtual machine: what is it?	A bytecode virtual machine runs a program that has been compiled into a compact sequence of simple instructions (bytecode), decoding and executing one instruction at a time in a loop.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
Bytecode virtual machine: Is bytecode the same as machine code?	No. Machine code runs on real hardware. Bytecode runs on a virtual machine, which is itself a program.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
Bytecode virtual machine: Is a bytecode VM a compiler?	It usually comes with one: a compiler turns source into bytecode, then the VM runs it. clox does both in one pass.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::definition
Crafting Interpreters ch 14, a common trap: “Reading freed memory after a reallocation moves the array.” What's the catch?	AddressSanitizer catches this.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::trap
Crafting Interpreters ch 14: what traps should you watch for?	<ul><li>Forgetting to update capacity or count when growing an array.</li><li>Missing include guards or mixing up .h and .c responsibilities.</li></ul>	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::traps
Crafting Interpreters ch 14: which end-of-chapter challenges are worth your time?	Challenge 1 (compress line info, for example with run-length encoding) and challenge 2 (add a long constant instruction for more than 256 constants) are both worth doing. Challenge 3 (write your own allocator) is a big stretch; save it for later or connect it to Knuth 2.5.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::challenges
Crafting Interpreters ch 14, Chunks of Bytecode: how should you work through it?	Compile with warnings on (-Wall -Wextra) and use AddressSanitizer (-fsanitize=address) from day one. Build the disassembler and use it constantly.	cracked.guide cracked.guide::phase::interpreters cracked.guide::chapter::14 cracked.guide::kind::approach
