<commit_before>

/*
inst_assemblier.rs

assemble the complete bytecode
*/


use serialize::json;
use texture_assemblier;
use std::collections::HashMap;
use fileutils;
use regex::Regex;

enum Inst {
  NOP = 0x00,
  LIT = 0x01,
  DEL = 0x02,
  JMP = 0x03,

  // math operations
  PLUS = 0x10,
  SUB = 0x11,
  MULT = 0x12,
  DIV = 0x13,

  //hooks
  TEX = 0x30, // change current texture index, also changes the character's hitbox data


  END = 0xff, //end this frame
}

#[derive(RustcDecodable, RustcEncodable)]
struct Flag  {
    key: String,
    value: String,
}


// The following representations are not the actual models for the datas.
// They are only modeled on the purpose of generating bytecodes
#[derive(Encodable)]
struct Move {
  frames: Vec<Frame>,
}

#[derive(Encodable)]
struct Frame {
  texture_id: i32,
  flags: HashMap<String, i32>,
}

impl Frame {
  fn assemble_contents(&self, idle_frame_address: i32) -> Vec<i32>{
    let mut assembling_inst: Vec<i32> = vec![Inst::LIT as i32, self.texture_id, Inst::TEX as i32];
    for i in 0..self.duration() {
      assembling_inst.push(Inst::END as i32);
    }
    return assembling_inst;
  }

  fn duration(&self) -> i32 {
    let r = match self.flags.get("duration") {
      Some(s) => s.clone(),
      None => panic!("this frame does not have a duration flag"),
    };
    return r;
  }
}

impl Move {
  fn idle(&self) -> bool {
    return self.first_frame_flag_val("idle") == 1;
  }

  fn first_frame(&self) -> &Frame {
    return &self.frames[0];
  }

  fn first_frame_flag_val(&self, key: &str) -> i32 {
    let f: &Frame = self.first_frame();
    let r: &i32 = match f.flags.get(key) {
      Some(v) => v,
      None => panic!("Could not find key :{} in the flags of first frame", key),
    };
    return r.clone();
  }

  fn assemble_my_frames(&self, idle_frame_address: i32) -> Vec<i32>{
    let mut r: Vec<i32> = Vec::new();
    for f in self.frames.iter() {
      r.push_all(&f.assemble_contents(idle_frame_address));
    }
    r.push_all(&[Inst::LIT as i32,idle_frame_address,Inst::JMP as i32]);
    return r;
  }
}



pub fn assemble(filename: &str, data: &HashMap<String, HashMap<String, Vec<HashMap<String, i32>>>>, flags: &HashMap<String, HashMap<String, i32>>) {
  //assemble_inst
  save_with_json(filename, assemble_inst(assemble_moves(group_file_vec(texture_assemblier::build_texture_vec(data)), data, flags)));
}

fn group_file_vec(filenames: Vec<String>) -> HashMap<String, Vec<String>>{
  let re = match Regex::new(r"^(?P<file_pre>\D+)\d+\.png$"){
    Ok(re) => re,
    Err(err) => panic!("{}", err),
  };
  let mut groups: HashMap<String, Vec<String>> = HashMap::new();

  let mut currentMax = 0;
  for n in filenames.iter() {
    let caps = match re.captures(n) {
      Some(s) => s,
      None => panic!("nothing matched to the regex of assemblier"),
    };<commit_msg>reformated jmp for production<commit_after>

/*
inst_assemblier.rs

assemble the complete bytecode
*/


use serialize::json;
use texture_assemblier;
use std::collections::HashMap;
use fileutils;
use regex::Regex;

enum Inst {
  NOP = 0x00,
  LIT = 0x01,
  DEL = 0x02,
  JMP = 0x03,

  // math operations
  PLUS = 0x10,
  SUB = 0x11,
  MULT = 0x12,
  DIV = 0x13,

  //hooks
  TEX = 0x30, // change current texture index, also changes the character's hitbox data


  END = 0xff, //end this frame
}

#[derive(RustcDecodable, RustcEncodable)]
struct Flag  {
    key: String,
    value: String,
}


// The following representations are not the actual models for the datas.
// They are only modeled on the purpose of generating bytecodes
#[derive(Encodable)]
struct Move {
  frames: Vec<Frame>,
}

#[derive(Encodable)]
struct Frame {
  texture_id: i32,
  flags: HashMap<String, i32>,
}

impl Frame {
  fn assemble_contents(&self, idle_frame_address: i32) -> Vec<i32>{
    let mut assembling_inst: Vec<i32> = vec![Inst::LIT as i32, self.texture_id, Inst::TEX as i32];
    for i in 0..self.duration() {
      assembling_inst.push(Inst::END as i32);
    }
    return assembling_inst;
  }

  fn duration(&self) -> i32 {
    let r = match self.flags.get("duration") {
      Some(s) => s.clone(),
      None => panic!("this frame does not have a duration flag"),
    };
    return r;
  }
}

impl Move {
  fn idle(&self) -> bool {
    return self.first_frame_flag_val("idle") == 1;
  }

  fn first_frame(&self) -> &Frame {
    return &self.frames[0];
  }

  fn first_frame_flag_val(&self, key: &str) -> i32 {
    let f: &Frame = self.first_frame();
    let r: &i32 = match f.flags.get(key) {
      Some(v) => v,
      None => panic!("Could not find key :{} in the flags of first frame", key),
    };
    return r.clone();
  }

  fn assemble_my_frames(&self, idle_frame_address: i32) -> Vec<i32>{
    let mut r: Vec<i32> = Vec::new();
    for f in self.frames.iter() {
      r.push_all(&f.assemble_contents(idle_frame_address));
    }
    r.push_all(&[Inst::JMP as i32, idle_frame_address]);
    return r;
  }
}



pub fn assemble(filename: &str, data: &HashMap<String, HashMap<String, Vec<HashMap<String, i32>>>>, flags: &HashMap<String, HashMap<String, i32>>) {
  //assemble_inst
  save_with_json(filename, assemble_inst(assemble_moves(group_file_vec(texture_assemblier::build_texture_vec(data)), data, flags)));
}

fn group_file_vec(filenames: Vec<String>) -> HashMap<String, Vec<String>>{
  let re = match Regex::new(r"^(?P<file_pre>\D+)\d+\.png$"){
    Ok(re) => re,
    Err(err) => panic!("{}", err),
  };
  let mut groups: HashMap<String, Vec<String>> = HashMap::new();

  let mut currentMax = 0;
  for n in filenames.iter() {
    let caps = match re.captures(n) {
      Some(s) => s,
      None => panic!("nothing matched to the regex of assemblier"),
    };
{'fraction_non_alphanumeric': 0.15234922861150071, 'fraction_numerical': 0.023492286115007012, 'mean_word_length': 3.5027624309392267, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 69, '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': '7424292', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2077, 'n_words': 538}