<commit_before>'use strict';

var SerialPort = require('serialport').SerialPort;
var bs2 = require('bs2-programmer');
var bluebird = require('bluebird');
var bs2tokenizer = require('pbasic-tokenizer');

var serial = require('./serial');

function bootload(options, cb){

  if(!options){
    throw new Error('Options error: no options');
  }

  if(!options.path){
    throw new Error('Options error: no path');
  }

  if(!options.memory || !options.memory.data){
    throw new Error('Options error: no program data');
  }

  if(!options.board){
    throw new Error('Options error: no board');
  }

  var serialport = new SerialPort(options.path, { baudrate: 200 }, false);
  bluebird.promisifyAll(serialport);

  var result = bluebird.using(serial.open(serialport), function(){
    return serial.bootload(serialport, options);
  });

  return result.nodeify(cb);
}

function compile(options, cb){

  var TModuleRec = bs2tokenizer.compile(options.source, false);

  if(!TModuleRec.Succeeded){
    throw new Error('Compile error: ', TModuleRec.Error);
  }

  var memory = {
    data: TModuleRec.PacketBuffer.slice(0, TModuleRec.PacketCount * 18)
  };

  var result = bluebird.resolve(memory);

  return result.nodeify(cb);
}

function getRevisions(cb){
  var result = bluebird.resolve(bs2.revisions);

  return result.nodeify(cb);
}<commit_msg>cleanup compile<commit_after>'use strict';

var SerialPort = require('serialport').SerialPort;
var bs2 = require('bs2-programmer');
var bluebird = require('bluebird');
var bs2tokenizer = require('pbasic-tokenizer');

var serial = require('./serial');

function internalCompile(options){
  var TModuleRec = bs2tokenizer.compile(options.source, false);

  if(!TModuleRec.Succeeded){
    throw new Error('Compile error: ' + TModuleRec.Error);
  }

  var memory = {
    data: TModuleRec.PacketBuffer.slice(0, TModuleRec.PacketCount * 18)
  };

  return memory;
}

function bootload(options, cb){

  if(!options){
    throw new Error('Options error: no options');
  }

  if(!options.path){
    throw new Error('Options error: no path');
  }

  if(!options.memory || !options.memory.data){
    throw new Error('Options error: no program data');
  }

  if(!options.board){
    throw new Error('Options error: no board');
  }

  var serialport = new SerialPort(options.path, { baudrate: 200 }, false);
  bluebird.promisifyAll(serialport);

  var result = bluebird.using(serial.open(serialport), function(){
    return serial.bootload(serialport, options);
  });

  return result.nodeify(cb);
}

function compile(options, cb){
  var result = bluebird.try(internalCompile, options);

  return result.nodeify(cb);
}

function getRevisions(cb){
  var result = bluebird.resolve(bs2.revisions);

  return result.nodeify(cb);
}
{'fraction_non_alphanumeric': 0.1438430802760625, 'fraction_numerical': 0.007991282237559027, 'mean_word_length': 4.5636363636363635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '705935', 'n_tokens_mistral': 904, 'n_tokens_neox': 853, 'n_words': 202}