From 8d6f4e1560bed1e82bd416dab3a7dd93cedc9867 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 24 Jan 2023 10:39:14 -0800 Subject: [PATCH 1/2] Make macro test more elaborate --- Tools/cases_generator/test_generator.py | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Tools/cases_generator/test_generator.py b/Tools/cases_generator/test_generator.py index ae0c1e2f97c35e..fc8dd458a68ba8 100644 --- a/Tools/cases_generator/test_generator.py +++ b/Tools/cases_generator/test_generator.py @@ -319,20 +319,21 @@ def test_super_instruction(): def test_macro_instruction(): input = """ - inst(OP1, (counter/1, arg --)) { - op1(); + inst(OP1, (counter/1, arg1 -- interim)) { + interim = op1(arg1); } - op(OP2, (extra/2, arg --)) { - op2(); + op(OP2, (extra/2, arg2, interim -- res)) { + res = op2(arg2, interim); } macro(OP) = OP1 + cache/2 + OP2; """ output = """ TARGET(OP1) { - PyObject *arg = PEEK(1); + PyObject *arg1 = PEEK(1); + PyObject *interim; uint16_t counter = read_u16(&next_instr[0].cache); - op1(); - STACK_SHRINK(1); + interim = op1(arg1); + POKE(1, interim); JUMPBY(1); DISPATCH(); } @@ -341,17 +342,23 @@ def test_macro_instruction(): PyObject *_tmp_1 = PEEK(1); PyObject *_tmp_2 = PEEK(2); { - PyObject *arg = _tmp_1; + PyObject *arg1 = _tmp_1; + PyObject *interim; uint16_t counter = read_u16(&next_instr[0].cache); - op1(); + 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); - op2(); + res = op2(arg2, interim); + _tmp_2 = res; } JUMPBY(5); - STACK_SHRINK(2); + STACK_SHRINK(1); + POKE(1, _tmp_2); DISPATCH(); } """ From 81b0508021ba7518c68f9f76ca7ffec08bcf742c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 24 Jan 2023 14:37:50 -0800 Subject: [PATCH 2/2] Add test for 'register inst()' --- Tools/cases_generator/test_generator.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Tools/cases_generator/test_generator.py b/Tools/cases_generator/test_generator.py index fc8dd458a68ba8..c31e54f4cbc592 100644 --- a/Tools/cases_generator/test_generator.py +++ b/Tools/cases_generator/test_generator.py @@ -344,7 +344,8 @@ def test_macro_instruction(): { PyObject *arg1 = _tmp_1; PyObject *interim; - uint16_t counter = read_u16(&next_instr[0].cache); + uint16_t counter = re + ad_u16(&next_instr[0].cache); interim = op1(arg1); _tmp_1 = interim; } @@ -441,3 +442,23 @@ def test_array_error_if(): } """ 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)