Change numpy.int16 to numpy.uint16 and flex_int16_t to flex_uint16_t everywhere
authorNick Downing <downing.nick@gmail.com>
Mon, 23 Jul 2018 08:50:03 +0000 (18:50 +1000)
committerNick Downing <downing.nick@gmail.com>
Mon, 23 Jul 2018 08:50:03 +0000 (18:50 +1000)
flex_dfa.py

index 7ce9a35..3af9641 100644 (file)
@@ -67,9 +67,9 @@ class FlexDFA:
     eob_state = len(_dfa.start_action)
 
     # state 0 is the jam state, make it exist but have empty acclist
-    self.acclist = numpy.zeros((0x100,), numpy.int16)
+    self.acclist = numpy.zeros((0x100,), numpy.uint16)
     n_acclist = 0
-    self.accept = numpy.zeros((0x100,), numpy.int16)
+    self.accept = numpy.zeros((0x100,), numpy.uint16)
     n_states = 1
 
     # transitions[i, j] is transition on character j in state i
@@ -77,7 +77,7 @@ class FlexDFA:
     # however, in the flex way these are both 0 (don't care),
     # the distinction being that failure has no associated action
     # thus all entries of states are filled, with 0 as a catch-all
-    transitions = numpy.zeros((0x100, 0x101), numpy.int16)
+    transitions = numpy.zeros((0x100, 0x101), numpy.uint16)
 
     # generate acclist, accept and transition tables
     while n_states < len(flex_state_to_action):
@@ -92,7 +92,7 @@ class FlexDFA:
         # extend accept
         new_accept = numpy.zeros(
           (self.accept.shape[0] * 2,),
-          numpy.int16
+          numpy.uint16
         )
         new_accept[:self.accept.shape[0]] = self.accept
         self.accept = new_accept
@@ -114,7 +114,7 @@ class FlexDFA:
           # extend acclist
           new_acclist = numpy.zeros(
             (self.acclist.shape[0] * 2,),
-            numpy.int16
+            numpy.uint16
           )
           new_acclist[:self.acclist.shape[0]] = self.acclist
           self.acclist = new_acclist
@@ -126,7 +126,7 @@ class FlexDFA:
         # extend transitions
         new_transitions = numpy.zeros(
           (transitions.shape[0] * 2, 0x101),
-          numpy.int16
+          numpy.uint16
         )
         new_transitions[:transitions.shape[0], :] = transitions
         transitions = new_transitions
@@ -152,7 +152,7 @@ class FlexDFA:
     if n_states >= self.accept.shape[0]:
       new_accept = numpy.zeros(
         (self.accept.shape[0] * 2,),
-        numpy.int16
+        numpy.uint16
       )
       new_accept[:self.accept.shape[0]] = self.accept
       self.accept = new_accept
@@ -167,9 +167,9 @@ class FlexDFA:
     # calculate default states by constructing minimum spanning tree
     # heap contains n states todo followed by n_states - n states done
     # each heap entry is [distance, hop count, state done, state todo]
-    heap = numpy.zeros((n_states, 4), numpy.int16)
+    heap = numpy.zeros((n_states, 4), numpy.uint16)
     heap[:-1, 0] = numpy.sum(transitions[1:, :] != transitions[:1, :], 1)
-    heap[:-1, 3] = numpy.arange(1, n_states, dtype = numpy.int16)
+    heap[:-1, 3] = numpy.arange(1, n_states, dtype = numpy.uint16)
     numpy_heap.heapify(heap, n_states - 1)
     for n in range(n_states - 2, 0, -1):
       if n % 100 == 0:
@@ -193,8 +193,8 @@ class FlexDFA:
           numpy_heap.bubble_up(heap, i, key)
 
     # state 0 is the jam state, the EOB state will be added later on
-    self.states = numpy.zeros((n_states, 2), numpy.int16) # base, def
-    self.entries = numpy.full((0x200, 2), -1, numpy.int16) # nxt, chk
+    self.states = numpy.zeros((n_states, 2), numpy.uint16) # base, def
+    self.entries = numpy.full((0x200, 2), -1, numpy.uint16) # nxt, chk
     self.entries[:0x101, :] = 0 # jam state just returns to jam state
     self.entries[0, 0] = eob_state # except for the EOB transition
     entries_free = numpy.full(0x200, True, numpy.bool)
@@ -225,7 +225,7 @@ class FlexDFA:
           new_entries = numpy.full(
             (self.entries.shape[0] * 2, 2),
             -1,
-            numpy.int16
+            numpy.uint16
           )
           new_entries[:n_entries, :] = self.entries[:n_entries, :]
           self.entries = new_entries
@@ -302,17 +302,17 @@ def generate(plex, skel_file, out_file):
           fout.write(
             '''/* GENERATE TABLES BEGIN */
 #define YY_END_OF_BUFFER {0:d}
-static const flex_int16_t yy_acclist[] = {{{1:s}
+static const flex_uint16_t yy_acclist[] = {{{1:s}
 }};
-static const flex_int16_t yy_accept[] = {{{2:s}
+static const flex_uint16_t yy_accept[] = {{{2:s}
 }};
-static const flex_int16_t yy_base[] = {{{3:s}
+static const flex_uint16_t yy_base[] = {{{3:s}
 }};
-static const flex_int16_t yy_def[] = {{{4:s}
+static const flex_uint16_t yy_def[] = {{{4:s}
 }};
-static const flex_int16_t yy_nxt[] = {{{5:s}
+static const flex_uint16_t yy_nxt[] = {{{5:s}
 }};
-static const flex_int16_t yy_chk[] = {{{6:s}
+static const flex_uint16_t yy_chk[] = {{{6:s}
 }};
 /* GENERATE TABLES END */
 '''.format(