Problems with python internal data structures

Hi,

I’ve finally given up going round in circles. I’m trying to modify Python but I’m really confused over which data structure gets used where …

I’ve been playing with “ideas” and “macro3” for a while and am now trying to make deeper changes. I’m using the source code for Python 3.10.7 on Ubuntu. Out of the box I found it really straight forward to build and test it. I’m only doing this to find out how things work. Not to solve any real problem.
So I got down to work.
My first target was to implement an approximately equals condition for floating point comparisons, x ~= y using a similar algorithm to math.isclose. This mostly worked though it is a bit unreliable and seg. faulted if x and y weren’t floats, sometimes. A problem for a later day.

Now I’ve moved onto the second of my targets, a statement to do dictionary unpacking. Inspired by a recent post on the “ideas discuss” pages. Specifically

{a,b, c} = **d

should unpack and assign the keys a, b and c from d, i.e a = d[a].

The basic grammar worked when I got the parser to call a tailor made function in Parser/pegen.c. I was able to retrieve all the names. I moved on to trying to get closer to generating code. I added a line to Python.asdl

| dup(identifiers* targets, identifier source)

and I added a line to the grammar

dup_stmt[stmt_ty]: ‘{‘ targets[asdl_identifer_seq*]=star_targrts ‘}’ ‘=’ ‘**’ source[identifier]=NAME _PyAST_Dup(targets, source, EXTRA)}

I can get it to build with empty stubs in symtable.c, compile.c etc. But concentrating on symtable.c I can get the correct type but when I try and access the targets I can’t even get the number of identifiers. See my code in contex.

    case AugAssign_kind:
        VISIT(st, expr, s->v.AugAssign.target);
        VISIT(st, expr, s->v.AugAssign.value);
        break;
	case Dup_kind:// Johns dictionary unpacking, does nothing,
		{ 
			FILE* f;
			int k = s->kind;
			asdl_identifier_seq *seq = s->v.Dup.targets;
			int si  = asdl_seq_LEN(seq);
			f = fopen("Test.txt", "a");
			fprintf(f, "Sym Table\n");
			fprintf(f, "ID: %d %d\n",  k, si);
			fclose(f);
		}
		break;
    case For_kind:
        VISIT(st, expr, s->v.For.target);
        VISIT(st, expr, s->v.For.iter);
        VISIT_SEQ(st, stmt, s->v.For.body);
        if (s->v.For.orelse)
            VISIT_SEQ(st, stmt, s->v.For.orelse);

si appears to be an arbitary large integer (an arbitary memory location!). I’m just trying to check if I can access the identifiers. I’m pretty sure I’m using the wrong data types, but I cant find anything that works for me even after spending hours reading and greping

I’d be grateful if some one could give me some pointers on how to get past this stage. Any links to aditional documentation would be useful as well.

Thanks in advance

John

PS I’ve been using Python since 1.4 but now I’m retired I thought I would find out more about how it all works.