Author Topic: Oxygen Basic 64-bit compiling  (Read 7412 times)

0 Members and 1 Guest are viewing this topic.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Oxygen Basic 64-bit compiling
« on: December 24, 2011, 01:06:23 AM »

I have just released Oxygen A038. This version can generate 64bit binaries.

This adds to the three existing modalities thus:

  • compiling 32-bit directly to memory
  • compiling to 32-bit EXE/DLL files with Oxygen.dll dependency
  • compiling to 32-bit EXE/DLL stand-alone files
  • compiling to 64-bit EXE/DLL stand-alone files

In the package, we have accumulated a substantial number of examples for Console, GDI, GDIplus, OpenGL and COM (SAPI).

Oxygen supports Object-Oriented programming and can also dynamically compile functions at run-time.

It is capable of reading both C-style and Basic-style headers

Also provided is a Scintilla-based IDE and a (somewhat brief) CHM manual

It has taken about 4 years to get this far and there is plenty more to do! All welcome to join in :)

Merry Christmas!

Charles


Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2009
    • www.zapsolution.com
Re: Oxygen Basic 64-bit compiling
« Reply #1 on: December 24, 2011, 09:16:58 AM »
Bravo, Charles!

Very impressive work.

Could you just post a small piece of H≤O code here, showing us the creation of a window with a common (SDK) message loop,
and how to call an external DLL ?

...
« Last Edit: December 24, 2011, 03:35:49 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Petr Schreiber

  • Sr. Member
  • ****
  • Posts: 254
Re: Oxygen Basic 64-bit compiling
« Reply #2 on: December 24, 2011, 10:20:25 AM »
Great job Charles...

Here is HelloWorld example code (slightly re-idented), picked from the alpha which can be downloaded here:
http://www.oxygenbasic.org/downloads.htm
Code: [Select]
$ filename "t.exe"
'#include "../../inc/RTL32.inc"
'#include "../../inc/RTL64.inc"
#include "../../inc/MinWin.inc"

#lookahead ' for procedures
s=error()
'
if s then
  print s
  goto endprog
end if

'=========
'MAIN CODE
'=========

    dim cmdline as asciiz ptr, inst as sys
    &cmdline = GetCommandLine
    inst     = GetModuleHandle 0

    '
    'WINDOWS
    '-------
    '
    WinMain inst,0,cmdline,SW_NORMAL

    endprog:

    'RELEASE SYSTEM RESOURCES
    '---------------------
    FreeMinWinLibraries

'===========
'END OF MAIN
'===========


'--------------------------------------------------------------------
Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
'====================================================================

    WndClass wc
    MSG      wm

    sys hwnd, wwd, wht, wtx, wty, tax

    wc.style = CS_HREDRAW or CS_VREDRAW
    wc.lpfnWndProc = &WndProc
    wc.cbClsExtra =0
    wc.cbWndExtra =0   
    wc.hInstance =inst
    wc.hIcon=LoadIcon 0, IDI_APPLICATION
    wc.hCursor=LoadCursor 0,IDC_ARROW
    wc.hbrBackground = GetStockObject WHITE_BRUSH
    wc.lpszMenuName =0
    wc.lpszClassName =@"Demo"

    RegisterClass (&wc)

    Wwd = 320 : Wht = 200
    Tax = GetSystemMetrics SM_CXSCREEN
    Wtx = (Tax - Wwd) /2
    Tax = GetSystemMetrics SM_CYSCREEN
    Wty = (Tax - Wht) /2

    hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
    ShowWindow hwnd,SW_SHOW
    UpdateWindow hwnd
    '
    sys bRet
    '
    do while bRet := GetMessage (&wm, 0, 0, 0)
        if bRet = -1 then
          'show an error message
        else
          TranslateMessage &wm
          DispatchMessage &wm
        end if
    wend

End Function

dim as rect crect 'for WndProc and TimerProc

'------------------------------------------------------------------
function WndProc ( sys hWnd, wMsg, wParam, lparam ) as sys callback
'==================================================================

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst

    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============

      GetClientRect  hWnd,&cRect

      '-------------- 
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============


      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
       
      '--------------   
      case WM_KEYDOWN
      '==============

      '============           
      Select wParam
      '============

    Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

      End Select
     

      '--------       
      case else
      '========
         
        function=DefWindowProc hWnd,wMsg,wParam,lParam
       
    end select

end function ' WndProc


Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: Oxygen Basic 64-bit compiling
« Reply #3 on: December 24, 2011, 12:32:22 PM »
And here is an elementary example of a 64-bit stand-alone DLL and a program to test it:

Code: [Select]
  '
  $dll
  $filename "t64.dll"
  #include "..\..\inc\RTL64.inc"


  print "t64.dll Loaded"

  function HelloA(string s) as string, export
    return "HelloA "+s
  end function

  function HelloW(wstring s) as wstring, export
    return "HelloW "+s
  end function

Code: [Select]

  $filename "TestHello64.exe"
  #include "..\..\inc\RTL64.inc"


  declare function HelloA lib "t64.dll" (string s) as string
  declare function HelloW lib "t64.dll" (wstring s) as wstring

  print HelloA "World!"
  print HelloW "World!"


These can be found in the package in examples/DLLs

Charles
« Last Edit: December 24, 2011, 12:39:25 PM by Charles Pegge »

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 966
    • it-berater
Re: Oxygen Basic 64-bit compiling
« Reply #4 on: December 25, 2011, 11:44:07 AM »
Could it be uses as a supplement for PowerBasic, which has `(at time of this writing)  no x64 version?
How difficult is it to transfer PB Code to OB?
For example a x64 Hook-Dll?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: Oxygen Basic 64-bit compiling
« Reply #5 on: December 25, 2011, 05:49:50 PM »

Not difficult for windows API programming. o2 has a much smaller function set and different syntax for creating objects and of course none of the specialisations like DDT. But if you need to produce DLLs for 64-bit clients, this is worth a try, and porting back into a latter 64 bit version of PB, should be quite simple, without too many syntax changes.

o2 has a number of features like inner (local) functions and C-style prototypes which you would not find in PB so you have to consider cross-compatibility quite carefully at the outset of a project.

Charles

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 966
    • it-berater
Re: Oxygen Basic 64-bit compiling
« Reply #6 on: December 25, 2011, 06:09:24 PM »
Quote
o2 has a number of features like inner (local) functions

IS the help file up to date?
I did not see anything about objects and such functions in the help file.

Is the assembler and anything included in just that dll or is is separate?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: Oxygen Basic 64-bit compiling
« Reply #7 on: December 25, 2011, 10:10:08 PM »
The manual is sketchy at this stage, and only covers the basics, but the examples included demonstrate most of the features. One day I hope a comprehensive manual will eventually emerge from Q&A with you guys and the collection of examples :)

o2 is a one piece compiler-assembler-linker, and you can freely mix assembler and basic. This is all coontained within Oxygen.dll. To make use of it as a compiler/executive. To small apps are provided: gxo2 for GUI compiling and exo2 for Console compiling.

the basic Classes look like this:

Code: [Select]

class testclass

s as string

method get() as string
  method=lcase s
end method

method set(w as string)
  s=w
end method

end class

'testing

dim obj as testclass
obj.set "Hello"
print obj.get

Most entities may have a limited or nested scope, and this includes functions

example of an local/inner function:

Code: [Select]
function A(v as double) as double
  '
  function cubed(v as double) as double
    return v*v*v
  end function
  '
  return cubed(v)+cubed(v)
end function

print A(2)

Charles
« Last Edit: December 25, 2011, 10:36:16 PM by Charles Pegge »

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 334
Re: Oxygen Basic 64-bit compiling
« Reply #8 on: December 25, 2011, 11:18:30 PM »
Hello Charles Pegge,
 looks good from almost as in Power Basic. I like it! :)
 regards Peter

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: Oxygen Basic 64-bit compiling
« Reply #9 on: December 26, 2011, 05:36:28 AM »
Yes it supports a range of coding styles

Take the WndProc prototype for example:

PB-style

function WndProc(byval hWnd as long, byval uMsg as long, byval wParam as long, byval lParam as long ) as long callback


intermediate-style

function WndProc(long hWnd, long uMsg, long wParam, long lParam) as long callback


Compact-style

function WndProc(long hWnd, uMsg, wParam, lParam) as long callback


Charles
« Last Edit: December 26, 2011, 06:04:22 AM by Charles Pegge »