Pure FB Runtime Library (in progress)

User projects written in or related to FreeBASIC.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 10, 2018 17:19

Has any one tried to compile and test this in FB since TeeEmmCee did a while back? I have been converting stuff like crazy, and have no idea if any of it actually works at this point.

I have not tried to use the make file he posted yet. Anyone had any success with it on Windows yet?
TeeEmCee
Posts: 243
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Pure FB Runtime Library (in progress)

Postby TeeEmCee » Jan 12, 2018 7:47

I get quite a few errors when I try to compile. Does "fbc -c *.bas" work for you? It doesn't work here. Not all of these are unix-specific problems. I'm currently working on fixing all the errors and warnings.

Also, (if I go back to git commit 7b994f739, which compiles on Unix), the make file also works fine for me on Windows. Doesn't it work for you? What's the problem?
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 12, 2018 23:58

TeeEmCee wrote:I get quite a few errors when I try to compile. Does "fbc -c *.bas" work for you?


Yeah, I am getting some errors on the con_print_tty_uni.bas file. I thought I had those fixed in my local copy... I will check that out. Give me a few days to look at it. I was going to work on it today during my spare time at work, but I didn't HAVE any. Been busy the last couple of days.
dodicat
Posts: 5251
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pure FB Runtime Library (in progress)

Postby dodicat » Jan 13, 2018 1:10

I cannot get the makefile to work.
But my fbc is not on the system path, so I probably have made a wrong edit to the makefile.
-gen gcc -c *.bas compiles all the files to .o
no errors.
(Run from a .bat file in fbrtLib-master.)
from then I compiled to a .a lib file using ar rcs librtlib2.a *.o (from my mingw which is on path)
The .a file is 313 KB.
That's as far as I get to test your source code.
Win 10.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 13, 2018 2:08

dodicat wrote:...
-gen gcc -c *.bas compiles all the files to .o
...


It should not compile right on -gen GCC just yet. The GCC backend does not support variadic functions, which are used in a lot of places. I am surprised it compiled.
dodicat
Posts: 5251
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pure FB Runtime Library (in progress)

Postby dodicat » Jan 13, 2018 2:21

My apologies.
-gen GAS.
Can you not just use the variadic macros.
I tested a while back, they compiled the chr function OK.
I think this was my mock up

Code: Select all

#undef chr
#define va__first(n)     cptr(typeof(n) ptr,@(n)+1)  'restricted to [unsigned] integers / doubles
#define va__arg(a,t) peek( t, a )
''#define va__arg(arg,datatype)   *cptr(datatype ptr,arg)
#define va__next(a,t) (cptr(t ptr, cptr(byte ptr, a) + (sizeof(t)+sizeof(any ptr)-1 and -sizeof(any ptr)) ) ) 

#define null 0



type FBSTRING
    as ubyte ptr      data';    /**< pointer to the real string data */
    as long           len';     /**< String length. */
    as long           size';    /**< Size of allocated memory block. */
end type


function fb__CHR cdecl ( args as integer, ... ) as string
   dim dst as FBSTRING ptr
   dim ap as any ptr
   dim num as ulong
   dim i as long

   if ( args <= 0 ) then
       return ""
   end if
   'va_start( ap, args )
   ap = va__first(args)


   /' alloc temp string '/
   'dim as string tmp=string(args,0)
   dst=new fbstring
   dst->data=callocate(args,sizeof(zstring ptr))'fb_hStrAllocTemp( NULL, args )
   if ( dst <> NULL ) then
      /' convert '/
      for i = 0 to args-1
         num = va__arg( ap, ulong )
       
         dst->data[i] = cast(ubyte, num)
       
         ap = va__next(ap, ulong)
      next
      'dst->data[args] = 0
   else
       dst=0
      'dst = @__fb_ctx.null_desc
   end if
   'va_end( ap )
'result=*cast(zstring ptr,dst->data)
   function= *cast(zstring ptr,dst->data)'result
   delete dst
end function

function size(s as string) as long export
    dim as long ct
    for n as long=0 to len(s)-1
        if s[n]=asc(",") then ct+=1
    next
    return ct+1
end function

#macro chr(start...)
 fb__CHR(size(#start),start)
#endmacro


print chr(48,52)


dim as double t
dim as string s
dim as string u
t=timer
for n as long=1 to 100000
u= fb__CHR(18,80,114,101,115,115,32,97,32,107,101,121,32,116,111,32,101,110,100)
next
print timer-t,u

t=timer
for n as long=1 to 100000
 u= chr(80,114,101,115,115,32,97,32,107,101,121,32,116,111,32,101,110,100)
next
print timer-t,u

sleep




 
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 13, 2018 2:32

dodicat wrote:...
Can you not just use the variadic macros.
...


I just replaced them with the FB command plus equivalent code. I can try later to add the macros and see what happens. I am trying to add as little code as possible to this. The macros were not in the original source, so I did not add them.

EDIT: I did get the make file to work. It generated fbrt0.o and libfb.a

Running the test suite on it now.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 13, 2018 3:39

I am amazed! Test suite Passed!

However, I seem to have messed something up somewhere along the line as the "String" will not take a quoted string as a parameter. It will work with the ASCII code for a character...

I am pretty sure I know what the problem is. I will soon post all my changes to github so others can try if they want.
TeeEmCee
Posts: 243
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Pure FB Runtime Library (in progress)

Postby TeeEmCee » Jan 13, 2018 5:59

You haven't checked in the con_print_tty_uni.bas file yet.
Anyway, what about warnings? There were quite a lot which indicated mistakes either in the translation, or in FB's CRT headers.
Also, too late, I've already nearly fixed everything.

(Edit: Imortis, you are too quick to add various casts to silence warnings, like the one below, when those warnings are actually due to something being wrong (FB's headers in this case). I'm working on it. Don't ignore warnings!)

Code: Select all

-   swprintf( p, 16+8+1, sadd("%.*g"), digits, _val )
+   swprintf( p, cast(wchar_t ptr, 16+8+1), sadd("%.*g"), digits, _val )


dodicat wrote:I cannot get the makefile to work.
But my fbc is not on the system path, so I probably have made a wrong edit to the makefile.

You should only need to edit the FBC and FB_SRC_PATH variables. What error do you get? Maybe you have a space in one of those paths? If so, you need to surround them in quotes.

BTW, I've discovered that many of the .bi files in fbrtlib break FB builtins like PRINT and WSTR, because they #undef the functions that these compile to, like fb_StrToWstr (aka WSTR) and then redeclare in a way that's incompatible. For example fbc internally declares various builtins as taking type zstring ptr, but they're declared in the runtime library as char*/ubyte ptr. I saw heaps of errors when I tried redefining FB_WCHAR as wstring, but I think replacing ubyte ptr with zstring ptr will be easier to fix.
TeeEmCee
Posts: 243
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Pure FB Runtime Library (in progress)

Postby TeeEmCee » Jan 13, 2018 6:58

I'm sorry to disappoint you, but you're compiling the testsuite with the wrong copy of libfb, not fbrtlib. FB's testcases (at least the cunit ones) link to libfbmt.a, not libfb.a. Maybe you can run the logtests ones? The makefile I provided doesn't build libfbmt.a, but I'm adding it now.
I assure you, there are heaps of bugs in fbrtlib! Try compiling some simple programs instead.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 13, 2018 7:19

I would rather be correct then not. No disappointment here. Like I said I tried a few string functions and they are broken on quoted temp strings.

As to silencing warnings, I am working under the assumption that the crt headers are correct. I have found a couple places where it is not, but I don't know enough about those specifics to be able to make that call in most places.

I believe a big issue in strings was from a mis-translation early on. I am pretty sure I know what I did, but I will need to go back and look at the originals.
TeeEmCee
Posts: 243
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Pure FB Runtime Library (in progress)

Postby TeeEmCee » Jan 13, 2018 9:29

OK, after building the mt variants I managed to compile fbc-tests (the cunit tests), but it freezes. I tried log-tests, and there are only 6 failures!
This was done on my own branch before I merged your work.
Wow, you've translated over half the rtlib now. Nice work!

I merged our fixes and submitted a pull request. I'm going to hand it back to you now, I don't have time to more work on it soon.
Unfortunately, while I had everything compiling without warnings before, now fbc crashes when compiling con_readline.bas. I also can't compile file_attr.bas and file_datetime.bas due to problems with FB's stat.bi header (which isn't supported on linux, but I can't compile when I crosscompile to windows either). Aside from that, no warnings.

I added the following to my config.mk to avoid the problems and build the libraries:

Code: Select all

# crashes fbc
BLACKLIST += ./con_readline.bas

# crt/stat.bi not supported on linux
BLACKLIST += ./file_attr.bas ./file_datetime.bas
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 15, 2018 16:36

TeeEmCee wrote:OK, after building the mt variants I managed to compile fbc-tests (the cunit tests), but it freezes. I tried log-tests, and there are only 6 failures!
This was done on my own branch before I merged your work.
Wow, you've translated over half the rtlib now. Nice work!

I merged our fixes and submitted a pull request. I'm going to hand it back to you now, I don't have time to more work on it soon.
Unfortunately, while I had everything compiling without warnings before, now fbc crashes when compiling con_readline.bas. I also can't compile file_attr.bas and file_datetime.bas due to problems with FB's stat.bi header (which isn't supported on linux, but I can't compile when I crosscompile to windows either). Aside from that, no warnings.

I added the following to my config.mk to avoid the problems and build the libraries:

Code: Select all

# crashes fbc
BLACKLIST += ./con_readline.bas

# crt/stat.bi not supported on linux
BLACKLIST += ./file_attr.bas ./file_datetime.bas


Merged. Thanks for your help.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 17, 2018 17:52

TeeEmCee wrote:You haven't checked in the con_print_tty_uni.bas file yet.


That was a mistake. The file SHOULD be con_print_tty_uni.bi. I save it with the wrong name to begin with. I removed it from the folder so it would not get checked in.
Imortis
Posts: 1579
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Postby Imortis » Jan 17, 2018 19:27

@TeeEmCee: I see that you replaces a bunch of ascii constants with ASC() calls. I was not doing that myself because ASC is part of the runtime library. I did not want to cause any chicken-egg problems. If that is not an issue here, I can go through and replace all the constants with ASC calls.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests