Pure FB Runtime Library (in progress)

User projects written in or related to FreeBASIC.
Post Reply
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Pure FB Runtime Library (in progress)

Post by MrSwiss »

> ... (all common knowledge)

Why, for Pete's sake, can't you ever admit, to have made a mistake?
Would probably make you look, a bit more human?
Last edited by MrSwiss on Sep 28, 2017 10:52, edited 1 time in total.
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Pure FB Runtime Library (in progress)

Post by St_W »

MrSwiss wrote:

Code: Select all

VarPtr(array(0))  ' or
VarPtr(LBound(array))
doesn't (and shouldn't) compile:
C:\test.bas(4) error 24: Invalid data types, for @ or VARPTR in 'print varptr(lbound(array))'
//edit: full test code:

Code: Select all

dim array(10) as integer

print @array(0)
print varptr(lbound(array))

sleep

MrSwiss wrote:Why, for Pete's sake, can't you ever admit, to have made a mistake?
Would probably make you look a bit more human?
Ask that yourself :-P (before blaming others)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Pure FB Runtime Library (in progress)

Post by MrSwiss »

St_W wrote:Ask that yourself :-P
It works very well, in a real example: (no errors!)

Code: Select all

Dim As ULong colour(0 To ...) = { &hFF000000, &hFF3F3F3F, &hFF7F7F7F }

Print VarPtr(colour(0))

Sleep
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Pure FB Runtime Library (in progress)

Post by fxm »

MrSwiss wrote:VarPtr used as follows, on a array:

Code: Select all

VarPtr(array(0))  ' or
VarPtr(LBound(array))
The syntax problem is on the second line.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Pure FB Runtime Library (in progress)

Post by MrSwiss »

fxm wrote:The syntax problem is on the second line.
OK, thanks, duly noted ...
The first one, however, which proves the point, works ...
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Pure FB Runtime Library (in progress)

Post by fxm »

That proves nothing at all because "array (0)" is a particular element of array, and not the array itself.

When we have a string (s), we can use not only:
VarPtr(s[0]) '' address of the first element of the character string
but also:
StrPtr(s) '' start address of the character string
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Pure FB Runtime Library (in progress)

Post by MrSwiss »

Are you aware of the fact, that for practical use, both of them are identical?
VarPtr(s[0]) = VarPtr(s) -- the very same Address ...
A String is (sort of, apart from "header"), a array of UByte (ASCII-String only).

Only: VarPtr(s[n]) would be different ... (where: n > 0)
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Pure FB Runtime Library (in progress)

Post by fxm »

Yes, these two entities have the same value, but they are entities of different types:

Code: Select all

Dim As String s

#print typeof(VarPtr(s[0]))
#print typeof(Strptr(s))
Compiler wrote:UBYTE PTR
ZSTRING * 4 CONST PTR
Fortunately, there is compatibility between "Ubyte Ptr" and "Zstring Ptr" for assignment, but not fully compatibility between "Ubyte" and "Zstring":

Code: Select all

Dim As String s = "FreeBASIC"

#print typeof(VarPtr(s[0]))
#print typeof(Strptr(s))
Dim As Ubyte Ptr pu = Strptr(s)       '' OK
Dim As Zstring Ptr pz = VarPtr(s[0])  '' OK

#print typeof(*VarPtr(s[0]))
#print typeof(*Strptr(s))
Dim As Ubyte u = *Strptr(s)           '' OK
Dim As Zstring *10 z = *VarPtr(s[0])  '' error 24: Invalid data types
Compiler wrote:UBYTE PTR
ZSTRING * 4 CONST PTR
UBYTE
ZSTRING
.....\FBIde0.4.6r4_fbc1.06.0\FBIDETEMP.bas(11) error 24: Invalid data types.....
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Pure FB Runtime Library (in progress)

Post by MrSwiss »

Now, that has nothing any longer to do, with the initial question, of:
"How to get the *start*-address of an array, with a FB-keyword?" since you stated:
@ is a *short-cut* of VarPtr ... (@ = symbol (for: "get address"), VarPtr = keyword)
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

I have a git repo for this project here: https://github.com/ImortisInglorian/fbrtLib
At this point I have only confirmed that it will compile with what I have. I have been going back and fixing bugs in my translations in older files as they crop up during the compile process. I am using posidenFB as my IDE and the project file for it is in the repo. I am compiling it as a static library as I figured that would make testing it much easier when I have something testable.

It is not in a usable state.

If you want to eye-ball the code and point out how stupid I am or how many errors I have made (please be specific), feel free. I have commented out things that are not yet needed, and left thing in that will not compile on a windows environment since that is what I am working in.

I am getting 5 to 6 files converted a day, which is not great, but it's what I can do and still get work done and have a life outside of work and coding.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Pure FB Runtime Library (in progress)

Post by counting_pine »

Imortis wrote:[abridged]

Code: Select all

static FB_STR_TMPDESC fb_tmpdsTB[FB_STR_TMPDESCRIPTORS];
I assumed the first was just an array declare, roughly this in FB:

Code: Select all

dim fb_tmpdsTB(FB_STR_TMPDESCRIPTORS) as FB_STR_TMPDESC
Declaring an array of size N in C gives you N elements starting at 0, i.e. 0 through N-1.
So it's necessary to adjust the array subscripts:

Code: Select all

dim shared fb_tmpdsTB(0 to FB_STR_TMPDESCRIPTORS-1) as FB_STR_TMPDESC
(I can see you've already added the 'shared' in https://github.com/ImortisInglorian/fbr ... re.bas#L20)

'dim array(0 to N-1)' is/should be pretty much considered as an idiom in FB, since 'dim a(N)' doesn't do the same thing, and 'dim a(N-1)' looks weird.
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

counting_pine wrote:
Imortis wrote:[abridged]

Code: Select all

static FB_STR_TMPDESC fb_tmpdsTB[FB_STR_TMPDESCRIPTORS];
I assumed the first was just an array declare, roughly this in FB:

Code: Select all

dim fb_tmpdsTB(FB_STR_TMPDESCRIPTORS) as FB_STR_TMPDESC
Declaring an array of size N in C gives you N elements starting at 0, i.e. 0 through N-1.
So it's necessary to adjust the array subscripts:

Code: Select all

dim shared fb_tmpdsTB(0 to FB_STR_TMPDESCRIPTORS-1) as FB_STR_TMPDESC
(I can see you've already added the 'shared' in https://github.com/ImortisInglorian/fbr ... re.bas#L20)

'dim array(0 to N-1)' is/should be pretty much considered as an idiom in FB, since 'dim a(N)' doesn't do the same thing, and 'dim a(N-1)' looks weird.
Thanks counting_pine. Already fixed in my local version.
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

Okay, next question:

Code: Select all

LenAdd = sprintf( ((pszAdd = FixPart), FixPart)"%d", fb_Day( value ) );
How is that valid? FixPart is a char array and spzAdd is a char pointer.

EDIT: Whoops, never mind. I accidentally removed a comma from the line of code.

EDIT #2: By the way: the code behind the "FORMAT" command is a real mess. There has got to be a better way to do it. Maybe after this project is finished I, or someone else, can take a stab at rewriting it.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Pure FB Runtime Library (in progress)

Post by counting_pine »

https://github.com/freebasic/fbc/blob/m ... mat.c#L843?
Potentially when writing in FB, it might be possible to simplify some code by using strings and string functions.
It might not be as fast or memory-efficient. But on the other hand, simpler implementations might be a better foundation for writing/testing more efficient code based on it.
I'd say, feel fee to make the code nicer/simpler if you want. It's one of the main advantages to be gained from writing in FB. It will also help the understanding of the code.
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Pure FB Runtime Library (in progress)

Post by TeeEmCee »

Wow, you've done a lot of work already! Have you tried running it at all?

I notice a mistake in the translation: you've been translating 'int' to 'integer', but the equivalent of C's 'int' in FB is 'long'.
Also, you need to wrap everything in Extern "C" if you're not doing that already.
Post Reply