Skip to content

Commit 706d15f

Browse files
committed
Don’t use bytecode length array in interpreter
Instead, hardcode the bytecode length. This should avoid another check on each bytecode. Signed-off-by: Stefan Marr <[email protected]>
1 parent e590a6b commit 706d15f

File tree

2 files changed

+160
-114
lines changed

2 files changed

+160
-114
lines changed

src/som/interpreter/bc/bytecodes.py

+74-70
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from rlib import jit
22

3+
LEN_NO_ARGS = 1
4+
LEN_ONE_ARG = 2
5+
LEN_TWO_ARGS = 3
6+
37

48
class Bytecodes(object):
59
# Bytecodes used by the Simple Object Machine (SOM)
@@ -196,77 +200,77 @@ def is_one_of(bytecode, candidates):
196200
]
197201

198202
_BYTECODE_LENGTH = [
199-
1, # halt
200-
1, # dup
201-
3, # push_frame
202-
3, # push_frame_0
203-
3, # push_frame_1
204-
3, # push_frame_2
205-
3, # push_inner
206-
3, # push_inner_0
207-
3, # push_inner_1
208-
3, # push_inner_2
209-
3, # push_field
210-
1, # push_field_0
211-
1, # push_field_1
212-
2, # push_block
213-
2, # push_block_no_ctx
214-
2, # push_constant
215-
1, # push_constant_0
216-
1, # push_constant_1
217-
1, # push_constant_2
218-
1, # push_0
219-
1, # push_1
220-
1, # push_nil
221-
2, # push_global
222-
1, # pop
223-
3, # pop_frame
224-
3, # pop_frame_0
225-
3, # pop_frame_1
226-
3, # pop_frame_2
227-
3, # pop_inner
228-
3, # pop_inner_0
229-
3, # pop_inner_1
230-
3, # pop_inner_2
231-
3, # pop_field
232-
1, # pop_field_0
233-
1, # pop_field_1
234-
2, # send_1
235-
2, # send_2
236-
2, # send_3
237-
2, # send_n
238-
2, # super_send
239-
1, # return_local
240-
2, # return_non_local
241-
1, # return_self
242-
1, # return_field_0
243-
1, # return_field_1
244-
1, # return_field_2
245-
1, # inc
246-
1, # dec
247-
3, # inc_field
248-
3, # inc_field_push
249-
3, # jump
250-
3, # jump_on_true_top_nil
251-
3, # jump_on_false_top_nil
252-
3, # jump_on_true_pop
253-
3, # jump_on_false_pop
254-
3, # jump_backward
255-
3, # jump2
256-
3, # jump2_on_true_top_nil
257-
3, # jump2_on_false_top_nil
258-
3, # jump2_on_true_pop
259-
3, # jump2_on_false_pop
260-
3, # jump2_backward
261-
2, # q_super_send_1
262-
2, # q_super_send_2
263-
2, # q_super_send_3
264-
2, # q_super_send_n
203+
LEN_NO_ARGS, # halt
204+
LEN_NO_ARGS, # dup
205+
LEN_TWO_ARGS, # push_frame
206+
LEN_TWO_ARGS, # push_frame_0
207+
LEN_TWO_ARGS, # push_frame_1
208+
LEN_TWO_ARGS, # push_frame_2
209+
LEN_TWO_ARGS, # push_inner
210+
LEN_TWO_ARGS, # push_inner_0
211+
LEN_TWO_ARGS, # push_inner_1
212+
LEN_TWO_ARGS, # push_inner_2
213+
LEN_TWO_ARGS, # push_field
214+
LEN_NO_ARGS, # push_field_0
215+
LEN_NO_ARGS, # push_field_1
216+
LEN_ONE_ARG, # push_block
217+
LEN_ONE_ARG, # push_block_no_ctx
218+
LEN_ONE_ARG, # push_constant
219+
LEN_NO_ARGS, # push_constant_0
220+
LEN_NO_ARGS, # push_constant_1
221+
LEN_NO_ARGS, # push_constant_2
222+
LEN_NO_ARGS, # push_0
223+
LEN_NO_ARGS, # push_1
224+
LEN_NO_ARGS, # push_nil
225+
LEN_ONE_ARG, # push_global
226+
LEN_NO_ARGS, # pop
227+
LEN_TWO_ARGS, # pop_frame
228+
LEN_TWO_ARGS, # pop_frame_0
229+
LEN_TWO_ARGS, # pop_frame_1
230+
LEN_TWO_ARGS, # pop_frame_2
231+
LEN_TWO_ARGS, # pop_inner
232+
LEN_TWO_ARGS, # pop_inner_0
233+
LEN_TWO_ARGS, # pop_inner_1
234+
LEN_TWO_ARGS, # pop_inner_2
235+
LEN_TWO_ARGS, # pop_field
236+
LEN_NO_ARGS, # pop_field_0
237+
LEN_NO_ARGS, # pop_field_1
238+
LEN_ONE_ARG, # send_1
239+
LEN_ONE_ARG, # send_2
240+
LEN_ONE_ARG, # send_3
241+
LEN_ONE_ARG, # send_n
242+
LEN_ONE_ARG, # super_send
243+
LEN_NO_ARGS, # return_local
244+
LEN_ONE_ARG, # return_non_local
245+
LEN_NO_ARGS, # return_self
246+
LEN_NO_ARGS, # return_field_0
247+
LEN_NO_ARGS, # return_field_1
248+
LEN_NO_ARGS, # return_field_2
249+
LEN_NO_ARGS, # inc
250+
LEN_NO_ARGS, # dec
251+
LEN_TWO_ARGS, # inc_field
252+
LEN_TWO_ARGS, # inc_field_push
253+
LEN_TWO_ARGS, # jump
254+
LEN_TWO_ARGS, # jump_on_true_top_nil
255+
LEN_TWO_ARGS, # jump_on_false_top_nil
256+
LEN_TWO_ARGS, # jump_on_true_pop
257+
LEN_TWO_ARGS, # jump_on_false_pop
258+
LEN_TWO_ARGS, # jump_backward
259+
LEN_TWO_ARGS, # jump2
260+
LEN_TWO_ARGS, # jump2_on_true_top_nil
261+
LEN_TWO_ARGS, # jump2_on_false_top_nil
262+
LEN_TWO_ARGS, # jump2_on_true_pop
263+
LEN_TWO_ARGS, # jump2_on_false_pop
264+
LEN_TWO_ARGS, # jump2_backward
265+
LEN_ONE_ARG, # q_super_send_1
266+
LEN_ONE_ARG, # q_super_send_2
267+
LEN_ONE_ARG, # q_super_send_3
268+
LEN_ONE_ARG, # q_super_send_n
265269
# rewritten on first use
266-
3, # push_local
267-
3, # push_argument
268-
3, # pop_local
269-
3, # pop_argument
270+
LEN_TWO_ARGS, # push_local
271+
LEN_TWO_ARGS, # push_argument
272+
LEN_TWO_ARGS, # pop_local
273+
LEN_TWO_ARGS, # pop_argument
270274
]
271275

272276

0 commit comments

Comments
 (0)