Author Topic: FreeBasic  (Read 21130 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
FreeBasic
« on: July 24, 2018, 09:05:36 PM »
Quote from: Charles - JRS Forum
I see FreeBasic is still being maintained. The source was last updated in June. I would say it's not dead, it's mature.

I'm glad to hear that some of the secondary FB developers are carrying the torch.

I'm not a fan of FreeBasic essentially morphing into a BASIC to (unreadable) C translator. Is there still an effort being put into the BASIC to ASM original direction? (beyond Windows 32 bit)

« Last Edit: July 24, 2018, 09:31:27 PM by John »

Charles Pegge

  • Guest
Re: FreeBasic
« Reply #1 on: July 25, 2018, 01:01:38 AM »
I suppose it's still dependent on GCC as a back-end. I have not tried the C options. There was some work on an LLVM back-end 2 years ago.

jack

  • Guest
Re: FreeBasic
« Reply #2 on: July 25, 2018, 04:04:42 AM »
I normally use -gen gcc -O 2 in the 32-bit compiler options, the executables are usually smaller than when using the default
as for LLVM, I was never able to compile even the simples hello world program using it as back-end

JRS

  • Guest
Re: FreeBasic
« Reply #3 on: July 25, 2018, 08:34:47 PM »
Quote from: DKL - FB forum
I'd like to let everyone know that I'm no longer actively working on the FreeBASIC Compiler project. Last year was already very slow, this year is the same so far, so to be fair and clear, I thought it's time to admit it. I no longer have the same interest and time for fbc as before.

For me the main reason is that I'm no longer sure that the FB language fits in with C++ on the one hand and Python on the other, plus other languages which also compile to native code, but provide more built-in features.

If the lead developer is smart enough to realize the project has reached its end of life , it should be a clue to others they need to move on.

Charles Pegge

  • Guest
Re: FreeBasic
« Reply #4 on: July 25, 2018, 08:57:11 PM »
Perhaps he had a bad experience with LLVM :)

JRS

  • Guest
Re: FreeBasic
« Reply #5 on: July 26, 2018, 07:34:51 AM »
I'm waiting for O2 to self compile and put FB behind it. It's a balll and chain moving forward.

Charles Pegge

  • Guest
Re: FreeBasic
« Reply #6 on: July 26, 2018, 09:19:06 AM »
I have been working on it today. There's a few interesting bugs to sort out, but it will be very satisfying to have a self-sufficient compiler. And it will UPX down to less than 128K!

JRS

  • Guest
Re: FreeBasic
« Reply #7 on: July 26, 2018, 06:40:21 PM »
Outstanding news Charles!

I have been lucky to work with a BASIC with tha only dependency being a C compiler.

More good news.

CC = FB + JR

Quote
Thanxx a lot everyone, this WinFBX just blew my mind

Would you hire CC to take you to 64 bit?

Kindness and understanding has its limits.

« Last Edit: July 28, 2018, 07:42:59 AM by John »

erosolmi

  • Guest
Re: FreeBasic
« Reply #8 on: July 27, 2018, 01:17:39 AM »
I have been working on it today. There's a few interesting bugs to sort out, but it will be very satisfying to have a self-sufficient compiler. And it will UPX down to less than 128K!
Great news indeed.

JRS

  • Guest
Re: FreeBasic
« Reply #9 on: July 27, 2018, 09:48:29 AM »
Eros,

Since we are discussing news, how are things going with the O2 thinBasic extensions direction?

JRS

  • Guest
Re: FreeBasic
« Reply #10 on: July 28, 2018, 10:44:55 AM »
Quote from: Charles - JRS forum
in o2 we would do similar, or use #lookahead

In Script BASIC the CALL statement is required for using functions not define before use.

JRS

  • Guest
Re: FreeBasic
« Reply #11 on: July 28, 2018, 05:01:39 PM »
I was thinking that JR and PS should take over tbe development of FreeBasic. It will slowly fade away without talented ledership.

Probably forking FreeBasic would be a better way to go. A fresh start and direction.  PJBasic  :)
« Last Edit: July 28, 2018, 06:38:22 PM by John »

JRS

  • Guest
Re: FreeBasic - Hello World
« Reply #12 on: July 28, 2018, 09:10:25 PM »
FreeBasic

Code: FreeBasic
  1. #include once "windows.bi"
  2.  
  3. 'Declare Function        WinMain     ( ByVal hInstance As HINSTANCE, _
  4. '                                      ByVal hPrevInstance As HINSTANCE, _
  5. '                                      ByRef szCmdLine As String, _
  6. '                                      ByVal iCmdShow As Integer ) As Integer
  7. '
  8. '
  9. '    ''
  10. '    '' Entry point
  11. '    ''
  12. '    WinMain( GetModuleHandle( null ), null, Command$, SW_NORMAL )
  13.  
  14. '' ::::::::
  15. '' name: WndProc
  16. '' desc: Processes windows messages
  17. ''
  18. '' ::::::::
  19. Function WndProc ( ByVal hWnd As HWND, _
  20.                    ByVal message As UINT, _
  21.                    ByVal wParam As WPARAM, _
  22.                    ByVal lParam As LPARAM ) As LRESULT
  23.  
  24.     Function = 0
  25.  
  26.     ''
  27.     '' Process messages
  28.     ''
  29.     Select Case( message )
  30.         ''
  31.         '' Window was created
  32.         ''
  33.         Case WM_CREATE
  34.             Exit Function
  35.  
  36.         '' User clicked the form
  37.         Case WM_LBUTTONUP
  38.             MessageBox NULL, "Hello world from FreeBasic", "FB Win", MB_OK
  39.         ''
  40.         '' Windows is being repainted
  41.         ''
  42.         Case WM_PAINT
  43.             Dim rct As RECT
  44.             Dim pnt As PAINTSTRUCT
  45.             Dim hDC As HDC
  46.  
  47.             hDC = BeginPaint( hWnd, @pnt )
  48.             GetClientRect( hWnd, @rct )
  49.  
  50.             DrawText( hDC, _
  51.                       "Hello Windows from FreeBasic!", _
  52.                       -1, _
  53.                       @rct, _
  54.                       DT_SINGLELINE Or DT_CENTER Or DT_VCENTER )
  55.  
  56.             EndPaint( hWnd, @pnt )
  57.  
  58.             Exit Function
  59.  
  60.         ''
  61.         '' Key pressed
  62.         ''
  63.         Case WM_KEYDOWN
  64.             'Close if esc key pressed
  65.             If( LoByte( wParam ) = 27 ) Then
  66.                 PostMessage( hWnd, WM_CLOSE, 0, 0 )
  67.             End If
  68.  
  69.         ''
  70.         '' Window was closed
  71.         ''
  72.         Case WM_DESTROY
  73.             PostQuitMessage( 0 )
  74.             Exit Function
  75.     End Select
  76.  
  77.     ''
  78.     '' Message doesn't concern us, send it to the default handler
  79.     '' and get result
  80.     ''
  81.     Function = DefWindowProc( hWnd, message, wParam, lParam )
  82.  
  83. End Function
  84.  
  85. '' ::::::::
  86. '' name: WinMain
  87. '' desc: A win2 gui program entry point
  88. ''
  89. '' ::::::::
  90. 'Function WinMain ( ByVal hInstance As HINSTANCE, _
  91. '                   ByVal hPrevInstance As HINSTANCE, _
  92. '                   ByREf szCmdLine As String, _
  93. '                   ByVal iCmdShow As Integer ) As Integer
  94.  
  95.     Dim wMsg As MSG
  96.     Dim wcls As WNDCLASS
  97.     Dim szAppName As String
  98.     Dim hWnd As HWND
  99.  
  100.     'Function = 0
  101.  
  102.     ''
  103.     '' Setup window class
  104.     ''
  105.     szAppName = "HelloWin"
  106.  
  107.     With wcls
  108.         .style         = CS_HREDRAW Or CS_VREDRAW
  109.         .lpfnWndProc   = @WndProc
  110.         .cbClsExtra    = 0
  111.         .cbWndExtra    = 0
  112.         .hInstance     = GetModuleHandle(null) 'hInstance
  113.         .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
  114.         .hCursor       = LoadCursor( NULL, IDC_ARROW )
  115.         .hbrBackground = GetStockObject( WHITE_BRUSH )
  116.         .lpszMenuName  = NULL
  117.         .lpszClassName = StrPtr( szAppName )
  118.     End With
  119.  
  120.     ''
  121.     '' Register the window class
  122.     ''
  123.     If( RegisterClass( @wcls ) = FALSE ) Then
  124.        MessageBox( null, "Failed to register wcls!", szAppName, MB_ICONERROR )
  125.        'Exit Function
  126.     End If
  127.  
  128.     ''
  129.     '' Create the window and show it
  130.     ''
  131.     hWnd = CreateWindowEx( 0, _
  132.                            szAppName, _
  133.                            "The Hello Program", _
  134.                            WS_OVERLAPPEDWINDOW, _
  135.                            CW_USEDEFAULT, _
  136.                            CW_USEDEFAULT, _
  137.                            CW_USEDEFAULT, _
  138.                            CW_USEDEFAULT, _
  139.                            NULL, _
  140.                            NULL, _
  141.                            GetModuleHandle(null), _ 'hInstance hInstance, _
  142.                            NULL )
  143.  
  144.  
  145.     ShowWindow( hWnd, SW_NORMAL) 'iCmdShow )
  146.     UpdateWindow( hWnd )
  147.  
  148.     ''
  149.     '' Process windows messages
  150.     ''
  151.     While( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )
  152.         TranslateMessage( @wMsg )
  153.         DispatchMessage( @wMsg )
  154.     Wend
  155.  
  156.  
  157.     ''
  158.     '' Program has ended
  159.     ''
  160. '    Function = wMsg.wParam
  161.  
  162. 'End Function
  163.  

Oxygen Basic

Code: OxygenBasic
  1.  
  2.   includepath "../../inc/"
  3.   $filename  "t.exe"
  4.   '#include   "RTL32.inc"
  5.  '#include   "RTL64.inc"
  6.  #include   "WinUtil.inc"
  7.   MainWindow 320,100,WS_OVERLAPPEDWINDOW
  8.  
  9.  
  10.   function WndProc(hWnd, wMsg, wParam,lparam) as sys callback
  11.   ===========================================================
  12.    
  13.   static sys hdc
  14.   static RECT r
  15.  
  16.   '==========
  17.  select wMsg
  18.   '==========
  19.        
  20.     case WM_CREATE
  21.     '=============
  22.  
  23.     SetWindowText hwnd,"Greeting"
  24.     'SendMessage hwnd,WM_SETTEXT,0,strptr "Greeting"
  25.  
  26.  
  27.     case WM_DESTROY
  28.     '===============
  29.          
  30.     PostQuitMessage 0
  31.        
  32.     case WM_PAINT
  33.     '============
  34.  
  35.     hdc=GetDC hwnd
  36.     GetClientRect  hWnd,@r
  37.     'style
  38.    '0x20 DT_SINGLELINE
  39.    '0x04 DT_VCENTER
  40.    '0x01 DT_CENTER
  41.    '0x25
  42.  
  43.     SetBkColor   hdc,white
  44.     SetTextColor hdc,blue
  45.     DrawText hDC,"Hello World!",-1,@r,0x25
  46.     ValidateRect hwnd,@r
  47.      
  48.     case WM_KEYDOWN
  49.     '==============
  50.  
  51.     if wParam=27 then SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE
  52.  
  53.     case else
  54.     '========
  55.          
  56.     function=DefWindowProc hWnd,wMsg,wParam,lParam
  57.    
  58.     end select
  59.     '
  60.  end function ' WndProc
  61.  

Script BASIC  (via DYC and IUP)

Code: Script BASIC
  1. ' DYC FFI Hello World
  2.  
  3. DECLARE SUB DLL ALIAS "dyc" LIB "dyc"
  4.  
  5. DLL "mc,i,iup.dll,IupOpen,PP",0,0
  6. win = DLL("mc,p,iup.dll,IupCreate,Z","dialog")
  7. lbl = DLL("mc,p,iup.dll,IupCreate,Z","label")
  8. DLL "mc,p,iup.dll,IupSetAttributes,PZ",lbl,"""
  9.  TITLE="Hello World!",
  10.  PADDING=100x75,
  11.  FONT="Arial, BOLD 24"
  12.  """
  13. DLL "mc,p,iup.dll,IupAppend,PP",win,lbl
  14. DLL "mc,i,iup.dll,IupShow,P",win
  15. DLL "mc,i,iup.dll,IupMainLoop,P",0
  16. DLL "mc,i,iup.dll,IupClose,P",0
  17.  

Script BASIC  (IUP C Extension Module)

Code: Script BASIC
  1. IMPORT pui.sbi
  2.  
  3. SUB Win_exit
  4.   Iup::ExitLoop = TRUE
  5. END SUB
  6.  
  7. Iup::Open
  8. win = Iup::Create("dialog")
  9. Iup::SetAttributes win,"TITLE=\"SB IUP C Extension Module\",SIZE=200x"
  10. lbl = Iup::Create("label")
  11. Iup::SetAttributes lbl,"""
  12.  TITLE="Hello World!",
  13.  PADDING=50x75,
  14.  FONT="Arial, BOLD 24"
  15.  """
  16. Iup::Append win,lbl
  17. Iup::SetCallback win,"CLOSE_CB",ADDRESS(Win_exit())
  18. Iup::Show win
  19. Iup::MainLoop
  20. Iup::Close
  21.  
« Last Edit: July 28, 2018, 10:47:19 PM by John »

José Roca

  • Guest
Re: FreeBasic
« Reply #13 on: July 29, 2018, 02:16:57 AM »
They're not comparable because in the SB/IUP examples you're using a label, the background is gray instead of white and you need third party libraries.

FreeBasic (via WinFBX)

High DPI and Unicode aware.

Code: [Select]
' ########################################################################################
' Microsoft Windows
' File: CW_GDI_HelloWord.fbtpl
' Contents: CWindow Hello Word example
' Compiler: FreeBasic 32 & 64 bit
' Copyright (c) 2016 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
USING Afx

DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG

   END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)

' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                  BYVAL hPrevInstance AS HINSTANCE, _
                  BYVAL szCmdLine AS ZSTRING PTR, _
                  BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   AfxSetProcessDPIAware

   ' // Create the main window
   DIM pWindow AS CWindow
   pWindow.Create(NULL, "CWindow Hello World", @WndProc)
   ' // Change the background to white
   pWindow.Brush = GetStockObject(WHITE_BRUSH)
   ' // Set the client size of the window
   pWindow.SetClientSize(500, 320)
   ' // Center the window
   pWindow.Center

   ' // Dispatch Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main window callback procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   STATIC hNewFont AS HFONT

   SELECT CASE uMsg

      CASE WM_CREATE
         ' // Get a pointer to the CWindow class from the CREATESTRUCT structure
         DIM pWindow AS CWindow PTR = AfxCWindowPtr(lParam)
         ' // Create a new font scaled according the DPI ratio
         IF pWindow->DPI <> 96 THEN hNewFont = pWindow->CreateFont("Tahoma", 9)
         EXIT FUNCTION

      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE WM_PAINT
    DIM rc AS RECT, ps AS PAINTSTRUCT, hDC AS HANDLE, hOldFont AS HFONT
         hDC = BeginPaint(hWnd, @ps)
         IF hNewFont THEN hOldFont = CAST(HFONT, SelectObject(hDC, CAST(HGDIOBJ, hNewFont)))
         GetClientRect(hWnd, @rc)
         DrawTextW(hDC, "Hello, World!", -1, @rc, DT_SINGLELINE or DT_CENTER or DT_VCENTER)
         IF hNewFont THEN SelectObject(hDC, CAST(HGDIOBJ, CAST(HFONT, hOldFont)))
         EndPaint(hWnd, @ps)
         EXIT FUNCTION

    CASE WM_DESTROY
         ' // Destroy the new font
         IF hNewFont THEN DeleteObject(CAST(HGDIOBJ, hNewFont))
         ' // End the application by sending an WM_QUIT message
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Default processing of Windows messages
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

JRS

  • Guest
Re: FreeBasic
« Reply #14 on: July 29, 2018, 02:40:44 AM »
This was a Hello World keep it simple demonstration.  SB is an interpreter and Windows API calls are FFI dynamically and a C extension module for a more seamless integration.

I think SB wins hands down for simple and easy to understand.