Announcement

Collapse
No announcement yet.

Variable Type Routies for ATmegaRFA1 devices

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variable Type Routies for ATmegaRFA1 devices

    I needed this for some debugging, but found that pythons type() built-in is not implemented, so I rolled my own. Some might find the following utilities handy in debugging, so I thought I'd contribute it here. You can either get the type code for a variable [as defined in the embedded C app note defines.h file] or test a var for a given type. The c code itself is not processor specific, so it can be re-compiled for other platforms, though some alteration may need to be done to adjust for different endianess of the various platforms. The compiled code attached is for the Atmel mega128rfa1 based devices.

    Here is the C code for the functions.
    Code:
    void getType(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_INT;
      stack[-8] = stack[-3] & TCM_TYPE;
      stack[-7] = 0;  
    }
    
    void isInt(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_BOOL;
      stack[-7] = 0;  
    }
    
    void isBool(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_BOOL;
      stack[-7] = 0;  
    }
    
    void isString(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_STRING;
      stack[-7] = 0;  
    }
    
    void isFunc(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE)] == TC_FUNC;
      stack[-7] = 0;  
    }
    
    void isCFunc(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_CFUNC;
      stack[-7] = 0;  
    }
    
    void isTuple(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_TUPLE;
      stack[-7] = 0;  
    }
    
    void isNone(U8 nArgs, U8 *stack, U8 *unused)
    {
      stack[-9] = TC_BOOL;
      stack[-8] = (stack[-3] & TCM_TYPE) == TC_NONE;
      stack[-7] = 0;  
    }
    Attached Files
    Last edited by glitch; 07-26-2012, 11:56 PM. Reason: Made the code more generic

  • #2
    Nice post. I like it. Thanks for sharing these information. Keep it up.
    Test king http://www.testking.us/
    Training 000-781 http://www.testking.us/000-781.htm
    Exams 350-018 http://www.testking.us/350-018.htm
    Material 640-722 http://www.testking.us/640-722.htm
    Exam material 646-364 http://www.testking.us/646-364.htm

    Comment

    Working...
    X