Aztec® Programming Language
Version 1.1 Alpha 2

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

Download Aztec

Search        Contact Us

But I would not be convicted... by a jury of my peers.

Still crazy... after all these years.

- Paul Simon

 

The Return statement and Exit statement each provide a mechanism to transfer control out of a method or the entire script/application. The following table shows the syntax for the Return and Exit statements.

Aztec Return and Exit Statement Syntax

 

♦ For the 'return' statement

♦ Stops execution within the current method and returns control to the calling method.

♦ If the Expression is specified, it is made available to the caller. The expression type must match the return type of the method. An empty expression is only valid for a method that does not return a value.

♦ If the current method is the “Main” method, the Application/Script will terminate and appropriate system cleanup is performed (see below).

♦ For the 'exit' statement

♦ Stops execution of the entire Aztec Script. The VM automatically cleans up threads, sockets, windows, objects and other system resources. It also flushes and closes all open files.

♦ If the Expression is specified, it must be an integer, and it is passed to the operating system as an application exit code. If no Expression is specified, zero is returned to the OS.

♦ The 'return' and 'exit' statements can only be used within a method.

♦ An example script showing 'return' and 'exit' statement usage.

#===================================================================================================
# Example Script: Return and Exit Statements
# Demonstrates the use of 'return' statement for a number of different data types and with
# normal and compiler methods. Also uses 'exit 0' to terminate the script with success.
#===================================================================================================

# Method reference data type used for a method that takes an integer arg and returns a string.
type<string method<int>> MethodRefTakesIntAndReturnsString

# Global variable used for primitive reference in compile-time logic.
data<float> compiler MyGlobalCompilerFloat = 87.65

# Call the compiler method to dump out return values from compiler methods.
DumpMethodReturns()

#----------------------------------------------------------------------------
# Some example compiler methods returning various data types. Note that the
# data type in the 'method<>' keyword must match data type in 'return'.
#----------------------------------------------------------------------------
method<int> compiler CompilerGetInt()
{
return(CompilerRandomInt(1,50))
}

method<string> compiler CompilerGetString()
{
data<string> MyString
MyString = CompilerStrPad(' Aztec Compiler String ',60,'-',string.PadCenter)
return(MyString)
}

method<float ref> compiler CompilerGetFloatRef()
{
data<float ref> MyFloatRef = @MyGlobalCompilerFloat
return(@MyFloatRef)
}

# Method to access the above methods and dump out the return values.
method compiler DumpMethodReturns()
{
data<int> MyInt
data<float ref> MyFloatRef
data<string> MyString

MyInt = CompilerGetInt()
CompilerWriteLog("Return integer value from compiler method is " + CompilerIntStr(MyInt))

@MyFloatRef = CompilerGetFloatRef()
CompilerWriteLog("Return float (using ref) value from compiler method is " + CompilerFloatStr(MyFloatRef))

MyString = CompilerGetString()
CompilerWriteLog("Return string value from compiler method is " + MyString)
}

#-----------------------------------------------------------------------
# Some example "run-time" methods returning various data types. The
# data type in the 'method<>' keyword must match data type in 'return'.
#-----------------------------------------------------------------------
method<int> GetInt()
{
return(int.Random(101,150))
}

method<string> GetString()
{
data<string> MyString
MyString = StrPad(' Aztec Run-Time String ',60,'-',string.PadCenter)
return(MyString)
}

method<float ref> GetFloatRef()
{
data<float ref> MyFloatRef = new<float(RandomInt(151,200))>
return(@MyFloatRef)
}

method<Test1> GetTest1()
{
return(new<Test1>)
}

method<MethodRefTakesIntAndReturnsString> GetMethodRef1()
{
return(TestMethod1)
}

# Method that will be returned from an above method (takes int and returns string)
method<string> unique TestMethod1(int Value)
{
return(Value.Str())
}

#-----------------------------------------------------------------------------------
# Run-time entry point for the script. Calls the above methods to demo various
# different data types being returned from a method, including a method reference.
#-----------------------------------------------------------------------------------
method Main()
{
data<int> MyInt
data<Test1> MyTest1
data<string> MyString
data<float ref> MyFloatRef
data<MethodRefTakesIntAndReturnsString> MyMethodRef

StdIO.Write("Return integer value from run-time method is " + GetInt().Str())

@MyFloatRef = GetFloatRef()
StdIO.Write("Return float (using ref) value from run-time method is " + MyFloatRef.Str())

MyString = GetString()
StdIO.Write("Return string value from run-time method is " + MyString)

MyTest1 = GetTest1()
StdIO.Write("Return string value from run-time Test1.Name() method is " + MyTest1.Name())

# Get method ref returned from the method call, and then call the method using the ref.
MyMethodRef = GetMethodRef1()
MyString = MyMethodRef(RandomInt(201,250)) # Executes method based on method ref returned from method.
StdIO.Write("Return string value using method ref from run-time method is " + MyString)

# Exit the application with a normal (success) return code to the OS.
exit 0
}

# Simple class used above for method return examples.
class Test1
{
method Test1
{
}

method<string> Name()
{
data<int> shared CallCount = 0
CallCount.Inc()
return("Test1_" + CallCount.Str())
}
}

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

Download Aztec