Oxygen Basic

Information => Open Forum => Topic started by: JRS on November 18, 2014, 01:12:17 AM

Title: Chameleon BASIC
Post by: JRS on November 18, 2014, 01:12:17 AM
Quote
This project was adopted from KoolB 16.  An abandoned project on yahoo.  It's kind of funny because this project was almost ahead of rapid Q.

Chameleon BASIC will be the new and better Visual Basic. With such features as compatibility with GWBasic thru VB6. Possibly overriding VB.NET as I've build VB6 applications compatible with VB.NET in VB6. VB.NET Requires a runtime, this will not be a problem in Chameleon as it will run native to Windows. I'm also thinking of ports to Java and .NET.

This is a BASIC to ASM compiler for Windows. Charles & Mike should find this interesting.


.
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on November 18, 2014, 05:33:33 AM
Nice find, John, thanks!

It's got a long way to go out of its craddle as a Windows BASIC yet but it's indeed a kool start -- it works! :D
Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 08:46:25 AM
Love those tiny executables. Looks like a fun project and a good way to learn ASM.

Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on November 18, 2014, 01:00:29 PM
The smallest unoptimized and unpacked exes start at some 40KB -- that's not so small at all. Nasm optimization can bring the size down almost twice but not always. Further minification is possible only with the aid of UPX (http://upx.sourceforge.net/) -- the most usable exe packer around that usually doesn't trigger off the pack of AV bloodhounds at VirusTotal dot com.
Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 01:40:21 PM
I tried to call the koolb.dll with SB DYC which worked until I closed the dialog. (exception error) The default DYC example which in essence is doing the same thing works fine. Something strange happening on the return. I even tried calling the EXIT function before exiting SB with no luck.

This works.
Code: Script BASIC
  1. include dyc.bas
  2.  
  3. a$ = "message text" & chr$(0)
  4. print dyc::dyc("ms,i,USER32.DLL,MessageBox,PZZL",0,a$,"title",3)
  5.  

This doesn't return without an exception error. I wonder if it's expecting a bstr?
Code: Script BASIC
  1. include dyc.bas
  2.  
  3. a$ = "Hello Chameleon BASIC from Script BASIC" & chr$(0)
  4. print dyc::dyc("ms,i,koolb.dll,MESSAGE,Z",a$)
  5.  

Code: Text
  1. ' KoolB DLL (requires new KoolB compiler)
  2. $AppType DLL
  3.  
  4. ' RapidQ calls the KoolB DLL, which in turn calls the WinAPI MessageBox function
  5. Declare Function MessageBox Lib "User32.dll" Alias "MessageBoxA" (I As Integer, S As String, S2 As String, I2 As Integer) As Integer
  6.  
  7. ' Preserve names as much as possible (ie, don't mangle)
  8. $Mangle OFF
  9.  
  10. ' Our sample function
  11. Function Message (S As String) As Integer
  12.   Result = MessageBox(0, S, "KoolB DLL showing you a little message:", 0)
  13. End Function
  14.  
  15. $Mangle ON
  16.  


Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on November 18, 2014, 02:22:08 PM
Nope, it expects an ASCIIZ string or it wouldn't show the message. I confirm the DLL is broken. It also has a non-standard layout of sections in its binary image.

P.S. The type of first parameter in your call to MessageBox isn't correct. It is of C type HANDLE that evaluates to BASIC's Long rather than pointer as in your PZZL. It should be LZZL.
Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 02:37:15 PM
Thanks again Mike for the help and determining if this BASIC is worth the effort.

Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 07:15:09 PM
I seem to be having better luck creating .exe programs using the examples provided.

FYI The .asm files are line terminating with &H0d0d0a instead of &H0d0a.

Code: Visual Basic
  1. '*******************
  2. '* ColorBlocks.bas *
  3. '*******************
  4.  
  5. $AppType GUI
  6. $Optimize Off
  7. $Compress Off
  8.  
  9. $Include "Windows.inc"
  10.  
  11. $Resource IDI_COLORBLOCKS As "ColorBlocks.ico"
  12.  
  13. $Const xSteps = 5
  14. $Const ySteps = 4
  15.  
  16. Dim message As MSG
  17. Dim rct As RECT
  18. Dim wcex As WNDCLASSEX
  19. Dim ps As PAINTSTRUCT
  20. Dim hInst As Integer
  21. Dim hWindow As Integer
  22. Dim xSize As Integer
  23. Dim ySize As Integer
  24. Dim strClassName As String
  25. Dim strAppTitle As String
  26.  
  27. Function OnSize(hWnd As Integer, uMsg As Integer, _
  28.                 wParam As Integer, lParam As Integer) As Integer
  29.   xSize = LoWord(lParam) / xSteps
  30.   ySize = HiWord(lParam) / ySteps
  31.   Result = 0
  32. End Function
  33.  
  34. Function OnPaint(hWnd As Integer, uMsg As Integer, _
  35.                 wParam As Integer, lParam As Integer) As Integer
  36.   Dim hdc As Integer
  37.   Dim PalIndex As Integer
  38.   Dim i As Integer
  39.   Dim j As Integer
  40.   Dim hPen As Integer
  41.   Dim hPenPrevious As Integer
  42.   Dim hBrush As Integer
  43.   Dim hBrushPrevious As Integer
  44.  
  45.   hdc = BeginPaint(hWnd, ps)
  46.   j = 0
  47.   while j < ySteps  
  48.     i = 0
  49.     while i < xSteps
  50.       PalIndex = j * xSteps + 0x01000000 + i
  51.       hPen = CreatePen(PS_SOLID, 1, PalIndex)
  52.       hPenPrevious = SelectObject(hdc, hPen)
  53.       hBrush = CreateSolidBrush(PalIndex)
  54.       hBrushPrevious = SelectObject(hdc, hBrush)
  55.       rct.left = i * xSize
  56.       rct.top = j * ySize
  57.       rct.right = (i + 1) * xSize - 1
  58.       rct.bottom = (j + 1) * ySize - 1
  59.       Rectangle(hdc, rct.left, rct.top, rct.right,rct.bottom)
  60.       DeleteObject(hPenPrevious)
  61.       DeleteObject(hBrushPrevious)
  62.       i = i + 1
  63.     Wend
  64.   j = j + 1
  65.   Wend
  66.   EndPaint(hWnd, ps)
  67.   Result = 0
  68. End Function
  69.  
  70. Function OnClose(hWnd As Integer, uMsg As Integer, _
  71.                  wParam As Integer, lParam As Integer) As Integer
  72.   If MessageBox(hWnd, "Exit application?", _
  73.                  strAppTitle, MB_YESNO + MB_ICONQUESTION) = IDYES Then
  74.     DestroyWindow(hWnd)
  75.     Result = 0
  76.   Else  
  77.     Result = 1
  78.   End If
  79. End Function
  80.    
  81. Function WindowProc(hWnd As Integer, uMsg As Integer, _
  82.                     wParam As Integer, lParam As Integer) As Integer
  83.   If uMsg = WM_SIZE Then
  84.     Result = OnSize(hWnd, uMsg, wParam, lParam)
  85.   ElseIf uMsg = WM_PAINT Then
  86.     Result = OnPaint(hWnd, uMsg, wParam, lParam)
  87.   ElseIf uMsg = WM_CLOSE Then
  88.     Result = OnClose(hWnd, uMsg, wParam, lParam)
  89.   ElseIf uMsg = WM_DESTROY Then
  90.     PostQuitMessage(0)
  91.     Result = 0
  92.   Else
  93.     Result = DefWindowProc(hWnd, uMsg, wParam, lParam)
  94.   End If
  95. End Function
  96.  
  97. '***
  98.  
  99. strAppTitle = "Color Blocks"
  100. strClassName = "KoolBClass"
  101.  
  102. hInst = GetModuleHandle(0)
  103. wcex.cbSize = SizeOf(WNDCLASSEX)
  104. wcex.style = CS_VREDRAW + CS_HREDRAW + CS_CLASSDC
  105. wcex.lpfnwndproc = CodePtr(WindowProc)
  106. wcex.cbClsExtra = 0
  107. wcex.cbWndExtra = 0
  108. wcex.hInstance = hInst
  109. wcex.hIcon = LoadIcon(hInst, MakeIntResource(IDI_COLORBLOCKS))
  110. wcex.hCursor = LoadCursor(0, MakeIntResource(IDC_ARROW))
  111. wcex.hbrBackground = GetStockObject(WHITE_BRUSH)
  112. wcex.lpszMenuName = ""
  113. wcex.lpszClassName = strClassName
  114. wcex.hIconSm = 0
  115.  
  116. If (RegisterClassEx(wcex)) = 0 Then
  117.   MessageBox(0, "RegisterClassEx failed.", strAppTitle, MB_OK)
  118.   ExitProcess(0)
  119. End If
  120.  
  121. hWindow = CreateWindowEx(WS_EX_APPWINDOW + WS_EX_WINDOWEDGE, _
  122.                          strClassName, strAppTitle, _
  123.                          WS_OVERLAPPEDWINDOW + WS_VISIBLE, _
  124.                          CW_USEDEFAULT, CW_USEDEFAULT, _
  125.                          583, 488, _
  126.                          0, 0, wcex.hInstance, 0)
  127. If hWindow = 0 Then
  128.   MessageBox(0, "CreateWindowEx failed.", strAppTitle, MB_OK)
  129.   ExitProcess(0)
  130. End If
  131.  
  132. While GetMessage(message, 0, 0, 0) > 0
  133.   TranslateMessage(message)
  134.   DispatchMessage(message)
  135. Wend
  136.  


C:\Chameleon\Examples\ColorBlocks>compile ColorBlocks.bas

C:\Chameleon\Examples\ColorBlocks>C:\Chameleon\Bin\Chameleon.exe "ColorBlocks.bas" C:\Chameleon\Inc\ Pause

          Welcome to Chameleon BASIC
Currently compiling "ColorBlocks.bas":
 - Compile time  ->  0.065000 seconds
 - Assemble time ->  0.272000 seconds
 - Linking time  ->  0.181000 seconds
   -------------------------------
 - Total time    ->  0.518000 seconds
Press any key to continue . . .
C:\Chameleon\Examples\ColorBlocks>ColorBlocks

C:\Chameleon\Examples\ColorBlocks>dir *.exe
 Volume in drive C has no label.
 Volume Serial Number is 1415-F200

 Directory of C:\Chameleon\Examples\ColorBlocks

11/18/2014  07:10 PM            26,624 ColorBlocks.exe
               1 File(s)         26,624 bytes
               0 Dir(s)  68,366,262,272 bytes free

C:\Chameleon\Examples\ColorBlocks>


The ASM source for ColoBlocks is attached in a zip.

.
Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 09:23:16 PM
Good News!

I recompiled the koolb.dll instead of using the pre-compiled version that came with the distribution and it worked with SB DYC.



.
Title: Re: Chameleon BASIC
Post by: JRS on November 18, 2014, 09:55:07 PM
I recompiled the Chameleon BASIC compiler with Visual Studio 2008. It removed the IIS support as it had been deprecated. I assume the the existing compiler was compiled with Visual Studio 6.


C:\sb22\koolb>C:\Chameleon\Bin\Chameleon.exe "koolb.bas" C:\Chameleon\Inc\

          Welcome to Chameleon BASIC
Currently compiling "koolb.bas":
 - Compile time  ->  0.030000 seconds
 - Assemble time ->  0.110000 seconds
 - Linking time  ->  0.080000 seconds
   -------------------------------
 - Total time    ->  0.220000 seconds
C:\sb22\koolb>scriba kbhello.sb
1
C:\sb22\koolb>


Maybe it's just me but the compiler seems a little faster with the recompile.

@Mike - Can you whip up a benchmark that would run in Chameleon BASIC, O2 and C?

.
Title: Re: Chameleon BASIC
Post by: JRS on November 19, 2014, 05:09:22 PM
Sure would be nice if a keyword list exist for Chameleon BASIC. The project hasn't been updated since last year this time.

I personally don't have any interest in this other than learning how a compiler/assembler/linker works. I'm not hearing much from Mike or anything from Charles so any further interest in this is at your own risk. Seems it would be a good project for the PowerBASIC folks to work on and improve.

Title: Re: Chameleon BASIC
Post by: JRS on November 19, 2014, 11:12:07 PM
Quote from: Mike
The smallest unoptimized and unpacked exes start at some 40KB

The colorblock example compiles to 26,624 bytes uncompressed. That's not bad for a Windows program with no runtime dependencies. (6,656 bytes compressed/optimize option On)

Code: [Select]
$Compress Off

Attached is the KoolB original project. At least it has docs.  :D

.
Title: Re: Chameleon BASIC
Post by: JRS on November 20, 2014, 09:10:03 AM
If I could get a conformation from Mike or Charles (or any other O2 forum member) that Chameleon BASIC is of any value, I would put resources behind it to help it along. I'm not a ASM programmer but always wanted to learn.

Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on November 20, 2014, 10:55:46 AM
John,

I have absolutely no time to have a closer look at this BASIC now. But since it targets Nasm that's a good assembler and it also works, it certainly has value at least as a learning material. Assembler is good to know for a language developer. In fact, I think one can't be a serious language developer without at least basic assembly knowledge. Look at Charles. :)

(Sorry, can't stay here any longer tonight. But I'll be keeping an eye on your progress. :) )
Title: Re: Chameleon BASIC
Post by: JRS on November 20, 2014, 11:18:13 AM
Thanks Mike!

That gives me enough to maybe throw some resources at it. I still have the old www.basic-compiler.com site (old BCX effort) for a forum and could create a Bitbucket repository to track any new development. Let me know when you have more time to look at this.

I'm thinking of calling this fork of the project BASM. There doesn't seems to be any reference to BASIC and ASM using this name.

@Charles - It would be great if you would provide your feedback and if it is a worth while project. What keeps my interest is this started as a tutorial and seems to have a fragmented following.
Title: Re: Chameleon BASIC
Post by: Charles Pegge on November 20, 2014, 02:38:33 PM
Hi John,

Have you found any gallery pics for this ChameleonBasic language. Visuals are often a good indicator as to whether a programming language is alive, or not.

I am still engaged on last weeks data-table project, which is proving to yield some very useful support functions for data processing.
Title: Re: Chameleon BASIC
Post by: JRS on November 20, 2014, 02:55:23 PM
The original KoolB project was well documented in tutorial form for the first round. (7 keywords) The author added functionality and documented it in the source. The  Chameleon project took it even further. (what we have today) That's all I know at this point.
Title: BASM
Post by: JRS on November 20, 2014, 08:20:08 PM
I setup the BASM (https://bitbucket.org/BASIC-Compiler/basm) Bitbucket repository which includes both KoolB (http://www.briancbecker.com/blog/projects/compiler-tutorial/) and Chameleon (http://sourceforge.net/projects/chameleonbasic/) projects for reference. Please use the issue tracking system to report problems or offer suggestions or code.

If this picks up momentum than I'll fire up the www.basic-compiler.com site with a SMF 2.0 forum.

I have gone as far as I can with this and it needs someone like Mike to steer.

.
Title: KoolB Linux
Post by: JRS on November 20, 2014, 09:50:00 PM
I tried to compile KoolB under Linux but get the following errors.


jrs@laptop:~/XP-xfer/KoolB 15.02/Source$ g++ KoolBmain.cpp -o bsam
In file included from KoolBmain.cpp:45:0:
Misc.h: In function ‘void Run(std::string)’:
Misc.h:42:22: error: ‘CLK_TCK’ was not declared in this scope
       if ((clock() / CLK_TCK) - StartTime > 120);
                      ^
Misc.h: At global scope:
Misc.h:48:3: error: ‘FileStart’ does not name a type
   FileStart = File.tellg();
   ^
Misc.h:49:3: error: ‘File’ does not name a type
   File.seekg(0, ios::end);
   ^
Misc.h:50:3: error: ‘FileEnd’ does not name a type
   FileEnd   = File.tellg();
   ^
Misc.h:51:3: error: ‘File’ does not name a type
   File.seekg(0, ios::beg);
   ^
Misc.h:54:3: error: expected unqualified-id before ‘if’
   if (FileEnd - FileStart > 0){
   ^
Misc.h:71:3: error: ‘File’ does not name a type
   File.close();
   ^
Misc.h:72:3: error: expected unqualified-id before ‘return’
   return;
   ^
Misc.h:73:1: error: expected declaration before ‘}’ token
 }
 ^
jrs@laptop:~/XP-xfer/KoolB 15.02/Source$


I also gave it a try compiling KoolB with MinGW using the supplied Makefile.win file.

E:\KoolB 15.02\Source>mingw32-make -B -f Makefile.win
g++.exe -c KoolBmain.cpp -o KoolBmain.o -I"C:/Programs/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Programs/Dev-Cpp/include/c++/3.
4.2/backward"  -I"C:/Programs/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Programs/Dev-Cpp/include/c++/3.4.2"  -I"C:/Programs/Dev-Cpp/
include"  -s
In file included from KoolBmain.cpp:45:0:
Misc.h:48:3: error: 'FileStart' does not name a type
   FileStart = File.tellg();
   ^
Misc.h:49:3: error: 'File' does not name a type
   File.seekg(0, ios::end);
   ^
Misc.h:50:3: error: 'FileEnd' does not name a type
   FileEnd   = File.tellg();
   ^
Misc.h:51:3: error: 'File' does not name a type
   File.seekg(0, ios::beg);
   ^
Misc.h:54:3: error: expected unqualified-id before 'if'
   if (FileEnd - FileStart > 0){
   ^
Misc.h:71:3: error: 'File' does not name a type
   File.close();
   ^
Misc.h:72:3: error: expected unqualified-id before 'return'
   return;
   ^
Misc.h:73:1: error: expected declaration before '}' token
 }
 ^
Makefile.win:30: recipe for target 'KoolBmain.o' failed
mingw32-make: *** [KoolBmain.o] Error 1

E:\KoolB 15.02\Source>

Title: Re: Chameleon BASIC
Post by: JRS on November 20, 2014, 11:20:41 PM
Here is a Petzold Sprial Chameleon example. I wonder how many of the Petzoil examples could be run in BASM? Could be a cool learning tool with BASIC, C++ and ASM all rolled into one.

@Mike or @Charles: Not that I have the time to do so but do you see any reason SB couldn't be used to build a like compiler?

Code: Visual Basic
  1. '**************
  2. '* Spiral.bas *
  3. '**************
  4.  
  5. ' Based on a Petzold example.
  6.  
  7. $AppType GUI
  8. $Optimize Off
  9. $Compress Off
  10.  
  11. $Include "Windows.inc"
  12. $Include "Math.inc"
  13.  
  14. $Const iNumRevs = 20
  15. $Const crAppleGreen = 0x0044AA00
  16. $Const PI = 3.14159
  17.  
  18. Dim message As MSG
  19. Dim wc As WNDCLASS
  20. Dim ps As PAINTSTRUCT
  21. Dim strClassName As String
  22. Dim strAppTitle As String
  23. Dim hWindow As Integer
  24. Dim cxClient As Integer
  25. Dim cyClient As Integer
  26.  
  27. Function OnSize(hWnd As Integer, uMsg As Integer, _
  28.                 wParam As Integer, lParam As Integer) As Integer
  29.   cxClient = LoWord(lparam)
  30.   cyClient = HiWord(lparam)
  31.   Result = 0
  32. End Function
  33.  
  34. Function OnPaint(hWnd As Integer, uMsg As Integer, _
  35.                 wParam As Integer, lParam As Integer) As Integer
  36.   Dim hdc As Integer
  37.   Dim iNumPoints As Integer
  38.   Dim ptX As Integer
  39.   Dim ptY As Integer    
  40.   Dim i As Integer
  41.   Dim fAngle As Double
  42.   Dim fScale As Double
  43.  
  44.   hdc = BeginPaint(hWnd, ps)
  45.   iNumPoints = iNumRevs * 2 * (cxClient + cyClient)
  46.   i = 0
  47.   While i < iNumPoints
  48.     fAngle = i * 2.0 * PI / (iNumPoints / iNumRevs)
  49.     fScale = 1.0 - i / iNumPoints
  50.     ptX = cxClient / 2.0 * (1.0 + fScale * Cos(fAngle))
  51.     ptY = cyClient / 2.0 * (1.0 + fScale * Sin(fAngle))
  52.     SetPixel(hdc, ptX, ptY, crAppleGreen)
  53.     i = i +1
  54.   Wend
  55.   EndPaint(hWnd, ps)
  56.   Result = 0
  57. End Function
  58.  
  59. Function WindowProc(hWnd As Integer, uMsg As Integer, _
  60.                     wParam As Integer, lParam As Integer) As Integer
  61.   If uMsg = WM_SIZE Then
  62.     Result = OnSize(hWnd, uMsg, wParam, lParam)
  63.   ElseIf uMsg = WM_PAINT Then
  64.     Result = OnPaint(hWnd, uMsg, wParam, lParam)
  65.   ElseIf uMsg = WM_DESTROY Then
  66.     PostQuitMessage(0)
  67.     Result = 0
  68.   Else
  69.     Result = DefWindowProc(hWnd, uMsg, wParam, lParam)
  70.   End If
  71. End Function
  72.  
  73. '***
  74.  
  75. strAppTitle = "Spiral"
  76. strClassName = "SpiralClass"
  77.  
  78. wc.style = CS_HREDRAW + CS_VREDRAW
  79. wc.lpfnWndProc = CodePtr(WindowProc)
  80. wc.cbClsExtra = 0
  81. wc.hInstance = GetModuleHandle(0)
  82. wc.hIcon = LoadIcon(0, MakeIntResource(IDI_APPLICATION))
  83. wc.hCursor = LoadCursor(0, MakeIntResource(IDC_ARROW))
  84. wc.hbrBackground = GetStockObject(WHITE_BRUSH)
  85. wc.lpszMenuName = ""
  86. wc.lpszClassName = strClassName
  87.  
  88. If (RegisterClass(wc)) = 0 Then
  89.   MessageBox(0, "RegisterClass failed.", strAppTitle, MB_OK)
  90.   ExitProcess(0)
  91. End If
  92.  
  93. hWindow = CreateWindowEx(0, strClassName, strAppTitle, _
  94.                          WS_OVERLAPPEDWINDOW, _
  95.                          165, 50, 380, 435, _
  96.                          0, 0, wc.hInstance, 0)
  97. If hWindow = 0 Then
  98.   MessageBox(0, "CreateWindowEx failed.", strAppTitle, MB_OK)
  99.   ExitProcess(0)
  100. End If
  101.  
  102. ShowWindow(hWindow, SW_SHOWNORMAL)
  103. UpdateWindow(hWindow)
  104.  
  105. While GetMessage(message, 0, 0, 0) > 0
  106.   TranslateMessage(message)
  107.   DispatchMessage(message)
  108. Wend
  109.  



.
Title: BASM Forum
Post by: JRS on November 21, 2014, 08:16:10 PM
If the BASM project sounds interesting and you would like to participate in the project, I have setup a forum.

BASIC-Compiler.com - BASM Forum (http://www.basic-compiler.com/forum)

Note: Registration is instant with an e-mail verification.
Title: BASM
Post by: JRS on November 23, 2014, 02:02:24 AM
I just release BASM Version 1.0  Build 1 that was built with MinGW32. Source and examples have been pushed to the Bitbucket repository.


C:\BASM\Bin>BASM

BASM - Version 1.0 Build 1
Usage: BASM <filename> [IncPath] [Pause]
Press any key to continue . . .


Update

For grins I thought I would try to compile BASM as a 64 bit Windows executable. That worked.  8) Next I tried to compile the Spiral example with the BASM64 compiler. That worked. (sorta) It created a 32 bit Windows executable with the 64 bit compiler.

Microsoft's latest Visual Studio 2013 is a 32 bit compiler that can create 32 or 64 bit executables. Does this translate to good news for BASM?  ???


jrs@laptop:~/BASM64$ ls -l
total 4148
-rw------- 1 jrs jrs 4220894 Nov 24 11:45 BASM.exe
-rw------- 1 jrs jrs   22528 Nov 24 11:57 Spiral.exe
jrs@laptop:~/BASM64$ file BASM.exe
BASM.exe: PE32+ executable (console) x86-64, for MS Windows
jrs@laptop:~/BASM64$ file Spiral.exe
Spiral.exe: PE32 executable (GUI) Intel 80386, for MS Windows
jrs@laptop:~/BASM64$

Title: Re: Chameleon BASIC
Post by: JRS on November 24, 2014, 08:40:20 PM
Brian C. Becker (KoolB Author)

(http://www.briancbecker.com/blog/wp-content/uploads/2009/08/becker_tulips-245x300.jpg)

Quote
I am a 5th Profile Pic year PhD student attending the Robotics Institute at Carnegie Mellon University. I work in the Surgical Mechatronics Lab under Cameron Riviere, but have a wide range of interests in medical robotics, computer vision, controls, and face recognition.
Title: Re: BASM IUP
Post by: JRS on November 25, 2014, 02:01:57 AM
Here is a quick Hello World! IUP example in BASM.

(http://www.basic-compiler.com/forum/screenshots/basm_iup.png)

Code: Text
  1. ' BASM IUP Hello World
  2.  
  3. $AppType GUI
  4.  
  5. DECLARE FUNCTION IupOpen LIB "iup.dll" ALIAS "IupOpen" (argc AS INTEGER, argv AS INTEGER) AS INTEGER
  6. DECLARE FUNCTION IupDialog LIB "iup.dll" ALIAS "IupDialog" () AS INTEGER
  7. DECLARE FUNCTION IupLabel LIB "iup.dll" ALIAS "IupLabel" (title AS STRING) AS INTEGER
  8. DECLARE FUNCTION IupAppend LIB "iup.dll" ALIAS "IupAppend" (ctl_to AS INTEGER, ctl_from AS INTEGER) AS INTEGER
  9. DECLARE FUNCTION IupShow LIB "iup.dll" ALIAS "IupShow" (ctl AS INTEGER) AS INTEGER
  10. DECLARE FUNCTION IupMainLoop LIB "iup.dll" ALIAS "IupMainLoop" () AS INTEGER
  11. DECLARE FUNCTION IupClose LIB "iup.dll" ALIAS "IupClose" () AS VOID
  12.  
  13. DIM win AS INTEGER
  14. DIM lbl AS INTEGER
  15.  
  16. IupOpen(0,0)
  17. win = IupDialog()
  18. lbl = IupLabel("Hello World!")
  19. IupAppend(win, lbl)
  20. IupShow(win)
  21. IupMainLoop()
  22. IupClose()
  23.  


C:\BASM\Examples\Iup>compile basm_iup.bas

C:\BASM\Examples\Iup>C:\BASM\Bin\BASM.exe "basm_iup.bas" C:\BASM\Inc\

BASM - Version 1.0 Build 1
Currently compiling "basm_iup.bas":
 - Compile time  ->  0.050000 seconds
 - Assemble time ->  0.180000 seconds
 - Linking time  ->  0.130000 seconds
   -------------------------------
 - Total time    ->  0.360000 seconds

C:\BASM\Examples\Iup>dir
 Volume in drive C has no label.
 Volume Serial Number is 1415-F200

 Directory of C:\BASM\Examples\Iup

11/25/2014  01:14 AM    <DIR>          .
11/25/2014  01:14 AM    <DIR>          ..
11/25/2014  01:14 AM            10,655 basm_iup.asm
11/25/2014  01:14 AM               819 basm_iup.bas
11/25/2014  01:14 AM             4,096 basm_iup.exe
11/25/2014  01:14 AM             8,209 basm_iup.obj
11/25/2014  01:14 AM                 2 basm_iup.rc
11/25/2014  01:14 AM                 0 results.txt
               6 File(s)         23,781 bytes
               2 Dir(s)  68,142,211,072 bytes free

C:\BASM\Examples\Iup>basm_iup
Title: BASM Linux
Post by: JRS on November 29, 2014, 01:16:52 AM
I thought I would share some good news on the BASM front. AIR (Armando) surfaced on the BP.org forum and I invited him to join us on the BASM forum. He said he wasn't interested in another Windows BASIC compiler but did say he was able to get Brian's KoolB to compile on his Mac. (with some work) I asked if he could send me what he had to try on Linux and AIR sent me his reworked 32 bit Linux source to try.

It compile fine on my 64 and 32 bit Ubuntu 14.02.1 versions but I'm still missing the linker and RC support. (guess until I hear from AIR)


jrs@laptop:~/BASM/koolb$ ./kool Example.bas

          Welcome to KoolB 15.01 by Brian C. Becker!

            Your open-source Linux BASIC compiler!

Currently compiling "Example.bas":
 - Compile time  ->  0.004786 seconds

jrs@laptop:~/BASM/koolb$ file kool
kool: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=b9aafa16cd153e6f16eef8cfb8d06e4b24a96694, not stripped
jrs@laptop:~/BASM/koolb$ ls -l kool
-rwxrwxr-x 1 jrs jrs 534895 Nov 28 22:47 kool
jrs@laptop:~/BASM/koolb$

Title: Re: BASM Linux
Post by: JRS on November 29, 2014, 10:22:27 AM
Got it working.


jrs@VB32:~/BASM/koolb$ cat whome.bas
PRINT "KoolB"


jrs@VB32:~/BASM/koolb$ ./kool whome.bas

          Welcome to KoolB 15.01 by Brian C. Becker!

            Your open-source Linux BASIC compiler!

Currently compiling "whome.bas":
 - Compile time  ->  0.001243 seconds
 - Assemble time ->  0.004015 seconds
 - Linking time  ->  0.001041 seconds
   -------------------------------
 - Total time    ->  0.007451 seconds
jrs@VB32:~/BASM/koolb$ ./whome
KoolB
jrs@VB32:~/BASM/koolb$ ls -l whome*
-rwxrwxr-x 1 jrs jrs 2068 Nov 29 10:01 whome
-rw-rw-r-- 1 jrs jrs 1366 Nov 29 10:01 whome.asm
-rw-rw-r-- 1 jrs jrs   16 Nov 29 00:15 whome.bas
-rw-rw-r-- 1 jrs jrs 1680 Nov 29 10:01 whome.o
-rw-rw-r-- 1 jrs jrs   51 Nov 29 10:01 whome.rc
jrs@VB32:~/BASM/koolb$


Update:

I installed support for 32 runtime & development on my Ubuntu 14.02.1 LTS 64 bit laptop.  BASM (KoolB) now compiles as a 64 bit application and the generated executables (32 bit) run on the 64 bit OS.


jrs@laptop:~/BASM/koolb$ ./kool whome.bas

          Welcome to KoolB 15.01 by Brian C. Becker!

            Your open-source Linux BASIC compiler!

Currently compiling "whome.bas":
 - Compile time  ->  0.000244 seconds
 - Assemble time ->  0.000477 seconds
 - Linking time  ->  0.000148 seconds
   -------------------------------
 - Total time    ->  0.000948 seconds
jrs@laptop:~/BASM/koolb$ ./whome
Koolb
jrs@laptop:~/BASM/koolb$ file kool
kool: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=fdbd995a552af76ab27bfe391cfe258ebbf60127, not stripped
jrs@laptop:~/BASM/koolb$ file whome
whome: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
jrs@laptop:~/BASM/koolb$ ls -l whome*
-rwxrwxr-x 1 jrs jrs 2068 Nov 29 17:37 whome
-rw-rw-r-- 1 jrs jrs 1366 Nov 29 17:37 whome.asm
-rw-rw-r-- 1 jrs jrs   15 Nov 29 00:05 whome.bas
-rw-rw-r-- 1 jrs jrs 1680 Nov 29 17:37 whome.o
-rw-rw-r-- 1 jrs jrs   51 Nov 29 17:37 whome.rc
jrs@laptop:~/BASM/koolb$

Title: Re: BASM Linux - DLL
Post by: JRS on December 01, 2014, 11:22:52 AM
Here is an example of creating a DLL (.so shared object) with the BASM-Linux 32 bit compiler and a test program to call it.

test.bas
Code: Text
  1. ' BASM-Linux test.so shared object example
  2.  
  3. $AppType DLL
  4.  
  5. Function Concat(S1 As string, S2 As String) As String
  6.   Result = S1 + S2
  7. End Function
  8.  
  9. Function Sqrt(Number As Double) As Double
  10.   Result = Number ^ (1/2)
  11. End Function
  12.  

TestDLL.bas
Code: Text
  1. ' TestDLL - calling functions in BASM-Linux created share object
  2.  
  3. $AppType Console
  4.  
  5. Declare Function ConCat Lib "./test.so" Alias "_CONCAT" (S1 As String, S2 As String) As String
  6. Declare Function Sqrt Lib "./test.so" Alias "_SQRT" (Number As Double) As Double
  7.  
  8. Print "Testing functions contained in test.so"
  9. Print ""
  10. Print "Concat(123, abc)   =>   "; Concat("123", "abc")
  11. Print "Sqrt(9)            =>   "; Sqrt(9)
  12.  

Output

jrs@VB32:~/BASM/linux/Examples/dll$ BASM test.bas

BASM Linux - Version 1.0 Build 1
Currently compiling "test.bas":
 - Compile time  ->  0.002524 seconds
 - Assemble time ->  0.003758 seconds
 - Linking time  ->  0.001053 seconds
   -------------------------------
 - Total time    ->  0.008471 seconds
jrs@VB32:~/BASM/linux/Examples/dll$ file test.so
test.so: ELF 32-bit LSB  shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped
jrs@VB32:~/BASM/linux/Examples/dll$ ls -l test.so
-rwxrwxr-x 1 jrs jrs 3875 Dec  1 10:31 test.so
jrs@VB32:~/BASM/linux/Examples/dll$ BASM TestDLL.bas

BASM Linux - Version 1.0 Build 1
Currently compiling "TestDLL.bas":
 - Compile time  ->  0.005107 seconds
 - Assemble time ->  0.007244 seconds
 - Linking time  ->  0.002439 seconds
   -------------------------------
 - Total time    ->  0.016106 seconds
jrs@VB32:~/BASM/linux/Examples/dll$ ls -l TestDLL
-rwxrwxr-x 1 jrs jrs 3524 Dec  1 10:32 TestDLL
jrs@VB32:~/BASM/linux/Examples/dll$ ./TestDLL
Testing functions contained in test.so

Concat(123, abc)   =>   123abc
Sqrt(9)            =>   3
jrs@VB32:~/BASM/linux/Examples/dll$
Title: O2 Abductions?
Post by: JRS on December 02, 2014, 01:01:49 PM
Did Charles and Mike get abducted by aliens?

Is O2 up in the air?  ::)
Title: BASM Windows
Post by: JRS on December 02, 2014, 09:13:29 PM
I've run into a problem on the Windows version of BASM when doing a callback to a function. Everything works until you press the button. (exception error) It works fine in the Linux version. We have no ASM level support for the Windows version and could use some help from the O2 team. I'm sure it's something simple.

Your support in helping the BASM project keeping it's Windows momentum going is important for that platform. The Linux side (understandable) has more interest. (AIR, vovchik and others)

Please get the current source from the BASM Bitbucket repository (https://bitbucket.org/BASIC-Compiler/basm).

Code: Text
  1.  
  2. ' BASM IUP Test Callback
  3.  
  4. $AppType Console
  5.  
  6. DECLARE FUNCTION IupOpen LIB "iup.dll" ALIAS "IupOpen" (argc AS INTEGER, argv AS INTEGER) AS INTEGER
  7. DECLARE FUNCTION IupDialog LIB "iup.dll" ALIAS "IupDialog" () AS INTEGER
  8. DECLARE FUNCTION IupButton LIB "iup.dll" ALIAS "IupButton" (title AS STRING, action AS STRING) AS INTEGER
  9. DECLARE FUNCTION IupAppend LIB "iup.dll" ALIAS "IupAppend" (ctl_to AS INTEGER, ctl_from AS INTEGER) AS INTEGER
  10. DECLARE FUNCTION IupSetCallback LIB "iup.dll" ALIAS "IupSetCallback" (ih AS INTEGER, cbtype AS STRING, FuncAddr AS INTEGER) AS INTEGER
  11. DECLARE FUNCTION IupShow LIB "iup.dll" ALIAS "IupShow" (ctl AS INTEGER) AS INTEGER
  12. DECLARE FUNCTION IupMainLoop LIB "iup.dll" ALIAS "IupMainLoop" () AS INTEGER
  13. DECLARE FUNCTION IupClose LIB "iup.dll" ALIAS "IupClose" () AS VOID
  14.  
  15. $CONST IUP_DEFAULT = -2
  16.  
  17. DIM win AS INTEGER
  18. DIM but AS INTEGER
  19.  
  20. ' FUNCTION ButtonPressed(ih AS INTEGER, button AS INTEGER, pressed AS INTEGER, x AS INTEGER, y AS INTEGER, status AS INTEGER) AS INTEGER
  21. FUNCTION ButtonPressed(ih AS INTEGER) AS INTEGER
  22. PRINT "Button Clicked"
  23. ' PRINT "button = "; button
  24. ' PRINT "pressed = "; pressed
  25. ' PRINT "x = "; x
  26. ' PRINT "y = "; y
  27. ' PRINT "status = ", status
  28. RESULT = IUP_DEFAULT
  29. END FUNCTION
  30.  
  31. IupOpen(0,0)
  32. win = IupDialog()
  33. but = IupButton("Press Me!", "")
  34. ' IupSetCallback(but, "BUTTON_CB", CALLBACK(ButtonPressed))
  35. IupSetCallback(but, "ACTION", CALLBACK(ButtonPressed))
  36. IupAppend(win, but)
  37. IupShow(win)
  38. IupMainLoop()
  39. IupClose()
  40.  
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 03, 2014, 05:21:30 AM
Hi John,

I'm afraid I'd rather not get involved with BASM at all. I consider this particular implementation of BASIC-to-Asm translator ineffectual. It is based off of double precision FPU storage and calc which leaves it, speed-wise, far behind any other competitive implementation, whether asm, or C, or C++, without any hope for major improvement simply because there's no easy way to optimise it except re-write it completely from scratch. The challenge to do so would be too much for me to get involved in.

Sorry to say that but that's how it is for me personally. Thanks for the invitation though.
Title: BASM
Post by: JRS on December 03, 2014, 08:08:32 AM
Thanks Mike for the feedback and good to hear you're okay. BASM is about learning ASM and building a compiler. There are already a glut of BASIC compilers on Windows so getting any help from this group isn't surprising. I don't see using floating point math as a negative aspect of the compiler. It makes it more typeless and easier to use. (unless casting is your thing) There is always O2 if a dose of pure speed is the only remedy. For me the only negative aspect of the compiler is it's 32 bit. I'm not knowledgeable enough to know what it's going to take to move it to 64 bit. NAsm seems to tout cross platform and 32/64 bit aware. I'm going to be putting my efforts into the Linux side as there are folks willing to help on that platform.

P.S. I was only asking for help to resolve the callback issue and not asking anyone for any long term commitments to the project.

Title: Re: Chameleon BASIC
Post by: Charles Pegge on December 04, 2014, 12:55:47 AM

Quote
Did Charles and Mike get abducted by aliens?

(http://thumbs.dreamstime.com/x/alien-abduction-9118176.jpg)
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 04, 2014, 05:55:07 AM
Was that a selfie, Charles? :D


@John:

Sorry but I can hardly analyse efficiently the sources where 32-bit code pointers are represented with double precision quantities and conditioned with a floor() call.
Title: Re: Chameleon BASIC
Post by: JRS on December 04, 2014, 09:43:54 AM
@Mike - Thanks for having a peek!

AIR has discovered a problem in the memory manager when one function calls another. (releases a string on exit and then again down the line) He says the ASM code is sloppy and a rats nest. The C++ translator is fine. He suggests that it should generate C/C++ rather than ASM. I wonder if substituting KoolB ASM with O2 ASM would give Charles a vehicle to get his compiler cross platform in a 32/64 bit way.


Title: BASM
Post by: JRS on December 04, 2014, 04:52:31 PM
The problem AIR was having on the Linux version works fine on the Windows version.

Code: Text
  1. FUNCTION Func2(s2 AS STRING) AS STRING
  2.   RESULT = s2 + "[Func2]"
  3. END FUNCTION
  4.  
  5. FUNCTION Func1(s1 AS STRING) AS STRING
  6.   s1 = s1 + "[Func1]"
  7.   RESULT = Func2(s1)
  8. END FUNCTION
  9.  
  10. PRINT Func1("[Main]")
  11.  

Windows

C:\BASM\test>C:\BASM\Bin\BASM.exe "testfunc.bas" C:\BASM\Inc\

BASM - Version 1.0 Build 1
Currently compiling "testfunc.bas":
 - Compile time  ->  0.008000 seconds
 - Assemble time ->  0.202000 seconds
 - Linking time  ->  0.126000 seconds
   -------------------------------
 - Total time    ->  0.336000 seconds

C:\BASM\test>testfunc
[Main][Func1][Func2]

C:\BASM\test>


Linux

jrs@laptop:~/BASM64/test$ BASM testfunc.bas

BASM Linux 64 (i386 output) - Version 1.0 Build 1
Currently compiling "testfunc.bas":
 - Compile time  ->  0.001088 seconds
 - Assemble time ->  0.000455 seconds
 - Linking time  ->  0.000230 seconds
   -------------------------------
 - Total time    ->  0.001882 seconds
jrs@laptop:~/BASM64/test$ ./testfunc
Segmentation fault (core dumped)
jrs@laptop:~/BASM64/test$
Title: BASM Linux
Post by: JRS on December 04, 2014, 07:23:43 PM
AIR in a second round was able to fix the problem. (with my example at least)

Quote
In Assembly.h at around line 2243, change the #IFDEF Linux part so it looks like this:

    //With Linux, we like to leave things for the calling process to deal with,
    //so we just do a simple LEAVE and RET
    #ifdef Linux
      Write.Line(Write.ToFunction, "LEAVE");
      Write.Line(Write.ToFunction, "RET");
    #endif

"LEAVE" resets the stack pointer, which was getting corrupted.


jrs@laptop:~/BASM64/test$ BASM testfunc.bas

BASM Linux 64 (i386 output) - Version 1.0 Build 1
Currently compiling "testfunc.bas":
 - Compile time  ->  0.001024 seconds
 - Assemble time ->  0.000626 seconds
 - Linking time  ->  0.000156 seconds
   -------------------------------
 - Total time    ->  0.001894 seconds
jrs@laptop:~/BASM64/test$ ./testfunc
[Main][Func1][Func2]
jrs@laptop:~/BASM64/test$


(http://lnkd.in/bgaVnbm)
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 05, 2014, 04:54:41 AM
Will you please post Assembly::EndCreateSubFunction()'s entire source, John? The function's existing common code that precedes the Windows/Linux fork you're talking about doesn't go well, asm-wise, with AIR's solution as it is described in your message. I just want to be sure we haven't overlooked anything before I start criticizing the solution proper. :)
Title: Re: BASM
Post by: JRS on December 05, 2014, 09:54:11 AM
Hi Mike!

Not sure what you're asking for. The current Linux BASM source is on Bitbucket if you want to have a peek. We are still trying to get our arms around what we have to work with. At this point the only open issue is Windows callbacks which works on Linux.

If you have any interest in helping / advising / contributing, please join the BASM forum.

I hope to be more helpful after finishing the KoolB tutorials Brian C. Becker did.
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 05, 2014, 09:32:25 PM
Hi John,

Thanks for the response. I am not interested in BASM. I was just curious how that particular remedy that you advertised here could possibly fix the sources, Linux or otherwise.

Since I see no constructive response to my simple request to post the problematic function's source code here that was formulated in a perfect English Sprache, I will just restrain myself to mentioning that the alleged solution makes no sense within the context of two common (i.e. effective for both Windows and Linux) asm instructions mov esp, ebp and pop ebp that precede immediately, as per Assembly.h dated December 2, 2014, the extra leave that AIR suggested. The resultant instruction sequence leads inevitably to stack underflow, which is as bad as the very bug you intended to cure.

Your quotation from AIR as it was presented earlier on December 4 (default forum date/time) alone cannot possibly cure the situation. It can only aggravate it. I would not recommend anyone to fix the sources as per your directions in the said post on this forum.
Title: BASM
Post by: JRS on December 05, 2014, 09:53:39 PM
I passed on your comments to AIR.

It makes it difficult to get momentum behind the BASM project when there is an offer of advice or direction but not interested enough to get involved. I'm trying my best to facilitate and advocate for the BASM project. Open source projects don't work if folks (community) don't get involved. I'm not asking or begging for anyone's help on this project. If it interests you fine. If not feel free to ignore my posts.

Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 05, 2014, 10:13:51 PM
Thanks for passing my feedback on.

Just one more question before I leave this thread. What is then the idea behind posting BASM specifics here rather than just indicating the general progress of the project that you are mentoring? It was the asm code that I reacted to. I would've just taken note of the developments had there been no questionable specifics that caught my eye.

Serves me right though.
Title: Re: BASM
Post by: JRS on December 05, 2014, 10:18:34 PM
Quote
What is then the idea behind posting BASM specifics here rather than just indicating the general progress of the project that you are mentoring facilitating?

I'm advocating for the project and trying to pick up talented programmers (open forum) looking for an interesting project to contribute to. It's the holiday season after all.

Title: Re: BASM
Post by: JRS on December 05, 2014, 10:24:22 PM
Quote from: AIR
You know he's actually 100% right.

The thing is, I'm not thinking about the Windows version.  I'm just playing around.  So viewed from the context he mentioned, I have to agree.

You should probably let him know that what I sent you at the time was part of a "work in progress".  Got to do things in stages, ya know? Come up with an intermediate by-the-seat-of-the-pants faux fix, and then work on overflow/underflow issues.  But you can't do that if you segfault every time you blink at the app!  LOL.

Mike's a good guy, I don't have any issues with what he said.  In fact, please let him know that I appreciate his comments and have nothing but the utmost respect for his coding skills and for him as well!

A.
Title: Re: Chameleon BASIC
Post by: Mike Lobanovsky on December 05, 2014, 10:30:20 PM
Whatever you say. It is an open forum and it is your server, after all.

And please give my best regards to AIR as well. I do respect him as a professional and I admire his cheerful attitude to things in life. :)

(http://www.therenegadeblog.com/wp-content/uploads/2011/05/hand-waving.jpg)
Title: Re: Chameleon BASIC
Post by: JRS on December 05, 2014, 10:54:49 PM
Quote
and it is your server

Actually it's Site Genie's server that I lease a VPS instance on.

I thought a language forum was about guys (no gals yet) with a common interest and sharing each others knowledge and contributing to a common cause that benefits everyone. (contributors or not) I think the problem is that there is too much ego and reading between the lines going on. It's childish and I running out of patience dealing with it. I don't know of anyone else that has put their free time and resource into multiple projects with only one goal and that is to keep BASIC alive. I have a consistent and successful track record with my efforts and you won't see me extending my hand out expecting freebies or ask for a free ride.

Hopefully someday you will get the fact that I'm not out to own BASIC and just a guy that believes in the concept of the language an trying to keep it simple.

Title: BASM
Post by: JRS on December 11, 2014, 04:01:54 PM
Just a quick update. We have CALLBACKs working on both Windows and Linux now. We picked up the masmBASIC author (Jochen) to help out with the Windows side. AIR is handling ASM development for the Linux/Mac version. The BaCon team (vovchik & Alex) are testing and integrating BASM with BaCon.

Join us if you wish.