Any chance of CALL being implemented?

Attempting to use the CALL statement results in an Unsupported BASIC V/VI feature found error, but evidently it's not entirely absent because CALL with no parameters results in Syntax error and CALL "string" results in Type mismatch: number wanted. So some parsing of parameters, at least, is present in Brandy.

Presumably the reason CALL isn't fully implemented is that there's no assembler, and CALL is most commonly used to call an assembled routine. But it need not be used for that purpose, it could perfectly well be used to call a function compiled from C (for example in a DLL or other Shared Object) as an alternative to SYS.

Indeed in BBC BASIC for SDL 2.0 CALL is used in exactly that way to support sorting on those platforms which don't have a working assembler (e.g. iOS and Emscripten). The advantage of CALL over SYS is that the parameters are passed as both a pointer and a type; there's no way of discovering the parameter's type when using SYS.

If CALL was implemented in Matrix Brandy it would make it possible to support sorting in an elegant way, potentially even compatible with the existing sortlib libraries for BB4W, BBCSDL and BBCTTY.

Comments

  • Currently CALL is only implemented for calling the classic MOS routines, e.g. A%=0: CALL &FFF4 will perform a *FX0.

    Matrix Brandy already has the means to call routines from a shared library (though, largely untested in Windows), with SYS calls "Brandy_dlopen" and "Brandy_dlcall". These are listed in docs/sys-calls.txt.
  • Richard_Russell
    edited March 9
    Soruk wrote: »
    Matrix Brandy already has the means to call routines from a shared library (though, largely untested in Windows), with SYS calls "Brandy_dlopen" and "Brandy_dlcall"
    I said "The advantage of CALL over SYS is that the parameters are passed as both a pointer and a type; there's no way of discovering the parameter's type when using SYS".

    Are you suggesting that's not correct? Is there a way of using SYS such that the parameters' types can be discovered by the called routine, as well as their pointers? That would be great, and should allow a sorting library to be written, but it's not something I was aware of.
  • Soruk
    edited March 9
    Not saying that's incorrect, just that for CALL, the implementation is minimal, just enough to support calling the old MOS calls.

    It is something I could look at, using the address of a library routine obtained by SYS"Brandy_dlgetaddr".
  • Soruk wrote: »
    Not saying that's incorrect, just that for CALL, the implementation is minimal, just enough to support calling the old MOS calls.
    How does that differ from USR? The key thing about CALL which distinguishes it from USR is that it can take (a variable number of) parameters; is that aspect already implemented in Matrix Brandy? If it is, the extension I am hoping for ought to be straightforward.
Sign In or Register to comment.