<commit_before>/////////////////////////
// EJson Data Encoding //
/////////////////////////

class EjValue {}

function cast<T>(x : EjValue): T {
  if (x instanceof T) {
    let r : T = changetype<T>(x);
    return r;
  }
  return unreachable();
}

export class EjNull extends EjValue {
  constructor() { super(); }
}
export const IdEjNull = idof<EjNull>()

const c_null = new EjNull();

export class EjBool extends EjValue {
  value: bool
  constructor(a: bool) { super(); this.value = a; }
}
export const IdEjBool = idof<EjBool>()

const c_true = new EjBool(true);
const c_false = new EjBool(false);

export class EjNumber extends EjValue {
  value: f64
  constructor(a: f64) { super(); this.value = a; }
}
export const IdEjNumber = idof<EjNumber>()

const c_neg1 = new EjNumber(-1);
const c_1 = new EjNumber(1);
const c_0 = new EjNumber(0);

export class EjBigInt extends EjValue {
  value: i64
  constructor(a: i64) { super(); this.value = a; }
}
export const IdEjBigInt = idof<EjBigInt>()
export function ejBigInt_of_f64(x: f64) : EjBigInt {
  let i = I64.parseInt(Math.trunc(x).toString());
  return new EjBigInt(i);
}

export class EjString extends EjValue {
  value: string
  constructor(a: string) { super(); this.value = a; }
}
export const IdEjString = idof<EjString>()

export class EjStringBuilderUTF8 {
  private buf: Uint8Array
  private pos: i32
  constructor(n: i32) {
    this.pos = 0;
    this.buf = new Uint8Array(n);
  }
  putByte(val: u8): void {
    this.buf[this.pos] = val;
    this.pos++;
  }
  finalize(): EjString {
    let str = String.UTF8.decode(this.buf.buffer);
    return new EjString(str);
  }
}

export class EjArray extends EjValue {
  values: Array<EjValue>
  constructor(a: Array<EjValue>) { super(); this.values = a; }
}
export const IdArrayEjValue = idof<Array<EjValue>>()
export const IdEjArray = idof<EjArray>()

export class EjArrayBuilder {
  private arr: Array<EjValue>
  private pos: i32
  constructor(n: i32) {
    this.pos = 0;
    this.arr = new Array<EjValue>(n);
  }
  put(val: EjValue): EjArrayBuilder {
    this.arr[this.pos] = val;
    this.pos++;
    return this;
  }
  finalize(): EjArray {
    return new EjArray(this.arr)
  }
}

export class EjObject extends EjValue {
  values: Map<string, EjValue>
  constructor() { super(); this.values = new Map<string, EjValue>(); }
  has(k: EjString): bool {
    return this.values.has(k.value);
  }
  set(k: EjString, v: EjValue): EjObject {
    this.values.set(k.value, v);
    return this;
  }
  get(k: EjString): EjValue {
    return this.values.get(k.value);
  }
  keys(): Array<EjString> {
    return this.values.keys().map<EjString>(x => new EjString(x));
  }
}
export const IdEjObject = idof<EjObject>()

/////////////////////////
// EJson Serialization //
/////////////////////////

class BytesBuilder {
  segments: Array<ArrayBuffer>
  size: i32

  constructor() { this.segments = []; this.size = 0; }<commit_msg>Wasm runtime: produce nicer error messages for mising keys.<commit_after>/////////////////////////
// EJson Data Encoding //
/////////////////////////

class EjValue {}

function cast<T>(x : EjValue): T {
  if (x instanceof T) {
    let r : T = changetype<T>(x);
    return r;
  }
  return unreachable();
}

export class EjNull extends EjValue {
  constructor() { super(); }
}
export const IdEjNull = idof<EjNull>()

const c_null = new EjNull();

export class EjBool extends EjValue {
  value: bool
  constructor(a: bool) { super(); this.value = a; }
}
export const IdEjBool = idof<EjBool>()

const c_true = new EjBool(true);
const c_false = new EjBool(false);

export class EjNumber extends EjValue {
  value: f64
  constructor(a: f64) { super(); this.value = a; }
}
export const IdEjNumber = idof<EjNumber>()

const c_neg1 = new EjNumber(-1);
const c_1 = new EjNumber(1);
const c_0 = new EjNumber(0);

export class EjBigInt extends EjValue {
  value: i64
  constructor(a: i64) { super(); this.value = a; }
}
export const IdEjBigInt = idof<EjBigInt>()
export function ejBigInt_of_f64(x: f64) : EjBigInt {
  let i = I64.parseInt(Math.trunc(x).toString());
  return new EjBigInt(i);
}

export class EjString extends EjValue {
  value: string
  constructor(a: string) { super(); this.value = a; }
}
export const IdEjString = idof<EjString>()

export class EjStringBuilderUTF8 {
  private buf: Uint8Array
  private pos: i32
  constructor(n: i32) {
    this.pos = 0;
    this.buf = new Uint8Array(n);
  }
  putByte(val: u8): void {
    this.buf[this.pos] = val;
    this.pos++;
  }
  finalize(): EjString {
    let str = String.UTF8.decode(this.buf.buffer);
    return new EjString(str);
  }
}

export class EjArray extends EjValue {
  values: Array<EjValue>
  constructor(a: Array<EjValue>) { super(); this.values = a; }
}
export const IdArrayEjValue = idof<Array<EjValue>>()
export const IdEjArray = idof<EjArray>()

export class EjArrayBuilder {
  private arr: Array<EjValue>
  private pos: i32
  constructor(n: i32) {
    this.pos = 0;
    this.arr = new Array<EjValue>(n);
  }
  put(val: EjValue): EjArrayBuilder {
    this.arr[this.pos] = val;
    this.pos++;
    return this;
  }
  finalize(): EjArray {
    return new EjArray(this.arr)
  }
}

export class EjObject extends EjValue {
  values: Map<string, EjValue>
  constructor() { super(); this.values = new Map<string, EjValue>(); }
  has(k: EjString): bool {
    return this.values.has(k.value);
  }
  set(k: EjString, v: EjValue): EjObject {
    this.values.set(k.value, v);
    return this;
  }
  get(k: EjString): EjValue {
    // redundant debugging code unreachable
    // for a valid combination of engine, runtime, and compiled ergo
    if (! this.has(k)) {
      throw new Error("EjObject misses key '" + k.value + "'");
    }
    // actual code
    return this.values.get(k.value);
  }
  keys(): Array<EjString> {
    return this.values.keys().map<EjString>(x => new EjString(x));
  }
}
export const IdEjObject = idof<EjObject>()

/////////////////////////
// EJson Serialization //
/////////////////////////

class BytesBuilder {
  segments: Array<ArrayBuffer>
  size: i32

  constructor() { this.segments = []; this.size = 0; }
{'fraction_non_alphanumeric': 0.16838319437632826, 'fraction_numerical': 0.012424391041360144, 'mean_word_length': 3.1393775372124493, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '1776250', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2212, 'n_words': 564}