Skip to main content
Elaine Litchfield
Participating Frequently
Apr 20, 2022 9:47 PM UTC

Compiler optimizations

Is there a list of the optimizations the Unibasic compiler does available anywhere?

------------------------------
Elaine Litchfield
Owner
Elaine Litchfield Consulting
San Diego CA US
------------------------------

    1 reply

    Apr 21, 2022 7:19 AM UTC
    Is there a list of the optimizations the Unibasic compiler does available anywhere?

    ------------------------------
    Elaine Litchfield
    Owner
    Elaine Litchfield Consulting
    San Diego CA US
    ------------------------------
    Elaine,

    The UniBASIC compiler compiles code to virtual code that is run by the UniVerse or UniData BASIC run-time engine as appropriate. As such it does not have an equivalent as might be used by a C code optimiser for example, the functionality is internal to the compiler itself. If using UniVerse it is possible to see the resulting virtual machine code using VLIST (see below), though UniData does not have an equivalent.

    >VLIST BP ENCODE.TEST
    Main Program "BP.O/ENCODE.TEST"
    Compiler Version: 11.3.0.0
    Object Level : 5
    Machine Type : 11
    Local Variables : 11
    Subroutine args : 0
    Unnamed Common : 0
    Named Common Seg: 0
    Object Size : 218
    Source lines : 27
    Object Date Time: 28 JAN 2022 11:34:53

    00001: CRT @(-1):@(0,0)
    00001 00000 : 04A cursor -1 -1 => $R0
    00001 00008 : 04A cursor 0 0 => $R1
    00001 00010 : 046 crtcrlf $R0 $R1

    00002: EXECUTE 'COMO ON ENCODE.COMO'
    00002 00018 : 07E execute "COMO ON ENCODE.COMO"

    00003: BASE.NAME = 'ENCODE.TEST'
    00003 0001C : 0F8 move "ENCODE.TEST" => BASE.NAME

    00004: T.COUNT = 20 ; * ENCODE attempts
    00004 00022 : 0F8 move 20 => T.COUNT

    00005: !

    00006: FOR T = 1 TO T.COUNT
    00006 00028 : 0F8 move 0 => T
    00006 0002E : 098 forincr T T.COUNT 1 000D4:

    00007: ATTACHMENT.PATH = SYSTEM(38):'\\TEST.ENCODE-':T:'.pdf'
    00007 0003C : 19A system 38 0 => $R0
    00007 00044 : 104 multi_cat $R0 "\\TEST.ENCODE-" T ".pdf" => ATTACHMENT.PATH

    00008: ENCODE.RET = '' ; * Encoding return code 0=Success 1=Unsupported Algorithm 2=Invalid Params 3=Cannot Read Data 4=Data Cannot be Encoded
    00008 00052 : 0F8 move "" => ENCODE.RET

    00009: ENCODE.ALGORITHM = 'Base64A' ; * Base64 with CRLF (One long ASCII String)
    00009 00058 : 0F8 move "Base64A" => ENCODE.ALGORITHM

    00010: ENCODE.ACTION = '1' ; * 1=Encode 2=Decode
    00010 0005E : 0F8 move "1" => ENCODE.ACTION

    00011: ENCODE.INPUT = ATTACHMENT.PATH ; * Input filepath or datastring
    00011 00064 : 0F8 move ATTACHMENT.PATH => ENCODE.INPUT

    00012: ENCODE.INPUT.SOURCE = '2' ; * Input Source 1=Datastring 2=Filepath
    00012 0006A : 0F8 move "2" => ENCODE.INPUT.SOURCE

    00013: ENCODE.OUTPUT = '' ; * Output filepath or datastring
    00013 00070 : 0F8 move "" => ENCODE.OUTPUT

    00014: ENCODE.OUTPUT.SOURCE = '1' ; * Output Source 1=Datastring 2=Filepath
    00014 00076 : 0F8 move "1" => ENCODE.OUTPUT.SOURCE

    00015: ENCODE.RET = ENCODE(ENCODE.ALGORITHM,ENCODE.ACTION,ENCODE.INPUT,ENCODE.INPUT.SOURCE,ENCODE.OUTPUT,ENCODE.OUTPUT.SOURCE)
    00015 0007C : 41A encode ENCODE.ALGORITHM ENCODE.ACTION ENCODE.INPUT ENCODE.INPUT.SOURCE ENCODE.OUTPUT => ENCODE.OUTPUT.SOURCE ENCODE.RET

    00016: IF ENCODE.RET THEN
    00016 0008C : 2DE testfw ENCODE.RET 000C4:

    00017: CRT
    00017 00094 : 020 ccrlf

    00018: CRT 'Encoding to ':DQUOTE(ENCODE.ALGORITHM):' failed on ':DQUOTE(ENCODE.INPUT):' with a return code of ':DQUOTE(ENCODE.RET):' !'
    00018 00096 : 140 quote ENCODE.ALGORITHM => $R0
    00018 0009C : 140 quote ENCODE.INPUT => $R1
    00018 000A2 : 140 quote ENCODE.RET => $R2
    00018 000A8 : 046 crtcrlf "Encoding to " $R0 " failed on " $R1 " with a return code of " $R2 " !"

    00019: CRT
    00019 000BA : 020 ccrlf
    00019 000BC : 0C2 jump 000CE:

    00020: END ELSE

    00021: CRT
    00021 000C4 : 020 ccrlf

    00022: CRT 'Successfully encoded.'
    00022 000C6 : 046 crtcrlf "Successfully encoded."

    00023: CRT
    00023 000CC : 020 ccrlf

    00024: END

    00025: NEXT T
    00025 000CE : 0C2 jump 0002E:

    etc...

    ------------------------------
    John Jenkins
    Principal Technical Support Engineer
    Rocket Software Limited
    U.K.
    ------------------------------