Beyond the Basics: Deep Slicing, FFI, and Multitasking
If January was about "Hacking" the Kindle, March has been about supercharging the engine under the hood of jdBasic. While IOTA and RESHAPE have been part of the language for a while, I've just unlocked a major milestone in array manipulation: Deep Sliced Assignment.
1. Deep Slicing & Array Assignments
I've overhauled the variable controller to support multi-dimensional slicing and cyclic assignments. You can now target specific layers of a 3D tensor or broadcast a scalar across an entire sub-array. This makes manipulating complex data structures significantly more intuitive.
' Create a 2x2x2 3D Array
C = RESHAPE(IOTA(8), [2,2,2])
' Broadcast a scalar to an entire 2D slice
C[0] = 99
' Assign a vector to a specific row within the matrix
C[1,0] = [42, 84]
PRINT "Updated 3D Tensor:"
PRINT C
2. The Win32 "Ghost Console" (FFI Magic)
The new Foreign Function Interface (FFI) allows jdBasic to talk directly to Windows DLLs like user32.dll. I wrote a "Ghost" demo that hooks its own Window Handle (HWND), uses SetLayeredWindowAttributes to turn the console transparent, and moves the physical window in an orbit using trigonometry.
3. Background Tasks with RECUR
One of the hardest things in an interpreter is non-blocking execution. The RECUR command allows a function to run at a fixed interval in the background. In my new world_clock.jdb, a background task updates a global clock at the top of the screen every 2 seconds without interrupting the main program flow.
' --- Time Ticker Background Task ---
FUNC DisplayWorldClock()
DIM baseTime = NOW()
DIM nyTime = DATEADD("H", -6, baseTime)
DIM oldX = GETX(): DIM oldY = GETY()
LOCATE 1, 1: COLOR 14, 0
PRINT "FRA: " + baseTime + " / NY: " + nyTime
COLOR 7, 0: LOCATE oldY, oldX
ENDFUNC
' Call every 2 seconds in the background
TickerID = RECUR(2000, "DisplayWorldClock")
4. Native UI Interaction
Using the DECLARE FUNC syntax, I can now trigger native Windows Message Boxes and control the system cursor. The dll_magic.jdb script teleports the mouse in a perfect circle using native Win32 calls—a fun stress test for the interpreter's call speed.
' Example of the new FFI syntax
DECLARE FUNC SetCursorPos LIB "user32.dll" (X AS INTEGER, Y AS INTEGER) AS INTEGER
What's Next?
With FFI and deep array slicing working, I'm getting closer to a truly "modern" BASIC experience. I’m working on more AI things next. Now, back to the compiler!