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

Side by Side Diff: pkg/fletchc/lib/src/fletch_selector.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
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.md file.
4
5 library fletchc.fletch_selector;
6
7 enum SelectorKind {
8 Method,
9 Getter,
10 Setter,
11 }
12
13 class FletchSelector {
14 final int encodedSelector;
15
16 const FletchSelector(this.encodedSelector);
17
18 int get id => decodeId(encodedSelector);
19
20 SelectorKind get kind => SelectorKind.values[encodedSelector >> 8 & 3];
21
22 int get arity => encodedSelector & 255;
23
24 static const MAX_ARITY = (1 << 8) - 1;
25 static const MAX_UNIQUE_SELECTORS = (1 << 22) - 1;
26 static const ID_SHIFT = 10;
27
28 // Encode a fletch selector. The result is a 32bit integer with the following
29 // layout (lower to higher):
30 // - 8 bit arity
31 // - 2 bit kind
32 // - 22 bit id
33 static int encode(int id, SelectorKind kind, int arity) {
34 if (arity > MAX_ARITY) throw "Only arity up to 255 is supported";
35 if (id > MAX_UNIQUE_SELECTORS) {
36 throw "Only ${MAX_UNIQUE_SELECTORS + 1} unique identifiers is supported";
37 }
38 return arity | (kind.index << 8) | (id << ID_SHIFT);
39 }
40
41 static int encodeMethod(int id, int arity) {
42 return encode(id, SelectorKind.Method, arity);
43 }
44
45 static int encodeGetter(int id) => encode(id, SelectorKind.Getter, 0);
46
47 static int encodeSetter(int id) => encode(id, SelectorKind.Setter, 1);
48
49 static int decodeId(int selector) => selector >> ID_SHIFT;
50 }
OLDNEW
« no previous file with comments | « pkg/fletchc/lib/src/fletch_registry.dart ('k') | pkg/fletchc/lib/src/fletch_system_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698