Sei sulla pagina 1di 57

David Cuny Modified and enhanced by Klaus Scharr 2006 wxBasics Home

1 Introduction
wxb is a cross-platform BASIC interpreter licensed under the not complying with the ANSI BASIC standard, wxBasic provides functionality associated with modern structured BASIC, along number of extensions borrowed from languages such as Python, Java. LGPL. While much of the with a Lua and

At its core, wxBasic is a fairly small language, weighing in at under 300K (less than 80K when compressed via UPX). However, wxBasic gains much of its functionality by using the wxWidgets library, which provides a cross-platform GUI and non-GUI functionality. The wxWidgets-enabled version of wxBasic is far more capable, but quite a bit heftier.

1.1

How wxBasic Differs from Other Basics

wxb has a mixed parentage, deriving mostly from QBasic, but pilfering from C, Lua, Python, and VB.NET. The result is a language with a lot of 'C-isms'. The main points where wxBasic differs from 'classic' BASICs is:

2.5.1 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6

Dynamic Variable Declaration Simple Datatypes Not Passed by Reference Functions Return Values via the RETURN Keyword Functions Can Return Multiple Values Functions Can Have Optional Parameters Functions Can Have Variable Numbers of Parameters No Need To Declare Forward References

1.1.1

Case Insensitive

The first version of wxb was case sensitive, but this is no longer true.

2 Using wxBasic
2.1 Running Scripts
When you start wxBasic, you always have to add a wxBasic-Script as Parameter. If you start without giving a Script-File, wxBasic shows you a dialog containing the calling-conventions. A wxBasic-Script-File is a simple text-file containing a set of wxBasic-Commands. Here is an example of a very simple wxBasic-Script:
PRINT Hello, wxBasic!

Write this text in an editor of your choice, save it and give the filename to the wxBasic-Interpreter as parameter. It may look like this:
wxBasic PrintHello.wxb

2.1.1

Windows

Add the folder of the wxBaxic-Interpreter to the PATH-variable in order

to be able to call the wxBasic-Interpreter from every folder.

2.1.2

Linux

Under Linux you can add the wxBasic-Executable to /usr/bin. Don't forget to make the scripts executable (chmod)

2.1.3

Mac

There was a Mac-Version of wxBasic, but as there are not much wxBasic User/Developer with a Mac and the respective skills, the Mac-Version of wxBasic is currently not released officially. If you have a Mac and you know how to compile wxBasic just do it and let us know!

2.2

Command Line Parameters

2.3
2.3.1

Script Editors
wxEditor

The wxEditor is an IDE written in wxBasic for wxBasic-Development.

There is an own wxEditor-thread at the wxBasic-Forum. The current Release (wxEditor3.5beta2) can be downloaded from here.

2.4

Binding Scripts

There is the possibility to bind wxBasic-Scripts with the wxBasicInterpreter in order to get a standalone Executable. The easiest way to do this, is to use the wxEditor, which supports the script-binding by a menu-item: RUN -> Bind (F6)

2.5
2.5.1

Variables
Assignment

lval {, lval} = expr {, expr }

Assigns a value to one or more lval:


a, b, c = 1, 2, 3

2.5.2

Dynamic variable declaration

In wxb, it is not necessary to declare variables or their type; they will be created "on the fly":
aString = "This is a string" aNumber = 123

Variables declared outside of routines are automatically global in scope:


globalVar = "I'm a global variable" SUB foo() localVar = "I'm a local variable" ' This references the global variable globalVar PRINT globalVar ' This references the local variable localVar PRINT localVar END SUB

As convenient as this option is, it's much safer to require variables to be explicitly declared in wxb. This is done by adding the statement:
OPTION Explicit

With Option Explicit enabled, you will need to explicitly declare your variables before use:

DIM globalVar = "I'm a global variable" SUB foo() DIM localVar = "I'm a local variable" ' This references the global variable globalVar PRINT globalVar ' This references the local variable localVar PRINT localVar END SUB

2.6
2.6.1

Functions
Simple datatypes not passed by reference

Some datatypes (like Arrays and Objects) are passed to routines by reference, but the "simple" datatypes (such as Number and String) are not. This means that if you change the parameter for simple datatypes, you won't change the parameter in the caller. For example:
SUB foo( a ) a = a + 10 PRINT "In foo(), a ="; a END SUB

b = 100 PRINT "Before calling foo(), b ="; b foo( b ) PRINT "After calling foo(), b ="; b

In some versions of Basic, changing the value of a would change the value of b. This isn't the case in wxb. If you want to change the value of b, you need to assign the value back:
FUNCTION foo( a ) a = a + 10 PRINT "In foo(), a ="; a END FUNCTION

b = 100 PRINT "Before calling foo(), b ="; b b = foo( b ) PRINT "After calling foo(), b ="; b

2.6.2

Functions return values via the RETURN-keyword

To return a value from a function in wxb, you need to use the Return keyword. It works the same way return works in C: the function exits at that point, and returns the values that follow the Return statement:
FUNCTION foo( a ) RETURN a * 10 END FUNCTION

If you want to continue processing through the function, just store the value in a temporary variable:
FUNCTION foo( a ) DIM tmp = a * 10 ' Do something else RETURN tmp END FUNCTION

2.6.3

Functions can return multiple values

Like Lua and Python, wxb allows functions to return multiple values. For example:
FUNCTION doubleTheValue( a ) ' Return double the value and original value RETURN a*2, a END FUNCTION

newValue, oldValue = doubleTheValue( 120 )

Basically, this replaces the need for passing values by reference. Wxb checks to make sure the number of arguments on both sides match. If they dont, wxb will fill in the missing values on the left hand side with Nothing, or drop extra values on the right hand side. For example:
a, b = 10, 20, 30

will cause a to be assigned the value 10, and b the value 20. There is no variable to receive the value 30, so it is dropped. Similarly: a, b = 10 will cause a to be assigned the value 10, and b the value Nothing. If a function doesnt explicitly return a value, it will by default return the value Nothing:

FUNCTION doNothing() END FUNCTION a = doNothing()

This will cause the variable a to be assigned the value Nothing. Functions Can Have Optional Parameters You can specify that a routine can have optional parameters. If the routine is called without these parameters being passed, they will be set to their default values. For example:
SUB hasOptionalParms( a, b, c = 10, d = 100 ) PRINT a, b, c, d END SUB

2.6.4

Functions Can Have Variable Numbers of Parameters

You can specify that a routine will take a number of (unnamed) parameters, similar to Cs printf command:
SUB hasVariableParms( a, b, ... )

TODO: how can the additional parameters be addressed example

2.6.5

Forward References

No Need To Declare Forward References wxb will automatically resolve all forward references.

2.7
TODO:

Object Orientation in wxBasic

3 Tutorials / Examples
3.1 Hello World (Command-Line)
A Hello to the world can be done in just one line. Open your editor of choice, insert the text
PRINT "Hello, World!"

save it as HelloWorld.wxb and call


wxBasic HelloWorld.wxb

from the command-shell. Either you have to put the location of the wxBasic-Executable to your PATH-Variable or you call it from the folder where the wxBasic-Executable is located.

3.2

Hello World (Message-Box)

If you want to say Hello to the world in a more appealing way, do it with a message-box and the best in wxBasic it can be done with one command:
wxMessageBox("Hello World!\n", "hello world ...")

And if you want to inform about your operating-system write:


DIM sOsDescription as String = wxGetOsDescription() wxMessageBox("Hello World!\n" & sOsDescription,"hello world ...")

3.3
TODO:

Hello World (Dialog)

4 Language Reference
4.1 Datatypes
All values in wxb are stored as Variants. However, the variant will be one of the following types:

NOTHING INTEGER NUMBER STRING DATETIME OBJECT ROUTINE COLLECTIONs INDEXEs SLICEs ARRAY TABLE LIST

These values have common properties:


integer = variant.GetType() string = variant.ToString() integer variant.Equal( otherValue ) integer variant.Compare( otherValue ) clone = variant.Clone()

However, not all datatypes implement these properties.

4.1.1

Nothing

Nothing is akin to other language's nil or null value. In a truth test, it evaluates to False. All unassigned variables default to Nothing, even if they have been declared as some other type. You can directly test for a value of Nothing:

IF a = NOTHING Then PRINT "a = Nothing" END IF

It implements the following methods:


isNumeric fromChar toChar isTrue

4.1.2

Integer

Integer is a integer. It is stored as an int value, although all math operations are internally done with double, even if both types are declared as Integer.

4.1.3

Number

Number is a floating point number, stored as a C double. All math operations in wxb are internally done with a Number type, even if the datatype is declared differently.

4.1.4

String

String is an alphanumeric string. When tested in a truth operation, an empty string returns False, and a non-empty string returns True. You can embed special characters into the string by using the backslash (\)
\n \r \t \' \" \\ newline carriage return tab single quote (not really needed) double quote backslash

For example:
stringWithANewline = "This is the first line\nThis is the second"

You can treat a string as if it were a collection. You iterate through a string. For example:

FOR EACH position, letter IN "Hello, World" PRINT "Position="; position, "Letter="; letter END FOR

You can also index and slice a string like an array. For example:
PRINT "Hello, World"[8]

prints "W", and:


PRINT "Hello, World"[1:5]

prints "Hello".

4.1.5

DateTime

DateTime represents a date and time. It is normally created by calling the routine TimeValue:
DIM myDate = TimeValue("Jan 12, 2003")

You can extract the parts of the date by calling the various methods (also available as builtin functions):
myDate.Year() myDate.Month() myDate.MonthName() myDate.Weekday() myDate.Day() myDate.DayName() myDate.Hour() myDate.Minute() myDate.Second()

DateTime values can be compares for exact equality or inequality. To determine specific differences between dates, use DateDiff (see the DateDiff function for details).

4.1.6

Object

Any data declared with a Class (builtin or user declared) is stored as a datatype Object. Objects are passed by reference, not by value. If you want to create a unique copy of an Object, use the Clone method:
myCopy = theObject.Clone()

Objects are reference counted, and automatically destroyed when no

object refers to them anymore. For more information about objects, see the section on CLASSES.

4.1.7

Routine

A Routine is a user-defined routine or method. There is currently only an internal datatype.

4.1.8

Collections

A collection is a grouping of Variant data which can be accessed by a key value. For example, Arrays, Tables, and Lists are all collections. There are operations that are (in general) common across collections. You can access an element in a collection by specifying that element's key. For example, here's a Table collection:
Dim myCats = {}

Indexes
Let's populate the Table:
myCats[ 1 ] = "Chester" myCats[ 2 ] = "Charlotte" myCats[ 3 ] = "Chloe"

If we print the table:


Print myTable

we'll get:
{ 1:"Chester", 2:"Charlotte", 3:"Chloe" }

We can access elements in a collection by specifying the collection, and the key in square brackets:
Print myCats[ 3 ]

prints
"Chloe".

Slices
If the collection is ordered, you can print a slice from the collection:
Print myCats[ 2:3 ]

prints
{ 2:"Charlotte", 3:"Chloe" }

Collection Methods
In addition to the methods implemented by Variants, most collections implement one or more of these methods:
collection.Append( value ) collection.Prepend( value ) collection.InsertAt( key, value ) collection.Slice( startSlice, endSlice ) integer = collection.Count

4.1.9

Array

An Array is a collection of static size. Like all other collections, they are passed by reference. Unlike most versions of Basic, wxb uses square brackets to help distinguish them from routine calls. Here's a simple declaration:
Dim myArray[10]

If the lower range is not declared, wxb will assume the array starts at zero. You can have up to five dimensions to the array:
Dim myArray[5 To 20, -10 To 10]

Array with undeclared types values initialize their values to zero. You can specify an initial value like this:
Dim myArray[10] = Nothing

You can declare the type as well:


Dim myArray[10] As Number

You can also declare the type and initial value:


Dim myaArray[10] As Integer = 10

4.1.10

Table

An Table is an unordered collection of dynamic size. Like all other collections, they are passed by reference. You create a table by declaring a collection within curly brackets. The following declares an empty Table:

Dim myTable = {}

A collection is indexed by keys, which can either be Integer or String values (Numbers will be automatically converted to Integers). For example:
Dim myCats = { 1:"Chester", 2:"Charlotte", 3:"Chloe", 4:"Julius" }

is the same as writing:


Dim myCats = {} myCats[1] = "Chester" myCats[2] = "Charlotte" myCats[3] = "Chloe" myCats[4] = "Julius"

Note here that if the key does not exist in the List, wxb will insert a new key/value pair. If you leave off the key in the declaration, wxb will assign a sequential value, so this produces the same result as the prior example:
Dim myCats = { "Chester", "Charlotte", "Chloe", "Julius" }

You can retrieve data by specifying the index, the same as an array:
Print myCats[1]

If a key does not exist in the Table, wxb returns the value Nothing. If a List contains another List, you can access it as if it were an array:
Dim myCats = {} myKids[ "Chester", "favorite food" ] = "Pounce"

is the same as writing:


Dim myCats = {} myKids[ "Chester" ] = { "favorite food":"Pounce" }

which is also the same as:


Dim myCats = { "Chester":{ "favorite food":"Pounce" } }

and it can be accessed similarly:


Print myKids[ "Chester", "favorite food" ]

prints
"Pounce".

As with the other collections, you can iterate through it with the For Each loop:

For Each index, name In myCats Print index, name End For

Note that the List is unordered, so there is no guarantee that the data will come back in any order. You can remove items from the list by removing the key from the collection:
myCats.Remove( "Julius" )

4.1.11

List

An List is an ordered collection of dynamic size. Like all other collections, they are passed by reference. You create a table by declaring a collection within square brackets. The following declares an empty List:
Dim myList = []

Construction of a Table is similar to that of a list, except that the keys are implicit, based on order:
Dim myCats = [ "Chester", "Charlotte", "Chloe", "Julius" ]

You can add items to the list with Append, which adds the elements to the end of the list:
Dim myCats = [] myCats.Append( myCats.Append( myCats.Append( myCats.Append( "Chester" ) "Charlotte" ) "Chloe" ) "Julius" )

Or with Prepend, which adds elements to the beginning:


Dim myCats = [] myCats.Prepend( myCats.Prepend( myCats.Prepend( myCats.Prepend( "Julius" ) "Chloe" ) "Charlotte" ) "Chester" )

Or Insert, which specifies a position to insert at:

Dim myCats = [] myCats.Insert( myCats.Insert( myCats.Insert( myCats.Insert( 1, 2, 3, 4, "Julius" ) "Chloe" ) "Charlotte" ) "Chester" )

Elements can be accessed by index, starting at 1. Attempting to access a non-existant element will result in wxb throwing an error.
Print myCats[3]

You can also access a slice of elements:


Print myCats[2:3]

4.2

Variables

2.5 Variables

4.3

Expressions / Operators
Example

An expression is a combination of one of the following: Expression Description


. + * / \ % ^ << >> | & = ! NOT <> != < >

Enables the access of classe-methods and -attributes Adds two values Substract two values Multiplication of two values Division of a value by another value Integer-Division of a value by another value Modulo shows the rest of a integerdivision Exponent Logical shift left Logical shift right Bitwise OR of values Concatenation of values or strings Test if two values are equal or assignment of a value to a variable Negation of a value whereas 0 is FALSE and greater than 0 i TRUE Test if two values are Not equal Test if a value is less than another Test if a value is greater

myString.Clear() myPoint.X 17+4 => 21 200-101 => 99 5 * 7 => 35 3 / 2 => 1.5 5 \ 2 => 2 5 % 2 => 1 2 ^ 3 => 8 5 << 2 => 20 5 >> 2 => 1 PRINT 2 | 4 => 6 PRINT 2 & 4 => 24 a = 17 If a = 3 Then ... !0 => 1 NOT 1 => 0 If myString <> NO If myString != NO If myValue < 17 If myValue > 4

Expression
<= >= NOT XOR IN OR AND INV () {} [] NEW integer float string NOTHING THIS

Description Test if a value is less or equal Test if a value is greater or equal Negation Logical exclusive OR operation Not coded yet Logical OR operation Logical AND operation ??? Round brackets are used to group expressions Curly brackets ??? ??? ??? ??? ??? ??? ??? ???

Example If myValue <= 11 If myValue >= 2 If NOT (...) If (...) XOR (...) If (...) OR (...) If (...) AND (...) (5+7)*3 => 36

className [ '(' [expr {, expr}] ')' ] variableName constantName functionName '(' [expr {, expr}] ')' expr '[' expr {, expr } ']'

4.4

Conditional Statements
IF ... ELSEIF ... ELSE ... END IF SELECT CASE ... END SELECT|outline

4.5

Looping
FOR ... NEXT FOR EACH ... END FOR WHILE ... END WHILE

4.6 4.7

Functions Comments

5 wxBasic Syntax
5.1 CLASS

CLASS className [INHERITS className] [DIM attribute {, attribute}] subroutineDefinition functionDefintition END CLASS

Explanation
Creates a new user-defined class. Single inheritance is supported. Class attributes are defined in the Dim section. New instances of a class object are created by calling a constructor method with the same name of the class.

Parameters
className attribute subroutineDefinition functionDefinition

Example
create a Point class CLASS Point DIM x, y END CLASS create a point p = Point() p.x = 10 p.y = 20

See also
NEW

Remarks
Objects are automatically destroyed when there are no references to the object. If you want an object to be permanent, create it with the New

keyword:
create a Point class CLASS Point DIM x, y END CLASS

create a temporary point and assign some values p1 = Point() p1.x, p1.y = 10, 20

create a permanent point and assign some values p2 = NEW Point() p2.x, p2.y = 40, 80

destroy the temporary point p1 = NOTHING

This does not destroy the permanent point p2 = NOTHING

To destroy an object created with New, use the Dispose command:

Destroy the point DISPOSE p2

You can define an initializer for a class by including a NEW method in the class:

create a Point class CLASS Point DIM x, y SUB NEW ( useX, useY ) x, y = useX, useY END SUB END CLASS

create a Point p1 = Point( 10, 20 )

When an object is destroyed, the FINALIZE routine for it is run:

create a Point class CLASS Point DIM x, y SUB NEW ( useX, useY ) x, y = useX, useY PRINT Created Point {; x; , ; y; ) END SUB SUB FINALIZE() PRINT Destroyed the point {; x; , ; y; ) END SUB END CLASS

5.2

CLOSE

CLOSE CLOSE #handle

Explanation
Close a currently open file. To close all files, use Close without a handle number.

Parameters
#handle The handle of the file to close. It's the handle of the OPEN operation.

Example
Append text to a file, and then close it OPEN tmp.txt FOR APPEND AS #1 PRINT #1, Some text CLOSE #1

See also
OPEN,FCLOSE,FOPEN

5.3

CONST, CONSTANT

CONST constantName = expression {, constantName = expression } CONSTANT constantName = expression {, constantName = expression }

Explanation
Declare a variable to be a constant. Constants are similar to variables, except they cannot be assigned values.

Parameters
constantName expression The name of the constant The expression for which the constant should be used for

Example
Declare the name and version of the program CONST ProgName = My Cool Program, Version = 1.0

See also

Remarks

5.4

CONTINUE

Explanation Parameters Example See also


REDO,

Remarks

5.5

DIM

DIM name [ '[' [expr [TO expr] ']' ] [ = expr] [AS type] (, name [= expr] }

Explanation
Define an object. Arrays can be initialized to a default value by assigning them Variables that are unassigned by default to NOTHING.

Parameters
name type Name of the variable Type of the variable e.g. integer, float, string...

Examples
' Create a 2 x 3 array, initialize it to zero DIM a[2,3] = 0

' Create a string variable and assign it DIM b AS STRING = "This is a string"

' Create and assign several variables DIM a = 10, b, c = a+12

See also
2.5 Variables

Remarks

5.6
END

END

Explanation
Halt the program.

Parameters
none

Examples
Stop the program if the user is bored. INPUT Do you want to play again (Y/N}?; answer IF answer = Y OR answer = y THEN END END IF

See also

5.7
TODO:

EXIT

5.8

FOR...NEXT

FOR variable = startExpr TO endExpr {STEP stepExpr} [CONTINUE] [BREAK] [EXIT FOR] { statement } ELSE { statement } END FOR | NEXT {variable}

Explanation
Loop from startExpr to endExpr, incrementing by stepExpr. If stepExpr is left off, it is assumed to be 1. BREAK leaves the loop immediately, while CONTINUE jumps to the top of the loop for the next value.

Parameters
variable startExpr endExpr stepExpr statement Name of the loop-variable Start-Value End-Value gives the step-width The code which should be run within the loop

Examples
Here is an example of a loop printing the numbers between 1 and 10, inclusive:
' loop from 1 to 10 FOR i = 1 TO 10 PRINT i NEXT

If the loop is not exited via the BREAK statement, the ELSE clause will execute.

' loop through an array, looking for a value FOR i = 1 to LENGTH( list ) IF list[i] = someValue THEN PRINT "Found it!" BREAK END IF ELSE PRINT "Didn't find it" END FOR

See also
FOR EACH,WHILE

5.9

FOR EACH...END FOR

FOR EACH variable {, variable} IN expression [CONTINUE] [BREAK] [EXIT FOR] { statement } ELSE { statement } END FOR

Explanation
Iterate through a COLLECTION (table, list). If only one loop variable is used, it will hold the index from the collection. If two variables are used, they will hold the key/index and value. CONTINUE, BREAK and ELSE behave the same as a FOR loop.

Parameters
variable expression statement Name of the looping-variable Collection variable containing the items to loop through Code to execute within the loop or the else part

Examples
' Print the value and keys from a list FOR EACH key, value IN list PRINT key, value END FOR

See also
FOR...NEXT,WHILE

5.10

FUNCTION ... END FUNCTION

FUNCTION name ( [arg [= expr]{,arg [= expr]} ] [, ...] ) [ DIM variable {, variable } ] [ STATIC variable {, variable } ] [ SHARED variable {, variable } ] [ RETURN expr {, expr} ] [ EXIT FUNCTION ] { statement } END FUNCTION

Explanation
Define a function. Unlike many BASICs, more than one value may be returned from a function. As a result, the Return keyword is used to return values from functions. If no value is explicitly returned, the value Nothing is returned.

Parameters
name arg expr variable statement Name of the function Name of the Argument that's given to the function If a expression is given it acts like a placeholder it's the default-value Name of local variable(s). This local variables are only valid within the function, except SHARED variables Can be everything of the wxBasic-Language-Repertoire

Example
FUNCTION addOne( n ) RETURN n + 1 END FUNCTION

See also
SUB,

Remarks
You can have optional values in parameters. If these parameters are not included in the function call, they are assigned the default value:
FUNCTION hasOptional( a, b=10, c=default string ) PRINT a=, a PRINT b=, b PRINT c=, c END FUNCTION

You can use Static variables in functions. These are variables that retain their value. The initial value of Static variables is Nothing:
FUNCTION accum( n ) declare result as a STATIC variable STATIC result first time calling accum? IF result = NOTHING THEN initialize the result result = n ELSE add value to the result result = result + n END IF return accumulated result RETURN result END FUNCTION

Some or all of the return values may be discarded by the caller. If a function returns more values than requested, the extra values are discarded. If the function returns less values than expected, the extra variables are assigned the value Nothing:

FUNCTION returnThreeValues() RETURN 1, 2, 3 END FUNCTION ignore all values returnThreeValues() ignore the last value a, b = returnThreeValues Nothing is assigned to d a, b, c, d = returnThreeValues()

5.11

IF ... ELSEIF ... ELSE ... END IF

IF <expr> THEN { statement } { ELSEIF <expr> THEN { statement } } [ ELSE { statement } ] END IF

Explanation
IF performs conditional operations.

Parameters
<expr> The statements will be executed, if the <expression> is true

Example
IF 10 > 12 THEN PRINT 10 is less than 12 END IF

See also
SELECT CASE

Remarks
These <expr> - tests can be chained together with additional ELSEIF tests, which are performed if the prior tests fail. An optional ELSE clause is executed if none of the prior tests were true:
IF a = PRINT ELSEIF PRINT ELSEIF PRINT ELSE PRINT END IF 1 THEN One a = 1 THEN Two a = 3 THEN Three Too big!

5.12

INCLUDE

INCLUDE <include-file>

Explanation
Include a file in the current script

Parameters
<include-file> The filename of the file that should be included

Example
The following example includes the content of the file myTooling.inc to the current script-file. The content of this file must also be wxBasic commands.
INCLUDE myTooling.inc

See also

Remarks

5.13

INPUT

INPUT [ promptString ;] variable

Explanation
Prompt the user for a value. This routine is only available in the command line (non-GUI) version of wxBasic.

Parameters
promptString variable An optianal string that will be shown at the inputprompt. It can be used to explain, what kind of input is expected. The variable to which the user-input will be stored

Example
Get the users name INPUT Whats your name; yourName PRINT Hello, ; yourName

See also
PRINT,

Remarks

5.14

OPEN

OPEN filename FOR mode AS #handle

Explanation
OPEN a file for reading, writing, or appending. This syntax is deprecated, and the function FOpen() is preferred.

Parameters
filename The name of the file that should be opened The mode the file should be handled: Input => read from the file Output => write to the file, destroying prior contents Append => write to a file, leaving prior content The handle is a filenumber. The next available handle can be found by calling FreeFile()

mode

#handle

Example
Copy source.txt to copy.txt OPEN source.txt FOR INPUT AS #1 OPEN copy.txt FOR OUTPUT AS #1 Read the first file, and copy to the second WHILE NOT EOF( 1 ) LINE INPUT #1, text PRINT #2, text WEND Close the files CLOSE #1 CLOSE #2

See also
CLOSE,FCLOSE,FOPEN,FREEFILE

Remarks
Close a file by calling CLOSE # or FCLOSE(). You can close all open files by calling Close.without #handle.

5.15

NEW

NEW object

Explanation
NEW creates an instance of an OBJECT. The object is represented by a class.

Parameter
object The object/class of which a new instance should be created.

Return
The reference to an instance of the object.

Example
DIM myDate AS wxDateTime = NEW wxDateTime() myDate.SetToCurrent() wxMessageBox(myDate.FormatDate())

See also
DIM,

Remarks
The object-orientation in wxBasic is shortly introduced in chapter 2.7 Object Orientation in wxBasic

5.16

Option

OPTION optionName

Explanation
OPTION allows toggling on various behaviors for the interpreter.

Parameters
optionName The name of the option that should be set to influence the interpreter. Possible values: EXPLICIT

Example
OPTION Explicit

See also
DIM,SHARED,

Remarks
The only option currently supported is Option Explicit, which will cause wxBasic to generate an error when it encounters a reference to a variable that has not been declared. Without Option Explicit, the variable a will be automatically declared for you:
Without OPTION EXPLICIT, variables are created on demand a = 12

However, with Option Explict, the same code will generate an error, since a has not been explicitly declared:
Generates an error, because it is not declared: OPTION Explicit a = 12

With Option Explicit, you must declare all variables before use:

No error, a is declared before use OPTION Explicit DIM a a = 12

This is true even for global variables. To use global variables with Option Explicit, use SHARED.

5.17

PRINT, PRINT #

PRINT { [expr] [,] [;] } PRINT # expr { [expr] [,] [;] }

Explanation
Send the values following the PRINT statement to the output. If no channel is given by '#', the expression will be printed to standardoutput, usually the screen. Values seperated by semicolons {;} have no spaces between them, while values seperated by commas {,} have a single space placed between them:

Parameters
expr The characters that should be printed

Example
PRINT Hello, world! PRINT a = ; a

See also
INPUT,

Remarks
The linefeed is automatically placed after the last item, unless it is followed by a semicolon:
this generates a linefeed PRINT Hello, world! this does not PRINT Hello, world;

Output can be directed to a file by using the Print # form of the command:

open a file for output OPEN output.txt FOR OUTPUT AS #1 print some text PRINT #1, This is written to the file PRINT #1, And so is this close the file CLOSE #1

5.18

RETURN

Explanation
TODO:

Parameter Example See also Remarks

5.19
REDO

REDO

Explanation
Redo jumps to the top of the loop (similar to CONTINUE), but doesnt reevalute the test condition again. Redo can also be used inside a Try statement.

Example
Open a file. On failure, delete temp file and try again. TRY Open a file OPEN test.txt FOR OUTPUT AS #1 Perhaps out of disk space. Can temp file be deleted? CATCH FileExists( data.tmp ) Delete the temp file KILL( data.tmp ) Try again REDO END TRY

See also
CONTINUE,

Remarks
REDO is an easy way to get into an infinite loop if you arent careful.

5.20

SELECT CASE ... END SELECT

SELECT CASE expression { CASE caseTest {, caseTest } { statement } } [CASE ELSE { statement } ] END SELECT

Explanation
The SELECT statement is used to perform a series of tests on the same value. If there is no caseTest true, the CASE-ELSE - branch will be executed.

Parameter
expression The item that should be tested mostly a variable The test-statement or test-case. If the result of this statement is true, the respective case branch will be executed. Following test-cases are possible:

caseTest

IS = | <> | < | > | < | >= expr expr TO expr expr

statement

The wxBasic-Code that should be executed.

Example
SELECT CASE a CASE 1, 3 PRINT The CASE 4 TO 6, PRINT The CASE IS > 12 PRINT The CASE ELSE PRINT The END SELECT

value is either 1, or 3 8 value is 4, 5, 6, or 8 value is greater than 12 value is something else

See also
IF,

Remarks
Unlike C, only a single CASE branch is executed. That is, the single branches need not to be finished by a BREAK command.

5.21

SHARED

SHARED variable {, variable }

Explanation
Declare a variable in a FUNCTION or SUB as referring to a global variable of the same name. This prevents Option Explicit from generating an error.

Parameter
variable Name of the variable that should be SHARED

Example
DIM myGlobalVariable FUNCTION myFunction() SHARED myGlobalVariable PRINT Value of global is ; myGlobalVariable END FUNCTION

See also
DIM,FUNCTION,SUB

Remarks

5.22

STATIC

STATIC variableName {, variableName }

Explanation
Declare a variable that is local to a FUNCTION or SUB, but retains its value after the routine is called. The initial value of a STATIC variable is NOTHING.

Parameter
variableName Name of the variable that should be declared as STATIC

Example
FUNCTION accum( n ) declare result as a STATIC variable STATIC result first time calling accum? IF result = NOTHING THEN initialize the result result = n ELSE add value to the result result = result + n END IF return accumulated result RETURN result END FUNCTION

See also
FUNCTION,SUB

Remarks

5.23

SUB ... END SUB


expr] {, arg [= expr]} ] [, ...] ) variable } ] {, variable } ] {, variable } ]

SUB name ( [arg [= [ DIM variable {, [ STATIC variable [ SHARED variable [ RETURN ] [ EXIT SUB ] { statement } END SUB

Explanation
SUB is essentially the same as FUNCTION, but does not return any values. Refer to FUNCTION for details.

Parameter
name arg expr variable statement Name of the function Name of the Argument that's given to the subroutine If a expression is given it acts like a placeholder it's the default-value Name of local variable(s). This local variables are only valid within the function, except SHARED variables. Can be everything of the wxBasic-Language-Repertoire

See also
FUNCTION

5.24

THROW

THROW expr

Explanation
THROW triggers the TRY clause that it is embedded in. See TRY for details.

Parameter
expr

Example See also


TRY,

Remarks

5.25

TRY ... CATCH ... END TRY

TRY THROW expression { statement } [ CATCH expression { statement } REDO ] [ CATCH | ELSE { statement } REDO ] [ FINALLY { statement } REDO ] END TRY

Explanation
TRY catches errors thrown either by wxBasic when an error occurs, or by the application via the THROW statement. If an error occurs, code jumps to the first CATCH statement. If no CATCH statement handles the exception, it jumps to the next TRY block. A CATCH without a test expression matches any thrown error. To execute the TRY block again, call REDO. The FINALLY clause is always executed, even if no error occurred.

Parameter
expression statement Can be everything of the wxBasic-Language-Repertoire.

Example
attempt to open a file TRY OPEN myfile.txt FOR INPUT AS #1 PRINT This is written to the file CATCH PRINT Error printing to the file" FINALLY CLOSE #1 END TRY

See also
THROW,

5.26

WHILE ... END WHILE

WHILE expression [ BREAK ] [ CONTINUE ] [ EXIT WHILE ] { statement } [ELSE { statement } ] END WHILE | WEND

Explanation
WHILE repeats a loop until the test conditions are met. BREAK exits the loop immediately, and CONTINUE jumps to the top of the loop. If the WHILE statement is exited without executing a BREAK, the optional ELSE statement will be executed.

Parameter
expression statement This is the test condition. Can be everything of the wxBasic-Language-Repertoire.

Example
Search a file for a matching string WHILE NOT EOF() INPUT #1, text IF instr( text, matchingText ) THEN PRINT Found the text BREAK END IF ELSE PRINT Text not found END WHILE

See also
FOR...NEXT,

Remarks

6 Internal Routines
6.1
6.1.1

Mathematic
ABS( n )
Returns the absolute value of n.

6.1.2

ACOS( n )
Returns the arccos of n.

6.1.3

ASIN( n )
Returns the arcsin value of n.

6.1.4

ARCTAN( n )
Returns the arctangent value of n.

6.1.5

COS( n )
Returns the cosine of n.

6.1.6

EXP( n )
Returns the exponent of n.

6.1.7

FIX( n )
Truncates fractional number, rounding down towards zero.

6.1.8

FRAC( n )
Returns fractional portion of n.

6.1.9

LOG( n )
Returns the natural log of n.

6.1.10

ROUND( n )

Returns n rounded to the nearest integer.

6.1.11

SIGN( n )

Returns -1 if n is negative, 1 if n is positive, and 0 if n is zero.

6.1.12

SIN( n )

Returns the sin of n.

6.1.13

SQR( n )

Returns square root of n.

6.1.14

TAN( n )

Returns tangent of given angle in radians.

6.2
6.2.1

Shell specific
ARGV( n )
Returns the value of parameter n.

6.2.2

CHDIR( directoryName )
Not currently implemented

6.2.3

COMMAND( n )
Returns the value of parameter n passed from the command line.

6.2.4

DATE()
Returns the current data in MM-DD-YYYY format.

6.2.5

DIR()
Not currently implemented.

6.2.6

DIREXISTS( name )
Not currently implemented.

6.2.7

KILL( fileName )
Delete fileName.

6.2.8

MKDIR( directoryName )
Not yet implemented.

6.2.9

RENAME( oldFileName, newFileName )


Renames oldFileName to newFileName.

6.2.10

RMDIR( directoryName )

Not yet implemented.

6.2.11

RUN( commandString )

Not yet implemented.

6.2.12

SHELL( commandString )

Executes commandString, waits until finished.

6.3
6.3.1

Variables and Conversion


ASC( string )
Returns the ASCII value of the first character in string.

6.3.2

CHR( n )
Returns a string representation of the ASCII value n.

6.3.3

HEX( n )
Returns hexidecimal representation of n.

6.3.4

INDEXES( arrayName )
Returns number of indexes in arrayName.

6.3.5

INT( n )
Convert n to a 32 bit integer, truncating fractional portion.

6.3.6

LBOUND( arrayName )
Returns the lower bound of arrayName.

6.3.7

QUICKSORT( arrayName )
Not yet implemented.

6.3.8

STR( n )
Returns the string representation of n.

6.3.9

STRF( n )
Returns the string representation of n.

6.3.10

UBOUND( arrayName, index )

Returns the upper bound of index index in arrayName. Not yet implemented.

6.4
6.4.1

String Management
CONCAT( string1, string2 )
Returns string1 joined to string2.

6.4.2

FORMAT( formatString, ... )


Not yet implemented.

6.4.3

INSERT( targetString, subString, position )


Not yet implemented.

6.4.4

INSTR( [startPosition, ] searchString, searchForString )


Returns position of searchForStringin searchString, or 0 if not found.

6.4.5

LCASE( string )
Returns string in lower case.

6.4.6

LEFT( string, length )


Returns the length leftmost characters in string.

6.4.7

LEN( string )

LENGTH( string ) Returns the length of string.

6.4.8

LTRIM( string )
Returns string with leftmost whitespace removed.

6.4.9

MID( string, startPosition [, length] )


Returns substring from string starting at startPosition for length characters.

6.4.10 REPLACE( [startPosition, ] sourceString, searchForString, replaceWithString )


Returns string with searchForString replaced with replaceWithString.

6.4.11

REVERSE( string )

Returns reversed string.

6.4.12

RIGHT( string, length )

Returns length rightmost characters in string.

6.4.13

RINSTR( searchString, searchForString [, optionalStartPosition] )

Reverse version of Inst, searches from end to start position.

6.4.14

RTRIM( string )

Returns string with whitespace characters removed from right side.

6.4.15

SPACE( n )

Returns string built of n spaces.

6.4.16

STRING( string, repetitions ); STRING( n, repetitions )

Returns a string with string repeated repetition times. If value is numeric, converts n to an ASCII value first.

6.4.17

SUBSTR( sourceString, startPosition, endPosition )

Returns substring from sourceString, starting at startPosition to endPosition.

6.4.18

TALLY( [startPosition, ] searchString, searchForString )

Returns number of times searchForString occurs in searchString.

6.4.19

UCASE( string )

Returns string in upper case.

6.4.20

VAL( string )

Returns the numeric value of string.

6.5
6.5.1

Object Management
CONNECT( object, [id, ] eventType, routineName )

When event is triggered in object, causes routineName to be triggered.

6.5.2

DISCONNECT( object, [id, ] eventType )

Removes any callback for attached to object for eventType. See CONNECT().

6.5.3

GETWXAPP( n )
Not yet implemented.

6.5.4

GETWXHANDLE( handle )
Not yet implemented.

6.5.5

TYPEOF( object )
Returns string with name of objects datatype.

6.6
6.6.1

File Management
EOF( fileHandle )
Returns nonzero if fileHandle is not at the end of the file.

6.6.2

FCLOSE( fileHandle )
Closes fileHandle. Same as CLOSE #fileHandle.

6.6.3

FGETS( fileHandle )
Returns next line of text from fileHandle.

6.6.4

FOPEN( fileName, modeString )


Opens file fileName in r (read), w (write) or a (append) mode.

6.6.5

FPUTS( fileHandle, string )


Write string to fileHandle.

6.6.6

FILEEXISTS( fileName )
Returns nonzero if file exists.

6.6.7

FREEFILE( n )
Returns next free handle number.

6.6.8

LOC( fileHandle )
Returns the position in fileHandle.

6.6.9

LOF( fileHandle )
Returns the length of fileHandle.

6.6.10

READBYTE( fileHandle )

Returns a single byte from fileHandle.

6.6.11

SEEK( handle [, filePosition] )

Returns current file position. If filePosition is specified, seeks to that position.

6.6.12

WRITEBYTE( fileHandle, byte )

Writes a single byte to fileHandle.

6.7
6.7.1

Misc
MAINLOOP( n )
Not yet implemented.

6.7.2

RANDOMIZE( [seed] )
Reseeds random number generator with seed.

6.7.3

TIMER()
Returns current timer value.

6.7.4

TIME( n )
Returns current time as string in HH:MM:SS format.

6.8
6.8.1

Bit Manipulation
NOTBITS( n )
Returns bitwise not of n.

6.8.2

ORBITS( n1, n2 )
Returns bitwise OR of n1and n2.

6.8.3

XOR( n1, n2 )
Returns bitwise XOR of n1 and n2.

7 Buillt In Routines
wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR) wxBell() wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3)

wxCopyFile(const wxString& file1, const wxString& file2, bool overwrite = TRUE) wxCreateDynamicObject(const wxString& className) wxCreateFileTipProvider(const wxString& filename, size_t currentTip) wxDirExists(const wxString& dirname) wxDisplaySize(int *width, int *height) wxDos2UnixFilename(char *s) wxEnableTopLevelWindows(bool enable = TRUE) wxEndBusyCursor() wxError(const wxString& msg, const wxString& title = "wxWindows Internal Error") wxExecute(const wxString& command, bool sync = FALSE, wxProcess *callback = NULL) wxExit() wxFatalError(const wxString& msg, const wxString& title = "wxWindows Fatal Error") wxFileExists(const wxString& filename) wxFileModificationTime(const wxString& filename) wxFileNameFromPath(const wxString& path) wxFileSelector(const wxString& message, const wxString& default_path = "", const wxString& default_filename = "", const wxString& default_extension = "", const wxString& wildcard = "*.*", int flags = 0, wxWindow *parent = NULL, int x = -1, int y = -1) wxFindFirstFile(const char *spec, int flags = 0) wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString) wxFindNextFile() wxFindWindowAtPoint(const wxPoint& pt) wxFindWindowAtPointer(wxPoint& pt) wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL) wxFindWindowByName(const wxString& name, wxWindow *parent=NULL) wxGetColorFromUser(wxWindow *parent, const wxColour& colInit) wxGetCwd() wxGetEnvValue( const wxString& var ) wxGetHomeDir() wxGetMousePosition() wxGetNumberFromUser( const wxString& message, const wxString& prompt, const wxString& caption, long value, long min = 0, long max = 100, wxWindow *parent = NULL, const wxPoint& pos = wxDefaultPosition) wxGetOsDescription() wxGetOSDirectory() wxGetOsVersion() Styles wxUNKNOWN_PLATFORM wxCURSES wxXVIEW_X wxMOTIF_X wxCOSE_X wxNEXTSTEP wxBEOS wxGTK wxGTK_WIN32 wxGTK_OS2 wxGTK_BEOS wxGEOS wxOS2_PM wxWINDOWS wxPENWINDOWS wxWINDOWS_NT wxWIN32S wxWIN95 wxWIN386 wxMGL_UNIX wxMGL_X wxMGL_WIN32 wxMGL_OS2 wxWINDOWS_OS2

wxUNIX wxGetPasswordFromUser(const wxString& message, const wxString& caption = "Input text", const wxString& default_value = "", wxWindow *parent = NULL) wxGetTempFileName(const wxString& prefix, wxString& buf) wxGetTextFromUser(const wxString& message, const wxString& caption = "Input text", const wxString& default_value = "", wxWindow *parent = NULL, int x = -1, int y = -1, bool centre = TRUE) wxGetTranslation(const wxString str) wxGetWorkingDirectory(char *buf=NULL, int sz=1000) wxHandleFatalExceptions(bool doIt = TRUE) wxIsAbsolutePath(const wxString& filename) wxIsBusy() wxIsWild(const wxString& pattern) wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special) wxMessageBox(const wxString& message, const wxString& caption = "Message", int style = wxOK | wxCENTRE, wxWindow *parent = NULL, int x = -1, int y = -1) Styles wxOK wxYES_NO wxCANCEL wxYES wxNO wxNO_DEFAULT wxYES_DEFAULT wxICON_EXCLAMATION wxICON_HAND wxICON_WARNING wxICON_ERROR wxICON_QUESTION wxICON_INFORMATION wxICON_STOP wxICON_ASTERISK wxICON_MASK wxMkdir(const wxString& dir, int perm = 0777) wxNewId() wxNow() wxPathOnly(const wxString& path) wxPostEvent(wxEvtHandler *dest, wxEvent& event) wxRegisterId(long id) wxRemoveFile(const wxString& file) wxRenameFile(const wxString& file1, const wxString& file2) wxRmdir(const wxString& dir, int flags=0) wxSafeYield(wxWindow* win = NULL) wxSetEnv(const wxString& var, const wxString *value) wxSetWorkingDirectory(const wxString& dir) wxShell(const wxString& command = NULL) wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE) wxSleep(int secs) wxTrap() wxUnix2DosFilename(const char *s) wxUnsetEnv(const wxString& var) wxUsleep(unsigned long milliseconds) wxWakeUpIdle() wxYield()

8 The wxBasic Virtual Machine


This section documents the opcodes used in the wxBasic virtual machine. You can see a listing of opcodes produced by your program by typing: wxbasic -list filename

8.1

UNDEFINED

UNDEFINED This is opcode zero, and will cause the VM to throw an error if it is executed.

8.2

NOOP

NOOP This is a "no op" opcode. It does nothing, but acts as a placeholder. It's currently never generated by the VM.

8.3

TRACE

TRACE lineNumber This opcode is used to keep track of what line in the source file is being executed. If an error is thrown, this is how the VM can display the errant line. Generation of TRACE opcodes can be suppressed by the -notrace command line option.

8.4

HALT

HALT This opcode causes the VM to halt and the application to end.

8.5

END

END This opcode indicates the end of the main code section has been reached. If the wxWidgets library is linked and there is an active top window, the wxWidgets main loop will be entered. Otherwise, the application will end.

8.6

DROP

DROP n Drop n items from the stack.

8.7

MISSING

MISSING n Returns true if parameter n was not passed on the arglist. Used to implement optional parameters.

8.8

NOTHING

NOTHING Push the value of Nothing onto the stack.

8.9

LITERAL

LITERAL n Push literal n from the literal table onto the stack.
W_OP_LITERAL, W_OP_EMPTYSTRING, W_OP_INTEGER, /* for loop */ W_OP_FORPREP, W_OP_FORPREP1, W_OP_FORSTEP, W_OP_FORSTEP1, W_OP_FOREACHPREP, W_OP_FOREACHLOOP, /* routine calls */ W_OP_ROUTINE, W_OP_CALL, W_OP_RETURN, /* input/output */ W_OP_FILECLOSE, W_OP_FILECLOSEALL, W_OP_FILEOPEN, W_OP_FILEREAD, W_OP_READ, W_OP_REDIRECT, W_OP_STDIO, W_OP_PRINT, W_OP_PRINTLN, W_OP_PRINTTAB, W_OP_EMITTAB, W_OP_EMITLN, /* jumps */ W_OP_JMP, W_OP_JMPT, W_OP_JMPF, W_OP_JMPONT, W_OP_JMPONF, /* subroutines */ W_OP_JSR, W_OP_RET, /* push a literal onto the stack */ /* push an empty string onto the stack */ /* push following integer onto the stack */ /* /* /* /* /* /* set up for loop */ set up for loop, no step */ increment for loop */ increment for loop by 1 */ for each test */ for increment for each loop */

/* push routine id onto stack */ /* call a routine */ /* return from a call */ /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* close file */ close all files */ open a file */ read a line from the file */ read from stdin */ redirect output of print */ redirect back to standard i/o */ print a value */ print a linefeed */ print with trailing space */ print a space, no data */ print a linefeed, no data */ unconditional jump */ jump on true */ jump on false */ jump on true, drop if false */ jump on false, drop if true */

/* jump to a subroutine */ /* exit from subroutine */

/* exception handling */ W_OP_STARTCATCH, /* push catch address onto the catch stack */ W_OP_ENDCATCH, /* pop catch address off the catch stack, jump */ W_OP_JMPCATCHF, /* jump if expression is not exception */ W_OP_THROW, /* throw an exception */ W_OP_RETHROW, /* pop catch and rethrow current exception */ W_OP_EXCEPTION, /* push exception onto stack */ /* class related */ W_OP_DTOR, W_OP_DELETE, W_OP_VIRTUAL, W_OP_MYVIRTUAL, W_OP_CALLMETHOD, W_OP_CALLMYMETHOD, /* /* /* /* /* /* object destructor */ delete an object */ resolve a virtual method */ resolve virtual method with Me */ call method with object on stack*/ call method belonging to Me */

W_OP_NEW, W_OP_NEWTEMP, /* math ops */ W_OP_POWER, W_OP_NEGATE, W_OP_ADD, W_OP_SUB, W_OP_MUL, W_OP_DIV, W_OP_IDIV, W_OP_MOD, W_OP_SHL, W_OP_SHR, W_OP_INV, W_OP_CONCAT, W_OP_OR_BITS, W_OP_AND_BITS, W_OP_ADD_SET , W_OP_SUB_SET , W_OP_MUL_SET , W_OP_DIV_SET , W_OP_IDIV_SET , W_OP_MOD_SET , W_OP_CONCAT_SET , /* tests */ W_OP_EQ, W_OP_NE, W_OP_LT, W_OP_LE, W_OP_GT, W_OP_GE, W_OP_NOT, W_OP_DUP, W_OP_AND, W_OP_OR, W_OP_XOR, /* case tests */ W_OP_CASERANGE, W_OP_CASE, W_OP_IN, /* arrays */ W_OP_CREATEARRAY, W_OP_INITARRAY, W_OP_ERASEARRAY, /* tables */ W_OP_CREATETABLE, W_OP_SETLIST, W_OP_SETMAP, /* lists */ W_OP_CREATELIST, W_OP_GETSLICE, W_OP_SETSLICE, /* variables */ W_OP_FREE, /* accessing values */ W_OP_VARIABLE,

/* call to new */ /* call to new, create on stack */ /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* power */ negate value */ addition */ subtraction */ multiplication */ division */ integer division */ modulus */ bitwise left shift */ bitwise right shift */ inverse */ string concatenation */ bitwise or */ bitwise and */ increment lval */ decrement lval */ multiply lval */ divide lval */ integer divide lval */ mod lval */ concat lval */ equality */ inequality */ less than */ less or equal than */ greater than */ greater or equal than */ logical not */ duplicate stack value */ logical and */ logical or */ logical exclusive or */

/* range of case values */ /* case test */ /* element is in array */ /* create an indexed array */ /* create an array with default values */ /* reset array back to default values */ /* create a table */ /* copy items from stack into table */ /* map keys and values into table */ /* create a list */ /* return a slice from a list */ /* set a slice in a list */ /* set variable to undefined */ /* return pointer to variable */

W_OP_INDEX, W_OP_PROP, W_OP_PROPBYNAME, W_OP_ME, /* modifiers */ W_OP_GET, W_OP_SET, W_OP_LVAL, W_OP_SETTYPE }; /* opcode names */ char *wOpcodeName[] = { "UNDEFINED", "NOOP", "TRACE", "HALT", "END", "DROP", "MISSING", "NOTHING", "LITERAL", "EMPTYSTRING", "INTEGER", "FORPREP", "FORPREP1", "FORSTEP", "FORSTEP1", "FOREACHPREP", "FOREACHLOOP", "ROUTINE", "CALL", "RETURN", "FILECLOSE", "FILECLOSEALL", "FILEOPEN", "FILEREAD", "READ", "REDIRECT", "STDIO", "PRINT", "PRINTLN", "PRINTTAB", "EMITTAB", "EMITLN", "JMP", "JMPT", "JMPF", "JMPONT", "JMPONF", "JSR", "RET", "STARTCATCH", "ENDCATCH", "JMPCATCHF", "THROW", "RETHROW", "EXCEPTION", "DTOR", "DELETE", "VIRTUAL", "MYVIRTUAL", "CALLMETHOD", "CALLMYMETHOD",

/* /* /* /* /* /* /* /*

return return return return

pointer pointer pointer pointer

to to to to

value at index position */ property by index */ property by name */ current object */

put value of pointer onto stack */ store value on stack into pointer */ put pointer on stack */ set datatype for variable */

/* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /* /*

no such op */ no op */ trace */ halt execution */ end of code */ drop stack item */ return true if parm not passed in list */ push undefined value onto the stack */ push a literal onto the stack */ push an empty string onto the stack */ push following integer onto the stack */ set up for loop */ set up for loop", no step */ increment for loop */ increment for loop by 1 */ for each test */ for increment for each loop */ push routine id onto stack */ call a routine */ return from a call */ close file */ close all files */ open a file */ read a line from the file */ read from stdin */ redirect output of print */ redirect back to standard i/o */ print a value */ print a linefeed */ print with trailing space */ print a space", no data */ print a linefeed", no data */ unconditional jump */ jump on true */ jump on false */ jump on true", drop if false */ jump on false", drop if true */ jump to a subroutine */ exit from subroutine */ push catch address onto the catch stack */ pop catch address off the catch stack", jump */ jump if expression is not exception */ throw an exception */ pop catch and rethrow current exception */ push exception onto stack */ object destructor */ delete an object */ resolve a virtual method */ resolve virtual method with Me */ call method with object on stack*/ call method belonging to Me */

"NEW", "NEWTEMP", "POWER", "NEGATE", "ADD", "SUB", "MUL", "DIV", "IDIV", "MOD", "SHL", "SHR", "INV", "CONCAT", "OR_BITS", "AND_BITS", "ADD_SET ", "SUB_SET ", "MUL_SET ", "DIV_SET ", "IDIV_SET ", "MOD_SET ", "CONCAT_SET ", "EQ", "NE", "LT", "LE", "GT", "GE", "NOT", "DUP", "AND", "OR", "XOR", "CASERANGE", "CASE", "IN", "CREATEARRAY", "INITARRAY", "ERASEARRAY", "CREATETABLE", "SETLIST", "SETMAP", "CREATELIST", "GETSLICE", "SETSLICE", "FREE", "VARIABLE", "INDEX", "PROP", "PROPBYNAME", "ME", "GET", "SET", "LVAL", "SETTYPE" };

/* call to new */ /* call to new", create on stack */ /* power */ /* negate value */ /* addition */ /* subtraction */ /* multiplication */ /* division */ /* integer division */ /* modulus */ /* bitwise left shift */ /* bitwise right shift */ /* inverse */ /* string concatenation */ /* bitwise or */ /* bitwise and */ /* increment lval */ /* decrement lval */ /* multiply lval */ /* divide lval */ /* integer divide lval */ /* mod lval */ /* concat lval */ /* equality */ /* inequality */ /* less than */ /* less or equal than */ /* greater than */ /* greater or equal than */ /* logical not */ /* duplicate stack value */ /* logical and */ /* logical or */ /* logical exclusive or */ /* range of case values */ /* case test */ /* element is in array */ /* create an indexed array */ /* create an array with default values */ /* reset array back to default values */ /* create a table */ /* copy items from stack into table */ /* map keys and values into table */ /* create a list */ /* return a slice from a list */ /* set a slice in a list */ /* set variable to undefined */ /* return pointer to variable */ /* return pointer to value at index position */ /* return pointer to property by index */ /* return pointer to property by name */ /* return pointer to current object */ /* put value of pointer onto stack */ /* store value on stack into pointer */ /* put pointer on stack */ /* set datatype for variable */

wVariant *wVmGetVariable( int index ); char *wVmVariableName( wSymbol *s, int index ); void wVmTypeCast( wVariant *variant ); void wVmTrace( wSymbol *sRoutine, int *pcode, int pc ); void wVmExecute( wSymbol *sRoutine );

void wVmDecompile( wSymbol *sRoutine ); int wVmDecompileOp( wSymbol *sRoutine, int *pcode, int pc ); void wVmDecompileAll( void ); void wVmShowOp( int opcode, int args, int arg1, int arg2, int arg3 );

9 License 10 Frequently Asked Questions (FAQ) 11 Related Links


11.1
11.1.1

wxBasic Home
Help-Site:

http://wxbasic.sourceforge.net/

http://noforum.de/wxBasicscript-documentation/wxbasic/frameset.htm

11.2
11.2.1

Foren
deutsch:

http://f27.parsimony.net/forum67321/index.htm

11.2.2

englisch:

http://wxbasic.sourceforge.net/phpBB2/index.php

11.3

Tutorials

http://www.wxwidgets.org/wiki/index.php/WxBasic_Tutorial

Potrebbero piacerti anche