Forum Index
Suggested Enhancement: VB Structures

 
Author Message
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 19 February 2006, 23:48 PM    Post subject: Suggested Enhancement: VB Structures

It would seem that there is enough support in both the compiler and the runtime to add ZBasic language support for Visual Basic like structures.

Under the covers it could be implemented by the compiler using an array of bytes with temporary variable aliases for each data element. This means that there may be some restrictions such as they are fixed in size, can only be passed ByRef to routines and cannot contain strings. The compiler needs to generate the alias variables for each place a variable is declared that uses a structure type including parmaters. But this does not result in any additional memory usage.

Perhaps Don has already thought of this idea but has not yet implemented it in the compiler. The advantage of course is that the VM does not need to be changed. Here is some example code of how it might be used:
Code:
Public Structure MotorControl
   Public Speed as Integer
   Public Turn as Integer
   Public Brake as Boolean
End Structure

Public Sub Main()
   Dim control as MotorControl   
   Do
      Call SenseInputs()
      control.Speed = 5
      control.Turn = 2
      control.Brake = false
      Call DriveMotor(control)
   Loop
End Sub

Public DriveMotor(ByRef c as MotorControl)
End Sub
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 20 February 2006, 1:39 AM    Post subject:

Quote:
It would seem that there is enough support in both the compiler and the runtime to add ZBasic language support for Visual Basic like structures.


That is on the list and some of the supporting infrastructure already exists in the compiler internals. The address of the structure members resolves to the address of the parent structure plus a fixed offset. The most significant work yet to be done is with the type checking system.

Structures could be passed by value in the same way that String variables are. Internally, a reference is passed but the structure is read-only in the called routine and neither it nor any of its members can be passed by reference to other routines.
Back to top
victorf



Joined: 01 Jan 2006
Location: Schenectady, New York

Posted: 20 February 2006, 2:21 AM    Post subject:

I agree with mikep about the need for Structures in ZBasic. I was suprised and somewhat mystified to find that the language did not have them. When programming in VB and Delphi I am contantly using Structures/Records. I am happy to hear that they are "on the list". Smile

Vic
Back to top
stevech



Joined: 23 Feb 2006

Posted: 23 February 2006, 20:44 PM    Post subject:

yeah, lack of structures is kind of like going without shoes - slower going.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008, 2009, 2010 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group