Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

You know love can endure.

- Stephen Stills, Rick Curtis and Michael Curtis

 

Aztec Primitive Classes

All Aztec primitive data types are treated as objects, and the user of the primitive classes have access to a large library of class methods. A primitive object is treated as a "value" by default, but it is also possible to use the reference to a primitive object as well. To maintain simplicity in the core language, there are only four primitive data types, as shown in the table below.

Aztec Primitive Data Types

 

♦ All primitive data types are objects, and they are treated as values by default. They are true Aztec objects, and all primitive classes have access to Base class methods.

♦ Aztec strings are true values at the language level. When two string objects are compared (String1 == String2), the contents of the two strings are compared.

♦ String constants can be surrounded by single quotes OR double quotes. A double quote is a valid text character within single quotes, and vice-versa.

♦ To use a double quote character inside a string constant that is surrounded by double quotes, two double quote characters are used together to represent a single double quote character within the string.

♦ Identical rules apply for strings surrounded by single quotes (two single quotes represent one single quote character).

♦ The Aztec Framework includes a large library of methods for all primitive data types.

♦ Each primitive class contains three sets of methods - instance methods, global methods and compiler methods - with similar naming conventions and argument lists for consistency.

♦ ‘compiler’ method  - Evaluated during compile-time processing
♦ global VM method  - VM global method returns value without modifying source
♦ instance VM method  - VM instance class method returns value and oftentimes modifies source

♦ All primitive instance and global methods are handled efficiently as internal VM instructions.

♦ This allows the language to significantly minimize the number of operators and still maintain maximium efficiency when working with primitive classes. Primitive class methods also provide a more elegant and flexible solution to primitive object manipulation than if the language had provided many more operators.

♦ The primitive methods are purposefully designed with relatively short names to facilitate their use in expressions, and similar naming conventions and argument lists are used between instance methods, global methods and compiler methods.

♦ The Aztec primitive class hierarchy is shown below, which also includes user defined enunmerations. All primitive data types are derived from Base. The "Enumerations" box is italicized since it is not an actual class. Every enumeration class, including 'bool', has a set of methods to operate on the enumeration object. They are created automatically by the Compiler when an enumeration is created. Each enumeration class has its own set of methods, but the naming is identical across all enumerations.

Aztec Primitive Class Hierarchy

 

♦ The Aztec 'int' data type is always treated as an 8 byte integer internally within the Compiler and Virtual Machine. However, the primitive class framework provides methods to manipulate the integer at 1, 2 and 4 byte levels and at the bit level as well. The stream I/O framework also provides mechanisms to read and write integers at the smaller sizes, so data interchange with other systems can easily be performed.

♦ Similarly, the Aztec 'float' data type is always treated as an 8 byte floating point number internally, but primitive class framework and stream I/O framework provide methods to treat the float object as a 4 byte floating point number.

♦ All primitive data types are defined in the ‘aztec.system’ space.

Aztec Primitive Class Methods

As already mentioned, every primitive class provides a large number of methods to operate on the data type. Each class also provides data constants related to size and potential limits for values of that data type. All primitive classes are documented in detail in the Aztec Class Framework section of the website. The following tables list a small subset of the available methods for each of the classes.

int Class Method Summary

Float Class Method Summary

String Class Method Summary

bool Class Method Summary

 

Each primitive class also provides data constants related to the size and potential limits for values of the primitive data type. A sampling is shown in the following table.

Primitive Class Constant Summary

 

Aztec Primitive Object References

The Aztec Programming Language supports the use of references for primitive data types. A primitive object is treated as a value by default, so it can be used directly within math and logical expressions. But the language also provides support to use the reference of a primitive object, providing the use of "pass by reference" arguments in a method, and other reference variable functionality.

♦ A reference variable to a primitive data type is defined using the “ref” keyword along with the data type (e.g. ‘data<int ref> IntRef’).

♦ We can take the reference of a global, local, shared class or instance class data item (value) by preceding it with the ‘@’ character.

♦ One interesting aspect of a primitive reference variable is that it is treated just like a normal primitive variable when it is used in an expression, so the language is very consistent in how the two are used (value versus reference).

♦ When a primitive reference variable is used without the '@' symbol before it, the language treats the reference variable as a primitive value, using the value of whatever primitive object the reference is currently "pointing at".

♦ The primitive reference variable can be thought of as primitive object that can be moved to overlay another primitive object, acting as a conduit to the overlaid object.

♦ When a primitive reference variable is used with the '@' symbol before it, the language treats the reference variable as a primitive reference.

♦ The following general rules define how a primitive object value or a primitive reference is treated, based on whether it is preceded with the ‘@’ operator:

♦ Uses ‘@’ and is the target variable for an assignment statement (e.g. 'Variable1' in the statement "@Variable1 = @Variable2")

♦ Sets a new reference for the primitive reference variable (i.e. overlay the reference variable on a different primitive object).
♦ This operation is not allowed for a primitive object value.

♦ Uses ‘@’ and is used in an expression (e.g. 'Variable2' in the statement "@Variable1 = @Variable2")

♦ Returns the reference of a primitive object, or null. If used with a primitive reference variable, it returns a reference to whatever primitive object the reference variable currently points at.
♦ If used with a primitive object value, it returns a reference to that object directly. The reference is guaranteed not to be null.

♦ No ‘@’ and is the target variable for an assignment statement (e.g. 'Variable1' in the statement "Variable1 = Variable2")

♦ For a reference variable, it sets a new primitive value for the object that the reference variable is currently pointing at. An exception will occur if the reference variable is null (does not point at anything).
♦ For a primitive object value, it simply sets a new primitive value for that object. This is always valid.

♦ No ‘@’ and is used in an expression  => Returns the primitive object value (e.g. 'Variable2' in the statement "Variable1 = Variable2")

♦ For a reference variable, it returns the primitive value for the object that the reference variable is currently pointing at. It returns null if the reference variable is currently not reference anything.
♦ For a primitive object value, it simply returns the primitive value for that object.

♦ It is possible to dynamically create a primitive object using new<>, which returns a reference to the newly allocated primitive object.

♦ Primitive references only support a single level of abstraction, and a reference always points directly at a valid primitive object or null.

♦ Primitive reference variables are also supported during compile-time logic.

♦ An example script showing the use of primitive objects, primitive references and primitive framework methods

#===================================================================================================
# Example Script: Aztec Primitive Classes Script
# Demonstrates use of Aztec primitive classes, primitive class framework, and primitive references.
#===================================================================================================

# Simple enumeration for use below to demo enum methods.
enum SingleDigits { zero, one, two, three, four, five, six, seven, eight, nine }

# Main run-time entry point for the script.
method Main
{
data<int> Count
data<int> IntTest
data<int> RandomInt
data<int> TotalResult
data<int> InternalKey = 113
data<string> EnumName
data<string> TotalString
data<string> EncryptedString
data<string ref> StringRef
data<SingleDigits> DigitEnum

#------------------------------------------------------------------------------------
# Get a random integer between 0 and 255 and analyze the bit settings. We will also
# manually build back up the same number based on bit settings - as demonstration.
#------------------------------------------------------------------------------------
RandomInt = int.Random(0,255)
iterate ( Count in 1..8 )
{
# If bit is on, add contribution from this term to result total (2**(n-1)).
if ( RandomInt.BitTest(Count) )
{
TotalResult.Add(2 ** (Count - 1))
}
}

StdIO.Write("Original random integer is " + RandomInt.Str())
StdIO.Write("Same number built up by bit analysis is " + TotalResult.Str())
StdIO.Write("Bit pattern for original random number is " + RandomInt.Str("B8"))

# Loop through several of the enumeration values and work with them using primitive methods.
for ( Count = 1 ; Count <= 4 ; Count.Inc() )
{
EnumName = SingleDigits.Enum(Count).Str()
StdIO.Write("SingleDigits name for index " + Count.Str() + " is '" + EnumName + "'")

# Use the name from the enum Str() method to get the enumeration back.
DigitEnum = SingleDigits.Enum(EnumName)
StdIO.Write("SingleDigits name (index to name to enum) is '" + DigitEnum.Str() + "'")
}

# Build up a string using random characters and then pad it to be a specific size.
iterate ( Count in 1..25 )
{
# Get random character from 65 - 90 (upper case letters) and add it to string.
TotalString.Add(IntChar(65 + int.Random(0,25)))
}

StdIO.Write("Padded string is '" + TotalString.Pad(45,'-',string.PadCenter) + "'")

# Encrypt the padded string and then decrypt it to get the original back.
EncryptedString = TotalString.Encrypt(InternalKey)
StdIO.Write("Encrypted string is '" + EncryptedString + "'")
StdIO.Write("Decrypted string is '" + EncryptedString.Decrypt(InternalKey) + "'")

# Get the reference of a string, then modify and display it via ref and from original.
@StringRef = @EncryptedString
StdIO.Write("Same decrypted string via ref is '" + StringRef + "'")
StdIO.Write("Same string to lower case via ref is '" + StringRef.Lwr() + "'")
StdIO.Write("Original string is changed to '" + EncryptedString + "'")

# Modify an integer by passing reference to method and it gets doubled.
IntTest = 100
StdIO.Write("Original integer is " + IntTest.Str())
DoubleInt(@IntTest)
StdIO.Write("Integer is now " + IntTest.Str() + " after being doubled via method")
}

# Method takes an integer reference and doubles the value of the referenced integer object.
method DoubleInt(int ref IntRefArg)
{
# Double the integer we're referencing.
IntRefArg.Mult(2)
}

Page UpPage DownCopyright © 2010-2017
Aztec Development Group
All Rights Reserved

Download Aztec