QuentinBrooks.com
Quentin Brooks
Quentin Brooks
CPP Portable Loader
C++ in the browser without hassle

EXPORT int isPrime(int checks, int doTrialDivision, int primeNumberByteCount) {
    for(int i = primeNumberByteCount; i < sizeof(isPrimeNumberToCheck); i++) {
        isPrimeNumberToCheck[i] = 0;
    }
    if(primeNumberByteCount == 0) {
        return 0;
    }
    // Round to sizeof(BN_ULONG) units
    int BN_ULONG_count = (primeNumberByteCount + sizeof(BN_ULONG) - 1) / sizeof(BN_ULONG);
    BIGNUM num = { (BN_ULONG*)isPrimeNumberToCheck, BN_ULONG_count, BIGNUM_MAX_BITS / 32, 0, 0 };

    int result = BN_is_prime_fasttest_ex(&num, checks, nullptr, doTrialDivision, nullptr);
    freeAllBigNums();
    return result;
}

int primeCheckIterations;
void primeHash(int checks, int doTrialDivision, int sha512InputLength) {
    mbedtls_sha512_context ctx;

    mbedtls_sha512_init(&ctx);
    mbedtls_sha512_starts(&ctx);

    primeCheckIterations = 0;
    while(true) {
        primeCheckIterations++;
        for(int i = 0; i < 512 / sha512InputLength + 2; i++) {
            mbedtls_sha512_update(&ctx, sha512InputData, sha512InputLength);
        }

        for(int i = 0; i < 8; i++) {
            ((uint64_t*)isPrimeNumberToCheck)[i] = ctx.state[i];
        }
        if(isPrime(checks, doTrialDivision, 64)) {
            for(int i = 0; i < 8; i++) {
                ((uint64_t*)sha512HashOut)[i] = ctx.state[i];
            }
            mbedtls_sha512_finish(&ctx, sha512HashOut);
            clearContext(&ctx);
            return;
        }
    }
}

EXPORT int isPrime(int checks, int doTrialDivision, int primeNumberByteCount) {
    for(int i = primeNumberByteCount; i < sizeof(isPrimeNumberToCheck); i++) {
        isPrimeNumberToCheck[i] = 0;
    }
    if(primeNumberByteCount == 0) {
        return 0;
    }
    // Round to sizeof(BN_ULONG) units
    int BN_ULONG_count = (primeNumberByteCount + sizeof(BN_ULONG) - 1) / sizeof(BN_ULONG);
    BIGNUM num = { (BN_ULONG*)isPrimeNumberToCheck, BN_ULONG_count, BIGNUM_MAX_BITS / 32, 0, 0 };

    int result = BN_is_prime_fasttest_ex(&num, checks, nullptr, doTrialDivision, nullptr);
    freeAllBigNums();
    return result;
}

int primeCheckIterations;
void primeHash(int checks, int doTrialDivision, int sha512InputLength) {
    mbedtls_sha512_context ctx;

    mbedtls_sha512_init(&ctx);
    mbedtls_sha512_starts(&ctx);

    primeCheckIterations = 0;
    while(true) {
        primeCheckIterations++;
        for(int i = 0; i < 512 / sha512InputLength + 2; i++) {
            mbedtls_sha512_update(&ctx, sha512InputData, sha512InputLength);
        }

        for(int i = 0; i < 8; i++) {
            ((uint64_t*)isPrimeNumberToCheck)[i] = ctx.state[i];
        }
        if(isPrime(checks, doTrialDivision, 64)) {
            for(int i = 0; i < 8; i++) {
                ((uint64_t*)sha512HashOut)[i] = ctx.state[i];
            }
            mbedtls_sha512_finish(&ctx, sha512HashOut);
            clearContext(&ctx);
            return;
        }
    }
}
// AUTO GENERATED FILE DO NOT EDIT DIRECTLY. SOURCE: C:/Users/quent/Dropbox/query-sub/dist//src/algorithms/isPrime.cpp.wasm

/** bool[1] */
export declare const initCalled: Uint8Array;
/** long unsigned int[256] */
export declare const isaacRandSeed: Uint32Array;
/** long unsigned int[256] */
export declare const isaacRandValues: Uint32Array;
/** unsigned char[128] */
export declare const sha512InputData: Uint8Array;
/** unsigned char[64] */
export declare const sha512HashOut: Uint8Array;
/** unsigned char[256] */
export declare const isPrimeNumberToCheck: Uint8Array;

/**
 * @returns {Uint32Array | Promise} long unsigned int*
 * */
export declare function isaacRandNext(): Uint32Array | Promise<Uint32Array>;

export declare function SHA512_init(): void | Promise;

/**
 * @param {number} sha512InputLength long unsigned int
 * */
export declare function SHA512_update(sha512InputLength: number): void | Promise;

export declare function SHA512_finish(): void | Promise;

/**
 * @param {number} checks int
 * @param {number} doTrialDivision int
 * @param {number} primeNumberByteCount int
 * @returns {number | Promise} int
 * */
export declare function isPrime(checks: number, doTrialDivision: number, primeNumberByteCount: number): number | Promise;

/** Returns a promise that is resolved when compilation is complete (does not trigger compilation though, compilation starts as soon as an import happens). Once compilation is complete returns a raw object instead of a promise, and will never return a promise again. */
export declare function CompileWasmFunctions(): Promise<{
    /** bool[1] */
    initCalled: Uint8Array;
    /** long unsigned int[256] */
    isaacRandSeed: Uint32Array;
    /** long unsigned int[256] */
    isaacRandValues: Uint32Array;
    /** unsigned char[128] */
    sha512InputData: Uint8Array;
    /** unsigned char[64] */
    sha512HashOut: Uint8Array;
    /** unsigned char[256] */
    isPrimeNumberToCheck: Uint8Array;

    /**
     * @returns {Uint32Array} long unsigned int*
     * */
    isaacRandNext(): Uint32Array;

    SHA512_init(): void;

    /**
     * @param {number} sha512InputLength long unsigned int
     * */
    SHA512_update(sha512InputLength: number): void;

    SHA512_finish(): void;

    /**
     * @param {number} checks int
     * @param {number} doTrialDivision int
     * @param {number} primeNumberByteCount int
     * @returns {number} int
     * */
    isPrime(checks: number, doTrialDivision: number, primeNumberByteCount: number): number;
}>;

/** Recompiles the file, possibly with new imports, creating a new module with new memory space. The module is self contained, and this recompilation doesn't impact the static exported functions. */
export declare function CompileNewWasm(): Promise<{
    /** bool[1] */
    initCalled: Uint8Array;
    /** long unsigned int[256] */
    isaacRandSeed: Uint32Array;
    /** long unsigned int[256] */
    isaacRandValues: Uint32Array;
    /** unsigned char[128] */
    sha512InputData: Uint8Array;
    /** unsigned char[64] */
    sha512HashOut: Uint8Array;
    /** unsigned char[256] */
    isPrimeNumberToCheck: Uint8Array;

    /**
     * @returns {Uint32Array} long unsigned int*
     * */
    isaacRandNext(): Uint32Array;

    SHA512_init(): void;

    /**
     * @param {number} sha512InputLength long unsigned int
     * */
    SHA512_update(sha512InputLength: number): void;

    SHA512_finish(): void;

    /**
     * @param {number} checks int
     * @param {number} doTrialDivision int
     * @param {number} primeNumberByteCount int
     * @returns {number} int
     * */
    isPrime(checks: number, doTrialDivision: number, primeNumberByteCount: number): number;
}>;

export declare function UtilGetBufferFromAddress(address: number): Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array;
export declare function UtilGetAddressFromBuffer(wasmBuffer: Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array): number;
export declare function UtilGetFncFromArg(arg: number): Function;
export declare function UtilGetArgFromFnc(wasmFnc: Function): number;
.debug_info
DW_TAG_compile_unit (has children) (0xb)(C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp)
| DW_AT_producer (clang version 8.0.1 (tags/RELEASE_801/final)) [DW_FORM_strp]
| DW_AT_language (4) [DW_FORM_data2]
| DW_AT_name (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_strp]
| DW_AT_stmt_list (0) [DW_FORM_sec_offset]
| DW_AT_comp_dir (C:/Users/quent/Dropbox/repos/new-site) [DW_FORM_strp]
| DW_AT_low_pc (0) [DW_FORM_addr]
| DW_AT_ranges (0) [DW_FORM_sec_offset]

    DW_TAG_variable (0x26)(SHIM__lastErrorString)
    | DW_AT_name (SHIM__lastErrorString) [DW_FORM_strp]
    | DW_AT_type (55) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0x37)
        | DW_AT_type (67) [DW_FORM_ref4]
            DW_TAG_base_type (0x43)(unsigned char)
            | DW_AT_name (unsigned char) [DW_FORM_strp]
            | DW_AT_encoding (8) [DW_FORM_data1]
            | DW_AT_byte_size (1) [DW_FORM_data1]


            DW_TAG_subrange_type (0x3c)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (250) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/../../node_modules/cpp-portable-loader/export-helpers.h) [DW_FORM_data1]
    | DW_AT_decl_line (22) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 0, 4, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0x37)
    | DW_AT_type (67) [DW_FORM_ref4]
        DW_TAG_base_type (0x43)(unsigned char)
        | DW_AT_name (unsigned char) [DW_FORM_strp]
        | DW_AT_encoding (8) [DW_FORM_data1]
        | DW_AT_byte_size (1) [DW_FORM_data1]


        DW_TAG_subrange_type (0x3c)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (250) [DW_FORM_data1]

    DW_TAG_base_type (0x43)(unsigned char)
    | DW_AT_name (unsigned char) [DW_FORM_strp]
    | DW_AT_encoding (8) [DW_FORM_data1]
    | DW_AT_byte_size (1) [DW_FORM_data1]

    DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
    | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
    | DW_AT_byte_size (8) [DW_FORM_data1]
    | DW_AT_encoding (7) [DW_FORM_data1]

    DW_TAG_variable (0x51)(sharedValue)
    | DW_AT_name (sharedValue) [DW_FORM_strp]
    | DW_AT_type (98) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0x62)
        | DW_AT_type (110) [DW_FORM_ref4]
            DW_TAG_base_type (0x6e)(int)
            | DW_AT_name (int) [DW_FORM_strp]
            | DW_AT_encoding (5) [DW_FORM_data1]
            | DW_AT_byte_size (4) [DW_FORM_data1]


            DW_TAG_subrange_type (0x67)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (2) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (3) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, fc, 4, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0x62)
    | DW_AT_type (110) [DW_FORM_ref4]
        DW_TAG_base_type (0x6e)(int)
        | DW_AT_name (int) [DW_FORM_strp]
        | DW_AT_encoding (5) [DW_FORM_data1]
        | DW_AT_byte_size (4) [DW_FORM_data1]


        DW_TAG_subrange_type (0x67)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (2) [DW_FORM_data1]

    DW_TAG_base_type (0x6e)(int)
    | DW_AT_name (int) [DW_FORM_strp]
    | DW_AT_encoding (5) [DW_FORM_data1]
    | DW_AT_byte_size (4) [DW_FORM_data1]

    DW_TAG_variable (0x75)(sharedValue2)
    | DW_AT_name (sharedValue2) [DW_FORM_strp]
    | DW_AT_type (98) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0x62)
        | DW_AT_type (110) [DW_FORM_ref4]
            DW_TAG_base_type (0x6e)(int)
            | DW_AT_name (int) [DW_FORM_strp]
            | DW_AT_encoding (5) [DW_FORM_data1]
            | DW_AT_byte_size (4) [DW_FORM_data1]


            DW_TAG_subrange_type (0x67)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (2) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (4) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 4, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_variable (0x86)(sharedValue3)
    | DW_AT_name (sharedValue3) [DW_FORM_strp]
    | DW_AT_type (151) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0x97)
        | DW_AT_type (163) [DW_FORM_ref4]
            DW_TAG_base_type (0xa3)(double)
            | DW_AT_name (double) [DW_FORM_strp]
            | DW_AT_encoding (4) [DW_FORM_data1]
            | DW_AT_byte_size (8) [DW_FORM_data1]


            DW_TAG_subrange_type (0x9c)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (2) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (5) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 10, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0x97)
    | DW_AT_type (163) [DW_FORM_ref4]
        DW_TAG_base_type (0xa3)(double)
        | DW_AT_name (double) [DW_FORM_strp]
        | DW_AT_encoding (4) [DW_FORM_data1]
        | DW_AT_byte_size (8) [DW_FORM_data1]


        DW_TAG_subrange_type (0x9c)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (2) [DW_FORM_data1]

    DW_TAG_base_type (0xa3)(double)
    | DW_AT_name (double) [DW_FORM_strp]
    | DW_AT_encoding (4) [DW_FORM_data1]
    | DW_AT_byte_size (8) [DW_FORM_data1]

    DW_TAG_variable (0xaa)(sharedValue4)
    | DW_AT_name (sharedValue4) [DW_FORM_strp]
    | DW_AT_type (187) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0xbb)
        | DW_AT_type (199) [DW_FORM_ref4]
            DW_TAG_base_type (0xc7)(long long int)
            | DW_AT_name (long long int) [DW_FORM_strp]
            | DW_AT_encoding (5) [DW_FORM_data1]
            | DW_AT_byte_size (8) [DW_FORM_data1]


            DW_TAG_subrange_type (0xc0)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (2) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (6) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 20, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0xbb)
    | DW_AT_type (199) [DW_FORM_ref4]
        DW_TAG_base_type (0xc7)(long long int)
        | DW_AT_name (long long int) [DW_FORM_strp]
        | DW_AT_encoding (5) [DW_FORM_data1]
        | DW_AT_byte_size (8) [DW_FORM_data1]


        DW_TAG_subrange_type (0xc0)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (2) [DW_FORM_data1]

    DW_TAG_base_type (0xc7)(long long int)
    | DW_AT_name (long long int) [DW_FORM_strp]
    | DW_AT_encoding (5) [DW_FORM_data1]
    | DW_AT_byte_size (8) [DW_FORM_data1]

    DW_TAG_variable (0xce)(sharedValue5)
    | DW_AT_name (sharedValue5) [DW_FORM_strp]
    | DW_AT_type (223) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0xdf)
        | DW_AT_type (235) [DW_FORM_ref4]
            DW_TAG_base_type (0xeb)(long double)
            | DW_AT_name (long double) [DW_FORM_strp]
            | DW_AT_encoding (4) [DW_FORM_data1]
            | DW_AT_byte_size (16) [DW_FORM_data1]


            DW_TAG_subrange_type (0xe4)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (2) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (7) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 30, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0xdf)
    | DW_AT_type (235) [DW_FORM_ref4]
        DW_TAG_base_type (0xeb)(long double)
        | DW_AT_name (long double) [DW_FORM_strp]
        | DW_AT_encoding (4) [DW_FORM_data1]
        | DW_AT_byte_size (16) [DW_FORM_data1]


        DW_TAG_subrange_type (0xe4)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (2) [DW_FORM_data1]

    DW_TAG_base_type (0xeb)(long double)
    | DW_AT_name (long double) [DW_FORM_strp]
    | DW_AT_encoding (4) [DW_FORM_data1]
    | DW_AT_byte_size (16) [DW_FORM_data1]

    DW_TAG_variable (0xf2)(exportedArray)
    | DW_AT_name (exportedArray) [DW_FORM_strp]
    | DW_AT_type (259) [DW_FORM_ref4]
        DW_TAG_array_type (has children) (0x103)
        | DW_AT_type (271) [DW_FORM_ref4]
            DW_TAG_typedef (0x10f)(whyTypeDef)
            | DW_AT_type (110) [DW_FORM_ref4]
                DW_TAG_base_type (0x6e)(int)
                | DW_AT_name (int) [DW_FORM_strp]
                | DW_AT_encoding (5) [DW_FORM_data1]
                | DW_AT_byte_size (4) [DW_FORM_data1]

            | DW_AT_name (whyTypeDef) [DW_FORM_strp]
            | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
            | DW_AT_decl_line (10) [DW_FORM_data1]


            DW_TAG_subrange_type (0x108)
            | DW_AT_type (74) [DW_FORM_ref4]
                DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
                | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
                | DW_AT_byte_size (8) [DW_FORM_data1]
                | DW_AT_encoding (7) [DW_FORM_data1]

            | DW_AT_count (12) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (11) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 50, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_array_type (has children) (0x103)
    | DW_AT_type (271) [DW_FORM_ref4]
        DW_TAG_typedef (0x10f)(whyTypeDef)
        | DW_AT_type (110) [DW_FORM_ref4]
            DW_TAG_base_type (0x6e)(int)
            | DW_AT_name (int) [DW_FORM_strp]
            | DW_AT_encoding (5) [DW_FORM_data1]
            | DW_AT_byte_size (4) [DW_FORM_data1]

        | DW_AT_name (whyTypeDef) [DW_FORM_strp]
        | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
        | DW_AT_decl_line (10) [DW_FORM_data1]


        DW_TAG_subrange_type (0x108)
        | DW_AT_type (74) [DW_FORM_ref4]
            DW_TAG_base_type (0x4a)(__ARRAY_SIZE_TYPE__)
            | DW_AT_name (__ARRAY_SIZE_TYPE__) [DW_FORM_strp]
            | DW_AT_byte_size (8) [DW_FORM_data1]
            | DW_AT_encoding (7) [DW_FORM_data1]

        | DW_AT_count (12) [DW_FORM_data1]

    DW_TAG_typedef (0x10f)(whyTypeDef)
    | DW_AT_type (110) [DW_FORM_ref4]
        DW_TAG_base_type (0x6e)(int)
        | DW_AT_name (int) [DW_FORM_strp]
        | DW_AT_encoding (5) [DW_FORM_data1]
        | DW_AT_byte_size (4) [DW_FORM_data1]

    | DW_AT_name (whyTypeDef) [DW_FORM_strp]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (10) [DW_FORM_data1]

    DW_TAG_variable (0x11a)(testglobal)
    | DW_AT_name (testglobal) [DW_FORM_strp]
    | DW_AT_type (110) [DW_FORM_ref4]
        DW_TAG_base_type (0x6e)(int)
        | DW_AT_name (int) [DW_FORM_strp]
        | DW_AT_encoding (5) [DW_FORM_data1]
        | DW_AT_byte_size (4) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (24) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 80, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_variable (0x12b)(testglobal2)
    | DW_AT_name (testglobal2) [DW_FORM_strp]
    | DW_AT_type (316) [DW_FORM_ref4]
        DW_TAG_base_type (0x13c)(float)
        | DW_AT_name (float) [DW_FORM_strp]
        | DW_AT_encoding (4) [DW_FORM_data1]
        | DW_AT_byte_size (4) [DW_FORM_data1]

    | DW_AT_external (true) [DW_FORM_flag_present]
    | DW_AT_decl_file (C:/Users/quent/Dropbox/repos/new-site/widgets/CPPPortableLoader/test.cpp) [DW_FORM_data1]
    | DW_AT_decl_line (25) [DW_FORM_data1]
    | DW_AT_location (Buffer([3, 84, 5, 0, 0])) [DW_FORM_exprloc]

    DW_TAG_base_type (0x13c)(float)
    | DW_AT_name (float) [DW_FORM_strp]
    | DW_AT_encoding (4) [DW_FORM_data1]
    | DW_AT_byte_size (4) [DW_FORM_data1]

    DW_TAG_pointer_type (0x143)
    | DW_AT_type (328) [DW_FORM_ref4]
        DW_TAG_pointer_type (0x148)
        | DW_AT_type (333) [DW_FORM_ref4]
            DW_TAG_const_type (0x14d)
            | DW_AT_type (338) [DW_FORM_ref4]
                DW_TAG_base_type (0x152)(char)
                | DW_AT_name (char) [DW_FORM_strp]
                | DW_AT_encoding (6) [DW_FORM_data1]
                | DW_AT_byte_size (1) [DW_FORM_data1]
    
HTML5 Video
Streaming video from encoding to muxing to rendering
{
    "boxes": [
        {
            "header": {
                "size": 32,
                "type": "ftyp",
                "headerSize": 8
            },
            "type": "ftyp",
            "major_brand": "isom",
            "minor_version": 512,
            "compatible_brands": [
                "isom",
                "iso2",
                "avc1",
                "mp41"
            ]
        },
        {
            "header": {
                "size": 8,
                "type": "free",
                "headerSize": 8
            },
            "type": "free",
            "bytes": "LargeBuffer(0)"
        },
        {
            "header": {
                "size": 1303253,
                "type": "mdat",
                "headerSize": 8
            },
            "type": "mdat",
            "bytes": "LargeBuffer(1303245)"
        },
        {
            "header": {
                "size": 1292,
                "type": "moov",
                "headerSize": 8
            },
            "type": "moov",
            "boxes": [
                {
                    "header": {
                        "size": 108,
                        "type": "mvhd",
                        "headerSize": 8
                    },
                    "type": "mvhd",
                    "version": 0,
                    "flags": 0,
                    "times": {
                        "creation_time": 0,
                        "modification_time": 0,
                        "timescale": 1000,
                        "duration": 5005
                    },
                    "rate": 1,
                    "volume": 1,
                    "reserved": 0,
                    "reserved0": 0,
                    "reserved1": 0,
                    "matrix": [
                        65536,
                        0,
                        0,
                        0,
                        65536,
                        0,
                        0,
                        "2 items removed..."
                    ],
                    "pre_defined": [
                        0,
                        0,
                        0,
                        0,
                        0,
                        0
                    ],
                    "next_track_ID": 2
                }
            ]
        }
    ]
};
Devtools Patch
Patching chrome to modify devtools
if (type.tagName === "DW_TAG_base_type") {
    let typeName = type.name;

    if (typeof value === "object") {

        let buffer = value.buffer;
        let end = pos + type.byte_size;
        if (end > buffer.length) {
            return `Invalid value, accessing ending at 0x${(end - type.byte_size).toString(16)} to 0x${end.toString(16)}, buffer end of 0x${buffer.length.toString(16)}`;
        }

        if (type.encodingName === "signed_char" && isMaybeAnArray) {
            let maxToRead = Math.min(100, value.byteLength - pos);
            let bytes = [];
            let hasNull = false;
            for (let i = 0; i < maxToRead; i++) {
                let b = value.getUint8(pos + i);
                if (b === 0) {
                    hasNull = true;
                    break;
                }
                bytes.push(b);
            }
            value = new TextDecoder().decode(new Uint8Array(bytes));
            if (!hasNull) {
                value += " (NO NULL)";
            }
        }
        else if (type.encodingName === "float") {
            if (type.byte_size === 8) {
                value = value.getFloat64(pos, true);
            } else if (type.byte_size === 4) {
                value = value.getFloat32(pos, true);
            } else {
                return `Unsupported floating point byte size of ${type.byte_size}`;
            }
        } else {
            if (type.byte_size === 8) {
                if (type.encodingName.includes("signed")) {
                    value = value.getBigInt64(pos, true);
                } else {
                    value = value.getBigUint64(pos, true);
                }
            } else if (type.byte_size === 4) {
                if (type.encodingName.includes("signed")) {
                    value = value.getInt32(pos, true);
                } else {
                    value = value.getUint32(pos, true);
                }
            } else if (type.byte_size === 2) {
                if (type.encodingName.includes("signed")) {
                    value = value.getInt16(pos, true);
                } else {
                    value = value.getUint16(pos, true);
                }
            } else if (type.byte_size === 1) {
                if (type.encodingName.includes("signed")) {
                    value = value.getInt8(pos, true);
                } else {
                    value = value.getUint8(pos, true);
                }
            } else {
                return `Unsupported integer byte size of ${type.byte_size}`;
            }
        }
    }

    if(isMaybeAnArray) {
        typeName += "*";
    }

    let result = `(${typeName}) ${value}`;

    if(isMaybeAnArray) {
        result += ` (0x${pos.toString(16)})`;
    }
    return result;
    //return `${value}, ${type.encodingName}, ${type.byte_size}, ${type.name}`;
}
function parseBlock(sizeSize) {
    let size = parseNum(sizeSize, false, true);
    let buffer = curBuffer.slice(curIndex, curIndex + size);
    curIndex += size;
    return buffer;
}
function parseVarBlock() {
    let size = parseLeb128();
    let buffer = curBuffer.slice(curIndex, curIndex + size);
    curIndex += size;
    return buffer;
}
function parseBytes(size) {
    let buffer = curBuffer.slice(curIndex, curIndex + size);
    curIndex += size;
    return buffer;
}
let forms = {
    [0x01]: { name: "DW_FORM_addr", parse: () => parseNum(4, false, true) },
    [0x03]: { name: "DW_FORM_block2", parse: () => parseBlock(2) },
    [0x04]: { name: "DW_FORM_block4", parse: () => parseBlock(4) },
    [0x05]: { name: "DW_FORM_data2", parse: () => parseNum(2, false, true) },
    [0x06]: { name: "DW_FORM_data4", parse: () => parseNum(4, false, true) },
    [0x07]: { name: "DW_FORM_data8", parse: () => parseBytes(8) },
    [0x08]: { name: "DW_FORM_string", parse: () => parseCString() },
    [0x09]: { name: "DW_FORM_block", parse: () => parseVarBlock() },
    [0x0a]: { name: "DW_FORM_block1", parse: () => parseBlock(1) },
    [0x0b]: { name: "DW_FORM_data1", parse: () => parseNum(1, false, true) },
    [0x0c]: { name: "DW_FORM_flag", parse: () => parseNum(1, false, true) },
    [0x0d]: { name: "DW_FORM_sdata", parse: () => parseVarBlock() },
    [0x0e]: { name: "DW_FORM_strp", parse: () => parseCStringAt(parseNum(4, false, true)) },
    [0x0f]: { name: "DW_FORM_udata", parse: () => parseLeb128() },
    [0x10]: { name: "DW_FORM_ref_addr", parse: () => parseNum(4, false, true) },
    [0x11]: { name: "DW_FORM_ref1", parse: () => parseNum(1, false, true) },
    [0x12]: { name: "DW_FORM_ref2", parse: () => parseNum(2, false, true) },
    [0x13]: { name: "DW_FORM_ref4", parse: () => parseNum(4, false, true) },
    [0x14]: { name: "DW_FORM_ref8", parse: () => parseBytes(8) },
    [0x15]: { name: "DW_FORM_ref_udata", parse: () => parseVarBlock() },
    [0x16]: { name: "DW_FORM_indirect", parse: () => getDwForm(parseLeb128(), tagName) },
    [0x17]: { name: "DW_FORM_sec_offset", parse: () => parseNum(4, false, true) },
    [0x18]: { name: "DW_FORM_exprloc", parse: () => parseVarBlock() },
    [0x19]: { name: "DW_FORM_flag_present", parse: () => true },
    [0x20]: { name: "DW_FORM_ref_sig8", parse: () => parseBytes(8) },
};
Devtools modified by building it from source, parsing a special section of the chrome binary, and then modifying a resource file. Function argument debugging for WASM is added by injecting Javascript parsers for DWARF and WebAssembly into Devtools.
var address_change = (mininum_instruction_length * Math.floor((curRegisters.op_index + operation_advance) / maximum_operations_per_instruction));
curRegisters.address += address_change;
curRegisters.op_index = (curRegisters.op_index + operation_advance) % maximum_operations_per_instruction;
if (!noLineChange) {
    curRegisters.line += line_base + (adjusted_opcode % line_range);
    pushMatrix(opCode);
    curRegisters.basic_block = false;
    curRegisters.prologue_end = false;
    curRegisters.epilogue_begin = false;
    curRegisters.discriminator = 0;
}

EXPORT int isPrime(int checks, int doTrialDivision, int primeNumberByteCount) {
    for(int i = primeNumberByteCount; i < sizeof(isPrimeNumberToCheck); i++) {
        isPrimeNumberToCheck[i] = 0;
    }
    if(primeNumberByteCount == 0) {
        return 0;
    }
    // Round to sizeof(BN_ULONG) units
    int BN_ULONG_count = (primeNumberByteCount + sizeof(BN_ULONG) - 1) / sizeof(BN_ULONG);
    BIGNUM num = { (BN_ULONG*)isPrimeNumberToCheck, BN_ULONG_count, BIGNUM_MAX_BITS / 32, 0, 0 };

    int result = BN_is_prime_fasttest_ex(&num, checks, nullptr, doTrialDivision, nullptr);
    freeAllBigNums();
    return result;
}

int primeCheckIterations;
void primeHash(int checks, int doTrialDivision, int sha512InputLength) {
    mbedtls_sha512_context ctx;

    mbedtls_sha512_init(&ctx);
    mbedtls_sha512_starts(&ctx);

    primeCheckIterations = 0;
    while(true) {
        primeCheckIterations++;
        for(int i = 0; i < 512 / sha512InputLength + 2; i++) {
            mbedtls_sha512_update(&ctx, sha512InputData, sha512InputLength);
        }

        for(int i = 0; i < 8; i++) {
            ((uint64_t*)isPrimeNumberToCheck)[i] = ctx.state[i];
        }
        if(isPrime(checks, doTrialDivision, 64)) {
            for(int i = 0; i < 8; i++) {
                ((uint64_t*)sha512HashOut)[i] = ctx.state[i];
            }
            mbedtls_sha512_finish(&ctx, sha512HashOut);
            clearContext(&ctx);
            return;
        }
    }
}

EXPORT int isPrime(int checks, int doTrialDivision, int primeNumberByteCount) {
    for(int i = primeNumberByteCount; i < sizeof(isPrimeNumberToCheck); i++) {
        isPrimeNumberToCheck[i] = 0;
    }
    if(primeNumberByteCount == 0) {
        return 0;
    }
    // Round to sizeof(BN_ULONG) units
    int BN_ULONG_count = (primeNumberByteCount + sizeof(BN_ULONG) - 1) / sizeof(BN_ULONG);
    BIGNUM num = { (BN_ULONG*)isPrimeNumberToCheck, BN_ULONG_count, BIGNUM_MAX_BITS / 32, 0, 0 };

    int result = BN_is_prime_fasttest_ex(&num, checks, nullptr, doTrialDivision, nullptr);
    freeAllBigNums();
    return result;
}

int primeCheckIterations;
void primeHash(int checks, int doTrialDivision, int sha512InputLength) {
    mbedtls_sha512_context ctx;

    mbedtls_sha512_init(&ctx);
    mbedtls_sha512_starts(&ctx);

    primeCheckIterations = 0;
    while(true) {
        primeCheckIterations++;
        for(int i = 0; i < 512 / sha512InputLength + 2; i++) {
            mbedtls_sha512_update(&ctx, sha512InputData, sha512InputLength);
        }

        for(int i = 0; i < 8; i++) {
            ((uint64_t*)isPrimeNumberToCheck)[i] = ctx.state[i];
        }
        if(isPrime(checks, doTrialDivision, 64)) {
            for(int i = 0; i < 8; i++) {
                ((uint64_t*)sha512HashOut)[i] = ctx.state[i];
            }
            mbedtls_sha512_finish(&ctx, sha512HashOut);
            clearContext(&ctx);
            return;
        }
    }
}
C++ code compiled to WebAssembly by an npm packaged version of clang, parsed to create Typescript typings, with additional type augmentation through parsing the DWARF information clang adds to binaries, resulting in a Webpack loader which makes C++ calls from Typescript almost seamless.
// test.cpp.d.ts (auto generated)
/** int[2] */
export declare const sharedValue: Int32Array;
export declare function returnSum(array: Int32Array): number | Promise;
export declare function returnCallFnc(fnc: (int: number) => number): number | Promise;
// test.cpp

#include "../../node_modules/cpp-portable-loader/export-helpers.h"

EXPORT int sharedArray[2];
EXPORT int returnSum() {
    int sum = 0;
    for(int i = 0; i < 2; i++) {
        sum += sharedArray[i];
    }
    return sum;
}
JPGs via Video4Linux2 to Typescript using node-v4l2camera C++ bindings.
static void Capture(const FunctionCallbackInfo<Value>& info);
h264 encoding via gstreamer using OpenMAX for hardware acceleration.
cat frame*.jpeg | gst-launch-1.0 -vv -e fdsrc fd=0 ! capsfilter caps="image/jpeg,width=1920,height=1080,framerate=30/1" ! jpegdec ! avenc_h264_omx bitrate=10000 gop-size=2 ! video/x-h264,profile=high ! fdsink fd=1 | cat > frames.nal && stat frames.nal
Remuxed into an ISOBMFF part 12 container (mp4) using mp4-typescript and then played in the browser with the Media Source Extensions API.
let mp4Video = await MuxVideo({
    sps: keyframe.sps,
    pps: keyframe.pps,
    frames: frameInfos,
    baseMediaDecodeTimeInSeconds: baseMediaDecodeTimeInSeconds,
    width: keyframe.width,
    height: keyframe.height,
    timescale: GetTimescaleSeconds(speed)
});
An implementation of require in Typescript that runs in both NodeJS and Web Browsers with support for URLs and Source Map remapping.
const $ = require("https://code.jquery.com/jquery-1.11.3.js");
With code context reflection to support management of many module require domains.
export function GetResolvedPathFromExport(exportedObj: unknown): {
    modulePath: string;
    exportName: string;
    domain: RequireDomain;
}|undefined;
InsideReferenceCount newCount = count;
newCount.count++;
// Make it an outside reference, as we use outsideCount as a flag to indicate we won't dereference any pointers inside of it.
newCount.outsideCount++;
if(InterlockedCompareExchange64(
    (LONG64*)&ref->valueForSet,
    newCount.valueForSet,
    count.valueForSet
) == count.valueForSet) {
    MemLog_Add((void*)0, ref, "acquired for MarkIfUniqueIdEqual", ref->valueForSet);
    break;
}
Threadsafe + non-blocking + resizable + memory managed, HashTable in C++.
typedef struct {
    uint64_t pointerClipped : BITS_IN_ADDRESS_SPACE;
    uint64_t count : 64 - BITS_IN_ADDRESS_SPACE - 1;
    uint64_t isNull : 1;
} OutsideReference;
typedef struct InsideReference {
    uint64_t count;

    // User stored values succeed the actual InsideReference contents, starting at pointer + sizeof(InsideReference)
} InsideReference;