Author Topic: MBC  (Read 810 times)

Offline AIR

  • BASIC Developer
  • Posts: 628
MBC
« on: December 11, 2018, 03:59:14 PM »
Dusted off my old translator, because I'm tired of looking for an easy to use macOS GUI.

So I'm re-rolling my own.  Here is example syntax:

Code: Text
  1. ' ************************************************
  2. ' * Demo of AIR's Cocoa Objects Library (libcol) *
  3. ' ************************************************
  4.  
  5. $MODULE "cocoa.inc"
  6.  
  7. const win_width = 600
  8. const win_height = 400
  9. const button_width = 90
  10.  
  11. widgets as enum
  12.     txtFld
  13.     button
  14.     colorButton
  15.     combo
  16.     checkbox
  17.     label
  18.     edit
  19. end enum
  20.  
  21. sub btnClick(sender as id)
  22.     dim fname$,a$
  23.     fname$ = mainWin.openDialog("bas:c:mm")
  24.     if len(fname$) then
  25.         mainWin.setText(txtFld,fname$)
  26.         a$ = LoadFile$(fname$)
  27.         mainWin.setText(edit,a$)
  28.     end if
  29. end sub
  30.  
  31. Global mainWin("AIR Cocoa Test Window", win_width, win_height) as FORM
  32.  
  33. Cocoa_Init()
  34.     with mainWin
  35.         .newEntry(txtFld, "Testing AIR's Cocoa Library with MBC", 16, 20, win_width-122, 26, akWidth)
  36.         .newButton(button, "Load", win_width-100, 20, button_width, 26, akRight, btnClick)
  37.         .newButton(colorButton, "Color", win_width-100, 50, button_width, 26, akRight)
  38.         .newCombo(combo, 16, 50, 210, 26)
  39.         .newCheck(checkbox, "Check Box 1", 240, 50, 100, 26)
  40.         .newLabel(label, "This is a Label", 360, 50, 100, 26)
  41.         .newEdit(edit,"", 16, 96, 480, 280,akWidth | akHeight)
  42.  
  43.         .Add(combo, "Apples:Oranges:Peaches", "Oranges")
  44.         .setText(edit, "Hello, World!")
  45.     end with
  46. Cocoa_Run()
  47.  

This is leveraging the fact the STRUCTS in C++ can be used like CLASSES; the only real difference is that with STRUCTS, all items are public by default whereas with CLASSES they're private by default.

The FORM struct/object uses a Constructor as seen in the creation of 'mainWin', but it is NOT a CLASS although it is used like one.

One of the interesting things is that only the mainWin object is global.  In other GUI implementations I've looked at, each GUI object that you might reference are declared Global (unless you're passing a pointer/reference to that object to a function).

The 'widgets' enum is just that:  An enum of integers.  So they are not GUI objects, but are used internally to track which object a given action needs to be performed on.

The attached screenshots show this demo in 'action', with the 3rd showing the OpenFileDialog which is attached to the form, and the 5th showing how resizing is handled if you use the 'ak*' series of flags.



AIR.


Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #1 on: December 11, 2018, 04:39:57 PM »
We both would be dead and gone waiting for IUP to run native on the Mac. A great project to combine all your talents.

Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #2 on: December 11, 2018, 05:17:56 PM »
I don't need the aneurysm.  An interface to an interface to an interface to native?  IUP's code-base is wayyyyy too abstracted to unravel. 

Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #3 on: December 22, 2018, 01:48:51 AM »
What advantages does BaCon and FreeBasic BASIC to C translators have over MBC?
« Last Edit: December 22, 2018, 12:25:11 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #4 on: December 22, 2018, 01:13:37 PM »
AIR,

I created a MBC-DEV project in the sandbox.

Quote
MBC is a Basic to C/C++ translator, originally based on the BCX Windows translator by Kevin Diggins. It has successfully compiled using Clang++ and G++ on macOS/Linux 64bit OS's, and G++ on RaspberryPi as 32bit.


Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #5 on: December 22, 2018, 09:19:19 PM »
I tried to compile the regextest.bas example and received the following errors.


MBC Version 4.0-Beta3 (2018/12/09)
MBC4: Based on Linux BCX by Mike Henning (c) 2009
(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques


********************
** 64 BIT VERSION **
********************

[Lines In:20] [Lines Out:185] [Statements:12] [Time:0.01 sec's]
BCX translated regextest.bas to regextest.cc
Shelling Out To: g++  -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings regextest.cc -ldl  -o regextest
regextest.cc: In function ‘int main(int, char**)’:
regextest.cc:170:12: error: ‘REGEX’ does not name a type; did you mean ‘REG_ERR’?
   static   REGEX  hits;
            ^~~~~
            REG_ERR
regextest.cc:171:11: error: ‘hits’ was not declared in this scope
   memset(&hits,0,sizeof(hits));
           ^~~~
regextest.cc:171:11: note: suggested alternative: ‘puts’
   memset(&hits,0,sizeof(hits));
           ^~~~
           puts
regextest.cc:177:6: error: ‘bcxregex’ was not declared in this scope
   if(bcxregex(Src,"( )", &hits))
      ^~~~~~~~
jrs@jrs-laptop:~/MBC$


« Last Edit: December 22, 2018, 09:20:59 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #6 on: December 22, 2018, 09:29:34 PM »
Give me a few minutes....

Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #7 on: December 22, 2018, 09:38:30 PM »
Sorry, the problem is here:

Code: C
  1.  if(bcxregex(Src,"( )", &hits))

I changed that function to 'regmatch'.

You also need to put in something to search for, as is it will search for a space.

Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #8 on: December 22, 2018, 09:44:19 PM »
Could you please post your working version? I'm still getting errors.


Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #9 on: December 22, 2018, 09:57:01 PM »
Code: Text
  1. $EXECON
  2. $NOMAIN
  3.  
  4. FUNCTION main(argc as integer, argv as PCHAR*) as integer
  5.     dim hits as REGEX
  6.     LOCAL Src$,j
  7.  
  8.     Src$ = "Hello, World! This is Armando"
  9.     IF regmatch(Src$,"(H.+,).+(man)",&hits) THEN
  10.         FOR j = 1 TO hits.count
  11.             IF LEN(hits.results[j]) THEN
  12.                 PRINT hits.results[j]$,SPC$;
  13.             END IF
  14.         NEXT
  15.         PRINT
  16.     END IF
  17. END FUNCTION
  18.  

Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #10 on: December 22, 2018, 10:04:47 PM »
Thanks!


MBC Version 4.0-Beta3 (2018/12/09)
MBC4: Based on Linux BCX by Mike Henning (c) 2009
(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques


********************
** 64 BIT VERSION **
********************

[Lines In:17] [Lines Out:246] [Statements:16] [Time:0.01 sec's]
BCX translated regextest.bas to regextest.cc
Shelling Out To: g++  -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings regextest.cc -ldl  -o regextest
jrs@jrs-laptop:~/MBC$ ./regextest
Hello, man
jrs@jrs-laptop:~/MBC$


Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #11 on: December 22, 2018, 11:00:44 PM »
Is there more MBC examples I can try under Ubuntu 18.10?

Converting some of the BaCon examples is an idea.

It would be interesting to compare the resulting C code for efficiency, readability and the ability to extend it at that level.
« Last Edit: December 22, 2018, 11:59:50 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #12 on: December 23, 2018, 09:42:08 PM »
Updated MBC and Examples uploaded to my repository.  You will need to recompile MBC for all of the items in Examples/Console to compile.

Offline John

  • Forum Support / SB Dev
  • Posts: 2622
    • ScriptBasic Open Source Project
Re: MBC
« Reply #13 on: December 24, 2018, 12:05:24 AM »
It would be great if you could push your MBC changes to sandbox copy. I really can't take on much more than I already have going. Feel free to remove the MBC repo in the sandbox if it's too much trouble to maintain.


Offline AIR

  • BASIC Developer
  • Posts: 628
Re: MBC
« Reply #14 on: December 24, 2018, 12:42:41 AM »
It would be great if you could push your MBC changes to sandbox copy. I really can't take on much more than I already have going. Feel free to remove the MBC repo in the sandbox if it's too much trouble to maintain.

If Gitlab CE had a PROPER mirroring option, this wouldn't be an issue.  Aside from all of the extras it comes with that I don't need, the lack of a simple mirroring option was a deal killer for me when I looked at it previously.

That's why I settled on GOGS and it's fork, GITEA.  GOGS is on my VPS, GITEA is on my local server at home.

They both support scheduled checking and updating of repositories, with no interaction required.

At one point, I had a mirror set up that would pull from BitBucket down to GOGS which was then pulled down to GITEA.  So any changes I pushed up to BitBucket would automatically sync to my GOGS and GITEA instances.  So I always had fully functional backup repositories no matter what.

Anyway, I simply don't have the time or the patience to maintain a repository in the SANDBOX for MBC, because keeping everything synced would be a PITA, and I would need to keep two active code bases going on multiple machines and VM's here.

AIR.