pointer calls in BASIC

Questions about the BASICtools and MakeItC
Post Reply
AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

pointer calls in BASIC

Post by AMDlloydsp »

Bruce,
Is there any way to call subs or functions via pointer in BASIC?
I can get the pointers via ADDRESSOF, and store them, but can't figure out how to call them.

(Building a dispatch routine, table-driven)

Thanks,
Lloyd



AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: pointer calls in BASIC

Post by AMDlloydsp »

BTW...
I can do this as an interrupt sub using one of the timers to launch it. However, there are so many things I cannot do while inside an interrupt routine, that it's not the optimum way.

I was hoping more for some way to (maybe) push a return address on the stack, or do a direct call via pointer, etc.. that wouldn't put me inside the interrupt scope.

Also, the code example for INTERRUPT SUB in the docs is for the LPC11xx processor, and the enabling of the interrupt is wrong for the LPC17xx parts.
It reads:

VICIntEnable = VICIntEnable or (1<<19) 'Enable interrupt
when it must be:
VICIntEnable = VICIntEnable or (1<<2) 'Enable interrupt

Thanks,
Lloyd

basicchip
Posts: 1029
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: pointer calls in BASIC

Post by basicchip »

This is something we had in the ARM7 code emitter, but I just turned it on and see the linkage is wrong for the Thumb instruction, warning inside baseball comment -- ie. it actually calls correctly but tries to return to ARM mode with the present subroutine linkage

I'll take a few minutes this AM and see if I can fix it quickly, otherwise it may be a few days before I can do it

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: pointer calls in BASIC

Post by AMDlloydsp »

Thank you, Bruce!
That would be a terrific addition for fueling table-driven dispatch routines.

Lloyd

basicchip
Posts: 1029
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: pointer calls in BASIC

Post by basicchip »

This compiler enables call to an expression

Code: Select all

sub doit
print "we be here"
endsub
main:
print "here"
gosub (addressof doit)
print "we be back"

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: pointer calls in BASIC

Post by AMDlloydsp »

Wow! You're quick.

Thanks!

(oooo! Works NICE, too!)


Lloyd

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: pointer calls in BASIC

Post by AMDlloydsp »

Bruce,

The prior version of the beta complier you supplied on my request works fine, but for the ability to call by expression.

Including ab_math.bas with the new "call-by-expression" compiler 9.27g results in an error. I chopped out the paths in the example below, as containing proprietary customer info.

Thanks,

Lloyd
---
Here's the BASIC code:
------------------
#include "./LPC17xx.bas"
#include "./PULSE.bas"
#include "./STRING.bas"

' math #defs for the various function groups
' they must be defined prior to including ab_math.bas

'define include_factorial
'define include_hyper
'define include_rand
#define include_power_exp_log_sqrt
#define include_misc
#define include_trig
#define include_inverse_trig
#define include_misc ' include miscellaneous functions in math lib below

#include "./ab_math.bas"

main:
print "done with main"
--------------------------------

and here are the errors:

Analyzing ./Compiler-test.bas
Programming Flash 1756...

symm = _halfpi-symm
-ERROR ./ab_math.bas: 611: Expected End Of Line, found symm

basicchip
Posts: 1029
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: pointer calls in BASIC

Post by basicchip »

I added the case to my validation programs.

There were some other errors now flagged in the floating point test routines Tod wrote that tested his AB_Math.bas library. Those were specifically where an addressof (now always returning an integer) was being assigned to a single. Which now thanks to you the compiler flags.
ARMbasic.exe
version 9.27h ARMbasic compiler
(130.33 KiB) Downloaded 369 times

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: pointer calls in BASIC

Post by AMDlloydsp »

Not only does the 9.27h work for my trig/call-by-reference application, it picked up two instances of illegal casting of an integer to single.
Out of 1400 lines of code, I guess that's not too bad <G>, but obviously I was getting results other than what I expected.

Thanks a lot for that attention.

Lloyd

Post Reply