Skip to content

Commit b289784

Browse files
committed
First set of coercion refactors for attribute_6model.
1 parent c6c1df5 commit b289784

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

src/PAST/SixModelPASTExtensions.pir

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,50 @@ some PAST that will produce it or a name that it can be looked up by.
3636
.const int STORAGE_SPEC_BP_NUM = 2
3737
.const int STORAGE_SPEC_BP_STR = 3
3838

39-
.sub 'attribute_6model' :method :multi(_, ['PAST';'Var'])
39+
.sub 'attribute_6model_type' :method
4040
.param pmc node
41-
.param pmc bindpost
4241

43-
.local pmc ops
44-
$P0 = get_hll_global ['POST'], 'Ops'
45-
ops = $P0.'new'('node'=>node)
46-
.local string name
47-
name = node.'name'()
48-
name = self.'escape'(name)
49-
5042
# See if we have a type. If so, use it to determine what op to use
5143
# and what the register type will be.
5244
.local pmc type
53-
.local string get_attr_op, set_attr_op, coerce_reg_type
5445
.local int primitive_type_id
5546
type = node.'type'()
5647
primitive_type_id = repr_get_primitive_type_spec type
5748
if primitive_type_id == STORAGE_SPEC_BP_INT goto prim_int
5849
if primitive_type_id == STORAGE_SPEC_BP_NUM goto prim_num
5950
if primitive_type_id == STORAGE_SPEC_BP_STR goto prim_str
60-
get_attr_op = 'getattribute'
61-
set_attr_op = 'setattribute'
62-
coerce_reg_type = 'P'
63-
goto type_done
51+
.return ('P', 'getattribute', 'setattribute')
6452
prim_int:
65-
get_attr_op = 'repr_get_attr_int'
66-
set_attr_op = 'repr_bind_attr_int'
67-
coerce_reg_type = 'I'
68-
goto type_done
53+
.return ('i', 'repr_get_attr_int', 'repr_bind_attr_int')
6954
prim_num:
70-
get_attr_op = 'repr_get_attr_num'
71-
set_attr_op = 'repr_bind_attr_num'
72-
coerce_reg_type = 'N'
73-
goto type_done
55+
.return ('n', 'repr_get_attr_num', 'repr_bind_attr_num')
7456
prim_str:
75-
get_attr_op = 'repr_get_attr_str'
76-
set_attr_op = 'repr_bind_attr_str'
77-
coerce_reg_type = 'S'
78-
goto type_done
79-
type_done:
57+
.return ('s', 'repr_get_attr_str', 'repr_bind_attr_str')
58+
.end
59+
60+
61+
62+
.sub 'attribute_6model' :method :multi(_, ['PAST';'Var'])
63+
.param pmc node
64+
.param pmc bindpost
65+
66+
.local pmc ops
67+
$P0 = get_hll_global ['POST'], 'Ops'
68+
ops = $P0.'new'('node'=>node)
69+
70+
unless bindpost goto have_bindpost
71+
$S0 = bindpost.'result'()
72+
bindpost = $P0.'new'('result'=>$S0)
73+
have_bindpost:
74+
75+
.local string name
76+
name = node.'name'()
77+
name = self.'escape'(name)
78+
79+
# See if we have a type. If so, use it to determine what op to use
80+
# and what the register type will be.
81+
.local string get_attr_op, set_attr_op, coerce_reg_type
82+
(coerce_reg_type, get_attr_op, set_attr_op) = self.'attribute_6model_type'(node)
8083

8184
# We have three cases here.
8285
# 0 children = use self
@@ -113,11 +116,8 @@ some PAST that will produce it or a name that it can be looked up by.
113116
.tailcall self.'vivify'(node, ops, fetchop, storeop)
114117

115118
attribute_bind:
116-
if coerce_reg_type == 'P' goto attribute_bind_coerced
117-
$P0 = self.'uniquereg'(coerce_reg_type)
118-
ops.'push_pirop'('set', $P0, bindpost)
119-
bindpost = $P0
120-
attribute_bind_coerced:
119+
bindpost = self.'coerce'(bindpost, coerce_reg_type)
120+
ops.'push'(bindpost)
121121
ops.'push_pirop'(set_attr_op, call_on, name, bindpost)
122122
ops.'result'(bindpost)
123123
.return (ops)
@@ -144,11 +144,8 @@ some PAST that will produce it or a name that it can be looked up by.
144144
.tailcall self.'vivify'(node, ops, fetchop, storeop)
145145

146146
attribute_bind_handle:
147-
if coerce_reg_type == 'P' goto attribute_bind_handle_coerced
148-
$P0 = self.'uniquereg'(coerce_reg_type)
149-
ops.'push_pirop'('set', $P0, bindpost)
150-
bindpost = $P0
151-
attribute_bind_handle_coerced:
147+
bindpost = self.'coerce'(bindpost, coerce_reg_type)
148+
ops.'push'(bindpost)
152149
ops.'push_pirop'(set_attr_op, call_on, handle, name, bindpost)
153150
ops.'result'(bindpost)
154151
.return (ops)

0 commit comments

Comments
 (0)