Language Syntax extensions for Native Mode

A private (members-only) forum for discussing all issues related to the Beta test of Native mode devices.
Locked
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Language Syntax extensions for Native Mode

Post by mikep »

From another thread:
dkinzer wrote:
mikep wrote:Can the alias feature be applied to regular ZBasic sub/functions or only those that are declared?
Currently, an alias can only be defined for an external procedure via the Declare statement. I'm not sure what value there would be in allowing an alias for a normal ZBasic procedure.
I like a language syntax that is consistent. It makes it easy on both the parser in my PC and the one in my head. Exceptions mean confusion. There are 5 separate points in this append on language syntax, extensibility and consistency.

1. Consider the following declarations:

Code: Select all

Public foo as Long
Public bar as Integer Alias foo
Public Declare bar2 as Integer Alias foo2
Public Declare bar3 as Integer Alias "_foo3"
 
Public Sub fred()
Public Declare Sub bill()
Public Declare Sub jenny Alias "jennifer"()
Public Sub kate Alias katherine()
The last one is not allowed but nevertheless it doesn't do any harm either. There is also an inconsistency between the declarations of bill and jenny. Perhaps the following is better:

Code: Select all

Declare Public Sub jenny() Alias "jennifer"
Declare Public Function jenny() As Byte Alias "jennifer"
2. What about Consts? Why couldn't they be declared in an external source e.g.

Code: Select all

Public Declare Const frequency
Public Declare Const frequency2 Alias "_CPU"
3. The Dim keyword is not completely orthogonal with Public and Private and doesn't match Visual Basic (which is the grand-parent of ZBasic). For variables, the Dim keyword should be reintroduced and made optional only in the case needed for backwards compatibility e.g.

Code: Select all

Dim bar as Long
Public Dim bar2 as Integer Alias bar
Public Declare Dim bar3 as Integer Alias foo3
Public Declare Dim bar4 as Integer Alias "_foo4"
4. Looking at the Visual Basic syntax for variables, the attributes are placed before the access modifier. However I think their concept of attributes is different to the one in ZBasic. The concepts however could be combined by defining a single attribute (in VB terms) called UsageAttribute and written in VB syntax as follows:

Code: Select all

<Usage&#40;Used, Inline&#41;> Public Declare Sub bill&#40;&#41;
5. Taking this whole thought just one step further, it might be better to not use the Declare syntax at all and instead use the concepts from something like the VB WebMethodAttribute and call it something like "ExternalAttribute" e.g.

Code: Select all

<External&#40;"foo3"&#41;> Public Sub jenny&#40;&#41;
I'm just thinking (and perhaps over-architecting) the language syntax so that it is easy to make future extensions.
Mike Perks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Language Syntax extensions for Native Mode

Post by dkinzer »

mikep wrote:There is also an inconsistency between the declarations of bill and jenny.
The syntax for the Declare statement for external procedures is identical to that of VB6 (perhaps with the exception of Public/Private). I had thought about putting the Alias clause after the declaration to be more consistent with ZBasic Aliases but didn't due the VB6 precedent.

Another option is to abandon the Declare keyword and use Attribute(External) instead.
mikep wrote:What about Consts? Why couldn't they be declared in an external source
I don't know how the linkage would be done. Constants are resolved at compile-time whereas external linkages are resolved at link-time. What would the definition of a constant in an external C or asm source file look like? C has no constants other than preprocessor definitions; it does have the const attribute for variables.
mikep wrote:The Dim keyword is not completely orthogonal with Public and Private and doesn't match Visual Basic.
In what way does it not match VB. I'm fairly certain that VB6 doesn't allow "Public Dim" or "Private Dim".
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Re: Language Syntax extensions for Native Mode

Post by mikep »

dkinzer wrote:
mikep wrote:There is also an inconsistency between the declarations of bill and jenny.
The syntax for the Declare statement for external procedures is identical to that of VB6 (perhaps with the exception of Public/Private). I had thought about putting the Alias clause after the declaration to be more consistent with ZBasic Aliases but didn't due the VB6 precedent.

Another option is to abandon the Declare keyword and use Attribute(External) instead.
Now I look at the VB Declare definition, you are correct. I would submit that the VB syntax is poor too. You did extend the Declare syntax for variables as well and that is confusing with the other use of Alias for variables. Perhaps that would be a good reason to use the <External("foo3")> attribute syntax.
dkinzer wrote:
mikep wrote:What about Consts? Why couldn't they be declared in an external source
I don't know how the linkage would be done. Constants are resolved at compile-time whereas external linkages are resolved at link-time. What would the definition of a constant in an external C or asm source file look like? C has no constants other than preprocessor definitions; it does have the const attribute for variables.
Yes consider the code:

Code: Select all

static const int t = 5;
How would "t" be referred to from ZBasic code?
dkinzer wrote:
mikep wrote:The Dim keyword is not completely orthogonal with Public and Private and doesn't match Visual Basic.
In what way does it not match VB. I'm fairly certain that VB6 doesn't allow "Public Dim" or "Private Dim".
This syntax would lead you to think otherwise:

Code: Select all

&#91; <attributelist> &#93; &#91; accessmodifier &#93; &#91;&#91; Shared &#93; &#91; Shadows &#93; | &#91; Static &#93;&#93; &#91; ReadOnly &#93; Dim &#91; WithEvents &#93; variablelist
which came from this page. It also says that "If you specify one of the modifiers Public, Protected, Friend, Protected Friend, Private, Shared, Shadows, Static, ReadOnly, or WithEvents, you can optionally omit the Dim keyword."
Mike Perks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Language Syntax extensions for Native Mode

Post by dkinzer »

mikep wrote:Yes consider the code:

Code: Select all

static const int t = 5;
How would "t" be referred to from ZBasic code?
Currently, it wouldn't. Defining a constant in ZBasic doesn't result in any contribution to the intermediate C files for a data item with the constant's name. Rather, the compiler simply substitutes the stated constant value wherever the constant's name appears. To make the linkage to an externally defined const item, we'd have to add the ability to specify Attribute(Constant) on a Declare statement. This would mark the "variable" as read-only so the compiler wouldn't generate code to modify it.
dkinzer wrote:This syntax would lead you to think otherwise:
I believe that the page to which you referred is for a version of VB later than VB6. I confirmed that VB6 does not allow Dim together with Public or Private.
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Re: Language Syntax extensions for Native Mode

Post by mikep »

dkinzer wrote:I believe that the page to which you referred is for a version of VB later than VB6. I confirmed that VB6 does not allow Dim together with Public or Private.
Yes you correct. Taking a step back for a moment I can see that you are trying to stay within the VB6 language definition. I admit that newer versions of the .NET VB are somewhat different and may constitute too much of a change. Language design is hard and it is difficult to put consistent extensions on top of a language when the language itself is not completely consistent.

It should be noted that some of the constructs in ZBasic are extensions to VB6 such as aliased and declared variables and the new Attribute keyword (I think).
Mike Perks
Locked