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

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 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 inputs.add(closureTarget); 1844 inputs.add(closureTarget);
1845 addDynamicSendArgumentsToList(node, inputs); 1845 addDynamicSendArgumentsToList(node, inputs);
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 if (link.isEmpty() || link.isEmpty()) {
1855 compiler.cancel('At least two arguments expected', node: node.arguments);
1856 }
1854 link = link.tail.tail; 1857 link = link.tail.tail;
1855 List<HInstruction> inputs = <HInstruction>[]; 1858 List<HInstruction> inputs = <HInstruction>[];
1856 addGenericSendArgumentsToList(link, inputs); 1859 addGenericSendArgumentsToList(link, inputs);
1857 LiteralString type = node.arguments.head; 1860 Node type = node.arguments.head;
1858 LiteralString literal = node.arguments.tail.head; 1861 Node literal = node.arguments.tail.head;
1859 compiler.ensure(literal is LiteralString); 1862 if (literal is !StringNode || literal.dynamic.isInterpolation) {
1860 compiler.ensure(type is LiteralString); 1863 compiler.cancel('JS code must be a string literal', node: literal);
1861 push(new HForeign(literal.dartString, type.dartString, inputs)); 1864 }
1865 if (type is !LiteralString) {
1866 compiler.cancel(
1867 'The type of a JS expression must be a string literal', node: type);
1868 }
1869 push(new HForeign(
1870 literal.dynamic.dartString, type.dynamic.dartString, inputs));
1862 } 1871 }
1863 1872
1864 void handleForeignUnintercepted(Send node) { 1873 void handleForeignUnintercepted(Send node) {
1865 Link<Node> link = node.arguments; 1874 Link<Node> link = node.arguments;
1866 if (!link.tail.isEmpty()) { 1875 if (!link.tail.isEmpty()) {
1867 compiler.cancel( 1876 compiler.cancel(
1868 'More than one expression in UNINTERCEPTED()', node: node); 1877 'More than one expression in UNINTERCEPTED()', node: node);
1869 } 1878 }
1870 Expression expression = link.head; 1879 Expression expression = link.head;
1871 disableMethodInterception(); 1880 disableMethodInterception();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 'Isolate library and compiler mismatch', node: node); 1943 'Isolate library and compiler mismatch', node: node);
1935 } 1944 }
1936 HStatic target = new HStatic(element); 1945 HStatic target = new HStatic(element);
1937 add(target); 1946 add(target);
1938 List<HInstruction> inputs = <HInstruction>[target]; 1947 List<HInstruction> inputs = <HInstruction>[target];
1939 addGenericSendArgumentsToList(link, inputs); 1948 addGenericSendArgumentsToList(link, inputs);
1940 push(new HInvokeStatic(Selector.INVOCATION_0, inputs)); 1949 push(new HInvokeStatic(Selector.INVOCATION_0, inputs));
1941 } 1950 }
1942 } 1951 }
1943 1952
1953 void handleForeignDartClosureToJs(Send node) {
1954 if (node.arguments.isEmpty() || !node.arguments.tail.isEmpty()) {
1955 compiler.cancel('Exactly one argument required', node: node.arguments);
1956 }
1957 Node closure = node.arguments.head;
1958 Element element = elements[closure];
1959 if (!Elements.isStaticOrTopLevelFunction(element)) {
1960 compiler.cancel(
1961 'JS_TO_CLOSURE requires a static or top-level method',
1962 node: closure);
1963 }
1964 FunctionElement function = element;
1965 FunctionParameters parameters = element.computeParameters(compiler);
1966 if (parameters.optionalParameterCount !== 0) {
1967 compiler.cancel(
1968 'JS_TO_CLOSURE does not handle closure with optional parameters',
1969 node: closure);
1970 }
1971 visit(closure);
1972 List<HInstruction> inputs = <HInstruction>[pop()];
1973 String invocationName = compiler.namer.closureInvocationName(
1974 new Selector(SelectorKind.INVOCATION,
1975 parameters.requiredParameterCount));
1976 push(new HForeign(new SourceString('#.$invocationName'),
1977 const SourceString('var'),
1978 inputs));
1979 }
1980
1944 handleForeignSend(Send node) { 1981 handleForeignSend(Send node) {
1945 Element element = elements[node]; 1982 Element element = elements[node];
1946 if (element === compiler.findHelper(const SourceString('JS'))) { 1983 if (element.name == const SourceString('JS')) {
1947 handleForeignJs(node); 1984 handleForeignJs(node);
1948 } else if (element === compiler.findHelper( 1985 } else if (element.name == const SourceString('UNINTERCEPTED')) {
1949 const SourceString('UNINTERCEPTED'))) {
1950 handleForeignUnintercepted(node); 1986 handleForeignUnintercepted(node);
1951 } else if (element === compiler.findHelper( 1987 } else if (element.name == const SourceString('JS_HAS_EQUALS')) {
1952 const SourceString('JS_HAS_EQUALS'))) {
1953 handleForeignJsHasEquals(node); 1988 handleForeignJsHasEquals(node);
1954 } else if (element === compiler.findHelper( 1989 } else if (element.name == const SourceString('JS_CURRENT_ISOLATE')) {
1955 const SourceString('JS_CURRENT_ISOLATE'))) {
1956 handleForeignJsCurrentIsolate(node); 1990 handleForeignJsCurrentIsolate(node);
1957 } else if (element === compiler.findHelper( 1991 } else if (element.name == const SourceString('JS_CALL_IN_ISOLATE')) {
1958 const SourceString('JS_CALL_IN_ISOLATE'))) {
1959 handleForeignJsCallInIsolate(node); 1992 handleForeignJsCallInIsolate(node);
1960 } else if (element === currentLibrary.find(const SourceString('native'))) { 1993 } else if (element.name == const SourceString('DART_CLOSURE_TO_JS')) {
1994 handleForeignDartClosureToJs(node);
1995 } else if (element.name == const SourceString('native')) {
1961 native.handleSsaNative(this, node); 1996 native.handleSsaNative(this, node);
1962 } else { 1997 } else {
1963 throw "Unknown foreign: ${node.selector}"; 1998 throw "Unknown foreign: ${node.selector}";
1964 } 1999 }
1965 } 2000 }
1966 2001
1967 visitSuperSend(Send node) { 2002 visitSuperSend(Send node) {
1968 Selector selector = elements.getSelector(node); 2003 Selector selector = elements.getSelector(node);
1969 Element element = elements[node]; 2004 Element element = elements[node];
1970 if (element === null) { 2005 if (element === null) {
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 false, 2963 false,
2929 <HInstruction>[target, input])); 2964 <HInstruction>[target, input]));
2930 return builder.pop(); 2965 return builder.pop();
2931 } 2966 }
2932 2967
2933 HInstruction result() { 2968 HInstruction result() {
2934 flushLiterals(); 2969 flushLiterals();
2935 return prefix; 2970 return prefix;
2936 } 2971 }
2937 } 2972 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698