|
| 1 | +#nullable enable |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | + |
| 7 | +namespace Python.Runtime |
| 8 | +{ |
| 9 | + public class TypeSpec |
| 10 | + { |
| 11 | + public TypeSpec(string name, int basicSize, IEnumerable<Slot> slots, TypeFlags flags, int itemSize = 0) |
| 12 | + { |
| 13 | + this.Name = name ?? throw new ArgumentNullException(nameof(name)); |
| 14 | + this.BasicSize = basicSize; |
| 15 | + this.Slots = slots.ToArray(); |
| 16 | + this.Flags = flags; |
| 17 | + this.ItemSize = itemSize; |
| 18 | + } |
| 19 | + public string Name { get; } |
| 20 | + public int BasicSize { get; } |
| 21 | + public int ItemSize { get; } |
| 22 | + public TypeFlags Flags { get; } |
| 23 | + public IReadOnlyList<Slot> Slots { get; } |
| 24 | + |
| 25 | + [StructLayout(LayoutKind.Sequential)] |
| 26 | + public struct Slot |
| 27 | + { |
| 28 | + public Slot(TypeSlotID id, IntPtr value) |
| 29 | + { |
| 30 | + ID = id; |
| 31 | + Value = value; |
| 32 | + } |
| 33 | + |
| 34 | + public TypeSlotID ID { get; } |
| 35 | + public IntPtr Value { get; } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public enum TypeSlotID : int |
| 40 | + { |
| 41 | + mp_ass_subscript = 3, |
| 42 | + mp_length = 4, |
| 43 | + mp_subscript = 5, |
| 44 | + nb_absolute = 6, |
| 45 | + nb_add = 7, |
| 46 | + nb_and = 8, |
| 47 | + nb_bool = 9, |
| 48 | + nb_divmod = 10, |
| 49 | + nb_float = 11, |
| 50 | + nb_floor_divide = 12, |
| 51 | + nb_index = 13, |
| 52 | + nb_inplace_add = 14, |
| 53 | + nb_inplace_and = 15, |
| 54 | + nb_inplace_floor_divide = 16, |
| 55 | + nb_inplace_lshift = 17, |
| 56 | + nb_inplace_multiply = 18, |
| 57 | + nb_inplace_or = 19, |
| 58 | + nb_inplace_power = 20, |
| 59 | + nb_inplace_remainder = 21, |
| 60 | + nb_inplace_rshift = 22, |
| 61 | + nb_inplace_subtract = 23, |
| 62 | + nb_inplace_true_divide = 24, |
| 63 | + nb_inplace_xor = 25, |
| 64 | + nb_int = 26, |
| 65 | + nb_invert = 27, |
| 66 | + nb_lshift = 28, |
| 67 | + nb_multiply = 29, |
| 68 | + nb_negative = 30, |
| 69 | + nb_or = 31, |
| 70 | + nb_positive = 32, |
| 71 | + nb_power = 33, |
| 72 | + nb_remainder = 34, |
| 73 | + nb_rshift = 35, |
| 74 | + nb_subtract = 36, |
| 75 | + nb_true_divide = 37, |
| 76 | + nb_xor = 38, |
| 77 | + sq_ass_item = 39, |
| 78 | + sq_concat = 40, |
| 79 | + sq_contains = 41, |
| 80 | + sq_inplace_concat = 42, |
| 81 | + sq_inplace_repeat = 43, |
| 82 | + sq_item = 44, |
| 83 | + sq_length = 45, |
| 84 | + sq_repeat = 46, |
| 85 | + tp_alloc = 47, |
| 86 | + tp_base = 48, |
| 87 | + tp_bases = 49, |
| 88 | + tp_call = 50, |
| 89 | + tp_clear = 51, |
| 90 | + tp_dealloc = 52, |
| 91 | + tp_del = 53, |
| 92 | + tp_descr_get = 54, |
| 93 | + tp_descr_set = 55, |
| 94 | + tp_doc = 56, |
| 95 | + tp_getattr = 57, |
| 96 | + tp_getattro = 58, |
| 97 | + tp_hash = 59, |
| 98 | + tp_init = 60, |
| 99 | + tp_is_gc = 61, |
| 100 | + tp_iter = 62, |
| 101 | + tp_iternext = 63, |
| 102 | + tp_methods = 64, |
| 103 | + tp_new = 65, |
| 104 | + tp_repr = 66, |
| 105 | + tp_richcompare = 67, |
| 106 | + tp_setattr = 68, |
| 107 | + tp_setattro = 69, |
| 108 | + tp_str = 70, |
| 109 | + tp_traverse = 71, |
| 110 | + tp_members = 72, |
| 111 | + tp_getset = 73, |
| 112 | + tp_free = 74, |
| 113 | + nb_matrix_multiply = 75, |
| 114 | + nb_inplace_matrix_multiply = 76, |
| 115 | + am_await = 77, |
| 116 | + am_aiter = 78, |
| 117 | + am_anext = 79, |
| 118 | + /// <remarks>New in 3.5</remarks> |
| 119 | + tp_finalize = 80, |
| 120 | + } |
| 121 | +} |
0 commit comments