edA-qa | 3 Oct 10:35

Revisit synonyms and references / typing

I would like to revist Slawek's example from before of the invoker series:

template<class T> void InvokerA( T^ fun )
{ fun.doSomething(); }

template<class T> void InvokerB( T^ fun )
{ InvokerA( fun ); }

...
T local;
T^ shared = new T();
InvokerB( local );
InvokerB( shared );

I believe this meets the requirements of no copying of the parameters 
without needing a reference.  Here's why, and it has to do with typing, 
an issue that has been somewhat ignored.

In my previous statemtn about references and instances, I am of the 
opinion, that in the way C2 works, the reference type has nothing to do 
with the actual instance type.  Therefore:

T local;
T^ sharedRef = new T();
T local^ localRef = @local;
T* ptr = /*something*/;

Unlike C/C++, in C2 all of the above references are used in the same 
fashion:
	local.func();
(Continue reading)

Rajesh Walkay | 30 Sep 22:16
Favicon

main function signature?

If pointers are second class citizens in C2, what would be the main 
function signature? (-:

-Rajesh

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
edA-qa | 30 Sep 19:43

const references and synonyms

This is a recall of a previous constant discussion.  I would like to 
differentiate between const instances and const references.

//the following is a shared reference to a const heap instance
T const ^ ref;	

//the following is a const shared reference to a heap instance
T ^ const ref;

//const references disallow rebinding, ro conversion to non-const
//references
ref @= otherRef;	//error, cannot rebind

void func( T^ param );
func( ref );	//error, cannot conver to non-const reference

This then needs to be extended to synonyms in the function call syntax. 
  To show why, here is an example of what bad happens without:

template<typename T>
void beNice( T& ref ) {
	ref @= somethingElse;
}

The callers of this function have no guarantee that their shared 
references aren't being rebound -- while sometimes they may want this, 
other times clearly not.  So:

template<typename T>
void beNice( T const& ) {
(Continue reading)

edA-qa | 30 Sep 19:16

Clarified references, shortcut notation

Okay, looking at the types more and more I get a clear picture of how 
they all related to each other and their usage.  I will try to give that 
picture here.

Firstly, in C2 all variables comprise two parts, the instance and the 
reference (I intentionally use this word).

Instances can exist:
	-on the stack
	-in the heap
	-elsewhere (not yet defined)

References are of the types:
	-shared ref to instance in heap
	-local ref to instance on stack
	-value ref to instance on stack
	-ref to instance anywhere

Notes:
-when all shared refs to items in the heap go out of scope, the instance 
is marked for removal/deleted
-when stack space for a stack instance goes out of scope, the instance 
is removed/deleted
-a value ref is the same as a local ref, except that it may not be 
rebound (this limitation is to prevent the losing of an instance)
-in this discussion, a pointer is being ignored, as I believe it can be 
implemented as a non-fundamental type

Notation:

(Continue reading)

Rajesh Walkay | 29 Sep 22:57
Favicon

references to shared objects - too much typing...

Isn't T shared^ too much typing? If C2 makes heap my primary store why 
not defaulting references to refer to objects on shared store only? In 
such a case reference to any-store object would be a special case (being 
less safe and all that) and expect users to be explicit. For example,

T^ myT1 = new T(); /// myT1: reference to shared T
T any^ myT2 = myT; /// myT2: reference to any-store T
myT1 @= myT2; /// error... cannot rebind from any-store

I used "any" for the lack of better name (-:

Constructors would then typically be written as:

struct X {
   X(X const any^ rhs) /// rhs: reference to any-store const X
   {...}
};

About references to local objects..., what's the use of explicitly 
specifying "local"? Won't shared and any-store qualifiers suffice?

-Rajesh

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
Rajesh Walkay | 28 Sep 20:11
Favicon

proxy class in C2

Since the use of operator-> is going to be largely reduced (because of 
references), how would I write a proxy class that "feels" like a 
reference? Will C2 allow to overload the dot operator?

-Rajesh

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
Rajesh Walkay | 28 Sep 20:06
Favicon

inefficient vector in C2?

I wonder how something like std:vector would be implemented in C2? If 
I'm correctly reading the proposed semantics for operator=, then 
containers of references will be quite inefficient. Shouldn't references 
act like pointers, where assignment of references would copy addresses 
only? I think Microsoft's CLI/C++ copies references and user-written 
assignment operator is disallowed for CLI (Ref) classes.

-Rajesh

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
Slawomir Lisznianski | 28 Sep 18:44

digressions on placement new

During private correspondence I was inquired about the placement new. 
Below is a short explanation of how placement new works in C2.

For uninitiated, placement new expression takes an additional argument: 
the memory address on which the object will be constructed. With 
placement new programmers can optimize memory management by using 
pre-allocated areas, something especially useful when implementing 
containers. The trade off is that the programmer must guarantee that the 
pre-allocated storage is sufficiently large and that it meets the memory 
alignment requirements.

Below is a list of issues to consider when using placement new in C2:

1) If the entity is a non-array object, the placement new-expression 
returns a reference to *any-store* object. If it is an array, the 
placement new-expression returns a reference to *any-store* array.

2) Entities returned by placement new expression *may not* be under the 
control of the GC. Whether entities are under the control of the GC 
depends on the type of store that entities are constructed on. [Example:

void fun()
{
   []<T> larr[10];  // array of 10 uninitialized entities of T;
                    //   array is on the stack

   T^ at = new (@larr[5]) T();  // constructs T, using default
                                //   constructor, at 4th element of
                                //   an array. at refers to an object
                                //   whose memory will be reclaimed
(Continue reading)

Slawomir Lisznianski | 24 Sep 22:30

Request for Review: C2 Lang--Declarators Working Draft

This is a notification of submission and request for review of a "C2 
Language Specification–-Declarators, Working Draft September 24, 2004".

The above document is available at http://c2-lang.org/proposals.html 
C2-LG page.

Regards,

--

-- 
Slawomir Lisznianski
C2 Language Group Principal (http://c2-lang.org)

-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
Slawomir Lisznianski | 19 Sep 18:37

generic params that never copy construct

The problem of "no copy-construction guarantee" with generic parameters 
was brought up in one of the previous posts. I find it significant 
enough to deserve a separate thread.

Let me demonstrate how through the use of proposed synonyms, C2 would 
tackle this problem, which by the way is present in C++ today, and, as I 
believe, in T&& model proposed earlier by edA-qa.

In case you haven't read previous posts, we wanted to write a generic 
function named Invoker that calls member function Process() on its 
parameter. A compliant implementation needs to meet the following 
conditions:

1 Shall not make copies of its arguments

Rationale:
  - some types may not support copying semantics,
    examples are fstream, thread,
  - invoker doesn't need a private copy,
  - avoids unnecessary overhead

2 Shall work with local and shared objects

Rationale:
  - C2 aims to unify referencing heap and stack objects

3 Must not use template specializations

Rationale:
  - the general need for using template specializations could
(Continue reading)

Slawomir Lisznianski | 18 Sep 06:41

references, handles and synonyms

After many discussions and plenty of solid input, I think we're finally 
getting somewhere with the C2's object referencing model. However, there 
is still something I wanted to get your opinion on. In one of my recent 
posts, I suggested to introduce T^ type, to which I referred as a handle 
to T. Soon after, I realized that the name "handle" is misleading or 
even incorrect. A handle implies a level of indirection. Handles are 
often used to encapsulate the guts of the underlaying type; in a way 
they are facades. You might have used them in Win32, where almost any 
resource, from a window to a network socket, is represented as a handle. 
So why is "handle" a wrong name in the context of C2? Well, because in 
C2, T^ would simply be a dereferenced native pointer. Programmers are 
assumed to take advantage of that simple fact, for example, when 
interfacing with system libraries.

I propose that T^ be then changed to mean a *reference* to type T. 
Naturally, the next question will be, what does T& stand for? T& would 
be a *synonym* or an *alias* of T. It would mean: T& is a synonym for T 
and requires an lvalue of type T for its initialization. Synonyms cannot 
be rebound too. T const& can be initialized with an rvalue though. Let's 
look at some examples:

T v;                     // v: value type of T
T shared^ t1 = new T();  // inits reference to shared T
T^ t3 = t2;              // inits reference to any-store T
                          // with shared t2

T& s1;                   // error, synonym must be initialized

T^& s2 = t2;             // s2: ok, synonym to any-store reference t2.

(Continue reading)


Gmane