Programmer Guide/Source code: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
====Source code====
==Source code==


The source code is the text which is interpreted and executed by the <code>BScript</code> application. Examples of S_TOOLS-STx scripts can be found in the directory Examples in the S_TOOLS-STx installation directory.
The '''source code''' is the text which is loaded, interpreted and executed by the [[User_Guide/BScript|BScript]] application. Examples of scripts can be found in the directory scripts\examples in the S_TOOLS-STx installation directory. A '''source file''' is a text file containing source code. By convention, source files end with the extension <code>sts</code>.
S_TOOLS-STx source files use a '''section file format''', where each section starts with a section header. Each source section delineates a section of source code. The code runs from the header to the next header, or to the end of the file. The section header defines the visibility, type and the name of the source code contained in the source section.


=====source file=====


A source file is a text file containing source code. By convention, source files end with the extension <code>sts</code>. S_TOOLS-STx source files use a section file format, where each section starts with a section header.
==Section header==


=====source section=====
The section header is defined within square brackets as follows. The opening bracket must be the first character in the line and there must not be any text behind the closing bracket expect comments.


Each source section delineates a section of source code. The code runs from the header to the next header, or to the end of the file.
<code>[{<var>visiblity</var>:}<var>sstype</var> <var>ssname</var> {<var>ssargs</var>}]</code>


A source file can also contain other types of sections. If an unknown section type is detected by the loader, the section is ignored. User defined sections can be used to store setup data or any other types of data and can be accessed with the macro <code>SECTIONFILE</code> or with a shell file item.
E.g.:
:<code>[LOCAL:MACRO MacroExample1]</code>
:<code>[MACRO MacroExample2 #args]</code>


=====section header=====
;<var>visibility</var>: The visibilty of a section defines from where the source code object can be accessed, instantiated or called. The following visibility keywords are currently supported.
:;There are currently four supported visibility values:


The section header defines the visibility, type and the name of the source code contained in the source section.
:<code>GLOBAL</code> - the section code is visible everywhere.


The header name must be unique in the source file. The type is used by S_TOOLS-STx to select the namespace and the loader which is used to load the source code. The name is used to access the source code (e.g. to call a macro, to create an spu item, to create a instance item of a class, to derive a class, ...). Source sections of type <code>MACRO</code> and <code>CLASS</code> are loaded into the same namespace. A separate namespace is used for <code>SPU</code> items.
:<code>LOCAL</code> - the section code is visible only for code inside the same source file.


======section header syntax======
:<code>MAIN</code> - defines the section code as the main application macro. This must be called from <code>APPMAIN</code> (for <code>MACRO</code> and <code>CLASS</code> sections only)


The section header is defined within square brackets as follows:
:<code>MSGHANDLER</code> - defines a message handler macro, which can only be called from the system macros <code>GETMESSAGE</code> or <code>DISPATCHMSG</code>.


<code>[ {</code> <var>visiblity</var><code>: }</code> <var>sstype</var> <var>ssname</var> <code>{</code> <var>ssargs</var> <code>} ]</code>


E.g.


<code>[LOCAL:MACRO MacroExample1]</code>


or
;<var>sstype</var>: Defines the type of source code in the section. The types [[#Define_a_Macro|MACRO]], [[#Define_a_Class|CLASS]] and [[#Define_a_SPU|SPU]] are defined in the scripting language. User-defined types can also be used (e.g. to store data) and accessed via the [[Programmer_Guide/Macro_Library/SECTIONFILE|SECTIONFILE]] macro or directly with the [[Programmer_Guide/Shell_Items/File|file item]] functions.


<code>[MACRO MacroExample2 #args]</code>
;<var>ssname</var>


The parameters <var>sstype</var> and <var>ssname</var> are mandatory for the built-in types <code>MACRO</code>, <code>CLASS</code> and <code>SPU</code>, whilst <var>visibility</var> and <var>ssargs</var> are optional.
:The name identifying this source code section. This is used to access the source code later on. The name must be unique in the namespace where the source code is loaded.


;<var>visibility</var>
;<var>ssargs</var>


:There are currently four supported visibility values:
:The meaning of this part of the header depends on the type of the source section. See <code>MACRO</code>, <code>CLASS</code> and <code>SPU</code> for details.


:<code>GLOBAL</code> - the section code is visible everywhere.
The parameters <var>sstype</var> and <var>ssname</var> are mandatory for the built-in types <code>MACRO</code>, <code>CLASS</code> and <code>SPU</code>, whilst <var>visibility</var> and <var>ssargs</var> are optional.
The header name must be unique in the source file. The type is used by S_TOOLS-STx to select the namespace and the loader which is used to load the source code. The name is used to access the source code (e.g. to call a macro, to create an spu item, to create a instance item of a class, to derive a class, ...). Source sections of type <code>MACRO</code> and <code>CLASS</code> are loaded into the same namespace. A separate namespace is used for <code>SPU</code> items.


:<code>LOCAL</code> - the section code is visible only for code inside the same source file.


:<code>MAIN</code> - defines the section code as the main application macro. This must be called from <code>APPMAIN</code> (for <code>MACRO</code> and <code>CLASS</code> sections only)


:<code>MSGHANDLER</code> - defines a message handler macro, which can only be called from the system macros <code>GETMESSAGE</code> or <code>DISPATCHMSG</code>.
A source file can also contain other types of sections. If an unknown section type is detected by the loader, the section is ignored. User defined sections can be used to store setup data or any other types of data and can be accessed with the macro <code>SECTIONFILE</code> or with a shell file item.


;<var>sstype</var>
=====section header=====


:Defines the type of source code in the section. The types <code>MACRO</code>, <code>CLASS</code> and <code>SPU</code> are defined in the S_TOOLS-STx scripting language. User-defined types can also be used (e.g. to store data) and accessed via the <code>SECTIONFILE</code> macro. See Macros, Classes and SPUs for an explanation of macro types.
The section header defines the visibility, type and the name of the source code contained in the source section.
 
;<var>ssname</var>
 
:The name identifying this source code section. This is used to access the source code later on. The name must be unique in the namespace where the source code is loaded.


;<var>ssargs</var>
:The meaning of this part of the header depends on the type of the source section. See <code>MACRO</code>, <code>CLASS</code> and <code>SPU</code> for details.


If a class or an spu is defined with local visibility, instances of the class/spu can only be created by macros/classes defined in the same source file.=====source code=====
If a class or an spu is defined with local visibility, instances of the class/spu can only be created by macros/classes defined in the same source file.=====source code=====

Revision as of 10:49, 23 March 2011

Source code

The source code is the text which is loaded, interpreted and executed by the BScript application. Examples of scripts can be found in the directory scripts\examples in the S_TOOLS-STx installation directory. A source file is a text file containing source code. By convention, source files end with the extension sts. S_TOOLS-STx source files use a section file format, where each section starts with a section header. Each source section delineates a section of source code. The code runs from the header to the next header, or to the end of the file. The section header defines the visibility, type and the name of the source code contained in the source section.


Section header

The section header is defined within square brackets as follows. The opening bracket must be the first character in the line and there must not be any text behind the closing bracket expect comments.

[{visiblity:}sstype ssname {ssargs}]

E.g.:

[LOCAL:MACRO MacroExample1]
[MACRO MacroExample2 #args]
visibility
The visibilty of a section defines from where the source code object can be accessed, instantiated or called. The following visibility keywords are currently supported.
There are currently four supported visibility values
GLOBAL - the section code is visible everywhere.
LOCAL - the section code is visible only for code inside the same source file.
MAIN - defines the section code as the main application macro. This must be called from APPMAIN (for MACRO and CLASS sections only)
MSGHANDLER - defines a message handler macro, which can only be called from the system macros GETMESSAGE or DISPATCHMSG.



sstype
Defines the type of source code in the section. The types MACRO, CLASS and SPU are defined in the scripting language. User-defined types can also be used (e.g. to store data) and accessed via the SECTIONFILE macro or directly with the file item functions.
ssname
The name identifying this source code section. This is used to access the source code later on. The name must be unique in the namespace where the source code is loaded.
ssargs
The meaning of this part of the header depends on the type of the source section. See MACRO, CLASS and SPU for details.

The parameters sstype and ssname are mandatory for the built-in types MACRO, CLASS and SPU, whilst visibility and ssargs are optional. The header name must be unique in the source file. The type is used by S_TOOLS-STx to select the namespace and the loader which is used to load the source code. The name is used to access the source code (e.g. to call a macro, to create an spu item, to create a instance item of a class, to derive a class, ...). Source sections of type MACRO and CLASS are loaded into the same namespace. A separate namespace is used for SPU items.


A source file can also contain other types of sections. If an unknown section type is detected by the loader, the section is ignored. User defined sections can be used to store setup data or any other types of data and can be accessed with the macro SECTIONFILE or with a shell file item.

section header

The section header defines the visibility, type and the name of the source code contained in the source section.


If a class or an spu is defined with local visibility, instances of the class/spu can only be created by macros/classes defined in the same source file.=====source code=====

The source code within a section may consist of statements (at least one is mandatory), empty lines (are ignored) and comments.

During loading (when you run a script, it is first loaded), the source code is parsed, the statements are precompiled and all empty lines and comments are ignored.

comments

A comment is part of the source code which is used for documentation purposes and is ignored by the loader. A comment can be placed anywhere, where a whitespace character is allowed. The standard C++ comment tags can be used in S_TOOLS-STx source code:

line comment:

A line comment starts with the tag '//' and ends at the end of the same line. E.g.

// this is a line comment

block comment:

A block comment is opened with the tag '/*' and closed with the tag '*/'. A block comment can be spanned over more than one line. E.g.

/* this comment

spans a couple

of lines */

Note that a comment open tag ('//' or '/*') can not be placed in a quoted string. In quoted strings comment tags are interpreted as normal text.

statements

A statement is the part of a line which remains after removing comments, and leading and trailing white space. In macros and classes, statements are label definitions and/or commands. In SPUs, the statements are used to define and connect the circuit elements.

Navigation menu

Personal tools