Teach the compiler about the operating system. Library calls. Multi-file compilation. By end of week your compiler can emit code that calls Math.multiply, Memory.peek, Screen.drawLine. The OS implementations land next week (Ch 12).
Reading
- Chapter prose (primary). draft-chapters/ch11-compiler-os-integration-prose.md
- Petzold weave anchors. Ch 22 The Operating System pp. 330 + 332 (fifth-and-final Ch 22 citation; the subroutine-collection-as-OS-API +
INT 21h); Ch 24 Languages High and Low pp. 362 + 363 (sixth-and-final Ch 24 citation; compiler-vs-interpreter; C-as-high-level-assembly); Ch 25 The Graphical Revolution p. 370 (Xerox Alto framebuffer) - Cross-chapter handouts. stdlib service reference, the OS API contract your compiled programs target
Lecture
lectures/ch11-compiler-os-integration-lecture.md. 3 hours. Key arc:
- The OS as a collection of subroutines. Each service (Math, Memory, Output, Console, Screen, GamePad, Sound, Sys, GPIO; plus String, Array helpers) exposes named entry points
- Library-call codegen. The compiler emits
call Math.multiply 2when it seesMath.multiply(a, b)in source; the linker resolves the name against the OS object file - Multi-file compilation. Each
.jacksource file produces a.vmfile; the VM translator turns each into.s; the assembler turns each into.vof; the linker combines everything - The
Sys.initentry point. The OS boots; callsMain.main; your program runs; control returns to the OS
Lab exercises
Four labs in worksheets/ch11/.
- lab-11.1-library-call-code-generation.md
- lab-11.2-multi-file-compilation.md
- lab-11.3-end-to-end-on-virtus-console-hdmi.md, HDMI output via Virtus Console
- lab-11.4-compiler-output-quality-reconciliation.md
Plan for ~5 hours of lab.
Independent practice
- Read the final visits to Petzold Ch 22 + Ch 24 carefully. The two dominant Petzold chapters of the course close their citation threads this week. Notice that you have read Ch 22 six times and Ch 24 six times by the end of week 12
- Update your Toolchain Diary. Week 12 introduces: cross-file dependency tracking, the academy's full toolchain runner, the Virtus Console HDMI output path
Architecture comparison sidebar
The Virtus OS calling convention from compiler-emitted code is a single VM op (call) plus name resolution at link time. Compare to hosted C on Linux: function calls go through the C ABI (System V AMD64); the OS is reached via syscall instructions or the vDSO; the C library hides the boundary. Compare to freestanding C (kernel code, embedded firmware): no OS to call; all functions inline or compile into the same flat binary. CSA-101 is hosted (you have an OS to call); CSA-201 introduces freestanding for the bootloader work.
Reflection prompts
- The compiler emits
call Math.multiply 2. The linker resolves the name. The OS provides the implementation. Three layers of indirection for one multiplication. What does this buy you? - Petzold Ch 22 closes its citation thread this week. Look back at the six places it appeared (Ch 6a, 7, 8, 10, 11, and one more in Ch 12 next week). What through-line connects them?
- Multi-file compilation lets the program scale beyond one file. What other forms of "scaling" did the toolchain pick up between week 1 and now?
What's next
Week 13 is Virtus OS. You write the standard library: Math, Memory, String, Array, Output, Console, Screen, Keyboard, Sound, GamePad, Sys, GPIO. By end of week the entire stack is yours; the capstone week takes that stack and ships a Virtus Console.