GH-98831: Elaborate some cases_generator tests (#101299)

* Make macro test more elaborate
* Add test for 'register inst()'
This commit is contained in:
Guido van Rossum 2023-01-25 08:55:46 -08:00 committed by GitHub
parent 498598e8c2
commit 395871e511
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -333,20 +333,21 @@ def test_super_instruction():
def test_macro_instruction(): def test_macro_instruction():
input = """ input = """
inst(OP1, (counter/1, arg --)) { inst(OP1, (counter/1, arg1 -- interim)) {
op1(); interim = op1(arg1);
} }
op(OP2, (extra/2, arg --)) { op(OP2, (extra/2, arg2, interim -- res)) {
op2(); res = op2(arg2, interim);
} }
macro(OP) = OP1 + cache/2 + OP2; macro(OP) = OP1 + cache/2 + OP2;
""" """
output = """ output = """
TARGET(OP1) { TARGET(OP1) {
PyObject *arg = PEEK(1); PyObject *arg1 = PEEK(1);
PyObject *interim;
uint16_t counter = read_u16(&next_instr[0].cache); uint16_t counter = read_u16(&next_instr[0].cache);
op1(); interim = op1(arg1);
STACK_SHRINK(1); POKE(1, interim);
JUMPBY(1); JUMPBY(1);
DISPATCH(); DISPATCH();
} }
@ -355,17 +356,24 @@ def test_macro_instruction():
PyObject *_tmp_1 = PEEK(1); PyObject *_tmp_1 = PEEK(1);
PyObject *_tmp_2 = PEEK(2); PyObject *_tmp_2 = PEEK(2);
{ {
PyObject *arg = _tmp_1; PyObject *arg1 = _tmp_1;
uint16_t counter = read_u16(&next_instr[0].cache); PyObject *interim;
op1(); uint16_t counter = re
ad_u16(&next_instr[0].cache);
interim = op1(arg1);
_tmp_1 = interim;
} }
{ {
PyObject *arg = _tmp_2; PyObject *interim = _tmp_1;
PyObject *arg2 = _tmp_2;
PyObject *res;
uint32_t extra = read_u32(&next_instr[3].cache); uint32_t extra = read_u32(&next_instr[3].cache);
op2(); res = op2(arg2, interim);
_tmp_2 = res;
} }
JUMPBY(5); JUMPBY(5);
STACK_SHRINK(2); STACK_SHRINK(1);
POKE(1, _tmp_2);
DISPATCH(); DISPATCH();
} }
""" """
@ -448,3 +456,23 @@ def test_array_error_if():
} }
""" """
run_cases_test(input, output) run_cases_test(input, output)
def test_register():
input = """
register inst(OP, (counter/1, left, right -- result)) {
result = op(left, right);
}
"""
output = """
TARGET(OP) {
PyObject *left = REG(oparg1);
PyObject *right = REG(oparg2);
PyObject *result;
uint16_t counter = read_u16(&next_instr[0].cache);
result = op(left, right);
Py_XSETREF(REG(oparg3), result);
JUMPBY(1);
DISPATCH();
}
"""
run_cases_test(input, output)