Skip to content

The Section Identifier

Raph Hennessy edited this page Nov 21, 2015 · 3 revisions

In Q PL, your code is divided up into a number of sections. Although this might seem to be purely for easy readability, when you do not comply to a valid sectioning setup in your code files, your Q PL code will fail to compile.

A simple section identifier looks like the example below.

section "mySection" {
    ## Your Code Here
}

The above code example is a valid declaration for a section called mySection. This is obviously not a required section but each required section in a Q PL code file is discussed below in the appropriate section of the file.

The Meta Section

Within the meta section of a Q PL file, you are able to declare metadata that the compiler will read but not put into the final output. Unlike comments, the compiler understands what you put in the meta area but like comments, it is not put into the final output.

A meta section is required in every Q PL file since the file extension for all code in Q OS is .code and the compiler needs to know what kind of code you have in your file. A valid meta section is shown below.

section "meta" {
    make meta language;
    set language = 'q';
}

The above example is the minimum amount of code you can have in your meta section for your code to compile. Without this, the compiler will not know what language you are programming in and thus will fail to compile and generate an error log. If you want to include more information in your meta section, however, it is perfectly accepted by the compiler so long as you do not use make statements that are not listed below.

## This is the only required make statement 
make meta language;

## These ones are optional if you want to add more information to the meta area of your code
make meta title;
make meta author;
make meta description;
make meta keywords;

If you create variables in the meta section that do not have the names listed above, it will likely generate warnings or errors and prevent your code being compiled correctly.

The Data Section

Like in the Assembly Language, files in Q PL must have a data and a text section. Unlike Assembly, however, they do not need to have a bss section. They do, instead, have the meta section as described above.

The Data section has almost the exact same purpose as in Assembly. It is used to declare and set the initial values of variables in your program. If you use any statements in the data section except for make and set, the Compiler will give you errors.

A valid data section can be completely empty except the section declaration at the start and end. The example below is the minimum you can include in your data section.

section "data" {
    ## This is the data section we can put stuff here
}

Obviously you probably want some things in your data section or your program will have no variables in it. Another example of a valid data section is below, however it includes some variable declarations unlike the other one.

section "data" {
    ## Below we are creating a `string` variable called `myCoolString`
    make string myCoolString;

    ## Below we are creating a `integer` variable called `aCoolInteger`
    make integer aCoolInteger;

    ## Finally, below this we are making an `array` type variable called `myArray`
    make array myArray;

    ## Now, let's set the value of `myCoolString` to "Hello World"
    set myCoolString = "Hello World";
}

As you can see, we have a few comments and a few variable declarations in this example. We also set the value of myCoolString to Hello World at the end of the section.

Overall, the data section can only include set and make statements, and is the only place in your program that you can declare variables to use in the text section in. It is important to note, however, that the make statement can actually be used outside of the data section. This is only permitted inside function blocks and the variables created inside function blocks are not accessible anywhere outside them. It is also permitted to use the make statement inside for block headers and again these are only accessible inside the associated for block.

Clone this wiki locally