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

Side by Side Diff: frog/leg/ssa/builder.dart

Issue 9750003: Write our JS blobs for handling native classes in Dart. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 push(new HInvokeClosure(selector, inputs)); 1846 push(new HInvokeClosure(selector, inputs));
1847 } 1847 }
1848 1848
1849 void handleForeignJs(Send node) { 1849 void handleForeignJs(Send node) {
1850 Link<Node> link = node.arguments; 1850 Link<Node> link = node.arguments;
1851 // If the invoke is on foreign code, don't visit the first 1851 // If the invoke is on foreign code, don't visit the first
1852 // argument, which is the type, and the second argument, 1852 // argument, which is the type, and the second argument,
1853 // which is the foreign code. 1853 // which is the foreign code.
1854 link = link.tail.tail; 1854 link = link.tail.tail;
1855 List<HInstruction> inputs = <HInstruction>[]; 1855 List<HInstruction> inputs = <HInstruction>[];
1856 addGenericSendArgumentsToList(link, inputs); 1856 addGenericSendArgumentsToList(link, inputs);
ahe 2012/03/26 13:43:45 if (node.arguments.isEmpty() || node.arguments.tai
ngeoffray 2012/03/26 13:55:32 Done.
1857 LiteralString type = node.arguments.head; 1857 Node type = node.arguments.head;
1858 LiteralString literal = node.arguments.tail.head; 1858 Node literal = node.arguments.tail.head;
1859 compiler.ensure(literal is LiteralString); 1859 if (literal is !StringNode || literal.dynamic.isInterpolation) {
1860 compiler.ensure(type is LiteralString); 1860 compiler.cancel('JS code must be a string literal', node: literal);
1861 push(new HForeign(literal.dartString, type.dartString, inputs)); 1861 }
1862 if (type is !LiteralString) {
1863 compiler.cancel(
1864 'The type of a JS expression must be a string literal', node: type);
1865 }
1866 push(new HForeign(
1867 literal.dynamic.dartString, type.dynamic.dartString, inputs));
1862 } 1868 }
1863 1869
1864 void handleForeignUnintercepted(Send node) { 1870 void handleForeignUnintercepted(Send node) {
1865 Link<Node> link = node.arguments; 1871 Link<Node> link = node.arguments;
1866 if (!link.tail.isEmpty()) { 1872 if (!link.tail.isEmpty()) {
1867 compiler.cancel( 1873 compiler.cancel(
1868 'More than one expression in UNINTERCEPTED()', node: node); 1874 'More than one expression in UNINTERCEPTED()', node: node);
1869 } 1875 }
1870 Expression expression = link.head; 1876 Expression expression = link.head;
1871 disableMethodInterception(); 1877 disableMethodInterception();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 'Isolate library and compiler mismatch', node: node); 1940 'Isolate library and compiler mismatch', node: node);
1935 } 1941 }
1936 HStatic target = new HStatic(element); 1942 HStatic target = new HStatic(element);
1937 add(target); 1943 add(target);
1938 List<HInstruction> inputs = <HInstruction>[target]; 1944 List<HInstruction> inputs = <HInstruction>[target];
1939 addGenericSendArgumentsToList(link, inputs); 1945 addGenericSendArgumentsToList(link, inputs);
1940 push(new HInvokeStatic(Selector.INVOCATION_0, inputs)); 1946 push(new HInvokeStatic(Selector.INVOCATION_0, inputs));
1941 } 1947 }
1942 } 1948 }
1943 1949
1950 void handleForeignJsToClosure(Send node) {
1951 Node closure = node.arguments.head;
1952 if (!node.arguments.tail.isEmpty()) {
ahe 2012/03/26 13:43:45 See above. You should probably test for node.argu
ngeoffray 2012/03/26 13:55:32 Done.
1953 compiler.cancel(
1954 'Invalid number of arguments in JS_TO_CLOSURE',
ahe 2012/03/26 13:43:45 'exactly one argument required'
ngeoffray 2012/03/26 13:55:32 Done.
1955 node: node);
ahe 2012/03/26 13:43:45 node: node.arguments
ngeoffray 2012/03/26 13:55:32 Done.
1956 }
1957 Element element = elements[closure];
1958 if (!Elements.isStaticOrTopLevelFunction(element)) {
1959 compiler.cancel(
1960 'JS_TO_CLOSURE requires a static or top-level method',
1961 node: closure);
1962 }
1963 FunctionElement function = element;
1964 FunctionParameters parameters = element.computeParameters(compiler);
1965 if (parameters.optionalParameterCount !== 0) {
1966 compiler.cancel(
1967 'JS_TO_CLOSURE does not handle closure with optional parameters',
1968 node: closure);
1969 }
1970 visit(closure);
1971 List<HInstruction> inputs = <HInstruction>[pop()];
1972 String invocationName = compiler.namer.closureInvocationName(
1973 new Selector(SelectorKind.INVOCATION,
1974 parameters.requiredParameterCount));
1975 push(new HForeign(new SourceString('#.$invocationName'),
1976 const SourceString('var'),
1977 inputs));
1978 }
1979
1944 handleForeignSend(Send node) { 1980 handleForeignSend(Send node) {
1945 Element element = elements[node]; 1981 Element element = elements[node];
1946 if (element === compiler.findHelper(const SourceString('JS'))) { 1982 if (element === compiler.findHelper(const SourceString('JS'))) {
ahe 2012/03/26 13:43:45 This is weird, I think. Wouldn't this be simpler:
ngeoffray 2012/03/26 13:55:32 Yes, but I thought we agreed on comparing elements
ahe 2012/03/26 14:01:23 In general yes, however, this is going too far in
ngeoffray 2012/03/26 14:13:44 No that's ok (a foreign element can only be create
1947 handleForeignJs(node); 1983 handleForeignJs(node);
1948 } else if (element === compiler.findHelper( 1984 } else if (element === compiler.findHelper(
1949 const SourceString('UNINTERCEPTED'))) { 1985 const SourceString('UNINTERCEPTED'))) {
1950 handleForeignUnintercepted(node); 1986 handleForeignUnintercepted(node);
1951 } else if (element === compiler.findHelper( 1987 } else if (element === compiler.findHelper(
1952 const SourceString('JS_HAS_EQUALS'))) { 1988 const SourceString('JS_HAS_EQUALS'))) {
1953 handleForeignJsHasEquals(node); 1989 handleForeignJsHasEquals(node);
1954 } else if (element === compiler.findHelper( 1990 } else if (element === compiler.findHelper(
1955 const SourceString('JS_CURRENT_ISOLATE'))) { 1991 const SourceString('JS_CURRENT_ISOLATE'))) {
1956 handleForeignJsCurrentIsolate(node); 1992 handleForeignJsCurrentIsolate(node);
1957 } else if (element === compiler.findHelper( 1993 } else if (element === compiler.findHelper(
1958 const SourceString('JS_CALL_IN_ISOLATE'))) { 1994 const SourceString('JS_CALL_IN_ISOLATE'))) {
1959 handleForeignJsCallInIsolate(node); 1995 handleForeignJsCallInIsolate(node);
1996 } else if (element === compiler.findHelper(
1997 const SourceString('JS_TO_CLOSURE'))) {
1998 handleForeignJsToClosure(node);
1960 } else if (element === currentLibrary.find(const SourceString('native'))) { 1999 } else if (element === currentLibrary.find(const SourceString('native'))) {
1961 native.handleSsaNative(this, node); 2000 native.handleSsaNative(this, node);
1962 } else { 2001 } else {
1963 throw "Unknown foreign: ${node.selector}"; 2002 throw "Unknown foreign: ${node.selector}";
1964 } 2003 }
1965 } 2004 }
1966 2005
1967 visitSuperSend(Send node) { 2006 visitSuperSend(Send node) {
1968 Selector selector = elements.getSelector(node); 2007 Selector selector = elements.getSelector(node);
1969 Element element = elements[node]; 2008 Element element = elements[node];
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 false, 2967 false,
2929 <HInstruction>[target, input])); 2968 <HInstruction>[target, input]));
2930 return builder.pop(); 2969 return builder.pop();
2931 } 2970 }
2932 2971
2933 HInstruction result() { 2972 HInstruction result() {
2934 flushLiterals(); 2973 flushLiterals();
2935 return prefix; 2974 return prefix;
2936 } 2975 }
2937 } 2976 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698