summaryrefslogtreecommitdiff
path: root/pad.h
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-12-24 13:17:47 +0000
committerPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2023-02-10 12:07:02 +0000
commit99b497aa90ed7db99d29a301b47c91fba65c9cb3 (patch)
tree09e231f3a6838cdb2df9db9454981b9205046ba1 /pad.h
parentb40895ae558e0aff0c347785dafeaaff40a01801 (diff)
downloadperl-99b497aa90ed7db99d29a301b47c91fba65c9cb3.tar.gz
Initial attack at basic 'class' feature
Adds a new experimental warning, feature, keywords and enough parsing to implement basic classes with an empty `new` constructor method. Inject a $self lexical into method bodies; populate it with the object instance, suitably shifted Creates a new OP_METHSTART opcode to perform method setup Define an aux flag to remark which stashes are classes Basic implementation of fields. Basic anonymous methods.
Diffstat (limited to 'pad.h')
-rw-r--r--pad.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/pad.h b/pad.h
index 7f4a82c948..c857929b56 100644
--- a/pad.h
+++ b/pad.h
@@ -55,6 +55,8 @@ struct padnamelist {
# define PERL_PADNAME_MINIMAL
#endif
+struct padname_fieldinfo;
+
#define _PADNAME_BASE \
char * xpadn_pv; \
HV * xpadn_ourstash; \
@@ -62,6 +64,7 @@ struct padnamelist {
HV * xpadn_typestash; \
CV * xpadn_protocv; \
} xpadn_type_u; \
+ struct padname_fieldinfo *xpadn_fieldinfo; \
U32 xpadn_low; \
U32 xpadn_high; \
U32 xpadn_refcnt; \
@@ -87,6 +90,14 @@ struct padname_with_str {
#define PADNAME_FROM_PV(s) \
((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str)))
+/* Most padnames are not field names. Keep all the field-related info in its
+ * own substructure, stored in ->xpadn_fieldinfo.
+ */
+struct padname_fieldinfo {
+ PADOFFSET fieldix; /* index of this field within ObjectFIELDS() array */
+ HV *fieldstash; /* original class package which added this field */
+};
+
/* a value that PL_cop_seqmax is guaranteed never to be,
* flagging that a lexical is being introduced, or has not yet left scope
@@ -132,6 +143,8 @@ typedef enum {
#define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */
#define padadd_STALEOK 0x08 /* allow stale lexical in active
* sub, but only one level up */
+#define padadd_FIELD 0x10 /* set PADNAMEt_FIELD */
+#define padfind_FIELD_OK 0x20 /* pad_findlex is permitted to see fields */
/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
* whether PL_comppad and PL_curpad are consistent and whether they have
@@ -244,6 +257,10 @@ are often referred to as 'fake'.
=for apidoc m|bool|PadnameIsSTATE|PADNAME * pn
Whether this is a "state" variable.
+=for apidoc m|bool|PadnameIsFIELD|PADNAME * pn
+Whether this is a "field" variable. PADNAMEs where this is true will
+have additional information available via C<PadnameFIELDINFO>.
+
=for apidoc m|HV *|PadnameTYPE|PADNAME * pn
The stash associated with a typed lexical. This returns the C<%Foo::> hash
for C<my Foo $bar>.
@@ -330,9 +347,11 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
#define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn)
#define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
#define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s))
+#define PadnameFIELDINFO(pn) (pn)->xpadn_fieldinfo
#define PadnameOUTER(pn) (PadnameFLAGS(pn) & PADNAMEf_OUTER)
#define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEf_STATE)
#define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE)
+#define PadnameIsFIELD(pn) (PadnameFLAGS(pn) & PADNAMEf_FIELD)
#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE)
#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE)
@@ -342,6 +361,7 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
#define PADNAMEf_LVALUE 0x04 /* used as lvalue */
#define PADNAMEf_TYPED 0x08 /* for B; unused by core */
#define PADNAMEf_OUR 0x10 /* for B; unused by core */
+#define PADNAMEf_FIELD 0x20 /* field var */
/* backward compatibility */
#ifndef PERL_CORE