Refactor active configuration handling
haxscramper opened this issue · comments
Refactor active configuration handling in the options.ConfigRef
- right now every single field is placed on the same level, including both mutable non-configuration values (error counter, list of symbols) and active/passive configurations (list of active notes, local and global options).
Field that are used to store explicit configuration values (backend/target/options/globalOptions) need to be factored out into a separate type definition.
- This would allow treating compiler (at least on conceptual level) as a function
proc compile(config: ActiveOptions)
. - This type can be reused in testament to serve as a configuration cell in test matrix
- Command-line configuration reading can be simplified as well - instead of using a whole
ConfigRef
object and mutating it in-place, it can simply returnActiveOptions
object
Old code should continue to work using getters and setters. Additional upside - this change would provide a single point of tracing for the active configuration and reduce number of direct access to fields (which cannot be debugged with echo
, cannot be asserted and so on).
type
+ ActiveOptions = object
+ options*: TOptions
ConfigRef* {.acyclic.} = ref object
- options*: TOptions
+ active: ActiveOptions
+ func options*(conf: ConfigRef): TOptions = conf.active.options
+ proc `options=`*(conf: ConfigRef, opts: TOptions) = conf.active.options = opts
Repeated for all "input" fields: backend
, target
, options
, filenamesOption