General questions

Started by Frank Brübach, June 30, 2024, 09:11:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hello Charles..

I have two General questions about programming

A) If you are using an extern Editor for oxygen Basic, for example Abc Editor, written in another Basic language.. and you are loading oxygen.dll you must declare every function for this new Editor to understand which procedures should BE execute? So its Not very comfortable to use this technique isnt IT?

B) what Basic language is after your Personal opinion closer to oxygen Basic If you are translating Code examples with include and header files for example of freebasic / Powerbasic ? 
Thx, frank

Charles Pegge

As a basic requirement, IDEs must be able to call co2.exe and/or co2m64.exe with the source code filename as a param. No details about the Oxygen internals are required. I often use humble Notepad and execute o2 programs directly from the .o2bas text files, configured to run with co2.exe.

o2 uses a similar string system to PB, so it might be the easiest  BASIC to translate.





Frank Brübach

Thanks for feedback. Do you have an example how to do that?

I must declare functions Like o2_basic and all other First ?

I can load CO2.exe with my IDE but thats all Here thanks, Frank

Frank Brübach

#3
Made this example for loading oxygen.dll but CO2.exe loading in a Powerbasic CSED Editor causes Error

#COMPILE EXE
#DIM ALL
#INCLUDE "Win32api.inc"

' if I am loading 'co2.exe' I have got an error "You must set the path ofa the headers"

    DECLARE FUNCTION o2_basic(BYREF s AS ASCIIZ) AS LONG
    DECLARE FUNCTION o2_exec (BYVAL p AS LONG) AS LONG
    DECLARE FUNCTION o2_errno() AS LONG
    'DECLARE FUNCTION o2_error() AS ASCIIZ*260 PTR '' error
    DECLARE FUNCTION ThisFunction() AS LONG

FUNCTION PBMAIN () AS LONG
    DIM lHandle AS LONG
    DIM lResult AS LONG
    DIM lAddress AS LONG

    lHandle = LoadLibrary("oxygen.dll")
    IF lHandle <> 0 THEN
        lAddress = GetProcAddress(lHandle, "thisFunction")
        IF lAddress <> 0 THEN
            CALL DWORD lAddress USING ThisFunction() TO lResult
        END IF
        FreeLibrary lHandle
    END IF
  '
  DIM qu AS STRING
  DIM cr AS STRING
  DIM src AS ASCIIZ*260 'STRING
  qu=CHR$(34)
  cr=CHR$(13)+CHR$(10)
  src="print " + qu+"Hello Batman"+qu+cr
  MSGBOX "src: " + src
  '
  o2_basic(src) ' error undefined sub/function reference
  '
  IF o2_errno()<>0 THEN
    'PRINT o2_error()
  'ELSE
    o2_exec(0)
  END IF
  END

END FUNCTION

Its only for understanding  how does this Work. I have already my IDE Editor  but would Like to know whats possible to load an extern DLL and exe File. Thx

Charles Pegge

The IDE generally needs to run compiler co2.exe with the source code filename, as a separate process. It does not need to know anything about oxygen.dll. IDEs all have their own ways of configuring this but you can see how this is done in tools\Oxide.o2bas

          'SELECT COMPILER
          if mo=1 'SHIFT ONLY
            s="\co2m64.exe" 'CO2M64 64BIT COMPILING
          else '
            s="\co2.exe" 'CO2 COMPILING
            's="\gxo2.exe" 'GXO2 COMPILING
          endif
          'RUN COMPILER AS A SEPARATE PROCESS
          'Exec qu+o2dir+s+qu+" "+qu+OxyPath(f)+qu
          's=qu+o2dir+s+qu+" "+cmo+qu+OxyPath(f)+qu
          'Exec(s)
          QuExec( o2dir+s, cmo, OxyPath(f) )
        end if
      end if

QuExec comes from inc\sysutil.inc

  'process flags:
  %CREATE_NEW_CONSOLE 0x00000010
  %CREATE_NO_WINDOW 0x08000000
  'etc
  '
  function Exec(string c, int wait=0, flags=0) as int
  ===================================================
  STARTUPINFO infs
  PROCESS_INFORMATION infp
  CreateProcess null,c,0,0,0,flags,0,0,@infs,@infp
  if wait
    WaitForMultipleObjects 1,@infp.hthread,1,-1
  end if
  GetExitCodeProcess(infp.hProcess,@function)
  CloseHandle infp.hProcess
  CloseHandle infp.hThread
  return 0
  end function


  function QuExec(string c,d,f, int wait=0,flags=0) as int
  ========================================================
    return Exec(qu+c+qu+" "+d+" "+qu+f+qu, wait,flags)
  end function
 

  function DOS(string s, int wait=0,flags=0)
  ==========================================
  string c
  if s then
    c="cmd.exe /c "+s
  else
    c="cmd.exe"
  end if
  Exec c, wait,flags
  end function

To understand how the co2 compiler uses Oxygen.dll

from tools\co2.bas
  extern lib "oxygen.dll"
  uses oxygenAPI
  end extern

inc\oxygenAPI.inc
  '12:43 18/03/2017
  '23:23 29/07/2022


  'ABST
  '====
  'compile source code string and return intermediate code string
  ! o2_abst( string s ) as string


  'BASIC
  '=====
  'compile source code string to binary code, and return pointer
  ! o2_basic( string s ) as sys


  'BUF
  '===
  'select current binary code buffer and return pointer
  ! o2_buf( int n ) as sys


  'ERRNO
  '=====
  'return error number, if any
  ! o2_errno() as int


  'ERROR
  '=====
  'return compiling error string, if any
  ! o2_error() as string


  'EXEC
  '====
  'execute inary code in current buffer (or from location specified by pointer
  ! o2_exec( sys p=0 )  as sys


  'LEN
  '===
  'return length of code in current binary code buffer
  ! o2_len() as int


  'LIB
  '===
  'return base location of o2 runtime function table
  ! o2_lib() as sys


  'LINK
  '====
  'compile o2 machine script to binary and return pointer
  ! o2_link( string src ) as sys


  'STATS
  '=====
  'return set of compilation metrics
  ! o2_stats() as string


  'MODE
  '====
  'specify string mode for various o2 API functions
  '0 ascii char*
  '1 ascii char*
  '2 unicode wchar*
  '8 ole bstring ascii
  '9 ole bstring ascii
  '10 ole bstring unicode
  ! o2_mode( int m )


  'PATHCALL
  'set callback to obtain hosted oxygenBasic path string
  ! o2_pathcall( sys m )


  'PREP
  '====
  'compile source code string and return assembly code string
  ! o2_prep( string s ) as string


  'VARCALL
  '=======
  'set callback to obtain host variable location, by name
  ! o2_varcall( sys m )


  'VERSION
  '=======
  'return version string, include time/datestamp
  ! o2_version() as string


  'VIEW
  '====
  'compile source code string and return o2 machine script string
  ! o2_view( string s ) as string



  o2_mode 9 'for oxygenBasic ascii strings

Frank Brübach

#5
Many thanks Charles for your detailed explanations.. some Things I know already by studying source Code but to be truly thats new for me that the IDE (oxide.o2bas)  wear the Main Part of CO2.exe and then extern loading oxygen.dll..

So If I am using another IDE for oxygen it must going a similar way with changed path filenames for source Code Files and DLL? And does it  make Sense to use another Editor with another Basic language? ;)

Thanks, Frank

Charles Pegge

Most IDEs will allow you to specify compiler, file paths and keyword lists for syntax highlighting. I understand that in more specialized IDEs, AI is also deployed in auto-complete and possible code generation.