Skip to content

Commit 32ee2e2

Browse files
committed
Remove specialized bytecodes
This also disables optimizations for trivial methods, which I won’t adapt to work, because we probably want to remove those optimizations too from this branch. Signed-off-by: Stefan Marr <[email protected]>
1 parent 228f028 commit 32ee2e2

File tree

10 files changed

+52
-1144
lines changed

10 files changed

+52
-1144
lines changed

src/som/compiler/ast/variable.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,44 +67,14 @@ def get_initialized_write_node(self, context_level, value_expr, source_section):
6767
return LocalInnerVarWriteNode(self.access_idx, value_expr, source_section)
6868
return LocalFrameVarWriteNode(self.access_idx, value_expr, source_section)
6969

70-
def get_push_bytecode(self, ctx_level):
70+
def get_push_bytecode(self, ctx_level): # pylint: disable=unused-argument
7171
if self.is_accessed_out_of_context():
72-
if ctx_level == 0:
73-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 0:
74-
return Bytecodes.push_inner_0
75-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 1:
76-
return Bytecodes.push_inner_1
77-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 2:
78-
return Bytecodes.push_inner_2
7972
return Bytecodes.push_inner
80-
81-
if ctx_level == 0:
82-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 0:
83-
return Bytecodes.push_frame_0
84-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 1:
85-
return Bytecodes.push_frame_1
86-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 2:
87-
return Bytecodes.push_frame_2
8873
return Bytecodes.push_frame
8974

90-
def get_pop_bytecode(self, ctx_level):
75+
def get_pop_bytecode(self, ctx_level): # pylint: disable=unused-argument
9176
if self.is_accessed_out_of_context():
92-
if ctx_level == 0:
93-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 0:
94-
return Bytecodes.pop_inner_0
95-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 1:
96-
return Bytecodes.pop_inner_1
97-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 2:
98-
return Bytecodes.pop_inner_2
9977
return Bytecodes.pop_inner
100-
101-
if ctx_level == 0:
102-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 0:
103-
return Bytecodes.pop_frame_0
104-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 1:
105-
return Bytecodes.pop_frame_1
106-
if self.access_idx == FRAME_AND_INNER_RCVR_IDX + 2:
107-
return Bytecodes.pop_frame_2
10878
return Bytecodes.pop_frame
10979

11080
def get_qualified_name(self):

src/som/compiler/bc/bytecode_generator.py

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
from som.interpreter.bc.bytecodes import Bytecodes as BC
2-
from som.vm.globals import nilObject, trueObject, falseObject
3-
from som.vm.symbols import sym_nil, sym_true, sym_false
4-
5-
6-
def emit_inc(mgenc):
7-
emit1(mgenc, BC.inc, 0)
8-
9-
10-
def emit_dec(mgenc):
11-
emit1(mgenc, BC.dec, 0)
12-
13-
14-
def emit_inc_field_push(mgenc, field_idx, ctx_level):
15-
emit3(mgenc, BC.inc_field_push, field_idx, ctx_level, 1)
162

173

184
def emit_pop(mgenc):
@@ -24,35 +10,14 @@ def emit_push_argument(mgenc, idx, ctx):
2410
emit3(mgenc, BC.push_argument, idx, ctx, 1)
2511

2612

27-
def emit_return_self(mgenc):
28-
mgenc.optimize_dup_pop_pop_sequence()
29-
emit1(mgenc, BC.return_self, 0)
30-
31-
3213
def emit_return_local(mgenc):
33-
if not mgenc.optimize_return_field():
34-
emit1(mgenc, BC.return_local, 0)
14+
emit1(mgenc, BC.return_local, 0)
3515

3616

3717
def emit_return_non_local(mgenc):
3818
emit2(mgenc, BC.return_non_local, mgenc.get_max_context_level(), 0)
3919

4020

41-
def emit_return_field(mgenc, field_idx):
42-
if field_idx == 0:
43-
emit1(mgenc, BC.return_field_0, 0)
44-
return
45-
if field_idx == 1:
46-
emit1(mgenc, BC.return_field_1, 0)
47-
return
48-
if field_idx == 2:
49-
emit1(mgenc, BC.return_field_2, 0)
50-
return
51-
raise NotImplementedError(
52-
"Don't support fields with index > 2, but got " + str(field_idx)
53-
)
54-
55-
5621
def emit_dup(mgenc):
5722
emit1(mgenc, BC.dup, 1)
5823

@@ -73,29 +38,13 @@ def emit_push_field(mgenc, field_name):
7338
emit_push_field_with_index(mgenc, field_idx, ctx_level)
7439

7540

76-
def emit_push_field_with_index(mgenc, field_idx, ctx_level):
77-
if ctx_level == 0:
78-
if field_idx == 0:
79-
emit1(mgenc, BC.push_field_0, 1)
80-
return
81-
if field_idx == 1:
82-
emit1(mgenc, BC.push_field_1, 1)
83-
return
84-
41+
def emit_push_field_with_index(
42+
mgenc, field_idx, ctx_level # pylint: disable=unused-argument
43+
):
8544
emit3(mgenc, BC.push_field, field_idx, mgenc.get_max_context_level(), 1)
8645

8746

8847
def emit_push_global(mgenc, glob):
89-
if glob is sym_nil:
90-
emit_push_constant(mgenc, nilObject)
91-
return
92-
if glob is sym_true:
93-
emit_push_constant(mgenc, trueObject)
94-
return
95-
if glob is sym_false:
96-
emit_push_constant(mgenc, falseObject)
97-
return
98-
9948
idx = mgenc.add_literal_if_absent(glob)
10049
# the block needs to be able to send #unknownGlobal: to self
10150
if not mgenc.is_global_known(glob):
@@ -115,20 +64,10 @@ def emit_pop_field(mgenc, field_name):
11564
ctx_level = mgenc.get_max_context_level()
11665
field_idx = mgenc.get_field_index(field_name)
11766

118-
if mgenc.optimize_inc_field(field_idx, ctx_level):
119-
return
120-
12167
emit_pop_field_with_index(mgenc, field_idx, ctx_level)
12268

12369

12470
def emit_pop_field_with_index(mgenc, field_idx, ctx_level):
125-
if ctx_level == 0:
126-
if field_idx == 0:
127-
emit1(mgenc, BC.pop_field_0, -1)
128-
return
129-
if field_idx == 1:
130-
emit1(mgenc, BC.pop_field_1, -1)
131-
return
13271
emit3(mgenc, BC.pop_field, field_idx, ctx_level, -1)
13372

13473

@@ -143,42 +82,11 @@ def emit_send(mgenc, msg):
14382
num_args = msg.get_number_of_signature_arguments()
14483
stack_effect = -num_args + 1 # +1 for the result
14584

146-
if num_args == 1:
147-
emit2(mgenc, BC.send_1, idx, stack_effect)
148-
elif num_args == 2:
149-
emit2(mgenc, BC.send_2, idx, stack_effect)
150-
elif num_args == 3:
151-
emit2(mgenc, BC.send_3, idx, stack_effect)
152-
else:
153-
emit2(mgenc, BC.send_n, idx, stack_effect)
85+
emit2(mgenc, BC.send_n, idx, stack_effect)
15486

15587

15688
def emit_push_constant(mgenc, lit):
157-
from som.vmobjects.integer import Integer
158-
159-
if isinstance(lit, Integer):
160-
if lit.get_embedded_integer() == 0:
161-
emit1(mgenc, BC.push_0, 1)
162-
return
163-
if lit.get_embedded_integer() == 1:
164-
emit1(mgenc, BC.push_1, 1)
165-
return
166-
167-
if lit is nilObject:
168-
emit1(mgenc, BC.push_nil, 1)
169-
return
170-
17189
idx = mgenc.add_literal_if_absent(lit)
172-
if idx == 0:
173-
emit1(mgenc, BC.push_constant_0, 1)
174-
return
175-
if idx == 1:
176-
emit1(mgenc, BC.push_constant_1, 1)
177-
return
178-
if idx == 2:
179-
emit1(mgenc, BC.push_constant_2, 1)
180-
return
181-
18290
emit2(mgenc, BC.push_constant, idx, 1)
18391

18492

src/som/compiler/bc/disassembler.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,7 @@ def dump_bytecode(m, b, indent=""):
8484
+ ", context: "
8585
+ str(m.get_bytecode(b + 2))
8686
)
87-
elif (
88-
bytecode == Bytecodes.push_frame_0
89-
or bytecode == Bytecodes.push_frame_1
90-
or bytecode == Bytecodes.push_frame_2
91-
or bytecode == Bytecodes.pop_frame_0
92-
or bytecode == Bytecodes.pop_frame_1
93-
or bytecode == Bytecodes.pop_frame_2
94-
or bytecode == Bytecodes.push_inner_0
95-
or bytecode == Bytecodes.push_inner_1
96-
or bytecode == Bytecodes.push_inner_2
97-
or bytecode == Bytecodes.pop_inner_0
98-
or bytecode == Bytecodes.pop_inner_1
99-
or bytecode == Bytecodes.pop_inner_2
100-
):
101-
# don't need any other arguments
102-
error_println("")
103-
elif (
104-
bytecode == Bytecodes.push_field
105-
or bytecode == Bytecodes.pop_field
106-
or bytecode == Bytecodes.inc_field_push
107-
or bytecode == Bytecodes.inc_field
108-
):
87+
elif bytecode == Bytecodes.push_field or bytecode == Bytecodes.pop_field:
10988
if m.get_holder():
11089
field_name = str(
11190
m.get_holder().get_instance_field_name(m.get_bytecode(b + 1))
@@ -151,15 +130,8 @@ def dump_bytecode(m, b, indent=""):
151130
+ str(m.get_constant(b))
152131
)
153132
elif bytecode in (
154-
Bytecodes.send_1,
155-
Bytecodes.send_2,
156-
Bytecodes.send_3,
157133
Bytecodes.send_n,
158134
Bytecodes.super_send,
159-
Bytecodes.q_super_send_1,
160-
Bytecodes.q_super_send_2,
161-
Bytecodes.q_super_send_3,
162-
Bytecodes.q_super_send_n,
163135
):
164136
error_println(
165137
"(index: "

0 commit comments

Comments
 (0)