Results 1 to 7 of 7

Thread: TOMDK - creating TB modules with Oxygen

  1. #1

    TOMDK - creating TB modules with Oxygen

    Creating thinBasic Oxygen Modules:

    TOMDK is a single script which can be used as a basis for creating DLLs for thinBasic. The zip file below is the first release. You can adapt the TOM script to build your own modules. No other software is required to generate the DLL, and you can see all the nuts and bolts involved in building a DLL from scratch.

    Once again I had to make some adjustments to Oxygen. But no new commands.

    Oxygen Update

    http://community.thinbasic.com/index.php?topic=1845.0
    Attached Files Attached Files

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Re: TOMDK - creating TB modules with Oxygen

    ;D

    I have no words ... thinBasic module compiling thinBasic module ...
    And with those clean macros it is very easy to understand.


    Karma up ,
    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

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: TOMDK - creating TB modules with Oxygen

    Charles with all that you are doing and with possibly what new PowerBasic brings, I am at a loss to categorize what can and will be possible with thinBasic. Your module is breaking all the rules for scripting languages and what can be done with them. I can't comment more as out of my league, but am watching in admiration that is for sure!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4

    Re: TOMDK - creating TB modules with Oxygen


    Well thank you Petr. It was quite hard work putting it together as the information available is rather limited. I've used a macro to place the Export code, out of sequence at the top of the file. The rest can be left unaltered in most instances.

    Larger modules will require an extended imports section but only in the virtual image.
    If you see [esi+3600] in the listing then its time to add another 4096 bytes but I can automate this in future versions.


  5. #5

    Re: TOMDK - creating TB modules with Oxygen


    Hi Kent,
    As long as the language is Turing-complete it can be used to generate another language of any complexity. It is certainly possible to build a compiler in pure thinBASIC though it might perform at a leisurely pace. My first attempt at a a compiler many years ago, for an 8088 based computer board I designed. It was written with mBasic, the standard Microsoft interpreter. (Later we compiled it with BASCOM). It was adequate for testing the board, and establishing basic communications.

    With Oxygen, I've been pushing the boundaries - but neglected the basics which are at least as important. So I will try to remedy this by posting some short pieces which are relatively easy to follow. These will form part of the h2o kernel.

  6. #6
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: TOMDK - creating TB modules with Oxygen

    It is definately possible to write a compiler in thinbasic. With and without the help of Charles great modules.

  7. #7

    Re: TOMDK - creating TB modules with Oxygen

    Compiler in thinBasic ;D

    This will convert simple expressions like
    a + b * c - d
    into assembly code taking account of operator precedence.
    (converted from PB)

    [code=thinbasic]

    DIM ascw,dtf,swd,i as Long
    DIM s AS STRING
    '
    s="a + b * c - d"
    '
    MSGBOX 0,s+$CRLF+$CRLF+compile_expr(s,1)
    stop

    ' Compile expression using operator precedence
    FUNCTION compile_expr(s AS STRING, i AS LONG) AS STRING
    LOCAL w,op,np,ins,t AS STRING
    LOCAL prec,stk AS LONG
    stk=1
    ' stack arrays
    DIM sprec(16) AS LONG ' precedence
    DIM sop(16) AS STRING ' operator
    DO
    w=nword(s,i)
    IF w="" THEN EXIT DO
    op="":ins=""
    IF w="+" THEN op="fadd qword "rec=5
    IF w="-" THEN op="fsub qword "rec=5
    IF w="*" THEN op="fmul qword "rec=6
    IF w="/" THEN op="fdiv qword "rec=6
    IF LEN(op) THEN w=nword(s,i)
    IF op="" THEN op="fld qword "rec=7
    np=nword(s,i) ' next operator
    IF (stk>1) then
    IF (sprec(stk-1)>=prec) THEN
    DECR stk
    ins= _
    "fst qword [esi]"+$CR _
    +"fld qword ptr [esi-8]"+$CR _
    +sop(stk)+"[esi]"+$CR _
    + "sub esi,8"+$CR
    END IF
    END IF
    i=swd ' restore reader position
    IF ((np="*")OR(np="/"))AND(prec<6) THEN
    ins= _
    "fstp qword [esi]"+$CR _
    +"add esi,8"+$CR
    sprec(stk)=prec:sop(stk)=op: op="fld qword "
    INCR stk
    END IF
    t=t+ins+op+w+$CR
    LOOP
    FUNCTION=t
    END FUNCTION

    GET NEXT WORD
    FUNCTION nword(BYREF s AS STRING, BYREF i AS LONG) AS STRING
    ' s source
    ' i position in source
    ' swd start of word position
    ' a ascii code
    ' b general purpose
    ' wr word

    LOCAL a,b,v AS LONG
    DIM wr AS STRING

    DO ' skip leading white space and blank lines
    a=ASC(s,i)
    IF a<=0 THEN EXIT DO
    'if a=10 then lct+=1
    IF a>32 THEN EXIT DO
    INCR i
    LOOP
    swd=i:dtf=0
    ascw=a
    DO
    a=ASC(s,i)
    IF a<33 THEN EXIT DO
    INCR i
    IF (a=34)OR(a=39)OR(a=96) THEN
    IF i>swd+1 THEN EXIT DO ' as terminating symbol
    b=a
    DO
    a=ASC(s,i)
    INCR i
    IF (a=b)OR(a=0) THEN EXIT DO
    LOOP
    a=ASC(s,i)
    IF a<>46 THEN EXIT DO
    END IF
    IF a=46 THEN
    IF dtf=0 THEN dtf=i-swd
    ITERATE DO
    END IF
    IF (a>96)AND(a<123) THEN ITERATE DO
    IF (a>64)AND(a<91) THEN ITERATE DO
    IF (a>47)AND(a<5 THEN ITERATE DO
    IF (a=35)OR(a=95) THEN ITERATE DO ' # _
    IF a>126 THEN ITERATE ' higher ascii
    IF i>swd+1 THEN DECR i' symbol as delimiter
    EXIT DO
    LOOP
    wr=MID$(s,swd,i-swd)
    'IF (ncase AND lowercase) THEN
    IF b=0 THEN wr=LCASE$(wr)
    'END IF
    FUNCTION=wr
    END FUNCTION

    [/code]

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
  •