Implementation/Auto Library

From Pit
Jump to: navigation, search

The library for supporting auto variables is in the _auto namespace. (Names prefixed with underscore are reserved for the compiler to use.)

The compiler translates each operation on an auto variable into a function call in the _auto namespace. Most of these function calls fall into several groups:

  • Binary and unary operators. For examples, $_auto.any.{add,sub,mul,div,assign,add_assign,neg,logical_not,bitwise_not}. These dispatch type-specific functions depending on what the type of the left side is. For example, when the add operation is called and the type of the stored value is integer, $_auto.int.add is called.
  • Constructors: For examples, $_auto.{undef,int,float,ref}.new
  • Fetchers: For examples, $_auto.{int,float}.fetch. These fetch a value to be stored in a primitive variable. The type of the target primitive variable determines which fetcher is called. For example, when converting an auto variable to a primitive integer, $_auto.int.fetch is called.
  • Other: $_auto.refcount_inc, $_auto.refcount_dec, $_auto.deref, $_auto.new.auto (?), $_auto.rstore