OLD | NEW |
| (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 file. | |
4 | |
5 library immic.primitives; | |
6 | |
7 enum PrimitiveType { | |
8 VOID, | |
9 BOOL, | |
10 | |
11 UINT8, | |
12 UINT16, | |
13 | |
14 INT8, | |
15 INT16, | |
16 INT32, | |
17 INT64, | |
18 | |
19 FLOAT32, | |
20 FLOAT64 | |
21 } | |
22 | |
23 int size(PrimitiveType type) { | |
24 switch (type) { | |
25 case PrimitiveType.VOID: return 0; | |
26 | |
27 case PrimitiveType.BOOL: | |
28 case PrimitiveType.INT8: | |
29 case PrimitiveType.UINT8: return 1; | |
30 | |
31 case PrimitiveType.INT16: | |
32 case PrimitiveType.UINT16: return 2; | |
33 | |
34 case PrimitiveType.FLOAT32: | |
35 case PrimitiveType.INT32: return 4; | |
36 | |
37 case PrimitiveType.FLOAT64: | |
38 case PrimitiveType.INT64: return 8; | |
39 } | |
40 return -1; | |
41 } | |
42 | |
43 PrimitiveType lookup(String identifier) { | |
44 Map<String, PrimitiveType> types = const { | |
45 'void' : PrimitiveType.VOID, | |
46 'bool' : PrimitiveType.BOOL, | |
47 | |
48 'uint8' : PrimitiveType.UINT8, | |
49 'uint16' : PrimitiveType.UINT16, | |
50 | |
51 'int8' : PrimitiveType.INT8, | |
52 'int16' : PrimitiveType.INT16, | |
53 'int32' : PrimitiveType.INT32, | |
54 'int64' : PrimitiveType.INT64, | |
55 | |
56 'float32' : PrimitiveType.FLOAT32, | |
57 'float64' : PrimitiveType.FLOAT64, | |
58 }; | |
59 return types[identifier]; | |
60 } | |
OLD | NEW |