Author Topic: Macro parameter issue  (Read 809 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Macro parameter issue
« on: February 12, 2021, 04:12:59 PM »

I am implementing some DDT statements, this in particular:

Code: [Select]
ARRAY SCAN INCLIBS(0) FOR (Comp.CurSystInc+1), = LibName, TO Index
When converted, PluriBASIC generates a macro called ?ArrayScanString and it is invoked like this:

Code: [Select]
?ArrayScanString(-16, inclibs, 0, (EXE.lng(@comp, 6393) + 1), null, null, null, null, =, libname, index, Err)
 I believe the syntax is correct, but at compilation Oxygen complains about this:

Code: [Select]
ERROR: ERROR: Undefined Symbol: @
WORD: 0
IN: add_systinc
LINE: 14902
FILE: "main source

 There are no @ symbols inside the macro, so, i am guessing the parameter (EXE.lng(@comp, 6393) + 1) is not being interpreted correctly.

 When removing the brackets, so that it gets genrated like this:

Code: [Select]
?ArrayScanString(-16, inclibs, 0, EXE.lng(@comp, 6393) + 1, null, null, null, null, =, libname, index, Err)
Oxygen says:

Code: [Select]
ERROR: ERROR: not defined
WORD: ?iend
IN: add_systinc
LINE: 14902
FILE: "main source

I suppose it refers to either of these lines inside the macro:
Code: [Select]
...
    int ?iEnd    = 0
    if istart = null then
        ?iStrt = a.lbound(1)
    else
        ?iStrt = istart
    end if
    if ifor = null then
        ?iEnd = a.ubound(1)
    else
        ?iEnd = ?iStrt + ifor
    end if   
    For ?index1 = ?iStrt to ?iEnd
        For ?index2 = ?iStrt to ?iEnd

...

Is the parameter being interpreted wrong?



Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #1 on: February 12, 2021, 04:36:36 PM »
 In this marco invocation:

Code: [Select]
?ArrayScanString(-16, rk, cns.c(listid), cne.c(listid), null, null, null, null, =, param, index, Err)
cns and cne are a class instances and c is a method in those class instances. listid is a parameter passed to the c method in the cne and cns classes, but Oxygen complains about this:

Code: [Select]
ERROR: ERROR: cannot use variable as constant
WORD: listid
IN: getdatatypeidbyname
LINE: 11051
FILE: "main source

Note that listid is not individually used inside the macro. I think it is not understanding that the macro parameter is composed of a class instance with a method and it's parameter. How can i fix this?


Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #2 on: February 12, 2021, 08:51:26 PM »
I believe the problem is that Oxygen works fine with this code:

Code: [Select]
#if typecodeof(null) = 0 ' Works fine.
 But is complaining at this exapanded code:

Code: [Select]
#if typecodeof((EXE.lng(@comp, 6393) + 1)) = 0 ' Compile error.
Code: [Select]
#if not match(((EXE.lng(@comp, 6393) + 1)), (null))  ' Compile error.
Code: [Select]
#if not match((cne.c(listid)), (null))  ' Compile error.
 Basically what i need is to know if one of the passed parameters is a literal null and not a literal 0 or a variable with a value of 0.


« Last Edit: February 12, 2021, 09:14:28 PM by Brian Alvarez »

JRS

  • Guest
Re: Macro parameter issue
« Reply #3 on: February 13, 2021, 06:18:59 AM »
Have you thought of using hex notation for your zero constants?

Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #4 on: February 13, 2021, 09:31:20 AM »
Have you thought of using hex notation for your zero constants?

 What do you mean?

Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #5 on: February 13, 2021, 10:43:19 AM »
This would be a perfect solution:

https://www.oxygenbasic.org/forum/index.php?topic=1280.msg12792#msg12792

 Was #ifexist deprecated?

 How about an #ifincluded?

 That way one could simply omit a parameter like this:

Code: [Select]
macro foo(a,b,c)
   #ifincluded a
   print "a included"
   #else
   print "a not included"
   #endif
   #ifincluded b
   print "b included"
   #else
   print "b not included"
   #endif
   #ifincluded c
   print "c included"
   #else
   print "c not included"
   #endif
end macro

foo(1, 2, 3)
foo(1,,3)
foo(1)


 

JRS

  • Guest
Re: Macro parameter issue
« Reply #6 on: February 13, 2021, 09:34:05 PM »
Have you thought of using hex notation for your zero constants?

 What do you mean?

If your scan string is in hex format, determining a zero from a null is easy.

Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #7 on: February 14, 2021, 01:18:01 PM »
 Oh, but that is not the problem. The problem is that ArrayScanString macro is supposed to take any parameter, and it is important to be able to tell if the parameter is a valid value (variable, literals, hex values, functions, ecuations etc) or a literal null parameter.

  A zero is also a valid parameter, that is why it is important to diferentiate it from a null parameter.

 I was previously including an extra parameter stating 0 if the parameter was not included and 1 if it was included, but im trying to get rid of that extra parameter by detrermining if the passed parameter is a literal null (or not included).

Charles Pegge

  • Guest
Re: Macro parameter issue
« Reply #8 on: February 16, 2021, 01:11:18 PM »
Hi Brian,

The match extended syntax is new.

I have just posted o2 version 0.3.0 in its current state, with all the tweaks we have discussed since 0.2.9 (April 2020).

https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenBasic030.zip

Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #9 on: February 16, 2021, 01:21:46 PM »

 Thanks Charles!! I will try it right away!  ;D ;D

Brian Alvarez

  • Guest
Re: Macro parameter issue
« Reply #10 on: February 17, 2021, 02:57:35 PM »

Amazing! match() works now. I can now continue with more implementations.

Thank you Charles! You are the best. :)