SmartMath Plugin - Real-time Calculations in AkelPad

Discuss and announce AkelPad plugins
  • Author
  • Message
Offline
Posts: 67
Joined: Thu Feb 04, 2016 5:27 am

SmartMath Plugin - Real-time Calculations in AkelPad

Post by c-sanchez »

SmartMath Plugin - Real-time Calculations in AkelPad

Hello everyone!
I would like to share a new plugin I've developed for AkelPad called SmartMath.

Inspired by tools like Soulver or Numara, SmartMath turns AkelPad into a dynamic, real-time calculator. It allows you to perform calculations naturally in plain text and shows the results instantly on the screen without altering your actual file content.

Image
Image
Image

✨ Key Features
  • Real-Time Evaluation: Instantly evaluates math operations as you type.
  • Non-Invasive Rendering: Results are drawn directly onto the screen margin using Windows GDI. Your document remains 100% untouched.
  • Variables in Memory: Define custom variables and reference them in subsequent lines.
  • Smart Percentages: Intuitive handling of the '%' character (e.g., 500 + 21% automatically yields 605).
  • Advanced Formatting: Support for thousands separators and customizable precision (0 to 14 decimal places).
  • Aesthetic Customization: 6 different text colors available. It also seamlessly integrates with AkelPad's "Active Line" background highlight.
  • Native Architecture: Zero dependencies on external scripting engines. Compiles to highly optimized x86 and x64 native binaries.
💡 Example Usage
You can type the following in your editor, and the results will automatically float in the right margin:

Code: Select all

BasePrice = 1500
Shipping = 45.50

Subtotal = BasePrice + Shipping
Taxes = Subtotal * 21%

FinalPrice = Subtotal + Taxes
⚙️ Installation
  1. Download the compiled DLL (choose x86 or x64 depending on your AkelPad version).
  2. Place SmartMath.dll inside your

    Code: Select all

    AkelFiles\Plugs\
    directory.
  3. Restart AkelPad.
  4. Go to Options -> Plugins (or press Alt+P), find

    Code: Select all

    SmartMath::ToggleSmartMath
    , check it to enable it, and set it to Autoload if you wish.
📥 Downloads & Source Code
Download Latest Release
GitHub Repository (Source Code)

Any feedback, bug reports, or suggestions are highly appreciated!

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

What built-in functions are supported? E.g., trigonometric, logarithmic?
Are user-defined functions supported?
Ideally, it would be very cool to achieve functionality similar to https://speqmath.com/ (Well, maybe without plots, but with array operations similar to SpeQ).

Offline
Posts: 67
Joined: Thu Feb 04, 2016 5:27 am

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by c-sanchez »

Hello! Thank you for your interest and for the feedback.

Currently, SmartMath does not support built-in functions (like trigonometric or logarithmic), user-defined functions, or array operations.

For this initial release, I have strictly limited the scope to:
  • Basic mathematical operations (+, -, *, /)
  • Custom variable assignments
  • The percentage operator ('%')
The main goal was to keep the plugin as lightweight, fast, and simple as possible for quick, everyday calculations (like invoices, budgets, or simple logic) without turning it into a heavy math suite.

Achieving something like SpeQ Math is a fantastic idea, but it would require a completely different and much more complex parsing engine. However, since the plugin is fully open-source, the door is always open! If the community is interested, those advanced math features could be explored in future updates, or anyone is welcome to fork the repository and contribute. :D

Offline
Posts: 87
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by ewild »

c-sanchez
Nice calculator, thank you.

The SmartMath resembles me OpalCalc, which is my nearly daily tool, and is also inspired by tools like Soulver. So this is a great idea to have a similar tool built into the AkelPad interface!

I've been making my own JavaScript-based MathText in-text calculator (not publicly released in its current form), and it was the only calculator for AkelPad that could do the percentage operations right, like:
80+50% = 120
80-50% = 40
80*50% = 40
80/50% = 160
As I can see, SmartMath can do it too, as intended; that's great!

One of my dreams is to make my calculator do in-text math with powers, in simple syntax like 2^2 = 4, 25^0.5 = 5 (at least, I've been trying to implement such a function).
It would be great if SmartMath could do it too!

With variable support (currently) and with power math support (in the future, I hope), your calculator will be exceptionally good in the role!

Doing math without changing the original text is a great idea (my calculator can do it too, directing its output into the Log plugin panel), but your approach is better since it keeps expressions and results in-line.
However, in SmartMath, I can see no option to insert the answer into the text (at least via the copy-paste method) if I explicitly want to do so.

One question, please.
How to create the SmartMath menu as it is seen in the screenshots on GitHub and here in the topic?
I can see no such thing in my AkelPad.
However, beyond the SmartMath entry, your menu looks like a vanilla one, while I use ContextMenu.dll and ToolBar.dll plugins, and maybe that tracks.
Since I cannot reach the SmartMath menu, I also don't have SmartMath.ini.
It would be great to have a SmartMath::Settings call to reach the settings, as most of the other plugins do.
And of course, a way to set the SmartMath menu up manually wherever a user prefers (in the main menu, submenus, context menus, batton bars...).

Thank you for the plugin one more time!
And I wish you the best of luck!

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

c-sanchez wrote: Fri Apr 24, 2026 3:21 amAchieving something like SpeQ Math is a fantastic idea, but it would require a completely different and much more complex parsing engine.
However, since the plugin is fully open-source, the door is always open! If the community is interested, those advanced math features could be explored in future updates, or anyone is welcome to fork the repository and contribute. :D
Remember, it was you who suggested it! :)

You see, I don't really remember Basic and especially don't know FreeBasic which I've never learnt.
But!
Today we have a very nice AI-driven IDE named "Cursor".
So, I've opened your sources in Cursor IDE and asked to analyze the source code and then implement the following features:
1. support array-like parameters such as `a = (1, 2, 3); a*10`;
2. support parentheses such as `1 + 2*(3 + 4)`;
3. add trigonometric functions such as `sin`, `cos`, etc.
4. add logarithmic functions such as `log`, `exp`, etc.
5. add functions `sum`, `product`, `min` and `max` that accept variable number of arguments such as `sum(1,2,3)`;
6. add user-defined functions such as `f(x, y) = x*y`;
7. in case of syntax errors, report these errors to a user.

Here are the results so far:
https://github.com/d0vgan/AkelPad-Smart ... calculator

It is successfully compiled and seems to work.
I say "seems to work" because, as I mentioned, I don't really know FreeBasic, so there may be some flows or issues which I'm not aware of.

Even with these already amazing changes (just try them yourself!), it is still work-in-progress, because:
1) I would like to add support of input hex numbers in a form of `0x7FFF`;
2) I would like to add a function `hex` that will print the result as a hex number;
3) the error reporting needs to be carefully inspected and improved (basing on user's feedback);
4) more to go :)

I hope you like these changes!

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

One screenshot is better than a thousand words :)
Image

Offline
Posts: 67
Joined: Thu Feb 04, 2016 5:27 am

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by c-sanchez »

ewild wrote: Fri Apr 24, 2026 6:51 am Nice calculator, thank you.

The SmartMath resembles me OpalCalc, which is my nearly daily tool, and is also inspired by tools like Soulver. So this is a great idea to have a similar tool built into the AkelPad interface!
Cheers! I'm glad you like it :D
I liked OpalCalc, although I wanted something that didn't require .NET, Java, Python, etc. — something as purist/native to the system as possible.
At the time, I thought about making my own calculator, but after seeing that making a plugin was a viable option, I decided to go down this route. That way, we have all the features / plugins / scripts available in AkelPad :D
ewild wrote: Fri Apr 24, 2026 6:51 am I've been making my own JavaScript-based MathText in-text calculator (not publicly released in its current form), and it was the only calculator for AkelPad that could do the percentage operations right, like:
80+50% = 120
80-50% = 40
80*50% = 40
80/50% = 160
As I can see, SmartMath can do it too, as intended; that's great!
This is one of those things that, even though it's really "silly", I thought was essential to have :lol:
I'm glad to hear you like it too :D
ewild wrote: Fri Apr 24, 2026 6:51 am Doing math without changing the original text is a great idea (my calculator can do it too, directing its output into the Log plugin panel), but your approach is better since it keeps expressions and results in-line.
However, in SmartMath, I can see no option to insert the answer into the text (at least via the copy-paste method) if I explicitly want to do so.
This would actually be something really useful; I'd thought about adding a context menu for the results section, like "Copy Results" or "Copy Operation & Results", but I wanted to get the plugin finished already, sorry ;p
But maybe assigning an operation to a variable and using that would be enough?
ewild wrote: Fri Apr 24, 2026 6:51 am One question, please.
How to create the SmartMath menu as it is seen in the screenshots on GitHub and here in the topic?
I can see no such thing in my AkelPad.
However, beyond the SmartMath entry, your menu looks like a vanilla one, while I use ContextMenu.dll and ToolBar.dll plugins, and maybe that tracks.
Since I cannot reach the SmartMath menu, I also don't have SmartMath.ini.
It would be great to have a SmartMath::Settings call to reach the settings, as most of the other plugins do.
And of course, a way to set the SmartMath menu up manually wherever a user prefers (in the main menu, submenus, context menus, batton bars...).
That's weird, when you activate SmartMath, it doesn't show up in your AkelPad top menu?
Although that's another little thing I thought about at the end—that maybe the menu should be more "global"—but thinking about how the other plugins work and all that was something I didn't want to pursue, so I ended up leaving it with the native menu. Like I said, I just wanted to get the plugin finished already :lol:

Anyway, I think DV knows all those bits I missed much better, especially for improving the integration with AkelPad and other plugins, and he's been making incredible improvements in a very short time, so maybe he'll fix all the stuff I missed :)
DV wrote: Fri Apr 24, 2026 4:36 pm Remember, it was you who suggested it! :)
Haha, definitely! I'm really glad to see a fork making everything better :D
DV wrote: Fri Apr 24, 2026 4:36 pm You see, I don't really remember Basic and especially don't know FreeBasic which I've never learnt.
But!
Today we have a very nice AI-driven IDE named "Cursor".
So, I've opened your sources in Cursor IDE and asked to analyze the source code and then implement the following features:
1. support array-like parameters such as `a = (1, 2, 3); a*10`;
2. support parentheses such as `1 + 2*(3 + 4)`;
3. add trigonometric functions such as `sin`, `cos`, etc.
4. add logarithmic functions such as `log`, `exp`, etc.
5. add functions `sum`, `product`, `min` and `max` that accept variable number of arguments such as `sum(1,2,3)`;
6. add user-defined functions such as `f(x, y) = x*y`;
7. in case of syntax errors, report these errors to a user.
Wow, I'm surprised how many new things you've added in such a short time; it took me much longer to polish every little bit haha :shock:
To be honest, I admit I built the plugin using Gemini via AI Studio, so I'm fine with you using Cursor either way; in the end, all that matters is that we check everything's working as it should :)
The hardest part for me was getting the results on the right-hand side of the editor and fixing some rendering/syncing issues with the font size. After that, everything was much easier, so I'm glad to at least leave a useful foundation :)
DV wrote: Fri Apr 24, 2026 4:36 pm Here are the results so far:
https://github.com/d0vgan/AkelPad-Smart ... calculator
Brilliant! I'm going to enjoy trying it out later :D
DV wrote: Fri Apr 24, 2026 4:36 pm It is successfully compiled and seems to work.
I say "seems to work" because, as I mentioned, I don't really know FreeBasic, so there may be some flows or issues which I'm not aware of.

Even with these already amazing changes (just try them yourself!), it is still work-in-progress, because:
1) I would like to add support of input hex numbers in a form of `0x7FFF`;
2) I would like to add a function `hex` that will print the result as a hex number;
3) the error reporting needs to be carefully inspected and improved (basing on user's feedback);
4) more to go :)
To be honest, when I finished the plugin I was thinking something like "I like it, but this still can't quite replace the system calculator yet", for instance because of the lack of trigonometric and logarithmic functions, but with your changes that's completely different.
Support for hex numbers seems like another brilliant idea!
I'm excited to see what new features you'll be adding soon; could you include ewild's ideas as well?
DV wrote: Fri Apr 24, 2026 4:36 pm I hope you like these changes!
Absolutely! :mrgreen:

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

The progress so far:
Image

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »


Offline
Posts: 67
Joined: Thu Feb 04, 2016 5:27 am

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by c-sanchez »

Wow, you're really making the plugin "Smart" haha
Btw, feel free to modify the "About" window too, include all the new features and your name as lead developer :)
I was going to mention that it would be great to have comments, but you've already done it haha

I'm really happy with how the plugin has evolved and to see that you're enjoying it too.
Also, I'm glad I've managed to get another user for FreeBASIC hehe, I was planning to post the plugin on the FreeBASIC forum but I forgot, if you like you can join the forum as well :)

Offline
Posts: 87
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by ewild »

DV
In the original c-sanchez's version, when SmartMath meets a line like this

Code: Select all

5*5 = 25 
it does nothing, i.e., ignores a line that looks like a resolved 'expression = result', which is pretty reasonable.
However, in your fork, SmartMath would throw an '! unexpected token...' error wherever it sees an equal sign outside of the variable assignment expressions. The same occurs with a lot of other, to say of 'dual-purpose', symbols.
As I understand, this is related to the diagnostics in the description:
If you need to diagnose a crash or a problematic input line, you can enable per-line parser logging in SmartMath.ini.
SmartMath.ini ([Settings] section):
LogParsedLines=1
Notes:
LogParsedLines=0 disables this logging (default).
So I've made it manually to force the debugging off; however, it seems to have no effect.

Code: Select all

SmartMath.ini
[Settings]
LogParsedLines=1
Also, since my AkalPad is in the save-settings-in-the-registry mode, I put SmartMath settings in the registry as well (even though I'm not sure if SmartMath currently can use the in-registry settings at all), as the other plug-ins do it:

Code: Select all

[HKEY_CURRENT_USER\SOFTWARE\Akelsoft\AkelPad\Plugs\SmartMath]
"LogParsedLines"=dword:00000000
Then I switched AkelPad ini-registry settings back and forth to no avail.
So it looks like SmartMath's diagnostic mode is currently hardcoded to be always on and cannot be turned off in the settings.

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

ewild wrote: Sun Apr 26, 2026 8:43 am

Code: Select all

5*5 = 25 
What you see here is the error reported by the parser/evaluator.
Currently there are no comparison operators supported, so the presence of `=` is an occurrence of an unsupported operators.
If we want, we may add comparison operators such as `=`, `>=`, `<` etc. Do we really need them?

As for the "LogParsedLines" option, this one is really for troubleshooting. For example, when AkelPad crashes because of the parser.
With "LogParsedLines=1", each parsed line is sent to `OutputDebugString` which can be seen in DbgView from SysInternals.

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

Actually, since SmartMath is so powerful that it widely deals with array arguments, the comparison operations make sense.
They have been added together with the logical operators.
Yep, the power of AI-driven development :)
And don't think that the speed of the development means low quality. On the contrary, each change is covered by new smoke tests which are also written by AI :)

Offline
Posts: 87
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by ewild »

c-sanchez, DV
  1. All known AkelPad's plugins keep their configuration in INI with the only section named [Options] (QSearch.dll also has the secondary section [FindHistory], but still with the primary [Options] one).
    SmartMath.ini is the only plugin that uses [Settings] as the title section.
    Could you please change that so that SmartMath follows the best practice as the other plugins do and has [Options] as its INI title section.
  2. SmartMath does not respect AkelPad's option to keep configuration in the registry, so it does not read/write its configuration using the Registry, which may lead to conflicts in certain environments.
  3. I've figured out why I cannot see the SmartMath menu and get the INI in a designed way.
    As I mentioned earlier, I use the ContextMenu plugin (as most of the advanced AP users do, I believe).
    However, since AkelPad's native Main menu entries are not configurable, going a bit further, I replicated vanilla menu entries with my custom ones (with additions important for me), and applied the CLEAR entry to force vanilla entries not to show up, like this:

    Code: Select all

    # Main menu
    
    CLEAR
    "File" Menu("FILEMENU") Index(-1)
    "Edit" Menu("EDITMENU") Index(-1)
    "View" Menu("VIEWMENU") Index(-1)
    "Options" Menu("OPTIONSMENU") Index(-1)
    "Plugins" Menu("PLUGINS") Index(-1)
    "Scripts" Menu("SCRIPTS") Index(-1)
    "Language" Menu("LANGUAGE") Index(-1)
    "Custom" Menu("CUSTOM") Index(-1)
    "Window" Index(-1)
    {
    INCLUDE("WINDOWMENU")
    SEPARATOR
    "Select window..." Command(4327) # Select window...
    MDIDOCUMENTS
    }
    "Help" Menu("HELPMENU") Index(-1)


    This configuration is reflected and can be read in the Registry:

    Code: Select all

    [HKEY_CURRENT_USER\SOFTWARE\Akelsoft\AkelPad\Plugs\ContextMenu]
    "MainMenuText"=hex:...
    Or in AkelFiles\Plugs\ContextMenu.ini:

    Code: Select all

    [Options]
    MainMenuText=...
    I hope, in the ideal world, SmartMath could do it too and make something with that.
    At least, SmartMath could support SmartMath::Settings call, as other configurable plugins do, then there would be no need for its own menu at all.
  4. Compiling SmartMath from the sources, it turns out, it is natively impossible in FreeBASIC to get a digitally identical DLL twice from the digitally identical sources.
    It's just weird.
    Digging into that, it turns out it is caused by:

    Code: Select all

    IMAGE_FILE_HEADER: TimeDateStamp: at fixed offset 0x88 (4 bytes)
    IMAGE_OPTIONAL_HEADER: CheckSum: at fixed offset 0xd8 (4 bytes)
    IMAGE_EXPORT_DIRECTORY.TimeDateStamp: at volatile offset (0x12404 at the time of the tests) (4 bytes)
    So, essentially, this happens because FreeBASIC uses the current date-time as a timestamp upon compiling, not the timestamp of the sources.
    Hence, each time it runs, it updates the timestamps within the otherwise same DLL.
    In theory, this could be overridden by setting the SOURCE_DATE_EPOCH variable, but FreeBASIC ignores that.
    There are tools that can strip out that data from the DLL, like:
    https://github.com/jasonwhite/ducible/releases
    However, such an approach of stripping/zeroing data doesn't seem appropriate for me.

    So I made for myself a script in PowerShell that:
    • Compiles SmartMath.dll as usual.
    • Gets the timestamp after the latest file in the sources.
    • Patches SmartMath.dll using said timestamp from the sources for:
      IMAGE_FILE_HEADER:TimeDateStamp
      IMAGE_EXPORT_DIRECTORY.TimeDateStamp
    • Then recalculates and writes the proper checksum for:
      IMAGE_OPTIONAL_HEADER: CheckSum
    This grants whoever, wherever, and whenever compiles the DLL from the same sources, they will always get a digitally identical one, as it should be.
    Additionally, the script can update the AkelPad\AkelFiles\Plugs\SmartMath.dll if there were changes.
    I find it useful for myself for testing, because I can quickly switch between c-sanchez's/DV's developer builds and c-sanchez's release build.
    Maybe someone else finds it useful, too.
    Notes:
    • In its given edition, the script is intended to reside next to the 'AkelPad-Smart-Math-main' and 'AkelPad-Smart-Math-feature-powerful-calculator' folders, where the 'AkelPad-Smart-Math-main.zip' (c-sanchez's) and 'AkelPad-Smart-Math-feature-powerful-calculator.zip' (DV's) sources are unpacked.
    • Also, correct the FreeBASIC and AkelPad paths according to your actual environment.

    Code: Select all

    $time = [diagnostics.stopwatch]::StartNew()
    $env:Path += ";$env:ProgramFiles\FreeBASIC\bin"
    
    # source path
    $root = 'AkelPad-Smart-Math-main' # for c-sanchez's sources
    # $root = 'AkelPad-Smart-Math-feature-powerful-calculator' #  for DV's sources
    
    # get latest source file timestamp
    'defining latest source file...'|Write-Host -f Yellow
    $last = Get-ChildItem -path $root -file -recurse -force -exclude *.dll,*.a|sort LastWriteTime|select -Last 1
    $stamp = ([DateTimeOffset]$last.LastWriteTime).ToUnixTimeSeconds()
    'file       {0}' -f [IO.Path]::GetRelativePath($pwd,$last)
    'timestamp  {0}' -f $last.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
    'unix epoch {0}' -f $stamp
    $env:SOURCE_DATE_EPOCH = $stamp
    ''
    # compile DLL
    'compiling plugin DLL...'|Write-Host -f Yellow
    cd $root
    $dll = 'SmartMath.dll'
    $bas = 'SmartMath.bas','SmartMath_Config.bas','SmartMath_Format.bas','SmartMath_About.bas','SmartMath_Menu.bas','MathParser.bas'
    fbc -x $dll -dll -gen gcc -arch x86_64 $bas
    if($?) {'{0} has been built successfully!' -f $dll|Write-Host -f Green}
    ''
    # patch compiled library to normalize data that affects the resulting DLL hashsum drift
    'normalizing data that results in DLL hashsum drift...'|Write-Host -f Yellow
    
    $file = Get-ChildItem -file -recurse -force -filter $dll|sort LastWriteTime|select -Last 1
    
    # patch function
    function Patch-FreeBasicDll {
        param([string]$FilePath, [uint32]$UnixStamp)
    
        if (-not (Test-Path $FilePath)) { Write-Error "File not found"; return }
        $bytes = [IO.File]::ReadAllBytes($FilePath)
    
        # 1. Find PE Header
        $peOffset = [BitConverter]::ToInt32($bytes, 0x3C)
        $tsBytes = [BitConverter]::GetBytes($UnixStamp)
    
        # 2. Architecture Check & Field Offsets
        $magic = [BitConverter]::ToUInt16($bytes, $peOffset + 24)
        $is64 = $magic -eq 0x20b
        $checkSumOffset = $peOffset + 88
        $dataDirOffset = if ($is64) { $peOffset + 136 } else { $peOffset + 120 }
    
        # 3. Patch Timestamps (File Header and Export Directory)
        [Array]::Copy($tsBytes, 0, $bytes, ($peOffset + 8), 4)
    
        $exportRva = [BitConverter]::ToInt32($bytes, $dataDirOffset)
        if ($exportRva -gt 0) {
            $numSections = [BitConverter]::ToInt16($bytes, $peOffset + 6)
            $sectionTableOffset = $peOffset + 24 + [BitConverter]::ToInt16($bytes, $peOffset + 20)
            for ($i = 0; $i -lt $numSections; $i++) {
                $sec = $sectionTableOffset + ($i * 40)
                $vAddr = [BitConverter]::ToInt32($bytes, $sec + 12)
                if ($exportRva -ge $vAddr -and $exportRva -lt ($vAddr + [BitConverter]::ToInt32($bytes, $sec + 8))) {
                    $rawPtr = [BitConverter]::ToInt32($bytes, $sec + 20)
                    [Array]::Copy($tsBytes, 0, $bytes, ($exportRva - $vAddr + $rawPtr + 4), 4)
                    break
                }
            }
        }
    
        # 4. Recalculate checksum
        # 4.1 Zero out existing checksum for calculation
        [Array]::Clear($bytes, $checkSumOffset, 4)
    
        # 4.2 16-bit word summation with carry
        [uint64]$totalSum = 0
        for ($i = 0; $i -lt $bytes.Length; $i += 2) {
            if ($i + 1 -lt $bytes.Length) {
                $word = [BitConverter]::ToUInt16($bytes, $i)
            } else {
                $word = $bytes[$i] # Handle odd byte
            }
            $totalSum += $word
            # Fold 64-bit sum into 32-bit (handling carries)
            if ($totalSum -gt 0xFFFFFFFF) {
                $totalSum = ($totalSum -band 0xFFFFFFFF) + ($totalSum -shr 32)
            }
        }
    
        # 4.3 Final fold to 16-bit, then add file length
        while ($totalSum -shr 16) {
            $totalSum = ($totalSum -band 0xFFFF) + ($totalSum -shr 16)
        }
        [uint32]$finalChecksum = $totalSum + $bytes.Length
    
        # 5. Patch Calculated Checksum back into DLL
        $csBytes = [BitConverter]::GetBytes($finalChecksum)
        [Array]::Copy($csBytes, 0, $bytes, $checkSumOffset, 4)
    
        [IO.File]::WriteAllBytes($FilePath, $bytes)
        '{0} patched; corrected timestamps, recalculated checksum 0x{1}' -f $dll,$finalChecksum.ToString('X')|Write-Host -f Green
    }
    
    # applying patch
    Patch-FreeBasicDll -FilePath $file.FullName -UnixStamp $stamp
    ''
    # update plugin
    'update plugin in the AkelPad directory...'|Write-Host -f Yellow
    $app = "$env:ProgramFiles\AkelPad"
    $plugs = 'AkelFiles\Plugs'
    $plugin = [IO.Path]::combine($app,$plugs,$dll)
    if ($plugin|Test-Path){$hash = ($plugin|Get-FileHash).Hash}
    if ($hash -eq ($file|Get-FileHash).Hash){
    $sign=' = ';$color='green';$hue='cyan'} else {$sign=' ! ';$color='red';$hue='yellow'}
    copy $file $plugin -force
    [IO.Path]::GetRelativePath($app,$plugin)|Write-Host -f $hue -no;$sign|Write-Host -f $color -no
    [IO.Path]::GetRelativePath($PSScriptRoot,$file)|Write-Host -f $color -no
    if ($color -eq 'red'){' - updated!'|Write-Host -f Yellow}
    else {' - same version, no changes required'|Write-Host -f Yellow}
    ''
    # finalizing
    $time.Stop()
    '{0:mm\:ss\.fff} by {1}' -f $time.Elapsed,$MyInvocation.MyCommand.Name
    sleep -s 12
  5. DV wrote: Sun Apr 26, 2026 10:04 am What you see here is the error reported by the parser/evaluator.
    Dear DV
    Could you please be so kind as to make it configurable and add an option to turn the parser/evaluator's error output completely off.
    Sometimes opening a text file becomes a pain for the eyes with those overwhelming error messages.
    So when a user would need that parser info specifically, they could turn the errors output on, otherwise they could prefer leaving it off.

DV
Offline
Posts: 1331
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: SmartMath Plugin - Real-time Calculations in AkelPad

Post by DV »

At this point, I'm _very_ happy with the math parser itself, which works as described here:
https://github.com/d0vgan/AkelPad-Smart ... _SYNTAX.md

At some point, the AI-agent created a C++ port of the very same parser, and I'm about to add this port as part of this source code base when all the code optimizations and cleanup are done.
The C++ port exists in parallel and independently from the main implementation in Basic.

During the development, an "add-mathparser-function" skill for an AI-agent had been created and updated multiple times. Here it is:
https://github.com/d0vgan/AkelPad-Smart ... n/SKILL.md
Here is how to use this skill: whenever we want to add a new functionality to the parser, we literally type the following: "using the `add-mathparser-function` skill, implement new function/operator that ...".
Whenever new functionality is added, it is automatically mirrored to another langauge (e.g. from Basic to C++) and the tests are automatically enhanced and run by the `add-mathparser-function` skill.

Further actions:
1. Store the plugin's configuration either in Registry or in ini-file, depending on AkelPad's current setup. (can be done with the help of AI).
2. Create and apply a syntax theme by means of e.g. "smartmath.coder" to highlight comments. (most likely can be done with the help of AI)
3. Reduce the number of unnecessary GUI repaintings. (this must be done manually - AI fails to help here).

Questionable points:
1. Consider idea to limit SmartMath by the tab (editing window) where it was invoked to avoid seeing hundreds of errors in other AkelPad's tabs.
2. The math parser already treats `5*5 = 25` as comparison and returns `1` (`TRUE`) in this case, so I'm not sure what else to do there.
Post Reply