Blitz runtime
The Blitz runtime module provides low level functionality required by BlitzMax applications when they are running. This includes things like memory management, exception handling and string and array operations.
Much of the functionality provided by this module is hidden from application programmers, but is instead used 'behind the scenes' by the compiler. However, there are some very useful commands for debugging, memory management and simple standard IO.
Function reference
RuntimeError( message$ ) Generate a runtime error
Throws a TRuntimeException.
DebugStop() Stop program execution and enter debugger
If there is no debugger present, this command is ignored.
DebugLog( message$ ) Write a string to debug log
If there is no debugger present, this command is ignored.
OnEnd( fun() ) Add a function to be called when program ends
OnEnd allows you to specify a function to be called when the program ends. OnEnd functions are called
in the reverse order to that in which they were added.
ReadStdin$() Read a string from stdin
Returns: A string read from stdin. The newline terminator, if any, is included in the returned string.
WriteStdout( str$ ) Write a string to stdout
Writes str to stdout and flushes stdout.
WriteStderr( str$ ) Write a string to stderr
Writes str to stderr and flushes stderr.
MemAlloc:Byte Ptr( size ) Allocate memory
Returns: A new block of memory size bytes long
MemFree( mem:Byte Ptr,size ) Free allocated memory
The memory specified by mem must have been previously allocated by MemAlloc or MemExtend.
MemExtend:Byte Ptr( mem:Byte Ptr,size,new_size ) Extend a block of memory
Returns: A new block of memory new_size bytes long
An existing block of memory specified by mem and size is copied into a new block
of memory new_size bytes long. The existing block is released and the new block is returned.
MemAlloced() Memory currently allocated by application
Returns: The amount of memory, in bytes, currently allocated by the application
MemUsage() Maximum memory allocated by application
Returns: The maximum amount of memory, in bytes, allocated by the application since program startup
MemClear( mem:Byte Ptr,size ) Clear a block of memory to 0
MemCopy( dst:Byte Ptr,src:Byte Ptr,size ) Copy a non-overlapping block of memory
MemMove( dst:Byte Ptr,src:Byte Ptr,size ) Copy a potentially overlapping block of memory
GCMalloc:Byte Ptr( size ) Allocate temporary memory from garbage collector
Returns: A block of memory size bytes long
The returned block of memory will be automatically released the next time FlushMem
is called. You must not release this memory manually.
End End program execution
EndRem End a remark block
True Constant integer of value 1
False Constant integer of value 0
Pi Constant double of value 3.1415926535897932384626433832795
Byte Unsigned 8 bit integer type
Short Unsigned 16 bit integer type
Int Signed 32 bit integer type
Long Signed 64 bit integer type
Float 32 bit Floating point type
Double 64 bit floating point type
Var Composite type specifier for 'by reference' types
Ptr Composite type specifier for pointer types
If Begin a conditional block.
Then Optional separator between the condition and associated code in an If statement.
Else Else provides the ability for an If Then construct to execute a second block of code when the If condition is false.
ElseIf ElseIf provides the ability to test and execute a section of code if the initial condition failed.
EndIf Marks the end of an If Then block.
For Marks the start of a loop that uses an iterator to execute a section of code repeatedly.
To Followed by a constant which is used to calculate when to exit a For..Next loop.
Step Specifies an optional constant that is used to increment the For iterator.
EachIn Iterate through an array or collection
While Execute a block of code while a condition is true
Repeat Execute a block of code until a termination condition is met, or forever
Forever End a repeat block
Select Begin a select block
EndSelect End a select block
Case Conditional code inside a select block
Default Default code inside a select block
Continue Continue execution of enclosing loop
Local Declare a local variable
Global Declare a global variable
Field Declare a field variable
Function Begin a function declaration
EndFunction End a function declaration
Return Return from a function
Example:
Rem
Return exits a BlitzMax Function Or Method with an optional value.
The Type of Return value is dictated by the Type of the Function.
End Rem
Function CrossProduct#(x0#,y0#,z0#,x1#,y1#,z1#)
Return x0*x1+y0*y1+z0*z1
End Function
Print "(0,1,2)x(2,3,4)="+CrossProduct(0,1,2,2,3,4)
Function LongRand:Long()
Return (Rand($80000000,$7fffffff) Shl 32)|(Rand($80000000,$7fffffff))
End Function
Print "LongRand()="+LongRand()
Print "LongRand()="+LongRand()
Type Begin a user defined type declaration
EndType End a user defined type declaration
Extends Specify user defined type supertype
Example:
Rem
Extends is used in a BlitzMax Type declaration To derive the Type from a specified base class.
End Rem
Type TShape
Field xpos,ypos
Method Draw() Abstract
End Type
Type TCircle Extends TShape
Field radius
Function Create:TCircle(x,y,r)
Local c:TCircle=New TCircle
c.xpos=x;c.ypos=y;c.radius=r
Return c
End Function
Method Draw()
DrawOval xpos,ypos,radius,radius
End Method
End Type
Type TRect Extends TShape
Field width,height
Function Create:TRect(x,y,w,h)
Local r:TRect=New TRect
r.xpos=x;r.ypos=y;r.width=w;r.height=h
Return r
End Function
Method Draw()
DrawRect xpos,ypos,width,height
End Method
End Type
Local shapelist:TShape[4]
Local shape:TShape
shapelist[0]=TCircle.Create(200,50,50)
shapelist[1]=TRect.Create(300,50,40,40)
shapelist[2]=TCircle.Create(400,50,50)
shapelist[3]=TRect.Create(200,180,250,20)
Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
Cls
For shape=EachIn shapelist
shape.draw
Next
Flip
Wend
End
Method Begin a method declaration
EndMethod End a method declaration
Abstract Denote a type or method as abstract
An abstract type cannot be instantiated using New - it is designed to be
extended. A type with any abstract methods is itself automatically abstract.
Example:
Rem
A BlitzMax Type that contains Abstract methods becomes Abstract itself.
Abstract types are used To define interfaces that extending types must
implement before they can be used To create New instances.
In the following code TShape is an Abstract Type in that you can Not
create a TShape but anything extending a TShape must implement a Draw()
Method.
End Rem
Type TShape
Field xpos,ypos
Method Draw() Abstract
End Type
Type TCircle Extends TShape
Field radius
Function Create:TCircle(x,y,r)
Local c:TCircle=New TCircle
c.xpos=x;c.ypos=y;c.radius=r
Return c
End Function
Method Draw()
DrawOval xpos,ypos,radius,radius
End Method
End Type
Type TRect Extends TShape
Field width,height
Function Create:TRect(x,y,w,h)
Local r:TRect=New TRect
r.xpos=x;r.ypos=y;r.width=w;r.height=h
Return r
End Function
Method Draw()
DrawRect xpos,ypos,width,height
End Method
End Type
Local shapelist:TShape[4]
Local shape:TShape
shapelist[0]=TCircle.Create(200,50,50)
shapelist[1]=TRect.Create(300,50,40,40)
shapelist[2]=TCircle.Create(400,50,50)
shapelist[3]=TRect.Create(200,180,250,20)
Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
Cls
For shape=EachIn shapelist
shape.draw
Next
Flip
Wend
End
Final Denote a type or method as final
New Create an instance of a user defined type
Self Self is used in BlitzMax Methods to reference the invoking variable.
Super Super evaluates to Self cast to the method's immediate base class.
Delete Reserved for future expansion
Release Release references to a handle or object
Public Public makes a constant, global variable or function accessible from outside the current source file (default).
Private Private makes a constant, global variable or function only accessible from within the current source file.
Extern Extern marks the beginning of an external list of function declarations.
EndExtern EndExtern marks the end of an Extern section.
Module Declare module scope and identifier
ModuleInfo Define module properties
IncbinPtr Get start address of embedded data file
IncbinLen Get length of embedded data file
Import Import declarations from a module or source file
Assert Throw a runtimeerror if a condition is false
FlushMem Discard all unused memory
Goto Transfer program flow to specified label
Try Begin declaration of a try block
EndTry End declaration of a try block
Catch Catch an exception object in a try block
Throw Throw an exception object to the enclosing try block
DefData Define class BASIC style data
ReadData Read classic BASIC style data
RestoreData Restore classic BASIC style data
And Conditional 'and' binary operator
Or Conditional 'Or' binary operator
Not Conditional 'Not' binary operator
Shl Bitwise 'Shift left' binary operator
Shr Bitwise 'Shift right' binary operator
Sar Bitwise 'Shit arithmetic right' binary operator
Len Number of characters in a string or elements in an array
Abs Numeric 'absolute value' unary operator
Mod Numeric 'modulus' or 'remainder' binary operator
Sgn Numeric 'sign' unary operator
Min Numeric 'minimum' binary operator
Max Numeric 'maximum' binary operator
Varptr Find the address of a variable
SizeOf Bytes of memory occupied by a variable, string, array or object
Asc Get character value of the first character of a string
Chr Create a string of length 1 with a character code
Module Information
Module | brl.blitz |
Version |
1.01 |
Author |
Mark Sibly |
License |
Blitz Shared Source Code |
Copyright |
Blitz Research Ltd |
Modserver |
BRL |