• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Conditional method definition

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 14061
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditional method definition

Curtisma
Curtisma over 6 years ago

I am trying to conditionally define a method by using a macro.  However, I keep getting an error with some variation of the body variable not getting expanded to the rest of the arguments.  I have tried using the ",@" and the "," operators along with no operator and using the apply function and none seem to work.  Any idea how to implement this or if it is possible? 

; Skips defining the current test if the current project does not match the
; project name specified
defmacro(utDefTest (@key project lib @rest body)
    prj = SkyPrj->newFromEnv(nil)
    prj = prj->Name
    if(!project || project && prj == project then
        'defmethod(,@body)

        ;'defmethod(,body)

        ;'defmethod(body)
        ;apply('defmethod ,@body)

    else

        warn("Test not defined: %s" car(body))
    )
)

Test Example:

utDefTest(test_macro ((testObj pkgTechTests)) let(()
    1+1
))

Error Example:

*Error* defmethod: too few arguments (at least 2 expected, 1 given) - (\@body)

Regards,

Curtis

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago

    Curtis,

    The issue is that the quote before defmethod should be a backquote not a normal quote. In other words `defmethod(,@body) not 'defmethod(,@body). If you use the normal quote, then nothing is evaluated within the following list; if you use backquote, the following list isn't evaluated unless it's preceded by comma or comma-at. The backquote character is essentially a macro itself which selectively evaluates.

    You should also make prj a local variable within the macro, as otherwise it's setting a global variable at macro expansion time:

    defmacro(utDefTest (@key project lib @rest body)
        let((prj)
            prj = SkyPrj->newFromEnv(nil)
            prj = prj->Name
            if(!project || project && prj == project then
                `defmethod(,@body)
            else
    
                warn("Test not defined: %s" car(body))
            )
        )
    )

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Curtisma
    Curtisma over 6 years ago in reply to Andrew Beckett

    That did it, thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information