zxul767 / lox

An interpreter for the Lox language
1 stars 0 forks source link

find cleaner way to implement execution tracing in `clox` #12

Open zxul767 opened 1 year ago

zxul767 commented 1 year ago

today we have a bunch of places that look like this:

    switch (OBJECT_TYPE(callee)) {
    case OBJECT_CLOSURE: {
#ifdef DEBUG_TRACE_EXECUTION
      if (vm->trace_execution) {
        debug__print_callframe_divider(vm);
      }
#endif
      bool result = call(AS_CLOSURE(callee), args_count, vm);

#ifdef DEBUG_TRACE_EXECUTION
      if (vm->trace_execution) {
      debug__show_callframe_names(vm);
#endif
      return result;
    }

one possibility might to follow the way of assert and make debug__ functions macros which hide all the ugliness behind them and which are compiled away when DEBUG_TRACE_EXECUTION is not defined.