Page 1 of 4 123 ... LastLast
Results 1 to 10 of 39

Thread: Oxygen O2H Tech Blog

  1. #1

    Oxygen O2H Tech Blog

    O2H

    O2H is a Just-In-Time compiler assembler, deployed in a single DLL that takes source code strings and returns executable binary. It is an extension of the Oxygen assembler. This implementation can be used with thinBasic to provide high speed functions for time critical operations, that would otherwise be impractical using interpreted code alone.

    I will be posting updates of the Oxygen source code and DLL here as the compiler develops.

    This code is in the alpha stage, - undergoing further work and testing so please approach with caution!

    The code is now split into the following parts:

    thinBasicOxygen modular interface for thinBasic
    thincore header for creating thinBasic modules in FreeBasic

    o2glo structures, constants and global variables
    o2lex lexing and parsing functions
    o2par parsing: lower translation functions
    o2sem semantics: higher translation functions
    o2fun the original oxygen machine code renderer / linker
    o2asm the assembler which translates assembly code into oxygen script
    o2prep preprocessor / compiler translating high level code to Assembler and o2 script
    o2run runtime procedures used by compiled programs

    Coding Strategy

    The Oxygen compiler is written in very basic BASIC and assembler. Once a stable kernel is established, Oxygen will extend itself with a library of functions and macros written in Oxygen - and ultimately the kernel itself will be rewritten in standalone Oxygen.



    compiling from the freebasic console: (FreeBasic 0.20.0)

    fbc -dylib thinBasic_Oxygen.bas

    Both the Module and source code can now be found here:

    http://community.thinbasic.com/index.php?topic=2517



  2. #2

    Re: Oxygen H2O Tech Blog


    Adopting Olestrings (BSTR)

    This brings h2o into line with thinBasic for handling dynamic strings, ensuring that strings are consistently allocated and deallocated by the OS.

    This code exposes the raw mid$() function. A negative index is read as counting from the end of the string backwards instead of counting from the beginning of the string forwards.


    [code=thinbasic]

    uses "OXYGEN"

    dim src as string
    dim s,t as string
    dim v as long

    src= "
    push ebp
    mov ebp,esp
    push ebx
    mov eax,[ebp+8]
    mov eax,[eax] ' deref once
    mov ebx,kernel
    mid eax,[ebp+12],[ebp+16]
    pop ebx
    mov esp,ebp
    pop ebp
    ret 12
    "

    o2_buf 1 : o2_asmo src : declare function MIDS ( s as string, byval i as long, byval le as long ) as string at o2_buf 1



    if len(o2_error) then msgbox 0,o2_error()+o2_view (src) : stop


    S="one two three"
    t=mids s,5,3
    't=mids s,-5,5
    msgbox 0,s+$cr+t
    [/code]

    Internal: (FreeBasic)

    [code=thinbasic]


    function mids(byval p as BSTR,byval i as long,byval j as long) as BSTR

    asm
    mov edi,[p] 'pointer
    mov edx,[edi-4] 'length
    '-------------'neg offsets
    mov esi,[i]
    cmp esi,0
    jg midok2 'skip if positive
    add esi,edx 'adjust negs
    inc esi
    cmp esi,1 'lowest limit=1
    jge midok1
    mov esi,1 'minimum is 1
    midok1:
    mov [i],esi
    midok2:
    mov esi,edi 'pointer
    cmp edx,[i]
    jge midok3 'past end?
    push 0
    push 0
    call SysAllocStringByteLen
    mov esi,eax
    jmp midx 'null allocation
    midok3:
    add edi,[i] 'src base
    dec edi 'base adjust
    mov eax,edi 'src base
    add eax,[j] 'req boundary
    add edx,esi 'end boundary
    cmp eax,edx
    jle midok4 'choose lower length
    mov eax,edx
    midok4:
    sub eax,edi 'set length
    push eax 'bytes
    push eax '
    push 0 'null string
    call SysAllocStringByteLen
    push edi 'src base
    push eax 'new string dest
    mov esi,eax
    call copyn
    midx:
    mov [function],esi ' new string
    end asm
    end function[/code]

  3. #3

    Re: Oxygen H2O Tech Blog


    Declarative Syntax

    dim global static local declare function sub byref byval ptr as pointer at =

    Dim supports both formats:

    dim as long a,b,c
    and
    dim a,b,c as long

    also mixed types

    dim a,b,c as long d,e,f as double

    and assignments

    dim as long a=40, b=50

    [code=thinbasic]

    uses "OXYGEN"
    uses "FILE"

    dim vv as long
    dim src as string

    src="
    declare function aaa ( byval da as double ) as long export
    declare function aab ( byref da() as double ) as long export
    global as long ga,gb
    global as long gc,gd
    function abc ( byref a as double, byval b as double, byval c as double ) as dword export
    dim as quad v1 at [ecx], v2 at [edx]
    dim as long v3=42,v4=46
    dim as double w3=42,w4=46
    dim v5,v6 as double as single l1,l2
    a=b
    end function
    "



    msgbox 0,o2_error()+o2_view (src) : stop
    file_save ("t.txt",o2_error()+o2_view(src)) : stop
    o2_asmo src : o2_exec : msgbox 0,"0x"+hex$(vv)

    [/code]

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10

    Re: Oxygen H2O Tech Blog

    That is great Charles.

    I need to align your DIM syntax in thinBasic too i order to keep compatible.
    Thanks a lot.
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5

    Re: Oxygen H2O Tech Blog


    Hi Eros,
    I split these compound dim structures into simple ones of single type in pre-def format - then they are all compiled the same way.

    [code=thinbasic]
    ' wt w3 variable types
    ' ws list of variables of the current type
    ' wva() dim statements accumulator
    if wr="as" then
    w3=getas(s,i)
    if ws="" then wt=w3:continue do ' set predef
    if wt="" then wva(n)+="var "+w3+ws+cr:ws="":continue do ' postdef
    wva(n)+="var "+wt+ws+cr:wt=w3:ws="":continue do ' predef
    end if
    [/code]

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10

    Re: Oxygen H2O Tech Blog

    Yes, thinBasic does very similarly. It will be quite easy for me to adapt.
    DIM AS <type> <var> [, var [... ]]
    is a syntax I wanted already developed.

    Thanks
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7

    Re: Oxygen H2O Tech Blog

    That is evil. I could understand

    TYPE var, var, var

    but DIM AS TYPE, VAR VAR make my toe nails bend backwards. Thank god it is optional.

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10

    Re: Oxygen H2O Tech Blog

    Yes, me too.

    But those are all different ways used by different BASIC dialects to make exactly the same things. The more we support, the better to migrate other piece of code or ... users

    I also like TYPE var [, var [...]]
    but a little more difficult to manage for example when UDT are used.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9

    Re: Oxygen H2O Tech Blog


    dim as long a,b,c is one of the delights of freebasic.

    It does have some advantages once you get accustomed to it. - editing is a little easier and also translating from C

    I am attempting to provide a very flexible dim statement to accommodate different dialects. On the down side its not so good for enforcing code discipline

    How about this: ;D

    dim a,b,c as long as double d e f

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: Oxygen H2O Tech Blog

    Charles,

    thanks for report on your H2O progress.

    If you need easy port from C, then what about using DIM <datatype> instead of DIM AS DATATYPE.
    Like:
    DIM LONG A, B ,C
    But I must say I like the current ThinBasic syntax still a bit more - it is more wordy, but also clear.
    It is a bit confusing when type specifier is once before variable name, and in other case after variable name - this mix would not be very clear.

    Like yours:
    dim a,b,c as long as double d e f
    ;D

    I don't know, I would probably use the classic thinBasic syntax I presume.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Id Tech 5 - New Carmack's pet
    By Petr Schreiber in forum Gaming
    Replies: 9
    Last Post: 13-06-2007, 11:48

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •