Deleted
Deleted Member
Posts: 0
|
BASM
Dec 3, 2014 0:47:17 GMT 1
Post by Deleted on Dec 3, 2014 0:47:17 GMT 1
Excellent!
Have you tried CALLBACKs yet?
Update This seems to be a Windows issue as it works fine on Linux.
WINDOWS ONLY
I'm getting GPF (Windows) when pressing the button.
' BASM IUP Test Callback
$AppType Console
DECLARE FUNCTION IupOpen LIB "iup.dll" ALIAS "IupOpen" (argc AS INTEGER, argv AS INTEGER) AS INTEGER DECLARE FUNCTION IupDialog LIB "iup.dll" ALIAS "IupDialog" () AS INTEGER DECLARE FUNCTION IupButton LIB "iup.dll" ALIAS "IupButton" (title AS STRING, action AS STRING) AS INTEGER DECLARE FUNCTION IupAppend LIB "iup.dll" ALIAS "IupAppend" (ctl_to AS INTEGER, ctl_from AS INTEGER) AS INTEGER DECLARE FUNCTION IupSetCallback LIB "iup.dll" ALIAS "IupSetCallback" (ih AS INTEGER, cbtype AS STRING, FuncAddr AS INTEGER) AS INTEGER DECLARE FUNCTION IupShow LIB "iup.dll" ALIAS "IupShow" (ctl AS INTEGER) AS INTEGER DECLARE FUNCTION IupMainLoop LIB "iup.dll" ALIAS "IupMainLoop" () AS INTEGER DECLARE FUNCTION IupClose LIB "iup.dll" ALIAS "IupClose" () AS VOID
$CONST IUP_DEFAULT = -2
DIM win AS INTEGER DIM but AS INTEGER
' FUNCTION ButtonPressed(ih AS INTEGER, button AS INTEGER, pressed AS INTEGER, x AS INTEGER, y AS INTEGER, status AS INTEGER) AS INTEGER FUNCTION ButtonPressed(ih AS INTEGER) AS INTEGER PRINT "Button Clicked" ' PRINT "button = "; button ' PRINT "pressed = "; pressed ' PRINT "x = "; x ' PRINT "y = "; y ' PRINT "status = ", status RESULT = IUP_DEFAULT END FUNCTION
IupOpen(0,0) win = IupDialog() but = IupButton("Press Me!", "") ' IupSetCallback(but, "BUTTON_CB", CALLBACK(ButtonPressed)) IupSetCallback(but, "ACTION", CALLBACK(ButtonPressed)) IupAppend(win, but) IupShow(win) IupMainLoop() IupClose()
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 3, 2014 3:58:02 GMT 1
Post by Deleted on Dec 3, 2014 3:58:02 GMT 1
I'm trying to get BASM Linux running on my 64 bit version of Ubuntu. I have the run/dev 32 bit libraries installed but I keep getting this error message. Is this telling me that the BASM created executables aren't compatible with the 32 bit emulation libraries?
BASM Linux - Version 1.0 Build 1 Currently compiling "who1.bas": - Compile time -> 0.003736 seconds - Assemble time -> 0.000481 seconds ld: i386 architecture of input file `who1.o' is incompatible with i386:x86-64 output - Linking time -> 0.000170 seconds ------------------------------- - Total time -> 0.004467 seconds
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 3, 2014 6:26:08 GMT 1
Post by Deleted on Dec 3, 2014 6:26:08 GMT 1
I'm wondering if AIR's JADE (C++ BASIC) string functions could be used with BASM?
DECLARE FUNCTION CSTRING LTRIM$ (CSTRING); DECLARE FUNCTION CSTRING RTRIM$ (CSTRING); DECLARE FUNCTION CSTRING TRIM$ (CSTRING); DECLARE FUNCTION CSTRING LEFT$ (CSTRING, INT); DECLARE FUNCTION CSTRING MID$ (CSTRING, INT, INT); DECLARE FUNCTION CSTRING RIGHT$ (CSTRING, INT); DECLARE FUNCTION INT INSTR (CSTRING,CSTRING,size_t=0); DECLARE FUNCTION CSTRING LCASE$ (CSTRING); DECLARE FUNCTION CSTRING UCASE$ (CSTRING); DECLARE FUNCTION CSTRING MCASE$ (CSTRING); DECLARE FUNCTION CSTRING LOADFILE$ (CSTRING); DECLARE FUNCTION CSTRING SPLITPATH$ (CSTRING, INT); DECLARE FUNCTION CSTRING ENC$ (CSTRING,INT=34,INT=34); DECLARE FUNCTION CSTRING REVERSE$ (CSTRING); DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace); DECLARE FUNCTION INT VAL (CSTRING); DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...); DECLARE FUNCTION VECTOR<CSTRING> SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty = TRUE); DECLARE SUB PRINT (CSTRING); DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname);
FUNCTION VECTOR<CSTRING> SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty) BEGIN DIM VECTOR<CSTRING> lst; DIM std::ostringstream word;
FOR (UINT n = 0 TO n < input.size() STEP n++) BEGIN IF (CSTRING::npos == separators.find(input[n])) THEN word << input[n]; ELSE IF (NOT word.str().empty() OR NOT remove_empty) lst.push_back(word.str()); word.str(""); ENDIF END IF (NOT word.str().empty() OR NOT remove_empty) lst.push_back(word.str());
RETURN lst; ENDFUNCTION
FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...) BEGIN DIM AS VECTOR<char> str(100,'\0'); DIM AS va_list ap; DIM AS INT n;
WHILE (TRUE) { va_start(ap, fmt); n = vsnprintf(str.data(), str.size(), fmt.c_str(), ap); va_end(ap); IF ((n > -1) AND (size_t(n) < str.size())) THEN RETURN str.data(); ENDIF IF (n > -1) THEN str.resize( n + 1 ); ELSE str.resize( str.size() * 2); ENDIF WEND
RETURN str.data(); ENDFUNCTION
FUNCTION CSTRING REVERSE$ (CSTRING src) BEGIN RETURN CSTRING( src.rbegin(),src.rend() ); ENDFUNCTION
SUB PRINT (CSTRING A="") BEGIN IF (A.empty()) THEN std::cout << std::endl; ELSE std::cout << A << std::endl; ENDIF ENDSUB
FUNCTION CSTRING LTRIM$ (CSTRING s) BEGIN s.erase(s.begin(),std::find_if(s.begin(),s.end(),std::not1(std::ptr_fun<INT,INT>(std::isspace)))); RETURN s; ENDFUNCTION
FUNCTION CSTRING RTRIM$ (CSTRING s) BEGIN s.erase(std::find_if(s.rbegin(),s.rend(),std::not1(std::ptr_fun<INT,INT>(std::isspace))).base(),s.end()); RETURN s; ENDFUNCTION
FUNCTION CSTRING TRIM$ (CSTRING s) BEGIN RETURN LTRIM$ (RTRIM$ (s)); ENDFUNCTION
FUNCTION CSTRING LEFT$ (CSTRING s, INT length) BEGIN RETURN s.substr(0,length); ENDFUNCTION
FUNCTION CSTRING MID$ (CSTRING s, INT start, INT length) BEGIN RETURN s.substr(start,length); ENDFUNCTION
FUNCTION CSTRING RIGHT$ (CSTRING s, INT length) BEGIN RETURN s.substr(s.size()-length); ENDFUNCTION
FUNCTION INT INSTR (CSTRING s,CSTRING match, size_t offset) BEGIN IF (s.empty() OR match.empty() OR offset>s.length()) THEN RETURN 0; ENDIF RETURN s.find(match,offset); ENDFUNCTION
FUNCTION CSTRING LCASE$ (CSTRING str) BEGIN DIM AS CSTRING name(str); std::transform(name.begin(),name.end(),name.begin(),::tolower); RETURN name; ENDFUNCTION
FUNCTION CSTRING UCASE$ (CSTRING str) BEGIN DIM AS CSTRING name(str); std::transform(name.begin(),name.end(),name.begin(),::toupper); RETURN name; ENDFUNCTION
FUNCTION CSTRING MCASE$ (CSTRING S) BEGIN DIM AS CSTRING tmpStr(S); DIM AS bool capFlag = FALSE; DIM AS register size_t i;
std::transform(tmpStr.begin(),tmpStr.end(),tmpStr.begin(),::tolower);
FOR (i=0 TO i<=tmpStr.length() STEP i++) BEGIN IF (std::ispunct(tmpStr[i]) OR std::isspace(tmpStr[i])) THEN capFlag=FALSE; ENDIF
IF (capFlag==FALSE AND std::isalpha(tmpStr[i])) THEN tmpStr[i]=std::toupper(tmpStr[i]); capFlag=TRUE; ENDIF END RETURN tmpStr; ENDFUNCTION
FUNCTION CSTRING LOADFILE$ (CSTRING N) BEGIN DIM AS CSTRING line, tmpStr; DIM AS std::ifstream myFile(N.c_str());
IF( NOT myFile.good()) BEGIN PRINT("Error opening file"); RETURN "ERROR"; ENDIF
WHILE ( NOT myFile.eof()) BEGIN getline(myFile,line); line+=LF; tmpStr+=line; WEND
myFile.close();
RETURN tmpStr;
ENDFUNCTION
SUB SAVEFILE (CSTRING src, CSTRING fname) BEGIN DIM AS std::ofstream outfile;
outfile.open(fname.c_str()); outfile << src; outfile.close();
ENDSUB
FUNCTION CSTRING SPLITPATH$ (CSTRING FPATH, INT mask) BEGIN DIM AS CSTRING fullPath(FPATH); DIM AS CSTRING path, filename, extension; DIM AS CSTRING::size_type lastSlashPos, extPos;
lastSlashPos=fullPath.find_last_of("/"); extPos=fullPath.find_last_of("."); IF (lastSlashPos==CSTRING::npos) THEN path.empty(); filename=fullPath; ELSE path=fullPath.substr(0,lastSlashPos); filename=fullPath.substr(lastSlashPos+1,(extPos-lastSlashPos)-1); ENDIF
IF (extPos==CSTRING::npos) THEN extension.empty(); ELSE extension=fullPath.substr(extPos+1,fullPath.size()-extPos-1); ENDIF
SELECT (mask) BEGIN CASE 4: RETURN path; ENDCASE
CASE 8: RETURN filename; ENDCASE
CASE 12: RETURN path.append("/").append(filename); ENDCASE
CASE 16: RETURN extension; ENDCASE
CASE_ELSE: RETURN "";
ENDSELECT
ENDFUNCTION
FUNCTION CSTRING ENC$ (CSTRING A, INT L, INT R) BEGIN DIM AS std::stringstream buf; buf<<(char)L<<A<<(char)R; RETURN buf.str(); ENDFUNCTION
FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace) BEGIN DIM AS size_t pos = 0;
WHILE( ( pos = subject.find(search, pos) ) != CSTRING::npos) BEGIN subject.replace(pos, search.length(), replace); pos += replace.length(); END RETURN subject; ENDFUNCTION
FUNCTION INT VAL (CSTRING str) BEGIN RETURN atoi(str.c_str()); ENDFUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 3, 2014 23:13:19 GMT 1
Post by Deleted on Dec 3, 2014 23:13:19 GMT 1
Good News!AIR sent me the fix I need to get my 64 bit compiled version of BASM for Liunx to work with my installed 32 bit support libraries. As icing, here is an example of creating a 32 bit test.so (2 BASM BASIC functions) and calling it with a 32 bit test program under Ubuntu 64. I'm working on getting 32 bit Gtk and IUP going on my Ubuntu 64 bit environment. ' Test DLL ' Example program for KoolB by Brian Becker
$AppType DLL $Optimize Off
Function Concat(S1 As string, S2 As String) As String Result = S1 + S2 End Function
Function Sqrt(Number As Double) As Double Result = Number ^ (1/2) End Function
' Test program for KoolB generated Test.dll ' KoolB example program by Brian Becker
$AppType Console
Declare Function ConCat Lib "./test.so" Alias "_CONCAT" (S1 As String, S1 As String) As String Declare Function Sqrt Lib "./test.so" Alias "_SQRT" (Number As Double) As Double
Print "Testing functions contained in Test.dll" Print "" Print "Concat(123, abc) => "; Concat("123", "abc") Print "Sqrt(9) => "; Sqrt(9)
jrs@laptop:~/BASM/koolb2/Source$ ./kool3 test.bas
Welcome to KoolB 15.01 by Brian C. Becker!
Your open-source Linux BASIC compiler!
Currently compiling "test.bas": - Compile time -> 0.000670 seconds - Assemble time -> 0.000539 seconds - Linking time -> 0.000204 seconds ------------------------------- - Total time -> 0.001513 seconds jrs@laptop:~/BASM/koolb2/Source$ file test.so test.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped jrs@laptop:~/BASM/koolb2/Source$ ./kool3 TestDLL.bas
Welcome to KoolB 15.01 by Brian C. Becker!
Your open-source Linux BASIC compiler!
Currently compiling "TestDLL.bas": - Compile time -> 0.001561 seconds - Assemble time -> 0.000759 seconds - Linking time -> 0.000217 seconds ------------------------------- - Total time -> 0.002649 seconds jrs@laptop:~/BASM/koolb2/Source$ ./TestDLL Testing functions contained in Test.dll
Concat(123, abc) => 123abc Sqrt(9) => 3 jrs@laptop:~/BASM/koolb2/Source$
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 4, 2014 6:09:29 GMT 1
Post by Deleted on Dec 4, 2014 6:09:29 GMT 1
I was able to get Gtk2:i386 and IUP working with the BASM 64 bit version of the compiler. (which currently generates 32 bit standalone binaries and shared objects .so) BASM is the Script BASIC of BASIC compilers. It tries to achieve a typeless/relaxed variable structure and is easy to use and intuitive like SB. ' BASM IUP Test Callback
$AppType Console
DECLARE FUNCTION IupOpen LIB "/usr/lib32/libiup.so" ALIAS "IupOpen" (argc AS INTEGER, argv AS INTEGER) AS INTEGER DECLARE FUNCTION IupDialog LIB "/usr/lib32/libiup.so" ALIAS "IupDialog" () AS INTEGER DECLARE FUNCTION IupButton LIB "/usr/lib32/libiup.so" ALIAS "IupButton" (title AS STRING, action AS STRING) AS INTEGER DECLARE FUNCTION IupAppend LIB "/usr/lib32/libiup.so" ALIAS "IupAppend" (ctl_to AS INTEGER, ctl_from AS INTEGER) AS INTEGER DECLARE FUNCTION IupSetCallback LIB "/usr/lib32/libiup.so" ALIAS "IupSetCallback" (ih AS INTEGER, cbtype AS STRING, FuncAddr AS INTEGER) AS iNTEGER DECLARE FUNCTION IupShow LIB "/usr/lib32/libiup.so" ALIAS "IupShow" (ctl AS INTEGER) AS INTEGER DECLARE FUNCTION IupMainLoop LIB "/usr/lib32/libiup.so" ALIAS "IupMainLoop" () AS INTEGER DECLARE FUNCTION IupClose LIB "/usr/lib32/libiup.so" ALIAS "IupClose" () AS VOID
$CONST IUP_DEFAULT = -2
DIM win AS INTEGER DIM but AS INTEGER
FUNCTION ButtonPressed(ih AS INTEGER, button AS INTEGER, pressed AS INTEGER, x AS INTEGER, y AS INTEGER, status AS STRING) AS INTEGER PRINT "button = "; button PRINT "pressed = "; pressed PRINT "x = "; x PRINT "y = "; y PRINT "status = ", status RESULT = IUP_DEFAULT END FUNCTION
IupOpen(0,0) win = IupDialog() but = IupButton("Press Me!", "") IupSetCallback(but, "BUTTON_CB", CALLBACK(ButtonPressed)) IupAppend(win, but) IupShow(win) IupMainLoop() IupClose()
Output jrs@laptop:~/BASM64/Examples/iup$ BASM basmiup32.bas
BASM Linux 64 (i386 output) - Version 1.0 Build 1 Currently compiling "basmiup32.bas": - Compile time -> 0.002542 seconds - Assemble time -> 0.000371 seconds - Linking time -> 0.000228 seconds ------------------------------- - Total time -> 0.003235 seconds jrs@laptop:~/BASM64/Examples/iup$ ./basmiup32 button = 49 pressed = 1 x = 61 y = 19 status = 1 button = 49 pressed = 0 x = 61 y = 19 status = 1 jrs@laptop:~/BASM64/Examples/iup$
|
|
|
BASM
Dec 4, 2014 9:57:35 GMT 1
Post by vovchik on Dec 4, 2014 9:57:35 GMT 1
Dear John,
Very nice. Since my iup libs are in a different place, 'LIB "libiup.so" ALIAS "IupOpen"' works for me. This is great progress. Thanks.
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 4, 2014 18:39:39 GMT 1
Post by Deleted on Dec 4, 2014 18:39:39 GMT 1
You 32 bit guys have it easy using BASM on Linux. My adventure has been using a 64 bit compiled version of BASM and using the i386 library sources on Ubuntu 14.02.1.LTS 64 bit. This use to be easy (12.04 <= ) but it seems this 32/64 Linux environment is losing steam. (deprecations, missing packages, ...) I just couldn't take the performance hit of running Ubuntu 32 bit in a VirtualBox. XP in a VirtualBox is a much better experience. vovchik - Are you working on a string management include? AIR may be working on something in this area. I'm glad you tried IUP.
|
|
|
BASM
Dec 4, 2014 21:02:04 GMT 1
Post by vovchik on Dec 4, 2014 21:02:04 GMT 1
Dear John, I am looking at strings but having some difficulty getting LEN to work as it should. It is, for any string stuff, a kind of 'sine qua non', and I am scratching my head because of errors I can't yet figure out. But I am working. At the moment I am trying to get this thing to work: DECLARE FUNCTION SETPROPERTY LIB "libiup.so" ALIAS "IupSetAttribute" _ (widget AS INTEGER, propname AS STRING, propval AS STRING) AS VOID
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 4, 2014 21:51:44 GMT 1
Post by Deleted on Dec 4, 2014 21:51:44 GMT 1
You need to use IupSetStrAttribute(). BTW: I don't think IupSetAttributes has this same issue. (only IupSetAttribute for some reason) ' BASM IUP Test Callback
$AppType Console
DECLARE FUNCTION IupOpen LIB "/usr/lib32/libiup.so" ALIAS "IupOpen" (argc AS INTEGER, argv AS INTEGER) AS INTEGER DECLARE FUNCTION IupDialog LIB "/usr/lib32/libiup.so" ALIAS "IupDialog" () AS INTEGER DECLARE FUNCTION IupButton LIB "/usr/lib32/libiup.so" ALIAS "IupButton" (title AS STRING, action AS STRING) AS INTEGER DECLARE FUNCTION IupSetStrAttribute LIB "/usr/lib32/libiup.so" ALIAS "IupSetStrAttribute" (ih AS INTEGER, propname AS STRING, propval AS STRING) AS VOID DECLARE FUNCTION IupAppend LIB "/usr/lib32/libiup.so" ALIAS "IupAppend" (ctl_to AS INTEGER, ctl_from AS INTEGER) AS INTEGER DECLARE FUNCTION IupSetCallback LIB "/usr/lib32/libiup.so" ALIAS "IupSetCallback" (ih AS INTEGER, cbtype AS STRING, FuncAddr AS INTEGER) AS iNTEGER DECLARE FUNCTION IupShow LIB "/usr/lib32/libiup.so" ALIAS "IupShow" (ctl AS INTEGER) AS INTEGER DECLARE FUNCTION IupMainLoop LIB "/usr/lib32/libiup.so" ALIAS "IupMainLoop" () AS INTEGER DECLARE FUNCTION IupClose LIB "/usr/lib32/libiup.so" ALIAS "IupClose" () AS VOID
$CONST IUP_DEFAULT = -2
DIM win AS INTEGER DIM but AS INTEGER
FUNCTION ButtonPressed(ih AS INTEGER, button AS INTEGER, pressed AS INTEGER, x AS INTEGER, y AS INTEGER, status AS STRING) AS INTEGER PRINT "button = "; button PRINT "pressed = "; pressed PRINT "x = "; x PRINT "y = "; y PRINT "status = ", status RESULT = IUP_DEFAULT END FUNCTION
IupOpen(0,0) win = IupDialog() IupSetStrAttribute(win,"TITLE","BASM IUP") but = IupButton("Press Me!", "") IupSetCallback(but, "BUTTON_CB", CALLBACK(ButtonPressed)) IupAppend(win, but) IupShow(win) IupMainLoop() IupClose()
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 5, 2014 1:07:02 GMT 1
Post by Deleted on Dec 5, 2014 1:07:02 GMT 1
AIR sent me an e-mail saying he discovered a nasty bug when one function calls another ending up with multiple cases of the memory manager trying to release the same string. He spent a lot of time tracking it down and came to the conclusion the ASM code is sloppy and a rats nest. The C++ translator is fine. He suggests that it be re-purposed to generate C/C++ instead of ASM. (these may be words of frustration before his second attempt) Personally I like the BASIC and the concept behind it. It seems like it would be a ashame to just let it die as a past high school project of a prodigy. UpdateThe problem AIR was having on the Linux version works fine on the Windows version. FUNCTION Func2(s2 AS STRING) AS STRING RESULT = s2 + "[Func2]" END FUNCTION
FUNCTION Func1(s1 AS STRING) AS STRING s1 = s1 + "[Func1]" RESULT = Func2(s1) END FUNCTION
PRINT Func1("[Main]")
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$
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 5, 2014 4:26:50 GMT 1
Post by Deleted on Dec 5, 2014 4:26:50 GMT 1
AIR in a second round was able to fix the problem. (with my example at least) 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$
Looks like we are back on the race track with Linux BASM.
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 6, 2014 0:55:28 GMT 1
Post by Deleted on Dec 6, 2014 0:55:28 GMT 1
AIR just sent me his string functions include / test he has be working on.
Update: There is a bug in MID$() where the fixed passed length value is changing internally in ASM. (AIR has been informed) I found it doing the (in BASM BASIC) INSTR() function.
' AIR - 2014-12-05 ' Testing updated implementation ' Of core String functions
$Apptype Console
Declare Function Len Lib "libc.so.6" Alias "strlen" (S As String) As Integer Declare Function strcpy Lib "libc.so.6" Alias "strcpy" (byref S1 As String, byval S2 As String) As String Declare Function ToLower Lib "libc.so.6" Alias "tolower" Call C (Char As Integer) As Integer
Function Asc(S As String) As Integer $Asm MOV EAX,dword[EBP+8] MOVSX EAX,byte[EAX] MOV dword[EBP-4],EAX $End Asm End Function
Function Chr$(ASCII As Integer) As String $Asm extern malloc ccall malloc, 2 MOV EBX,EAX MOV AH,byte[EBP+8] MOV byte[EBX],AH MOV byte[EBX+1],0 MOV dword[EBP-4],EBX $End ASM End Function
Function Mid$(S As String, Start As Integer, Length As Integer) As String If Start < 1 Then Start = 1 End If If Start + Length > LEN(S) Then Length = LEN(S) - Start - 1 End If Length = Length - 1 $Asm extern strlen extern strcpy extern strncpy extern calloc MOV EBX,dword[EBP+8] ;EBX = S MOV ESI,dword[EBP+12] ;ESI = Start MOV EDI,dword[EBP+16] ;EDI = Length DEC ESI ;Convert to zero-based ADD EBX,ESI ;Move Ptr to Start ADD ESI,EDI INC ESI ccall calloc,ESI,1 ;DEC ESI ;ADD EDI, 1 ccall strncpy,EAX,EBX,ESI MOV dword[EBP-4],EAX $End Asm End Function
Function LCase$(S As String) As String Result = "" Index& = 1 tmp$="" Length& = Len(S) While Index& <= Length& tmp$ = tmp$ + Chr$(ToLower(Asc(Mid$(S, Index&, 1)))) Index& = Index& + 1 WEnd Result = tmp$ End Function
Function Reverse$(S As String) As String Dim Length As Integer, Index As Integer Index = 1 Length = Len(S) While Index <= Length Result = Chr$(Asc(Mid$(S, Index, 1))) + Result Index = Index + 1 WEnd End Function
Function Left$(S As String, N As Integer) As String Result = Mid$(S, 1, N) End Function
Function LTrim$(S As String) As String Dim Length As Integer, Index As Integer, Found As Integer Index = 1 Length = Len(S) Found = 0 While Index < Length And Found = 0 If Mid$(S, Index, 1) <> " " Then Found = 1 End If Index = Index + 1 WEnd Index = Index - 1 'Counter act last increment Result = Mid$(S, Index, Len(S) - Index) End Function
Function l (in as string) As String '~ print "One" print Len(in) result = in end Function
Sub m (in as string) print "Two" print in+" AIR" End Sub
sub go(in as string) print l(in) m(in) end sub
dim A as integer go("Hello") print len(mid$("John Smith",1,4)) print len("Hello Two") print LCASE$("This Should be ALL LOWERCASE!") print ASC("A") print reverse$("Print this Backwards?") print CHR$(65) print LEFT$("One, Two, Three",3) print LTRIM$(" Strip")
jrs@laptop:~/BASM64/test$ BASM strfuncs.bas
BASM Linux 64 (i386 output) - Version 1.0 Build 1 Currently compiling "strfuncs.bas": - Compile time -> 0.011857 seconds - Assemble time -> 0.000545 seconds - Linking time -> 0.000162 seconds ------------------------------- - Total time -> 0.012653 seconds jrs@laptop:~/BASM64/test$ ./strfuncs 5 Hello Two Hello AIR 4 9 this should be all lowercase! 65 ?sdrawkcaB siht tnirP A One Strip jrs@laptop:~/BASM64/test$
|
|
|
BASM
Dec 6, 2014 10:33:00 GMT 1
Post by vovchik on Dec 6, 2014 10:33:00 GMT 1
Dear John, Nice that AIR did those string routines, although I get a segfault with MID$, CHR$ etc. ASC does nothing (it worked with the older basm - without the Assembly.h mod). I am wondering why it all works on your machine and not on mine... With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 6, 2014 10:52:33 GMT 1
Post by Deleted on Dec 6, 2014 10:52:33 GMT 1
I have updated the BASM Bitbucket site with a new branch. BASM-Linux64. This has all the current code I have been working with AIR with. It should compile fine as a 32 bit Linux executable. (ignore BASM Linux 64 in banner) Also note that this version looks for macros.inc (included) in your home directory with a path of .config/basm/macros.inc.
Let me know how it goes.
|
|
|
BASM
Dec 6, 2014 11:43:43 GMT 1
Post by vovchik on Dec 6, 2014 11:43:43 GMT 1
Dear John, Thanks. Works like a charm - and AIR's stuff for strings, too. With kind regards, vovchik
|
|