Beispiel #1
0
AutoloadHandler::Result AutoloadHandler::loadFromMap(const String& name,
                                                     const String& kind,
                                                     bool toLower,
                                                     const T &checkExists) {
  assert(!m_map.isNull());
  while (true) {
    const Variant& type_map = m_map.get()->get(kind);
    auto const typeMapCell = type_map.asCell();
    if (typeMapCell->m_type != KindOfArray) return Failure;
    String canonicalName = toLower ? f_strtolower(name) : name;
    const Variant& file = typeMapCell->m_data.parr->get(canonicalName);
    bool ok = false;
    if (file.isString()) {
      String fName = file.toCStrRef().get();
      if (fName.get()->data()[0] != '/') {
        if (!m_map_root.empty()) {
          fName = m_map_root + fName;
        }
      }
      try {
        JIT::VMRegAnchor _;
        bool initial;
        auto const ec = g_context.getNoCheck();
        Unit* u = ec->evalInclude(fName.get(), nullptr, &initial);
        if (u) {
          if (initial) {
            TypedValue retval;
            ec->invokeFunc(&retval, u->getMain(), init_null_variant,
                           nullptr, nullptr, nullptr, nullptr,
                           ExecutionContext::InvokePseudoMain);
            tvRefcountedDecRef(&retval);
          }
          ok = true;
        }
      } catch (...) {}
    }
    if (ok && checkExists(name)) {
      return Success;
    }
    const Variant& func = m_map.get()->get(s_failure);
    if (func.isNull()) return Failure;
    // can throw, otherwise
    //  - true means the map was updated. try again
    //  - false means we should stop applying autoloaders (only affects classes)
    //  - anything else means keep going
    Variant action = vm_call_user_func(func, make_packed_array(kind, name));
    auto const actionCell = action.asCell();
    if (actionCell->m_type == KindOfBoolean) {
      if (actionCell->m_data.num) continue;
      return StopAutoloading;
    }
    return ContinueAutoloading;
  }
}
Beispiel #2
0
void crUsbIo( xCoRoutineHandle xHandle, 
              unsigned portBASE_TYPE uxIndex )
{
    static uint8_t data;
    static portBASE_TYPE rcTo;
    static uint8_t state = STATE_CMD;
    static uint8_t size = 0;
    static uint8_t bufferIndex = 0;
    static uint32_t stateResetTimeout = 0;
    
    crSTART( xHandle );

    for ( ;; )
    {
        if ( !g_usbInitialized )
        {
            initUsbIo();
            // USB setup.
            Set_USBClock();
            USB_Interrupts_Config();
            USB_Init();

            g_usbInitialized = 1;
        }

        /*if ( !g_usbInitialized )
        {
            // Data for gpioEn.
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
   
            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 2;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Data for gpioConfig
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 2;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 255;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 255;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 0x48;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
   
            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 3;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Data for gpio.
            data = 0;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );

            // Call gpioConfig.
            data = 1;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
            data = 5;
            crQUEUE_SEND( xHandle, g_toMcu, &data, 0, &rcTo );
 
            g_usbInitialized = 1;
        }*/
        // Receive data from USB and place to an execution buffer.
        crQUEUE_RECEIVE( xHandle, g_toMcu, &data, 0, &rcTo );
        if ( rcTo == pdPASS )
        {
            // Analyze data and put it into execution buffer.
            switch ( state )
            {
                case STATE_CMD:
                    //setRed( 1 );
                    //setGreen( 0 );
                    // Reset timer.
                    stateResetTimeout = STATE_RESET_TIMEOUT;
                    if ( data == CMD_DATA )
                    {
                        state = STATE_SIZE;
                    }
                    else if ( data == CMD_FUNC )
                    {
                        state = STATE_FUNC;
                    }
                    break;
                case STATE_SIZE:
                    size = data;
                    state = STATE_DATA;
                    break;
                case STATE_DATA:
                    g_buffer[ bufferIndex++ ] = data;
                    size--;
                    if ( size == 0 )
                        state = STATE_CMD;
                    break;
                case STATE_FUNC:
                    //setRed( 0 );
                    //setGreen( 1 );
                    // Function invocation.
                    invokeFunc( data );
                    // And state back to STATE_CMD
                    state = STATE_CMD;
                    bufferIndex = 0;
                    break;
            }
        }
        else
        {
            if ( stateResetTimeout > 0 )
                stateResetTimeout--;
            else
            {
                state = STATE_CMD;
                bufferIndex = 0;
            }
        }
        crDELAY( xHandle, 1 );

        // Debugging.
        //static uint8_t a = 'a';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
        /*a = 'b';
        crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        if ( rcFrom == pdPASS )
            setRed( ( red() ) ? 0 : 1 );*/
        //a = '\r';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
        //a = '\n';
        //crQUEUE_SEND( xHandle, g_fromMcu, &a, 0, &rcFrom );
        //if ( rcFrom == pdPASS )
        //    setRed( ( red() ) ? 0 : 1 );
    
        /*taskENTER_CRITICAL();
        USB_Send_Data( 'a' );
        USB_Send_Data( '\r' );
        USB_Send_Data( '\n' );
        taskEXIT_CRITICAL();*/
        //crDELAY( xHandle, 20 );

    }

    crEND();
}