| OLD | NEW |
| 1 Sky Script Language | 1 Sky Script Language |
| 2 =================== | 2 =================== |
| 3 | 3 |
| 4 The Sky script language is Dart. | 4 The Sky script language is Dart. |
| 5 | 5 |
| 6 The way that Sky integrates the module system with its script language | 6 The way that Sky integrates the module system with its script language |
| 7 is described in [modules.md](modules.md). | 7 is described in [modules.md](modules.md). |
| 8 | 8 |
| 9 All the APIs defined in this documentation, unless explicitly called | 9 All the APIs defined in this documentation, unless explicitly called |
| 10 out as being in a framework, are in the `dart:sky` built-in module. | 10 out as being in a framework, are in the `dart:sky` built-in module. |
| 11 | 11 |
| 12 When a method in `dart:sky` defined as ``external`` receives an | 12 When a method in `dart:sky` defined as ``external`` receives an |
| 13 argument, it must type-check it, and, if the argument's value is the | 13 argument, it must type-check it, and, if the argument's value is the |
| 14 wrong type, then it must throw an ArgumentError as follows: | 14 wrong type, then it must throw an ArgumentError as follows: |
| 15 | 15 |
| 16 throw new ArgumentError(value, name: name); | 16 throw new ArgumentError(value, name: name); |
| 17 | 17 |
| 18 ...where "name" is the name of the argument. Type checking here | 18 ...where "name" is the name of the argument. Type checking here |
| 19 includes rejecting nulls unless otherwise indicated or unless null is | 19 includes rejecting nulls unless otherwise indicated or unless null is |
| 20 argument's default value. | 20 argument's default value. |
| 21 | 21 |
| 22 The following definitions are exposed in ``dart:sky``: | 22 The following definitions are exposed in ``dart:sky``: |
| 23 | 23 |
| 24 ```dart | 24 ```dart |
| 25 import 'dart:mirrors'; | 25 import 'dart:mirrors'; |
| 26 | 26 |
| 27 abstract class AutomaticMetadata { | 27 abstract class AutomaticMetadata { |
| 28 const AutomaticMetadata(); | 28 const AutomaticMetadata(); |
| 29 void init(DeclarationMirror target, Module module); | 29 void init(DeclarationMirror target, Module module, ScriptElement script); |
| 30 | 30 |
| 31 static void runLibrary(LibraryMirror library, Module module) { | 31 static void runLibrary(LibraryMirror library, Module module, ScriptElement scr
ipt) { |
| 32 library.declarations.values.toList() /* ..sort((DeclarationMirror a, Declara
tionMirror b) { | 32 library.declarations.values.toList() /* ..sort((DeclarationMirror a, Declara
tionMirror b) { |
| 33 bool aHasLocation; | 33 bool aHasLocation; |
| 34 try { | 34 try { |
| 35 aHasLocation = a.location != null; | 35 aHasLocation = a.location != null; |
| 36 } catch(e) { | 36 } catch(e) { |
| 37 aHasLocation = false; | 37 aHasLocation = false; |
| 38 } | 38 } |
| 39 bool bHasLocation; | 39 bool bHasLocation; |
| 40 try { | 40 try { |
| 41 bHasLocation = b.location != null; | 41 bHasLocation = b.location != null; |
| 42 } catch(e) { | 42 } catch(e) { |
| 43 bHasLocation = false; | 43 bHasLocation = false; |
| 44 } | 44 } |
| 45 if (!aHasLocation) | 45 if (!aHasLocation) |
| 46 return bHasLocation ? 1 : 0; | 46 return bHasLocation ? 1 : 0; |
| 47 if (!bHasLocation) | 47 if (!bHasLocation) |
| 48 return -1; | 48 return -1; |
| 49 if (a.location.sourceUri != b.location.sourceUri) | 49 if (a.location.sourceUri != b.location.sourceUri) |
| 50 return a.location.sourceUri.toString().compareTo(b.location.sourceUri.to
String()); | 50 return a.location.sourceUri.toString().compareTo(b.location.sourceUri.to
String()); |
| 51 if (a.location.line != b.location.line) | 51 if (a.location.line != b.location.line) |
| 52 return a.location.line - b.location.line; | 52 return a.location.line - b.location.line; |
| 53 return a.location.column - b.location.column; | 53 return a.location.column - b.location.column; |
| 54 }) */ | 54 }) */ |
| 55 ..forEach((DeclarationMirror d) { | 55 ..forEach((DeclarationMirror d) { |
| 56 d.metadata.forEach((InstanceMirror i) { | 56 d.metadata.forEach((InstanceMirror i) { |
| 57 if (i.reflectee is AutomaticMetadata) | 57 if (i.reflectee is AutomaticMetadata) |
| 58 i.reflectee.run(d, module); | 58 i.reflectee.run(d, module, script); |
| 59 }); | 59 }); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 class AutomaticFunction extends AutomaticMetadata { | 64 class AutomaticFunction extends AutomaticMetadata { |
| 65 const AutomaticFunction(); | 65 const AutomaticFunction(); |
| 66 void init(DeclarationMirror target, Module module) { | 66 void init(DeclarationMirror target, Module module, ScriptElement script) { |
| 67 assert(target is MethodMirror); | 67 assert(target is MethodMirror); |
| 68 MethodMirror f = target as MethodMirror; | 68 MethodMirror f = target as MethodMirror; |
| 69 assert(!f.isAbstract); | 69 assert(!f.isAbstract); |
| 70 assert(f.isRegularMethod); | 70 assert(f.isRegularMethod); |
| 71 assert(f.isTopLevel); | 71 assert(f.isTopLevel); |
| 72 assert(f.isStatic); | 72 assert(f.isStatic); |
| 73 assert(f.parameters.length == 0); | 73 assert(f.parameters.length == 1); |
| 74 assert(f.parameters[0].type == ScriptElement); |
| 74 assert(f.returnType == currentMirrorSystem().voidType); | 75 assert(f.returnType == currentMirrorSystem().voidType); |
| 75 (f.owner as LibraryMirror).invoke(f.simpleName, []); | 76 (f.owner as LibraryMirror).invoke(f.simpleName, [script]); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 const autorun = const AutomaticFunction(); | 79 const autorun = const AutomaticFunction(); |
| 79 ``` | 80 ``` |
| 80 | 81 |
| 81 Extensions | 82 Extensions |
| 82 ---------- | 83 ---------- |
| 83 | 84 |
| 84 The following as-yet unimplemented features of the Dart language are | 85 The following as-yet unimplemented features of the Dart language are |
| 85 assumed to exist: | 86 assumed to exist: |
| 86 | 87 |
| 87 * It is assumed that a subclass can define a constructor by reference | 88 * It is assumed that a subclass can define a constructor by reference |
| 88 to a superclass' constructor, wherein the subclass' constructor has | 89 to a superclass' constructor, wherein the subclass' constructor has |
| 89 the same arguments as the superclass' constructor and does nothing | 90 the same arguments as the superclass' constructor and does nothing |
| 90 but invoke that superclass' constructor with the same arguments. The | 91 but invoke that superclass' constructor with the same arguments. The |
| 91 syntax for defining this is, within the class body for a class | 92 syntax for defining this is, within the class body for a class |
| 92 called ClassName: | 93 called ClassName: |
| 93 | 94 |
| 94 ```dart | 95 ```dart |
| 95 ClassName = SuperclassName; | 96 ClassName = SuperclassName; |
| 96 ClassName.namedConstructor = SuperclassName.otherNamedConstructor; | 97 ClassName.namedConstructor = SuperclassName.otherNamedConstructor; |
| 97 ``` | 98 ``` |
| 98 | 99 |
| 99 * The reflection APIs (`dart:mirrors`) are assumed to reflect a | 100 * The reflection APIs (`dart:mirrors`) are assumed to reflect a |
| 100 library's declarations in source order. | 101 library's declarations in source order. |
| OLD | NEW |