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