Skip to content

Commit 395871e

Browse files
authored
GH-98831: Elaborate some cases_generator tests (#101299)
* Make macro test more elaborate * Add test for 'register inst()'
1 parent 498598e commit 395871e

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

Tools/cases_generator/test_generator.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,21 @@ def test_super_instruction():
333333

334334
def test_macro_instruction():
335335
input = """
336-
inst(OP1, (counter/1, arg --)) {
337-
op1();
336+
inst(OP1, (counter/1, arg1 -- interim)) {
337+
interim = op1(arg1);
338338
}
339-
op(OP2, (extra/2, arg --)) {
340-
op2();
339+
op(OP2, (extra/2, arg2, interim -- res)) {
340+
res = op2(arg2, interim);
341341
}
342342
macro(OP) = OP1 + cache/2 + OP2;
343343
"""
344344
output = """
345345
TARGET(OP1) {
346-
PyObject *arg = PEEK(1);
346+
PyObject *arg1 = PEEK(1);
347+
PyObject *interim;
347348
uint16_t counter = read_u16(&next_instr[0].cache);
348-
op1();
349-
STACK_SHRINK(1);
349+
interim = op1(arg1);
350+
POKE(1, interim);
350351
JUMPBY(1);
351352
DISPATCH();
352353
}
@@ -355,17 +356,24 @@ def test_macro_instruction():
355356
PyObject *_tmp_1 = PEEK(1);
356357
PyObject *_tmp_2 = PEEK(2);
357358
{
358-
PyObject *arg = _tmp_1;
359-
uint16_t counter = read_u16(&next_instr[0].cache);
360-
op1();
359+
PyObject *arg1 = _tmp_1;
360+
PyObject *interim;
361+
uint16_t counter = re
362+
ad_u16(&next_instr[0].cache);
363+
interim = op1(arg1);
364+
_tmp_1 = interim;
361365
}
362366
{
363-
PyObject *arg = _tmp_2;
367+
PyObject *interim = _tmp_1;
368+
PyObject *arg2 = _tmp_2;
369+
PyObject *res;
364370
uint32_t extra = read_u32(&next_instr[3].cache);
365-
op2();
371+
res = op2(arg2, interim);
372+
_tmp_2 = res;
366373
}
367374
JUMPBY(5);
368-
STACK_SHRINK(2);
375+
STACK_SHRINK(1);
376+
POKE(1, _tmp_2);
369377
DISPATCH();
370378
}
371379
"""
@@ -448,3 +456,23 @@ def test_array_error_if():
448456
}
449457
"""
450458
run_cases_test(input, output)
459+
460+
def test_register():
461+
input = """
462+
register inst(OP, (counter/1, left, right -- result)) {
463+
result = op(left, right);
464+
}
465+
"""
466+
output = """
467+
TARGET(OP) {
468+
PyObject *left = REG(oparg1);
469+
PyObject *right = REG(oparg2);
470+
PyObject *result;
471+
uint16_t counter = read_u16(&next_instr[0].cache);
472+
result = op(left, right);
473+
Py_XSETREF(REG(oparg3), result);
474+
JUMPBY(1);
475+
DISPATCH();
476+
}
477+
"""
478+
run_cases_test(input, output)

0 commit comments

Comments
 (0)