- Van Morrison
#===================================================================================================
# Example Script: Aztec Basic Syntax and Statement Usage Example
# Demonstrates basic Aztec syntax, operators, expressions and valid statement usage.
#===================================================================================================
# Data items defined at the module level using default "space".
data<int> compiler CompilerData1 = 0xff # Init in hex (255 dec)
data<string> compiler CompilerData2 = "Test"
data<int> const ModuleData1 = 0b10101010 # Init in binary (170 dec), visible in module
data<int> ModuleData2 = 0b11111111 # Init in binary (255 dec), visible in module
# Assignment and Method Call statements can be used at module level for compile-time logic.
CompilerData1 = ModuleData1 + 10
CompilerMethod1(CompilerData2)
# Compiler method defined and visible at the module level.
method compiler CompilerMethod1(string Arg1)
{
CompilerWriteLog("Inside compiler method 1 with arg " + Arg1)
}
# Normal (run-time) method defined at module level - visible everywhere due to 'public'.
public method RunTimeMethod1(int Arg1)
{
StdIO.Write("Inside normal method 1 with arg " + Arg1.Str())
}
# Public data item to be used at run-time.
public data<int> GlobalData3 = 0b01 # Init in binary (1 dec), visible in module
# Define a new method reference data type and a new enumeration.
type<method> SimpleMethodRef # Reference to method with no args and no return value.
enum SimpleEnum { abc, def, lmnop, wxyz }
# Run-time entry point for the script.
method Main()
{
data<int> Count
data<Test1> MyTest1 = new<Test1>
data<SimpleMethodRef> MyMethRef
data<SimpleEnum> MyEnum = SimpleEnum.lmnop
data<string[]> TestStrings = { "String with double quotes",
'String with single quotes',
"String with 'embedded' quotes",
'String with ''embedded'' quotes',
'String with "embedded" quotes',
"String with ""embedded"" quotes" }
# Loop through string array and dump each one.
iterate ( Count in 1..TestStrings.Size() )
{
StdIO.Write("String " + Count.Str() + " from array is '" + TestStrings[Count] + "'")
}
#------------------------------------------------------------------------------------------------
# This expression uses operator precedence to work correctly. No parens are needed. The logic
# works like "( (BitOr(ModuleData1,ModuleData2) == ModuleData2) & (CompilerData2 == "Test") )".
#------------------------------------------------------------------------------------------------
if ( BitOr(ModuleData1,ModuleData2) == ModuleData2 & CompilerData2 == "Test" )
{
StdIO.Write("MyEnum current value is " + MyEnum.Str())
}
# Call the same run-time method with three different parameters.
RunTimeMethod1(CompilerData1)
RunTimeMethod1(ModuleData1)
# Assigns Test1.Dump instance "method reference" to method ref variable and then executes it.
MyMethRef = MyTest1.Dump
MyMethRef()
# Dump out some module/global values using primitive framework method to convert to strings.
StdIO.Write('Value of ModuleData2 is ' + ModuleData2.Str())
StdIO.Write("Value of GlobalData3 is " + GlobalData3.Str())
}
# Simple class to hold instance and shared data and methods.
class Test1
{
# Data embedded in the Test1 class - 1 shared and 2 instance.
data<string> shared SharedData1
data<string> InstanceData1
data<int> InstanceData2
# Shared constructor executed automatically by system one time at startup.
method shared Test1()
{
SharedData1 = "SharedString"
StdIO.Write("Inside Test1 shared constructor")
}
# Standard (instance) constructor with no arguments.
method Test1()
{
InstanceData1 = "InstanceString"
InstanceData2 = 456
StdIO.Write("Inside Test1 constructor")
}
method Dump()
{
StdIO.Write("Values in Test1 object are '" + SharedData1 + "', '" +
InstanceData1 + "', " + InstanceData2.Str())
}
method<string> GetData1()
{
return(InstanceData1)
}
method<int> GetData2()
{
return(InstanceData2)
}
}
#===================================================================================================
# Example Script: Aztec Space Usage
# Demonstrates use of Aztec "spaces" when defining and using module level items, which include
# 'data', 'class', 'method', 'type' and 'enum'. This script changes the default "space" several
# times and creates several items in each one. This is likely overkill for most needs, but is
# used to demonstrate implicit/explicit spaces. Most Aztec scripts can likely forego the use of
# spaces altogether, but the feature is there if needed more complex scripts.
#===================================================================================================
# Data items defined at the module level using default "space" (aztec.script unless changed on command line).
data<int> const ModuleData1 = 0b10101010 # Init in binary (170 dec), visible in module
data<int> ModuleData2 = 0b11111111 # Init in binary (255 dec), visible in module
#-----------------------------------------------------------------------------------------
# Normal (run-time) method defined at module level - visible everywhere due to 'public'.
# This method is defined in an explicit "space" (aztec.script.test1).
#-----------------------------------------------------------------------------------------
public method aztec.script.test1.RunTimeMethod1(int Arg1)
{
StdIO.Write("Inside normal method 1 with arg " + Arg1.Str())
}
# Set new "space" to be used for creation of method, data and class below.
CompilerSetSpace('aztec.script.test2')
# Public Normal (run-time) method defined at module level - visible to the world due to 'public'.
public method RunTimeMethod2(string Arg1)
{
StdIO.Write("Inside normal method 2 with arg " + Arg1)
}
# Public data item to be used at run-time defined inside new space.
public data<int> GlobalData3 = 0b11111111 # Init in binary (255 dec), visible in module
# This simple class will also be created in "aztec.script.test2" space as set above.
class Test2
{
method Test2()
{
StdIO.Write("In Test2 constructor")
}
method Dump()
{
StdIO.Write("In Test2 Dump method")
}
}
# Set new "space" to be used for creation of the 'type' and 'enum' below, as well as Main() method.
CompilerSetSpace('aztec.script.test3')
# Define a new method reference data type and a new enumeration in "aztec.script.test3" space.
type<method> SimpleMethodRef
enum SimpleEnum { abc, def, lmnop, wxyz }
# Add '...test1' and '...test2' spaces to list ('...test3' not needed as it's default for rest of module).
CompilerUseSpace('aztec.script.test1')
CompilerUseSpace('aztec.script.test2')
#---------------------------------------
# Run-time entry point for the script.
#---------------------------------------
method Main()
{
# Local data items defined using explicit space to identify data types and implicit for enum value.
data<aztec.script.test2.Test2> MyTest1, MyTest2
data<aztec.script.test3.SimpleMethodRef> MyMethRef
data<aztec.script.test3.SimpleEnum> MyEnum = SimpleEnum.lmnop
# Allocate a new Test2 object using implicit and explicit space.
MyTest1 = new<Test2>
MyTest2 = new<aztec.script.test2.Test2>
# Execute the two global methods using implicit and explicit space.
RunTimeMethod1(1)
RunTimeMethod1(ModuleData2)
aztec.script.test1.RunTimeMethod1(ModuleData1)
RunTimeMethod2('ABC')
aztec.script.test2.RunTimeMethod2('XYZ')
# Assigns the Dump "method reference" to a method ref variable and then executes it.
MyMethRef = MyTest1.Dump
MyMethRef()
# Finally, access global data items implicitly and explictly.
StdIO.Write("Value of ModuleData2 is " + ModuleData2.Str())
StdIO.Write("Value of GlobalData3 is " + aztec.script.test2.GlobalData3.Str())
}