Esempio n. 1
0
File: hll.js Progetto: donaldh/nqp
op.bindhllsym = function(hllName, name, value) {
  if (!hllSyms.has(hllName)) {
    hllSyms.set(hllName, new Map());
  }
  hllSyms.get(hllName).set(name, value);
  return value;
};
Board.prototype.i2cConfig = function(options) {
  var delay;

  if (typeof options === "number") {
    delay = options;
  } else {
    if (typeof options === "object" && options !== null) {
      delay = options.delay;
    }
  }

  delay = delay || 0;

  i2cActive.set(this, true);

  i2cRequest(this,
    new Buffer([
      START_SYSEX,
      I2C_CONFIG,
      delay & 0xFF, (delay >> 8) & 0xFF,
      END_SYSEX
    ])
  );

  return this;
};
Esempio n. 3
0
/**
 * Groups by the VariableDeclarator/AssignmentExpression node that each
 * reference of given variables belongs to.
 * This is used to detect a mix of reassigned and never reassigned in a
 * destructuring.
 *
 * @param {escope.Variable[]} variables - Variables to group by destructuring.
 * @returns {Map<ASTNode, (escope.Reference|null)[]>} Grouped references.
 */
function groupByDestructuring(variables) {
    var writersMap = new Map();

    for (var i = 0; i < variables.length; ++i) {
        var variable = variables[i];
        var references = variable.references;
        var writer = getWriteReferenceIfShouldBeConst(variable);
        var prevId = null;

        for (var j = 0; j < references.length; ++j) {
            var reference = references[j];
            var id = reference.identifier;

            // Avoid counting a reference twice or more for default values of
            // destructuring.
            if (id === prevId) {
                continue;
            }
            prevId = id;

            // Add the writer into the destructuring group.
            var group = getDestructuringHost(reference);

            if (group) {
                if (writersMap.has(group)) {
                    writersMap.get(group).push(writer);
                } else {
                    writersMap.set(group, [writer]);
                }
            }
        }
    }

    return writersMap;
}
Esempio n. 4
0
    _getBound(fn) {
        if (map.has(fn)) {
            return map.get(fn);
        }

        return map.set(fn, this[fn].bind(this)).get(fn);
    }
Esempio n. 5
0
 log (double, call) {
   this.callHistory.push({double, call})
   if (this.calls.has(double)) {
     this.calls.get(double).push(call)
   } else {
     this.calls.set(double, [call])
   }
 }
Esempio n. 6
0
  static for(path, context) {
    let exportMap

    const cacheKey = hashObject(createHash('sha256'), {
      settings: context.settings,
      parserPath: context.parserPath,
      parserOptions: context.parserOptions,
      path,
    }).digest('hex')

    exportMap = exportCache.get(cacheKey)

    // return cached ignore
    if (exportMap === null) return null

    const stats = fs.statSync(path)
    if (exportMap != null) {
      // date equality check
      if (exportMap.mtime - stats.mtime === 0) {
        return exportMap
      }
      // future: check content equality?
    }

    // check valid extensions first
    if (!hasValidExtension(path, context)) {
      exportCache.set(cacheKey, null)
      return null
    }

    const content = fs.readFileSync(path, { encoding: 'utf8' })

    // check for and cache ignore
    if (isIgnored(path, context) && !hasExports.test(content)) {
      exportCache.set(cacheKey, null)
      return null
    }

    exportMap = ExportMap.parse(path, content, context)
    exportMap.mtime = stats.mtime

    exportCache.set(cacheKey, exportMap)
    return exportMap
  }
    'ImportDeclaration': function (n) {
      // resolved path will cover aliased duplicates
      let resolvedPath = resolve(n.source.value, context) || n.source.value

      if (imported.has(resolvedPath)) {
        imported.get(resolvedPath).add(n.source)
      } else {
        imported.set(resolvedPath, new Set([n.source]))
      }
    },
Esempio n. 8
0
  function addNamed(name, node) {
    let nodes = named.get(name)

    if (nodes == null) {
      nodes = new Set()
      named.set(name, nodes)
    }

    nodes.add(node)
  }
Esempio n. 9
0
 declaration.specifiers.forEach((specifier) => {
   switch (specifier.type) {
     case 'ImportNamespaceSpecifier':
       if (!imports.size) {
         context.report(specifier,
           `No exported names found in module '${declaration.source.value}'.`)
       }
       namespaces.set(specifier.local.name, imports)
       break
     case 'ImportDefaultSpecifier':
     case 'ImportSpecifier': {
       const meta = imports.get(
         // default to 'default' for default http://i.imgur.com/nj6qAWy.jpg
         specifier.imported ? specifier.imported.name : 'default')
       if (!meta || !meta.namespace) break
       namespaces.set(specifier.local.name, meta.namespace)
       break
     }
   }
 })
Esempio n. 10
0
function updateRegistryUrl(url, isNew) {
  var result = registryRequests.get(url);
  if (result) return result;
  result = getRegistry(url).then(function (result) {
    return put(url, JSON.stringify(result)).then(function () { return result; });
  });
  registryRequests.set(url, isNew ? result : true);
  setTimeout(function () {
    registryRequests.delete(url);
  }, 30000);
  return result;
}
Esempio n. 11
0
 constructor(config) {
   this.config = config;
   this.muted = false;
   this.error = true;
   this.uiSprite = new Howl({
     src: spriteConfig.urls,
     sprite: spriteConfig.sprite,
     onload: () => {
       console.log('loaded');
       this.error = false;
     },
   });
   const url = '/audio/loops/';
   this.loopSounds = new Map();
   this.loopSounds.set('bass', new Howl({
     loop: true,
     src: [
       `${url}loop1-bass.mp3`,
       `${url}loop1-bass.ogg`,
     ],
     onload: () => {
       this.loopSounds.get('bass').play();
     },
   }));
   this.loopSounds.set('bass-pad', new Howl({loop: true, src: [
     `${url}loop1-bass-pad.mp3`,
     `${url}loop1-bass-pad.ogg`,
   ]}));
   this.loopSounds.set('bass-pad-synth', new Howl({loop: true, src: [
     `${url}loop1-bass-pad-synth.mp3`,
     `${url}loop1-bass-pad-synth.ogg`,
   ]}));
   this.loopSounds.set('waiting', new Howl({loop: true, src: [
     `${url}waiting.mp3`,
     `${url}waiting.ogg`,
   ]}));
   if (localStorage.muted === 'true') {
     this.mute();
   }
 }
Esempio n. 12
0
 var meshes = objects.map(function(o){
     // Generate unique ids since the data producers may fail to do so
     var id;
     if(!ids.has(o.name)){
         id = o.name;
         ids.set(o.name, 1);
     }
     else{
         var nb = ids.get(o.name);
         id = o.name + '-' + nb;
         while(ids.has(id)){
             nb++;
             id = o.name + '-' + nb;
         }
         ids.set(o.name, nb+1);
     }   
     
     return {
         id: id,
         vertices: o.meshes.vertices,
         faces: o.meshes.faces
     };
     
 });
Esempio n. 13
0
 __resolve(ref) {
     var variable, name;
     name = ref.identifier.name;
     if (this.set.has(name)) {
         variable = this.set.get(name);
         variable.references.push(ref);
         variable.stack = variable.stack && ref.from.variableScope === this.variableScope;
         if (ref.tainted) {
             variable.tainted = true;
             this.taints.set(variable.name, true);
         }
         ref.resolved = variable;
         return true;
     }
     return false;
 }
Esempio n. 14
0
Board.prototype.i2cConfig = function(delay) {
  delay = delay || 0;

  i2cActive.set(this, true);

  i2cRequest(this,
    new Buffer([
      START_SYSEX,
      I2C_CONFIG,
      delay & 0xFF, (delay >> 8) & 0xFF,
      END_SYSEX
    ])
  );

  return this;
};
Esempio n. 15
0
function put(path, value) {
  inFlight.set(path, value);
  return Promise.resolve(value).then(function (value) {
    return new Promise(function (resolve, reject) {
      db.put(path, value, function (err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res);
        }
      });
    });
  }).then(function () {
    inFlight.delete(path);
    return value;
  }, function (err) {
    inFlight.delete(path);
    throw err;
  });
}
export default (styles, styleNames: Array<string>, errorWhenNotFound: boolean): string => {
    let appendClassName,
        stylesIndexMap;

    stylesIndexMap = stylesIndex.get(styles);

    if (stylesIndexMap) {
        const styleNameIndex = stylesIndexMap.get(styleNames);

        if (styleNameIndex) {
            return styleNameIndex;
        }
    } else {
        stylesIndexMap = stylesIndex.set(styles, new Map());
    }

    appendClassName = '';

    for (const styleName in styleNames) {
        if (styleNames.hasOwnProperty(styleName)) {
            const className = styles[styleNames[styleName]];

            if (className) {
                appendClassName += ' ' + className;
            } else if (errorWhenNotFound === true) {
                throw new Error('"' + styleNames[styleName] + '" CSS module is undefined.');
            }
        }
    }

    appendClassName = appendClassName.trim();

    stylesIndexMap.set(styleNames, appendClassName);

    return appendClassName;
};
Esempio n. 17
0
    ast.body.forEach(function (n) {

      if (n.type === 'ExportDefaultDeclaration') {
        const exportMeta = captureDoc(docStyleParsers, n)
        if (n.declaration.type === 'Identifier') {
          addNamespace(exportMeta, n.declaration)
        }
        m.namespace.set('default', exportMeta)
        return
      }

      if (n.type === 'ExportAllDeclaration') {
        let remoteMap = remotePath(n)
        if (remoteMap == null) return
        m.dependencies.set(remoteMap, () => ExportMap.for(remoteMap, context))
        return
      }

      // capture namespaces in case of later export
      if (n.type === 'ImportDeclaration') {
        let ns
        if (n.specifiers.some(s => s.type === 'ImportNamespaceSpecifier' && (ns = s))) {
          namespaces.set(ns.local.name, n)
        }
        return
      }

      if (n.type === 'ExportNamedDeclaration'){
        // capture declaration
        if (n.declaration != null) {
          switch (n.declaration.type) {
            case 'FunctionDeclaration':
            case 'ClassDeclaration':
            case 'TypeAlias': // flowtype with babel-eslint parser
              m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n))
              break
            case 'VariableDeclaration':
              n.declaration.declarations.forEach((d) =>
                recursivePatternCapture(d.id, id =>
                  m.namespace.set(id.name, captureDoc(docStyleParsers, d, n))))
              break
          }
        }

        n.specifiers.forEach((s) => {
          const exportMeta = {}
          let local

          switch (s.type) {
            case 'ExportDefaultSpecifier':
              if (!n.source) return
              local = 'default'
              break
            case 'ExportNamespaceSpecifier':
              m.namespace.set(s.exported.name, Object.defineProperty(exportMeta, 'namespace', {
                get() { return resolveImport(n) },
              }))
              return
            case 'ExportSpecifier':
              if (!n.source) {
                m.namespace.set(s.exported.name, addNamespace(exportMeta, s.local))
                return
              }
              // else falls through
            default:
              local = s.local.name
              break
          }

          // todo: JSDoc
          m.reexports.set(s.exported.name, { local, getImport: () => resolveImport(n) })
        })
      }
    })
function cachePath(cacheKey, result) {
  fileExistsCache.set(cacheKey, { result, lastSeen: Date.now() })
}
Esempio n. 19
0
var Board = function(port, options, callback) {
  Emitter.call(this);

  if (typeof options === "function" || typeof options === "undefined") {
    callback = options;
    options = {};
  }

  var board = this;
  var defaults = {
    reportVersionTimeout: 5000,
    samplingInterval: 19,
    serialport: {
      baudRate: 57600,
      bufferSize: 1
    }
  };

  var settings = assign({}, defaults, options);

  this.isReady = false;

  this.MODES = {
    INPUT: 0x00,
    OUTPUT: 0x01,
    ANALOG: 0x02,
    PWM: 0x03,
    SERVO: 0x04,
    SHIFT: 0x05,
    I2C: 0x06,
    ONEWIRE: 0x07,
    STEPPER: 0x08,
    IGNORE: 0x7F,
    UNKOWN: 0x10
  };

  this.I2C_MODES = {
    WRITE: 0x00,
    READ: 1,
    CONTINUOUS_READ: 2,
    STOP_READING: 3
  };

  this.STEPPER = {
    TYPE: {
      DRIVER: 1,
      TWO_WIRE: 2,
      FOUR_WIRE: 4
    },
    RUNSTATE: {
      STOP: 0,
      ACCEL: 1,
      DECEL: 2,
      RUN: 3
    },
    DIRECTION: {
      CCW: 0,
      CW: 1
    }
  };

  this.HIGH = 1;
  this.LOW = 0;
  this.pins = [];
  this.analogPins = [];
  this.version = {};
  this.firmware = {};
  this.currentBuffer = [];
  this.versionReceived = false;
  this.name = "Firmata";
  this.settings = settings;

  if (typeof port === "object") {
    this.transport = port;
  } else {
    this.transport = new SerialPort(port, settings.serialport);
  }

  // For backward compat
  this.sp = this.transport;

  this.transport.on("open", function() {
    this.emit("connect");
  }.bind(this));

  this.transport.on("error", function(string) {
    if (typeof callback === "function") {
      callback(string);
    }
  });

  this.transport.on("data", function(data) {
    var byt, cmd;

    if (!this.versionReceived && data[0] !== REPORT_VERSION) {
      return;
    } else {
      this.versionReceived = true;
    }

    for (var i = 0; i < data.length; i++) {
      byt = data[i];
      // we dont want to push 0 as the first byte on our buffer
      if (this.currentBuffer.length === 0 && byt === 0) {
        continue;
      } else {
        this.currentBuffer.push(byt);

        // [START_SYSEX, ... END_SYSEX]
        if (this.currentBuffer[0] === START_SYSEX &&
          SYSEX_RESPONSE[this.currentBuffer[1]] &&
          this.currentBuffer[this.currentBuffer.length - 1] === END_SYSEX) {

          SYSEX_RESPONSE[this.currentBuffer[1]](this);
          this.currentBuffer.length = 0;
        } else if (this.currentBuffer[0] !== START_SYSEX) {
          // Check if data gets out of sync: first byte in buffer
          // must be a valid command if not START_SYSEX
          // Identify command on first byte
          cmd = this.currentBuffer[0] < 240 ? this.currentBuffer[0] & 0xF0 : this.currentBuffer[0];

          // Check if it is not a valid command
          if (cmd !== REPORT_VERSION && cmd !== ANALOG_MESSAGE && cmd !== DIGITAL_MESSAGE) {
            // console.log("OUT OF SYNC - CMD: "+cmd);
            // Clean buffer
            this.currentBuffer.length = 0;
          }
        }

        // There are 3 bytes in the buffer and the first is not START_SYSEX:
        // Might have a MIDI Command
        if (this.currentBuffer.length === 3 && this.currentBuffer[0] !== START_SYSEX) {
          //commands under 0xF0 we have a multi byte command
          if (this.currentBuffer[0] < 240) {
            cmd = this.currentBuffer[0] & 0xF0;
          } else {
            cmd = this.currentBuffer[0];
          }

          if (MIDI_RESPONSE[cmd]) {
            MIDI_RESPONSE[cmd](this);
            this.currentBuffer.length = 0;
          } else {
            // A bad serial read must have happened.
            // Reseting the buffer will allow recovery.
            this.currentBuffer.length = 0;
          }
        }
      }
    }
  }.bind(this));

  // if we have not received the version within the alotted
  // time specified by the reportVersionTimeout (user or default),
  // then send an explicit request for it.
  this.reportVersionTimeoutId = setTimeout(function() {
    if (this.versionReceived === false) {
      this.reportVersion(function() {});
      this.queryFirmware(function() {});
    }
  }.bind(this), settings.reportVersionTimeout);

  function ready() {
    board.isReady = true;
    board.emit("ready");
    if (typeof callback === "function") {
      callback();
    }
  }

  // Await the reported version.
  this.once("reportversion", function() {
    clearTimeout(this.reportVersionTimeoutId);
    this.versionReceived = true;
    this.once("queryfirmware", function() {

      if (settings.samplingInterval) {
        this.setSamplingInterval(settings.samplingInterval);
      }
      if (settings.skipCapabilities) {
        ready();
      } else {
        this.queryCapabilities(function() {
          this.queryAnalogMapping(ready);
        });
      }
    });
  });

  i2cActive.set(this, false);
};