Programmer Guide/Source code: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 2: Line 2:
==Source code==
==Source code==


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>.  
The '''source code''' is the text which is loaded, interpreted and executed by the [[Programmer_Guide/Programming#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.
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.  
 


==Section header==
==Section header==
The section header defines the visibility, type and the name of the source code contained in the source section. The section header must be enclosed within square brackets, where the opening bracket must be the first character in the line and there must not be any text behind the closing bracket expect comments.


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.
:;<code>[{<var>visiblity</var>:}<var>sstype</var> <var>ssname</var> {<var>ssargs</var>}]</code>
 
;<code>[{<var>visiblity</var>:}<var>sstype</var> <var>ssname</var> {<var>ssargs</var>}]</code>
 
E.g.:
:<code>[LOCAL:MACRO MacroExample1]</code>
:<code>[MACRO MacroExample2 #args]</code>


;<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.
;<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.
Line 23: Line 17:
::;MSGHANDLER: Defines a message handler macro, which can only be called from the system macros [[Programmer_Guide/Macro_Library/GETMESSAGE|GETMESSAGE]] or [[Programmer_Guide/Macro_Library/DISPATCHMSG|DISPATCHMSG]].
::;MSGHANDLER: Defines a message handler macro, which can only be called from the system macros [[Programmer_Guide/Macro_Library/GETMESSAGE|GETMESSAGE]] or [[Programmer_Guide/Macro_Library/DISPATCHMSG|DISPATCHMSG]].


;<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 meaningful for the STx scripting language. Other  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. The section type [[
;<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 meaningful for the STx scripting language. Other  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. The section script processing application uses the special types [[Programmer_Guide/Programming#BScript|Libraries]] and [[Programmer_Guide/Programming#BScript|Scripts]]. A source file can also contain other types of sections. If an unknown section type is detected by the loader, the section is ignored.
 
;<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>
;<var>ssname</var>: The name identifying this source code section. This is used to access the source code later on (e.g. to call a [[Programmer_Guide/Command_Reference/MACRO_and_SHELL|macro]], to create an [[Programmer_Guide/Shell_Items/SPU|spu item]], to create a [[Programmer_Guide/Shell_Items/Instance|instance item]] of a class, to derive a class, ...). . The name must be unique in the namespace where the source code is loaded, which is selected by the section type. Source sections of type [[#Define_a_Macro|macro]] and [[#Define_a_Class|CLASS]] are loaded into the same namespace. A separate namespace is used for [[#Define_a_SPU|SPU]] items.


: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.
;<var>ssargs</var>: The meaning of this part of the header depends on the type of the source section.


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 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.
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  


Examples:
:<code>[LOCAL:MACRO MacroExample1]</code>
:<code>[MACRO MacroExample2 #args]</code>:
:<code>[SPU DSPCircuit1 #in1 #in2 OUT #out1]</code>


=====Section body=====
The section body consists of statements (at least one is mandatory), empty lines (are ignored) and comments. The section body ends at the next section header or the end of the file.


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.
;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: starts with the tag '''<code>//</code>''' and ends at the end of the same line. E.g.
=====section header=====
:;block comment: is opened with the tag '''<code>/*</code>''' and closed with the tag '''<code>*/</code>'''. A block comment can be spanned over more than one line. If the begin and end tag of a block comment is on the same line, the comment is treated like a whitespace character, otherwise like a ''end of line''.
 
:Note that a comment open tag ('//' or '/*') can not be placed in a quoted string, where it is interpreted as normal text. Its also possible to escape the character of a comment tag (like: <code>`//</code>) to avoid its interpretation.
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.
 
<code>// this is a line comment</code>
 
=====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.
 
<code>/* this comment</code>
 
<code>spans a couple</code>
 
<code>of lines */</code>
 
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=====
=====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.
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.

Revision as of 13:27, 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.

Section header

The section header defines the visibility, type and the name of the source code contained in the source section. The section header must be enclosed within square brackets, where 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}]
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.
GLOBAL
The section code is visible everywhere. This is the default.
LOCAL
The section code is visible only for code inside the same source file. A local MACRO can only be called, and a local CLASS or SPU can only be instantiated from macros defined in the same source file.
MAIN
Defines the section code as the main macro of an STx application. A main macro must be called by the system macro AppMain. This keyword is defined for macro and class sections only, and should only be used for the main function of an STx application but not for scripts.
SHELL
Defines the section code as a shell startup code. This means, the macro implements the startup code of a command interpreter instance (shell) and can only be used in the SHELL. This keyword is defined 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 meaningful for the STx scripting language. Other types can also be used (e.g. to store data) and accessed via the SECTIONFILE macro or directly with the file item functions. The section script processing application uses the special types Libraries and Scripts. A source file can also contain other types of sections. If an unknown section type is detected by the loader, the section is ignored.
ssname
The name identifying this source code section. This is used to access the source code later on (e.g. to call a macro, to create an spu item, to create a instance item of a class, to derive a class, ...). . The name must be unique in the namespace where the source code is loaded, which is selected by the section type. Source sections of type macro and CLASS are loaded into the same namespace. A separate namespace is used for SPU items.
ssargs
The meaning of this part of the header depends on the type of the source section.

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

Examples:

[LOCAL:MACRO MacroExample1]
[MACRO MacroExample2 #args]:
[SPU DSPCircuit1 #in1 #in2 OUT #out1]
Section body

The section body consists of statements (at least one is mandatory), empty lines (are ignored) and comments. The section body ends at the next section header or the end of the file.

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
starts with the tag // and ends at the end of the same line. E.g.
block comment
is opened with the tag /* and closed with the tag */. A block comment can be spanned over more than one line. If the begin and end tag of a block comment is on the same line, the comment is treated like a whitespace character, otherwise like a end of line.
Note that a comment open tag ('//' or '/*') can not be placed in a quoted string, where it is interpreted as normal text. Its also possible to escape the character of a comment tag (like: `//) to avoid its interpretation.
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