Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Issue 9284022: Operators. (Closed)

Created:
8 years, 11 months ago by ngeoffray
Modified:
8 years, 11 months ago
CC:
reviews_dartlang.org, floitsch, karlklose, kasperl
Visibility:
Public.

Description

Implement support for user-defined operators. Committed: https://code.google.com/p/dart/source/detail?r=3646

Patch Set 1 : '' #

Total comments: 20

Patch Set 2 : '' #

Patch Set 3 : '' #

Patch Set 4 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+335 lines, -90 lines) Patch
M frog/leg/compiler.dart View 1 2 3 1 chunk +4 lines, -2 lines 0 comments Download
M frog/leg/elements/elements.dart View 1 2 3 2 chunks +34 lines, -1 line 0 comments Download
M frog/leg/emitter.dart View 1 2 3 1 chunk +2 lines, -1 line 0 comments Download
M frog/leg/lib/core.dart View 1 2 3 17 chunks +49 lines, -28 lines 0 comments Download
M frog/leg/namer.dart View 1 2 3 4 chunks +4 lines, -8 lines 0 comments Download
M frog/leg/resolver.dart View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M frog/leg/scanner/class_element_parser.dart View 1 2 3 1 chunk +7 lines, -4 lines 0 comments Download
M frog/leg/scanner/parser.dart View 1 2 3 3 chunks +7 lines, -3 lines 0 comments Download
M frog/leg/ssa/builder.dart View 1 2 3 7 chunks +76 lines, -37 lines 0 comments Download
M frog/tests/leg/src/ResolverTest.dart View 1 2 3 2 chunks +2 lines, -2 lines 0 comments Download
A frog/tests/leg_only/src/CompoundOperatorIndexTest.dart View 1 2 1 chunk +73 lines, -0 lines 0 comments Download
A frog/tests/leg_only/src/OperatorEqualsTest.dart View 1 chunk +25 lines, -0 lines 0 comments Download
M tests/language/language.status View 1 2 3 1 chunk +3 lines, -0 lines 0 comments Download
M tests/language/language-leg.status View 1 2 3 2 chunks +0 lines, -3 lines 0 comments Download
A tests/language/src/OperatorIndexEvaluationOrderTest.dart View 1 2 1 chunk +48 lines, -0 lines 0 comments Download

Messages

Total messages: 3 (0 generated)
ngeoffray
8 years, 11 months ago (2012-01-25 12:50:10 UTC) #1
Lasse Reichstein Nielsen
LGTM https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.dart File frog/leg/lib/core.dart (right): https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.dart#newcode116 frog/leg/lib/core.dart:116: if (JS("bool", @"$0.operator$eq$1", a)) { I recommend doing ...
8 years, 11 months ago (2012-01-27 09:42:34 UTC) #2
ngeoffray
8 years, 11 months ago (2012-01-27 10:50:04 UTC) #3
Thank you Lasse! And great test :)

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.dart
File frog/leg/lib/core.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.da...
frog/leg/lib/core.dart:116: if (JS("bool", @"$0.operator$eq$1", a)) {
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> I recommend doing the foreign PREOPRTY_CHECK macro now.
> Having a literal pre-mangled name is fragile.

As discussed, added a JS_HAS_EQUALS to avoid the mangled hardcoding.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.da...
frog/leg/lib/core.dart:132: if (JS("bool", @"$0.operator$eq$1", a)) {
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Ditto here.

Done.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/lib/core.da...
frog/leg/lib/core.dart:395: static void isTrue(var actual) {
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Add a TODO to add the optional message parameter when we support optional
> parameters.

Done.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/resolver.dart
File frog/leg/resolver.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/resolver.da...
frog/leg/resolver.dart:653: constructorName =
Elements.constructConstructorName(className, name);
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> You are mangling the name here, right?
> How about not mangling it until codegen?

No I'm not mangling it. I'm making it a single SourceString, because that's the
keys for our maps.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/scanner/par...
File frog/leg/scanner/parser.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/scanner/par...
frog/leg/scanner/parser.dart:571: } else if (isIdentifier(peek)) {
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> You could move the test for 'operator' to after the isIdentifier test here.

Code has changed since after Peter's recent changes on getset.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/ssa/builder...
File frog/leg/ssa/builder.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/ssa/builder...
frog/leg/ssa/builder.dart:1083: assert(op.source == const SourceString("="));
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Might as well do 
>   op.source.stringValue == "="
> (or even ===).

Done.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/ssa/builder...
frog/leg/ssa/builder.dart:1100: bool isPrefix = !node.isPostfix;  // Compound
assignments are prefix.
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> "are prefix." => "are considered as being prefix."
> They *are* infix.

Done.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/leg/ssa/builder...
frog/leg/ssa/builder.dart:1126: } else if (const SourceString("=") == op.source
&& !node.isIndex) {
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Change that to
>  assert(!node.isIndex);
> It can't happen with this being an else branch of an if with condition
> (node.isIndex).

You're right, that's a leftover from a previous implementation. Removed (and I
did not add an assert since the first if (node.isIndex) is quite trivial to
read).

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/tests/leg/src/R...
File frog/tests/leg/src/ResolverTest.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/tests/leg/src/R...
frog/tests/leg/src/ResolverTest.dart:520: resolveConstructor(script, "A a = new
A.a();", "A", "A\$a", 1,
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Consider using raw strings.

Done.

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/tests/leg_only/...
File frog/tests/leg_only/src/CompoundOperatorIndexTest.dart (right):

https://chromiumcodereview.appspot.com/9284022/diff/4008/frog/tests/leg_only/...
frog/tests/leg_only/src/CompoundOperatorIndexTest.dart:29: a[0] += 2;
On 2012/01/27 09:42:34, Lasse Reichstein Nielsen wrote:
> Try testing that the object and operand are only evaluated once, and that we
> only call the [] and []= operators once each, and in the correct order.
> 
> Something like:
> 
> List<int> trace = <int>[];
> class B {
>   int value = 100;
>   operator [](index) { 
>     trace.add(-3); 
>     trace.add(index); 
>     trace.add(this.value);
>     this.value = this.value + 1; 
>     return this; 
>   }
>   operator []=(index, value) { 
>     trace.add(-5);
>     trace.add(index);
>     trace.add(value.value);
>     this.value = this.value + 1;
>   }
>   operator +(int value) {
>     trace.add(-4);
>     trace.add(this.value);
>     trace.add(value);
>     this.value = this.value + 1;
>     return this;
>   }
> }
> 
> var b = new B();
> B getB() {
>   trace.add(-1);
>   return new B();
> }
> int getIndex() {
>   trace.add(-2);
>   return 42;
> }
> getB()[getIndex()] += 37;
> 
> and then check that trace is 
>  [-1, -2, -3, 42, 100, -4, 101, 37, -5, 42, 102]

Done, with some little tweaks :)

Powered by Google App Engine
This is Rietveld 408576698