Appearance
| 1 | namespace Semantic.Symbols is | |
| 2 | use Types.Type | |
| 3 | ||
| 4 | // What a generated argument pack thunk does. A thunk stands between | |
| 5 | // the two shapes one pack has - a function of the pack's elements and | |
| 6 | // a function of the tuple they make - for a function value that has | |
| 7 | // one shape going where the other is wanted. It has no source: its | |
| 8 | // body is this description, and is emitted from it. | |
| 9 | // | |
| 10 | // The function it stands for is either `target`, called directly, or | |
| 11 | // the thunk's own first parameter, over which the thunk's delegate is | |
| 12 | // built closed. A pack marked past the function's own type is reached | |
| 13 | // through a chain: a thunk at `depth` above zero calls its function | |
| 14 | // with its parameters and returns the next thunk's delegate, built | |
| 15 | // closed over the result, and the thunk at depth zero is the one that | |
| 16 | // packs or unpacks. | |
| 17 | class PACK_THUNK is | |
| 18 | // Whether the thunk takes the tuple and calls a function of the | |
| 19 | // elements, rather than taking the elements and calling a | |
| 20 | // function of the tuple. | |
| 21 | is_unpack: bool | |
| 22 | ||
| 23 | // How many leading parameters are passed through as they are. | |
| 24 | fixed_count: int | |
| 25 | ||
| 26 | element_types: Collections.List[Type] | |
| 27 | ||
| 28 | // The type the function the thunk stands for is called at. | |
| 29 | callee_type: Type | |
| 30 | ||
| 31 | // A function the thunk calls by name: one that needs no receiver | |
| 32 | // and no type arguments, so there is nothing to close over. | |
| 33 | target: Function? | |
| 34 | ||
| 35 | // How many returns above the pack this thunk sits. | |
| 36 | depth: int | |
| 37 | ||
| 38 | // The thunk below this one and the type of the delegate built | |
| 39 | // over it, for a thunk above depth zero. | |
| 40 | inner: Closure? | |
| 41 | inner_presented: Type? | |
| 42 | ||
| 43 | init( | |
| 44 | is_unpack: bool, | |
| 45 | fixed_count: int, | |
| 46 | element_types: Collections.List[Type], | |
| 47 | callee_type: Type, | |
| 48 | target: Function? | |
| 49 | ) is | |
| 50 | self.is_unpack = is_unpack | |
| 51 | self.fixed_count = fixed_count | |
| 52 | self.element_types = element_types | |
| 53 | self.callee_type = callee_type | |
| 54 | self.target = target | |
| 55 | self.depth = 0 | |
| 56 | si | |
| 57 | ||
| 58 | // A thunk above the pack: calls its function with its parameters | |
| 59 | // and hands the result on to `inner`. | |
| 60 | chain(callee_type: Type, depth: int, inner: Closure, inner_presented: Type) -> PACK_THUNK static is | |
| 61 | let result = PACK_THUNK(true, 0, Collections.LIST[Type](0), callee_type, null) | |
| 62 | ||
| 63 | result.depth = depth | |
| 64 | result.inner = inner | |
| 65 | result.inner_presented = inner_presented | |
| 66 | ||
| 67 | return result | |
| 68 | si | |
| 69 | ||
| 70 | // Whether the function the thunk stands for is its first | |
| 71 | // parameter. | |
| 72 | takes_callee: bool => !target? | |
| 73 | si | |
| 74 | si |