Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

BTMs can add/remove their own library functions!

May
13,009
174
Apparently, "LIBRARY /R /U" will quietly disregard anything that doesn't look like a library function definition. This lets BTMs load their own (self-contained) library functions (and unload them later). That's nice. Some simple testing suggests that library functions have a significant speed advantage over subroutines.
By example ...
Code:
v:\> type melib.btm
echo Current library functions ...
library /f
pause
echo.
echo Adding my library functions ... see ...
library /r /u %0
library /f
pause
echo.
echo Calling my library functions ...
melib1 foo bar
melib2 7 3
pause
echo.
echo Removing my library functions ... see ...
library /d melib1
library /d melib2
library /f
quit

melib1 {
        do i=1 to %#
                echo %[%i]
        enddo
}

melib2 {
        echo %@eval[%1 + %2]
}

Code:
v:\> melib.btm
Current library functions ...
TCC: V:\melib.btm [2]  No functions defined
Press any key when ready...

Adding my library functions ... see ...
melib1 {
        do i=1 to %#
                echo %[%i]
        enddo
}

melib2 {
        echo %@eval[%1 + %2]
}

Press any key when ready...

Calling my library functions ...
foo
bar
10
Press any key when ready...

Removing my library functions ... see ...
TCC: V:\melib.btm [18]  No functions defined
 
Well, that's awesome, and something that should be added to the HELP file.

I agree that library functions are faster.

Joe
 
Here's a little BTM that shows they are faster. With a library function, the time is reduced by ~32%, which means the speed is increased by ~46%. Those numbers would be less impressive if the subroutine/library function actually did something, but it's the overhead I want to test here.
Code:
v:\> type subvlib.btm
echo Using a subroutine ...
timer /q
do i=1 to 50000
        gosub nooper
enddo
timer

echo ^r^nUsing a library function ...
library /r /u %0 & rem load my library functions
timer /q
do i=1 to 50000
        nooper
enddo
timer

library /d nooper & rem delete my library functions
quit

nooper {
echos
}

:nooper
        echos
return

Code:
v:\> subvlib.btm
Using a subroutine ...
Timer 1 off: 13:11:00  Elapsed: 0:00:14.95

Using a library function ...
Timer 1 off: 13:11:10  Elapsed: 0:00:10.20
 
Here's a little BTM that shows they are faster.

You're preaching to the choir, brother!

LIBRARY is an excellent addition to TCC. I'm hoping that my suggestions for LIBRARY can be implemented.

Joe
 
It would be nice to have the delete equivalent of LIBRARY /R file. Maybe LIBRARY /D file could delete any functions defined in the file without having to specify the names of each.
 
It would be nice to have the delete equivalent of LIBRARY /R file. Maybe LIBRARY /D file could delete any functions defined in the file without having to specify the names of each.
Actually, "LIBRARY /D" does delete all functions. And wildcards work also. That's nice. Then a BTM can name the functions it loads carefully, and delete only those with wildcards in one fell swoop.
Code:
v:\> library /f
iprocessline {
do l in @con:
        set ip=%@word[".",0-3,%@word[2,%l]]
        echo %_month/%_day,%@word[".",0,%l]^t%ip^t%@word[".",4,%@word[" :",6,%l]]^t%@execstr[ipc %ip]
enddo
}

nooperation {
echos
}


v:\> library /d n*

v:\> library /f
iprocessline {
do l in @con:
        set ip=%@word[".",0-3,%@word[2,%l]]
        echo %_month/%_day,%@word[".",0,%l]^t%ip^t%@word[".",4,%@word[" :",6,%l]]^t%@execstr[ipc %ip]
enddo
}

v:\>
 
I was thinking of 'LIBRARY /D file' to delete just the functions defined in that file without having to know the specific names of them or for them to have a common (safe) prefix to delete them. In your prior example, you did a /R on the BTM, but you then had to specifically list those when deleting them or risk also deleting a global of the same name or prefix. If you could have done the load equivalent of /D %0, that would not have been necessary.
 
I was thinking of 'LIBRARY /D file' to delete just the functions defined in that file without having to know the specific names of them or for them to have a common (safe) prefix to delete them. In your prior example, you did a /R on the BTM, but you then had to specifically list those when deleting them or risk also deleting a global of the same name or prefix. If you could have done the load equivalent of /D %0, that would not have been necessary.

How about an UnLibrary command?

Joe
 
A Library equivalent for UnAlias /R file would work just fine for my needs whether that is a new command or extending the existing one to allow combining /D and /R. There is disconnect, though. Alias does not have a /D, thus requiring UnAlias. Library does have a /D, which would make an UnLibrary redundant with that. So long as I can delete the set specified in the file without naming them individually, either would work for me.
 
Back
Top