Snap! Websites
An Open Source CMS System in C++
#include <options.h>
Each option is an integer of this type. The type is at least 32 bits.
Most options just use 0 (false/not set) or 1 (true/set). However, some options may use other values. In most cases the value will be used as a set of flags:
This enumeration defines all the options available in the compiler. Additional options may be available in the command line tool, but these are all those supported in the code via the 'use' keyword (i.e. pragma) and expected to be command line options to the command line tool.
EnumeratorOPTION_UNKNOWNUnknown option, used as a fallback in different situations.
This is not really an option. It is used as a fallback in a few situations where some otion is required, but none is really available to do the job.
OPTION_ALLOW_WITHWhether the 'with' keyword can be used.
By default the 'with' keyword is forbidden by as2js. You must explicitly allow it to use it with:
In general, the 'with' statement is considered as deprecated and it should not be used because the order in which objects are checked for a field found inside a with statement is undefined. Because of that, it is not possible to make sure that code within a 'with' statement does what it is expected to do.
In other words, it is not secure.
Note that if the compiler is set in strict mode, the 'with' statement is not allowed, whether or not this flag is turned on.
OPTION_BINARYWhether binary numbers are allowed.
By default, binary numbers are not supported. If this option is turned on, then the compiler recognizes binary numbers.
The syntax of a binary number is: ('0' 'b' ['0'-'1']+)
For example, 170 in binary:
JavaScript does not support the binary notation at all. However, the introducer '0b' is not compatible is a welformed JavaScript source file.
Whether coverage is requested.
AlexScript includes the necessary support to generate coverage code. This is used to know whether your tests are thorough and really test all the code.
It is possible that your code becomes very slow because of this option. Code that you use in a loop or that generally needs to be fast may require that you surround that code with pragmas to temporarilly turn the coverage off:
A future version will allow you to push/pop the current status so you do not have to delete the pragmas once done running your tests.
Turn on debug features.
AlexScript supports a set of debug features, which still need to be implemented, to help you find problems in your code.
The debug option turns on those features and autmoatically adds debug code in the output so you can easily find problems in your source.
OPTION_EXTENDED_ESCAPE_SEQUENCESAccept additional escape sequences in strings.
This options authorizes the compiler to transform escape sequences that are otherwise forbidden in JavaScript. The compiler will automatically transform those to a valid supported value in the final output.
The extensions are:
Note that "\0" is always accepted and it represents the NUL character.
OPTION_EXTENDED_OPERATORSAccept additional operators.
AlexScript offers additional operators to cover some operations that are fairly common in programming and most often annoying to write by hand.
When this option is turned off, those extended operators are recognized so everything continues to compile, but the parser generates errors on each one found. When this option is set to a value other than zero, the extended operators are accepted.
The supported extensions are:
...
' – allow regular expressions to be written without the use of the standard /.../ syntax which can be confused when used improperly (i.e. the '/' is used by comments, divisions, assignments...)This option has an extended feature which is to use flag 1 as a mean to authorize (0) or forbid (1) the use of the '=' character as the assignment operator. In other words, the following code is normal AlexScript code:
which fails with an error when bit 1 of the OPTION_EXTENDED_OPERATORS value is set. So the following will NOT compile:
There is another extended operator which is the Pascal assignment operator: ':=', which must be used to replace the '=' operator. This the statment we've just see can be rewritten as:
The idea is simple: it is much less likely that you would mistakingly use ':=' instead of '=='. Also, at some point we want to completely forbid assignments in expressions and instead only allow them as statements (as done in Ada and Pascal). This way you avoid potential problems with lines of code such as:
which is the same as:
since (a = 3) returns 3 and that is viewed as always true and it is probably a bug. In other words, the programmer probably meant:
With a feature saying that assignments have to be writte as statements, the if(a = 3)
statement is not legal because in that case the assignment is in an expression.
Accept additional statement structures.
AlexScript offers additional capabilities while parsing your code.
The following is the list of statements that are available to you when the extended statement option is set:
This option can also have bit 1 set to trigger the 'force a block of statements' here feature. When writing code, one can use one liners such as:
This is all good until the programmer notices that he needs a second line of code and writes:
As we can see, the second statement does not depend on the if() BUT if you do not pay close attention, the fact that the curvly brackets are missing may not be obvious. Bit 1 of the extended statement option is used to force the programmer to use such statements with curvly brackets, ALWAYS.
Note that if you do not put the curvly brackets to save space in the final JavaScript code, know that our assembler will do that for you automatically. So you do not have to worry about that in your AlexScript source code.
Change the lexer to read data for our JSON implementation.
The js2as library includes a JSON parser. It will force this option to 1 when using the lexer from that parser. This tells the lexer that a certain number of characters (such as 0x2028) are to be viewed as standard characters instead of specialized characters.
Whether octal numbers are allowed.
By default, octal numbers are not supported. If this option is turned on, then the compiler recognizes octal numbers.
The syntax of an octal number is: ('0' ['0'-'7']+)
For example, 170 in octal:
JavaScript does supports the octal notation. However, it is forbidden in strict mode and it is not considered safe so we only use decimal numbers in the output.
Whether strict mode is turned on.
By defaut, just like JavaScript, the compiler accepts 'weak' code practices. This option turns on the strict mode of AlexScript.
Note that by default AlexScript is already way strictier than the standard JavaScript. For example, semi-colons are required everywhere. On the other hand, AlexScript allows break and return statements to be written on multiple lines.
The following is legal code, even in strict mode:
We may look into fixing these, although the only reason for JavaScript to disallow this syntax is to allow missing semi-colons so it is not really important. We will always output semi-colons after each line in our output.
OPTION_TRACETurn on trace mode.
This option requests that trace mode be turned on.
Trace mode is a feature from AlexScript which adds code to trace each "statement" just before it gets executed. We put statement between quotes because in many cases it is more like a line of code (i.e. an if(...) statement includes the block of statements, the else and the blocks following the else, and in that case the trace only shows the if() and its expression.)
The trace feature makes use the Trace package which can be tweaked to your liking. The Trace object records the information from the original source file such as the line number, file name, options, etc.
OPTION_UNSAFE_MATHTell the optimizer whether to apply unsafe mathematical optimizations.
Many operations in JavaScript look like they can be optimized. For example:
All of these operations have side effects. The bitwise operations first transform the contents of variable 'a' to 32 bits integer, then apply the operation, and finally save the result back in a double. In other words, the bitwise operations presented here are equivalent to a &= 0xFFFFFFFF;
.
The multiplication first transforms 'a' into a number, then multiplies by 1, and finally saves the result in 'a'. If 'a' was a string, it applies a conversion which may be important when using 'a' later (i.e. some functions you call may check whether 'a' is a number.)
The concatenation in the last statement transforms the variable 'a' to a string. You could also have used the a.toString()
function.
When the unsafe math option is turned on, many of these operations will get optimized anyway. In all the examples shown above, the optimizer would simply remove the entire statement. The result is different and thus it may not work right, this is why we offer this option because at times you may want to turn off the pragma.
In most cases, it is not recommended to use this option.
OPTION_maxGives the number of options defined.
This is not an option. It is used to define arrays of options as all options are numbered from 0 to OPTION_max - 1.
The default constructor initializes the options array to the maximum number of options. The options are all set to the default, zero (0).
To change the option value, use the set_option() function. At this point pretty much all the options accept either 0 or 1 as their value, although any number of than 0 is considered to represent "set".
Definition at line 583 of file options.cpp.
This function is used to retrieve the current value of an option. At this point, all options are expected to be zero (0), the default, or one (1). It is possible to set options to other values, though.
Definition at line 618 of file options.cpp.
References f_options.
This function sets the option to the specified value.
At this point, all options expect the value to be 0 or 1, although the system does not enforce that at this point. Any value is thus accepted.
Options make use of an int64_t so any 64 bit values works.
Definition at line 602 of file options.cpp.
References f_options.
When creating an Options object, you get a set of options defined in this f_options variable member.
By default all the options are considered to be set to zero. So if no option object was created, you may assume that all the values are set to zero.
If you then want to modify an option to a value other than zero (0) then you must allocate an Options object and use the set_option() function to set the value accordingly.
Definition at line 83 of file options.h.
Referenced by get_option(), and set_option().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.
Snap! Websites
An Open Source CMS System in C++