PDA

View Full Version : Oxygen Flexi Parameter Passing



Charles Pegge
19-05-2010, 12:10
Flexible Parameter Passing

This feature enables functions subs and methods to specify default values for their parameters. If you use HTML you will be familiar with tags and their optional attributes. This does the same for BASIC functions.

All you have to do is assign a value to each parameter in the function prototype. For example:

function f( byval a=20 as long, byval b=22 as long ) as long
function=a+b
end function


then you can use this function in the normal way or assign values to specific parameters replacing their default values.

f(b=4) 'DEFAULT 'A' VALUE IS USED

You can assign values to any or all of the parameters or none, and the parameters may be given in any order.


Get the latest Oxygen here:

http://community.thinbasic.com/index.php?topic=2517





'===================
'FLEXI PARAM PASSING
'===================

uses "oxygen"
dim src as string

src = "

basic

cr=chr 13
so="FLEXIBLE PARAMETER PASSING FOR FUNCTION f()" cr cr

'---------
function f
'=========
(
byval a=1 as long, 'DEFAULT VALUE 1
byval b=2 as long 'DEFAULT VALUE 2
)
as long
'
so+= "a=" a " b=" b cr
'
return a+b
'
end function


f 'ALL DEFAULT VALUES ARE USED
f() 'ALL DEFAULT VALUES ARE USED
f(a=3) 'DEFAULT B VALUE USED
f(b=4) 'DEFAULT A VALUE IS USED
f(a=5,b=6) 'NO DEFAULT VALUES ARE USED
f(b=6,a=5) 'AND PARAMS CAN BE SPECIFIED IN ANY ORDER

print so

"



o2_asmo src

'msgbox 0, o2_prep src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec

Petr Schreiber
19-05-2010, 16:37
Very nice Charles,

I am happy to see you continuing the Oxygen project!
Example worked great here, only minor trouble was NOD32 thinks there is trojan in the DLL, but I presume it is another false positive, as it was not precisely identified.


Petr

Charles Pegge
19-05-2010, 21:12
Hi Petr,

I think the core functionality of the language is nearly complete now. There are still C header trials, Linux and 64 bit compiling to go through, but these will require only minor additions to the command set.

Not sure what to do about capricious antivirus software since the DLL internals are bound to change with every release. I hope you were able to tell it to calm down!

Charles

danbaron
19-05-2010, 21:52
[font=courier new]I downloaded the latest Oxygen zip file.

I extracted it into, "c:\thinBasic\SDK\".

Then, I had two Oxygen folders.

The old one, "thinBasic_o2h", and the new one, "thinBasic_Oxygen".

I deleted "thinBasic_o2h".

I ran two programs, "DO NOTHING", and "HELLO".

Both worked.

Inside the folder, "thinBasic_Oxygen", is another folder, "Examples".

Inside the folder, "Examples", there are 19 more folders, with lots of examples on various topics.

My first impression is that the capabilities of Oxygen can be determined, by running the examples.

(Now must hurry for train.)

:oops:
Dan :x :P

Charles Pegge
19-05-2010, 22:42
Hi, Dan,

I face the task of writing a manual with trepidation, so I hope the examples will suffice meanwhile.

The simplest way to deploy the new thinBasic_Oxygen.dll is to transfer it into \thinBasic\Lib overwriting the previous version.

Then the new examples will work from any folder on your PC.

Whenever a thinBasic Beta is released, Eros incorporates the latest version of Oxygen in the thinBasic\lib folder , and the examples appear in thinBasic\SampleScripts\Oxygen.

One warning: I have removed a few earlier examples which have become obsolete or broken - these may linger in your thinBasic\SampleScripts folder from previous installations.

Charles

danbaron
20-05-2010, 07:50
[font=courier new][size=8pt]You've already got a ".chm" file, in, "\thinBasic\help". So, you have the format.

I think, the best way is, don't try to make it good. Just write anything you feel like.

Bit by bit, you can add little topics. Release it, and modify it as you go along. It doesn't have to be complete. Don't
wait for the super-royal-grand release.

When someone writes, it's bad if he becomes too self-conscious. Doesn't writer's block appear, when the creator feels
too much pressure, whether internal or external? Who could write if he feels he has to live up to Shakespeare?

Once begun, it's half done.

(On the other hand, you have supplied many samples. I also procrastinate when I have doubt.)

:oops:
Dan :x :P

Charles Pegge
21-05-2010, 07:57
Good advice. Thanks Dan :)

thinBasic O2 made its first appearance as a machine code module here

http://community.thinbasic.com/index.php?board=149.0.

We have come quite a long way since then.

Charles

danbaron
21-05-2010, 21:27
[font=courier new][size=8pt]I only understand a tiny bit of what Oxygen does.

I don't know how you learned all this stuff.

Since I know so little, I'm not able to guess its future possibilities.

For instance, I cannot estimate the probability that you will be able to combine it with DNA strands.

If I'm correct, it has only existed for approximately two years; so who knows?

I hope you are careful not to let anything dangerous escape from the laboratory. :twisted:

:oops:
Dan :x :P

zak
22-05-2010, 07:33
thanks Charles for the oxygen
i have just discovered the example in the new posted oxygen file:
thinBasic_Oxygen\Examples\DLLandEXE\ConsoleCompilerMaker
i am sure dan will find this great for his research on mathematics:
as an example the following text file fibo.bas: extracted from Eros example http://community.thinbasic.com/index.php?topic=2649.0

#file "fibo.exe"
FUNCTION fibonacci(byval sequence as Dword) as Dword
IF sequence < 2 THEN
FUNCTION = sequence
Else FUNCTION = fibonacci(sequence - 1) + fibonacci(sequence - 2)
END IF
END FUNCTION
print fibonacci(40)
terminate

to compile this to a very small exe program type from console:
co2 fibo.bas

then run the exe fibo.exe it will give you 102334155
four questions:
1-how to print to a console instead a msgbox?
2-how to make the above program to a dll to be called from other programming language such as thinbasic or vb6 as an example ?
3-is it possible to attach an icon to the generated exe ?
4-is it neccessary to use terminate, the code can run without using terminate but does it have unseen function?
thanks

zak
22-05-2010, 09:36
in addition to my above message using fibonacci(60) will not issue a message , and i have noticed that the cpu temperature increased very slowly from 40 centigrade to critical 55, in the task manager the numbers beside fibo.exe in the processes tab is as follows : fibo.exe 50 1320k,
when i terminate the fibo.exe the temperature return normal.

Charles Pegge
22-05-2010, 14:06
Hi Zak,

I hope the zip file below satisfies most of your questions. I will include something similar in future Oxygen releases :)

Charles

1-how to print to a console instead a msgbox?

Set up a console using Windows kernel functions

2-how to make the above program to a dll to be called from other programming language such as thinbasic or vb6 as an example ?

Create functions with Aliases and `export` word. Also provide a `finish` procedure.

3-is it possible to attach an icon to the generated exe ?

Not yet. I have further work to do on this.

4-is it neccessary to use terminate, the code can run without using terminate but does it have unseen function?

"Terminate" is automatic unless the binary needs to be persistent such a DLL or a function provider in a thinBasic script. Terminate frees libraries and memory blocks used by Oxygen.

6 Heat!

If there was a law against cruelty to computers, this recursive fibo function would surely be illegal. It requires a huge amount of processing power and when you raise the agony to 50 I think the stack overflows.

zak
22-05-2010, 15:38
thank you Charles for the explanations and the valuable and rich example.
indeed there is a gems inside the examples.
regarding the heat, you may set internaly a temporary limitation to the recursivity levels, until you find a solution to prevent the program from floating in the memory without ending.
i was not aware about the heat until the "pc probe 2" utility for the asus motherboards have warned me loudly after 3 minutes of running fibonacci(60) while i am in another room.
thanks and best wishes

Charles Pegge
22-05-2010, 16:22
Glad you like it Zak,

I should also mention the thinBasic Oxygen dependency. The compile exe or dll can be deployed on systems without thinBasic if you include thinBasic_Oxygen.dll with the application.

This file may be located in the same folder as the application or in a child folder called lib or in a sister folder (of the application folder) called lib.

These are currently the fixed locations where the dll will look for its Oxygen.

This is how the Oxygen hunt is internally implemented:


const as string hostdll=""+_
"`.\thinBasic_oxygen.dll` : call fwd libpath : cmp eax,0 : jnz fwd ndll"+crlf+_
"`lib\thinBasic_oxygen.dll` : call fwd libpath : cmp eax,0 : jnz fwd ndll"+crlf+_
"`..\lib\thinBasic_Oxygen.dll` : push eax : call [ebx] : cmp eax,0 : jnz fwd ndll"+crlf+_
"`\thinbasic\lib\thinBasic_Oxygen.dll` : push eax : call [ebx] : cmp eax,0 : jnz fwd ndll"+crlf+_
"`c:\thinbasic\lib\thinBasic_Oxygen.dll` : push eax : call [ebx] : cmp eax,0 : jnz fwd ndll"+crlf


Charles

Charles Pegge
24-05-2010, 21:55
Zak,

Further to your question 3

Is it possible to attach an icon to the generated exe ?

I discovered a naughty little program called Resource Hacker which allows you to add icons to EXE files amongst other things. Very easy to use.

www.angusj.com/resourcehacker/

and IcoFX is good for creating icons

http://icofx.ro/


Charles

zak
25-05-2010, 09:32
thank you Charles, i have downloaded Resource Hacker ,
it is a very usefull utility
then choosing Action -> Add new resource ; icon file, then save as.
the new exe now with a new icon
best wishes