Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce symbol table API into pad #22850

Open
wants to merge 41 commits into
base: blead
Choose a base branch
from

Conversation

happy-barney
Copy link

Changes summary

For purpose of this changes let's distinguish between:

  • sigil - expression type representation in source code
  • symbol type - internal identification of symbol type

For implementation of sigil-less symbols we will still need their symbol type, eg:

  • attributes
  • named patterns
  • data contracts
  • ...

replace literals representing type of symbol stored in pad with explicit tokens

For example, '&' in code can mean also:

  • subroutine symbol type
  • subroutine sigil
  • code-block prototype
  • predefined variable name

This set of changes replaces its usage as symbol type with C token Perl_Symbol_Table_Code.

Extend padname API with "split" macros

Instead of relying on layout of string content explicit macros providing symbol type and symbol name are introduced, eg:

// current approach:
*PadnamePV (pn)
PadnamePV (pn)[0]

// new approach
Padname_Symbol_Table (pn)
  • change allows to change underlying data type and values (eg to index to registry array)
  • using explicit token expresses intention and makes it easier to search code base

Provide padname functions with split symbol type and symbol name parameters

Alternatives to existing functions but with two parameters.
Example:

// current
pad_add_name_pvs("$(self)", 0, NULL, NULL);

// new approach
pad_add_symbol_pvs (Perl_Symbol_Table_Scalar, "(self)", 0, NULL, NULL);

Possible follow-ups

  • replace more characters literals with macros, eg:
    • Perl_Var_Match
    • Perl_Prototype_Code
  • provide builtin symbol table registry
  • use this approach also with global symbols

Open questions

  • what (if anything) to put into perldelta ?
  • mark old functions as deprecated ?

Branislav Zahradník added 29 commits December 10, 2024 11:51
…fication

Using dedicated C tokens instead of literal values will improve readability
of source code by separating intention from other usages of literal characters:
- sigil (as language structure)
- predefined variable name
- prototype

It will also make it feasible to add functionality, like
- new sigil-less symbol tables (attributes, patterns, contracts, ...)
- add support for custom symbol tables
…m symbol table

Returns true value when provided `PADNAME *` represents symbol belonging
to provided symbol table.
By wrapping implementation into single intent expressing token
it can evolve without affecting its usage.
Using macro instead of direct access:
- identifies code where such value is used / required
- hides any future changes from code which uses it, eg
  - type change from 'char' to 'U32'
Returns name without symbol type so it will properly work
when we will change symbol table id type or when we will add new
symbol types.

For backward compatibility user of this macro can rely on -1 being
valid index.
stored in pad, excluding symbol table id (sigil)

eg:
- `$` => 0
- `$_` => 1
- `$self` => 4
into handy macros to avoid code duplication as well as
simplify future changes.
eg: scalar, array, and hash are "variable"
Move printf format and proper expansion of parameters,
into macros so when code evolves, it will be isolated
from usage.
extracting common part of condition and using `Perl_Symbol_Table_*` constants
…nts first

Common problem is when macro expands as multiple arguments.
Without intermediate step allowing to expand arguments before
macro call there will be an error due treating such expansion as
single argument.
@jkeenan
Copy link
Contributor

jkeenan commented Dec 10, 2024

What is the point of this very large change? AFAICT, it's not a bug fix or a response to an open issue. Does it respond to some previously expressed need?

@happy-barney
Copy link
Author

@jkeenan already discussed that on IRC, this PR is quite huge, it in fact combines parts of 3 changesets (in my eyes, maybe more by someone else)

I will extract first two changes into separated PRs, each announced first for discussion on mailing list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants