@@ -333,20 +333,21 @@ def test_super_instruction():
333
333
334
334
def test_macro_instruction ():
335
335
input = """
336
- inst(OP1, (counter/1, arg --)) {
337
- op1();
336
+ inst(OP1, (counter/1, arg1 -- interim )) {
337
+ interim = op1(arg1 );
338
338
}
339
- op(OP2, (extra/2, arg -- )) {
340
- op2();
339
+ op(OP2, (extra/2, arg2, interim -- res )) {
340
+ res = op2(arg2, interim );
341
341
}
342
342
macro(OP) = OP1 + cache/2 + OP2;
343
343
"""
344
344
output = """
345
345
TARGET(OP1) {
346
- PyObject *arg = PEEK(1);
346
+ PyObject *arg1 = PEEK(1);
347
+ PyObject *interim;
347
348
uint16_t counter = read_u16(&next_instr[0].cache);
348
- op1();
349
- STACK_SHRINK(1 );
349
+ interim = op1(arg1 );
350
+ POKE(1, interim );
350
351
JUMPBY(1);
351
352
DISPATCH();
352
353
}
@@ -355,17 +356,24 @@ def test_macro_instruction():
355
356
PyObject *_tmp_1 = PEEK(1);
356
357
PyObject *_tmp_2 = PEEK(2);
357
358
{
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;
361
365
}
362
366
{
363
- PyObject *arg = _tmp_2;
367
+ PyObject *interim = _tmp_1;
368
+ PyObject *arg2 = _tmp_2;
369
+ PyObject *res;
364
370
uint32_t extra = read_u32(&next_instr[3].cache);
365
- op2();
371
+ res = op2(arg2, interim);
372
+ _tmp_2 = res;
366
373
}
367
374
JUMPBY(5);
368
- STACK_SHRINK(2);
375
+ STACK_SHRINK(1);
376
+ POKE(1, _tmp_2);
369
377
DISPATCH();
370
378
}
371
379
"""
@@ -448,3 +456,23 @@ def test_array_error_if():
448
456
}
449
457
"""
450
458
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