7f4ac7d27e
In CPS, closure variables are modeled as ref cells. In tree, variables are in scope within inner functions and closure variables are handled directly. In Dart, a function must be declared if it has a return type or is recursive. Therefore tree now has both FunctionExpression and FunctionDeclaration, the latter is mainly to be used for functions that cannot occur in expression context. The CPS also has two ways of creating functions, CreateFunction and DeclareFunction, but here the latter is only strictly necessary for recursive function. The CL also contains quite a bit of other code improvements that came along. BUG= R=kmillikin@google.com, sigurdm@google.com Review URL: https://codereview.chromium.org//366853007 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38005 260f80e4-7a28-3924-810f-c04153c831b5
21 lines
481 B
Dart
21 lines
481 B
Dart
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
// The intermediate variable 'y' must either be preserved
|
|
// or parameters must be renamed.
|
|
|
|
foo(x) {
|
|
var y = x;
|
|
bar(x) {
|
|
return y - x;
|
|
}
|
|
return bar;
|
|
}
|
|
|
|
main() {
|
|
Expect.equals(-10, foo(10)(20));
|
|
}
|