Skip to content

Change the interpreter definition DSL to be legal C syntax #477

Closed
@markshannon

Description

@markshannon

The proposed DSL for defining the interpreter has sound semantics, but the syntax is problematic due to lack of tooling.
We want to be able to edit and view the code in standard tools.

The 3.11 (and earlier) instructions definitions are understood by tools that understand C, we want to retain that.

To do that we need to change the DSL to be a subset of C, as follows:

  • The definition file will start with macro and function declarations to enable C tooling to understand the following definition. Our tooling will ignore that section.
  • Definitions will change from kind NAME ... to kind "(" NAME ")" ...
  • The stack effect will be embedded in a C comment ( -- value) becomes /* -- value */
  • Sequences will be need to become C expressions, so CHECK_OBJECT_TYPE LOAD_SLOT becomes CHECK_OBJECT_TYPE + LOAD_SLOT
  • Stream values will be indicated by multiplication, #index becomes index*1 and ##version becomes version*2.

From the examples,

inst LOAD_ATTR_SLOT = #counter CHECK_OBJECT_TYPE LOAD_SLOT ####unused;

becomes

inst(LOAD_ATTR_SLOT) = counter*1 + CHECK_OBJECT_TYPE + LOAD_SLOT  + unused*4;

Alternatively we could define S1, S2 and S4 for values in the instruction stream:

inst(LOAD_ATTR_SLOT) = S1(counter) + CHECK_OBJECT_TYPE + LOAD_SLOT  + S4(unused);

The definition of LOAD_FAST changes from:

inst LOAD_FAST ( -- value ) {
        value = frame->f_localsplus[oparg];
        Py_INCREF(value);
    }

to:

inst(LOAD_FAST)
/* -- value */
{
    value = frame->f_localsplus[oparg];
    Py_INCREF(value);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic-generatorDSL-based code generator for the interpreter(s)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions