Slawomir Lisznianski | 12 Sep 15:51

Local and global object referencing model of C2

[Working Draft, for public review]

There are three main ways you can refer to a class instance T:

     * As the object itself-- by value T
     * As the memory address of the object-- by pointer T*
     * With an alias to the object-- by reference T&

C2 upholds the stack and heap stores of C++ but encourages the object 
by-reference model. Pointers are primarily used for array traversals and 
calls to C libraries. In C2, automatic objects are called local objects, 
whereas heap objects are referred to as global objects. C2 defines heap 
as garbage-collectable store, with garbage-collector to be of a 
non-compacting, conservative type. Additionally, with qualifiers read 
right-to-left:

If T represents an object of type T, 'T&' declares reference to global T 
and 'T local&' declares a reference to local T.

A variable declared to be a 'T&', that is reference to global T, shall 
be initialized by operator new of type T or from another reference to 
global T or derived from T.

Double ampersand (&&) designates a reference to global or local object. 
This type of reference is called an "any-store" reference.

A cv-qualified local object can be assigned to a cv-qualified 'T local&' 
or 'T&&' reference variable.

A cv-qualified heap object can be assigned to a cv-qualified 'T&', 'T&&' 
(Continue reading)

Slawomir Lisznianski | 14 Sep 04:18

Re: Local and global object referencing model of C2

Remove:
> An address of a value-object T can be converted to a pointer to T by 
> prefixing the variable with an 'at' (@) sign.

Instead:
Applying an operator '@' to an lvalue-object T will yield a pointer to T.

> It is possible to rebind references with a binary operator '@='. Note 
> that initialization of a reference is treated differently from an 
> assignment to it.

The assignment to a reference has been simplified. The above now reads:

It is possible to rebind references through an assignment.

[Example:

class A { ... };

A& a1 = new A(); // a1: initialized reference to global A
A& a2 = null;    // a2: null initialized reference to global A.
A* a3 = null;    // a3: null initialized pointer to global A.
A a4;            // a4: local A
A&& a5;          // a5: uninitialized reference to any-store A

a2 = a1;   // ok, a2 refers to a1
a5 = a1;   // ok, a5 refers a1
a5 = *a3;  // ok, a5 refers to pointed A (null in this case)
a5 = a4;   // ok, a5 refers to local A
a2 = *a3;  // err, cannot bind global reference with a
(Continue reading)

edA-qa | 14 Sep 16:46

Re: Local and global object referencing model of C2

Hey, this description looks like you just made the = operator behave 
like in Java and always do a rebinding.

Didn't we previously discuss that = by default does assignment, except 
in construction, and the @= must be used for rebinding?

Slawomir Lisznianski wrote:
> Remove:
> 
>> An address of a value-object T can be converted to a pointer to T by 
>> prefixing the variable with an 'at' (@) sign.
> 
> 
> Instead:
> Applying an operator '@' to an lvalue-object T will yield a pointer to T.
> 
>> It is possible to rebind references with a binary operator '@='. Note 
>> that initialization of a reference is treated differently from an 
>> assignment to it.
> 
> 
> The assignment to a reference has been simplified. The above now reads:
> 
> It is possible to rebind references through an assignment.
> 
> [Example:
> 
> class A { ... };
> 
> A& a1 = new A(); // a1: initialized reference to global A
(Continue reading)

Slawomir Lisznianski | 14 Sep 20:59

Re: missing @=

edA-qa <edA-qa <at> disemia.com> writes:
> Hey, this description looks like you just made the = operator behave 
> like in Java and always do a rebinding.

I have received numerous examples in the context of template programming where
having to use @= or = would require excessive use of type traits-- hence the
"assignment unification". 

For clarification, value objects will still be using user-provided assignment
operator. Example:

class Complex
{
  Complex&& operator=(Complex const&& rhs);
  ...
};

Complex&& ac = null; 
Complex lc1, lc2;
...

lc2 = lc1; // invokes user-provided assignment operator
ac = lc3;  // rebinds any-store reference.

If the user doesn't provide an assginment operator, a compiler-provided one will
be used instead.

> Didn't we previously discuss that = by default does assignment, except 
> in construction, and the  <at> = must be used for rebinding?

(Continue reading)

edA-qa | 15 Sep 19:20

Re: missing @=

Slawomir Lisznianski wrote:
> I have received numerous examples in the context of template programming where
> having to use @= or = would require excessive use of type traits-- hence the
> "assignment unification". 

Please provide those examples.  I find a unified = operator to be one of 
Java's great weaknesses and I would hate to see C2 incorporate it.

Assignment and rebinding are /entirely/ different operations, I have a 
hard time believing their lack of unification would make certain kinds 
of templates difficult to program.  I need to see examples to believe that.	

To give some problems that arise:

A& a1 = new A(); // a1: initialized reference to global A
A& a2 = null;    // a2: null initialized reference to global A.
A a4;            // a4: local A

a2 = a1;	//rebinding
a2 = a4;	//assignment

That is just wrong!  Those two statements should not be separate 
operations, that will confuse both newbies and experienced programmers. 
  The only reasons it is bearable in Java is because the operator 
differs between native types and classes, but in C2 these are unified.

And your

template<typename T>
class Holder {
(Continue reading)

Slawomir Lisznianski | 16 Sep 04:13

Re: missing @=

edA-qa wrote:

> Please provide those examples.  I find a unified = operator to be one of 
> Java's great weaknesses and I would hate to see C2 incorporate it.

On place where operator@= was considered harmful was in a generic 
container storing either value objects or references:

Vector<T> v1;
Vector<T&> v2;

The problem is that when dealing with a collection of references, 
generic algorithms, such as sort, copy_if, etc, should, at least 
optionally, perform manipulations on references, not copy-assign objects.

Your Holder class example accurately demonstrated some of the 
ambiguities C2 introduces. However, with or without an operator@=, there 
are still things that simply don't click. For example, the rule "user 
types should be able to simulate built-ins" is broken. Consider a vector 
and an array:

[]<int&> intArray[5];      // declares a local array of 5
                            // references to global int

Vector<int&> intVector(5); // local vector of 5 references
                            // to global int.

intArray[0] @= new int(10);  // places global int at 0th pos.

intVector[0] @= new int(10); // lack of C++-style reference semantics
(Continue reading)

Rajesh Walkay | 17 Sep 16:59
Favicon

Re: missing @=

Slawomir Lisznianski wrote:

> 1) For value object T, T& declares a reference to T, T^ declares a 
> handle to any-store T, T* declares a pointer to T.
> 

Well, we're just one step behind CLI/C++ ;-) These guys came up with one 
more : T%

what I do like about C2 is that stack or heap objects can be ref'd 
through T^. In CLI each one is a different type and users have to pin 
handles to get regular references or pointers. thats somewhat confusing.

Rajesh

-------------------------------------------------------
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 | 17 Sep 17:58

Re: missing @=

Rajesh Walkay wrote:

> In CLI each one is a different type and users have to pin 
> handles to get regular references or pointers.

That's because CLI GC is free to move objects within a so called CLI 
heap. If you don't pin, your "raw" pointer may be invalidated by the 
concurrent collector and crash your program. I think CLI/C++ won't let 
you inadvertently assign a handle to a raw pointer without an explicit 
pinning, even for class members. Consider:

struct Inner { };

struct Outer
{
   Inner i;
};

Microsoft CLI/C++:
------------------
Outer^ o1 = gcnew Outer();
Inner* i1 = &(o1.i);          // error, have to pin or use
                               // internal pointer which "tracks"
                               // object instance

interior_ptr<Inner> ipInner
   = &(o1.i);                  // okay, internal_ptr *tracks*

pin_ptr<Outer> ppOuter = &o1; // pin instance of o1
i1 = &(ppOuter->i);           // okay, Outer was pinned so
(Continue reading)

edA-qa | 16 Sep 17:20

Re: missing @=

Slawomir Lisznianski wrote:
> Vector<T> v1;
> Vector<T&> v2;
> 1) For value object T, T& declares a reference to T, T^ declares a 
> handle to any-store T, T* declares a pointer to T.

Whoa, we don't want to be introducing any more value types, that'll just 
  make it even more confusing.  I think I have a solution that will let 
templates work just fine, and can also allow an explicit or implicit 
rebinding operator.

In my desired system, with a rebinding, the above Vectors, and your 
previous []<int> example will work just fine, which the following 
stipulation:
-Assigning a value to a reference to a reference has the effect of 
rebinding the stored reference variable.

To be clear I'm going to give a complete explanation.

In the definition:
	T& m = new T();
m has two purposes:
	1) m *is* the newly created object when used in all operations
	2) m *is* a real value on the stack containing a pointer to a  real object

Because of these two meanings, it is not possible to have a single 
meaningful assignment operator.  So my view is we maintain that all 
non-special ops work strictly on the 1) meaning.  Only special ops work 
with the second meaning.

(Continue reading)

Slawomir Lisznianski | 16 Sep 22:11

Re: missing @=

edA-qa wrote:
> But there is another type that may seem unclear, but makes perfect sense:
>     T&& p;
> 
> A& myA = new A();
> A& demo = new A();
> 
> Vector<A> vals;    //operator[] returns A&
> vals[0] = myA;    //takes a copy as intended
> demo = myA;    //also takes a copy, as expected

The above looks fine.

> If I haven't made any mistakes this satifies:
>     1. no ambigiuous = operators
>     2. natural template syntax
>     3. overloading of native types / equivalence

I noticed your references don't consider object locality (local vs. 
shared). Did you intentionally remove it, or forget to put it? If you 
removed it, then certain kinds of idioms won't be available, example:

struct Task
{
   virtual void operator()() = 0; // runs within a thread
};

struct Thread
{
   Thread(Task& t);
(Continue reading)

edA-qa | 19 Sep 10:53

Re: missing @=

Slawomir Lisznianski wrote:
> I noticed your references don't consider object locality (local vs. 
> shared). Did you intentionally remove it, or forget to put it? If you 
> removed it, then certain kinds of idioms won't be available, example:

I just wanted simpler examples, but the technique should work fine for 
differnet localities.

> handles almost exclusively, with occasional T^&, that is reference to 
> handle, in cases of operator[], operator=, etc. Pointers are for 
> pointer-arithmetic and compatibility with C. Finally, value objects are 

All I was pointing out is that the ^ operator is not needed, you simply 
allow T&& and everything works fine.  It provides more generality, the 
operations are clear, and avoids one symbol.

--

-- 
edA-qa mort-ora-y
Idea Architect
http://disemia.com/

-------------------------------------------------------
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 15:54

Re: missing @=

edA-qa wrote:
> All I was pointing out is that the ^ operator is not needed, you simply 
> allow T&& and everything works fine.  It provides more generality, the 
> operations are clear, and avoids one symbol.

According to my interpretation of your T&&, this techqniue wouldn't work 
as desired in certain cases. But let me make sure I understood you:

struct A
{
   void process();
};

A la;              // local object
A& ga = new A();   // shared object
A&& pa = ga;       // pointer to ref

la.process();  // okay
ga.process();  // okay
pa.process();  // error, A&& doesn't support value-type semantics

The error above communicates to users that pa is not an ordinary value 
object, but a pointer. For example, assignments to it will rebind, not 
invoke assignment operator.

The problem is when we start writing generic code. We should be able to 
control if objects are copy-constructed, copy-assigned, or just 
references rebound.

With your T&& in place, how can you write a generic function, without 
(Continue reading)

edA-qa | 29 Sep 14:23

Re: missing @=

I still maintain we don't need an extra ^ operator.

Please give the requirements you need to meet, in terms of templates, 
and I will show you how the more limited set of operators (with an &&) 
supports those requirements.  Include requirements about consistency, 
non-copying, etc...

Slawomir Lisznianski wrote:
> edA-qa wrote:
> 
>> All I was pointing out is that the ^ operator is not needed, you 
>> simply allow T&& and everything works fine.  It provides more 
>> generality, the operations are clear, and avoids one symbol.
> 
> 
> According to my interpretation of your T&&, this techqniue wouldn't work 
> as desired in certain cases. But let me make sure I understood you:
> 
> struct A
> {
>   void process();
> };
> 
> A la;              // local object
> A& ga = new A();   // shared object
> A&& pa = ga;       // pointer to ref
> 
> la.process();  // okay
> ga.process();  // okay
> pa.process();  // error, A&& doesn't support value-type semantics
(Continue reading)

Slawomir Lisznianski | 19 Sep 16:30

Re: missing @=

[continuation of previous email]

2nd Attempt
-----------

template <typename T>
void Invoker(T& a)
{
   a.Process();
}

A la;
A& ga = new A();

Invoker(la); // okay
Invoker(ga); // compiler error within Invoker.
              // template parameter T evaluates to T&&.

Both attempts failed to work as desired and I do not see a workaround 
other than template specializations.

--

-- 
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
(Continue reading)

Slawomir Lisznianski | 19 Sep 16:26

Re: missing @=

[continuation of previous email]

2nd Attempt
-----------

template <typename T>
void Invoker(T& a)
{
   a.Process();
}

A la;
A& ga = new A();

Invoker(la); // okay
Invoker(ga); // compiler error within Invoker.
              // template parameter T evaluates to T&&.

Both attempts failed to work as desired and I do not see a workaround 
other than template specializations.

--

-- 
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
(Continue reading)

Slawomir Lisznianski | 19 Sep 16:11

Re: cont missing @=

My son pressed the sent button interrupting my previous email...

2nd Attempt
-----------

template <typename T>
void Invoker(T& a)
{
   a.Process();
}

A la;
A& ga = new A();

Invoker(la); // okay
Invoker(ga); // compiler error within Invoker.
              // template parameter T evaluates to T&&.

Both attempts failed to work as desired and I do not see a workaround 
other than template specializations.

--

-- 

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.
(Continue reading)

Slawomir Lisznianski | 12 Sep 16:00

Correction: value-object of T to pointer to T

Line:
An address of a value-object T can be converted to a pointer to T by 
prefixing the variable with an 'at' (@) sign.

Should be:
Applying an operator '@' to a variable of value-object of type T will 
yield a pointer to T.

--

-- 
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. 13. Go here: http://sf.net/ppc_contest.php

Gmane