PDA

View Full Version : StandAlone Oxygen



Charles Pegge
07-09-2010, 07:10
Hello Everyone,

For those of you who would like to try a stand-alone version of Oxygen, I have set up a site at SourceForge

http://oxygenbasic.sourceforge.net/

This version of Oxygen comes with a generic Scintilla-based IDE, a linked-in manual and a subset of the thinBasic examples (those without thinBasic dependencies). The two versions will be kept in sync as closely as possible.

When I did a preliminary posting last Sunday, it was only one among a multitude of over 200 new projects for the day! There are around 100,000 projects held at SourceForge though quite a few of these appear to be moribund, including "Oxygen" and "Oxide". But Oxygene and DOxygen are very much alive.

Charles

Petr Schreiber
07-09-2010, 10:59
Hi Charles,

thanks for letting us know. I will check it out very soon.
And thanks for adding Scintilla IDE to the pack!


Petr

Petr Schreiber
07-09-2010, 11:04
My will is very weak, I had ton of work to do, but simply had to check it out immediately :D

I like it, maybe I would organize all the samples to Samples directory, all binaries to Bin directory and so on, but that is just ultramarginary detail.
Other minor thing - the ' comments are not colored properly.

But the comfort is there, Scintilla is much better than notepad :)
You did good job on the documentation, maybe if it could be context sensitive it would be even better.

But overall - fantastic job, major leap forward indeed :occasion:


Petr

Charles Pegge
07-09-2010, 11:41
Thanks Petr, Good luck with the work load. A ton is a lot to carry :)

Yes I can bunch all the examples together in one folder.

To get full syntax highlighting you need to select Language/Oxygen from the menu bar. But the lexer does not understand Basic comments and considers them to be unclosed quotes. I may be able to get them colored but had to suppress the default behaviour. If anyone is familiar with configuring Scintilla, your advice will be most welcome.

You can get any script to run instantly with F5 or use F7 to compile.

To get context sensitive help put the caret on a keyword and press F1. The help manual will appear with a list of keywords on the right. The indicated keyword should be at the top of this list.

I'm also thinking about making #basic the default mode instead of #asm. I've been caught out several times myself. It will be one less instruction to worry about when scripting.

Charles

zak
07-09-2010, 11:46
thanks Charles for this great project.
scintella ide, multi tabs, Go, build, compile,... a very good additions
for the future: my suggestion:
more examples for the new users
some simple examples GUI such as TextBox, button... ,
and a canvas with instructions like plot, circle, ellipse, pset,point, line, with a refresh canvas capability.... and not only the Api direct call because it is extremely complex.
some tutorials.
any way this is a great project. it is not heavy on the cpu, i have launched the portviewer looking always at my cpu temperature monitoring utility, it was 44 degree and stay arround it,
i hope the basic languages forums to declare an announcement about this new born compiler.
also you may think of a dedicated forum for the standalone version.

best wishes

Petr Schreiber
07-09-2010, 11:53
Hi Charles,

thanks for the tips. Maybe the context sensitivity could be pushed one step forward, by opening the topic directly.

One of the things I like is the fast compile, even for larger programs.

Making the #basic default could help, maybe providing simple template with this predefined could solve the problem as well.

One thing - in DataProcessing there are some Ink files which I thInk should not be there.


Petr

ErosOlmi
07-09-2010, 12:02
Charles,

great!
Good luck for Oxygen, you and your project deserve a bright future.

Ciao
Eros

Michael Hartlef
07-09-2010, 12:13
Hi Charles,

good luck for your project. I hope it will recognized in a good way and a lot.

Best wishes
Michael

Charles Pegge
07-09-2010, 12:14
Thanks for your suggestions Zak.

I am going to develop the Graphics side using Opengl and possibly OpenAL for audio - considering cross-platform development. I won't need to touch the core language for these. It may be sufficient to provide source code libraries for users to add to their projects.

The manual would be a good place for tutorials and small script examples. I have made a start on this by getting the manual builder to incorporate a number of the short demo scripts.

Charles

Charles Pegge
07-09-2010, 12:52
@Eros
@Mike

Thanks, I hope this project will be another seed in the diaspora of Basic. Working on this forum has been a very good experience and long may our shared path of development continue.

@Petr

I put all my development tools in the examples. The manual generator sprouted from data processing and should have its own folder now. The source code for the compiler is to be found in ToolSrc. You can create your own customised compiler from these.

For scripts up to 50k, the compiler is fast enough to JIT compile. All you have to do is associate o2bas files with eo2.exe (in the main oxygen folder) and then run scripts anywhere on your PC.

Charles

John Spikowski
07-09-2010, 16:19
Charles,

This is great news! You might want to post something about your new Basic compiler on the www.allbasic.info/forum as well.

Good luck with your new standalone Basic compiler. I will be checking it out for sure.

John

efgee
07-09-2010, 18:55
Hello Charles,
congratulations to your endeavor...

As I used Oxygen as a standalone compiler from the start :oops: (sorry Eros...) my question is:

Where do you want us to drop questions, examples, etc. for the (now) official standalone version?


Thank you
efgee

ErosOlmi
07-09-2010, 19:46
:D nothing to be sorry efgee. I will be very happy if Charles will create a killer compiler.
For me, the 2 most important things are: passion and good feeling. And Charles has a lot of both.

Charles, feel free to use this forum as you prefer (if you need a specific sub forum just drop me a PM) or feel free to move where is best for your language to succeed.

Ciao
Eros

Charles Pegge
07-09-2010, 21:08
@John

Thanks! I have made my submission on your new AllBasic Forum. I hope we will be able to attract new interest in Basic.

@efgee
@Eros
We will see how it works out covering several forums. It might be like trying to ride three or four horses at the same time but each forum has its own specialised community interests, and I think the cross fertilisation will be highly beneficial. I'm very happy for things to continue here as they are.

Charles

John Spikowski
08-09-2010, 02:00
I hope we will be able to attract new interest in Basic.

What other language has over 100 variations? :fishing:

Variety is the spice of life.

I think AllBasic will do better this time around.

kryton9
08-09-2010, 04:31
Congratulations Charles to get to this major milestone! The few examples I ran, compiled so quickly and there were no problems. Now to go back to testing it out. Thanks again!

Charles Pegge
08-09-2010, 07:18
I am glad it worked smoothly for you Kent. I've been looking again at the OpenGL stuff, and see how much complexity there is. I can abstract a substantial amount of this material and put it into source code libraries.

Charles

kryton9
08-09-2010, 23:04
I've been tinkering with making classes like for lights and materials for opengl. But with opengl evolving at the moment into a whole new direction and moving away from the pipeline we know well, I stopped work on it.

I think where your brain power should go Charles is to make oxygen operable with google's native sdk next, just my opinion of course. This way oxygen can then run on all the new portable devices as well.
Here is a link to a nice video overview. As they say, it uses gcc c/c++ compiled binaries.
http://www.youtube.com/watch?v=nP8Mo0jGQDk&feature=player_embedded

Charles Pegge
09-09-2010, 00:58
Yes Kent,these are good videos. I know I have to avoid embedding inline data in assembly code to be compatible withe the Google native-code sandbox.

I wouldnt be too concerned about the new, (revolutionary) OpenGL APIs. We will always be dealing with points, lines surfaces and textures however Opengl may choose to implement them in the future. And it is the inevitable fate of programmers to spend their time rewriting the same sections of code many times :)

Charles

kryton9
09-09-2010, 09:06
I've halted my c++ work as I was waiting for o2h to get to this point. I will be heavily being using it in the coming months.

Do you plan on making it work with the native sdk any time soon, the reason I am asking is as you know Android devices have exploded way beyond my expectations here and of course Chrome OS is due out in November in some tablets. So I am sure by early 2011 we will have many more devices to use Android or Chrome based devices. It would be great to program on them :)

kryton9
09-09-2010, 09:58
Another reason to develop for the new technology that is going to be mobile and non windows os.

http://www.engadget.com/2010/09/09/arm-reveals-eagle-core-as-cortex-a15-capable-of-quad-core-compu/

Charles Pegge
09-09-2010, 14:13
I very much enjoyed working in ARM assembly code, with its elegant simplicity. But I don't have a clear picture of how you program these devices. Do you have to work through an IDE and emulate on the PC?

Charles

efgee
09-09-2010, 18:16
Charles,
are you saying that you consider to address different cpu architecture with Oxygen?

Do ARM chips now have a divide function?
And what about floating points?

bye
efgee

Charles Pegge
09-09-2010, 22:52
ARM is certainly a possibility. My last encounter with ARM was about 20 years ago. The contemporary ones have built-in divide and the more advanced chips have floating point.

http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf

Anyway it all depends on what development tools we are meant to use on these mobile devices. If native assembly code is too specific then we can always resort to emitting C.

Charles

kryton9
10-09-2010, 02:03
That is why I was saying the native sdk. The new devices next year will use those new chips. Nvidia uses arm cpus for their tegra 2's. So I am sure the tegra 3's or it should perhaps be called tegra 4's should use these quad core cpus. Android and Chrome are slated come out on tegra 2 based devices soon. I think in some lucky parts of the world they are out already.

So making o2h work with the native sdk, it should work fine, especially since it is geared for gcc c/c++.

http://www.nvidia.com/object/tegra-games-applications.html

As you can see, these companies have or are making software and I know it is via Android for now. They must be doing this via the native sdk.

kryton9
10-09-2010, 12:00
Charles, I was going through the help file tonight. When I copy and pasted code from the help that I thought would work, it didn't. Perhaps a starter page saying what is needed to make a basic program run.

Here is a screenshot of the help I copied from and then how I got it to run. Minor things, but for someone just coming to o2h it could be a tough start without a simple introduction of where to begin.

Also, for those writing new code... you need to save your file with .o2bas extension before you can run, compile etc. That took me a few minutes to figure out :)

kryton9
10-09-2010, 12:07
Charles, when I went to compile instead of run the opengl 4 port example, I get this message.
error 3 about missing oxygenb.bas file.

Pressing F5, I can run it fine, but no build or compile without getting that message.

Charles Pegge
10-09-2010, 14:22
Hi Kent,

I see the problem. It is a truncation of the command line in the CO2 compiler. I have fixed this and added a few more locations to the Oxygen search path.

I'll be posting this update later today.

Thanks for testing!
Charles

Charles Pegge
10-09-2010, 15:26
Okay, that's all working.

I'm developing another Opengl demo PortViewer2 which you can find in the /graphical folder.
This hides all the crusty bits in a source library: glo2.inc

http://oxygenbasic.sourceforge.net

I will post the thinBasic version as soon as I have made a thinBasicSync tool.

Charles

Lionheart008
12-09-2010, 00:30
hi charles, first of all, many many thanks for your great works and compliments! :) to be truly I have started some month ago to dive up into new dimensions with assembler coding! but it's just another cosmos for me ;)

I've tested your oxygen stand alone compiler (oxideSc.exe) some minutes before.

=> push "F5" (GO) and Compile "Ctrl+F7".

1) "f5" caused "sc1" error message. 2) Ctrl+F7 works fine. But I cannot seen "HelloWin1.o2bas" window Frame (dialog). but where is it ? ;) all tested with win xp sp2.

good luck for further examples and fixing first errors. thanks for your hard work.

one tipp: if you uses dialog with pbwin take perhaps to place dialog something with...


DIALOG NEW 0, "OxideSc",100,100, 800, 600, %WS_SYSMENU,, TO hDlg

best regards, frank

Michael Clease
12-09-2010, 01:04
I confirm the problem, seems to be when spaces are in the path.

Charles Pegge
12-09-2010, 06:31
@Frank
@Mike

I have reconfigured the compile tools and the IDE to support filepaths with spaces in them. I hope this resolves the problem.

When you press F7 or ctrl-F7 the program is compiled but does not execute from the IDE. The EXE or DLL is filed in the same folder as the source code.

If you want programs to execute directly from script (like thinBasic) then all you have to do is associate o2bas files with eo2.exe located in the OxygenBasic folder. eo2 is also used by the IDE to execute programs on F5


Charles

ReneMiner
16-05-2024, 11:27
Hello Charles,

I wanted to check out your oxygen-basic-asm-package but the download is blocked by browser security settings that are not possible to disable (@ sourceforge)
On the github page i do not understand how to download a file and which at all. But that is probably caused by the github-page - most projects there are not usable if one does not have some "i don't know-tool" - sometimes its possible to download a zip there which contains hundreds of files where i don't see what to start with.

Anyway i wanted to know if oxygen has like some IDE that allows to type in the code that it can instantly run / compile and run?
Can oxygen call thinbasic-builtin-instructions by name or can it make use of $()-interpolation or Evaluate()/Evaluate$() ?
Or is it possible to embed thinbasic to the stand-alone version of oxygen so it can take care of a projects frame imagine as making use of the many functions that thinbasic provides - perhaps the thinbasic-scripted functions as a file per function stored to a .7z-archive (7z.exe, the commandline version provides all the required procedures) or even as .zip,.rar,... any kind of archive that can be implemented into a compiled executable package?
Does oxygen provide any GUI-library / win32Api or a graphics window with simple built-in 2d drawing-library that allows just drawing rectangles, lines and fonts to create an independent UI?

What would be the file to download?

Is there a full-installation-package or some portable to run as is from unzipped folder? I have so many thinbasic-scripted-procedures but
somehow with thinbasic seems no more possible to complete a project without to run into some hindrances that keep it from working as expected and there seems not enough time to get it all fixed.
...
Secretly i hope there is a complete makeover in process - maybe thinbasic x64 or 2.0 is on the way? Who knows?

It's a bad feeling to get nothing to work as planned - even the used tool has the potential to achieve it - but... yes that's sad. Without any success it means to lose the passion finally.

..

Does it require registry-settings or an environment variable or does it need a folder that is like %path% ?

jack
21-05-2024, 14:20
hello ReneMiner :)
go to the oxygen basic GitHub https://github.com/Charles-Pegge/OxygenBasic
click on the most recent OxygenBasic.zip and then on the right, near the top you will see some action icons, click on the down-arrow icon to download
to use just unzip the archive to your favorite location, there's an IDE included called oxide
but be aware that Windows Defender may flag some of the components of Oxygen Basic as malware, so you need to take appropriate action

btw, Charles is active on this Forum https://forum.it-berater.org/index.php

ReneMiner
23-05-2024, 10:03
Hello Jack,
Thanks , i got it.

Sadly the forum of José is not open to new members - guess to the waves of spam-bot-attacks. And José told me a year ago or so that he retired and is no more active.

I will study what possibilities there are.
Maybe the easier way is to create a library that provides the functions that i would miss without thinbasic but somehow it should be possible as Charles was up to embed thinbasic that way two years ago or so, starting from the pb-sdk, having the similar datatypes available and the knowledge how to embed tb it should work to make use of $("thinbasic-string-interpolation"), Evaluate() and Evaluate$().

Charles Pegge
23-05-2024, 11:47
Hi ReneMiner,

You can email Theo Gottwald for membership (requires your real name).

Ed Davis has produced a demo TinyBasic interpreter which could be adapted to make eval functions:
OxygenBasic\demos\interpreters.

All the self-compiling source code for Oxygen, its tools and its demos, is included without copyright restrictions. The catch is you have to be able to understand it :)

ReneMiner
24-05-2024, 11:03
...The catch is you have to be able to understand it :)

Yes, that is - somehow bit difficult - in oxygenbasic i've found not any asm- keywords nor did i encounter any sample that uses such - only the registers are there and samples that show the binary way making it to byte-sequences.
So what command-set would i use? Equal MASM, NetAsm, FlatAsm,...?

Also it's bit complicated when help shows only a bunch of keywords but not really explains what these do, so to get some idea realized it requires to find running samples.

At first sight there is some confusion, i did not find keywords: opt[ional], not
But discoverd them existing in a sample.
RET makes me wonder, once it says to use as counterpart of Gosub, another place i read use with asm as counterpart of jsr - another page says i must use retn for gosub but return from a procedure - does it mean i can use jsr or gosub equally?
Were it difficult to implement the asm-instruction-set that it exchanges them to bytes before compilation or is there already a tool made by someone to do so?

Charles Pegge
24-05-2024, 12:59
Generally, I would avoid using Asm, and allow the compiler to do all the low-level coding. 32bit compiling and 64bit compiling can generate very different Asm. However, it is there if you need it, and it is tightly integrated with Basic variables etc.

Classical gosub is available, but uses the ret instruction instead of return, which is reserved for functions. But more recently, o2 has adopted more formal terms to give subroutines their own block structure: (so you can't fall into a subroutine accidently)

gosub xx
...
subroutine xx
print "ok"
'exit subroutine
end subroutine

ReneMiner
24-05-2024, 18:34
i see. Still checking out many things at once.

So this Subroutine can be inside sub or function and shares the "parenting procedures scope?
enter with gosub - exit is fine - avoids accidental return.
What if subroutine inside function ?
Will Return immediately leave the function then?


And extern / external - is it same?

And just one more: i saw in help "Selection" and i imagined it was like thinBasic "SelectExpression" which is a pretty long verb...
I tried but it does not know "selection" but it were great not to repeat that request from top of select case where it might be some calculated result
or whatever

example


Byte bCharcode

Select [Case] <numexpression>
Case <= 0 ' not a valid char

case 1 to 31 ' not a visible char...

case 42 ' * only in this case i know what exactly matched

case 48 to 57 ' 0 to 9

case 65 to 72 ' A to F , maybe hex

case 73 to 90 ' G to Z
case else
' in this case always, in the other cases on top i can not detect without to re-evaluate <expression>
' but there should be a possibility to use a pseudo-variable (even a byte-string) that i can use here
' when the group (case) is the correct/expected one to pass the value somewhere for any purpose.
' i thought like i know what datatype i used up there so it were my fault when i try to assign it to a
' type thats not capable of storing it but

bCharCode = SELECTION

EndSelect



would be nice in this case and in all the others that it does not require to store it in advance since it is not
sure if it is required because the selected case will show if the value is of use.

And do you remember syntax as "On x Goto/Gosub ..."?

Not exactly that but a similar mechanism works for
choice = Choose/Choose$ (x, <expr1>[,<expr2>[,...] [{else|default} <defaultexpr>])

when x =1 then expr1 is assigned to choice etc.

I did not find yet anything about passing a previously unknown count of parameters, otherwise
Index = IN|IN$(<comparisonvalue>, <optionA>[, <optionB>][,...])
Index is assigned 1 if optionA matches, 2 for optionB,... and 0 if no option matches the comparisonvalue - no else/default here ...

IIF/IIF$ - no need to mention... but


Boolean matching = ALL(<expr>,<expr>[, <expr>]) - true when All expressions evaluate to True,( skips further check if one was false)
Boolean matching = SOME(<expr>, <expr>) - true if one of those is true ( will skip further checks then)
Boolean matching = NONE(<expr>,<expr>) - true if none is correct, (skip and returns false if one was true)


those are quite useful to nest one in another and avoids many IF since the problem is mostly to leave from the if-block if not matching a dozen conditions.

Ok, i wil go on snooping around... :D

btw. Demos\WinGUI\Autosizing anything in there refuses to work :(

Charles Pegge
24-05-2024, 21:13
Subroutines are normally inside functions/procedures, and can see all the local variables and other local symbols. (Subroutines can also be nested)

extern is not external.

you can make your own SELECTION as a local variable before starting a select block.

on x goto ... is not directly supported, but it is easy to create a jump table, and goto any of its values. This could be further extended to create a function call table.

You can pass unknown counts by using countof:
int a={1,2,3,4,5}
print countof() '5

IIF can be formulated as a macro function:
macro iif int(a, b, c,d)
if b
a=c
else
a=d
endif
end macro
...
print iif(1>2, 10,20) '20



Demos\WinGUI\Autosizing should work, at least with the most recent github OxygenBasic

Charles Pegge
25-05-2024, 07:40
Calling subroutines via a table:



sys tgs={@sr1,@sr2,@sr3} 'subroutine table
'
subroutine sr1
print 10
end subroutine
subroutine sr2
print 20
end subroutine
subroutine sr3
print 30
end subroutine
'
gosub tgs[2] '20

ReneMiner
27-05-2024, 17:46
calling the function|subroutine by its ptr, i see.
Something i saw in oxygen but don't remember where it was and what was the exact syntax but i am certain it was oxygen, it was like



Function f() as Int
{

Dim Int result At @f
'...
result = 42
}



was it really that simple ? is the function-pointer also the pointer where to read or write the result?

Ans omething that annys me now for a while and i don't know why:
I am passing parameters BYVAL to a function - i tried already to use CAST and lots more- and usually BYVAL can not be parameter type mismatch
but it keeps complaining i would pass double - even i dont.
Same is when i use Extended type as function parameters - it always complains about DOUBLE and parameter type mismatches.


I just post the script.
The bugging line is 63, (### marked ###) but as you see in StrRight at the same position where i used ABS it is the same . Actually i would prefer to use the limit- functions without the need to cast for integer types mainly - and to return also integers without the need to cast parameters nor results




$ filename "teststr.exe"
$ CRLF chr(13) chr(10)
$ DQ chr(34)






Function StrLen(byref s as bstring) as dword
===================================
dim dword dwLen at strPtr s

if @dwLen then
dword dwLen at (strptr s) - 4
Function = dwLen
end if
end function




function InLimits(byval nX as int, byval nMin as int, byval nMax as int) as boolean
' should tell if numberX is within limits nMin and nMax (inclusive)
if nX < nMin then return false
if nX > nMax then return false
function = true
end function


function SetLimits(byval nX as int, byval nMin as int, byval nMax as int) as int
' should return number nX limited between nMin and nMax if outside that range
if nX < nMin then return nMin
if nX > nMax then return nMax
function = nX
end function



------------------------------------
function StrLeft(byref sX as Bstring,
byval numbytes as int) as bstring
=============================================================
' get the left part (in bytes count ) passed through lbytLen
' e.g. assumed sX ="1234567890"
' when lbytLen is a:
' value > 0 but <= len(sX) it works as Left(sX, lbytLen)
' e.g. assumed lbytLen = 3 returned is "123"
' Value < 0 but abs(lbytLen) <= len(s) it works as Left(s, Len(s)-lbytLen):
' e.g. assumed lbytLen = -3, returns "1234567"




' StrRight works exactly opposing to StrLeft
static sResult as bstring
dim dword dwLen at strPtr sX


if @dwLen then
dword dwLen at (strptr sX) - 4
'# # # # # # #
if inLimits( sgn(numbytes) * numBytes, 1, dwLen ) then
'# # # # # # #
if numBytes < 0 then
numBytes = dwLen + numbytes
sResult = String(numBytes, chr(0))
copy strPtr sResult, strPtr sX, numBytes
else
sResult = String(numBytes, chr(0))
copy strptr sResult, strptr sX, numBytes
endif
endif
endif


function = sResult


end function
-------------------------------------------
function StrRight(byref sX as Bstring,
byval numbytes as int) as bstring
=============================================================
' get the right part of sX
' e.g. assumed sX ="1234567890"
' when
' numbytes > 0 and <= len(s) it works as Right(s, numbytes)
' e.g. assumed numbytes = 3, returns "890"
' numbytes < 0 and abs(numbytes) <= len(s) it works as Right(sX, Len(sX)+numbytes)
' e.g. assumed numbytes=-3, returns "4567890"




' StrRight works exactly opposing to StrLeft
dim sResult as bstring
dim dword dwLen at strPtr sX


if @dwLen then
dword dwLen at (strptr sX) - 4
'# # # # # # #
if inLimits(abs numBytes, 1, dwLen ) then
'# # # # # # #
if numBytes < 0 then
sResult = String(dwLen + numBytes, chr(0))
copy strPtr sResult, (strPtr sX)+abs(numBytes), dwLen + numBytes
else
sResult = String(numBytes, chr(0))
copy strptr sResult, (strptr sX) + dwLen - numBytes, numBytes
endif
endif
endif


function = sResult


end function




dim x1, x2, x3, xx as bstring


x1 = "A b c d e f g h i j k l m n o p q r s t u v w x y z"
x2= strLeft x1, 20
x3= strLeft x1,-10


xx = "String " DQ x1 DQ CRLF Str(strLen x1) " bytes of length" crlf
xx &= "StrLeft s, 20 = " DQ x2 DQ str(StrLen x2) " bytes" crlf
xx &= "StrLeft s,-10 = " DQ x3 DQ str(StrLen x3) " bytes" crlf


x2= strRight x1, 20
x3= strRight x1,-10


xx &= "StrRight s, 20 = " dq x2 DQ str(strlen x2) " bytes" crlf
xx &= "StrRight s, -10 = " dq x3 DQ str(strlen x3) " bytes" crlf

print xx







btw. are bStrings the default ? can i also peek a dword in front of a "String"-string without to risk a gpf?

Charles Pegge
27-05-2024, 19:18
Integer functions return values in the eax register. This code makes no sense:

Function f() as Int
{
Dim Int result At @f
'...
result = 42
}



The standard string type is 'string' which contains a garbage-collected bstring. But you can use bstrings directly if you do your own garbage collection.


inlimits macro function accepting all types:



macro inlimits int(r, a,min,max)
=================================
r=-1
if a<min then r=0
if a>max then r=0
end macro


PS: abs(..) requires brackets

ReneMiner
01-06-2024, 19:46
Integer functions return values in the eax register. This code makes no sense:

Function f() as Int
{
Dim Int result At @f
'...
result = 42
}


I know, it was just to visualize the context where it applies. The actual required information to that was:

Is it really that easy : the function-result can be written to the functions address when the result type is numeric?

I am not sure about it and what syntax to use since i want to avoid the risk of GPF with pointers - which i experienced very frustrating worst-case-scenario in the past, when it completely made all partitions of a connected hard-disk unreadable and all contained data was irreversible lost forever.
Even when error-trapping is used to the most-possible-best-most grade of what reality provides: if a GPF occurs - the trap is instantly terminated with the faulty program before it could catch anything and the risk of that is around 50:50, meaning will happen FOR SURE with only a little chance for stupid users that are not aware of the possibility to remain lucky in the current process but for
100% without any chance for someone who has ever read what the 3 chars GPF will be expanded to.


And Strings? Is the functions ptr in that case equal to a VarPtr that points a StrPtr?

Can i swap the functions-result-StrPtr with some other defined (local or global, whatsoever) string X
to avoid the creation of a copy of the string X's content (it would require time-consuming memory-allocation when string X is pretty large)

assumed of course- the original/source-strings variable (here BString sDummy) is not required thereafter any more

Intention is to swap the value that points a strings position - equal to the result of StrPtr(X) - with the value "@X" that i suspect at the position of a function (when function returns a string) and this "@X" is -alike Varptr(X) - when X were a string-variable in powerbasic -
the value pointing to the first byte of data for a Stringvariable X

but since O2basic does not seem to have a function working as VarPtr()
(only a guess):
"@X" would be the position to ask for and where to place virtually a sys-variable AT
and it would make that
- upon @X placed virtual sys variable - hold a value that is equal to the value returned by StrPtr(X) ?

and a virtual Dword variable, dimensioned AT @X-4 were located exactly on the result of STRPTR(X) - 4
(this Dword would be equal to the returned value of a Function as StrLen() - see below



(Macro?) Function StrLen( s As String ) As Dword

' get length of a string to pass byref that will - as thinBasic LENF()
'(a faster working version of the common LEN()-function) -
' not need to create a local copy (= byval function-parameter)
' and obtain the length of the string that is already counted and present

if StrPtr(s) Then
'Question:
' will this lead to a problem when the first time this is called the StrPtr(s) is equal to zero
' and this If-clause gets skipped so the virtual variable dwLen is actually not defined after the first
' time execution of the StrLen-procedure?

Dim Dword dwLen At StrPtr(s)-4
StrLen = dwLen
endif

end (Macro?) Function

About Macro (Functions)? : can these just replace text or as (in powerbasic "Macro Function") calculate using variables local to the macro [function]
as known from powerbasic, where it requires to introduce such variables (and local jump-labels) using some statement as


MACROTEMP localVar, localLabel



Now the main concern:

I will comment it in form of a question what i expected to obtain in the current line,
please correct if doable at all


Function sf() As String '( no result yet assigned )

Dim sys funcPtr At @sf() ' is *funcPtr now the position where to write a value that is the stringpointer for the result?
' e.g.

bString sDummy = "Hello!?" ' (only create an example string here)

sys *_varPtr = @sDummy ' does @sDummy hold the position where to obtain StrPtr of sDummy?
' Is '*_varPtr' equal to result of 'StrPtr(sDummy)'
sys _strPtr = @_varptr ' will '*_strPtr' now hold the same value as returned by StrPtr(sDummy)

sys _temp ' temporary swap-container
' when writing
Temp = *funcPtr ' will this copy the original pointer - that points a value that can be treated as the
' Strptr(of by the function sf() returned string) - into Temp?

*funcPtr=*_strPtr ' will function sf() now return "Hello!?"

*strPtr=Temp ' will exiting the function sf() correctly wipe out an (supposedly empty) BString sDummy
' from the procedures local scope level that was the former result-string of function sf()

Dim Dword dwLen At funcPtr ' can I read the length (in bytes)

End Function

Charles Pegge
01-06-2024, 21:37
If you define a function f, its starting code address will be @f.

Functions with parameters have signatures attached to the name. For instance:

function f(string s,double d, int *f) as int would be have an address
@f#string#double#int



To get the address of any string content, use strptr(s). It will correctly resolve zstrings bstrings and strings.

But only bstrings and strings (based on olestrings) have a length field located at strptr(s)-4.

If a string is uninitialized the strptr will return 0. You will get a GPF if you try to reference it! But I think modern PCs are well protected from memory violations.



MacroTemps in Oxygen are simply listed after the params for instance:
macro m(a,b,c, tmp1,tmp2)

Macro functions are specified by adding a return type and a return parameter at the start, for instance:
macro f float(r, a,b)
r=a+b
end macro

Charles Pegge
02-06-2024, 15:04
'function' is a variable to hold return values

I hope this example helps:


function sf() as string
function="ok"
sys p=strptr(function)
sys le at p-4
print len(function) " " le " " p
end function
'
print sf()

ReneMiner
02-06-2024, 19:42
If you define a function f, its starting code address will be @f.

Functions with parameters have signatures attached to the name. For instance:

function f(string s,double d, int *f) as int would be have an address
@f#string#double#int



am a bit confused now of this one: i see "int" twice in function headline. The parameters and a result. Its missing the - what INT ?
Results position would it be treated as
common Array of int
starting first element =3rd parameter second element = result?
in this case because of same type?

Charles Pegge
02-06-2024, 20:15
Only the function parameter types are used to compose the signature, not the byref levels or return type. Hence the label f#string#double#int. (The main purpose of a function signature is to support function overloading / polymorphism.)