Revision: 18796
Author: [email protected]
Date: Thu Jan 23 18:54:00 2014 UTC
Log: Experimental parser: revert read_cursor
[email protected]
BUG=
Review URL: https://codereview.chromium.org/139853014
http://code.google.com/p/v8/source/detail?r=18796
Modified:
/branches/experimental/parser/tools/lexer_generator/code_generator.jinja
/branches/experimental/parser/tools/lexer_generator/code_generator.py
=======================================
---
/branches/experimental/parser/tools/lexer_generator/code_generator.jinja
Thu Jan 23 11:54:29 2014 UTC
+++
/branches/experimental/parser/tools/lexer_generator/code_generator.jinja
Thu Jan 23 18:54:00 2014 UTC
@@ -34,8 +34,10 @@
{%- for r in key -%}
{%- if not loop.first %} || {% endif -%}
{%- if r[0] == 'PRIMARY_RANGE' -%}
- {%- if r[1][0] == r[1][1] -%}
+ {%- if r[1][0] == r[1][1] and r[1][0] != 0 -%}
primary_char == {{r[1][0]}}
+ {%- elif r[1][0] == r[1][1] -%}
+ (primary_char == 0 && cursor_ < buffer_end_)
{%- elif r[1][0] == 0 -%}
primary_char <= {{r[1][1]}}
{%- elif r[1][1] == upper_bound and not encoding == 'utf16'-%}
@@ -229,22 +231,14 @@
{% endif -%}
{%- macro do_transition(jump_id) -%}
+ {%- set transition_state_id = jump_table[jump_id][0] -%}
+ {%- set inline_transition = jump_table[jump_id][1] == 'inline' %}
FORWARD();
- if (cursor_ < buffer_end_) {
- {%- set transition_state_id = jump_table[jump_id][0] -%}
- {%- set inline_transition = jump_table[jump_id][1] == 'inline' %}
- {%- if inline_transition %}
- {{ do_dfa_state(transition_state_id) }}
- {% else %}
- {{ jump(jump_id) }}
- {% endif %}
- }
- {% if 'eos' in state['unique_transitions'] -%}
- {{ jump(state['unique_transitions']['eos']) }} // eos handler
- {%- else -%}
- BACKWARD(1);
- {{ jump(state['jump_before_match']) }} // no eos handler
- {%- endif %}
+ {%- if inline_transition %}
+ {{ do_dfa_state(transition_state_id) }}
+ {% else %}
+ {{ jump(jump_id) }}
+ {% endif %}
{%- endmacro -%}
{%- if state['switch_transitions'] -%}
@@ -266,7 +260,13 @@
}
{% endfor -%}
- {%- if state['deferred_transitions'] -%}
+ {%- if 'eos' in state['unique_transitions'] %}
+ if (primary_char == 0 && cursor_ >= buffer_end_) { // eos handler
+ {{ jump(state['unique_transitions']['eos']) }}
+ }
+ {%- endif -%}
+
+ {%- if state['deferred_transitions'] %}
if ({{long_char_check()}}) {
next_.is_onebyte = false;
{{long_char_create()}}
@@ -276,9 +276,7 @@
}
{% endfor -%}
}
- {%- endif-%}
-
- {{ write_label('before_match', node_number) }}
+ {%- endif -%}
{%- set match_action = state.match_action -%}
{%- if match_action %}
@@ -312,8 +310,8 @@
}
#define READ_CURSOR() { \
- ASSERT(cursor_ < buffer_end_); \
- primary_char = *(cursor_); \
+ if (cursor_ >= buffer_end_) primary_char = 0; \
+ else primary_char = *(cursor_); \
}
#ifdef DEBUG
=======================================
--- /branches/experimental/parser/tools/lexer_generator/code_generator.py
Thu Jan 23 11:54:29 2014 UTC
+++ /branches/experimental/parser/tools/lexer_generator/code_generator.py
Thu Jan 23 18:54:00 2014 UTC
@@ -54,7 +54,7 @@
self.__switching = switching
self.__jump_table = []
- __jump_labels = ['state_entry', 'after_entry_code', 'before_match']
+ __jump_labels = ['state_entry', 'after_entry_code']
@staticmethod
def __transform_state(encoding, state):
@@ -74,6 +74,7 @@
old_transitions = transitions
transitions = []
(class_keys, distinct_keys, ranges) = (0, 0, 0)
+ zero_transition = None
for key, transition_id in old_transitions:
keys = []
for (t, r) in key.range_iter(encoding):
@@ -83,6 +84,14 @@
elif t == 'PRIMARY_RANGE':
distinct_keys += r[1] - r[0] + 1
ranges += 1
+ # split 0 out of range, don't bother updating stats
+ assert r[0] >= 0
+ if r[0] == 0:
+ assert zero_transition == None
+ zero_transition = transition_id
+ if r[0] == r[1]:
+ continue
+ r = (r[0] + 1, r[1])
keys.append((t, r))
elif t == 'UNIQUE':
assert r == 'no_match' or r == 'eos'
@@ -92,6 +101,9 @@
raise Exception()
if keys:
transitions.append((keys, transition_id))
+ # delay zero transition until last
+ if zero_transition != None:
+ transitions.append(([('PRIMARY_RANGE', (0, 0))], transition_id))
return {
'node_number' : None,
'original_node_number' : state.node_number(),
@@ -99,7 +111,7 @@
# flags for code generator
'can_elide_read' : len(transitions) == 0,
'is_eos_handler' : False,
- 'inline' : None,
+ 'inline' : False,
'must_not_inline' : False,
# transitions for code generator
'if_transitions' : [],
@@ -125,7 +137,6 @@
return len(self.__jump_table) - 1
def __set_inline(self, count, state):
- assert state['inline'] == None
inline = False
if state['must_not_inline']:
inline = False
@@ -160,7 +171,8 @@
# all class checks will be deferred to after all other checks
if r[0] == 'CLASS':
d.append(r)
- elif no_switch:
+ # zero must assigned to an if check because of eos check
+ elif no_switch or (r[1][0] == 0):
i.append(r)
else:
s.append(r[1])
@@ -354,9 +366,6 @@
eos_state_id = state['unique_transitions']['eos']
jump = self.__register_jump(eos_state_id, 'state_entry')
state['unique_transitions']['eos'] = jump
- elif state['transitions']:
- jump = self.__register_jump(state_id, 'before_match')
- state['jump_before_match'] = jump
# now rewrite all nodes created
nodes_created = len(inline_mapping) - len(inline_mapping_in)
assert len(self.__dfa_states) == (
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.