compiler icon indicating copy to clipboard operation
compiler copied to clipboard

#section implementation

Open YashasSamaga opened this issue 6 years ago • 5 comments

The language guide talks about #section pre-processor directive but it hasn't been implemented in the compiler.

#section name Starts a new section for the generated code. Any variables and functions that are declared “static” are only visible to the section to which they belong. By default, each source file is a separate section and there is only one section per file.

With the #section directive, you can create multiple sections in a source file. The name of a section is optional, if it is not set, a unique identifier for the source file is used for the name of the section. Any declared section ends automatically at the end of the file

If we could come up with the details of the feature, we could try to implement it.

YashasSamaga avatar Jun 15 '18 16:06 YashasSamaga

Do newer official versions of the compiler support this directive?

IS4Code avatar Jun 15 '18 16:06 IS4Code

Not as far as I know.

Southclaws avatar Jun 15 '18 17:06 Southclaws

I'm sure we discussed this not too long ago in discord. One thing I'd like is for named sections, where two sections given the same name count as the same scope. That way you can have variables which are module (package) local, but without putting everything in one file. Or I think the idea then was that this should only apply to section names that started with @, so it wouldn't change existing semantics too much without being quite explicit.

Y-Less avatar Jun 15 '18 23:06 Y-Less

To clarify the above comment:

#section A
static a;
#section A
static a;

Those are SEPARATE variables inaccessible from each other, since they are in separate sections. The name doesn't matter (for compatibility with existing documentation). UNLESS the name starts with @:

#section @A
static a;
#section @A
static a;

In that case that's a compile-time error, because all @A sections are compacted.

And two sections with the same @ name in different files will still be the same section.

Y-Less avatar Jul 06 '19 21:07 Y-Less

I got into this situation twice recently where I wished this feature had been implemented already. It would be nice to have it, at least minimally according to the Pawn documentation.

IS4Code avatar Feb 01 '22 18:02 IS4Code