Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-93678: reduce boilerplate and code repetition in the compiler#93682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes from1 commit
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
996be64
move line/noline to arg and remove _noline version of functions
iritkatrielJun 10, 2022
af31e92
add struct location to reduce boilerplate
iritkatrielJun 10, 2022
f8a0767
merge basicblock_addop, basicblock_addop_i and basicblock_add_jump in…
iritkatrielJun 10, 2022
430b4b9
add news
iritkatrielJun 10, 2022
66d5609
assume that oparg is < (1<<30)
iritkatrielJun 10, 2022
7670a7c
Merge remote-tracking branch 'upstream/main' into codegen-reduce-repe…
iritkatrielJun 10, 2022
7d74572
use the new location struct for the compiler unit's location
iritkatrielJun 10, 2022
016ebbc
use the new location struct for the instruction location
iritkatrielJun 10, 2022
5e06cad
basicblock_addop takes location by reference
iritkatrielJun 10, 2022
c23e2cf
LOCATION needs to return a const
iritkatrielJun 10, 2022
fc74555
define static no_location in function scope
iritkatrielJun 10, 2022
9220fc1
are we const now?
iritkatrielJun 10, 2022
9b5dc34
trivial stuff
iritkatrielJun 10, 2022
5330060
Merge remote-tracking branch 'upstream/main' into codegen-reduce-repe…
iritkatrielJun 13, 2022
414e26a
remove two unused fields from struct assembler
iritkatrielJun 13, 2022
26dc190
define NO_LOCATION as a static const in global scope
iritkatrielJun 13, 2022
98d24f2
Merge remote-tracking branch 'upstream/main' into codegen-reduce-repe…
iritkatrielJun 14, 2022
7851ccd
Merge remote-tracking branch 'upstream/main' into codegen-reduce-repe…
iritkatrielJun 14, 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
PrevPrevious commit
NextNext commit
define static no_location in function scope
  • Loading branch information
@iritkatriel
iritkatriel committedJun 10, 2022
commitfc7455552ce1cafdbadf15d133aef72aff4ca50e
27 changes: 16 additions & 11 deletionsPython/compile.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,7 +159,7 @@ struct location {
#define LOCATION(LNO, END_LNO, COL, END_COL) \
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})

static struct locationNO_LOCATION= (LOCATION(-1, -1, -1, -1));
#defineNO_LOCATION (LOCATION(-1, -1, -1, -1))

struct instr {
int i_opcode;
Expand DownExpand Up@@ -1283,6 +1283,8 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
IS_BLOCK_PUSH_OPCODE(opcode));
assert(oparg == 0 || target == NULL);

static struct location no_location = NO_LOCATION;

int off = basicblock_next_instr(b);
if (off < 0) {
return 0;
Expand All@@ -1291,7 +1293,7 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
i->i_opcode = opcode;
i->i_oparg = oparg;
i->i_target = target;
i->i_loc = *loc;
i->i_loc =loc ?*loc : no_location;

return 1;
}
Expand All@@ -1304,7 +1306,7 @@ compiler_addop(struct compiler *c, int opcode, bool line)
return -1;
}

const struct location *loc = line ? &c->u->u_loc :&NO_LOCATION;
const struct location *loc = line ? &c->u->u_loc :NULL;
return basicblock_addop(c->u->u_curblock, opcode, 0, NULL, loc);
}

Expand DownExpand Up@@ -1512,7 +1514,7 @@ compiler_addop_i(struct compiler *c, int opcode, Py_ssize_t oparg, bool line)

int oparg_ = Py_SAFE_DOWNCAST(oparg, Py_ssize_t, int);

const struct location *loc = line ? &c->u->u_loc :&NO_LOCATION;
const struct location *loc = line ? &c->u->u_loc :NULL;
return basicblock_addop(c->u->u_curblock, opcode, oparg_, NULL, loc);
}

Expand All@@ -1522,7 +1524,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *target, bool line)
if (compiler_use_new_implicit_block_if_needed(c) < 0) {
return -1;
}
const struct location *loc = line ? &c->u->u_loc :&NO_LOCATION;
const struct location *loc = line ? &c->u->u_loc :NULL;
assert(target != NULL);
assert(IS_JUMP_OPCODE(opcode) || IS_BLOCK_PUSH_OPCODE(opcode));
return basicblock_addop(c->u->u_curblock, opcode, 0, target, loc);
Expand DownExpand Up@@ -7386,7 +7388,8 @@ push_cold_blocks_to_end(struct compiler *c, basicblock *entry, int code_flags) {
if (explicit_jump == NULL) {
return -1;
}
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &NO_LOCATION);
static struct location no_location = NO_LOCATION;
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &no_location);

explicit_jump->b_cold = 1;
explicit_jump->b_next = b->b_next;
Expand DownExpand Up@@ -8289,9 +8292,10 @@ static int
insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
int *fixed, int nfreevars, int code_flags)
{

assert(c->u->u_firstlineno > 0);

static struct location no_location = NO_LOCATION;

/* Add the generator prefix instructions. */
if (code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
struct instr make_gen = {
Expand All@@ -8306,7 +8310,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
struct instr pop_top = {
.i_opcode = POP_TOP,
.i_oparg = 0,
.i_loc =NO_LOCATION,
.i_loc =no_location,
.i_target = NULL,
};
if (insert_instruction(entryblock, 1, &pop_top) < 0) {
Expand DownExpand Up@@ -8338,7 +8342,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
.i_opcode = MAKE_CELL,
// This will get fixed in offset_derefs().
.i_oparg = oldindex,
.i_loc =NO_LOCATION,
.i_loc =no_location,
.i_target = NULL,
};
if (insert_instruction(entryblock, ncellsused, &make_cell) < 0) {
Expand All@@ -8353,7 +8357,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
struct instr copy_frees = {
.i_opcode = COPY_FREE_VARS,
.i_oparg = nfreevars,
.i_loc =NO_LOCATION,
.i_loc =no_location,
.i_target = NULL,
};
if (insert_instruction(entryblock, 0, &copy_frees) < 0) {
Expand DownExpand Up@@ -9359,7 +9363,8 @@ propagate_line_numbers(struct assembler *a) {
continue;
}

struct location prev_location = NO_LOCATION;
static struct location no_location = NO_LOCATION;
struct location prev_location = no_location;
for (int i = 0; i < b->b_iused; i++) {
if (b->b_instr[i].i_loc.lineno < 0) {
b->b_instr[i].i_loc = prev_location;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp