Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f7c220a
Implement FOR_END
sweeneyde Feb 20, 2022
4178c30
Use jabs, not jrel
sweeneyde Feb 20, 2022
245b43f
Bump magic
sweeneyde Feb 20, 2022
61a85f0
merge with main
sweeneyde Mar 1, 2022
b0030d5
merge with main
sweeneyde Mar 20, 2022
8f3cd5a
Remove FOR_ITER entirely
sweeneyde Mar 20, 2022
4520a5a
Fix some failng tests
sweeneyde Mar 20, 2022
6284f20
exclude test_frozenmain
sweeneyde Mar 20, 2022
3a0d53e
merge with main
sweeneyde Mar 24, 2022
3b328e7
fix some tracing tests
sweeneyde Mar 24, 2022
bdd7f07
fix swap pop/push in frameobject.c
sweeneyde Mar 24, 2022
b20fed8
merge with main
sweeneyde Apr 9, 2022
77d52e6
Get test.test_trace passing
sweeneyde Apr 10, 2022
53a8734
when marking backwards jumps, set todo=1
sweeneyde Apr 10, 2022
7d32011
remove debugging code
sweeneyde Apr 10, 2022
4a2e781
update test_dis
sweeneyde Apr 10, 2022
0af7e1e
make FOR_END a relative jump
sweeneyde Apr 10, 2022
d3552aa
make test.test_bdb and test.test_pdb pass
sweeneyde Apr 10, 2022
563ca00
refactor maybe_call_line_trace logic
sweeneyde Apr 11, 2022
719e756
add blurb
sweeneyde Apr 11, 2022
8626569
FOR_ITER --> FOR_END in dis.rst
sweeneyde Apr 11, 2022
2884727
FOR_ITER --> FOR_END in specialize.c
sweeneyde Apr 11, 2022
44baacc
Update whatsnew
sweeneyde Apr 11, 2022
0adffbd
Merge branch 'main' into for_end
sweeneyde Apr 11, 2022
7a62601
merge with main
sweeneyde Apr 11, 2022
92e8c6d
Merge branch 'for_end' of https://github.com/sweeneyde/cpython into f…
sweeneyde Apr 11, 2022
e4f240e
fix test_dis
sweeneyde Apr 12, 2022
6c2e53d
Merge branch 'main' into for_end
sweeneyde Apr 12, 2022
32bed37
fix opcode.h
sweeneyde Apr 12, 2022
1a19c91
Re-introduce FOR_ITER
sweeneyde Apr 12, 2022
4c0c180
get test_dis passing
sweeneyde Apr 12, 2022
29decd2
get test_trace passing
sweeneyde Apr 12, 2022
069dd51
fix restore mark_stacks behavior of FOR_ITER
sweeneyde Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make FOR_END a relative jump
  • Loading branch information
sweeneyde committed Apr 10, 2022
commit 0af7e1eefb3fff797e7e57869d3a3c14833d6aac
2 changes: 1 addition & 1 deletion Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
LOAD_CONST = opmap['LOAD_CONST']
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
BINARY_OP = opmap['BINARY_OP']
JUMP_BACKWARD = opmap['JUMP_BACKWARD']

BACK_JUMPS = {code for name, code in opmap.items()
if 'JUMP_BACKWARD' in name} | {opmap['FOR_END']}

CACHE = opmap["CACHE"]

Expand Down Expand Up @@ -442,7 +444,7 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argval = arg*2
argrepr = "to " + repr(argval)
elif op in hasjrel:
signed_arg = -arg if op == JUMP_BACKWARD else arg
signed_arg = -arg if op in BACK_JUMPS else arg
argval = offset + 2 + signed_arg*2
argrepr = "to " + repr(argval)
elif op in haslocal or op in hasfree:
Expand Down Expand Up @@ -568,7 +570,7 @@ def findlabels(code):
for offset, op, arg in _unpack_opargs(code):
if arg is not None:
if op in hasjrel:
if op == JUMP_BACKWARD:
if op in BACK_JUMPS:
arg = -arg
label = offset + 2 + arg*2
elif op in hasjabs:
Expand Down
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3494).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3493).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
2 changes: 1 addition & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def jabs_op(name, op, entries=0):
def_op('KW_NAMES', 172)
hasconst.append(172)

jabs_op('FOR_END', 173)
jrel_op('FOR_END', 173)

del def_op, name_op, jrel_op, jabs_op

Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def bug708901():

%3d NOP

%3d >> FOR_END 18 (to 36)
%3d >> FOR_END 3 (to 36)
LOAD_CONST 0 (None)
RETURN_VALUE
""" % (bug708901.__code__.co_firstlineno,
Expand Down Expand Up @@ -576,7 +576,7 @@ def foo(x):
LOAD_FAST 1 (z)
BINARY_OP 0 (+)
LIST_APPEND 2
>> FOR_END 5 (to 10)
>> FOR_END 7 (to 10)
RETURN_VALUE
""" % (dis_nested_1,
__file__,
Expand Down Expand Up @@ -1236,7 +1236,7 @@ def _prepare_test_cases():
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=48, argval=96, argrepr='to 96', offset=90, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=92, starts_line=8, is_jump_target=False, positions=None),
Instruction(opname='JUMP_FORWARD', opcode=110, arg=16, argval=128, argrepr='to 128', offset=94, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='FOR_END', opcode=173, arg=17, argval=34, argrepr='to 34', offset=96, starts_line=3, is_jump_target=True, positions=None),
Instruction(opname='FOR_END', opcode=173, arg=32, argval=34, argrepr='to 34', offset=96, starts_line=3, is_jump_target=True, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=3, argval='print', argrepr='NULL + print', offset=98, starts_line=10, is_jump_target=False, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=110, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='PRECALL', opcode=166, arg=1, argval=1, argrepr='', offset=112, starts_line=None, is_jump_target=False, positions=None),
Expand Down
2 changes: 1 addition & 1 deletion Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ mark_stacks(PyCodeObject *code_obj, int len)
{
int64_t target_stack = push_value(next_stack, Object);
stacks[i+1] = pop_value(next_stack);
j = get_arg(code, i);
j = i + 1 - get_arg(code, i);
if (stacks[j] == UNINITIALIZED && j < i) {
todo = 1;
}
Expand Down
32 changes: 16 additions & 16 deletions Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4193,7 +4193,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
if (next != NULL) {
PUSH(next);
JUMPTO(oparg);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
PREDICT(STORE_FAST);
PREDICT(UNPACK_SEQUENCE);
Expand Down
4 changes: 3 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7657,12 +7657,14 @@ assemble_jump_offsets(struct assembler *a, struct compiler *c)
if (is_relative_jump(instr)) {
if (instr->i_oparg < bsize) {
assert(instr->i_opcode == JUMP_BACKWARD ||
instr->i_opcode == JUMP_BACKWARD_NO_INTERRUPT);
instr->i_opcode == JUMP_BACKWARD_NO_INTERRUPT ||
instr->i_opcode == FOR_END);
instr->i_oparg = bsize - instr->i_oparg;
}
else {
assert(instr->i_opcode != JUMP_BACKWARD);
assert(instr->i_opcode != JUMP_BACKWARD_NO_INTERRUPT);
assert(instr->i_opcode != FOR_END);
instr->i_oparg -= bsize;
}
}
Expand Down