Oxygen Basic Compiler - documentation.help · Oxygen Basic (o2H) is a Just-In-Time compiler...

Post on 13-Feb-2020

26 views 0 download

transcript

OxygenBasicCompiler

Copyright©CharlesEVPegge,2010-2018

IntroductionOxygenBasic(o2H)isaJust-In-Timecompilerassembler,deployedinasingleDLLthattakessourcecodestringsandreturnsexecutablebinary.ItisanextensionoftheO2assembler.Thisimplementationcanbeembeddedinanyapplicationtoprovidehighperformanceprogrammability.Thecompilercanalsogenerateconventionalexecutablesanddynamiclinklibraries(DLL).

OxygensupportsObjectOrientedProgrammingwithmultipleinheritanceandalsosingleinheritancemodes,moresuitedtoCOM.InadditiontothisO2HsupportsUser-definedoperatorsandoperatorsetsforusewithcomplexnumbers,matrices,vectors,setsandotherspecialisedforms.Itcanalsocompile&executestringsofsourcecodeatruntimewithitsbuiltincompile()function,openingnewpossibilitiesforfunctionalprogramming.

Thebuiltinfunctionsetissmall.butcontainsthenecessarytoolstobuildclass/functionlibrariestoanyscale.

InadditiontounderstandingBasicintheQBasicgenre,OxygencanreadsufficientCsyntaxtodealwithmostCheadersdirectly,eliminatingtheneedtotranslatethemintoBasic.

Copyright©CharlesPegge,2010

typesvoid,sbyte,ubyte,byte,string,string2,wstring,bstring,gstr_,bstr,bstring2,char,wchar,cstr_,asciiz,zstring,zstring2,asciiz2,short,wide,long,int,integer,float,single,double,extended,quad,word,dword,ulong,uint,qword,any,sys,boolean,bool,

USE: tospecifythetypesofvariablesandcreatethemEXAMPLE:

intx

dimasintx

dimxasint

varintx

dimsyntaxdim,

REMARKS: Cstyleinstantiationsisasimpleralternativetousing'Dim'.

RELATED: globallocalstatic

'--------------

'DIMVARIATIONS

'==============

'----------------

'POSTDEFINETYPE

'================

dimi,j,kaslong

'---------------

'PREDEFINETYPE

'===============

dimaslongi,j,k

'-----------

'MIXEDTYPES

'===========

dimaslongi,j,k,asstrings,t

'----------

'MULTILINE

'==========

dimaslongi,j,k,

asstrings,t

dimaslong,

i,

j,

k

'--------------

'INITIALVALUES

'==============

dimaslong,

i=1,

j=2,

k=42

'-------------------------

'SPREADLINESANDCOMMENTS

'=========================

dimaslong,

i=1,'thesecanbespreadovermanylines

'--------

j=2,'withinterveningcomments

'--------

k=42'

'--------------------

'MULTIPLEASSIGNMENTS

'====================

dimaslonga(10)=>(2,4,6,8,10,12,42,99)

print"Answer:"stra(7)

'-----------------

'SYNTAXVARIATIONS

'=================

dimlonga(10)=>(2,4,6,8,10,12,42,99)

dimlonga[10]=>(2,4,6,8,10,12,42,99)

longa[10]=>(2,4,6,8,10,12,42,99)

longa[10]<=(2,4,6,8,10,12,42,99)

longa[10]={2,4,6,8,10,12,42,99}

longa[]={2,4,6,8,10,12,42,99}

longa={2,4,6,8,10,12,42,99}

longa=

{

2,4,6,8,10,12,42,99

}

'------------------

'POINTEREDVARIABLE

'==================

dimstrings="ABCDEFGHIJ"

dimbytebatstrptrs

dimbytebyrefb:@b=strptrs

bytebatstrptrs

byte*b=strptrs

'printb[7]'71G

'--------------------

'USINGDYNAMICMEMORY

'====================

dimfloatfatgetmemory1024*4:f={1.5,2.5,3.5}

'printf[2]

freememory@f'releaseallocatedmemory

'---------------------------

'DIMS:GLOBAL,STATIC,LOCAL

'===========================

globalintg=1'visibletorestofprogramfollowingthisstatement

functionf(pasint)asint

staticints=0'permanentstorage

localintl=100'temporarystorage

s+=10

returnp+l+s+g

endfunction

printf(1000)'1111

printf(1000)'1121

'--------------

'LIMITINGSCOPE

'==============

dimlonga=16

scope

dimlonga=1

'printa'1

...

endscope

'printa'16

inhstructurestype,

USE: specifycompundstructureforavariableRELATED: structtypedef

'--------------

'COMPOUNDTYPES

'==============

typecolor32

rasbyte

gasbyte

basbyte

aasbyte

=

rgbaaslong'UNION

endtype

'-------------

'DERIVEDTYPE:

'=============

typecolortext

txtasstring

cascolor32

endtype

dimtascolortext

t.txt=`Colorcode`

t.c.r=8

t.c.b=16

t.c.g=32

t.c.a=64

printt.txthext.c.rgba

'print"STRUCTURE:

'"structureofcolor32

'-----------------

'SYNTAXVARIATIONS

'=================

typecolor32

byter

byteg

byteb

bytea

=

longrgba'UNION

endtype

typecolor32

byter,g,b,a

=

longrgba'UNION

endtype

typecolor32byter,g,b,a=longrgba

typecolortextstringtxt,color32c

structcolor32{

byter,g,b,a

=

longrgba

}

typedefstruct_color32{

byter,g,b,a

=

longrgba

}color32,*pcolor32

typedefstruct_color32{

union{

struct{

byter,g,b,a

}

longrgba

}

}color32,*pcolor32

'#recordofcolor32

'#recordof_color32

'#recordofcolortext

includesonce,

ACTION: ensuresthatafileisincludedinthesourcecodeoneonly.EXAMPLE:

#includeonce"../../MinWin.inc"

RELATED: include#includeincludepath

equates$,%,

REMARKS: $and%areequivalent

RELATED: def#defmacro#define

'$filename"t.exe"

'usesrtl64

'---------------

'EQUATES:$or%

'===============

'strictlyspeakingthesearesingle-linemacros

%a=1

%b=2

%c3

%c3

%c=3

$d4

$d"four"

%d"four"

%=eb*c'precalcuateevalue'6

'#recordofe

%f8

%%f7'defaultvalue7(unlesspreviouslydefined)

%sp""

%cm","

'$%prefixesandsuffixesareignored

print""acmbcmccmdcmecmf'1,2,3,four,6,8

'print%acm%bcm%ccm%dcm%ecmf

'INCLUDINGARGUMENTS

'argumentsarerepresentedby%1..%9

%display"valueof%1:"%1

printdisplayd

arraysarrays,

REMARKS: Onlysingledimensionedarraysaredirectlysupported

RELATED: dim

'%filename"t.exe"

'usesrtl64

'-------------

'STATICARRAYS

'=============

dimaslonga(10)={2,4,6,8,10,12}

a(10)=a(1)+a(4)

printa(10)

'--------------

'DYNAMICARRAYS

'==============

dimaslongaatgetmemory(10*sizeof(long)):a={2,4,6,8,10,12}

...

freememory@a

dimaslonga(10)={2,4,6,8,10,12}

'--------

'OVERLAYS

'========

dimasstrings="ABCDEFGHIJ"

dimasbytebatstrptr(s)

printstr(b[3])":"chr(b[3])

'-----------------------

'MULTIDIMENSIONALARRAYS

'=======================

macroa(x,y)av(y*1024+x)

dimintav[1024*1024]

a(100,200)=42

printa(100,200);42

'----------

'INDEXBASE

'==========

'

diminta[100]={10,20,30,40}

indexbase1'default:firstelementisindexedas1

'printa[2]'20

indexbase0

printa[2]'30

'-------------

'PSEUDOARRAYS

'=============

dimav[100]

functiona(inti,v)'setter

i*=2

av[i]=v

endfunction

functiona(inti)asint'getter

i*=2

returnav[i]

endfunction

a(7)=42'thisisinterpretedasa(7,42)

'printa(7)

blocksblock,scope,skip,o2,(,

RELATED: proceduresmacros

'------

'MACROS

'======

macrocube(v)

v*v*v

endmacro

#definecube(v)v*v*v

defcube%1*%1*%1

%cube%1*%1*%1

$cube%1*%1*%1

'printcube3

'MACROMEMBERS

'=============

macromultiple(v)

macro.two(v)

v*v

endmacro

macro.three(v)

v*v*v

endmacro

macro.four(v)

v*v*v*v

endmacro

endmacro

printmultiple.four3

macrosmacro,#define,def,deff,%,$,

RELATED:macrofunctionsmacrooperatorsprocedures

proceduresfunction,sub,method,gosub,

RELATED:macro

'----------

'PROCEDURES

'==========

'SUBROUTINES

floatv

gotoncube

cube:'subroutine

'printv*v*v

ret

ncube:

v=3:gosubcube

'SUBSANDFUNCTIONS

'==================

subcube(fasfloat,gasfloat)

g=f*f*f

endsub

dimfloata

cube2,a

'printa

functioncube(fasfloat)asfloat

function=f*f*f

endfunction

functioncube(fasfloat)asfloat

returnf*f*f

endfunction

'printcube2

'METHODS(INCLASSES)

'====================

classmultipliers

methodcube(fasfloat)asfloat

returnf*f*f

endmethod

endclass

dimmultipliersm

'printm.cube4

'ALTERNATIVESYNTAX

'==================

'USEOF{..}

'===========

functioncube(fasfloat)asfloat{returnf*f*f}

functioncube(fasfloat)asfloat{

returnf*f*f

}

floatcube(fasfloat){

returnf*f*f

}

floatcube(floatf){

returnf*f*f

}

'printcube2

'PASSINGPARAMETERSBYREFERENCE

'===============================

dimasfloatf()={1,2,3,4,5}

functioncubes(fasfloat,byvalnasint)'defaultbyref

indexbase1

inti

fori=1ton

v=f[i]

printv*v*v

next

endfunction

functioncubes(float*f,intn)

indexbase1

floatv

inti

fori=1ton

v=f[i]

printv*v*v

next

endfunction

'cubesf(2),3

'cubesf,countof(f)

'OPTIONALPARAMETERS

'===================

functioncubes(fasfloat,optionalbyvalnasint)

ifn=0thenn=1

indexbase1

floatv

inti

fori=1ton

v=f[i]

printv*v*v

next

endfunction

'cubesf(3)

'cubesf(3),1

'cubesfloat{1,2,3,4},countof'PASSINGLITERALDATASET

'DEFAULTPARAMETERS

'==================

functioncubes(float*f,intn=2)

indexbase1

floatv

inti

fori=1ton

v=f[i]

printv*v*v

next

endfunction

'cubesf(3)

'cubesf(3),2

'ELLIPSIS...

'============

functioncuber(intn,...)

indexbase0

floatv

inti

fori=1ton

v=(int)param[i]

printv*v*v

next

endfunction

'cuber3,2,3,4

conditionalsif,then,elseif,else,endif,

RELATED: selectionloops

'------------

'CONDITIONALS

'============

strings

inta=1,b=2

'SINGLELINEFORMAT

ifa>bthens="A>B"elses="A<=B"

'prints

'MULTI-LINEFORMAT

ifa>bthen

s="A>B"

elseifa=bthen

s="A=B"

else

s="A<B"

endif

'-----------------

'SYNTAXVARIATIONS

'=================

if(a>b){s="A>B"}elseif(a=b){s="A=B"}else{s="A<B"}

ifa>b{s="A>B"}elseifa=b{s="A=B"}else{s="A<B"}

ifa>b{

s="A>B"

}elseifa=b{

s="A=B"

}else{

s="A<B"

}

print"A=1B=2

"s

loopsdo,while,exit,continue,wend,enddo,

RELATED: iterationconditionals

'-----

'LOOPS

'=====

dima,b,c,daslong,sasstring

'SIMPLELOOPS

'------------

a=4

'

b=0

do

b+=1

ifb>athenexitdo

enddo'orenddo

b=0

do

b+=1

ifb>athenexitdo

loop

'-----------------

'CONDITIONALFORMS

'=================

b=0

whileb<=a

b+=1

endwhile'orendwhile

b=0

whileb<=a

b+=1

wend

b=0

whileb<=a{b+=1}

b=0

do{b+=1}whileb<a

b=0

do{b+=1}untilb>=a

b=0

do

b+=1

loopwhileb<a

b=0

do

b+=1

loopuntilb>=a

b=0

do

b+=1

ifb<athencontinuedo

ifb<athenrepeatdo

ifb>=athenexitdo

ifb>=athenbreak

loop

b=0

do

b+=1

continuewhileb<a'if/when/while

continueuntilb>=a

repeatuntilb>=a

redountilb>=a

redountilnotb<a

exitwhenb>=a'if/when

exitwhennotb<a

breakwhenb>=a'if/when

enddo

print"ok"

iterationfor,to,step,next,

RELATED: loops

'---------

'ITERATION

'=========

dima,b,c,d,iaslong

dimsasstring="QWERTY"

'checksumexample

b=0

fori=1tolen(s)

b+=asc(s,i)

next

b=0

fori=1tolen(s)step1

b+=asc(s,i)

next

b=0

fori=len(s)to1step-1

b+=asc(s,i)

next

'-----------------

'SYNTAXVARIATIONS

'=================

b=0

fori=1tolen(s)step1{

a=asc(s,i)

b+=a

}

b=0

fori=1,len(s),1{

a=asc(s,i)

b+=a

}

b=0

for(i=1,i<=len(s),i++){

a=asc(s,i)

b+=a

}

#semicolonseparator

b=0

for(i=1;i<=len(s);i++){

a=asc(s,i)

b+=a

}

#semicoloncomment

b=0

for(i=1,i<=len(s),i++){

a=asc(s,i)

b+=a

}

defqu"'"

print"Checksumfor"qusqu"="b

selectionselect,case,case,endselect,

RELATED: conditionals

'------

'SELECT

'======

dimaaslong,sasstring

a=3

'COMPACTFORM

'------------

selecta'selectcasea

case1:s="A=1"

case2:s="A=2"

case3:s="A=3"

caseelse:s="A>3"

endselect'endsel

'GENERALFORM

'------------

selecta

case1

s="A=1"

case2

s="A=2"

case3

s="A=3"

caseelse

s="A>3"

endselect

'------------------

'SYNTAXVARIATIONS

'=================

selecta{

case1

s="A=1"

case2

s="A=2"

case3

s="A=3"

caseelse

s="A>3"

}

switcha{

case1

s="A=1"

break

case2

s="A=2"

break

case3

s="A=3"

break

caseelse

s="A>3"

break

}

'----------

'EXTENSIONS

'==========

selecta

case1

s="A=1"

case2

s="A=2"

case3

s="A=3"

case4,5,6

'

case7to9

'

case10to<20

'

caseelse

s="A>3"

endselect

prints

structurestype,

RELATED: classesclass

'--------------

'COMPOUNDTYPES

'==============

typecolor32

rasbyte

gasbyte

basbyte

aasbyte

=

rgbaaslong'UNION

endtype

'-------------

'DERIVEDTYPE:

'=============

typecolortext

txtasstring

cascolor32

endtype

dimtascolortext

t.txt=`Colorcode`

t.c.r=8

t.c.b=16

t.c.g=32

t.c.a=64

printt.txthext.c.rgba

'print"STRUCTURE:

'"structureofcolor32

'-----------------

'SYNTAXVARIATIONS

'=================

typecolor32

byter

byteg

byteb

bytea

=

longrgba'UNION

endtype

typecolor32

byter,g,b,a

=

longrgba'UNION

endtype

typecolor32byter,g,b,a=longrgba

typecolortextstringtxt,color32c

structcolor32{

byter,g,b,a

=

longrgba

}

typedefstruct_color32{

byter,g,b,a

=

longrgba

}color32,*pcolor32

typedefstruct_color32{

union{

struct{

byter,g,b,a

}

longrgba

}

}color32,*pcolor32

'#recordofcolor32

'#recordof_color32

'#recordofcolortext

classesclass,objects,oop,has,of,from,inherits,virtual,pure,com,new,del,

RELATED: structurestype

'-------

'CLASSES

'=======

'METHODS(INCLASSES)

'====================

classmultipliers

methodcube(fasfloat)asfloat

returnf*f*f

endmethod

endclass

dimmultipliersm

'printm.cube4

'ALTERNATIVESYNTAX

'==================

classmultipliers{

methodcube(fasfloat)asfloat{

returnf*f*f

}

}

dimmultipliersm

printm.cube4

operatorsand,or,xor,=,:=,+,-,*,/,\,^,+=,-=,*=,/=,==,!=,<>,<,>,<=,>,>=,<=,and=,or=,xor=",&,|,&=,|=,&&,||,^^,&&=,||=,^^=,<<,>>,<<,>>>,

ACTION: changesthestateofanaccumulatorUSE: formulatingexpressions,inconjunctionwithoperandsEXAMPLE:

a*b+c/4

REMARKS: universalfeatureofmathsandprogramminglanguages

RELATED: types

callingstdcall,cdecl,ms64,pascal,

ACTION: determineshowparametersarepassedonthestack,whenmakingacall

voidUSE: specifyanulltypeEXAMPLE:

'Variables:

void*pv=getmemory(100*sizeoffloat)

...

freememorypv

'

'Infunctionheaders:

functionfoo(byrefvasvoid)asvoidptr

void*foo(void*v)

'Proceduresnotreturningavalue:

voidfoo()

'

REMARKS: Voidcannotbeuseddirectly.

RELATED: sysanytypes

sbyteUSE: specifyasignedbytetype(8bitswide)EXAMPLE:

sbytex=-10

REMARKS: limitedtovaluesrangingfrom-128to127/0x80to0x7F

RELATED: types

ubyteUSE: specifyabytetype(8bitswide)EXAMPLE:

ubytesemicolon=59

REMARKS: limitedtovalues0..255/0x00to0xFF

RELATED: types

byteUSE: specifyabytetype(8bitswide)EXAMPLE:

bytecolon=58

REMARKS: limitedtovalues0..255/0x00to0xFF

RELATED: types

stringACTION: returnsastringofcharactersUSE: string=string(length,character)EXAMPLE:

string=string(4,"a")

RESULT:s="aaaa"

RELATED: spacenulsasc

string2USE: specifyastringtypewith16-bitcharacters,supportingunicodeEXAMPLE:

wstringsw

getfile"greek.txt",sw

REMARKS: stringsareautomaticallydestroyedwhenoutofscope.

RELATED: unictypes

wstringUSE: specifyastringtypewith16-bitcharacters,supportingunicodeEXAMPLE:

wstringsw

getfile"greek.txt",sw

REMARKS: stringsareautomaticallydestroyedwhenoutofscope.

RELATED: unictypes

bstringUSE: specifyabstringtypewith8-bitcharactersEXAMPLE:

bstrings="name:"

...

freess

REMARKS: bstringsmustbefreedbeforegoingoutofscope.

RELATED: bstring2types

gstr_

bstrUSE: specifyabstringtypewith8-bitcharactersEXAMPLE:

bstrs="name:"

...

freess

REMARKS: bstringsmustbefreedbeforegoingoutofscope.

RELATED: bstring2types

bstring2USE: specifyabstringtypewith16-bitcharacters,supportingunicodeEXAMPLE:

bstring2sw

getfile"greek.txt",sw

...

freessw

REMARKS: bstringsmustbefreedbeforegoingoutofscope.

RELATED: bstringtypes

charUSE: specifyastringofasciicharacters(8bitswide)EXAMPLE:

charw="world"

charbuf[1024]

buf=w

print"hello"+buf

REMARKS: similartoCchar,butisnotconflatedwithbytewhichisanumerictype

RELATED: wchartypes

wcharUSE: specifyastringofwidecharacters(16bitswide)EXAMPLE:

wcharw="world"

wcharbuf[1024]

buf=w

printbuf

RELATED: chartypes

cstr_

asciizUSE: specifyastringofasciicharacters(8bitswide)EXAMPLE:

asciizw="world"

asciizbuf[1024]

buf=w

print"hello"+buf

REMARKS: similartoCchar,butisnotconflatedwithbytewhichisanumerictype

RELATED: wchartypes

zstringUSE: specifyastringofasciicharacters(8bitswide)EXAMPLE:

zstringw="world"

zstringbuf[1024]

buf=w

print"hello"+buf

REMARKS: similartoCchar,butisnotconflatedwithbytewhichisanumerictype

RELATED: wchartypes

zstring2USE: specifyastringofwidecharacters(16bitswide)EXAMPLE:

zstring2w="world"

zstring2buf[1024]

buf=w

printbuf

RELATED: chartypes

asciiz2USE: specifyastringofwidecharacters(16bitswide)EXAMPLE:

asciiz2w="world"

asciiz2buf[1024]

buf=w

printbuf

RELATED: chartypes

shortUSE: specifyashortinteger(16bitswide).Alsousedinconjunction

withothertypestohalvethebitwidthEXAMPLE:

shorta

shortintb

shortshortc'ansbyte

RELATED: longtypes

wideUSE: specifyawidecharacterstring(16bitswide).Alsousedin

conjunctionwithothertypestodoublethebitwidthEXAMPLE:

wides

widecharsw

widefloatfw'adoubleprecisionfloat

RELATED: shorttypes

longUSE: specifyalonginteger(32bitswide).Alsousedinconjunction

withothertypestodoublethebitwidthEXAMPLE:

longi

RELATED: shorttypes

intUSE: specifyalongsignedinteger(32bitswide)EXAMPLE:

inti=0x7fffffff

RELATED: dwordtypes

integerUSE: specifyalongsignedinteger(32bitswide)EXAMPLE:

integeri=0x7fffffff

RELATED: dwordtypes

floatUSE: specifyafloatingpointvariable(32bitswide)EXAMPLE:

floatf=1/100

REMARKS: sameassingle

RELATED: singledoubleextendedtypes

singleUSE: specifyafloatingpointvariable(32bitswide)EXAMPLE:

singlef=1/100

REMARKS: sameasfloat

RELATED: floatdoubleextendedtypes

doubleUSE: specifyadoubleprecisionfloatingpointvariable(64bitswide)EXAMPLE:

doublef=1/3

RELATED: singlefloatextendedtypes

extendedUSE: specifyanextendedprecisionfloatingpointvariable(80bitswide)EXAMPLE:

extendede=1/3

REMARKS: thistypeholdsthefullprecisionofthepentiumfloatinpointprocessor(FPU)

RELATED: singlefloatdoubletypes

quadUSE: specifyadoubleprecisionsignedinteger(64bitswide)EXAMPLE:

quadq

REMARKS: Ina64bitsystem,theseareprocesseddirectlyontheCPU.Ina32bitsystem,quadsarepassedtotheFPUforprocessing

RELATED: qwordintshortsbytetypes

wordUSE: specifyashortunsignedinteger(16bitswide)EXAMPLE:

wordw=0xA000

RELATED: shortintdwordtypes

dwordUSE: specifyalongunsignedinteger(32bitswide)EXAMPLE:

dwordui=0xA0000000

RELATED: wordlongintquadtypes

ulongUSE: specifyalongunsignedinteger(32bitswide)EXAMPLE:

ulongu=0xA0000000

REMARKS: sameasuint

RELATED: uintwordtypes

uintUSE: specifyalongunsignedinteger(32bitswide)EXAMPLE:

uintu=0xA0000000

REMARKS: sameasdwordandulong

RELATED: dwordwordbytetypes

qwordUSE: specifya64bitoperandinassemblycodeEXAMPLE:

fldqwordd

REMARKS: Onlyusedinassemblycode,notBasic.

RELATED: integerquadtypes

anyUSE: specifyaparameterofuncertaintype,nominallyasignedinteger

ofsystemwidth(32/64bitswide)EXAMPLE:

functionf(any*a){...}

REMARKS: Parameterofanytypemaybepassedby-reference.LikeCvoid*.

RELATED: systypes

sysUSE: specifyasignedintegerofsystemwidth(32/64bitswide)EXAMPLE:

sysi=42

REMARKS: thistypeisalwayswideenoughtoholdapointer.

RELATED: anyintquadtypes

booleanUSE: specifyavariabletoholdBooleantrue/falsestatesEXAMPLE:

booleant=true

ifnottthen...

REMARKS: NotionallyaBooleantype,butinreality.itisansbyte(8bitsignedinteger

RELATED: boolbyteintanytypesbooleantypes

boolUSE: specifyavariabletoholdBooleantrue/falsestatesEXAMPLE:

boolt=true

ifnottthen...

REMARKS: NotionallyaBooleantype,butinreality.itisa32bitsignedinteger,asinC

RELATED: anytypesbooleaninttypes

dimACTION: defineasetofvariablesUSE: createvariablesandarraysofvariableswithoptionalinitialvaluesEXAMPLE:

dimasstrings="HelloWorld"

RELATED: redimletvar

localACTION: definealocalsetofvariablesEXAMPLE:

localstrings

RELATED: dimstatic

staticACTION: defineastaticsetofvariables,(persistantbutinvisibleoutsidthe

block)EXAMPLE:

staticstrings

RELATED: dimlocal

typeACTION: defineacompoundvariabletypeEXAMPLE:

'typergbacolor

redasbyte

greenasbyte

blueasbyte

alphaasbyte

endtype

RELATED: typedefstructclass

structACTION: defineacompoundvariabletype(CSyntax)EXAMPLE:

structrgbacolor

{

redasbyte

greenasbyte

blueasbyte

alphaasbyte

}

RELATED: typetypedefclass

typedefACTION: defineasetoftypes(Csyntax)USE: createtypedefinitionsforcreatingothertypesEXAMPLE:

'typedefDouble*pDouble

RELATED: typestructclassunionenum

includeACTION: includesourcecodefromanotherfileUSE: usedforincludingheaderfilesandotherunitsofsourcecodeEXAMPLE:

#include"rtl32.inc"

REMARKS: includeand#includearethesame

RELATED: includepathembedfile

#includeACTION: includesourcecodefromanotherfileUSE: usedforincludingheaderfilesandotherunitsofsourcecodeEXAMPLE:

#include"rtl32.inc"

REMARKS: includeand#includearethesame

RELATED: includepathembedfile

includepathACTION: defineafilepathforsourcefilesspecifiedbyinclude.RELATED: includelibrarypath

$ACTION: defineanequate(whichcanbeusedasconstants)RELATED: equatesmacros#define.#def.def

%ACTION: defineanequate(whichcanbeusedasconstants)RELATED: equatesmacros#define.#def.def

defACTION: definealowlevelmacroEXAMPLE:

''DEFINEMACRO:

REMARKS: defand#defarethesame

RELATED: macro#definedeff

#defACTION: definealowlevelmacroEXAMPLE:

''DEFINEMACRO:

REMARKS: defand#defarethesame

RELATED: macro#definedeff

macroACTION: defineahighlevelmacroUSE: manyuses.Oftenapseudofunctionforproducinginlinecode

insteadofacall

'------

'MACROS

'======

macrocube(v)

v*v*v

endmacro

#definecube(v)v*v*v

defcube%1*%1*%1

%cube%1*%1*%1

$cube%1*%1*%1

'printcube3

'MACROMEMBERS

'=============

macromultiple(v)

macro.two(v)

v*v

endmacro

macro.three(v)

v*v*v

endmacro

macro.four(v)

v*v*v*v

endmacro

endmacro

printmultiple.four3

RELATED:macros#define#defdefdeff

#defineACTION: defineamacro(Csyntax)USE: CpreprocessorstatementsEXAMPLE:

#defineX32

RELATED: macrosmacrodef#ifdef#ifndef

blockACTION: startablockRELATED: blocksscopeexitrepeatdowhileifselect

scopeACTION: startascopeUSE: createablockwherevariablesandfunctionsmaybelocally

definedEXAMPLE:

:

sysi=4

scope

sysi=8

'print"innerscopei="i

endscope

'-----------------

'EQUIVALENTSYNTAX

'=================

scope

{

sysi=8

'print"innerscopei="i

}

(

sysi=8

'print"innerscopei="i

)

print"outerscopei="i'i=4

REMARKS: whenthescopeendsanydefinitionscreatedwithinthescopewillbeforgotten.

RELATED: blocksblocknamespace

o2ACTION: startablockofo2machinecodenotationUSE: insertinginlinemachinecodeandotherbinarydata.directuseof

o2language(usedbytheo2linker)EXAMPLE:

o2b800010000'machinecodeformoveax,256

RELATED: blocks

deffACTION: createanassemblycodemacrofortheFPU(metatype-17)USE: tocreatefloatingpointmathsfunctionsEXAMPLE:

deffsinefsin

REMARKS: DeffmacrosmakeuseoftheFPU.Allfloatfunctionsaredefinedthisway.Thesearenon-recursivemacrosandtakenomacroarguments.TheexpressionparserisFPU-awareandtakescareofpassingparametersontotheFPUstack.

RELATED: macrosdef#definemacrosincos

macrofunctionsUSE: invokemulti-linemacroswithinexpressions

'USINGMACROFUNCTIONS

'2DARRAYWITHBOUNDARYCLIPPING

indexbase0

intpix[800*600]

'

'SINGLE-LINEMACROFUNCTION

'macropix2d(x,y)pix(y*800+x)

'

'MULTI-LINEMACRORETURNINGAUNIQUEVARIABLE

'

macropix2dint*(v,x,y,vv)

=============================

'vpixelpointersupportingread/write

'xhorizontalcoordinate

'yverticalcoodinate

'vvsinkpixel

ifx>=0andx<800andy>=0andy<600

@v=@pix(y*800+x)

else

intvv=0xffffffff'valuewhenoutofbounds

@v=@vv

endif

endmacro

'

'TEST

pix2d(1,20)=0xaabbccdd

printhexpix2d(1,20)

printhexpix2d(800,10)

REMARKS: implementsin-linefunctions

RELATED: macrosmacrooperators

macrooperatorsUSE: encodeoperatorsetsfordifferenttypes(UDTs)

'---------------

'MACROOPERATORS

'===============

'PARTIALDEMO

typevector3f

floatx,y,z

endtype

macrovector3f_op

macro."save"(a,acc)

a.x=acc.x

a.y=acc.y

a.z=acc.z

endmacro

macro."load"(acc,a)

acc.x=a.x

acc.y=a.y

acc.z=a.z

endmacro

macro."neg"(acc,a)

acc.x=-a.x

acc.y=-a.y

acc.z=-a.z

endmacro

macro."+"(acc,a)

acc.x+=a.x

acc.y+=a.y

acc.z+=a.z

endmacro

macro."-"(acc,a)

acc.x-=a.x

acc.y-=a.y

acc.z-=a.z

endmacro

macro."*"(acc,a)

acc.x*=a.x

acc.y*=a.y

acc.z*=a.z

endmacro

macro."/"(acc,a)

acc.x/=a.x

acc.y/=a.y

acc.z/=a.z

endmacro

'

macro."str"string(out,a)'COREFUNCTIONS

out=str(a.x)+","+str(a.y)+","+str(a.z)

endmacro

'

endmacro

'TESTS

'=====

'#recordof"r.txt"vector3f_op

dimvector3fA={1,2,3}

dimvector3fB={10,20,30}

dimvector3fC={10,100,1000}

printstr(A)

printstr(A+B)

printstr(C*(A+B))

REMARKS: implementingoperatorsforcompundtypes:vectors,complexnumbers,matrices,etc.

RELATED: macrosmacrofunctions

functionACTION: defineafunctionEXAMPLE:

functiontriple(iasint)asint

returni*3

endfunction

RELATED: proceduressubmethod

subACTION: defineasub.(likeafunctionbutnotreturningavalue)EXAMPLE:

subtriple(iasint,jasint)

j=i*3

endsub

RELATED: proceduresfunctionmethod

methodACTION: defineamethod.(afunctionorsubforobjects)EXAMPLE:

methodtriple(iasint)asint

returni*3

endmethod

RELATED: proceduresfunctionsub

gosubACTION: callalabelledsubroutineUSE: invokelocalsubroutinesinsideaprocedure

'%filename"t.exe"

'usesrtl64

functionf()

inta=42

intb

'gosubg

gosubgwhena>0

printb

return

'

g:

b=a/2

ret

'

endfunction

f

RELATED: procedurescallgoto

ifACTION: startaconditionalblockwithatestUSE: conditionalexecutionEXAMPLE:

ifa<bthena=b

RELATED: conditionalsthenelseelseifendifwhile

thenACTION: startstheconditionalblockwherethepriortestismet.USE: conditionalexecutionEXAMPLE:

ifa>bthenprinta

RELATED: conditionalsifelseifendif

elseifACTION: makeanalternativetestifthepreviousconditionwasnotmet.USE: conditionalexecutionRELATED: conditionalsifelseendif

elseACTION: startsthealternativeblockwherenoneofthepriorconditionsare

metUSE: conditionalexecutionEXAMPLE:

ifa>bthenprintaelseprintb

RELATED: conditionalsifelseifendif

endifendifACTION: endtheconditionalblockUSE: conditionalexecutionEXAMPLE:

ifa>bthen

a=b

endif

RELATED: conditionalsifthenelseifelseendif

doACTION: startablockforrepetition(looping)EXAMPLE:

a=0

do

'...

a+=1:ifa=4thenexitdo

enddo

RESULT:a=4'4loops

RELATED: loopswhilecontinueexitenddoloop

whileACTION: startablockforconditionalrepetitionEXAMPLE:

a=0

whilea<4

a+=1

wend

RESULT:a=4'4loops

REMARKS: whileidacombinationofdoandif¬.

RELATED: loopsdocontinueexitwendenddo

exitACTION: exitadowhilefor(...)blockimmediatelyUSE: leavealoop,usuallyafteraconditionhasbeenmetEXAMPLE:

a=0:b=1

do

a+=1

ifa>4thenexitdo

b+=b

enddo

RESULT:a=5:b=16

REMARKS: Alsousedtoexitlow-levelnestingblocks.

RELATED: loopsdowhilecontinuerepeat

continueACTION: gobacktothebeginningofado,whileorforblockUSE: to"shortcircuit"aloopREMARKS: continuedoandcontinuewhilewillloopbacktothe

nearestdoorwhile¬atthesamenestinglevel.

RELATED: loopsdowhileforbreakexitwendenddorepeat

wendendwhile,loopACTION: endawhileblockUSE: see:whileRELATED: loopsdowhilecontinueexit

enddoenddo,loopACTION: endadorepeatingblockUSE: see:doRELATED: loopswhiledoloopcontinueexit

forACTION: startaniterationblockRELATED: iterationtostepnext

toACTION: specifylimitofaniterationRELATED: iterationforstepnext

stepACTION: specifyincrementofaniterationUSE: foriterator=starttoendstepstepincrementEXAMPLE:

fori=1to10step2:...:next

RESULT:iincreeasesby2witheachcycle:13579

RELATED: iterationfortonext

nextACTION: enditerationblockRELATED: iterationfortostep

selectACTION: StartaCaseblock(Cstyle)RELATED: selectioncaseendselend

caseACTION: specifyacasetomatchfollowedbyactionstoperformRELATED: selectionselectendselend

classACTION: defineaclass(strucureandmethodsforobjects)EXAMPLE:

''DEFINECLASS

'

classrgbacolor

redasbyte

greenasbyte

blueasbyte

alphaasbyte

'

methodin(sysr,sysg,sysb,sysa)

red=r:green=g:blue=b:alpha=a

endmethod

'

endclass

RELATED: classestypetypedefstruct

hasEXAMPLE:

classperson

hasmind

REMARKS: 'has'isusedwhentheclassisderivedfrommorethanasingleparentalclass.ie:multipleinheritance.'has'maybeomitted.Itissufficienttoprovidetheclass/typenamewithoutthisqualifier.

RELATED: offromextendsclassclasses

ofREMARKS: 'of',and'from'andextendsareequivalent.They

indicatederivationfromasingleparentalclass.COMinterfacesussingleinheritance

RELATED: hasclassclasses

fromREMARKS: 'of',and'from'andextendsareequivalent.They

indicatederivationfromasingleparentalclass.COMinterfacesussingleinheritance

RELATED: hasclassclasses

virtualREMARKS: objectsofvirtualclassesareusuallycreatedbysome

kindofserverorclassfactory.Theclientonlyreceivesareference(pointer)totheobjectfromtheserverandonlyknowshowtoinvokeitsmethods.Itassumesnoknowledgeofitsinnerworkings.

RELATED: comexternalexportclassexterncomclass

comREMARKS: COMisaprotocolusedbyMicrosofttoprovideObjectinterfaces.

ClasseswiththisattributeareconsideredVirtual.

RELATED: virtualexternalexportclassofinheritsexternvirtualclass

newACTION: createadynamicobjectandcallitsconstructormethod.USE: tocreateandinitialisepersistentobjectsEXAMPLE:

newshapecuboid1,1,1

RELATED: classesdelredimdim

delACTION: Calladynamicobject'sdestructormethodanddisallocateits

memoryblock.USE: todeletedynamicobjectsEXAMPLE:

delcuboid

REMARKS: 'del'mayalsobeusedtodeletethecontentofindividualstringsandbstrings.Stringsaresettonull;thecontentsarereleasedandremovedfromthegarbagecollector'slists.

RELATED: classesnew

and&REMARKS: bitwiseoperator

RELATED: andorxoroperators

or|REMARKS: bitwiseoperator

RELATED: andor=xoroperators

xorREMARKS: bitwiseoperator

RELATED: andorxor=operators

*ACTION: returntheintegervaluelocatedbytheaddresscontainedinthevariableUSE: readingwritingdata,usingpointersEXAMPLE:

inta=42

print@a'addressofa

sysb'sys'ensuresanintegerlargeenoughtoholdapointer

b=@a'assinaddressofatob

print*b'42

REMARKS: UnlikeC,pointerresolutionisnormallyhandledimplictly.

RELATED: @?strptraddr

and=&=REMARKS: bitwiseassignoperator

RELATED: andorxoroperators

or=|=REMARKS: bitwiseassignoperator

RELATED: andorxoroperators

&&REMARKS: logicaloperator

RELATED: &&||^^operators

||REMARKS: logicaloperator

RELATED: &&||^^operators

^^REMARKS: logicaloperator

RELATED: &&||^^operators

&&=REMARKS: logicalassignoperator

RELATED: &&||^^operators

||=REMARKS: logicalassignoperator

RELATED: &&||^^operators

^^=REMARKS: logicalassignoperator

RELATED: &&||^^operators

stdcallACTION: determineshowparametersarepassedonthestackUSE: declaringexternalfunctionsEXAMPLE:

!Sleeplib"kernel32.dll"stdcall(intmsec)

REMARKS: thisisthedefaultcallingconventionon32bitWindowsplatforms.

RELATED: callingcdeclms64pascal

cdeclACTION: determineshowparametersarepassedonthestackUSE: declaringexternalfunctions,andvariadicfunctionsREMARKS: thisisacommoncallingconventionon32bitplatforms.Thestack

iscleanedupafterthecallbythecaller.

RELATED: callingcdeclms64pascalcallback

ms64ACTION: determineshowparametersarepassedonthestackUSE: declaringexternalfunctions,andvariadicfunctionsREMARKS: thisisthedefaultWindowscallingconventionon64bitplatforms.

Thefirstfourparametersarepassedinregisters.Thestackiscleanedupafterthecallbythecaller.

RELATED: callingstdcallcdeclpascal

pascalACTION: determineshowparametersarepassedonthestackUSE: declaringexternalfunctionsEXAMPLE:

!Sleeplib"kernel32.dll"stdcall(intmsec)

REMARKS: thisisalegacycallingconventionon32bitplatforms.

RELATED: callingstdcallcdeclms64

spaceACTION: returnsastringofspacesUSE: string=spacelengthEXAMPLE:

s=space10

RESULT:s=""'10spaces(ascii32)

REMARKS: forwidestringsusestring(n,wchr32)instead

RELATED: nulsstringltrimrtrim

nulsACTION: returnstheaddressofastringofnullcharactersgiventhelength.USE: string=nulslengthEXAMPLE:

s=nuls1000

RESULT:sisastringof1000nullcharacters

REMARKS: forwidestringsusestring(n,wchr0)instead

RELATED: spacestringnewsfreesgetmemory

ascACTION: returnsasciiencodingofacharacterinastringUSE: AsciiCode=asc(String,CharacterPosition)EXAMPLE:

a=asc("ABCDEF",2)

RESULT:a=66'character='B'

RELATED: unicchrvallenstr

unicACTION: returnsencodingofacharacterinawidestringUSE: uni=unic(String,CharacterPosition)EXAMPLE:

a=unic("ABCDEF",2)

RESULT:a=0x0042'character='B'

RELATED: ascwchrchrvallenstr

redimACTION: createorresizeadynamicarray,preservingcontentswithinrangeUSE: extendorreduceanarraysizeatrun-timeEXAMPLE:

redimstrings(n)

REMARKS: toflushanarray'scontents,redimitwith0elementsfirst.Butavoiddoingthiswitharraysofstrings;theorphanedstringsarenotgarbage-collecteduntiltheendoftheprogram,andwillaccumulateoneachiterationwheretheredimreducesthenumberofelements.

RELATED: dimnew

letACTION: definesavariableorobjectUSE: createanewvariableorindirectobjectEXAMPLE:

lets="thisisastring"

printtypeofs'result:'string'

REMARKS: Similartousing'dim'butthetypeisinferredfromtheassignedvalue.

RELATED: dimvar

varACTION: defineasetofvariablesUSE: low-leveldimensioningofvariablesEXAMPLE:

varstrings,t,u(64),v

REMARKS: varisnormallyonlyusedinternally.itaccepts*forindirectvariablesand"at"forvariablemapping.Arraysarealsosupported.

RELATED: dim

unionACTION: defineaunion(Csyntax)USE: allowsdifferentvariablestooccupythesamespace.EXAMPLE:

unionutype

{

byteb

shortw

longi

}

RESULT:v.b=42:v.w=42:v.i=42

REMARKS: aunionmayalsobenestedinsideatype.

RELATED: typedeftypestructclassenum

enumACTION: createanenumerationUSE: assignanumericidentitytoaname

'------------

'ENUMERATIONS

'============

'SIMPLEENUMERATION

'==================

enumManyThings

shoes

ships

sealing_wax

cabbages

kings

endenum

defshow"%1:"%1

printshowcabbages

'ENUMERATIONFROMABASEVALUE

'=============================

enumManyThings

shoes=11

ships

sealing_wax

cabbages

kings

endenum

printshowships

'BITWISEENUMERATION

'===================

'1248163264...

enumbitManyThings

shoes

ships

sealing_wax

cabbages

kings

endenum

'ENUMERATIONUSAGE

'=================

'DimasManyThingsmt

ManyThingsmt

mt=cabbages

printmt

REMARKS: Csyntaxissupportedforthisconstruct.Alsoenumbitassignsvalues1,2,4,8,16..insteadof0,1,2,3,4..

RELATED: typedefenum#define(%)

embedfileACTION: specifiyafiletobeembeddedinthedatasectionUSE: storedatafileinaprogram,andgetapointertoit.EXAMPLE:

sysdat:embedfile"data.txt",dat

REMARKS: Textorbinaryfilesmaybeembeddedwiththiscommand.Thedataisread-only.Eitherasysorabstringvariablemaybeusedtoreferencethedata.Anupperlimitof255filescanbeembedded.

RELATED: includestrptrgetfile

librarypathACTION: defineafilepathforDLLfilesUSE: tellsthecomputerwheretofindDynamicLinkLibrariesrequired

toruntheprogram.(SystemDLLsdonotrequirethis.)RELATED: libraryexternincludepath

#ifdefACTION: includecodeifsymbolalreadydefinedUSE: toallowblocksofcodetobeincludedoromittedatcompiletimeEXAMPLE:

#ifdefMSWIN

#include"windows.inc"

#endif

RELATED: #if#elseif#endif

#ifndefACTION: includecodeifsymbolalreadydefinedUSE: toallowblocksofcodetobeincludedoromittedatcompiletimeEXAMPLE:

#ifdefMSWIN

#include"windows.inc"

#endif

RELATED: #if#elseif#endif

namespaceACTION: startanamspaceUSE: createaregionwheresymbolslocallydefinedEXAMPLE:

'

inti=1

'

namespaceaa

inti=10

namespacebb

inti=20

endnamespace

'

printi+aa::i+bb::i'31

'

namespacebb

printi'20

endnamespace

RELATED: scope

sinACTION: returnsthesineofavaluegiveninradiansUSE: Sine=sin(Radians)EXAMPLE:

v=sin(pi/6)

RESULT:v=0.5

RELATED: asincostan

cosACTION: returnscosinevalue(ratioofx/r)givenangleinradiansUSE: Cosine=cos(radians)EXAMPLE:

c=cos(pi/3)

RESULT:c=0.5

RELATED: sintan

gotoACTION: jumptoaspecifiedlabelinthecodeEXAMPLE:

functioncube(fasfloat)asfloat{returnf*f*f}

RELATED: jmpgosub

endACTION: markstheendofacodeblockUSE: terminatingvariousblockstructuresEXAMPLE:

ifa>bthen

b=a

endif

REMARKS: Anisolated'end'terminatestheprogram.

RELATED: blockscopeifdowhileselectfunctionsubmethodclassmacrodef

loopenddo,enddoACTION: endadorepeatingblockUSE: see:doRELATED: loopsdocontinueexit

breakACTION: exitaswitchblockordo/whileblockRELATED: caseswitchwhiledocontinue

endselendselectACTION: endtheselectblockRELATED: selectionselectcase

extendsREMARKS: 'of',and'from'andextendsareequivalent.They

indicatederivationfromasingleparentalclass.COMinterfacesussingleinheritance

RELATED: hasclassclasses

externalREMARKS: functionswiththeexternalattributeexpecttobecalledfrom

proceduresexternaltoOxygen.Additionalregistermanagementisenlistedtosupportexternalcalls.

RELATED: externcomexportcallbackcomvirtualfunctionsubmethod

exportREMARKS: procedureswiththisattributearevisibletoexternalcallers

whentheyarecompiledaspartofaDLL(DynamicLinkLibrary)

RELATED: externalfunctionsubextern

externACTION: associatedeclaredprocedureswithacallingconventionand/ordllnameEXAMPLE:

externstdcalllib"kernel32.dll"

declarefunctionQueryPerformanceCounter(lpPerformanceCountasquad)assys

declarefunctionQueryPerformanceFrequency(lpPerformanceFrequencyasquad)assys

endextern

REMARKS: notetherisnoneedtouseanAliasinthesedeclarationsifyougivetheexactnameoftheproceduresintheiroriginalcase.

RELATED: liblibrarycalling

xor=REMARKS: bitwiseassignoperator

RELATED: andorxoroperators

@ACTION: returntheaddressofavariableUSE: readingwritingdataofvariablesandarraysofvariables,by

referenceEXAMPLE:

inta=42

print@a'addressofa

int*b'indirect(pointer)variable

@b=@a'coupledbyaddress

printb'42

REMARKS: UnlikeC,pointerresolutionishandledimplictly.Sothe@operatorisrequiredformanipulatingpointers.Itissimilartothe&operatorinC.

RELATED: *?strptraddr

?ACTION: returntheintegervaluecontainedinthevariableUSE: castingvariablesasintegersEXAMPLE:

floatf=100

printhex(?f)'displaythehexadecimalformoffloatf

RELATED: cast*@strptraddr

strptrACTION: returnastringpointerUSE: obtainbaseaddressofstringcontentsEXAMPLE:

strings="Hello"

sysa=strptrs

RELATED: typecodeofaddr

addrACTION: resolveaddressofavariable(assembler)USE: loadaddressofavariabletoaregisterEXAMPLE:

sysa

addrecx,a

RELATED: @*?strptr

ltrimACTION: returnsstringwithwhitespaceonthelefttrimmedoffUSE: string=rtrim(string)EXAMPLE:

s=ltrim"abc"

RESULT:s="abc"

RELATED: rtrimspacestrlcaseucase

rtrimACTION: returnsstringwithwhitespaceontherighttrimmedoffUSE: string=rtrim(string)EXAMPLE:

s=rtrim"abc"

RESULT:s="abc"

RELATED: ltrimspacestrlcaseucase

newsACTION: allocatesabstringofnullcharactersgiventhelengthinbytesUSE: bstring=newslengthEXAMPLE:

b=news1000

'...

freesb

RESULT:bcontainsaddressofastringof1000nulcharacters.Thenthestingisfreed

REMARKS: OxygenstringsareautomaticallyfreedbutBstringsmustbeexplicitlyfreedwhennolongerneeded.

RELATED: freesnulsspacebstringgetmemory

freesACTION: deallocatesabstringUSE: freesbstringfreememoryEXAMPLE:

b=news1000

'...

freesb

RESULT:bcontainsaddressofastringof1000nulcharacters.Thenthestingisfreed

REMARKS: OxygenstringsareautomaticallyfreedbutBstringsmustbeexplicitlyfreedwhennolongerneeded.

RELATED: newsnulsfreememorygetmemory

getmemoryACTION: allocateblockofmemoryandreturnitsbaseaddressUSE: address=getmemorybytesEXAMPLE:

m=getmemory8000

RELATED: freememorynewsfrees

chrACTION: returnsstringof1characterofasciiencoding(0..255)USE: string=chr(AsciiValue)EXAMPLE:

s=chr(65)

RESULT:scontains"A"

RELATED: wchrascunicstring

valACTION: returnsnumericvalueofstringUSE: value=valstringEXAMPLE:

v=val"2.5"

RESULT:v=2.5

RELATED: trhexasc

lenACTION: returnslengthofstringincharatersUSE: length=len(string)EXAMPLE:

v=len("Hello")

RESULT:v=5

REMARKS: charactersmaybeoneortwobytes(widecharacters)

RELATED: stringspacemidsizeof

strACTION: returnsstringrepresentationofnumberUSE: String=str(value)EXAMPLE:

s=str(-1.23456)'result:-1.23456

s=str(-1.23456,3)'result:-1.235

REMARKS: roundingisautomaticallyappliedbeforedecimalplacesaretruncated.

RELATED: hexval

wchrACTION: returnswidestringofa2bytecharacter(encoding0..65535/

0xffff)USE: widestring=wchr(WideCharValue)EXAMPLE:

wstringws=wchr(65)

RESULT:wscontainsunicodecharacter0x0041

RELATED: unicascstring

getfileACTION: copiesfilecontenttoastringUSE: String=getfileFileName:getfileFileName,StringEXAMPLE:

strings:getfile"t.txt",s

RESULT:scontainscontentof"t.txt"

RELATED: putfileprint

libraryACTION: specifythenameofaDLLlibrarytoassociatewithasetof

proceduredeclarationsEXAMPLE:

lib"kernel32.dll"

RELATED: declare

#ifACTION: includeblockofcodeifconditionsaremetRELATED: #else#elseif#endif

#elseifACTION: includeblockofcodeifthesealternativeconditionsaremetRELATED: #if#else#endif#fi

#endifACTION: endofconditionalcodeinclusionblockRELATED: #if#elseif

asinACTION: returnsangleinradiansgiventheratioy/radiusUSE: angle=asin(YRRatio)EXAMPLE:

a=asin(0.5)

RESULT:a=pi/6

RELATED: sinacosatnatan

tanACTION: returnsthetangentofavaluegiveninradiansUSE: tangent=tan(radians)EXAMPLE:

t=tan(a)

RESULT:t=ratioy/x

RELATED: atanatnsincos

switchACTION: StartaCaseblock(Cstyle)RELATED: selectioncaseendselend

libREMARKS: libmaybespecifiedintheDeclarestatementoritmaybe

specifiedinanexternstatement,referringtoanentiregroupofdeclarations.

RELATED: librarydeclareexternaliaslinkat

castACTION: changeorspecifythetypeofavariabletemporarily,inanexpressionEXAMPLE:

floatf=100

printhex(cast(int)f)'displaythehexadecimalformoffloatf

printhex((int)f)'thesamewithoutusingthe'cast'word

RELATED: convert?union

typecodeofACTION: returntypecodenumberofvariablesandliterals.USE: obtaindatafordiagnosticsorreflectiveprogrammingRELATED: typeofrecordofsizeofoffsetofspanofprototypeof#recordof

lcaseACTION: returnslowercaseofstringUSE: string=lcase(string)EXAMPLE:

s=lcase"ABCDEF"

RESULT:s="abcdef"

RELATED: ucaseltrimrtrimasc

ucaseACTION: returnsuppercaseofstringUSE: string=ucase(string)EXAMPLE:

s=ucase"abcdef"

RESULT:s="ABCDEF"

RELATED: lcaseltrimrtrimasc

freememoryACTION: freepreviouslyallocatedmemoryblockUSE: freememoryaddressEXAMPLE:

freememorym

RELATED: getmemorynewsfrees

hexACTION: returnshexadecimalstringrepresentationofintegerpartofnumberUSE: hexString=hex(value)EXAMPLE:

printhex(14.4)'result'E'

printhex(14.4,4)'result'000E'

RELATED: strval

sizeofACTION: returnlengthofvariableelement(inbytes)USE: nbytes=sizeofvariableEXAMPLE:

n=sizeofa

RELATED: offsetofspanoftypeoftypecodeof

putfileACTION: savesastringtoafileUSE: putfileFileName,StringEXAMPLE:

putfile"t.txt","Hello"

RESULT:Afilenamed"t.xt"iscreatedoroverwrittencontaining"Hello"

RELATED: getfileprint

printACTION: DisplaysstringsandnumbersUSE: printString:printNumberEXAMPLE:

print"ABC":print123:print"ABC:"123"DEF:"456

RESULT:ABC

123

ABC:123DEF:456

REMARKS: stringscanbecombinedwithnumbersassysasthefirstelementisastring

RELATED: valstrhexputfilegetfile

declareACTION: declareaprocedurewithitsprototype(maybeexternalordeclared

inadvance)EXAMPLE:

declarefun(floata,b,c,d)asfloat

declarefunctionfun(floata,b,c,d)asfloat

REMARKS: ThereisawiderangeofoptionsforDeclarestatements.Pleaselookattheexamplesandheaderfiles.

RELATED: !librarylibaliasdim

#elseACTION: alternativeblockofcodetoincludeifpriorconditionsarenotmet.RELATED: #if#elseif#endif

acosACTION: returnsangleinradiansgiventheratiox/radiusUSE: angle=acos(YRRatio)EXAMPLE:

a=acos(0.5)

RESULT:a=pi/3

RELATED: cosasinatnatan

atnACTION: returnsangleinradiansgivenratioy/xUSE: angle=atn(YXRatio)EXAMPLE:

a=atn(1)*4

RESULT:a=pi

RELATED: atanasinacostan

atanACTION: returnsangleinradiansgiventhevaluesofyandxUSE: angle=atan(y,x)EXAMPLE:

a=atan(0.5,sqr(0.75))

RESULT:a=pi/6

RELATED: atnasinacostan

aliasREMARKS: iftheprocedurenameisanexactcasematchthenitisnot

necessarytospecifyanAlias.

RELATED: librarydeclareexternallibrarydeclareexternal

convertACTION: explicitlyconvertthetypeofanexpression.USE: passvalues,intherequiredtype,toanunprototypedfunctionEXAMPLE:

floatf=2.5

sleep(convertint(f*1000))

RELATED: cast

typeofACTION: returnnameofthevariabletypeUSE: name=typeofvariableEXAMPLE:

dimaslongv:s=typeofv

RESULT:s="long"

RELATED: typecodeofsizeofoffsetofspanofrecordof

recordofACTION: returnrecordofcompound(UDT)variableUSE: obtaindatafordiagnosticsorreflectiveprogrammingEXAMPLE:

typevtlongv,doubled

dimasvtv:r=recordofv

RESULT:r="

v041A0,long

d441A0,double

"

REMARKS: use#recordoftodisplaytherecordduringcompilation.

RELATED: #recordofprototypeofsizeofoffsetofspanoftypeoftypecodeof#recordof

offsetofACTION: returnoffsetofvariablefromindexregisterUSE: nbytes=offsetofvariableEXAMPLE:

n=offsetofa

RELATED: sizeofspanoftypeoftypecodeofrecordof

spanofACTION: returnspanofarrayvariabledimensionUSE: nbytes=spanofvariabledimensionEXAMPLE:

dimaslongv(10):n=spanofv

RESULT:n=10

RELATED: sizeofoffsetoftypeoftypecodeofrecordof

prototypeofACTION: returnprototype(s)offunctions,subsandhighlevelmacrosUSE: obtaindatafordiagnosticsorreflectiveprogrammingRELATED: recordofsizeofoffsetofspanoftypeoftypecoedof#recordof

#recordofACTION: returninternalrecordofadeclaredentity.USE: tocheckstatusatcompiletime.EXAMPLE:

#recordofMyStructure

REMARKS: thiscommandwasintroducedtoaiddebuggingatcompiletimeareoftenhardtotrace.

RELATED: #blockdepth