9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] copy paste bug in cc.y?
@ 2014-10-14 22:11 Yoann Padioleau
  2014-10-14 22:45 ` Rob Pike
  0 siblings, 1 reply; 11+ messages in thread
From: Yoann Padioleau @ 2014-10-14 22:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 563 bytes --]

Hi,

It’s a copy paste bug here right?
https://code.google.com/p/ken-cc/source/browse/src/cmd/cc/cc.y#476


|       LSWITCH '(' cexpr ')' stmnt

        {

                $$ = new(OCONST, Z, Z);

                $$->vconst = 0;

                $$->type = types[TINT];

                $3 = new(OSUB, $$, $3);



                $$ = new(OCONST, Z, Z);

                $$->vconst = 0;

                $$->type = types[TINT];

                $3 = new(OSUB, $$, $3);



                $$ = new(OSWITCH, $3, $5);

        }



[-- Attachment #2: Type: text/html, Size: 9273 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-14 22:11 [9fans] copy paste bug in cc.y? Yoann Padioleau
@ 2014-10-14 22:45 ` Rob Pike
  2014-10-15  0:50   ` Rob Pike
  0 siblings, 1 reply; 11+ messages in thread
From: Rob Pike @ 2014-10-14 22:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

Looks like it.

-rob


On Tue, Oct 14, 2014 at 3:11 PM, Yoann Padioleau <pad@fb.com> wrote:

>  Hi,
>
>  It’s a copy paste bug here right?
> https://code.google.com/p/ken-cc/source/browse/src/cmd/cc/cc.y#476
>
>
>    |       LSWITCH '(' cexpr ')' stmnt
>           {
>                   $$ = new(OCONST, Z, Z);
>                   $$->vconst = 0;
>                   $$->type = types[TINT];
>                   $3 = new(OSUB, $$, $3);
>
>                   $$ = new(OCONST, Z, Z);
>                   $$->vconst = 0;
>                   $$->type = types[TINT];
>                   $3 = new(OSUB, $$, $3);
>
>                   $$ = new(OSWITCH, $3, $5);
>           }
>
>
>

[-- Attachment #2: Type: text/html, Size: 6556 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-14 22:45 ` Rob Pike
@ 2014-10-15  0:50   ` Rob Pike
  2014-10-17 17:48     ` Yoann Padioleau
  0 siblings, 1 reply; 11+ messages in thread
From: Rob Pike @ 2014-10-15  0:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

It's not dead code. It's prepping the switch somehow.

-rob


On Tue, Oct 14, 2014 at 3:45 PM, Rob Pike <robpike@gmail.com> wrote:

> Looks like it.
>
> -rob
>
>
> On Tue, Oct 14, 2014 at 3:11 PM, Yoann Padioleau <pad@fb.com> wrote:
>
>>  Hi,
>>
>>  It’s a copy paste bug here right?
>> https://code.google.com/p/ken-cc/source/browse/src/cmd/cc/cc.y#476
>>
>>
>>    |       LSWITCH '(' cexpr ')' stmnt
>>           {
>>                   $$ = new(OCONST, Z, Z);
>>                   $$->vconst = 0;
>>                   $$->type = types[TINT];
>>                   $3 = new(OSUB, $$, $3);
>>
>>                   $$ = new(OCONST, Z, Z);
>>                   $$->vconst = 0;
>>                   $$->type = types[TINT];
>>                   $3 = new(OSUB, $$, $3);
>>
>>                   $$ = new(OSWITCH, $3, $5);
>>           }
>>
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 7131 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-15  0:50   ` Rob Pike
@ 2014-10-17 17:48     ` Yoann Padioleau
  2014-10-17 19:07       ` Charles Forsyth
  2014-10-17 21:30       ` Charles Forsyth
  0 siblings, 2 replies; 11+ messages in thread
From: Yoann Padioleau @ 2014-10-17 17:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

Somehow?

Would be nice to have a comment explaining this “somehow" then
because it looks tricky.

Also is there a place explaining the naming conventions?
I have a hard time understanding what is the difference
between tcom(), acom(), xcom(), and then there’s  complex() …


On Oct 14, 2014, at 5:50 PM, Rob Pike <robpike@gmail.com<mailto:robpike@gmail.com>> wrote:

It's not dead code. It's prepping the switch somehow.

-rob


On Tue, Oct 14, 2014 at 3:45 PM, Rob Pike <robpike@gmail.com<mailto:robpike@gmail.com>> wrote:
Looks like it.

-rob


On Tue, Oct 14, 2014 at 3:11 PM, Yoann Padioleau <pad@fb.com<mailto:pad@fb.com>> wrote:
Hi,

It’s a copy paste bug here right?
https://code.google.com/p/ken-cc/source/browse/src/cmd/cc/cc.y#476<https://urldefense.proofpoint.com/v1/url?u=https://code.google.com/p/ken-cc/source/browse/src/cmd/cc/cc.y%23476&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=%2FN9d7W2LRwZks3eyFNLr8Q%3D%3D%0A&m=4cyv139G%2BaY3rKB1R87WcxrtStd7gWlsDg4w5ndKAww%3D%0A&s=0dfb82e35769784cecce2b03828c23174d1f09519028880890cc63d7dd24265c>


|       LSWITCH '(' cexpr ')' stmnt

        {

                $$ = new(OCONST, Z, Z);

                $$->vconst = 0;

                $$->type = types[TINT];

                $3 = new(OSUB, $$, $3);



                $$ = new(OCONST, Z, Z);

                $$->vconst = 0;

                $$->type = types[TINT];

                $3 = new(OSUB, $$, $3);



                $$ = new(OSWITCH, $3, $5);

        }






[-- Attachment #2: Type: text/html, Size: 8573 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 17:48     ` Yoann Padioleau
@ 2014-10-17 19:07       ` Charles Forsyth
  2014-10-17 20:00         ` Yoann Padioleau
  2014-10-21 17:34         ` Yoann Padioleau
  2014-10-17 21:30       ` Charles Forsyth
  1 sibling, 2 replies; 11+ messages in thread
From: Charles Forsyth @ 2014-10-17 19:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

On 17 October 2014 18:48, Yoann Padioleau <pad@fb.com> wrote:

> Somehow?
>
>  Would be nice to have a comment explaining this “somehow" then
> because it looks tricky.
>

it's building a tree for (0:int-(0:int-x)) which later transformations will
simplify to x, but having done "the usual arithmetic conversions"
balancing and promoting 0s and x as required, if it's char/int/long/vlong.

[-- Attachment #2: Type: text/html, Size: 800 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 19:07       ` Charles Forsyth
@ 2014-10-17 20:00         ` Yoann Padioleau
  2014-10-17 20:04           ` minux
  2014-10-21 17:34         ` Yoann Padioleau
  1 sibling, 1 reply; 11+ messages in thread
From: Yoann Padioleau @ 2014-10-17 20:00 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]


0:int - x   was not enough for those balancing(?) and promoting thing?


On Oct 17, 2014, at 12:07 PM, Charles Forsyth <charles.forsyth@gmail.com<mailto:charles.forsyth@gmail.com>> wrote:

it's building a tree for (0:int-(0:int-x)) which later transformations will simplify to x, but having done "the usual arithmetic conversions"
balancing and promoting 0s and x as required, if it's char/int/long/vlong.


[-- Attachment #2: Type: text/html, Size: 1530 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 20:00         ` Yoann Padioleau
@ 2014-10-17 20:04           ` minux
  2014-10-17 20:32             ` Yoann Padioleau
  0 siblings, 1 reply; 11+ messages in thread
From: minux @ 2014-10-17 20:04 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

On Fri, Oct 17, 2014 at 4:00 PM, Yoann Padioleau <pad@fb.com> wrote:
>
> 0:int - x   was not enough for those balancing(?) and promoting thing?
>
It's enough for type promotion, but you changed the semantics of the
program.

[-- Attachment #2: Type: text/html, Size: 554 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 20:04           ` minux
@ 2014-10-17 20:32             ` Yoann Padioleau
  0 siblings, 0 replies; 11+ messages in thread
From: Yoann Padioleau @ 2014-10-17 20:32 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 353 bytes --]

:) Got it :)

On Oct 17, 2014, at 1:04 PM, minux <minux.ma@gmail.com<mailto:minux.ma@gmail.com>> wrote:


On Fri, Oct 17, 2014 at 4:00 PM, Yoann Padioleau <pad@fb.com<mailto:pad@fb.com>> wrote:
0:int - x   was not enough for those balancing(?) and promoting thing?
It's enough for type promotion, but you changed the semantics of the program.


[-- Attachment #2: Type: text/html, Size: 1056 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 17:48     ` Yoann Padioleau
  2014-10-17 19:07       ` Charles Forsyth
@ 2014-10-17 21:30       ` Charles Forsyth
  1 sibling, 0 replies; 11+ messages in thread
From: Charles Forsyth @ 2014-10-17 21:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 2550 bytes --]

On 17 October 2014 18:48, Yoann Padioleau <pad@fb.com> wrote:

> Also is there a place explaining the naming conventions?
> I have a hard time understanding what is the difference
> between tcom(), acom(), xcom(), and then there’s  complex() …
>

the compiler assumes you've know your  Aho and Ullmann  either by reading
them or by working with them.
this will be useful later.

complex runs tcom, ccom, acom, xcom in that order on a node (and each of
those can recurse).
the compiler works by a series of tree transformations, informed by
attributes attached to each node,
representing types, notional costs, addressability, and other ... stuff.

tcom has a comment!

  /*
   * evaluate types
   * evaluate lvalues (addable == 1)
   */

so that's sorted. "evaluate types" means it does most of the type checking
and making casts explicit.
t->addable is set to 1 if t is an l-value.  L-value and R-value are terms
introduced by Christopher Strachey (see
https://www.itu.dk/courses/BPRD/E2009/fundamental-1967.pdf): briefly,
lvalues
are forms legal on the left-hand side of an assignment ("address-like
objects"), and r-values legal only the right-hand side ("value-like
objects")
where "objects" means what it used to mean before it was ruined.

acom is Aho and Ullman's acommute (with all the exercises done). basically
it does code improvements
taking advantage of associative-commutative operations, and extends that to
look for further optimisations
mentioned in Thompson's paper on the compiler. Ritchie's PDP-11 C compiler
did something similar (but he
called it acommute and distrib). comments such as "bust terms out" and "look
for factorable terms c1*i + c1*c2*j -> c1*(i + c2*j)
suggest what it's doing). essentially it flattens levels of an expression
tree using associative and commutative operators into an array
and rearranges them.

xcom, which is machine-dependent, also has a comment. it assigns an index
of complexity to a sub-expression, which is usually
expressed as the number of registers needed to compute it (and good luck
with that on an x86), but it's also a good place to look
for machine-dependent aspects of machine addressing, such as indexing,
double-indexing, scaling, etc and it sets values in each
tree node to mark that.

"balancing", "casting", "coercion" and other terms connected with
languages, types and compilation were often introduced by Algol-68.
"Balancing" for instance is making  operand types match each other (eg,
int+long => long+long).

[-- Attachment #2: Type: text/html, Size: 3607 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-17 19:07       ` Charles Forsyth
  2014-10-17 20:00         ` Yoann Padioleau
@ 2014-10-21 17:34         ` Yoann Padioleau
  2014-10-21 20:53           ` Charles Forsyth
  1 sibling, 1 reply; 11+ messages in thread
From: Yoann Padioleau @ 2014-10-21 17:34 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]


but (0:int + x)   would not do the same thing? What is special about using SUB instead
of ADD?


On Oct 17, 2014, at 12:07 PM, Charles Forsyth <charles.forsyth@gmail.com<mailto:charles.forsyth@gmail.com>> wrote:


On 17 October 2014 18:48, Yoann Padioleau <pad@fb.com<mailto:pad@fb.com>> wrote:
Somehow?

Would be nice to have a comment explaining this “somehow" then
because it looks tricky.

it's building a tree for (0:int-(0:int-x)) which later transformations will simplify to x, but having done "the usual arithmetic conversions"
balancing and promoting 0s and x as required, if it's char/int/long/vlong.


[-- Attachment #2: Type: text/html, Size: 1457 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] copy paste bug in cc.y?
  2014-10-21 17:34         ` Yoann Padioleau
@ 2014-10-21 20:53           ` Charles Forsyth
  0 siblings, 0 replies; 11+ messages in thread
From: Charles Forsyth @ 2014-10-21 20:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 266 bytes --]

On 21 October 2014 18:34, Yoann Padioleau <pad@fb.com> wrote:

> but (0:int + x)   would not do the same thing? What is special about using
> SUB instead
> of ADD?
>

you can't subtract pointers from 0 but you can add 0 to a pointer, since +
is commutative

[-- Attachment #2: Type: text/html, Size: 561 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-10-21 20:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-14 22:11 [9fans] copy paste bug in cc.y? Yoann Padioleau
2014-10-14 22:45 ` Rob Pike
2014-10-15  0:50   ` Rob Pike
2014-10-17 17:48     ` Yoann Padioleau
2014-10-17 19:07       ` Charles Forsyth
2014-10-17 20:00         ` Yoann Padioleau
2014-10-17 20:04           ` minux
2014-10-17 20:32             ` Yoann Padioleau
2014-10-21 17:34         ` Yoann Padioleau
2014-10-21 20:53           ` Charles Forsyth
2014-10-17 21:30       ` Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).