# Changeset acb3a793

Ignore:
Timestamp:
Feb 7, 2018, 1:24:46 PM (4 years ago)
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
396fd72, 3d5f2ef
Parents:
5f4f31f
Message:

Incorporate Rob's suggestions on reference section of paper

File:
1 edited

### Legend:

Unmodified
 r5f4f31f Secondly, unlike the references in \CC which always point to a fixed address, \CFA references are rebindable. This allows \CFA references to be default-initialized (to a null pointer), and also to point to different addresses throughout their lifetime. This allows \CFA references to be default-initialized (\eg to a null pointer), and also to point to different addresses throughout their lifetime. This rebinding is accomplished without adding any new syntax to \CFA, but simply by extending the existing semantics of the address-of operator in C. In C, the address of a lvalue is always a rvalue, as in general that address is not stored anywhere in memory, and does not itself have an address. The syntactic motivation for this is clearest when considering overloaded operator-assignment, \eg @int ?+=?(int &, int)@; given @int x, y@, the expected call syntax is @x += y@, not @&x += y@. This initialization of references from lvalues rather than pointers can be considered a lvalue-to-reference'' conversion rather than an elision of the address-of operator; similarly, use of a the value pointed to by a reference in an rvalue context can be thought of as a reference-to-rvalue'' conversion. \CFA includes one more reference conversion, an rvalue-to-reference'' conversion, implemented by means of an implicit temporary. More generally, this initialization of references from lvalues rather than pointers is an instance of a lvalue-to-reference'' conversion rather than an elision of the address-of operator; this conversion can actually be used in any context in \CFA an implicit conversion would be allowed. Similarly, use of a the value pointed to by a reference in an rvalue context can be thought of as a reference-to-rvalue'' conversion, and \CFA also includes a qualifier-adding reference-to-reference'' conversion, analagous to the @T *@ to @const T *@ conversion in standard C. The final reference conversion included in \CFA is rvalue-to-reference'' conversion, implemented by means of an implicit temporary. When an rvalue is used to initialize a reference, it is instead used to initialize a hidden temporary value with the same lexical scope as the reference, and the reference is initialized to the address of this temporary. This allows complex values to be succinctly and efficiently passed to functions, without the syntactic overhead of explicit definition of a temporary variable or the runtime cost of pass-by-value. One of the strengths of C is the control over memory management it gives programmers, allowing resource release to be more consistent and precisely timed than is possible with garbage-collected memory management. However, this manual approach to memory management is often verbose, and it is useful to manage resources other than memory (\eg file handles) using the same mechanism as memory. \CC is well-known for an approach to manual memory management that addresses both these issues, Resource Allocation Is Initialization (RAII), implemented by means of special \emph{constructor} and \emph{destructor} functions; we have implemented a similar feature in \CFA. \CC is well-known for an approach to manual memory management that addresses both these issues, Resource Aquisition Is Initialization (RAII), implemented by means of special \emph{constructor} and \emph{destructor} functions; we have implemented a similar feature in \CFA. \TODO{Fill out section. Mention field-constructors and at-equal escape hatch to C-style initialization. Probably pull some text from Rob's thesis for first draft.}