Working Through WACC – chapter 17 void, malloc etc

WACC is this excellent book

and I am blogging my way through it.

This chapter tackles dynamic memory. Once again I was surprised by the complexity. For c dynamic memory just means calling a few functions and working with the returned pointers … well we already have function calls and pointers, so hard can that be? Wrong as usual. The keyword void now rears its ugly head

  • void expressions
  • void * pointer conversions.

void expressions are things like this

(void)42
void_fn() // where void_fn is 'void void_fn(){...}'

I added a new SymbolType::Void, just to deal with this.

Note that functions that return void can either be internally represented by

  • returning SymbolType::Void
  • make all functions return rust’s Option<SymbolType> and in this case use None

I chose the latter.

The parser needs to check that void expressions are not being used in many places.

  • not allowed in logical expressions; if void_fn() {...} for example
  • no arithmetic etc.

Ran 1073 tests in 91.318s

OK


Comments

Leave a comment