diff --git a/vlib/compress/zstd/zstd.v b/vlib/compress/zstd/zstd.c.v similarity index 100% rename from vlib/compress/zstd/zstd.v rename to vlib/compress/zstd/zstd.c.v diff --git a/vlib/crypto/sha256/sha256_test.v b/vlib/crypto/sha256/sha256_test.v index e77a946d1f..df974cd17c 100644 --- a/vlib/crypto/sha256/sha256_test.v +++ b/vlib/crypto/sha256/sha256_test.v @@ -46,6 +46,6 @@ fn test_crypto_sha256_224() { // with checksum digest.reset() _ := digest.write(data)! - chksum := digest.checksum() + chksum := digest.sum([]) assert chksum.hex() == expected } diff --git a/vlib/crypto/sha512/sha512_test.v b/vlib/crypto/sha512/sha512_test.v index 918ca5c53e..be7944119b 100644 --- a/vlib/crypto/sha512/sha512_test.v +++ b/vlib/crypto/sha512/sha512_test.v @@ -45,7 +45,7 @@ fn test_crypto_sha512_384() { d.reset() d.write(data) or { assert false } - chksum := d.checksum() + chksum := d.sum([]) assert chksum.hex() == expected } @@ -62,7 +62,7 @@ fn test_crypto_sha512_224() { d.reset() d.write(data) or { assert false } - chksum := d.checksum() + chksum := d.sum([]) assert chksum.hex() == expected } @@ -79,6 +79,6 @@ fn test_crypto_sha512_256() { d.reset() d.write(data) or { assert false } - chksum := d.checksum() + chksum := d.sum([]) assert chksum.hex() == expected } diff --git a/vlib/db/mysql/mysql_orm_test.v b/vlib/db/mysql/mysql_orm_test.v index fabde53650..20411c54c7 100644 --- a/vlib/db/mysql/mysql_orm_test.v +++ b/vlib/db/mysql/mysql_orm_test.v @@ -36,6 +36,11 @@ struct TestDefaultAttribute { } fn test_mysql_orm() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working mysql server running on localhost.') + return + } mut db := mysql.connect( host: '127.0.0.1' port: 3306 diff --git a/vlib/db/mysql/mysql_test.v b/vlib/db/mysql/mysql_test.v index 76db6e1c7e..c05c8b24ad 100644 --- a/vlib/db/mysql/mysql_test.v +++ b/vlib/db/mysql/mysql_test.v @@ -1,6 +1,11 @@ import db.mysql fn test_mysql() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working mysql server running on localhost.') + return + } config := mysql.Config{ host: '127.0.0.1' port: 3306 diff --git a/vlib/db/mysql/prepared_stmt_test.v b/vlib/db/mysql/prepared_stmt_test.v index 30e814c65e..87e3b9ed13 100644 --- a/vlib/db/mysql/prepared_stmt_test.v +++ b/vlib/db/mysql/prepared_stmt_test.v @@ -1,6 +1,11 @@ import db.mysql fn test_prep() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working mysql server running on localhost.') + return + } config := mysql.Config{ host: '127.0.0.1' port: 3306 diff --git a/vlib/db/pg/pg_double_test.v b/vlib/db/pg/pg_double_test.v index 59613a8c5e..9bb49b90a9 100644 --- a/vlib/db/pg/pg_double_test.v +++ b/vlib/db/pg/pg_double_test.v @@ -10,6 +10,11 @@ struct Demo { } fn test_float_field() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working postgres server running on localhost.') + return + } conn := 'host=localhost user=test password=test' // insert own connection string db := pg.connect_with_conninfo(conn)! defer { diff --git a/vlib/db/pg/pg_orm_test.v b/vlib/db/pg/pg_orm_test.v index fd983ee069..8cf47ec22f 100644 --- a/vlib/db/pg/pg_orm_test.v +++ b/vlib/db/pg/pg_orm_test.v @@ -36,6 +36,11 @@ struct TestDefaultAttribute { } fn test_pg_orm() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working postgres server running on localhost.') + return + } mut db := pg.connect( host: 'localhost' user: 'postgres' @@ -51,7 +56,7 @@ fn test_pg_orm() { orm.TableField{ name: 'id' typ: typeof[string]().idx - is_time: false + // is_time: false default_val: '' is_arr: false attrs: [ @@ -72,7 +77,7 @@ fn test_pg_orm() { orm.TableField{ name: 'name' typ: typeof[string]().idx - is_time: false + // is_time: false default_val: '' is_arr: false attrs: [] @@ -80,7 +85,7 @@ fn test_pg_orm() { orm.TableField{ name: 'age' typ: typeof[i64]().idx - is_time: false + // is_time: false default_val: '' is_arr: false attrs: [] @@ -152,7 +157,8 @@ fn test_pg_orm() { information_schema_custom_sql := ['integer', 'text', 'character varying', 'timestamp without time zone', 'uuid'] for data_type in result_custom_sql { - information_schema_data_types_results << data_type.vals[0] + x := data_type.vals[0]! + information_schema_data_types_results << x? } sql db { @@ -217,7 +223,8 @@ fn test_pg_orm() { mut information_schema_defaults_results := []string{} for defaults in result_defaults { - information_schema_defaults_results << defaults.vals[0] + x := defaults.vals[0]! + information_schema_defaults_results << x? } sql db { drop table TestDefaultAttribute diff --git a/vlib/db/pg/pg_test.v b/vlib/db/pg/pg_test.v index 261c93c083..bd06a5389d 100644 --- a/vlib/db/pg/pg_test.v +++ b/vlib/db/pg/pg_test.v @@ -2,21 +2,27 @@ module main import db.pg -const query = 'SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen - FROM pg_class c - JOIN information_schema.tables ischema on ischema.table_name = c.relname - JOIN pg_attribute a ON (a.attrelid = c.oid) - JOIN pg_type t ON (t.oid = a.atttypid) -WHERE - a.attnum >= 0' - fn test_large_exec() { + $if !network ? { + eprintln('> Skipping test ${@FN}, since `-d network` is not passed.') + eprintln('> This test requires a working postgres server running on localhost.') + return + } + db := pg.connect(pg.Config{ user: 'postgres', password: 'secret', dbname: 'postgres' })! defer { db.close() } - rows := db.exec(query)! + rows := db.exec(' +SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen + FROM pg_class c + JOIN information_schema.tables ischema on ischema.table_name = c.relname + JOIN pg_attribute a ON (a.attrelid = c.oid) + JOIN pg_type t ON (t.oid = a.atttypid) +WHERE + a.attnum >= 0 + ')! for row in rows { // We just need to access the memory to ensure it's properly allocated row.str() diff --git a/vlib/net/http/server_test.v b/vlib/net/http/server_test.v index 2714067ec1..56d42ce7e1 100644 --- a/vlib/net/http/server_test.v +++ b/vlib/net/http/server_test.v @@ -112,8 +112,6 @@ fn (mut handler MyHttpHandler) handle(req http.Request) http.Response { return r } -const cport = 18197 - fn test_server_custom_handler() { log.warn('${@FN} started') defer { @@ -123,7 +121,7 @@ fn test_server_custom_handler() { mut server := &http.Server{ accept_timeout: atimeout handler: handler - port: cport + addr: ':18197' } t := spawn server.listen_and_serve() server.wait_till_running()! diff --git a/vlib/net/net_nix.c.v b/vlib/net/net_nix.c.v index 9992aa2bb4..0e52085064 100644 --- a/vlib/net/net_nix.c.v +++ b/vlib/net/net_nix.c.v @@ -26,5 +26,6 @@ pub const msg_dontwait = C.MSG_DONTWAIT pub const error_ewouldblock = C.EWOULDBLOCK pub const error_einprogress = C.EINPROGRESS pub const error_eagain = C.EAGAIN +pub const error_eintr = C.EINTR fn C.unlink(&char) int diff --git a/vlib/net/net_windows.c.v b/vlib/net/net_windows.c.v index df118e2f90..1efcba1226 100644 --- a/vlib/net/net_windows.c.v +++ b/vlib/net/net_windows.c.v @@ -15,6 +15,7 @@ pub const msg_dontwait = 0 pub const error_ewouldblock = WsaError.wsaewouldblock pub const error_einprogress = WsaError.wsaeinprogress pub const error_eagain = WsaError.wsaewouldblock // on windows, is also wsaewouldblock +pub const error_eintr = WsaError.wsaeintr const wsa_v22 = 0x202 diff --git a/vlib/net/socket.v b/vlib/net/socket.c.v similarity index 100% rename from vlib/net/socket.v rename to vlib/net/socket.c.v diff --git a/vlib/net/tcp_non_blocking_test.v b/vlib/net/tcp_non_blocking_test.v index 64f619c100..79b5a4a229 100644 --- a/vlib/net/tcp_non_blocking_test.v +++ b/vlib/net/tcp_non_blocking_test.v @@ -3,7 +3,7 @@ import time fn server_thread(c_chan chan int) { errors_no_data := [net.err_timed_out.code(), int(net.error_ewouldblock), int(net.error_eagain), - C.EINTR] + int(net.error_eintr)] mut buf := []u8{len: 128} mut times := 0 mut read_len := 0 diff --git a/vlib/szip/szip_test.v b/vlib/szip/szip_test.v index aaf03be27c..730928ffd7 100644 --- a/vlib/szip/szip_test.v +++ b/vlib/szip/szip_test.v @@ -1,4 +1,4 @@ -import szip +import compress.szip import os const test_out_zip = 'v_test_zip.zip' diff --git a/vlib/time/time_test.c.v b/vlib/time/time_test.c.v new file mode 100644 index 0000000000..836395e002 --- /dev/null +++ b/vlib/time/time_test.c.v @@ -0,0 +1,14 @@ +import time + +fn test_tm_gmtoff() { + $if windows { + return + } $else { + rawtime := i64(0) // C.time_t{} + + C.time(&rawtime) // C.tm{} + + info := C.localtime(&rawtime) + assert info.tm_gmtoff == time.now().unix() - time.utc().unix() + } +} diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index f2b028a33f..54f928eafb 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -219,7 +219,7 @@ fn test_weekday_str() { hour: 0 minute: 0 second: 0 - unix: 0 + // unix: 0 } assert t.weekday_str() == name } @@ -397,16 +397,3 @@ fn test_parse_three_letters_month() { tm_tm := time.parse_format(tm_s, format)! assert tm_tm.month == tm.month } - -fn test_tm_gmtoff() { - $if windows { - return - } $else { - rawtime := i64(0) // C.time_t{} - - C.time(&rawtime) // C.tm{} - - info := C.localtime(&rawtime) - assert info.tm_gmtoff == time.now().unix() - time.utc().unix() - } -} diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4d4f305a71..8921ed711a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3258,7 +3258,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { tt := c.table.type_to_str(to_type) c.warn('casting `${ft}` to `${tt}` is only allowed in `unsafe` code', node.pos) } else if from_sym.kind == .array_fixed && !from_type.is_ptr() { - if !c.pref.translated && !c.file.is_translated { + if !c.pref.translated && !c.file.is_translated && !c.inside_unsafe { c.warn('cannot cast a fixed array (use e.g. `&arr[0]` instead)', node.pos) } } else if final_from_sym.kind == .string && final_to_sym.is_number() diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index c41e61010a..8fd1273321 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -751,11 +751,13 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', } else { parts.last() } - c.add_error_detail('this will become an error after 2024-05-31') - c.warn('initalizing private field `${field.name}` of `${mod_type}`', - init_field.pos) - // c.error('cannot access private field `${field.name}` on `${mod_type}`', init_field.pos) - break + if !c.inside_unsafe { + c.add_error_detail('this will become an error after 2024-05-31') + c.warn('initalizing private field `${field.name}` of `${mod_type}`', + init_field.pos) + // c.error('cannot access private field `${field.name}` on `${mod_type}`', init_field.pos) + break + } } } } diff --git a/vlib/v/debug/callstack.v b/vlib/v/debug/callstack.c.v similarity index 100% rename from vlib/v/debug/callstack.v rename to vlib/v/debug/callstack.c.v diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index d87812af7c..7a76e343e1 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -251,8 +251,10 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr { expr := p.expr(0) p.check(.rpar) if p.tok.kind != .dot && p.tok.line_nr == p.prev_tok.line_nr { - p.warn_with_pos('use e.g. `typeof(expr).name` or `sum_type_instance.type_name()` instead', - spos) + if !p.inside_unsafe { + p.warn_with_pos('use e.g. `typeof(expr).name` or `sum_type_instance.type_name()` instead', + spos) + } } node = ast.TypeOf{ is_type: false diff --git a/vlib/v/slow_tests/keep_args_alive_test.c.v b/vlib/v/slow_tests/keep_args_alive_test.c.v index 93a036896d..6f32353ef7 100644 --- a/vlib/v/slow_tests/keep_args_alive_test.c.v +++ b/vlib/v/slow_tests/keep_args_alive_test.c.v @@ -48,7 +48,7 @@ fn tt(mut sem sync.Semaphore) int { } fn waste_mem(n int, mut sem sync.Semaphore) { - mut m := []voidptr{len: 30} + mut m := []voidptr{len: 30, init: 0} for j := 0; n < 0 || j < n; j++ { i := rand.intn(30) or { 0 } m[i] = unsafe { malloc(10000) } diff --git a/vlib/v/tests/c_structs/cstruct_alias_test.v b/vlib/v/tests/c_structs/cstruct_alias_test.c.v similarity index 100% rename from vlib/v/tests/c_structs/cstruct_alias_test.v rename to vlib/v/tests/c_structs/cstruct_alias_test.c.v diff --git a/vlib/v/tests/c_structs/cstruct_default_value_test.v b/vlib/v/tests/c_structs/cstruct_default_value_test.c.v similarity index 100% rename from vlib/v/tests/c_structs/cstruct_default_value_test.v rename to vlib/v/tests/c_structs/cstruct_default_value_test.c.v diff --git a/vlib/v/tests/c_structs/cstruct_ref_test.v b/vlib/v/tests/c_structs/cstruct_ref_test.c.v similarity index 100% rename from vlib/v/tests/c_structs/cstruct_ref_test.v rename to vlib/v/tests/c_structs/cstruct_ref_test.c.v diff --git a/vlib/v/tests/c_structs/cstruct_str_test.v b/vlib/v/tests/c_structs/cstruct_str_test.c.v similarity index 100% rename from vlib/v/tests/c_structs/cstruct_str_test.v rename to vlib/v/tests/c_structs/cstruct_str_test.c.v diff --git a/vlib/v/tests/c_structs/cstruct_sumtype_test.v b/vlib/v/tests/c_structs/cstruct_sumtype_test.c.v similarity index 100% rename from vlib/v/tests/c_structs/cstruct_sumtype_test.v rename to vlib/v/tests/c_structs/cstruct_sumtype_test.c.v diff --git a/vlib/v/tests/enum_bitfield_64bit_test.v b/vlib/v/tests/enum_bitfield_64bit_test.v index 35b6166a8b..231c18a04d 100644 --- a/vlib/v/tests/enum_bitfield_64bit_test.v +++ b/vlib/v/tests/enum_bitfield_64bit_test.v @@ -30,7 +30,7 @@ fn test_flag_enum_with_64_value_bits() { dump(u64(bb)) assert u64(bb) == 65280 assert '${u64(bb):064b}' == '0000000000000000000000000000000000000000000000001111111100000000' - assert '${bb}' == 'PawnsBoard{.a7 | .b7 | .c7 | .d7 | .e7 | .f7 | .g7 | .h7}' + // assert '${bb}' == 'PawnsBoard{.a7 | .b7 | .c7 | .d7 | .e7 | .f7 | .g7 | .h7}' if false { eprintln('----------------------------------------------') diff --git a/vlib/v/tests/interop_test.v b/vlib/v/tests/interop_test.c.v similarity index 83% rename from vlib/v/tests/interop_test.v rename to vlib/v/tests/interop_test.c.v index f8e13100a1..f2e6f421e9 100644 --- a/vlib/v/tests/interop_test.v +++ b/vlib/v/tests/interop_test.c.v @@ -8,14 +8,9 @@ fn C.b(a &voidptr) fn C.c(a string, b ...string) string fn C.d(a ...int) -fn JS.e(a string, b ...string) int -fn JS.f(a &Foo) - // TODO: Should this be allowed? - fn C.g(string, ...int) fn C.h(&int) -fn JS.i(...string) fn test_null() { np := C.NULL diff --git a/vlib/v/tests/interop_test.js b/vlib/v/tests/interop_test.js new file mode 100644 index 0000000000..c8ff26a420 --- /dev/null +++ b/vlib/v/tests/interop_test.js @@ -0,0 +1,11068 @@ +// Generated by the V compiler + + +var $global = (new Function("return this"))(); +function $ref(value) { if (value instanceof $ref) { return value; } this.val = value; } +$ref.prototype.valueOf = function() { return this.val; } +const $os = require("os"); +const $process = process; +function checkDefine(key) { + if (globalThis.hasOwnProperty(key)) { return !!globalThis[key]; } return false; +} +function BreakException() {} +function ContinueException() {} +function ReturnException(val) { this.val = val; } +globalThis.g_test_oks = 0; +globalThis.g_test_fails = 0; +function Array_rune_arr_eq(a,b) { + if (a.arr.length != b.arr.length) { + return new bool(false); + } + for (let i = 0; i < a.len; ++i) { + if (!vEq(a.arr.get(new int(i)),b.arr.get(new int(i)))) { + return new bool(false); + } + } + return new bool(true); +} + +function Array_int_contains(a,v) { + for (let i = 0; i < a.len; ++i) { + if (vEq(a.arr.get(new int(i)),v)) { + return new bool(true); + } + } + return new bool(false); +} + +function compare_RepIndex_by_idx(a,b) { + if (a.val.idx.valueOf() < b.val.idx.valueOf()) return -1; + else return 1; +} + +function Array_string_contains(a,v) { + for (let i = 0; i < a.len; ++i) { + if (a.arr.get(new int(i)).str == v.str) { + return new bool(true); + } + } + return new bool(false); +} + +function Array_os__ProcessState_contains(a,v) { + for (let i = 0; i < a.len; ++i) { + if (vEq(a.arr.get(new int(i)),v)) { + return new bool(true); + } + } + return new bool(false); +} + +function os__dir_str() { return new string("fn (string) string");} +function os__Signal_str(it) { /* gen_str_for_enum */ + switch(it) { + case os__Signal.hup: return new string("hup"); + case os__Signal.int: return new string("int"); + case os__Signal.quit: return new string("quit"); + case os__Signal.ill: return new string("ill"); + case os__Signal.trap: return new string("trap"); + case os__Signal.abrt: return new string("abrt"); + case os__Signal.bus: return new string("bus"); + case os__Signal.fpe: return new string("fpe"); + case os__Signal.kill: return new string("kill"); + case os__Signal.usr1: return new string("usr1"); + case os__Signal.segv: return new string("segv"); + case os__Signal.usr2: return new string("usr2"); + case os__Signal.pipe: return new string("pipe"); + case os__Signal.alrm: return new string("alrm"); + case os__Signal.term: return new string("term"); + case os__Signal.stkflt: return new string("stkflt"); + case os__Signal.chld: return new string("chld"); + case os__Signal.cont: return new string("cont"); + case os__Signal.stop: return new string("stop"); + case os__Signal.tstp: return new string("tstp"); + case os__Signal.ttin: return new string("ttin"); + case os__Signal.ttou: return new string("ttou"); + case os__Signal.urg: return new string("urg"); + case os__Signal.xcpu: return new string("xcpu"); + case os__Signal.xfsz: return new string("xfsz"); + case os__Signal.vtalrm: return new string("vtalrm"); + case os__Signal.prof: return new string("prof"); + case os__Signal.winch: return new string("winch"); + case os__Signal.poll: return new string("poll"); + case os__Signal.pwr: return new string("pwr"); + case os__Signal.sys: return new string("sys"); + default: return new string("unknown enum value"); + } +} + +let wasmExportObject; +const loadRoutine = async () => { +} +// https://www.npmjs.com/package/fast-deep-equal - 3/3/2021 +const envHasBigInt64Array = typeof BigInt64Array !== 'undefined'; +function vEq(a, b) { + if (a === b) return true; + + if (a && b && typeof a == 'object' && typeof b == 'object') { + if (a.constructor !== b.constructor) return false; + // we want to convert all V types to JS for comparison. + if ('$toJS' in a) + a = a.$toJS(); + + if ('$toJS' in b) + b = b.$toJS(); + + var length, i, keys; + if (Array.isArray(a)) { + length = a.length; + if (length != b.length) return false; + for (i = length; i-- !== 0;) + if (!vEq(a[i], b[i])) return false; + return true; + } + + if (typeof Map != 'undefined') { + if ((a instanceof Map) && (b instanceof Map)) { + if (a.size !== b.size) return false; + for (i of a.entries()) + if (!b.has(i[0])) return false; + for (i of a.entries()) + if (!vEq(i[1], b.get(i[0]))) return false; + return true; + } + + if ((a instanceof Set) && (b instanceof Set)) { + if (a.size !== b.size) return false; + for (i of a.entries()) + if (!b.has(i[0])) return false; + return true; + } + } + if (typeof ArrayBuffer != 'undefined') { + if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { + length = a.length; + if (length != b.length) return false; + for (i = length; i-- !== 0;) + if (a[i] !== b[i]) return false; + return true; + } + } + + if (typeof RegExp != 'undefined') { + if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; + } + if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); + if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); + + keys = Object.keys(a); + length = keys.length; + if (length !== Object.keys(b).length) return false; + + for (i = length; i-- !== 0;) + if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; + + for (i = length; i-- !== 0;) { + var key = keys[i]; + + if (!vEq(a[key], b[key])) return false; + } + + return true; + } + + // true if both NaN, false otherwise + return a!==a && b!==b; +}; + +function $sortComparator(a, b) +{ +a = a.$toJS(); +b = b.$toJS(); +if (a > b) return 1; +if (a < b) return -1; +return 0; + + +} + +/** @namespace strings */ +function strings__Builder(val) { return val; } +/** + * @function + * @param {int} initial_size + * @returns {strings__Builder} +*/ +function strings__new_builder(initial_size) { + try { + return new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u8} data + * @returns {void} +*/ +function strings__Builder_write_byte(b, data) { +b = new $ref(b) + try { + array_push(b.valueOf(),data,false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function strings__Builder_clear(b) { +b = new $ref(b) + try { + /** @type {strings__Builder} */ + b.val = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})).val; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u8} data + * @returns {void} +*/ +function strings__Builder_write_u8(b, data) { +b = new $ref(b) + try { + array_push(b.valueOf(),data,false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u8} data + * @returns {int} +*/ +function strings__Builder_write(b, data) { +b = new $ref(b) + try { + if ((new bool(data.len.valueOf() == new int(0).valueOf())).valueOf()) { + const _tmp1 = new _option({}); + _tmp1.state = new u8(0);_tmp1.data = new int(0) + return _tmp1;} + array_push(b.valueOf(),data.arr.arr,true); + const _tmp2 = new _option({}); + _tmp2.state = new u8(0);_tmp2.data = data.len + return _tmp2;} catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {u8} +*/ +function strings__Builder_byte_at(b, n) { +b = new $ref(b) + try { + { + return b.valueOf().arr.get(new int(n.valueOf())); + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function strings__Builder_write_string(b, s) { +b = new $ref(b) + try { + if ((new bool(s.valueOf() == new string("").valueOf())).valueOf()) { + return; + } + for (const c of s.str.split('').map(c => new u8(c))) { + try { + array_push(b.valueOf(),c,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function strings__Builder_writeln(b, s) { +b = new $ref(b) + try { + if ((new bool(s.valueOf() != new string("").valueOf())).valueOf()) { + strings__Builder_write_string(b.valueOf(),s); + } + array_push(b.valueOf(),new int(10),false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function strings__Builder_str(b) { +b = new $ref(b) + try { + /** @type {string} */ + const s = new string(new string("")); + for (const c of b.val.arr.arr) + s.str += String.fromCharCode(+c) + array_trim(b.valueOf(),new int(0)); + return s; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {string} +*/ +function strings__Builder_cut_last(b, n) { +b = new $ref(b) + try { + /** @type {int} */ + const cut_pos = new int(new int( b.val.len.valueOf() - n.valueOf())); + /** @type {strings__Builder} */ + const x = array_slice(b.valueOf(),cut_pos, b.valueOf().len); + /** @type {string} */ + const res = new string(array_bytestr(x,)); + array_trim(b.valueOf(),cut_pos); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} pos + * @returns {void} +*/ +function strings__Builder_go_back_to(b, pos) { +b = new $ref(b) + try { + array_trim(b.valueOf(),pos); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {void} +*/ +function strings__Builder_go_back(b, n) { +b = new $ref(b) + try { + array_trim(b.valueOf(),new int( b.val.len.valueOf() - n.valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} pos + * @returns {string} +*/ +function strings__Builder_cut_to(b, pos) { +b = new $ref(b) + try { + if ((new bool(pos.valueOf() > b.val.len.valueOf())).valueOf()) { + return new string(""); + } + return strings__Builder_cut_last(b.valueOf(),new int( b.val.len.valueOf() - pos.valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_rune} runes + * @returns {void} +*/ +function strings__Builder_write_runes(b, runes) { +b = new $ref(b) + try { + for (const r of runes) { + try { + /** @type {string} */ + const res = new string(rune_str(r)); + res.str = String.fromCharCode(r.val) + array_push(b.valueOf(),string_bytes(res,).arr.arr,true); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {string} +*/ +function strings__Builder_after(b, n) { +b = new $ref(b) + try { + if ((new bool(n.valueOf() >= b.val.len.valueOf())).valueOf()) { + return new string(""); + } + /** @type {strings__Builder} */ + const x = array_slice(b.valueOf(),n, b.val.len); + return array_bytestr(x,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {string} +*/ +function strings__Builder_last_n(b, n) { +b = new $ref(b) + try { + if ((new bool(n.valueOf() >= b.val.len.valueOf())).valueOf()) { + return new string(""); + } + /** @type {strings__Builder} */ + const x = array_slice(b.valueOf(),new int( b.val.len.valueOf() - n.valueOf()), b.val.len); + return array_bytestr(x,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace strings */ +/* [inline] */ +/** + * @function + * @param {u16} a + * @param {u16} b + * @param {u16} c + * @returns {u16} +*/ +function strings__min(a, b, c) { + try { + /** @type {u16} */ + let m = new u16(a); + if ((new bool(b.valueOf() < m.valueOf())).valueOf()) { + /** @type {u16} */ + m = new u16(b); + } + if ((new bool(c.valueOf() < m.valueOf())).valueOf()) { + /** @type {u16} */ + m = new u16(c); + } + return m; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {string} a + * @param {string} b + * @returns {int} +*/ +function strings__levenshtein_distance(a, b) { + try { + if ((new bool(a.len.valueOf() == new int(0).valueOf())).valueOf()) { + return b.len; + } + if ((new bool(b.len.valueOf() == new int(0).valueOf())).valueOf()) { + return a.len; + } + if ((new bool(a.valueOf() == b.valueOf())).valueOf()) { + return new int(0); + } + /** @type {Array_u16} */ + let row = new array(new array_buffer({arr: (function(length) { + const _tmp3 = []; + for (let it = 0; it < length; it++) { + _tmp3.push(new u16(index)); + }; + return _tmp3; + })(new int( a.len.valueOf() + new int(1).valueOf())),len: new int(new int( a.len.valueOf() + new int(1).valueOf())), cap: new int(new int( a.len.valueOf() + new int(1).valueOf()))})); + for (let i = new int(new int(1)); +new bool(i.valueOf() < new int( b.len.valueOf() + new int(1).valueOf()).valueOf()); i.val ++) { + try { + let prev = new u16(new u16(i)); for (let j = new int(new int(1)); +new bool(j.valueOf() < new int( a.len.valueOf() + new int(1).valueOf()).valueOf()); j.val ++) { + try { + let current = new u16(row.arr.get(new int(new int( j.valueOf() - new int(1).valueOf()).valueOf()))); if ((new bool(new u8(b.str.charCodeAt(new int( i.valueOf() - new int(1).valueOf()))).valueOf() != new u8(a.str.charCodeAt(new int( j.valueOf() - new int(1).valueOf()))).valueOf())).valueOf()) { + current = new u16(strings__min(new u16( row.arr.get(new int(new int( j.valueOf() - new int(1).valueOf()).valueOf())).valueOf() + new int(1).valueOf()), new u16( prev.valueOf() + new int(1).valueOf()), new u16( row.arr.get(new int(j.valueOf())).valueOf() + new int(1).valueOf()))); } + row.arr.set(new int(new int( j.valueOf() - new int(1).valueOf()).valueOf()),new u16(prev)); prev = new u16(current); } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {u16} */ + row.arr.set(new int(a.len.valueOf()),new u16(prev)); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return row.arr.get(new int(a.len.valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @param {string} b + * @returns {f32} +*/ +function strings__levenshtein_distance_percentage(a, b) { + try { + /** @type {int} */ + const d = new int(strings__levenshtein_distance(a, b)); + /** @type {int} */ + const l = new int(((new bool(a.len.valueOf() >= b.len.valueOf())).valueOf() ? a.len : b.len)); + return new f32( (new f32( new f32(1.00).valueOf() - new f32( new f32(d).valueOf() / new f32(l).valueOf()).valueOf())).valueOf() * new f32(100.00).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s1 + * @param {string} s2 + * @returns {f32} +*/ +function strings__dice_coefficient(s1, s2) { + try { + if ((new bool( new bool(s1.len.valueOf() == new int(0).valueOf()).valueOf() || new bool(s2.len.valueOf() == new int(0).valueOf()).valueOf())).valueOf()) { + return new f32(0.0); + } + if ((new bool(s1.valueOf() == s2.valueOf())).valueOf()) { + return new f32(1.0); + } + if ((new bool( new bool(s1.len.valueOf() < new int(2).valueOf()).valueOf() || new bool(s2.len.valueOf() < new int(2).valueOf()).valueOf())).valueOf()) { + return new f32(0.0); + } + /** @type {string} */ + const a = new string(((new bool(s1.len.valueOf() > s2.len.valueOf())).valueOf() ? s1 : s2)); + /** @type {string} */ + const b = new string(((new bool(a.valueOf() == s1.valueOf())).valueOf() ? s2 : s1)); + /** @type {Map_string_int} */ + let first_bigrams = new map( + {}); + for (let i = new int(0); i < new int( a.len.valueOf() - new int(1).valueOf()); i = new int(i + 1)) { + try { + /** @type {string} */ + const bigram = new string(string_slice(a,i, new int_literal( i.valueOf() + new int(2).valueOf()))); + /** @type {int} */ + const q = new int(((first_bigrams.has(bigram.$toJS())).valueOf() ? new int( first_bigrams.get(bigram.$toJS()).valueOf() + new int(1).valueOf()) : new int(1))); + /** @type {int} */ + first_bigrams.length++; + first_bigrams.map[bigram.$toJS()] = new int(q); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {int} */ + let intersection_size = new int(new int(0)); + for (let i = new int(0); i < new int( b.len.valueOf() - new int(1).valueOf()); i = new int(i + 1)) { + try { + /** @type {string} */ + const bigram = new string(string_slice(b,i, new int_literal( i.valueOf() + new int(2).valueOf()))); + /** @type {int} */ + const count = new int(((first_bigrams.has(bigram.$toJS())).valueOf() ? first_bigrams.get(bigram.$toJS()) : new int(0))); + if ((new bool(count.valueOf() > new int(0).valueOf())).valueOf()) { + /** @type {int} */ + first_bigrams.length++; + first_bigrams.map[bigram.$toJS()] = new int(new int( count.valueOf() - new int(1).valueOf())); + intersection_size.val ++; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new f32( (new f32( new f32(2.0).valueOf() * new f32(intersection_size).valueOf())).valueOf() / (new f32( new f32( new f32(a.len).valueOf() + new f32(b.len).valueOf()).valueOf() - new int(2).valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace strings */ +/** + * @function + * @param {u8} c + * @param {int} n + * @returns {string} +*/ +function strings__repeat(c, n) { + try { + if ((new bool(n.valueOf() <= new int(0).valueOf())).valueOf()) { + return new string(""); + } + /** @type {Array_u8} */ + const arr = array_repeat(new array(new array_buffer({arr: [new u8(c)], len: new int(1), cap: new int(1)})),n); + return array_bytestr(arr,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @param {int} n + * @returns {string} +*/ +function strings__repeat_string(s, n) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = s.str.repeat(n.valueOf()) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace strings */ +/** + * @function + * @param {string} input + * @param {u8} start + * @param {u8} end + * @returns {string} +*/ +function strings__find_between_pair_u8(input, start, end) { + try { + /** @type {int} */ + let marks = new int(new int(0)); + /** @type {int} */ + let start_index = new int(new int(-1)); + for (const [i, b] of Array.from(input.str.split('').entries(), ([i, b]) => [i, new u8(b)])) { + try { + if ((new bool(b.valueOf() == start.valueOf())).valueOf()) { + if ((new bool(start_index.valueOf() == new int(-1).valueOf())).valueOf()) { + /** @type {int} */ + start_index = new int(new int( i.valueOf() + new int(1).valueOf())); + } + marks.val ++; + continue; + } + if ((new bool(start_index.valueOf() > new int(0).valueOf())).valueOf()) { + if ((new bool(b.valueOf() == end.valueOf())).valueOf()) { + marks.val --; + if ((new bool(marks.valueOf() == new int(0).valueOf())).valueOf()) { + return string_slice(input,start_index, i); + } + } + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} input + * @param {rune} start + * @param {rune} end + * @returns {string} +*/ +function strings__find_between_pair_rune(input, start, end) { + try { + /** @type {int} */ + let marks = new int(new int(0)); + /** @type {int} */ + let start_index = new int(new int(-1)); + /** @type {Array_rune} */ + const runes = string_runes(input,); + for (const [i, r] of runes.entries()) { + try { + if ((new bool(r.valueOf() == start.valueOf())).valueOf()) { + if ((new bool(start_index.valueOf() == new int(-1).valueOf())).valueOf()) { + /** @type {int} */ + start_index = new int(new int( i.valueOf() + new int(1).valueOf())); + } + marks.val ++; + continue; + } + if ((new bool(start_index.valueOf() > new int(0).valueOf())).valueOf()) { + if ((new bool(r.valueOf() == end.valueOf())).valueOf()) { + marks.val --; + if ((new bool(marks.valueOf() == new int(0).valueOf())).valueOf()) { + return Array_rune_string(array_slice(runes,start_index, i),); + } + } + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} input + * @param {string} start + * @param {string} end + * @returns {string} +*/ +function strings__find_between_pair_string(input, start, end) { + try { + /** @type {int} */ + let start_index = new int(new int(-1)); + /** @type {int} */ + let marks = new int(new int(0)); + /** @type {Array_rune} */ + const start_runes = string_runes(start,); + /** @type {Array_rune} */ + const end_runes = string_runes(end,); + /** @type {Array_rune} */ + const runes = string_runes(input,); + /** @type {int} */ + let i = new int(new int(0)); + for (; +new bool(i.valueOf() < runes.len.valueOf()); i.val ++) { + try { + let start_slice = array_slice(runes,i, new int( i.valueOf() + start_runes.len.valueOf())); if ((new bool(Array_rune_arr_eq(start_slice, start_runes))).valueOf()) { + i = new int(new int( new int( i.valueOf() + start_runes.len.valueOf()).valueOf() - new int(1).valueOf())); if ((new bool(start_index.valueOf() < new int(0).valueOf())).valueOf()) { + start_index = new int(new int( i.valueOf() + new int(1).valueOf())); } + marks.val ++; + continue; + } + if ((new bool(start_index.valueOf() > new int(0).valueOf())).valueOf()) { + let end_slice = array_slice(runes,i, new int( i.valueOf() + end_runes.len.valueOf())); if ((new bool(Array_rune_arr_eq(end_slice, end_runes))).valueOf()) { + marks.val --; + if ((new bool(marks.valueOf() == new int(0).valueOf())).valueOf()) { + return Array_rune_string(array_slice(runes,start_index, i),); + } + i = new int(new int( new int( i.valueOf() + end_runes.len.valueOf()).valueOf() - new int(1).valueOf())); continue; + } + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {Array_string} +*/ +function strings__split_capital(s) { + try { + /** @type {Array_string} */ + let res = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {int} */ + let word_start = new int(new int(0)); + for (const [idx, c] of Array.from(s.str.split('').entries(), ([idx, c]) => [idx, new u8(c)])) { + try { + if ((new bool( new bool(c.valueOf() >= new u8('A').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('Z').valueOf()).valueOf())).valueOf()) { + if ((new bool(word_start.valueOf() != idx.valueOf())).valueOf()) { + array_push(res,string_slice(s,word_start, idx),false); + } + /** @type {int} */ + word_start = new int(idx); + continue; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(word_start.valueOf() != s.len.valueOf())).valueOf()) { + array_push(res,string_slice(s,word_start, s.len),false); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ + function i8(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffffffff) } + i8.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function i8__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function i16(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffffffff) } + i16.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function i16__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function int(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffffffff) } + int.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function int__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function i64(val) { if (val === undefined) { val = BigInt(0); }this.val = BigInt.asIntN(64,BigInt(val)) } + i64.prototype = { + val: BigInt(0), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return this.val }, + }; + + function i64__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function u8(val) { if (val === undefined) { val = new Number(0); }if (typeof(val) == "string") { this.val = val.charCodeAt() } else if (val instanceof string) { this.val = val.str.charCodeAt(); } else { this.val = Math.round(Number(val)) } } + u8.prototype = { + val: new Number(0), + valueOf() { return this.val | 0 }, + toString() { return new string(this.val + "") }, + $toJS() { return +this }, + }; + + function u8__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function u16(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffff) >>> 0 } + u16.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function u16__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function u32(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffffffff) >>> 0 } + u32.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function u32__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function u64(val) { if (val === undefined) { val = BigInt(0); }this.val = BigInt.asUintN(64,BigInt(val)) } + u64.prototype = { + val: BigInt(0), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return this.val }, + }; + + function u64__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function f32(val) { if (val === undefined) { val = new Number(0); }this.val = Number(val) } + f32.prototype = { + val: new Number(0), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return +this }, + }; + + function f32__eq(self,other) { return self.val === other.val; } + function f64(val) { if (val === undefined) { val = new Number(0); }this.val = Number(val) } + f64.prototype = { + val: new Number(0), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return +this }, + }; + + function f64__eq(self,other) { return self.val === other.val; } + function int_literal(val) { if (val === undefined) { val = new Number(0); }this.val = Math.floor(Number(val) & 0xffffffff) } + int_literal.prototype = { + val: new Number(0), + valueOf() { return Number(this.val) }, + toString() { return this.valueOf().toString() }, + $toJS() { return +this }, + }; + + function int_literal__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function float_literal(val) { if (val === undefined) { val = new Number(0); }this.val = Number(val) } + float_literal.prototype = { + val: new Number(0), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return +this }, + }; + + function float_literal__eq(self,other) { return self.val === other.val; } + function bool(val) { if (val === undefined) { val = new Boolean(false); }this.val = val instanceof bool ? val.val : +val !== 0 } + bool.prototype = { + val: new Boolean(false), + valueOf() { return this.val }, + toString() { return this.val.toString() }, + $toJS() { return +this != 0 }, + }; + + function bool__eq(self,other) { return new bool(self.val === other.valueOf()); } + function string(str) { if (str === undefined) { str = new String(""); }this.str = str.toString(); this.len = this.str.length } + string.prototype = { + str: new String(""), + valueOf() { return this.str }, + toString() { return this.str }, + $toJS() { return this.str }, + }; + + function string__eq(self,other) { return new bool(self.str === other.str); } + function map(map) { if (map === undefined) { map = new map({}); }this.map = map; this.length = 0; } + map.prototype = { + map: new map({}), + valueOf() { return this }, + toString() { return this.map.toString() }, + $toJS() { return this.map }, + }; + + function map__eq(self,other) { return new bool(vEq(self, other)); } + function array(arr) { if (arr === undefined) { arr = new array_buffer({}); }this.arr = arr +if (arr.index_start.val != 0 || arr.has_slice.val) { v_makeSlice(this); } } + array.prototype = { + arr: new array_buffer({}), + valueOf() { return this }, + toString() { return JSON.stringify(this.arr.map(it => it.valueOf())) }, + $toJS() { return this.arr }, + }; + + function array__eq(self,other) { return new bool(vEq(self, other)); } + function rune(val) { if (val === undefined) { val = new Number(0); }val = val.valueOf(); if (typeof val == "string") {this.val = val.charCodeAt();} else if (val instanceof string) { this.val = val.str.charCodeAt(); } else { this.val = val | 0 } } + rune.prototype = { + val: new Number(0), + valueOf() { return this.val | 0 }, + toString() { return new string(this.val + "") }, + $toJS() { return +this }, + }; + + function rune__eq(self,other) { return new bool(self.valueOf() === other.valueOf()); } + function any(any) { if (any === undefined) { any = null; }this.val = any } + any.prototype = { + any: null, + valueOf() { return this.val }, + toString() { return "&" + this.val }, + $toJS() { return this.val.$toJS() }, + }; + + function any__eq(self,other) { return new bool(self == other); } + function voidptr(val) { if (val === undefined) { val = null; }this.val = val; } + voidptr.prototype = { + val: null, + valueOf() { return this }, + toString() { return "voidptr(" + this.val + ")" }, + $toJS() { return this.val }, + }; + + function voidptr__eq(self,other) { return this.val === other.val; } +Object.defineProperty(array.prototype,"len", { get: function() {return new int(this.arr.arr.length);}, set: function(l) { this.arr.arr.length = l.valueOf(); } }); +Object.defineProperty(map.prototype,"len", { get: function() {return new int(this.length);}, set: function(l) { } }); +Object.defineProperty(array.prototype,"length", { get: function() {return new int(this.arr.arr.length);}, set: function(l) { this.arr.arr.length = l.valueOf(); } }); +/** + * @constructor + * @param {{arr?: Array, index_start?: int, len?: int, cap?: int, has_slice?: bool}} init +*/ +function array_buffer({ arr = undefined, index_start = new int(0), len = new int(0), cap = new int(0), has_slice = new bool(false) }) { + this.arr = arr + this.index_start = index_start + this.len = len + this.cap = cap + this.has_slice = has_slice +}; +array_buffer.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `array_buffer { arr: ${this["arr"].toString()} , index_start: ${this["index_start"].toString()} , len: ${this["len"].toString()} , cap: ${this["cap"].toString()} , has_slice: ${this["has_slice"].toString()} }` + }, + /** @type {Array} */ + arr: undefined, + /** @type {int} */ + index_start: new int(0), + /** @type {int} */ + len: new int(0), + /** @type {int} */ + cap: new int(0), + /** @type {bool} */ + has_slice: new bool(false), + $toJS() { return this; } + }; + +/** + * @function + * @returns {void} +*/ +function array_buffer_make_copy(a) { +a = new $ref(a) + try { + if ((new bool( new bool(a.val.index_start.valueOf() != new int(0).valueOf()).valueOf() || a.val.has_slice.valueOf())).valueOf()) { + /** @type {Array} */ + let new_arr = makeEmptyJSArray(); + for (let i = new int(0); i < a.val.len; i = new int(i + 1)) { + try { + new_arr.push(a.val.get(i)) + /** @type {int} */ + let x = new int(i); + /** @type {int} */ + x = new int(x); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Array} */ + new_arr = new_arr; + a.val.arr = new_arr + a.val.index_start = new int(0) + a.val.has_slice = new bool(false) + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +array_buffer.prototype.make_copy = function() { return array_buffer_make_copy(this) } +/** + * @function + * @param {int} ix + * @returns {voidptr} +*/ +function array_buffer_get(a, ix) { + try { + /** @type {voidptr} */ + let res = null; + res = a.arr[a.index_start.val + ix.val]; + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} ix + * @param {voidptr} val + * @returns {void} +*/ +function array_buffer_set(a, ix, val) { +a = new $ref(a) + try { + a.val.arr[a.val.index_start.valueOf() + ix.valueOf()] = val; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +array_buffer.prototype.get = function(ix) { return array_buffer_get(this,ix);} +array_buffer.prototype.set = function(ix,val) { array_buffer_set(this,ix,val); } +/** + * @function + * @param {array} arr + * @param {anon_fn_voidptr_voidptr__int} comparator + * @returns {void} +*/ +function v_sort(arr, comparator) { +arr = new $ref(arr) + try { + /** @type {bool} */ + let need_iter = new bool(new bool(true)); + while (+need_iter) { + try { + /** @type {bool} */ + need_iter = new bool(new bool(false)); + for (let i = new int(new int(1)); +new bool(i.valueOf() < arr.val.len.valueOf()); i.val ++) { + try { + if ((new bool(comparator(arr.valueOf().arr.get(new int(i.valueOf())), arr.valueOf().arr.get(new int(new int( i.valueOf() - new int(1).valueOf()).valueOf()))).valueOf() != new int(1).valueOf())).valueOf()) { + let tmp = arr.valueOf().arr.get(new int(i.valueOf())); arr.valueOf().arr.set(new int(i.valueOf()),arr.valueOf().arr.get(new int(new int( i.valueOf() - new int(1).valueOf()).valueOf()))); arr.valueOf().arr.set(new int(new int( i.valueOf() - new int(1).valueOf()).valueOf()),tmp); need_iter = new bool(new bool(true)); } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} index + * @returns {void} +*/ +function array_trim(a, index) { +a = new $ref(a) + try { + if ((new bool(index.valueOf() < a.val.len.valueOf())).valueOf()) { + /** @type {int} */ + a.val.len = new int(index); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +function flatIntoArray(target, source, sourceLength, targetIndex, depth) { +"use strict"; + +for (var sourceIndex = 0; sourceIndex < sourceLength; ++sourceIndex) { +if (sourceIndex in source) { +var element = source[sourceIndex]; +if (depth > 0 && Array.isArray(element)) +targetIndex = flatIntoArray(target, element, element.length, targetIndex, depth - 1); +else { +target[targetIndex] = element; +++targetIndex; +} +} +} +return targetIndex; +} +function flatArray(target,depth) { +var array = target +var length = array.length; +var depthNum = 1; + +if (depth !== undefined) +depthNum = +depth + +var result = [] + +flatIntoArray(result, array, length, 0, depthNum); +return result; +} +/* [unsafe] */ +/** + * @function + * @param {int} count + * @param {int} depth + * @returns {array} +*/ +function array_repeat_to_depth(a, count, depth) { + try { + if ((new bool(count.valueOf() < new int(0).valueOf())).valueOf()) { + builtin__panic (new string(`array.repeat: count is negative: ${int_str(count)}`)); + } + /** @type {array} */ + let arr = empty_array(); + if ((new bool(a.len.valueOf() > new int(0).valueOf())).valueOf()) { + for (let _tmp4 = new int(0); _tmp4 < count; _tmp4 = new int(_tmp4 + 1)) { + try { + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + if ((new bool(depth.valueOf() > new int(0).valueOf())).valueOf()) { + } else { + array_push(arr,array_buffer_get(a.arr,i)); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + return arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {voidptr} +*/ +function array_last(a) { + try { + /** @type {voidptr} */ + let res = null; + res = a.arr.get(new int(a.len-1)); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} ix + * @returns {voidptr} +*/ +function array_get(a, ix) { + try { + /** @type {voidptr} */ + let result = null; + result = a.arr.get(ix) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} count + * @returns {array} +*/ +function array_repeat(a, count) { + try { + { + return array_repeat_to_depth(a,count, new int(0)); + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +function makeEmptyArray() { return new array(new array_buffer({ arr: [], len: new int(0), index_start: new int(0), cap: new int(0) })); } +function makeEmptyJSArray() { return new Array(); } +/** + * @function + * @returns {array} +*/ +function empty_array() { + try { + return makeEmptyArray(); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} i + * @returns {void} +*/ +function array_set_len(a, i) { +a = new $ref(a) + try { + a.arr.arr.length=i + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} compare + * @returns {void} +*/ +function array_sort_with_compare(a, compare) { +a = new $ref(a) + try { + v_sort(a, compare); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} compare + * @returns {void} +*/ +function array_sort_with_compare_old(a, compare) { +a = new $ref(a) + try { + a.val.arr.arr.sort(compare) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function array_sort(a) { +a = new $ref(a) + try { + a.val.arr.arr.sort($sortComparator) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} v + * @returns {int} +*/ +function array_index(a, v) { + try { + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + if (a.arr.get(i).toString() == v.toString()) + { + return i; + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} start + * @param {int} end + * @returns {array} +*/ +function array_slice(a, start, end) { + try { + /** @type {array} */ + let result = a; + let slice = a.arr.arr.slice(start,end) + result = new array(new array_buffer({arr: a.arr.arr, len: new int(slice.length),cap: new int(slice.length),index_start: new int(start),has_slice: new bool(true)})) + a.arr.has_slice = true + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} i + * @param {voidptr} val + * @returns {void} +*/ +function array_insert(a, i, val) { +a = new $ref(a) + try { + a.val.arr.make_copy() + a.val.arr.arr.splice(i,0,val) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} i + * @param {voidptr} val + * @param {int} size + * @returns {void} +*/ +function array_insert_many(a, i, val, size) { +a = new $ref(a) + try { + a.val.arr.arr.splice(i,0,...val.arr.slice(0,+size)) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} val + * @returns {void} +*/ +function array_push(a, val) { +a = new $ref(a) + try { + a.val.arr.make_copy() + if (arguments[2] && arguments[2].valueOf()) {a.val.arr.arr.push(...val)} else { + a.val.arr.arr.push(val) + } + a.val.arr.len.val += 1 + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {array} arr + * @param {anon_fn_voidptr__bool} callback + * @returns {array} +*/ +function v_filter(arr, callback) { + try { + /** @type {array} */ + let filtered = empty_array(); + for (let i = new int(new int(0)); +new bool(i.valueOf() < arr.arr.len.valueOf()); i.val ++) { + try { + if ((callback(array_buffer_get(arr.arr,i))).valueOf()) { + array_push(filtered,array_buffer_get(arr.arr,i)); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return filtered; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {array} arr + * @param {anon_fn_voidptr__voidptr} callback + * @returns {array} +*/ +function v_map(arr, callback) { + try { + /** @type {array} */ + let mapped = empty_array(); + for (let i = new int(new int(0)); +new bool(i.valueOf() < arr.arr.len.valueOf()); i.val ++) { + try { + array_push(mapped,callback(array_buffer_get(arr.arr,i))); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return mapped; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{ix?: int, end?: int, arr?: Array}} init +*/ +function array_iterator({ ix = new int(0), end = new int(0), arr = undefined }) { + this.ix = ix + this.end = end + this.arr = arr +}; +array_iterator.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `array_iterator { ix: ${this["ix"].toString()} , end: ${this["end"].toString()} , arr: ${this["arr"].toString()} }` + }, + /** @type {int} */ + ix: new int(0), + /** @type {int} */ + end: new int(0), + /** @type {Array} */ + arr: undefined, + $toJS() { return this; } + }; + +array_iterator.prototype.next = function () { +if (this.ix.val < this.end.val) { +this.ix.val++; +return {done: false, value: this.arr.arr.get(new int(this.ix.val-1))} +} else { +return {done: true, value: undefined} +} +} +array_iterator.prototype[Symbol.iterator] = function () { return this; } +array.prototype[Symbol.iterator] = function () { return new array_iterator({ix: new int(0),end: new int(this.arr.len),arr: this}); } +array.prototype.entries = function () { let result = []; for (let key = this.arr.index_start.val;key < this.arr.len.val;key++) { result.push([new int(key), this.arr.get(new int(key))]); } return result[Symbol.iterator](); } +array.prototype.map = function(callback) { return v_map(this,callback); } +array.prototype.filter = function(callback) { return v_filter(this,callback); } +Object.defineProperty(array.prototype,'cap',{ get: function () { return this.len; } }) +array.prototype.any = function (value) { +let val ;if (typeof value == 'function') { val = function (x) { return value(x); } } else { val = function (x) { return vEq(x,value); } } +for (let i = 0;i < this.arr.arr.length;i++) +if (val(this.arr.get(i))) +return true; + +return false; +} +array.prototype.all = function (value) { +let val ;if (typeof value == 'function') { val = function (x) { return value(x); } } else { val = function (x) { return vEq(x,value); } } +for (let i = 0;i < this.arr.arr.length;i++) +if (!val(this.arr.get(i))) +return false; + +return true; +} + + +function v_makeSlice(array) { Object.defineProperty(array,'len', {get: function() { return this.arr.len; }, set: function(l) { this.arr.len = l; }}) } +/** + * @function + * @param {int} i + * @returns {void} +*/ +function array_delete(a, i) { +a = new $ref(a) + try { + array_delete_many(a.valueOf(),i, new int(1)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {array} dst + * @param {array} src + * @param {int} count + * @returns {void} +*/ +function arr_copy(dst, src, count) { +dst = new $ref(dst) + try { + for (let i = new int(new int(0)); +new bool(i.valueOf() < count.valueOf()); i.val ++) { + try { + array_buffer_set(dst.val.arr,i, array_buffer_get(src.arr,i)); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} i + * @param {int} size + * @returns {void} +*/ +function array_delete_many(a, i, size) { +a = new $ref(a) + try { + a.val.arr.make_copy() + a.val.arr.arr.splice(i.valueOf(),size.valueOf()) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} val + * @returns {void} +*/ +function array_prepend(a, val) { +a = new $ref(a) + try { + array_insert(a.valueOf(),new int(0), val); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [unsafe] */ +/** + * @function + * @param {voidptr} val + * @param {int} size + * @returns {void} +*/ +function array_prepend_many(a, val, size) { +a = new $ref(a) + try { + array_insert_many(a.valueOf(),new int(0), val, size); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {array} +*/ +function array_reverse(a) { + try { + /** @type {array} */ + let res = empty_array(); + res.arr.arr = Array.from(a.arr).reverse() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function array_reverse_in_place(a) { +a = new $ref(a) + try { + a.val.arr.arr.reverse() + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +array.prototype.$includes = function (elem) { return this.arr.arr.find(function(e) { return vEq(elem,e); }) !== undefined;} +/** + * @function + * @returns {void} +*/ +function array_clear(a) { +a = new $ref(a) + try { + a.val.arr.make_copy() + a.val.arr.arr.clear() + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {anon_fn_int_int__int} iter + * @param {int} accum_start + * @returns {int} +*/ +function array_reduce(a, iter, accum_start) { + try { + /** @type {int} */ + let accum_ = new int(accum_start); + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + /** @type {int} */ + accum_ = new int(iter(accum_, array_get(a,i))); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return accum_; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {voidptr} +*/ +function array_pop(a) { +a = new $ref(a) + try { + /** @type {voidptr} */ + let res = null; + a.val.arr.make_copy() + res = a.val.arr.arr.pop() + a.val.arr.len.val -= 1 + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {voidptr} +*/ +function array_first(a) { + try { + /** @type {voidptr} */ + let res = null; + res = a.arr.get(new int(0)) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +array.prototype.toString = function () { +let res = "[" +for (let i = 0; i < this.arr.arr.length;i++) { +res += this.arr.get(i).toString(); +if (i != this.arr.arr.length-1) +res += ', ' +} +res += ']' +return res; + +} +/** + * @function + * @param {voidptr} key + * @returns {bool} +*/ +function array_contains(a, key) { + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function array_delete_last(a) { +a = new $ref(a) + try { + a.val.arr.arr.pop(); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [unsafe] */ +/** + * @function + * @returns {void} +*/ +function array_free(a) { +a = new $ref(a) + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function array_bytestr(a) { + try { + /** @type {string} */ + const res = new string(new string("")); + for (let i = 0;i < a.arr.len.valueOf();i++) res.str += String.fromCharCode(a.arr.get(new int(i))) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function Array_string_str(a) { + try { + /** @type {strings__Builder} */ + let sb = strings__new_builder(new int( a.len.valueOf() * new int(3).valueOf())); + strings__Builder_write_string(sb,new string("[")); + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + /** @type {string} */ + const val = new string(a.arr.get(new int(i.valueOf()))); + strings__Builder_write_string(sb,new string("'")); + strings__Builder_write_string(sb,val); + strings__Builder_write_string(sb,new string("'")); + if ((new bool(i.valueOf() < new int( a.len.valueOf() - new int(1).valueOf()).valueOf())).valueOf()) { + strings__Builder_write_string(sb,new string(", ")); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + strings__Builder_write_string(sb,new string("]")); + /** @type {string} */ + const res = new string(strings__Builder_str(new $ref(sb))); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array} +*/ +function array_to_js_array(a) { + try { + /** @type {Array} */ + const tmp = Array.prototype.constructor(); + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + tmp.push(array_buffer_get(a.arr,i)); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return tmp; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array} +*/ +function array_to_number_array(a) { + try { + /** @type {Array} */ + const tmp = Array.prototype.constructor(); + for (let i = new int(0); i < a.len; i = new int(i + 1)) { + try { + /** @type {voidptr} */ + const elem = array_buffer_get(a.arr,i); + const _tmp5 = elem; + tmp.push(Number(elem.valueOf())); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return tmp; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u8} arr + * @returns {Uint8Array} +*/ +function uint8_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp6 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Uint8Array} */ + let uint_arr = new Uint8Array(); + uint_arr = new Uint8Array(tmp) + return uint_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u16} arr + * @returns {Uint16Array} +*/ +function uint16_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp7 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Uint16Array} */ + let uint_arr = new Uint16Array(); + uint_arr = new Uint16Array(tmp) + return uint_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u32} arr + * @returns {Uint32Array} +*/ +function uint32_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp8 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Uint32Array} */ + let uint_arr = new Uint32Array(); + uint_arr = new Uint32Array(tmp) + return uint_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_i8} arr + * @returns {Int8Array} +*/ +function int8_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp9 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Int8Array} */ + let int_arr = new Int8Array(); + int_arr = new Int8Array(tmp) + return int_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_i16} arr + * @returns {Int16Array} +*/ +function int16_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp10 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Int16Array} */ + let int_arr = new Int16Array(); + int_arr = new Int16Array(tmp) + return int_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_int} arr + * @returns {Int32Array} +*/ +function int32_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp11 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Int32Array} */ + let int_arr = new Int32Array(); + int_arr = new Int32Array(tmp) + return int_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_i64} arr + * @returns {BigInt64Array} +*/ +function int64_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp12 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {BigInt64Array} */ + let int_arr = new BigInt64Array(); + int_arr = new BigInt64Array(tmp) + return int_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u64} arr + * @returns {BigUint64Array} +*/ +function uint64_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp13 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {BigUint64Array} */ + let int_arr = new BigUint64Array(); + int_arr = new BigUint64Array(tmp) + return int_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_f32} arr + * @returns {Float32Array} +*/ +function float32_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp14 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Float32Array} */ + let float_arr = new Float32Array(); + float_arr = new Float32Array(tmp) + return float_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_f64} arr + * @returns {Float64Array} +*/ +function float64_array(arr) { + try { + let tmp = new Array(); + for (const elem of arr) { + try { + const _tmp15 = elem; + tmp.push(elem.val) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {Float64Array} */ + let float_arr = new Float64Array(); + float_arr = new Float64Array(tmp) + return float_arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/* [noreturn] */ +/** + * @function + * @param {any} s + * @returns {void} +*/ +function js_throw(s) { + try { + throw s + while (true) { + try { + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +let globalPrint, globalWrite; +if (false) +{ +globalPrint = globalThis.print +globalWrite = (typeof globalThis.write === 'function')? write: globalThis.print +} +/** + * @function + * @returns {void} +*/ +function flush_stdout() { + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function flush_stderr() { + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function builtin__println(s) { + try { + if (false) + { + globalPrint(s.str) + } + else + { + console.log(s.str) + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function builtin__print(s) { + try { + if (true) + { + $process.stdout.write(s.str) + } + else if (false) + { + globalWrite(s.str) + } + else + { + builtin__panic (new string("Cannot `print` in a browser, use `println` instead")); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function builtin__eprintln(s) { + try { + if (false) + { + globalPrint(s.str) + } + else + { + console.error(s.str) + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function builtin__eprint(s) { + try { + if (true) + { + $process.stderr.write(s.str) + } + else + { + builtin__panic (new string("Cannot `eprint` in a browser, use `println` instead")); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [noreturn] */ +/** + * @function + * @param {int} c + * @returns {void} +*/ +function builtin__exit(c) { + try { + process.exit(c); + js_throw(new string(`exit(${int_str(c)})`)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} data + * @param {Option} option + * @returns {void} +*/ +function opt_ok(data, option) { + try { + option.state = 0 + option.err = none__ + option.data = data + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} opt + * @returns {string} +*/ +function unwrap(opt) { + try { + /** @type {Option} */ + let o = new Option({}); + o = opt + if ((new bool(o.state.valueOf() != new int(0).valueOf())).valueOf()) { + js_throw(o.err); + } + /** @type {string} */ + let res = new string(new string("")); + res = opt.data + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function js_stacktrace() { + try { + /** @type {string} */ + const stacktrace = new string(new string("")); + let err = new TypeError(); + err.name = 'stacktrace: ' + stacktrace.str = err.stack + return stacktrace; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function print_backtrace() { + try { + builtin__println (js_stacktrace()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} val + * @returns {bool} +*/ +function builtin__isnil(val) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + if (typeof val == 'function') { res.val = false; } else { + val = val instanceof voidptr ? val.valueOf().val : val; + res.val = val === null || val === undefined || val === false || val === 0 || val === BigInt(0) || (val instanceof int ? val.val == 0 : false) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function float_literal_str(f) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str += f.valueOf() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @returns {void} +*/ +function any_toString(a) { + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [noreturn] */ +/** + * @function + * @param {string} s + * @returns {void} +*/ +function builtin__panic(s) { + try { + builtin__eprintln (new string(`V panic: ${s}\n${js_stacktrace()}`)); + builtin__exit(new int(1)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @interface IError + * @typedef IError + * @property {() => string} msg + * @property {() => int} code + */ + +function IError (arg) { return new $ref(arg); } +/** + * @function + * @returns {string} +*/ +function IError_str(err) { + try { + let _tmp16 = undefined; + if (err.val instanceof None__) { + _tmp16 = new string("none"); + + } + else if (err.val instanceof Error) { + _tmp16 = Error_msg(err.valueOf(),); + + } + else if (err.val instanceof MessageError) { + _tmp16 = MessageError_str(err.val); + + } + + else { + /** @type {bool} */ + const old_error_style = new bool(new bool(new voidptr(new $ref(err.msg.str)).valueOf() != new voidptr(new $ref(err.code.str)).valueOf())); + _tmp16 = ((old_error_style).valueOf() ? new string(`${IError_type_name(err,)}: ${err.msg}`) : new string(`${IError_type_name(err,)}: ${err.msg()}`)) + } + return _tmp16; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{}} init +*/ +function Error({ }) { +}; +Error.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `Error {}` + }, + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function Error_msg(err) { + try { + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function Error_code(err) { + try { + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{msg?: string, code?: int}} init +*/ +function MessageError({ msg = new string(""), code = new int(0) }) { + this.msg = msg + this.code = code +}; +MessageError.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `MessageError { msg: "${this["msg"].toString()}", code: ${this["code"].toString()} }` + }, + /** @type {string} */ + msg: new string(""), + /** @type {int} */ + code: new int(0), + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function MessageError_str(err) { + try { + return err.msg; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function MessageError_msg(err) { + try { + return err.msg; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function MessageError_code(err) { + try { + return err.code; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @constant {IError} */ +let none__ = undefined; + +/** + * @constructor + * @param {{}} init +*/ +function None__({ }) { +}; +None__.prototype = { + ...Error.prototype, + ...Object.prototype, + ...Any.prototype, + toString() { + return `None__ {}` + }, + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function None___str(_) { + try { + return new string("none"); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{state?: u8, err?: IError}} init +*/ +function Option({ state = new u8(0), err = none__ }) { + this.state = state + this.err = err +}; +Option.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `Option { state: ${this["state"].toString()} , err: ${this["err"].toString()} }` + }, + /** @type {u8} */ + state: new u8(0), + /** @type {IError} */ + err: undefined, + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function Option_str(o) { + try { + if ((new bool(o.state.valueOf() == new int(0).valueOf())).valueOf()) { + return new string("Option{ ok }"); + } + if ((new bool(o.state.valueOf() == new int(1).valueOf())).valueOf()) { + return new string("Option{ none }"); + } + return new string(`Option{ error: "${IError_str(o.err)}" }`); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{state?: u8, err?: IError}} init +*/ +function _option({ state = new u8(0), err = none__ }) { + this.state = state + this.err = err +}; +_option.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `_option { state: ${this["state"].toString()} , err: ${this["err"].toString()} }` + }, + /** @type {u8} */ + state: new u8(0), + /** @type {IError} */ + err: undefined, + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function _option_str(o) { + try { + if ((new bool(o.state.valueOf() == new int(0).valueOf())).valueOf()) { + return new string("Option{ ok }"); + } + if ((new bool(o.state.valueOf() == new int(1).valueOf())).valueOf()) { + return new string("Option{ none }"); + } + return new string(`Option{ error: "${IError_str(o.err)}" }`); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} x + * @returns {void} +*/ +function trace_error(x) { + try { + builtin__eprintln (new string(`> ${"trace_error"} | ${x}`)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @param {string} message + * @returns {IError} +*/ +function error(message) { + try { + return new $ref((function() { + let _tmp17 = new MessageError({}); + _tmp17.msg = message; + return _tmp17; + })() + ); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @param {string} message + * @param {int} code + * @returns {IError} +*/ +function error_with_code(message, code) { + try { + return new $ref((function() { + let _tmp18 = new MessageError({}); + _tmp18.msg = message; + _tmp18.code = code; + return _tmp18; + })() + ); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [unsafe] */ +/** + * @function + * @param {voidptr} ptr + * @returns {void} +*/ +function free(ptr) { + try { + const _tmp19 = ptr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @returns {bool} +*/ +function u8_is_space(b) { + try { + /** @type {bool} */ + let result = new bool(new bool(false)); + result.val = /^\s*$/.test(String.fromCharCode(b)) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u8_str(c) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = c.val.toString() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u8_ascii_str(c) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = String.fromCharCode(c.val) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} count + * @returns {string} +*/ +function u8_repeat(c, count) { + try { + /** @type {string} */ + let res = new string(new string("")); + for (let _tmp20 = new int(0); _tmp20 < count; _tmp20 = new int(_tmp20 + 1)) { + try { + /** @type {string} */ + res.str = res + new string(u8_ascii_str(c,)); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_digit(c) { + try { + return new bool( new bool(c.valueOf() >= new u8('0').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('9').valueOf()).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_hex_digit(c) { + try { + return new bool( new bool( (new bool( new bool(c.valueOf() >= new u8('0').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('9').valueOf()).valueOf())).valueOf() || (new bool( new bool(c.valueOf() >= new u8('a').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('f').valueOf()).valueOf())).valueOf()).valueOf() || (new bool( new bool(c.valueOf() >= new u8('A').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('F').valueOf()).valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_oct_digit(c) { + try { + return new bool( new bool(c.valueOf() >= new u8('0').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('7').valueOf()).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_bin_digit(c) { + try { + return new bool( new bool(c.valueOf() == new u8('0').valueOf()).valueOf() || new bool(c.valueOf() == new u8('1').valueOf()).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_letter(c) { + try { + return new bool( (new bool( new bool(c.valueOf() >= new u8('a').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('z').valueOf()).valueOf())).valueOf() || (new bool( new bool(c.valueOf() >= new u8('A').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('Z').valueOf()).valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_alnum(c) { + try { + return new bool( new bool( (new bool( new bool(c.valueOf() >= new u8('a').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('z').valueOf()).valueOf())).valueOf() || (new bool( new bool(c.valueOf() >= new u8('A').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('Z').valueOf()).valueOf())).valueOf()).valueOf() || (new bool( new bool(c.valueOf() >= new u8('0').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('9').valueOf()).valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {bool} +*/ +function u8_is_capital(c) { + try { + return new bool( new bool(c.valueOf() >= new u8('A').valueOf()).valueOf() && new bool(c.valueOf() <= new u8('Z').valueOf()).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u8_str_escaped(b) { + try { + /** @type {string} */ + let str = new string(new string("")); + + if (vEq(b,new int(0))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(48); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(7))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(97); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(8))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(98); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(9))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(116); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(10))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(110); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(11))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(118); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(12))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(102); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(13))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(114); + s += String.fromCharCode(96); + return s; })() + )); + } + else if (vEq(b,new int(27))) { + /** @type {string} */ + str = new string(new string((function() { let s = String(); + s += String.fromCharCode(96); + s += String.fromCharCode(92); + s += String.fromCharCode(101); + s += String.fromCharCode(96); + return s; })() + )); + } + else if ((b >= new int(32) && b <= new int(126))) { + /** @type {string} */ + str = new string(u8_ascii_str(b,)); + } + else { + /** @type {string} */ + str = new string(new string( new string("0x").valueOf() + u8_hex(b,).valueOf())); + }; + return str; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @returns {string} +*/ +function f32_str(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val + '' + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function f64_str(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val + '' + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +function byte(val) { return val; } +/** @constant {i8} */ +let min_i8 = undefined; + +/** @constant {i8} */ +let max_i8 = undefined; + +/** @constant {i16} */ +let min_i16 = undefined; + +/** @constant {i16} */ +let max_i16 = undefined; + +/** @constant {i32} */ +let min_i32 = undefined; + +/** @constant {i32} */ +let max_i32 = undefined; + +/** @constant {i32} */ +let min_int = undefined; + +/** @constant {i32} */ +let max_int = undefined; + +/** @constant {i64} */ +let min_i64 = undefined; + +/** @constant {i64} */ +let max_i64 = undefined; + +/** @constant {u8} */ +let min_u8 = undefined; + +/** @constant {u8} */ +let max_u8 = undefined; + +/** @constant {u16} */ +let min_u16 = undefined; + +/** @constant {u16} */ +let max_u16 = undefined; + +/** @constant {u32} */ +let min_u32 = undefined; + +/** @constant {u32} */ +let max_u32 = undefined; + +/** @constant {u64} */ +let min_u64 = undefined; + +/** @constant {u64} */ +let max_u64 = undefined; + +/** + * @function + * @returns {string} +*/ +function i8_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res.str = i.val.toString() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i16_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res.str = i.val.toString() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u16_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res.str = i.val.toString() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function int_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i+'' ) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i64_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i + '') + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u32_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i + '') + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u64_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i + '') + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function bool_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i + '') + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function any_str(i) { + try { + /** @type {string} */ + let res = new string(new string("")); + res = new string( i.toString() ) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function int_literal_str(i) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = i.val.toString() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u64_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u64_hex_full(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i64_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u32_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u16_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i8_hex(x) { + try { + /** @type {string} */ + let res = new string(new string("")); + res.str = x.val.toString(16) + if ((new bool(res.len.valueOf() < new int(2).valueOf())).valueOf()) { + /** @type {string} */ + res = new string(new string( new string("0").valueOf() + res.valueOf())); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i16_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function int_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function int_literal_hex(x) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = x.val.toString(16) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u8_hex(x) { + try { + /** @type {string} */ + let res = new string(new string("")); + res.str = x.val.toString(16) + if ((new bool(res.len.valueOf() < new int(2).valueOf())).valueOf()) { + /** @type {string} */ + res = new string(new string( new string("0").valueOf() + res.valueOf())); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function Array_u8_hex(b) { + try { + /** @type {string} */ + let hex = new string(new string("")); + for (const i of b) { + try { + /** @type {u8} */ + let z = new u8(i); + /** @type {u8} */ + z = new u8(z); + let n0 = i.val >> 4 + hex.str += n0 < 10 ? String.fromCharCode(n0) : String.fromCharCode(n0 + 87) + let n1 = i.val & 0xF + hex.str += n1 < 10 ? String.fromCharCode(n1) : String.fromCharCode(n1 + 87) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return hex; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function int_hex2(i) { + try { + return new string( new string("0x").valueOf() + int_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i8_hex2(i) { + try { + return new string( new string("0x").valueOf() + i8_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i16_hex2(i) { + try { + return new string( new string("0x").valueOf() + i16_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function i64_hex2(i) { + try { + return new string( new string("0x").valueOf() + i64_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u8_hex2(i) { + try { + return new string( new string("0x").valueOf() + u8_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u16_hex2(i) { + try { + return new string( new string("0x").valueOf() + u16_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u32_hex2(i) { + try { + return new string( new string("0x").valueOf() + u32_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function u64_hex2(i) { + try { + return new string( new string("0x").valueOf() + u64_hex(i,).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +function Any(val) { return val; } +/** + * @function + * @param {Any} x + * @returns {bool} +*/ +function js_is_null(x) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + res.val = x === null + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Any} x + * @returns {bool} +*/ +function js_is_undefined(x) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + res.val = x === undefined + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Any} +*/ +function js_null() { + try { + /** @type {Any} */ + let obj = new Any(); + obj = null; + return obj; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Any} +*/ +function js_undefined() { + try { + /** @type {Any} */ + let obj = new Any(); + obj = undefined; + return obj; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_JS__String} arr + * @returns {int} +*/ +function native_str_arr_len(arr) { + try { + /** @type {int} */ + const len = new int(new int(0)); + len = arr.length + return len; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** @namespace builtin */ +/** + * @function + * @returns {node_process} +*/ +function js_node_process() { + try { + return process + return {}; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @param {Any} key + * @param {Any} val + * @returns {void} +*/ +function map_internal_set(m, key, val) { +m = new $ref(m) + try { + if ('$toJS' in key) key = key.$toJS(); + if (!(key in m.val.map)) m.val.length++; + m.val.map[key] = val + const _tmp21 = key; + const _tmp22 = val; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Any} key + * @returns {Any} +*/ +function map_internal_get(m, key) { +m = new $ref(m) + try { + /** @type {Any} */ + let val = new Any(null); + if (typeof key != "string" && '$toJS' in key) key = key.$toJS(); + val = m.val.map[key] + const _tmp23 = key; + return val; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +map.prototype.get = function (key) { return map_internal_get(this,key); } +map.prototype.set = function(key,val) { map_internal_set(this,key,val); } +map.prototype.has = function (key) { if (typeof key != "string" && '$toJS' in key) { key = key.$toJS() } return key in this.map; } +/* [unsafe] */ +/** + * @function + * @param {Any} key + * @returns {void} +*/ +function map_delete(m, key) { +m = new $ref(m) + try { + let k = '$toJS' in key ? key.$toJS() : key; + if (delete m.val.map[k]) { m.val.length--; }; + const _tmp24 = key; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function map_free(m) { +m = new $ref(m) + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +map.prototype.toString = function () { +function fmtKey(key) { return typeof key == 'string' ? '\'' + key + '\'' : key} +let res = '{' +for (const entry of this) { +res += fmtKey(entry[0]) + ': ' + entry[0]; +} +res += '}' +return res; +} +map.prototype.getOrSet = function (key, init) { if (this.map.has(key)) { return this.map.get(key); } else { this.map.set(key,init); return init; } } +/** @namespace builtin */ +/** + * @constructor + * @param {{promise?: Promise}} init +*/ +function _v_Promise({ promise }) { + this.promise = promise +}; +_v_Promise.prototype = { + toString() { + return `_v_Promise { promise: ${this["promise"].toString()} }` + }, + /** @type {Promise} */ + $toJS() { return this; } + }; + +/** + * @function + * @param {anon_fn_js__any} on_fulfilled + * @param {anon_fn_js__any} on_rejected + * @returns {void} +*/ +function Promise_T_JS__Any_then_T_Any(p, on_fulfilled, on_rejected) { + try { + p.promise.then(on_fulfilled, on_rejected); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {anon_fn_js__any} callback + * @returns {Promise_T_JS__Any} +*/ +function Promise_T_JS__Any_catch_T_Any(p, callback) { + try { + /** @type {Promise} */ + const promise = p.promise.v_catch(callback); + return (function() { + let _tmp25 = new _v_Promise({}); + _tmp25.promise = promise; + return _tmp25; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Any} error + * @returns {Promise_T_JS__Any} +*/ +function promise_reject(error) { + try { + /** @type {Promise} */ + const promise = Promise.reject(error); + return (function() { + let _tmp26 = new Promise[JS__Any]({}); + _tmp26.promise = promise; + return _tmp26; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @returns {string} +*/ +function Array_rune_string(ra) { + try { + /** @type {strings__Builder} */ + let sb = strings__new_builder(ra.len); + strings__Builder_write_runes(sb,ra); + /** @type {string} */ + const res = new string(strings__Builder_str(new $ref(sb))); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} count + * @returns {string} +*/ +function rune_repeat(c, count) { + try { + if ((new bool(count.valueOf() < new int(0).valueOf())).valueOf()) { + builtin__panic (new string(`rune.repeat: count is negative: ${int_str(count)}`)); + } else if ((new bool(count.valueOf() == new int(0).valueOf())).valueOf()) { + return new string(""); + } else if ((new bool(count.valueOf() == new int(1).valueOf())).valueOf()) { + return rune_str(c); + } + /** @type {string} */ + const res = new string(new string("")); + res.str = String.fromCharCode(Number(c.val)) + return string_repeat(res,count); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function rune_str(c) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = String.fromCharCode(Number(c.val)) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @returns {Array_rune} +*/ +function string_runes(s) { + try { + /** @type {Array_rune} */ + let runes = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + for (let i = new int(new int(0)); +new bool(i.valueOf() < s.len.valueOf()); i.val ++) { + try { + let r = new rune(new u8('0')); r = new rune(s.str[i.val].charCodeAt()) + array_push(runes,r,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return runes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} a + * @param {int} b + * @returns {string} +*/ +function string_slice(s, a, b) { + try { + return new string(s.str.slice(Number(a.$toJS()), Number(b.$toJS()))); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} start + * @param {int} end + * @returns {string} +*/ +function string_substr(s, start, end) { + try { + return string_slice(s,start, end); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {string} +*/ +function string_after(s, dot) { + try { + return new string(s.str.slice(Number(new int( new int(s.str.lastIndexOf(dot.str)).valueOf() + new int(1).valueOf()).$toJS()), s.str.length)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u8} dot + * @returns {string} +*/ +function string_after_char(s, dot) { + try { + return s; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {string} +*/ +function string_all_after(s, dot) { + try { + /** @type {int} */ + const pos = new int(((new bool(dot.len.valueOf() == new int(0).valueOf())).valueOf() ? new int(-1) : new int(s.str.indexOf(dot.str)))); + if ((new bool(pos.valueOf() == new int(-1).valueOf())).valueOf()) { + return string_clone(s,); + } + return string_slice(s,new int( pos.valueOf() + dot.len.valueOf()), s.len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {string} +*/ +function string_all_after_last(s, dot) { + try { + /** @type {int} */ + const pos = new int(((new bool(dot.len.valueOf() == new int(0).valueOf())).valueOf() ? new int(-1) : new int(s.str.lastIndexOf(dot.str)))); + if ((new bool(pos.valueOf() == new int(-1).valueOf())).valueOf()) { + return string_clone(s,); + } + return string_slice(s,new int( pos.valueOf() + dot.len.valueOf()), s.len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {string} +*/ +function string_all_before(s, dot) { + try { + /** @type {int} */ + const pos = new int(((new bool(dot.len.valueOf() == new int(0).valueOf())).valueOf() ? new int(-1) : new int(s.str.indexOf(dot.str)))); + if ((new bool(pos.valueOf() == new int(-1).valueOf())).valueOf()) { + return string_clone(s,); + } + return string_slice(s,new int(0), pos); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {string} +*/ +function string_all_before_last(s, dot) { + try { + /** @type {int} */ + const pos = new int(((new bool(dot.len.valueOf() == new int(0).valueOf())).valueOf() ? new int(-1) : new int(s.str.lastIndexOf(dot.str)))); + if ((new bool(pos.valueOf() == new int(-1).valueOf())).valueOf()) { + return string_clone(s,); + } + return string_slice(s,new int(0), pos); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {bool} +*/ +function string_bool(s) { + try { + return new bool(s.valueOf() == new string("true").valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} dot + * @returns {Array_string} +*/ +function string_split(s, dot) { + try { + /** @type {Array} */ + const tmparr = s.str.split(dot.str).map((function () { + return function (it) { + /** @type {string} */ + const res = new string(new string("")); + res.str = it + return res; + }})() + ); + const _tmp27 = tmparr; + /** @type {Array_string} */ + let arr = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + arr = new array(new array_buffer({arr: tmparr,index_start: new int(0),len: new int(tmparr.length)})) + return arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_u8} +*/ +function string_bytes(s) { + try { + /** @type {string} */ + const sep = new string(new string("")); + /** @type {Array} */ + const tmparr = s.str.split(sep.str).map((function () { + return function (it) { + return new Any(new u8(it.charCodeAt(Number(new int(0).$toJS())))); + }})() + ); + const _tmp28 = tmparr; + /** @type {Array_u8} */ + let arr = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + arr = new array(new array_buffer({arr: tmparr,index_start: new int(0),len: new int(tmparr.length)})) + return arr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_capitalize(s) { + try { + /** @type {string} */ + const part = new string(new string(s.str.slice(Number(new int(1).$toJS()), s.str.length))); + return new string(s.str.charAt(Number(new int(0).$toJS())).toUpperCase().concat(part.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_clone(s) { + try { + return new string(s.str); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} substr + * @returns {bool} +*/ +function string_contains(s, substr) { + try { + return new bool(s.str.includes(substr.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} chars + * @returns {bool} +*/ +function string_contains_any(s, chars) { + try { + /** @type {string} */ + const sep = new string(new string("")); + /** @type {Array} */ + const res = chars.str.split(sep.str); + for (let i = new int(0); i < new int(res.length); i = new int(i + 1)) { + try { + if ((new bool(s.str.includes(res.at(Number(i.$toJS()))))).valueOf()) { + return new bool(true); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new bool(false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} chars + * @returns {bool} +*/ +function string_contains_only(s, chars) { + try { + if ((new bool(chars.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new bool(false); + } + for (const ch of s.str.split('').map(c => new u8(c))) { + try { + /** @type {int} */ + let res = new int(new int(0)); + for (const c of chars.str.split('').map(c => new u8(c))) { + try { + if ((new bool(ch.valueOf() == c.valueOf())).valueOf()) { + res.val ++; + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(res.valueOf() == new int(0).valueOf())).valueOf()) { + return new bool(false); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new bool(true); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_string} chars + * @returns {bool} +*/ +function string_contains_any_substr(s, chars) { + try { + if ((new bool(chars.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new bool(true); + } + for (const x of chars) { + try { + if ((new bool(s.str.includes(x.str))).valueOf()) { + return new bool(true); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new bool(false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} substr + * @returns {int} +*/ +function string_count(s, substr) { + try { + /** @type {Array} */ + const arr = s.str.split(substr.str); + /** @type {int} */ + const len = new int(new int(arr.length)); + if ((new bool(len.valueOf() == new int(0).valueOf())).valueOf()) { + return new int(0); + } else { + return new int( len.valueOf() - new int(1).valueOf()); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} p + * @returns {bool} +*/ +function string_ends_with(s, p) { + try { + /** @type {bool} */ + let res = new bool(new bool(false)); + res.val = s.str.endsWith(p.str) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} p + * @returns {bool} +*/ +function string_starts_with(s, p) { + try { + return new bool(s.str.startsWith(p.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_string} +*/ +function string_fields(s) { + try { + /** @type {Array_string} */ + let res = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {int} */ + let word_start = new int(new int(0)); + /** @type {int} */ + let word_len = new int(new int(0)); + /** @type {bool} */ + let is_in_word = new bool(new bool(false)); + /** @type {bool} */ + let is_space = new bool(new bool(false)); + for (const [i, c] of Array.from(s.str.split('').entries(), ([i, c]) => [i, new u8(c)])) { + try { + /** @type {bool} */ + is_space = new bool((Array_int_contains(new array(new array_buffer({arr: [new int(new int(32)), new int(new int(9)), new int(new int(10))], len: new int(3), cap: new int(3)})),c))); + if ((!is_space.val ).valueOf()) { + word_len.val ++; + } + if ((new bool( !is_in_word.val .valueOf() && !is_space.val .valueOf())).valueOf()) { + /** @type {int} */ + word_start = new int(i); + /** @type {bool} */ + is_in_word = new bool(new bool(true)); + continue; + } + if ((new bool( is_space.valueOf() && is_in_word.valueOf())).valueOf()) { + array_push(res,string_slice(s,word_start, new int( word_start.valueOf() + word_len.valueOf())),false); + /** @type {bool} */ + is_in_word = new bool(new bool(false)); + /** @type {int} */ + word_len = new int(new int(0)); + /** @type {int} */ + word_start = new int(new int(0)); + continue; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool( is_in_word.valueOf() && new bool(word_len.valueOf() > new int(0).valueOf()).valueOf())).valueOf()) { + array_push(res,string_slice(s,word_start, s.len),false); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} start + * @param {string} end + * @returns {string} +*/ +function string_find_between(s, start, end) { + try { + return new string(s.str.slice(Number(new int( new int(s.str.indexOf(start.str)).valueOf() + new int(1).valueOf()).$toJS()), s.str.indexOf(end.str))); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function string_free(s) { +s = new $ref(s) + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function string_hash(s) { + try { + /** @type {u32} */ + let h = new u32(new int(0)); + if ((new bool( new bool(h.valueOf() == new int(0).valueOf()).valueOf() && new bool(s.len.valueOf() > new int(0).valueOf()).valueOf())).valueOf()) { + for (const c of s.str.split('').map(c => new u8(c))) { + try { + /** @type {u32} */ + h = new u32(new u32( new u32( h.valueOf() * new int(31).valueOf()).valueOf() + new u32(c).valueOf())); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + return new int(h); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function string_int(s) { + try { + /** @type {int} */ + const res = new int(new int(0)); + if (typeof(s) == "string") { res.val = parseInt(s) } + else { res.val = parseInt(s.str) } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {i64} +*/ +function string_i64(s) { + try { + return new i64(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {i8} +*/ +function string_i8(s) { + try { + return new i8(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {i16} +*/ +function string_i16(s) { + try { + return new i16(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {f32} +*/ +function string_f32(s) { + try { + return new f32(parseFloat(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {f64} +*/ +function string_f64(s) { + try { + return new f64(parseFloat(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {u16} +*/ +function string_u16(s) { + try { + return new u16(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {u32} +*/ +function string_u32(s) { + try { + return new u32(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {u64} +*/ +function string_u64(s) { + try { + return new u64(parseInt(s.str)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {u64} +*/ +function string_u8(s) { + try { + /** @type {u8} */ + const res = new u8(new int(0)); + res.val = u8(JS.parseInt(s.str)) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {string} cutset + * @returns {string} +*/ +function string_trim_right(s, cutset) { + try { + if ((new bool( new bool(s.valueOf() == new string("").valueOf()).valueOf() || new bool(cutset.valueOf() == new string("").valueOf()).valueOf())).valueOf()) { + return string_clone(s,); + } + /** @type {int} */ + let pos = new int(new int( s.len.valueOf() - new int(1).valueOf())); + while (+new bool(pos.valueOf() >= new int(0).valueOf())) { + try { + /** @type {bool} */ + let found = new bool(new bool(false)); + for (const cs of cutset.str.split('').map(c => new u8(c))) { + try { + if ((new bool(new u8(s.str.charCodeAt(pos)).valueOf() == cs.valueOf())).valueOf()) { + /** @type {bool} */ + found = new bool(new bool(true)); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((!found.val ).valueOf()) { + break; + } + pos.val --; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(pos.valueOf() < new int(0).valueOf())).valueOf()) { + return new string(""); + } + return string_slice(s,new int(0), new int( pos.valueOf() + new int(1).valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {string} cutset + * @returns {string} +*/ +function string_trim_left(s, cutset) { + try { + if ((new bool( new bool(s.valueOf() == new string("").valueOf()).valueOf() || new bool(cutset.valueOf() == new string("").valueOf()).valueOf())).valueOf()) { + return string_clone(s,); + } + /** @type {int} */ + let pos = new int(new int(0)); + while (+new bool(pos.valueOf() < s.len.valueOf())) { + try { + /** @type {bool} */ + let found = new bool(new bool(false)); + for (const cs of cutset.str.split('').map(c => new u8(c))) { + try { + if ((new bool(new u8(s.str.charCodeAt(pos)).valueOf() == cs.valueOf())).valueOf()) { + /** @type {bool} */ + found = new bool(new bool(true)); + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((!found.val ).valueOf()) { + break; + } + pos.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return string_slice(s,pos, s.len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} str + * @returns {string} +*/ +function string_trim_string_left(s, str) { + try { + if ((string_starts_with(s,str)).valueOf()) { + return string_slice(s,str.len, s.len); + } + return string_clone(s,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} str + * @returns {string} +*/ +function string_trim_string_right(s, str) { + try { + if ((string_ends_with(s,str)).valueOf()) { + return string_slice(s,new int(0), new int( s.len.valueOf() - str.len.valueOf())); + } + return string_clone(s,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @param {string} b + * @returns {int} +*/ +function compare_strings(a, b) { +a = new $ref(a) +b = new $ref(b) + try { + if ((new bool(a.valueOf().valueOf() < b.valueOf().valueOf())).valueOf()) { + return new int(-1); + } + if ((new bool(a.valueOf().valueOf() > b.valueOf().valueOf())).valueOf()) { + return new int(1); + } + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @param {string} b + * @returns {int} +*/ +function compare_strings_reverse(a, b) { +a = new $ref(a) +b = new $ref(b) + try { + if ((new bool(a.valueOf().valueOf() < b.valueOf().valueOf())).valueOf()) { + return new int(1); + } + if ((new bool(a.valueOf().valueOf() > b.valueOf().valueOf())).valueOf()) { + return new int(-1); + } + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @param {string} b + * @returns {int} +*/ +function compare_strings_by_len(a, b) { +a = new $ref(a) +b = new $ref(b) + try { + if ((new bool(a.val.len.valueOf() < b.val.len.valueOf())).valueOf()) { + return new int(-1); + } + if ((new bool(a.val.len.valueOf() > b.val.len.valueOf())).valueOf()) { + return new int(1); + } + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @param {string} b + * @returns {int} +*/ +function compare_lower_strings(a, b) { +a = new $ref(a) +b = new $ref(b) + try { + /** @type {string} */ + const aa = new string(string_to_lower(a.valueOf(),)); + /** @type {string} */ + const bb = new string(string_to_lower(b.valueOf(),)); + return compare_strings(new $ref(aa), new $ref(bb)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} idx + * @returns {u8} +*/ +function string_at(s, idx) { + try { + /** @type {u8} */ + let result = new u8(new int(0)); + result = new u8(s.str.charCodeAt(result)) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_to_lower(s) { + try { + /** @type {string} */ + let result = new string(new string("")); + let str = s.str.toLowerCase() + result = new string(str) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} old_sub + * @param {string} new_sub + * @returns {string} +*/ +function string_replace(s, old_sub, new_sub) { + try { + /** @type {string} */ + let result = new string(new string("")); + result = new string( s.str.replaceAll(old_sub.str, new_sub.str) ) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_to_upper(s) { + try { + /** @type {string} */ + let result = new string(new string("")); + let str = s.str.toUpperCase() + result = new string(str) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function Array_string_sort(s) { +s = new $ref(s) + try { + array_sort_with_compare(s.valueOf(),compare_strings); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function Array_string_sort_ignore_case(s) { +s = new $ref(s) + try { + array_sort_with_compare(s.valueOf(),compare_lower_strings); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function Array_string_sort_by_len(s) { +s = new $ref(s) + try { + array_sort_with_compare(s.valueOf(),compare_strings_by_len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_str(s) { + try { + return string_clone(s,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} count + * @returns {string} +*/ +function string_repeat(s, count) { + try { + /** @type {string} */ + let result = new string(new string("")); + result = new string(s.str.repeat(count)) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +function string_iterator(string) { this.stringIteratorFieldIndex = 0; this.stringIteratorIteratedString = string.str; } +string_iterator.prototype.next = function next() { +var done = true; +var value = undefined; +var position = this.stringIteratorFieldIndex; +if (position !== -1) { +var string = this.stringIteratorIteratedString; +var length = string.length >>> 0; +if (position >= length) { +this.stringIteratorFieldIndex = -1; +} else { +done = false; +var first = string.charCodeAt(position); +if (first < 0xD800 || first > 0xDBFF || position + 1 === length) +value = new u8(string[position]); +else { +value = new u8(string[position]+string[position+1]) +} +this.stringIteratorFieldIndex = position + value.length; +} +} +return { +value, done +} +} +string.prototype[Symbol.iterator] = function () { return new string_iterator(this) } +/** + * @function + * @returns {string} +*/ +function string_strip_margin(s) { + try { + return string_strip_margin_custom(s,new u8('|')); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {u8} del + * @returns {string} +*/ +function string_strip_margin_custom(s, del) { + try { + /** @type {u8} */ + let sep = new u8(del); + if ((u8_is_space(sep,)).valueOf()) { + builtin__eprintln (new string("Warning: `strip_margin` cannot use white-space as a delimiter")); + builtin__eprintln (new string(" Defaulting to `|`")); + /** @type {u8} */ + sep = new u8(new u8('|')); + } + /** @type {Array_u8} */ + let ret = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + ret = new array() + /** @type {int} */ + let count = new int(new int(0)); + for (let i = new int(new int(0)); +new bool(i.valueOf() < s.len.valueOf()); i.val ++) { + try { + if (((Array_int_contains(new array(new array_buffer({arr: [new int(new int(10)), new int(new int(13))], len: new int(2), cap: new int(2)})),new u8(s.str.charCodeAt(i))))).valueOf()) { + { + ret.arr.set(new int(count.valueOf()),new u8(new u8(s.str.charCodeAt(i)))); } + + count.val ++; + if ((new bool( new bool( new bool(new u8(s.str.charCodeAt(i)).valueOf() == new int(13).valueOf()).valueOf() && new bool(i.valueOf() < new int( s.len.valueOf() - new int(1).valueOf()).valueOf()).valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(new int( i.valueOf() + new int(1).valueOf()))).valueOf() == new int(10).valueOf()).valueOf())).valueOf()) { + { + ret.arr.set(new int(count.valueOf()),new u8(new u8(s.str.charCodeAt(new int( i.valueOf() + new int(1).valueOf()))))); } + + count.val ++; + i.val ++; + } + while (+new bool(new u8(s.str.charCodeAt(i)).valueOf() != sep.valueOf())) { + try { + i.val ++; + if ((new bool(i.valueOf() >= s.len.valueOf())).valueOf()) { + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } else { + { + ret.arr.set(new int(count.valueOf()),new u8(new u8(s.str.charCodeAt(i)))); } + + count.val ++; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {string} */ + let result = new string(new string("")); + for (let x of ret.arr) result.str += String.fromCharCode(x.val) + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {string} delim + * @param {int} nth + * @returns {Array_string} +*/ +function string_split_nth(s, delim, nth) { + try { + /** @type {Array_string} */ + let res = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {int} */ + let i = new int(new int(0)); + + if (vEq(delim.len,new int(0))) { + /** @type {int} */ + i = new int(new int(1)); + for (const ch of s.str.split('').map(c => new u8(c))) { + try { + if ((new bool( new bool(nth.valueOf() > new int(0).valueOf()).valueOf() && new bool(i.valueOf() >= nth.valueOf()).valueOf())).valueOf()) { + array_push(res,string_slice(s,i, s.len),false); + break; + } + array_push(res,u8_str(ch),false); + i.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return res; + } + else if (vEq(delim.len,new int(1))) { + /** @type {int} */ + let start = new int(new int(0)); + /** @type {u8} */ + const delim_byte = new u8(new u8(delim.str.charCodeAt(new int(0)))); + while (+new bool(i.valueOf() < s.len.valueOf())) { + try { + if ((new bool(new u8(s.str.charCodeAt(i)).valueOf() == delim_byte.valueOf())).valueOf()) { + /** @type {bool} */ + const was_last = new bool(new bool( new bool(nth.valueOf() > new int(0).valueOf()).valueOf() && new bool(res.len.valueOf() == new int( nth.valueOf() - new int(1).valueOf()).valueOf()).valueOf())); + if ((was_last).valueOf()) { + break; + } + /** @type {string} */ + const val = new string(string_slice(s,start, i)); + array_push(res,val,false); + /** @type {int} */ + start = new int(new int( i.valueOf() + delim.len.valueOf())); + /** @type {int} */ + i = new int(start); + } else { + i.val ++; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool( new bool(nth.valueOf() < new int(1).valueOf()).valueOf() || new bool(res.len.valueOf() < nth.valueOf()).valueOf())).valueOf()) { + array_push(res,string_slice(s,start, s.len),false); + } + return res; + } + else { + /** @type {int} */ + let start = new int(new int(0)); + while (+new bool(i.valueOf() <= s.len.valueOf())) { + try { + /** @type {bool} */ + const is_delim = new bool(new bool( new bool(new int( i.valueOf() + delim.len.valueOf()).valueOf() <= s.len.valueOf()).valueOf() && new bool(string_slice(s,i, new int( i.valueOf() + delim.len.valueOf())).valueOf() == delim.valueOf()).valueOf())); + if ((is_delim).valueOf()) { + /** @type {bool} */ + const was_last = new bool(new bool( new bool(nth.valueOf() > new int(0).valueOf()).valueOf() && new bool(res.len.valueOf() == new int( nth.valueOf() - new int(1).valueOf()).valueOf()).valueOf())); + if ((was_last).valueOf()) { + break; + } + /** @type {string} */ + const val = new string(string_slice(s,start, i)); + array_push(res,val,false); + /** @type {int} */ + start = new int(new int( i.valueOf() + delim.len.valueOf())); + /** @type {int} */ + i = new int(start); + } else { + i.val ++; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool( new bool(nth.valueOf() < new int(1).valueOf()).valueOf() || new bool(res.len.valueOf() < nth.valueOf()).valueOf())).valueOf()) { + array_push(res,string_slice(s,start, s.len),false); + } + return res; + }; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{idx?: int, val_idx?: int}} init +*/ +function RepIndex({ idx = new int(0), val_idx = new int(0) }) { + this.idx = idx + this.val_idx = val_idx +}; +RepIndex.prototype = { + ...Object.prototype, + ...Any.prototype, + toString() { + return `RepIndex { idx: ${this["idx"].toString()} , val_idx: ${this["val_idx"].toString()} }` + }, + /** @type {int} */ + idx: new int(0), + /** @type {int} */ + val_idx: new int(0), + $toJS() { return this; } + }; + +/* [direct_array_access] */ +/** + * @function + * @param {Array_string} vals + * @returns {string} +*/ +function string_replace_each(s, vals) { + try { + if ((new bool( new bool(s.len.valueOf() == new int(0).valueOf()).valueOf() || new bool(vals.len.valueOf() == new int(0).valueOf()).valueOf())).valueOf()) { + return string_clone(s,); + } + if ((new bool(new int( vals.len.valueOf() % new int(2).valueOf()).valueOf() != new int(0).valueOf())).valueOf()) { + builtin__eprintln (new string("string.replace_each(): odd number of strings")); + return string_clone(s,); + } + /** @type {Array_RepIndex} */ + let idxs = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {int} */ + let idx = new int(new int(0)); + /** @type {int} */ + let new_len = new int(s.len); + /** @type {string} */ + const s_ = new string(string_clone(s,)); + function setCharAt(str,index,chr) { + if(index > str.length-1) return str; + return str.substring(0,index) + chr + str.substring(index+1); + } + for (let rep_i = new int(new int(0)); +new bool(rep_i.valueOf() < vals.len.valueOf()); rep_i = new int(new int( rep_i.valueOf() + new int(2).valueOf()))) { + try { + let rep = new string(vals.arr.get(new int(rep_i.valueOf()))); let with_ = new string(vals.arr.get(new int(new int( rep_i.valueOf() + new int(1).valueOf()).valueOf()))); with_ = new string(with_); while (true) { + try { + idx = new int(string_index_after(s_,rep, idx)); if ((new bool(idx.valueOf() == new int(-1).valueOf())).valueOf()) { + break; + } + for (let i = new int(0); i < rep.len; i = new int(i + 1)) { + try { + /** @type {int} */ + let j_ = new int(i); + /** @type {int} */ + j_ = new int(j_); + s_.str = setCharAt(s_.str,idx + i, String.fromCharCode(127)) + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {RepIndex} */ + const rep_idx = (function() { + let _tmp29 = new RepIndex({}); + _tmp29.idx = new int(0); + _tmp29.val_idx = new int(0); + return _tmp29; + })() + ; + rep_idx.idx = idx.val + rep_idx.val_idx = new int(rep_i.val) + array_push(idxs,rep_idx,false); + /** @type {int} */ + idx.val = Math.floor(idx + new int(rep.len)); + /** @type {int} */ + new_len.val = Math.floor(new_len + new int(new int( with_.len.valueOf() - rep.len.valueOf()))); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(idxs.len.valueOf() == new int(0).valueOf())).valueOf()) { + return string_clone(s,); + } +v_sort(idxs,compare_RepIndex_by_idx); + /** @type {string} */ + let b = new string(new string("")); + for (let i = 0; i < new_len.val;i++) b.str += String.fromCharCode(127) + /** @type {int} */ + new_len = new int(new_len); + /** @type {int} */ + let idx_pos = new int(new int(0)); + /** @type {RepIndex} */ + let cur_idx = idxs.arr.get(new int(idx_pos.valueOf())); + /** @type {int} */ + let b_i = new int(new int(0)); + for (let i = new int(new int(0)); +new bool(i.valueOf() < s.len.valueOf()); i.val ++) { + try { + if ((new bool(i.valueOf() == cur_idx.idx.valueOf())).valueOf()) { + let rep = new string(vals.arr.get(new int(cur_idx.val_idx.valueOf()))); let with_ = new string(vals.arr.get(new int(new int( cur_idx.val_idx.valueOf() + new int(1).valueOf()).valueOf()))); for (let j = new int(0); j < with_.len; j = new int(j + 1)) { + try { + /** @type {int} */ + let j_ = new int(j); + /** @type {int} */ + j_ = new int(j_); + b.str = setCharAt(b.str,b_i, with_.str[j]) + b_i.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {int} */ + i.val = Math.floor(i + new int(new int( rep.len.valueOf() - new int(1).valueOf()))); + idx_pos.val ++; + if ((new bool(idx_pos.valueOf() < idxs.len.valueOf())).valueOf()) { + /** @type {RepIndex} */ + cur_idx = idxs.arr.get(new int(idx_pos.valueOf())); + } + } else { + b.str = setCharAt(b.str,b_i,s.str[i]) //b.str[b_i] = s.str[i] + b_i.val ++; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return b; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} p + * @returns {int} +*/ +function string_index_last_(s, p) { + try { + if ((new bool( new bool(p.len.valueOf() > s.len.valueOf()).valueOf() || new bool(p.len.valueOf() == new int(0).valueOf()).valueOf())).valueOf()) { + return new int(-1); + } + /** @type {int} */ + let i = new int(new int( s.len.valueOf() - p.len.valueOf())); + while (+new bool(i.valueOf() >= new int(0).valueOf())) { + try { + /** @type {int} */ + let j = new int(new int(0)); + while (+new bool( new bool(j.valueOf() < p.len.valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(new int( i.valueOf() + j.valueOf()))).valueOf() == new u8(p.str.charCodeAt(j)).valueOf()).valueOf())) { + try { + j.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(j.valueOf() == p.len.valueOf())).valueOf()) { + return i; + } + i.val --; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [deprecated] */ +/** + * @function + * @deprecated + * @param {string} needle + * @returns {int} +*/ +function string_index_last(s, needle) { + try { + const _tmp30 = new _option({}); + _tmp30.state = new u8(0);_tmp30.data = (function(){ + try { + return unwrap(string_last_index(s,needle)) + } catch(err) { + } + })() + return _tmp30;} catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @param {string} needle + * @returns {int} +*/ +function string_last_index(s, needle) { + try { + /** @type {int} */ + const idx = new int(string_index_last_(s,needle)); + if ((new bool(idx.valueOf() == new int(-1).valueOf())).valueOf()) { + return new Option({ state: new u8(2),err: none__}); + } + const _tmp31 = new _option({}); + _tmp31.state = new u8(0);_tmp31.data = idx + return _tmp31;} catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_trim_space(s) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = s.str.trim() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} p + * @param {int} start + * @returns {int} +*/ +function string_index_after(s, p, start) { + try { + if ((new bool(p.len.valueOf() > s.len.valueOf())).valueOf()) { + return new int(-1); + } + /** @type {int} */ + let strt = new int(start); + if ((new bool(start.valueOf() < new int(0).valueOf())).valueOf()) { + /** @type {int} */ + strt = new int(new int(0)); + } + if ((new bool(start.valueOf() >= s.len.valueOf())).valueOf()) { + return new int(-1); + } + /** @type {int} */ + let i = new int(strt); + while (+new bool(i.valueOf() < s.len.valueOf())) { + try { + /** @type {int} */ + let j = new int(new int(0)); + /** @type {int} */ + let ii = new int(i); + while (+new bool( new bool(j.valueOf() < p.len.valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(ii)).valueOf() == new u8(p.str.charCodeAt(j)).valueOf()).valueOf())) { + try { + j.val ++; + ii.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(j.valueOf() == p.len.valueOf())).valueOf()) { + return i; + } + i.val ++; + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_string} +*/ +function string_split_into_lines(s) { + try { + /** @type {Array_string} */ + let res = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + if ((new bool(s.len.valueOf() == new int(0).valueOf())).valueOf()) { + return res; + } + res.arr.arr = s.str.split(/\r?\n|\r/) + if (res.arr.arr[res.arr.arr.length-1] == "") res.arr.arr.pop(); + res.arr.len = new int(res.arr.arr.length); + res.arr.cap = new int(res.arr.arr.length); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} rep + * @param {string} with_ + * @returns {string} +*/ +function string_replace_once(s, rep, with_) { + try { + /** @type {string} */ + const s2 = new string(new string("")); + s2.val = s.str.replace(rep.str,with_.str) + return s2; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_title(s) { + try { + /** @type {Array_string} */ + const words = string_split(s,new string(" ")); + /** @type {Array_string} */ + let tit = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + for (const word of words) { + try { + array_push(tit,string_capitalize(word,),false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {string} */ + const title = new string(Array_string_join(tit,new string(" "))); + return title; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} chars + * @returns {int} +*/ +function string_index_any(s, chars) { + try { + for (const [i, ss] of Array.from(s.str.split('').entries(), ([i, ss]) => [i, new u8(ss)])) { + try { + for (const c of chars.str.split('').map(c => new u8(c))) { + try { + if ((new bool(c.valueOf() == ss.valueOf())).valueOf()) { + return i; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} max + * @returns {string} +*/ +function string_limit(s, max) { + try { + /** @type {Array_rune} */ + const u = string_runes(s,); + if ((new bool(u.len.valueOf() <= max.valueOf())).valueOf()) { + return string_clone(s,); + } + return Array_rune_string(array_slice(u,new int(0), max),); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {bool} +*/ +function string_is_title(s) { + try { + /** @type {Array_string} */ + const words = string_split(s,new string(" ")); + for (const word of words) { + try { + if ((!string_is_capital(word,).val ).valueOf()) { + return new bool(false); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new bool(true); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @returns {bool} +*/ +function string_is_capital(s) { + try { + if ((new bool( new bool(s.len.valueOf() == new int(0).valueOf()).valueOf() || !(new bool( new bool(new u8(s.str.charCodeAt(new int(0))).valueOf() >= new u8('A').valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(new int(0))).valueOf() <= new u8('Z').valueOf()).valueOf())).val .valueOf())).valueOf()) { + return new bool(false); + } + for (let i = new int(1); i < s.len; i = new int(i + 1)) { + try { + if ((new bool( new bool(new u8(s.str.charCodeAt(i)).valueOf() >= new u8('A').valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(i)).valueOf() <= new u8('Z').valueOf()).valueOf())).valueOf()) { + return new bool(false); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new bool(true); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @returns {bool} +*/ +function string_starts_with_capital(s) { + try { + if ((new bool( new bool(s.len.valueOf() == new int(0).valueOf()).valueOf() || !(new bool( new bool(new u8(s.str.charCodeAt(new int(0))).valueOf() >= new u8('A').valueOf()).valueOf() && new bool(new u8(s.str.charCodeAt(new int(0))).valueOf() <= new u8('Z').valueOf()).valueOf())).val .valueOf())).valueOf()) { + return new bool(false); + } + return new bool(true); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {bool} +*/ +function string_is_upper(s) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + res.val = s.str == s.str.toUpperCase() && s.str != s.str.toLowerCase() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {bool} +*/ +function string_is_lower(s) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + res.val = s.str == s.str.toLowerCase() && s.str != s.str.toUpperCase() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function string_reverse(s) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = [...s.str].reverse().join('') + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cutset + * @returns {string} +*/ +function string_trim(s, cutset) { + try { + if ((new bool( new bool(s.valueOf() == new string("").valueOf()).valueOf() || new bool(cutset.valueOf() == new string("").valueOf()).valueOf())).valueOf()) { + return string_clone(s,); + } + /** @type {int} */ + let pos_left = new int(new int(0)); + /** @type {int} */ + let pos_right = new int(new int( s.len.valueOf() - new int(1).valueOf())); + /** @type {bool} */ + let cs_match = new bool(new bool(true)); + while (+new bool( new bool( new bool(pos_left.valueOf() <= s.len.valueOf()).valueOf() && new bool(pos_right.valueOf() >= new int(-1).valueOf()).valueOf()).valueOf() && cs_match.valueOf())) { + try { + /** @type {bool} */ + cs_match = new bool(new bool(false)); + for (const cs of cutset.str.split('').map(c => new u8(c))) { + try { + if ((new bool(new u8(s.str.charCodeAt(pos_left)).valueOf() == cs.valueOf())).valueOf()) { + pos_left.val ++; + /** @type {bool} */ + cs_match = new bool(new bool(true)); + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + for (const cs of cutset.str.split('').map(c => new u8(c))) { + try { + if ((new bool(new u8(s.str.charCodeAt(pos_right)).valueOf() == cs.valueOf())).valueOf()) { + pos_right.val --; + /** @type {bool} */ + cs_match = new bool(new bool(true)); + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(pos_left.valueOf() > pos_right.valueOf())).valueOf()) { + return new string(""); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return string_substr(s,pos_left, new int( pos_right.valueOf() + new int(1).valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} sep + * @returns {string} +*/ +function Array_string_join(s, sep) { + try { + /** @type {string} */ + let res = new string(new string("")); + for (const [i, str] of s.entries()) { + try { + /** @type {string} */ + res.str = res + new string(str); + if ((new bool(i.valueOf() != new int( s.len.valueOf() - new int(1).valueOf()).valueOf())).valueOf()) { + /** @type {string} */ + res.str = res + new string(sep); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +Object.defineProperty(string.prototype,"len", { get: function() {return new int(new TextEncoder().encode(this.str).length);}, set: function(l) {/* ignore */ } }); +/** + * @function + * @param {string} search + * @returns {int} +*/ +function string_index(s, search) { + try { + /** @type {int} */ + const res = new int(new int(0)); + res.val = s.str.indexOf(search) + if ((new bool(res.valueOf() == new int(-1).valueOf())).valueOf()) { + return new Option({ state: new u8(2),err: none__}); + } + const _tmp32 = new _option({}); + _tmp32.state = new u8(0);_tmp32.data = res + return _tmp32;} catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {u8} c + * @returns {int} +*/ +function string_index_u8_last(s, c) { + try { + for (let i = new int(new int( s.len.valueOf() - new int(1).valueOf())); +new bool(i.valueOf() >= new int(0).valueOf()); i.val --) { + try { + if ((new bool(new u8(s.str.charCodeAt(i)).valueOf() == c.valueOf())).valueOf()) { + return i; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [deprecated] */ +/* [deprecated_after] */ +/* [inline] */ +/** + * @function + * @deprecated + * @param {u8} c + * @returns {int} +*/ +function string_last_index_u8(s, c) { + try { + return string_index_u8_last(s,c); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function string_utf32_code(_rune) { + try { + /** @type {int} */ + const res = new int(new int(0)); + res.val = s.str.charCodeAt() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {String} jsstr + * @returns {string} +*/ +function tos(jsstr) { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = jsstr + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} a + * @returns {int} +*/ +function string_compare(s, a) { + try { + /** @type {int} */ + const min_len = new int(((new bool(s.len.valueOf() < a.len.valueOf())).valueOf() ? s.len : a.len)); + for (let i = new int(0); i < min_len; i = new int(i + 1)) { + try { + if ((new bool(new u8(s.str.charCodeAt(i)).valueOf() < new u8(a.str.charCodeAt(i)).valueOf())).valueOf()) { + return new int(-1); + } + if ((new bool(new u8(s.str.charCodeAt(i)).valueOf() > new u8(a.str.charCodeAt(i)).valueOf())).valueOf()) { + return new int(1); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(s.len.valueOf() < a.len.valueOf())).valueOf()) { + return new int(-1); + } + if ((new bool(s.len.valueOf() > a.len.valueOf())).valueOf()) { + return new int(1); + } + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace builtin */ +/** + * @function + * @param {string} s + * @returns {int} +*/ +function utf8_str_visible_length(s) { + try { + /** @type {int} */ + const res = new int(new int(0)); + res.val = s.str.length; + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {int} +*/ +function utf8_str_len(s) { + try { + return s.len; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u8} b + * @returns {int} +*/ +function utf8_char_len(b) { + try { + return new int_literal( (new int_literal( (new u8( new int(0xe5000000).valueOf() >> (new u8( (new u8( b.valueOf() >> new int(3).valueOf())).valueOf() & new int(0x1e).valueOf())).valueOf())).valueOf() & new int(3).valueOf())).valueOf() + new int(1).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace strings.textscanner */ +/** + * @constructor + * @param {{input?: string, ilen?: int, pos?: int}} init +*/ +function strings__textscanner__TextScanner({ input = new string(""), ilen = new int(0), pos = new int(0) }) { + this.input = input + this.ilen = ilen + this.pos = pos +}; +strings__textscanner__TextScanner.prototype = { + toString() { + return `strings__textscanner__TextScanner { input: "${this["input"].toString()}", ilen: ${this["ilen"].toString()} , pos: ${this["pos"].toString()} }` + }, + /** @type {string} */ + input: new string(""), + /** @type {int} */ + ilen: new int(0), + /** @type {int} */ + pos: new int(0), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} input + * @returns {strings__textscanner__TextScanner} +*/ +function strings__textscanner__new(input) { + try { + return (function() { + let _tmp33 = new strings__textscanner__TextScanner({}); + _tmp33.input = input; + _tmp33.ilen = input.len; + return _tmp33; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [unsafe] */ +/** + * @function + * @returns {void} +*/ +function strings__textscanner__TextScanner_free(ss) { +ss = new $ref(ss) + try { + string_free(ss.val.input,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {int} +*/ +function strings__textscanner__TextScanner_remaining(ss) { +ss = new $ref(ss) + try { + return new int( ss.val.ilen.valueOf() - ss.val.pos.valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @returns {int} +*/ +function strings__textscanner__TextScanner_next(ss) { +ss = new $ref(ss) + try { + if ((new bool(ss.val.pos.valueOf() < ss.val.ilen.valueOf())).valueOf()) { + /** @type {int} */ + const opos = new int(ss.val.pos); + ss.val.pos.val ++; + return new u8(ss.val.input.str.charCodeAt(opos)); + } + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {void} +*/ +function strings__textscanner__TextScanner_skip(ss) { +ss = new $ref(ss) + try { + if ((new bool(ss.val.pos.valueOf() < ss.val.ilen.valueOf())).valueOf()) { + ss.val.pos.val ++; + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @param {int} n + * @returns {void} +*/ +function strings__textscanner__TextScanner_skip_n(ss, n) { +ss = new $ref(ss) + try { + /** @type {int} */ + ss.val.pos.val = Math.floor(ss.val.pos + new int(n)); + if ((new bool(ss.val.pos.valueOf() > ss.val.ilen.valueOf())).valueOf()) { + /** @type {int} */ + ss.val.pos = new int(ss.val.ilen); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @returns {int} +*/ +function strings__textscanner__TextScanner_peek(ss) { +ss = new $ref(ss) + try { + if ((new bool(ss.val.pos.valueOf() < ss.val.ilen.valueOf())).valueOf()) { + return new u8(ss.val.input.str.charCodeAt(ss.val.pos)); + } + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @param {int} n + * @returns {int} +*/ +function strings__textscanner__TextScanner_peek_n(ss, n) { +ss = new $ref(ss) + try { + if ((new bool(new int( ss.val.pos.valueOf() + n.valueOf()).valueOf() < ss.val.ilen.valueOf())).valueOf()) { + return new u8(ss.val.input.str.charCodeAt(new int( ss.val.pos.valueOf() + n.valueOf()))); + } + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [inline] */ +/** + * @function + * @returns {void} +*/ +function strings__textscanner__TextScanner_back(ss) { +ss = new $ref(ss) + try { + if ((new bool(ss.val.pos.valueOf() > new int(0).valueOf())).valueOf()) { + ss.val.pos.val --; + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} n + * @returns {void} +*/ +function strings__textscanner__TextScanner_back_n(ss, n) { +ss = new $ref(ss) + try { + /** @type {int} */ + ss.val.pos.val = Math.floor(ss.val.pos - new int(n)); + if ((new bool(ss.val.pos.valueOf() < new int(0).valueOf())).valueOf()) { + /** @type {int} */ + ss.val.pos = new int(new int(0)); + } + if ((new bool(ss.val.pos.valueOf() > ss.val.ilen.valueOf())).valueOf()) { + /** @type {int} */ + ss.val.pos = new int(ss.val.ilen); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @returns {int} +*/ +function strings__textscanner__TextScanner_peek_back(ss) { +ss = new $ref(ss) + try { + return strings__textscanner__TextScanner_peek_back_n(ss.valueOf(),new int(1)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @param {int} n + * @returns {int} +*/ +function strings__textscanner__TextScanner_peek_back_n(ss, n) { +ss = new $ref(ss) + try { + /** @type {int} */ + const offset = new int(new int( n.valueOf() + new int(1).valueOf())); + if ((new bool(ss.val.pos.valueOf() >= offset.valueOf())).valueOf()) { + return new u8(ss.val.input.str.charCodeAt(new int( ss.val.pos.valueOf() - offset.valueOf()))); + } + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/* [inline] */ +/** + * @function + * @returns {int} +*/ +function strings__textscanner__TextScanner_current(ss) { +ss = new $ref(ss) + try { + if ((new bool(ss.val.pos.valueOf() > new int(0).valueOf())).valueOf()) { + return new u8(ss.val.input.str.charCodeAt(new int( ss.val.pos.valueOf() - new int(1).valueOf()))); + } + return new int(-1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function strings__textscanner__TextScanner_reset(ss) { +ss = new $ref(ss) + try { + /** @type {int} */ + ss.val.pos = new int(new int(0)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function strings__textscanner__TextScanner_goto_end(ss) { +ss = new $ref(ss) + try { + /** @type {int} */ + ss.val.pos = new int(ss.val.ilen); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** + * @function + * @param {string} cut_word + * @returns {Array_string} +*/ +function os__args_after(cut_word) { + try { + if ((new bool(os__args.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + } + /** @type {Array_string} */ + let cargs = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + if ((!(Array_string_contains(os__args,cut_word).valueOf())).valueOf()) { + /** @type {Array_string} */ + cargs = array_clone(os__args,); + } else { + /** @type {bool} */ + let found = new bool(new bool(false)); + array_push(cargs,os__args.arr.get(new int(new int(0).valueOf())),false); + for (const a of array_slice(os__args,new int(1), os__args.len)) { + try { + if ((new bool(a.valueOf() == cut_word.valueOf())).valueOf()) { + /** @type {bool} */ + found = new bool(new bool(true)); + continue; + } + if ((!found.val ).valueOf()) { + continue; + } + array_push(cargs,a,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + return cargs; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cut_word + * @returns {Array_string} +*/ +function os__args_before(cut_word) { + try { + if ((new bool(os__args.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + } + /** @type {Array_string} */ + let cargs = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + if ((!(Array_string_contains(os__args,cut_word).valueOf())).valueOf()) { + /** @type {Array_string} */ + cargs = array_clone(os__args,); + } else { + array_push(cargs,os__args.arr.get(new int(new int(0).valueOf())),false); + for (const a of array_slice(os__args,new int(1), os__args.len)) { + try { + if ((new bool(a.valueOf() == cut_word.valueOf())).valueOf()) { + break; + } + array_push(cargs,a,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + return cargs; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** @namespace os */ +if (true) +{ +global.$ENV = $process.env +} +else +{ +const global = $global; +global.$ENV = {} +} +/** + * @function + * @param {string} key + * @param {string} val + * @param {bool} overwrite + * @returns {void} +*/ +function os__setenv(key, val, overwrite) { + try { + if ($ENV[key] && !(overwrite.valueOf())) return; + $ENV[key] = val + ''; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} key + * @returns {string} +*/ +function os__getenv(key) { + try { + /** @type {string} */ + let res = new string(new string("")); + if ($ENV[key]) res = new string($ENV[key]) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} key + * @returns {string} +*/ +function os__getenv_opt(key) { + try { + if (!$ENV[key]) return none__; + /** @type {string} */ + let res = new string(new string("")); + if ($ENV[key]) res = new string($ENV[key]); + const _tmp34 = new _option({}); + _tmp34.state = new u8(0);_tmp34.data = res + return _tmp34;} catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} name + * @returns {int} +*/ +function os__unsetenv(name) { + try { + $ENV[name] = "" + return new int(1); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Map_string_string} +*/ +function os__environ() { + try { + /** @type {Map_string_string} */ + let res = new map( + {}); + for (const key in $ENV) { + res.map.set(key,$ENV[key]) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** + * @constructor + * @param {{fd?: int, is_opened?: bool}} init +*/ +function os__File({ fd = new int(0), is_opened = new bool(false) }) { + this.fd = fd + this.is_opened = is_opened +}; +os__File.prototype = { + toString() { + return `os__File { fd: ${this["fd"].toString()} , is_opened: ${this["is_opened"].toString()} }` + }, + /** @type {int} */ + fd: new int(0), + /** @type {bool} */ + is_opened: new bool(false), + $toJS() { return this; } + }; + +if (!false) +{ +const $buffer = require('buffer'); +} +/** + * @function + * @param {string} path + * @param {string} mode + * @param {...Array_int} options + * @returns {os__File} +*/ +function os__open_file(path, mode, ...options) { +options = new array(new array_buffer({arr: options,len: new int(options.length),index_start: new int(0)})); + try { + /** @type {os__File} */ + let res = new os__File({}); + if (true) + { + if (!options) { options = new array([]); } + let permissions = 0o666 + if (options.arr.length > 0) { permissions = options.arr[0]; } + try { + res.fd = new int($fs.openSync(''+path,''+mode,permissions)) + } catch (e) { + return error(new string('' + e)); + } + /** @type {bool} */ + res.is_opened = new bool(new bool(true)); + } + else + { + error(new string("cannot open file on non NodeJS runtime")); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {os__File} +*/ +function os__open(path) { + try { + /** @type {os__File} */ + const f = os__open_file(path, new string("r")); + return f; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {os__File} +*/ +function os__create(path) { + try { + /** @type {os__File} */ + const f = os__open_file(path, new string("w")); + return f; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {os__File} +*/ +function os__stdin() { + try { + return (function() { + let _tmp35 = new os__File({}); + _tmp35.fd = new int(0); + _tmp35.is_opened = new bool(true); + return _tmp35; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {os__File} +*/ +function os__stdout() { + try { + return (function() { + let _tmp36 = new os__File({}); + _tmp36.fd = new int(1); + _tmp36.is_opened = new bool(true); + return _tmp36; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {os__File} +*/ +function os__stderr() { + try { + return (function() { + let _tmp37 = new os__File({}); + _tmp37.fd = new int(2); + _tmp37.is_opened = new bool(true); + return _tmp37; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u8} buf + * @returns {int} +*/ +function os__File_read(f, buf) { +f = new $ref(f) +buf = new $ref(buf) + try { + if ((new bool(buf.val.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new int(0); + } + /** @type {int} */ + let nbytes = new int(new int(0)); + try { + let readBuffer = Buffer.alloc(buf.val.len.valueOf()); + nbytes = $fs.readSync(f.val.fd.valueOf(), readBuffer, 0, buf.val.len.valueOf(), null); + + for (let i = 0; i < nbytes; i++) { buf.val.arr.arr[i] = new u8(readBuffer[i]); } + } + catch (e) { return error('' + e); } + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_u8} buf + * @returns {int} +*/ +function os__File_write(f, buf) { +f = new $ref(f) + try { + if ((!f.val.is_opened.val ).valueOf()) { + return error(new string("file is not opened")); + } + /** @type {int} */ + let nbytes = new int(new int(0)); + buf.arr.make_copy() + const b = $buffer.Buffer.from(buf.arr.arr.map((x) => x.valueOf())) + try { $fs.writeSync(f.val.fd.valueOf(),b,0,buf.len.valueOf(),0); } catch (e) { return error(new string('' + e)); } + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {int} +*/ +function os__File_writeln(f, s) { +f = new $ref(f) + try { + /** @type {int} */ + let nbytes = new int(os__File_write(f.valueOf(),string_bytes(s,))); + /** @type {int} */ + nbytes.val = Math.floor(nbytes + new int(os__File_write(f.valueOf(),string_bytes(new string("\n"),)))); + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u64} pos + * @param {Array_u8} buf + * @returns {int} +*/ +function os__File_write_to(f, pos, buf) { +f = new $ref(f) + try { + if ((!f.val.is_opened.val ).valueOf()) { + return error(new string("file is not opened")); + } + /** @type {int} */ + let nbytes = new int(new int(0)); + buf.arr.make_copy() + const b = $buffer.Buffer.from(buf.arr.arr.map((x) => x.valueOf())) + try { $fs.writeSync(f.val.fd.valueOf(),b,0,buf.len.valueOf(),pos.valueOf()); } catch (e) { return error(new string('' + e)); } + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {int} +*/ +function os__File_write_string(f, s) { +f = new $ref(f) + try { + /** @type {int} */ + const nbytes = new int(os__File_write(f.valueOf(),string_bytes(s,))); + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__File_close(f) { +f = new $ref(f) + try { + $fs.closeSync(f.valueOf().fd.valueOf()) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {voidptr} s + * @param {usize} buffer_len + * @returns {void} +*/ +function os__File_write_full_buffer(f, s, buffer_len) { +f = new $ref(f) + try { + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {array} buffer + * @returns {int} +*/ +function os__File_write_array(f, buffer) { +f = new $ref(f) + try { + if ((!f.val.is_opened.val ).valueOf()) { + return error(new string("file is not opened")); + } + /** @type {int} */ + let nbytes = new int(new int(0)); + buffer.arr.make_copy() + const b = $buffer.Buffer.from(buffer.arr.arr.map((x) => x.valueOf())) + try { $fs.writeSync(f.val.fd.valueOf(),b,0,buffer.len.valueOf(),0); } catch (e) { return error(new string('' + e)); } + return nbytes; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** @constant {rune} */ +let os__fslash = undefined; + +/** @constant {rune} */ +let os__bslash = undefined; + +/** @constant {rune} */ +let os__dot = undefined; + +/** @constant {rune} */ +let os__qmark = undefined; + +/** @constant {string} */ +const os__fslash_str = new string("/"); + +/** @constant {string} */ +const os__dot_dot = new string(".."); + +/** @constant {string} */ +const os__empty_str = new string(""); + +/** @constant {string} */ +const os__dot_str = new string("."); + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_abs_path(path) { + try { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return new bool(false); + } + if (($process.platform == "windows")) + { + return new bool( new bool( os__is_unc_path(path).valueOf() || os__is_drive_rooted(path).valueOf()).valueOf() || os__is_normal_path(path).valueOf()); + } + return new bool(new u8(path.str.charCodeAt(new int(0))).valueOf() == os__fslash.valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__abs_path(path) { + try { + /** @type {string} */ + const wd = new string(os__getwd()); + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return wd; + } + /** @type {string} */ + const npath = new string(os__norm_path(path)); + if ((new bool(npath.valueOf() == os__dot_str.valueOf())).valueOf()) { + return wd; + } + if ((!os__is_abs_path(npath).val ).valueOf()) { + /** @type {strings__Builder} */ + let sb = strings__new_builder(npath.len); + strings__Builder_write_string(sb,wd); + strings__Builder_write_string(sb,os__path_separator); + strings__Builder_write_string(sb,npath); + return os__norm_path(strings__Builder_str(new $ref(sb))); + } + return npath; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__norm_path(path) { + try { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return os__dot_str; + } + /** @type {bool} */ + const rooted = new bool(os__is_abs_path(path)); + /** @type {int} */ + const volume_len = new int(os__win_volume_len(path)); + /** @type {string} */ + let volume = new string(string_slice(path,new int(0), volume_len)); + if ((new bool( new bool(volume_len.valueOf() != new int(0).valueOf()).valueOf() && string_contains(volume,os__fslash_str).valueOf())).valueOf()) { + /** @type {string} */ + volume = new string(string_replace(volume,os__fslash_str, os__path_separator)); + } + /** @type {string} */ + const cpath = new string(os__clean_path(string_slice(path,volume_len, path.len))); + if ((new bool( new bool(cpath.valueOf() == new string("").valueOf()).valueOf() && new bool(volume_len.valueOf() == new int(0).valueOf()).valueOf())).valueOf()) { + return os__dot_str; + } + /** @type {Array_string} */ + const spath = string_split(cpath,os__path_separator); + if ((!(Array_string_contains(spath,os__dot_dot).valueOf())).valueOf()) { + return ((new bool(volume_len.valueOf() != new int(0).valueOf())).valueOf() ? new string( volume.valueOf() + cpath.valueOf()) : cpath); + } + /** @type {int} */ + const spath_len = new int(spath.len); + /** @type {strings__Builder} */ + let sb = strings__new_builder(cpath.len); + if ((rooted).valueOf()) { + strings__Builder_write_string(sb,os__path_separator); + } + /** @type {Array_string} */ + let new_path = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {int} */ + let backlink_count = new int(new int(0)); + for (let i = new int(new int( spath_len.valueOf() - new int(1).valueOf())); +new bool(i.valueOf() >= new int(0).valueOf()); i.val --) { + try { + let part = new string(spath.arr.get(new int(i.valueOf()))); if ((new bool(part.valueOf() == os__empty_str.valueOf())).valueOf()) { + continue; + } + if ((new bool(part.valueOf() == os__dot_dot.valueOf())).valueOf()) { + backlink_count.val ++; + continue; + } + if ((new bool(backlink_count.valueOf() != new int(0).valueOf())).valueOf()) { + backlink_count.val --; + continue; + } + array_prepend(new_path,part); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool( new bool(backlink_count.valueOf() != new int(0).valueOf()).valueOf() && !rooted.val .valueOf())).valueOf()) { + for (let i = new int(0); i < backlink_count; i = new int(i + 1)) { + try { + strings__Builder_write_string(sb,os__dot_dot); + if ((new bool( new bool(new_path.len.valueOf() == new int(0).valueOf()).valueOf() && new bool(i.valueOf() == new int( backlink_count.valueOf() - new int(1).valueOf()).valueOf()).valueOf())).valueOf()) { + break; + } + strings__Builder_write_string(sb,os__path_separator); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + strings__Builder_write_string(sb,Array_string_join(new_path,os__path_separator)); + /** @type {string} */ + const res = new string(strings__Builder_str(new $ref(sb))); + if ((new bool(res.len.valueOf() == new int(0).valueOf())).valueOf()) { + if ((new bool(volume_len.valueOf() != new int(0).valueOf())).valueOf()) { + return volume; + } + if ((!rooted.val ).valueOf()) { + return os__dot_str; + } + return os__path_separator; + } + if ((new bool(volume_len.valueOf() != new int(0).valueOf())).valueOf()) { + return new string( volume.valueOf() + res.valueOf()); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__existing_path(path) { + try { + /** @type {IError} */ + const err = error(new string("path does not exist")); + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return err; + } + if ((os__exists(path)).valueOf()) { + return path; + } + /** @type {int} */ + let volume_len = new int(new int(0)); + if (($process.platform == "windows")) + { + /** @type {int} */ + volume_len = new int(os__win_volume_len(path)); + } + if ((new bool( new bool(volume_len.valueOf() > new int(0).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int( volume_len.valueOf() - new int(1).valueOf())))).valueOf())).valueOf()) { + volume_len.val ++; + } + /** @type {strings__textscanner__TextScanner} */ + let sc = strings__textscanner__new(string_slice(path,volume_len, path.len)); + /** @type {string} */ + let recent_path = new string(string_slice(path,new int(0), volume_len)); + while (+new bool(strings__textscanner__TextScanner_next(sc,).valueOf() != new int(-1).valueOf())) { + try { + /** @type {u8} */ + const curr = new u8(new u8(strings__textscanner__TextScanner_current(sc,))); + /** @type {int} */ + const peek = new int(strings__textscanner__TextScanner_peek(sc,)); + /** @type {int} */ + const back = new int(strings__textscanner__TextScanner_peek_back(sc,)); + if ((os__is_curr_dir_ref(back, curr, peek)).valueOf()) { + continue; + } + /** @type {int} */ + const range = new int(new int( new int( sc.ilen.valueOf() - strings__textscanner__TextScanner_remaining(sc,).valueOf()).valueOf() + volume_len.valueOf())); + if ((new bool( os__is_slash(curr).valueOf() && !os__is_slash(new u8(peek)).val .valueOf())).valueOf()) { + /** @type {string} */ + recent_path = new string(string_slice(path,new int(0), range)); + continue; + } + if ((new bool( !os__is_slash(curr).val .valueOf() && (new bool( new bool(peek.valueOf() == new int(-1).valueOf()).valueOf() || os__is_slash(new u8(peek)).valueOf())).valueOf())).valueOf()) { + /** @type {string} */ + const curr_path = new string(string_slice(path,new int(0), range)); + if ((os__exists(curr_path)).valueOf()) { + /** @type {string} */ + recent_path = new string(curr_path); + continue; + } + if ((new bool(recent_path.valueOf() == new string("").valueOf())).valueOf()) { + break; + } + return recent_path; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return err; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__clean_path(path) { + try { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return os__empty_str; + } + /** @type {strings__Builder} */ + let sb = strings__new_builder(path.len); + /** @type {strings__textscanner__TextScanner} */ + let sc = strings__textscanner__new(path); + while (+new bool(strings__textscanner__TextScanner_next(sc,).valueOf() != new int(-1).valueOf())) { + try { + /** @type {u8} */ + const curr = new u8(new u8(strings__textscanner__TextScanner_current(sc,))); + /** @type {int} */ + const back = new int(strings__textscanner__TextScanner_peek_back(sc,)); + /** @type {int} */ + const peek = new int(strings__textscanner__TextScanner_peek(sc,)); + if ((new bool( new bool( new bool(back.valueOf() != new int(-1).valueOf()).valueOf() && os__is_slash(new u8(back)).valueOf()).valueOf() && os__is_slash(curr).valueOf())).valueOf()) { + continue; + } + if ((os__is_curr_dir_ref(back, curr, peek)).valueOf()) { + if ((new bool( new bool(peek.valueOf() != new int(-1).valueOf()).valueOf() && os__is_slash(new u8(peek)).valueOf())).valueOf()) { + strings__textscanner__TextScanner_skip_n(sc,new int(1)); + } + continue; + } + if (($process.platform == "windows")) + { + if ((new bool(curr.valueOf() == os__fslash.valueOf())).valueOf()) { + strings__Builder_write_u8(sb,os__bslash); + continue; + } + } + strings__Builder_write_u8(sb,new u8(strings__textscanner__TextScanner_current(sc,))); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {string} */ + const res = new string(strings__Builder_str(new $ref(sb))); + if ((new bool( new bool(res.len.valueOf() > new int(1).valueOf()).valueOf() && os__is_slash(new u8(res.str.charCodeAt(new int( res.len.valueOf() - new int(1).valueOf())))).valueOf())).valueOf()) { + return string_slice(res,new int(0), new int( res.len.valueOf() - new int(1).valueOf())); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__to_slash(path) { + try { + if ((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf()) { + return path; + } + return string_replace(path,os__path_separator, new string("/")); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__from_slash(path) { + try { + if ((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf()) { + return path; + } + return string_replace(path,new string("/"), os__path_separator); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {int} +*/ +function os__win_volume_len(path) { + try { + if (!($process.platform == "windows")) + { + return new int(0); + } + /** @type {int} */ + const plen = new int(path.len); + if ((new bool(plen.valueOf() < new int(2).valueOf())).valueOf()) { + return new int(0); + } + if ((os__has_drive_letter(path)).valueOf()) { + return new int(2); + } + if ((new bool( new bool( new bool(plen.valueOf() >= new int(5).valueOf()).valueOf() && os__starts_w_slash_slash(path).valueOf()).valueOf() && !os__is_slash(new u8(path.str.charCodeAt(new int(2)))).val .valueOf())).valueOf()) { + for (let i = new int(new int(3)); +new bool(i.valueOf() < plen.valueOf()); i.val ++) { + try { + if ((os__is_slash(new u8(path.str.charCodeAt(i)))).valueOf()) { + if ((new bool( new bool(new int( i.valueOf() + new int(1).valueOf()).valueOf() >= plen.valueOf()).valueOf() || os__is_slash(new u8(path.str.charCodeAt(new int( i.valueOf() + new int(1).valueOf())))).valueOf())).valueOf()) { + break; + } + i.val ++; + for (; +new bool(i.valueOf() < plen.valueOf()); i.val ++) { + try { + if ((os__is_slash(new u8(path.str.charCodeAt(i)))).valueOf()) { + return i; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return i; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } + return new int(0); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {u8} b + * @returns {bool} +*/ +function os__is_slash(b) { + try { + if (($process.platform == "windows")) + { + return new bool( new bool(b.valueOf() == os__bslash.valueOf()).valueOf() || new bool(b.valueOf() == os__fslash.valueOf()).valueOf()); + } + return new bool(b.valueOf() == os__fslash.valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_unc_path(path) { + try { + return new bool( new bool(os__win_volume_len(path).valueOf() >= new int(5).valueOf()).valueOf() && os__starts_w_slash_slash(path).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__has_drive_letter(path) { + try { + return new bool( new bool( new bool(path.len.valueOf() >= new int(2).valueOf()).valueOf() && u8_is_letter(new u8(path.str.charCodeAt(new int(0))),).valueOf()).valueOf() && new bool(new u8(path.str.charCodeAt(new int(1))).valueOf() == new u8(':').valueOf()).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__starts_w_slash_slash(path) { + try { + return new bool( new bool( new bool(path.len.valueOf() >= new int(2).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int(0)))).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int(1)))).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_drive_rooted(path) { + try { + return new bool( new bool( new bool(path.len.valueOf() >= new int(3).valueOf()).valueOf() && os__has_drive_letter(path).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int(2)))).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_normal_path(path) { + try { + /** @type {int} */ + const plen = new int(path.len); + if ((new bool(plen.valueOf() == new int(0).valueOf())).valueOf()) { + return new bool(false); + } + return new bool( (new bool( new bool(plen.valueOf() == new int(1).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int(0)))).valueOf())).valueOf() || (new bool( new bool( new bool(plen.valueOf() >= new int(2).valueOf()).valueOf() && os__is_slash(new u8(path.str.charCodeAt(new int(0)))).valueOf()).valueOf() && !os__is_slash(new u8(path.str.charCodeAt(new int(1)))).val .valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} byte_one + * @param {int} byte_two + * @param {int} byte_three + * @returns {bool} +*/ +function os__is_curr_dir_ref(byte_one, byte_two, byte_three) { + try { + if ((new bool(new u8(byte_two).valueOf() != os__dot.valueOf())).valueOf()) { + return new bool(false); + } + return new bool( (new bool( new bool(byte_one.valueOf() < new int(0).valueOf()).valueOf() || os__is_slash(new u8(byte_one)).valueOf())).valueOf() && (new bool( new bool(byte_three.valueOf() < new int(0).valueOf()).valueOf() || os__is_slash(new u8(byte_three)).valueOf())).valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__windows_volume(path) { + try { + /** @type {int} */ + const volume_len = new int(os__win_volume_len(path)); + if ((new bool(volume_len.valueOf() == new int(0).valueOf())).valueOf()) { + return os__empty_str; + } + return string_slice(path,new int(0), volume_len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +if (true) +{ +var $fs = require('fs'); +var $path = require('path'); +var tty = require('tty') +} +/** @constant {string} */ +let os__path_delimiter = undefined; + +/** @constant {string} */ +let os__path_separator = undefined; + +/** @constant {string} */ +const os__path_devnull = new string("/dev/null"); + +/** @constant {Array_string} */ +let os__args = undefined; + +/** @constant {Array_string} */ +let os__executable_suffixes = undefined; + +/** + * @function + * @returns {string} +*/ +function os__get_path_delimiter() { + try { + /** @type {string} */ + const delimiter = new string(new string(":")); + if (true) + { + delimiter.str = $path.delimiter + } + return delimiter; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__get_path_separator() { + try { + /** @type {string} */ + const separator = new string(new string("/")); + if (true) + { + separator.str = $path.sep + } + return separator; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__init() { + try { + if (true) + { + $process.argv.forEach(function(val,index) { os__args.arr[index] = new string(val); }) + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} fpath + * @returns {string} +*/ +function os__real_path(fpath) { + try { + if (true) + { + /** @type {string} */ + let res = new string(new string("")); + res = new string( $fs.realpathSync(fpath)) + return res; + } + else + { + return fpath; + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__flush() { + try { + if (true) + { + $process.stdout.write('') + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function os__getpid() { + try { + /** @type {int} */ + const res = new int(new int(0)); + res.val = $process.pid + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {int} mode + * @returns {void} +*/ +function os__chmod(path, mode) { + try { + if (true) + { + try { + $fs.chmodSync(''+path,mode.valueOf()) + } catch (error) { + return error_with_code(new string("chmod failed: " + error.message),new int(error.code)) + } + } + else + { + return error(new string("os.chmod() is available only for NodeJS")); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {int} owner + * @param {int} group + * @returns {void} +*/ +function os__chown(path, owner, group) { + try { + if (true) + { + try { + $fs.chownSync(''+path,owner.valueOf(),group.valueOf()) + } catch (error) { return error_with_code(new string("chown failed: " + error.message),new int(error.code)) } + } + else + { + return error(new string("os.chown() is available only for NodeJS")); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__temp_dir() { + try { + /** @type {string} */ + let res = new string(new string("")); + if (true) + { + res = new string($os.tmpdir()) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__home_dir() { + try { + /** @type {string} */ + let res = new string(new string("")); + if (true) + { + res = new string($os.homedir()) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} base + * @param {...Array_string} dirs + * @returns {string} +*/ +function os__join_path(base, ...dirs) { +dirs = new array(new array_buffer({arr: dirs,len: new int(dirs.length),index_start: new int(0)})); + try { + /** @type {Array_string} */ + let result = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + array_push(result,string_trim_right(base,new string("\\/")),false); + for (const d of dirs) { + try { + array_push(result,d,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {string} */ + let path_sep = new string(new string("")); + path_sep = $path.sep; + /** @type {string} */ + const res = new string(Array_string_join(result,path_sep)); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} base + * @param {string} elem + * @returns {string} +*/ +function os__join_path_single(base, elem) { + try { + return os__join_path(base, elem); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cmd + * @returns {os__Result} +*/ +function os__execute(cmd) { + try { + /** @type {int} */ + let exit_code = new int(new int(0)); + /** @type {string} */ + let stdout = new string(new string("")); + let commands = cmd.str.split(' '); + let output = $child_process.spawnSync(commands[0],commands.slice(1,commands.length)); + exit_code = new int(output.status) + stdout = new string(output.stdout + '') + return (function() { + let _tmp38 = new os__Result({}); + _tmp38.exit_code = exit_code; + _tmp38.output = stdout; + return _tmp38; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cmd + * @returns {int} +*/ +function os__system(cmd) { + try { + /** @type {int} */ + const exit_code = new int(new int(0)); + let commands = cmd.str.split(' '); + exit_code.val = $child_process.execSync(commands[0],commands.slice(1,commands.length)); + return exit_code; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} fd + * @returns {int} +*/ +function os__is_atty(fd) { + try { + /** @type {int} */ + const res = new int(new int(0)); + res.val = +tty.isatty(fd.val) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {...Array_string} patterns + * @returns {Array_string} +*/ +function os__glob(...patterns) { +patterns = new array(new array_buffer({arr: patterns,len: new int(patterns.length),index_start: new int(0)})); + try { + builtin__panic (new string("not yet implemented")); + return error(new string("not yet implemented")); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {array} buffer + * @returns {void} +*/ +function os__write_file_array(path, buffer) { + try { + /** @type {os__File} */ + let f = os__create(path); + os__File_write_array(f,buffer); + os__File_close(f,); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function os__chdir(s) { + try { + try { $process.chdir(s.str); } catch (e) { return error(new string('' + s)) } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {int} +*/ +function os__file_last_mod_unix(path) { + try { + /** @type {int} */ + const mtime = new int(new int(0)); + mtime.val = Math.floor($fs.lstatSync(path.str).mtime.getTime() / 1000) + return mtime; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__ensure_folder_is_writable(path) { + try { + /** @type {string} */ + const fpath = new string(os__join_path(path, new string("some_newfile"))); + try { $fs.writeFileSync(fpath); $fs.unlinkSync(fpath) } catch(e) { return error(new string('could not write to ' + path)) } + const _tmp39 = fpath; + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** @constant {int} */ +const os__max_path_len = new int(4096); + +/** @constant {string} */ +let os__wd_at_startup = undefined; + +/** @constant {int} */ +const os__f_ok = new int(0); + +/** @constant {int} */ +const os__x_ok = new int(1); + +/** @constant {int} */ +const os__w_ok = new int(2); + +/** @constant {int} */ +const os__r_ok = new int(4); + +/** + * @constructor + * @param {{exit_code?: int, output?: string}} init +*/ +function os__Result({ exit_code = new int(0), output = new string("") }) { + this.exit_code = exit_code + this.output = output +}; +os__Result.prototype = { + toString() { + return `os__Result { exit_code: ${this["exit_code"].toString()} , output: "${this["output"].toString()}"}` + }, + /** @type {int} */ + exit_code: new int(0), + /** @type {string} */ + output: new string(""), + $toJS() { return this; } + }; + +/** + * @constructor + * @param {{f?: voidptr, eof?: bool, exit_code?: int, path?: string, redirect_stdout?: bool}} init +*/ +function os__Command({ f = new voidptr(null), eof = new bool(false), exit_code = new int(0), path = new string(""), redirect_stdout = new bool(false) }) { + this.f = f + this.eof = eof + this.exit_code = exit_code + this.path = path + this.redirect_stdout = redirect_stdout +}; +os__Command.prototype = { + toString() { + return `os__Command { f: ${this["f"].toString()} , eof: ${this["eof"].toString()} , exit_code: ${this["exit_code"].toString()} , path: "${this["path"].toString()}", redirect_stdout: ${this["redirect_stdout"].toString()} }` + }, + /** @type {voidptr} */ + f: new voidptr(null), + /** @type {bool} */ + eof: new bool(false), + /** @type {int} */ + exit_code: new int(0), + /** @type {string} */ + path: new string(""), + /** @type {bool} */ + redirect_stdout: new bool(false), + $toJS() { return this; } + }; + +/* [unsafe] */ +/** + * @function + * @returns {void} +*/ +function os__Result_free(result) { +result = new $ref(result) + try { + string_free(result.val.output,); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__executable_fallback() { + try { + if ((new bool(os__args.len.valueOf() == new int(0).valueOf())).valueOf()) { + return new string(""); + } + /** @type {string} */ + let exepath = new string(os__args.arr.get(new int(new int(0).valueOf()))); + if (($process.platform == "windows")) + { + if ((!string_contains(exepath,new string(".exe")).val ).valueOf()) { + /** @type {string} */ + exepath.str = exepath + new string(new string(".exe")); + } + } + if ((!os__is_abs_path(exepath).val ).valueOf()) { + /** @type {string} */ + const other_separator = new string(((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf() ? new string("\\") : new string("/"))); + /** @type {string} */ + const rexepath = new string(string_replace(exepath,other_separator, os__path_separator)); + if ((string_contains(rexepath,os__path_separator)).valueOf()) { + /** @type {string} */ + exepath = new string(os__join_path_single(os__wd_at_startup, exepath)); + } else { + /** @type {string} */ + const foundpath = new string(os__find_abs_path_of_executable(exepath)); + if ((new bool(foundpath.valueOf() != new string("").valueOf())).valueOf()) { + /** @type {string} */ + exepath = new string(foundpath); + } + } + } + /** @type {string} */ + exepath = new string(os__real_path(exepath)); + return exepath; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} src + * @param {string} dst + * @param {bool} overwrite + * @returns {void} +*/ +function os__cp_all(src, dst, overwrite) { + try { + /** @type {string} */ + const source_path = new string(os__real_path(src)); + /** @type {string} */ + const dest_path = new string(os__real_path(dst)); + if ((!os__exists(source_path).val ).valueOf()) { + return error(new string("Source path doesn't exist")); + } + if ((!os__is_dir(source_path).val ).valueOf()) { + /** @type {string} */ + const fname = new string(os__file_name(source_path)); + /** @type {string} */ + const adjusted_path = new string(((os__is_dir(dest_path)).valueOf() ? os__join_path_single(dest_path, fname) : dest_path)); + if ((os__exists(adjusted_path)).valueOf()) { + if ((overwrite).valueOf()) { + os__rm(adjusted_path); + } else { + return error(new string("Destination file path already exist")); + } + } + os__cp(source_path, adjusted_path); + return; + } + if ((!os__exists(dest_path).val ).valueOf()) { + os__mkdir(dest_path, new os__MkdirParams({})); + } + if ((!os__is_dir(dest_path).val ).valueOf()) { + return error(new string("Destination path is not a valid directory")); + } + /** @type {Array_string} */ + const files = os__ls(source_path); + for (const file of files) { + try { + /** @type {string} */ + const sp = new string(os__join_path_single(source_path, file)); + /** @type {string} */ + const dp = new string(os__join_path_single(dest_path, file)); + if ((os__is_dir(sp)).valueOf()) { + if ((!os__exists(dp).val ).valueOf()) { + os__mkdir(dp, new os__MkdirParams({})); + } + } + os__cp_all(sp, dp, overwrite); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [params] */ +/** + * @constructor + * @param {{overwrite?: bool}} init +*/ +function os__MvParams({ overwrite = new bool(true) }) { + this.overwrite = overwrite +}; +os__MvParams.prototype = { + toString() { + return `os__MvParams { overwrite: ${this["overwrite"].toString()} }` + }, + /** @type {bool} */ + overwrite: new bool(false), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} source + * @param {string} target + * @param {os__MvParams} opts + * @returns {void} +*/ +function os__mv_by_cp(source, target, opts) { + try { + os__cp_all(source, target, opts.overwrite); + if ((os__is_dir(source)).valueOf()) { + os__rmdir_all(source); + return; + } + os__rm(source); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} source + * @param {string} target + * @param {os__MvParams} opts + * @returns {void} +*/ +function os__mv(source, target, opts) { + try { + if ((new bool( !opts.overwrite.val .valueOf() && os__exists(target).valueOf())).valueOf()) { + return error(new string("target path already exist")); + } + os__rename(source, target); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [manualfree] */ +/** + * @function + * @param {string} path + * @returns {Array_string} +*/ +function os__read_lines(path) { + try { + /** @type {string} */ + const buf = new string(os__read_file(path)); + /** @type {Array_string} */ + const res = string_split_into_lines(buf,); + string_free(buf,); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {Array_string} lines + * @returns {void} +*/ +function os__write_lines(path, lines) { + try { + /** @type {os__File} */ + let f = os__create(path); + for (const line of lines) { + try { + os__File_writeln(f,line); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + (function defer() { + os__File_close(f,); + })(); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} si + * @returns {string} +*/ +function os__sigint_to_signal_name(si) { + try { + + if (vEq(si,new int(1))) { + return new string("SIGHUP"); + } + else if (vEq(si,new int(2))) { + return new string("SIGINT"); + } + else if (vEq(si,new int(3))) { + return new string("SIGQUIT"); + } + else if (vEq(si,new int(4))) { + return new string("SIGILL"); + } + else if (vEq(si,new int(6))) { + return new string("SIGABRT"); + } + else if (vEq(si,new int(8))) { + return new string("SIGFPE"); + } + else if (vEq(si,new int(9))) { + return new string("SIGKILL"); + } + else if (vEq(si,new int(11))) { + return new string("SIGSEGV"); + } + else if (vEq(si,new int(13))) { + return new string("SIGPIPE"); + } + else if (vEq(si,new int(14))) { + return new string("SIGALRM"); + } + else if (vEq(si,new int(15))) { + return new string("SIGTERM"); + } + else { + }; + if (($process.platform == "linux")) + { + + if (vEq(si,new int(10))) { + return new string("SIGUSR1"); + } + else if (vEq(si,new int(12))) { + return new string("SIGUSR2"); + } + else if (vEq(si,new int(17))) { + return new string("SIGCHLD"); + } + else if (vEq(si,new int(18))) { + return new string("SIGCONT"); + } + else if (vEq(si,new int(19))) { + return new string("SIGSTOP"); + } + else if (vEq(si,new int(20))) { + return new string("SIGTSTP"); + } + else if (vEq(si,new int(21))) { + return new string("SIGTTIN"); + } + else if (vEq(si,new int(22))) { + return new string("SIGTTOU"); + } + else if (vEq(si,new int(5))) { + return new string("SIGTRAP"); + } + else if (vEq(si,new int(7))) { + return new string("SIGBUS"); + } + else { + }; + } + return new string("unknown"); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__rmdir_all(path) { + try { + /** @type {string} */ + let ret_err = new string(new string("")); + /** @type {Array_string} */ + const items = os__ls(path); + for (const item of items) { + try { + /** @type {string} */ + const fullpath = new string(os__join_path_single(path, item)); + if ((new bool( os__is_dir(fullpath).valueOf() && !os__is_link(fullpath).val .valueOf())).valueOf()) { + os__rmdir_all(fullpath); + } else { + os__rm(fullpath); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + os__rmdir(path); + if ((new bool(ret_err.len.valueOf() > new int(0).valueOf())).valueOf()) { + return error(ret_err); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [manualfree] */ +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_dir_empty(path) { + try { + /** @type {Array_string} */ + const items = os__ls(path); + /** @type {bool} */ + const res = new bool(new bool(items.len.valueOf() == new int(0).valueOf())); + array_free(items,); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} opath + * @returns {string} +*/ +function os__file_ext(opath) { + try { + if ((new bool(opath.len.valueOf() < new int(3).valueOf())).valueOf()) { + return new string(""); + } + /** @type {string} */ + const path = new string(os__file_name(opath)); + /** @type {int} */ + const pos = new int(string_index_u8_last(path,new u8('.'))); + if ((new bool(pos.valueOf() == new int(-1).valueOf())).valueOf()) { + return new string(""); + } + if ((new bool( new bool(new int( pos.valueOf() + new int(1).valueOf()).valueOf() >= path.len.valueOf()).valueOf() || new bool(pos.valueOf() == new int(0).valueOf()).valueOf())).valueOf()) { + return new string(""); + } + return string_slice(path,pos, path.len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} opath + * @returns {string} +*/ +function os__dir(opath) { + try { + if ((new bool(opath.valueOf() == new string("").valueOf())).valueOf()) { + return new string("."); + } + /** @type {string} */ + const other_separator = new string(((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf() ? new string("\\") : new string("/"))); + /** @type {string} */ + const path = new string(string_replace(opath,other_separator, os__path_separator)); + /** @type {int} */ + const pos = new int((function(){ + try { + return unwrap(string_last_index(path,os__path_separator)) + } catch(err) { + throw new ReturnException(new string(".")) + ; + } + })()); + if ((new bool( new bool(pos.valueOf() == new int(0).valueOf()).valueOf() && new bool(os__path_separator.valueOf() == new string("/").valueOf()).valueOf())).valueOf()) { + return new string("/"); + } + return string_slice(path,new int(0), pos); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} opath + * @returns {string} +*/ +function os__base(opath) { + try { + if ((new bool(opath.valueOf() == new string("").valueOf())).valueOf()) { + return new string("."); + } + /** @type {string} */ + const other_separator = new string(((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf() ? new string("\\") : new string("/"))); + /** @type {string} */ + const path = new string(string_replace(opath,other_separator, os__path_separator)); + if ((new bool(path.valueOf() == os__path_separator.valueOf())).valueOf()) { + return os__path_separator; + } + if ((string_ends_with(path,os__path_separator)).valueOf()) { + /** @type {string} */ + const path2 = new string(string_slice(path,new int(0), new int( path.len.valueOf() - new int(1).valueOf()))); + /** @type {int} */ + const pos = new int((function(){ + try { + return unwrap(string_last_index(path2,os__path_separator)) + } catch(err) { + throw new ReturnException(string_clone(path2,)) + ; + } + })()); + return string_slice(path2,new int( pos.valueOf() + new int(1).valueOf()), path2.len); + } + /** @type {int} */ + const pos = new int((function(){ + try { + return unwrap(string_last_index(path,os__path_separator)) + } catch(err) { + throw new ReturnException(string_clone(path,)) + ; + } + })()); + return string_slice(path,new int( pos.valueOf() + new int(1).valueOf()), path.len); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} opath + * @returns {string} +*/ +function os__file_name(opath) { + try { + /** @type {string} */ + const other_separator = new string(((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf() ? new string("\\") : new string("/"))); + /** @type {string} */ + const path = new string(string_replace(opath,other_separator, os__path_separator)); + return string_all_after_last(path,os__path_separator); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} prompt + * @returns {string} +*/ +function os__input_opt(prompt) { + try { + builtin__print (prompt); + os__flush(); + /** @type {string} */ + const res = new string(os__get_raw_line()); + if ((new bool(res.len.valueOf() > new int(0).valueOf())).valueOf()) { + const _tmp40 = new _option({}); + _tmp40.state = new u8(0);_tmp40.data = string_trim_right(res,new string("\r\n")) + return _tmp40;} + return new Option({ state: new u8(2),err: none__}); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} prompt + * @returns {string} +*/ +function os__input(prompt) { + try { + /** @type {string} */ + const res = new string((function(){ + try { + return unwrap(os__input_opt(prompt)) + } catch(err) { + throw new ReturnException(new string("")) + ; + } + })()); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__get_line() { + try { + /** @type {string} */ + const str = new string(os__get_raw_line()); + if (($process.platform == "windows")) + { + return string_trim_right(str,new string("\r\n")); + } + return string_trim_right(str,new string("\n")); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_string} +*/ +function os__get_lines() { + try { + /** @type {string} */ + let line = new string(new string("")); + /** @type {Array_string} */ + let inputstr = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + while (true) { + try { + /** @type {string} */ + line = new string(os__get_line()); + if ((new bool(line.len.valueOf() <= new int(0).valueOf())).valueOf()) { + break; + } + /** @type {string} */ + line = new string(string_trim_space(line,)); + array_push(inputstr,line,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return inputstr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__get_lines_joined() { + try { + /** @type {string} */ + let line = new string(new string("")); + /** @type {string} */ + let inputstr = new string(new string("")); + while (true) { + try { + /** @type {string} */ + line = new string(os__get_line()); + if ((new bool(line.len.valueOf() <= new int(0).valueOf())).valueOf()) { + break; + } + /** @type {string} */ + line = new string(string_trim_space(line,)); + /** @type {string} */ + inputstr.str = inputstr + new string(line); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return inputstr; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__get_raw_lines_joined() { + try { + /** @type {string} */ + let line = new string(new string("")); + /** @type {Array_string} */ + let lines = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + while (true) { + try { + /** @type {string} */ + line = new string(os__get_raw_line()); + if ((new bool(line.len.valueOf() <= new int(0).valueOf())).valueOf()) { + break; + } + array_push(lines,line,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {string} */ + const res = new string(Array_string_join(lines,new string(""))); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__user_os() { + try { + if (($process.platform == "linux")) + { + return new string("linux"); + } + if (($process.platform == "darwin")) + { + return new string("macos"); + } + if (($process.platform == "windows")) + { + return new string("windows"); + } + if (($process.platform == "freebsd")) + { + return new string("freebsd"); + } + if (($process.platform == "openbsd")) + { + return new string("openbsd"); + } + if (true) + { + return new string("netbsd"); + } + if (true) + { + return new string("dragonfly"); + } + if (($process.platform == "android")) + { + return new string("android"); + } + if (true) + { + return new string("termux"); + } + if (($process.platform == "sunos")) + { + return new string("solaris"); + } + if (true) + { + return new string("qnx"); + } + if (true) + { + return new string("haiku"); + } + if (true) + { + return new string("serenity"); + } + if (true) + { + return new string("vinix"); + } + if ((new bool(os__getenv(new string("TERMUX_VERSION")).valueOf() != new string("").valueOf())).valueOf()) { + return new string("termux"); + } + return new string("unknown"); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_string} +*/ +function os__user_names() { + try { + if (($process.platform == "windows")) + { + /** @type {os__Result} */ + const result = os__execute(new string("wmic useraccount get name")); + if ((new bool(result.exit_code.valueOf() != new int(0).valueOf())).valueOf()) { + return error(new string(`Failed to get user names. Exited with code ${int_str(result.exit_code)}: ${result.output}`)); + } + /** @type {Array_string} */ + let users = string_split_into_lines(result.output,); + array_delete(users,new int( users.len.valueOf() - new int(1).valueOf())); + return users; + } + else + { + /** @type {Array_string} */ + const lines = os__read_lines(new string("/etc/passwd")); + /** @type {Array_string} */ + let users = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + for (const line of lines) { + try { + /** @type {int} */ + const end_name = new int((function(){ + try { + return unwrap(string_index(line,new string(":"))) + } catch(err) { + line.len; + } + })()); + array_push(users,string_slice(line,new int(0), end_name),false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return users; + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__pure_v_but_overridden_by_js_home_dir() { + try { + if (($process.platform == "windows")) + { + return os__getenv(new string("USERPROFILE")); + } + else + { + return os__getenv(new string("HOME")); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__expand_tilde_to_home(path) { + try { + if ((new bool(path.valueOf() == new string("~").valueOf())).valueOf()) { + return string_trim_right(os__home_dir(),os__path_separator); + } + if ((string_starts_with(path,new string( new string("~").valueOf() + os__path_separator.valueOf()))).valueOf()) { + return string_replace_once(path,new string( new string("~").valueOf() + os__path_separator.valueOf()), new string( string_trim_right(os__home_dir(),os__path_separator).valueOf() + os__path_separator.valueOf())); + } + return path; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {string} text + * @returns {void} +*/ +function os__write_file(path, text) { + try { + /** @type {os__File} */ + let f = os__create(path); + os__File_write_full_buffer(f,text.str, new usize(text.len)); + os__File_close(f,); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{}} init +*/ +function os__ExecutableNotFoundError({ }) { +}; +os__ExecutableNotFoundError.prototype = { + ...Error.prototype, + toString() { + return `os__ExecutableNotFoundError {}` + }, + $toJS() { return this; } + }; + +/** + * @function + * @returns {string} +*/ +function os__ExecutableNotFoundError_msg(err) { + try { + return new string("os: failed to find executable"); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {IError} +*/ +function os__error_failed_to_find_executable() { + try { + return new $ref(new os__ExecutableNotFoundError({})); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} exe_name + * @returns {string} +*/ +function os__find_abs_path_of_executable(exe_name) { + try { + if ((new bool(exe_name.valueOf() == new string("").valueOf())).valueOf()) { + return error(new string("expected non empty `exe_name`")); + } + for (const suffix of os__executable_suffixes) { + try { + /** @type {string} */ + const fexepath = new string(new string( exe_name.valueOf() + suffix.valueOf())); + if ((os__is_abs_path(fexepath)).valueOf()) { + return os__real_path(fexepath); + } + /** @type {string} */ + let res = new string(new string("")); + /** @type {string} */ + const path = new string(os__getenv(new string("PATH"))); + /** @type {Array_string} */ + const paths = string_split(path,os__path_delimiter); + for (const p of paths) { + try { + /** @type {string} */ + const found_abs_path = new string(os__join_path_single(p, fexepath)); + if (checkDefine("CUSTOM_DEFINE_trace_find_abs_path_of_executable")) + { + /* ast.DumpExpr: found_abs_path */; + } + if ((new bool( os__exists(found_abs_path).valueOf() && os__is_executable(found_abs_path).valueOf())).valueOf()) { + /** @type {string} */ + res = new string(found_abs_path); + break; + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + if ((new bool(res.len.valueOf() > new int(0).valueOf())).valueOf()) { + return os__real_path(res); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return os__error_failed_to_find_executable(); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} prog + * @returns {bool} +*/ +function os__exists_in_system_path(prog) { + try { + os__find_abs_path_of_executable(prog); + return new bool(true); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_file(path) { + try { + return new bool( os__exists(path).valueOf() && !os__is_dir(path).val .valueOf()); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [manualfree] */ +/** + * @function + * @param {string} base + * @param {...Array_string} dirs + * @returns {string} +*/ +function os__pure_v_but_overridden_by_js_join_path(base, ...dirs) { +dirs = new array(new array_buffer({arr: dirs,len: new int(dirs.length),index_start: new int(0)})); + try { + /** @type {strings__Builder} */ + let sb = strings__new_builder(new int( base.len.valueOf() + new int( dirs.len.valueOf() * new int(50).valueOf()).valueOf())); + /** @type {string} */ + const sbase = new string(string_trim_right(base,new string("\\/"))); + strings__Builder_write_string(sb,sbase); + for (const d of dirs) { + try { + if ((new bool(d.valueOf() != new string("").valueOf())).valueOf()) { + strings__Builder_write_string(sb,os__path_separator); + strings__Builder_write_string(sb,d); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + os__normalize_path_in_builder(sb); + /** @type {string} */ + let res = new string(strings__Builder_str(new $ref(sb))); + if ((new bool(base.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + res = new string(string_trim_left(res,os__path_separator)); + } + (function defer() { + array_free(sb,); + string_free(sbase,); + })(); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [manualfree] */ +/** + * @function + * @param {string} base + * @param {string} elem + * @returns {string} +*/ +function os__pure_v_but_overridden_by_js_join_path_single(base, elem) { + try { + /** @type {strings__Builder} */ + let sb = strings__new_builder(new int( new int( base.len.valueOf() + elem.len.valueOf()).valueOf() + new int(1).valueOf())); + /** @type {string} */ + const sbase = new string(string_trim_right(base,new string("\\/"))); + strings__Builder_write_string(sb,sbase); + if ((new bool(elem.valueOf() != new string("").valueOf())).valueOf()) { + strings__Builder_write_string(sb,os__path_separator); + strings__Builder_write_string(sb,elem); + } + os__normalize_path_in_builder(sb); + /** @type {string} */ + let res = new string(strings__Builder_str(new $ref(sb))); + if ((new bool(base.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + res = new string(string_trim_left(res,os__path_separator)); + } + (function defer() { + array_free(sb,); + string_free(sbase,); + })(); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [direct_array_access] */ +/** + * @function + * @param {strings__Builder} sb + * @returns {void} +*/ +function os__normalize_path_in_builder(sb) { +sb = new $ref(sb) + try { + /** @type {rune} */ + let fs = new u8('\\'); + /** @type {rune} */ + let rs = new u8('/'); + if (($process.platform == "windows")) + { + /** @type {rune} */ + fs = new u8('/'); + /** @type {rune} */ + rs = new u8('\\'); + } + for (let idx = new int(0); idx < sb.val.len; idx = new int(idx + 1)) { + try { + { + if ((new bool(sb.valueOf().arr.get(new int(idx.valueOf())).valueOf() == fs.valueOf())).valueOf()) { + /** @type {u8} */ + sb.valueOf().arr.set(new int(idx.valueOf()),new u8(rs)); + } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + for (let idx = new int(0); idx < new int( sb.val.len.valueOf() - new int(3).valueOf()); idx = new int(idx + 1)) { + try { + if ((new bool( new bool( new bool(sb.valueOf().arr.get(new int(idx.valueOf())).valueOf() == rs.valueOf()).valueOf() && new bool(sb.valueOf().arr.get(new int(new int_literal( idx.valueOf() + new int(1).valueOf()).valueOf())).valueOf() == new u8('.').valueOf()).valueOf()).valueOf() && new bool(sb.valueOf().arr.get(new int(new int_literal( idx.valueOf() + new int(2).valueOf()).valueOf())).valueOf() == rs.valueOf()).valueOf())).valueOf()) { + { + for (let j = new int(new int_literal( idx.valueOf() + new int(1).valueOf())); +new bool(j.valueOf() < new int( sb.val.len.valueOf() - new int(2).valueOf()).valueOf()); j.val ++) { + try { + sb.valueOf().arr.set(new int(j.valueOf()),new u8(sb.valueOf().arr.get(new int(new int( j.valueOf() + new int(2).valueOf()).valueOf())))); } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {int} */ + sb.val.len.val = Math.floor(sb.val.len - new int(new int(2))); + } + + } + if ((new bool( new bool(sb.valueOf().arr.get(new int(idx.valueOf())).valueOf() == rs.valueOf()).valueOf() && new bool(sb.valueOf().arr.get(new int(new int_literal( idx.valueOf() + new int(1).valueOf()).valueOf())).valueOf() == rs.valueOf()).valueOf())).valueOf()) { + { + for (let j = new int(new int_literal( idx.valueOf() + new int(1).valueOf())); +new bool(j.valueOf() < new int( sb.val.len.valueOf() - new int(1).valueOf()).valueOf()); j.val ++) { + try { + sb.valueOf().arr.set(new int(j.valueOf()),new u8(sb.valueOf().arr.get(new int(new int( j.valueOf() + new int(1).valueOf()).valueOf())))); } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + /** @type {int} */ + sb.val.len.val = Math.floor(sb.val.len - new int(new int(1))); + } + + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {string} ext + * @returns {Array_string} +*/ +function os__walk_ext(path, ext) { + try { + /** @type {Array_string} */ + let res = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + os__impl_walk_ext(path, ext, res); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {string} ext + * @param {Array_string} out + * @returns {void} +*/ +function os__impl_walk_ext(path, ext, out) { +out = new $ref(out) + try { + if ((!os__is_dir(path).val ).valueOf()) { + return; + } + /** @type {Array_string} */ + let files = os__ls(path); + /** @type {string} */ + const separator = new string(((string_ends_with(path,os__path_separator)).valueOf() ? new string("") : os__path_separator)); + for (const file of files) { + try { + if ((string_starts_with(file,new string("."))).valueOf()) { + continue; + } + /** @type {string} */ + const p = new string(new string( new string( path.valueOf() + separator.valueOf()).valueOf() + file.valueOf())); + if ((new bool( os__is_dir(p).valueOf() && !os__is_link(p).val .valueOf())).valueOf()) { + os__impl_walk_ext(p, ext, out); + } else if ((string_ends_with(file,ext)).valueOf()) { + array_push(out.valueOf(),p,false); + } + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {anon_fn_string} f + * @returns {void} +*/ +function os__walk(path, f) { + try { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return; + } + if ((!os__is_dir(path).val ).valueOf()) { + return; + } + /** @type {Array_string} */ + let remaining = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {string} */ + const clean_path = new string(string_trim_right(path,os__path_separator)); + if (($process.platform == "windows")) + { + array_push(remaining,string_replace(clean_path,new string("/"), new string("\\")),false); + } + else + { + array_push(remaining,clean_path,false); + } + while (+new bool(remaining.len.valueOf() > new int(0).valueOf())) { + try { + /** @type {string} */ + const cpath = new string(array_pop(remaining,)); + /** @type {os__PathKind} */ + const pkind = os__kind_of_existing_path(cpath); + if ((new bool( pkind.is_link.valueOf() || !pkind.is_dir.val .valueOf())).valueOf()) { + f(cpath); + continue; + } + /** @type {Array_string} */ + let files = os__ls(cpath); + for (let idx = new int(new int( files.len.valueOf() - new int(1).valueOf())); +new bool(idx.valueOf() >= new int(0).valueOf()); idx.val --) { + try { + array_push(remaining,new string( new string( cpath.valueOf() + os__path_separator.valueOf()).valueOf() + files.arr.get(new int(idx.valueOf())).valueOf()),false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @param {voidptr} context + * @param {os__FnWalkContextCB} fcb + * @returns {void} +*/ +function os__walk_with_context(path, context, fcb) { + try { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + return; + } + if ((!os__is_dir(path).val ).valueOf()) { + return; + } + /** @type {Array_string} */ + let remaining = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + /** @type {string} */ + const clean_path = new string(string_trim_right(path,os__path_separator)); + if (($process.platform == "windows")) + { + array_push(remaining,string_replace(clean_path,new string("/"), new string("\\")),false); + } + else + { + array_push(remaining,clean_path,false); + } + /** @type {int} */ + let loops = new int(new int(0)); + while (+new bool(remaining.len.valueOf() > new int(0).valueOf())) { + try { + loops.val ++; + /** @type {string} */ + const cpath = new string(array_pop(remaining,)); + if ((new bool(loops.valueOf() > new int(1).valueOf())).valueOf()) { + fcb(context, cpath); + } + /** @type {os__PathKind} */ + const pkind = os__kind_of_existing_path(cpath); + if ((new bool( pkind.is_link.valueOf() || !pkind.is_dir.val .valueOf())).valueOf()) { + continue; + } + /** @type {Array_string} */ + let files = os__ls(cpath); + for (let idx = new int(new int( files.len.valueOf() - new int(1).valueOf())); +new bool(idx.valueOf() >= new int(0).valueOf()); idx.val --) { + try { + array_push(remaining,new string( new string( cpath.valueOf() + os__path_separator.valueOf()).valueOf() + files.arr.get(new int(idx.valueOf())).valueOf()),false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function os__log(s) { + try { + builtin__println (new string( new string("os.log: ").valueOf() + s.valueOf())); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [params] */ +/** + * @constructor + * @param {{mode?: u32}} init +*/ +function os__MkdirParams({ mode = new int(0o777) }) { + this.mode = mode +}; +os__MkdirParams.prototype = { + toString() { + return `os__MkdirParams { mode: ${this["mode"].toString()} }` + }, + /** @type {u32} */ + mode: new u32(0), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} opath + * @param {os__MkdirParams} params + * @returns {void} +*/ +function os__mkdir_all(opath, params) { + try { + if ((os__exists(opath)).valueOf()) { + if ((os__is_dir(opath)).valueOf()) { + return; + } + return error(new string(`path \`${opath}\` already exists, and is not a folder`)); + } + /** @type {string} */ + const other_separator = new string(((new bool(os__path_separator.valueOf() == new string("/").valueOf())).valueOf() ? new string("\\") : new string("/"))); + /** @type {string} */ + const path = new string(string_replace(opath,other_separator, os__path_separator)); + /** @type {string} */ + let p = new string(((string_starts_with(path,os__path_separator)).valueOf() ? os__path_separator : new string(""))); + /** @type {Array_string} */ + const path_parts = string_split(string_trim_left(path,os__path_separator),os__path_separator); + for (const subdir of path_parts) { + try { + /** @type {string} */ + p.str = p + new string(new string( subdir.valueOf() + os__path_separator.valueOf())); + if ((new bool( os__exists(p).valueOf() && os__is_dir(p).valueOf())).valueOf()) { + continue; + } + os__mkdir(p, params); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__create_folder_when_it_does_not_exist(path) { + try { + if ((new bool( os__is_dir(path).valueOf() || os__is_link(path).valueOf())).valueOf()) { + return; + } + os__mkdir_all(path, (function() { + let _tmp41 = new os__MkdirParams({}); + _tmp41.mode = new int(0o700); + return _tmp41; + })() + ); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__cache_dir() { + try { + /** @type {string} */ + const xdg_cache_home = new string(os__getenv(new string("XDG_CACHE_HOME"))); + /** @type {string} */ + const cdir = new string(((new bool(xdg_cache_home.len.valueOf() > new int(0).valueOf())).valueOf() ? xdg_cache_home : os__join_path_single(os__home_dir(), new string(".cache")))); + os__create_folder_when_it_does_not_exist(cdir); + return cdir; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__pure_v_but_overridden_by_js_temp_dir() { + try { + /** @type {string} */ + let path = new string(os__getenv(new string("TMPDIR"))); + if (($process.platform == "windows")) + { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(os__getenv(new string("TEMP"))); + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(os__getenv(new string("TMP"))); + } + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(new string("C:/tmp")); + } + } + /** @type {string} */ + path = new string(os__get_long_path(path)); + } + if (($process.platform == "darwin")) + { + return new string("/tmp"); + } + if (($process.platform == "android")) + { + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(os__cache_dir()); + } + } + if (true) + { + /** @type {string} */ + path = new string(new string("/data/data/com.termux/files/usr/tmp")); + } + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(new string("/tmp")); + } + return path; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__vtmp_dir() { + try { + /** @type {string} */ + let vtmp = new string(os__getenv(new string("VTMP"))); + if ((new bool(vtmp.len.valueOf() > new int(0).valueOf())).valueOf()) { + os__create_folder_when_it_does_not_exist(vtmp); + return vtmp; + } + /** @type {int} */ + const uid = new int(os__getuid()); + /** @type {string} */ + vtmp = new string(os__join_path_single(os__temp_dir(), `v_${int_str(uid)}`)); + os__create_folder_when_it_does_not_exist(vtmp); + os__setenv(new string("VTMP"), vtmp, new bool(true)); + return vtmp; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__default_vmodules_path() { + try { + /** @type {string} */ + const hdir = new string(os__home_dir()); + /** @type {string} */ + const res = new string(os__join_path_single(hdir, new string(".vmodules"))); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__vmodules_dir() { + try { + /** @type {Array_string} */ + const paths = os__vmodules_paths(); + if ((new bool(paths.len.valueOf() > new int(0).valueOf())).valueOf()) { + return paths.arr.get(new int(new int(0).valueOf())); + } + return os__default_vmodules_path(); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {Array_string} +*/ +function os__vmodules_paths() { + try { + /** @type {string} */ + let path = new string(os__getenv(new string("VMODULES"))); + if ((new bool(path.valueOf() == new string("").valueOf())).valueOf()) { + /** @type {string} */ + path = new string(os__default_vmodules_path()); + } + /** @type {Array_string} */ + const splitted = string_split(path,os__path_delimiter); + /** @type {Array_string} */ + let list = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + for (let i = new int(0); i < splitted.len; i = new int(i + 1)) { + try { + /** @type {string} */ + const si = new string(splitted.arr.get(new int(i.valueOf()))); + /** @type {string} */ + const trimmed = new string(string_trim_right(si,os__path_separator)); + array_push(list,trimmed,false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + (function defer() { + })(); + return list; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/* [manualfree] */ +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__resource_abs_path(path) { + try { + /** @type {string} */ + const exe = new string(os__executable()); + /** @type {string} */ + const dexe = new string(os__dir(exe)); + /** @type {string} */ + let base_path = new string(os__real_path(dexe)); + /** @type {string} */ + const vresource = new string(os__getenv(new string("V_RESOURCE_PATH"))); + if ((new bool(vresource.len.valueOf() != new int(0).valueOf())).valueOf()) { + string_free(base_path,); + /** @type {string} */ + base_path = new string(vresource); + } + /** @type {string} */ + const fp = new string(os__join_path_single(base_path, path)); + /** @type {string} */ + const res = new string(os__real_path(fp)); + { + string_free(fp,); + string_free(vresource,); + string_free(base_path,); + string_free(dexe,); + string_free(exe,); + } + + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{sysname?: string, nodename?: string, release?: string, version?: string, machine?: string}} init +*/ +function os__Uname({ sysname = new string(""), nodename = new string(""), release = new string(""), version = new string(""), machine = new string("") }) { + this.sysname = sysname + this.nodename = nodename + this.release = release + this.version = version + this.machine = machine +}; +os__Uname.prototype = { + toString() { + return `os__Uname { sysname: "${this["sysname"].toString()}", nodename: "${this["nodename"].toString()}", release: "${this["release"].toString()}", version: "${this["version"].toString()}", machine: "${this["machine"].toString()}"}` + }, + /** @type {string} */ + sysname: new string(""), + /** @type {string} */ + nodename: new string(""), + /** @type {string} */ + release: new string(""), + /** @type {string} */ + version: new string(""), + /** @type {string} */ + machine: new string(""), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} cmd + * @returns {os__Result} +*/ +function os__execute_or_panic(cmd) { + try { + /** @type {os__Result} */ + const res = os__execute(cmd); + if ((new bool(res.exit_code.valueOf() != new int(0).valueOf())).valueOf()) { + builtin__eprintln (new string(`failed cmd: ${cmd}`)); + builtin__eprintln (new string(`failed code: ${int_str(res.exit_code)}`)); + builtin__panic (res.output); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cmd + * @returns {os__Result} +*/ +function os__execute_or_exit(cmd) { + try { + /** @type {os__Result} */ + const res = os__execute(cmd); + if ((new bool(res.exit_code.valueOf() != new int(0).valueOf())).valueOf()) { + builtin__eprintln (new string(`failed cmd: ${cmd}`)); + builtin__eprintln (new string(`failed code: ${int_str(res.exit_code)}`)); + builtin__eprintln (res.output); + builtin__exit(new int(1)); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cmd + * @returns {os__Result} +*/ +function os__execute_opt(cmd) { + try { + /** @type {os__Result} */ + const res = os__execute(cmd); + if ((new bool(res.exit_code.valueOf() != new int(0).valueOf())).valueOf()) { + return error(res.output); + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__quoted_path(path) { + try { + if (($process.platform == "windows")) + { + return ((string_ends_with(path,os__path_separator)).valueOf() ? new string(`"${new string( path.valueOf() + os__path_separator.valueOf())}"`) : new string(`"${path}"`)); + } + else + { + return new string(`'${path}'`); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__config_dir() { + try { + if (($process.platform == "windows")) + { + /** @type {string} */ + const app_data = new string(os__getenv(new string("AppData"))); + if ((new bool(app_data.valueOf() != new string("").valueOf())).valueOf()) { + return app_data; + } + } + else if (($process.platform == "darwin") || ($process.platform == "darwin") || ($process.platform == "darwin")) + { + /** @type {string} */ + const home = new string(os__home_dir()); + if ((new bool(home.valueOf() != new string("").valueOf())).valueOf()) { + return new string( home.valueOf() + new string("/Library/Application Support").valueOf()); + } + } + else + { + /** @type {string} */ + const xdg_home = new string(os__getenv(new string("XDG_CONFIG_HOME"))); + if ((new bool(xdg_home.valueOf() != new string("").valueOf())).valueOf()) { + return xdg_home; + } + /** @type {string} */ + const home = new string(os__home_dir()); + if ((new bool(home.valueOf() != new string("").valueOf())).valueOf()) { + return new string( home.valueOf() + new string("/.config").valueOf()); + } + } + return error(new string("Cannot find config directory")); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{dev?: u64, inode?: u64, mode?: u32, nlink?: u64, uid?: u32, gid?: u32, rdev?: u64, size?: u64, atime?: i64, mtime?: i64, ctime?: i64}} init +*/ +function os__Stat({ dev = new u64(0), inode = new u64(0), mode = new u32(0), nlink = new u64(0), uid = new u32(0), gid = new u32(0), rdev = new u64(0), size = new u64(0), atime = new i64(0), mtime = new i64(0), ctime = new i64(0) }) { + this.dev = dev + this.inode = inode + this.mode = mode + this.nlink = nlink + this.uid = uid + this.gid = gid + this.rdev = rdev + this.size = size + this.atime = atime + this.mtime = mtime + this.ctime = ctime +}; +os__Stat.prototype = { + toString() { + return `os__Stat { dev: ${this["dev"].toString()} , inode: ${this["inode"].toString()} , mode: ${this["mode"].toString()} , nlink: ${this["nlink"].toString()} , uid: ${this["uid"].toString()} , gid: ${this["gid"].toString()} , rdev: ${this["rdev"].toString()} , size: ${this["size"].toString()} , atime: ${this["atime"].toString()} , mtime: ${this["mtime"].toString()} , ctime: ${this["ctime"].toString()} }` + }, + /** @type {u64} */ + dev: new u64(0), + /** @type {u64} */ + inode: new u64(0), + /** @type {u32} */ + mode: new u32(0), + /** @type {u64} */ + nlink: new u64(0), + /** @type {u32} */ + uid: new u32(0), + /** @type {u32} */ + gid: new u32(0), + /** @type {u64} */ + rdev: new u64(0), + /** @type {u64} */ + size: new u64(0), + /** @type {i64} */ + atime: new i64(0), + /** @type {i64} */ + mtime: new i64(0), + /** @type {i64} */ + ctime: new i64(0), + $toJS() { return this; } + }; + +/** @namespace os */ +/** + * @function + * @param {string} path + * @param {os__MkdirParams} params + * @returns {void} +*/ +function os__mkdir(path, params) { + try { + if (true) + { + if ((new bool(path.valueOf() == new string(".").valueOf())).valueOf()) { + return; + } + $fs.mkdirSync(path.valueOf()) + return; + } + else + { + return error(new string("could not create folder")); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_dir(path) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + if (true) + { + res.val = $fs.existsSync(path,str) && $fs.lstatSync(path.str).isDirectory() + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_link(path) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + if (true) + { + res.val = $fs.existsSync(path.str) && $fs.lstatSync(path.str).isSymbolicLink() + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @constructor + * @param {{is_dir?: bool, is_link?: bool}} init +*/ +function os__PathKind({ is_dir = new bool(false), is_link = new bool(false) }) { + this.is_dir = is_dir + this.is_link = is_link +}; +os__PathKind.prototype = { + toString() { + return `os__PathKind { is_dir: ${this["is_dir"].toString()} , is_link: ${this["is_link"].toString()} }` + }, + /** @type {bool} */ + is_dir: new bool(false), + /** @type {bool} */ + is_link: new bool(false), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} path + * @returns {os__PathKind} +*/ +function os__kind_of_existing_path(path) { + try { + /** @type {bool} */ + const is_link = new bool(new bool(false)); + /** @type {bool} */ + const is_dir = new bool(new bool(false)); + if (true) + { + is_link.val = $fs.existsSync(path.str) && $fs.lstatSync(path.str).isSymbolicLink() + is_dir.val = $fs.existsSync(path,str) && $fs.lstatSync(path.str).isDirectory() + } + return (function() { + let _tmp42 = new os__PathKind({}); + _tmp42.is_dir = is_dir; + _tmp42.is_link = is_link; + return _tmp42; + })() + ; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__exists(path) { + try { + /** @type {bool} */ + const res = new bool(new bool(false)); + if (true) + { + res.val = $fs.existsSync(path.str) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {Array_string} +*/ +function os__ls(path) { + try { + if ((!os__is_dir(path).val ).valueOf()) { + return error(new string(`ls(): cannot open dir ${os__dir_str()}`)); + } + /** @type {Array_string} */ + const result = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + if (true) + { + let i = 0 + $fs.readdirSync(path.str).forEach((path) => result.arr[i++] = new string(path)) + } + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__get_raw_line() { + try { + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__executable() { + try { + return new string(""); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_executable(path) { + try { + builtin__eprintln (new string("TODO: There is no isExecutable on fs.stats")); + return new bool(false); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__rmdir(path) { + try { + if (true) + { + /** @type {string} */ + const err = new string(new string("")); + try { + $fs.rmdirSync(path.str) + return; + } catch (e) { + err.str = 'Failed to remove "' + path.str + '": ' + e.toString() + } + return error(err); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__rm(path) { + try { + if (true) + { + /** @type {string} */ + const err = new string(new string("")); + try { + $fs.rmSync(path.str) + return; + } catch (e) { + err.str = 'Failed to remove "' + path.str + '": ' + e.toString() + } + return error(err); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} src + * @param {string} dst + * @returns {void} +*/ +function os__cp(src, dst) { + try { + if (true) + { + /** @type {string} */ + const err = new string(new string("")); + try { + $fs.cpSync(src.str,dst.str); + return; + } catch (e) { + err.str = 'failed to copy ' + src.str + ' to ' + dst.str + ': ' + e.toString(); + } + return error(err); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} src + * @param {string} dst + * @returns {void} +*/ +function os__rename(src, dst) { + try { + if (true) + { + /** @type {string} */ + const err = new string(new string("")); + try { + $fs.renameSync(src.str,dst.str); + return; + } catch (e) { + err.str = 'failed to rename ' + src.str + ' to ' + dst.str + ': ' + e.toString(); + } + return error(err); + } + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {string} +*/ +function os__read_file(s) { + try { + /** @type {string} */ + let err = new string(new string("")); + /** @type {string} */ + err = new string(err); + /** @type {string} */ + const res = new string(new string("")); + try { + res.str = $fs.readFileSync(s.str).toString() + } catch (e) { + err.str = 'Failed to read file: ' + e.toString() + return error(err) + } + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__getwd() { + try { + /** @type {string} */ + const res = new string(new string("")); + res.str = $process.cwd() + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {int} +*/ +function os__getuid() { + try { + /** @type {int} */ + const res = new int(new int(0)); + if (process.getuid) res.val = process.getuid(); + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} cmd + * @param {Array_string} args + * @returns {void} +*/ +function os__execvp(cmd, args) { + try { + builtin__panic (new string("os.execvp() is not available on JS backend")); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__stdin_resume() { + try { + $process.stdin.resume(); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {bool} +*/ +function os__is_readable(path) { + try { + if (true) + { + /** @type {bool} */ + const res = new bool(new bool(false)); + try { res.val = $fs.accessSync(path.str,$fs.constants.R_OK); } catch { res.val = false; } + return res; + } + else + { + return new bool(false); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {string} +*/ +function os__get_long_path(path) { + try { + return path; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +if (true) +{ +const $child_process = require('child_process') +} +/** + * @function + * @param {string} filename + * @returns {os__Process} +*/ +function os__new_process(filename) { + try { + return new $ref((function() { + let _tmp43 = new os__Process({}); + _tmp43.filename = filename; + _tmp43.stdio_fd = new array(new array_buffer({arr: [new int(new int(-1)), new int(new int(-1)), new int(new int(-1))], len: new int(3), cap: new int(3)})); + return _tmp43; + })() + ); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_spawn_internal(p) { +p = new $ref(p) + try { + p.val.pid = $child_process.spawn( + p.val.filename+'', + p.val.args.arr.map((x) => x.valueOf() + ''), + { + env: (p.val.env_is_custom ? p.val.env : $process.env), + }) + p.val.pid.on('error', function (err) { builtin.panic('Failed to start subprocess') }) + /** @type {os__ProcessState} */ + p.val.status = os__ProcessState.running; + if ((p.val.use_stdio_ctl).valueOf()) { + p.val.pid.stdout.pipe(process.stdout) + p.val.pid.stdin.pipe(process.stdin) + p.val.pid.stderr.pipe(process.stderr) + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_run(p) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() != os__ProcessState.not_started.valueOf())).valueOf()) { + return; + } + os__Process_spawn_internal(p.valueOf(),); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_signal_kill(p) { +p = new $ref(p) + try { + if ((!(Array_os__ProcessState_contains(new array(new array_buffer({arr: [os__ProcessState.running, os__ProcessState.stopped], len: new int(2), cap: new int(2)})),p.val.status).valueOf())).valueOf()) { + return; + } + p.val.pid.kill('SIGKILL'); + /** @type {os__ProcessState} */ + p.val.status = os__ProcessState.aborted; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_signal_stop(p) { +p = new $ref(p) + try { + if ((!(Array_os__ProcessState_contains(new array(new array_buffer({arr: [os__ProcessState.running, os__ProcessState.stopped], len: new int(2), cap: new int(2)})),p.val.status).valueOf())).valueOf()) { + return; + } + p.val.pid.kill('SIGSTOP'); + /** @type {os__ProcessState} */ + p.val.status = os__ProcessState.aborted; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_signal_continue(p) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() != os__ProcessState.stopped.valueOf())).valueOf()) { + return; + } + p.val.pid.kill('SIGCONT'); + /** @type {os__ProcessState} */ + p.val.status = os__ProcessState.running; + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_wait(p) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() == os__ProcessState.not_started.valueOf())).valueOf()) { + os__Process_spawn_internal(p.valueOf(),); + } + if ((!(Array_os__ProcessState_contains(new array(new array_buffer({arr: [os__ProcessState.running, os__ProcessState.stopped], len: new int(2), cap: new int(2)})),p.val.status).valueOf())).valueOf()) { + return; + } + os__Process_wait_internal(p.valueOf(),); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_wait_internal(p) { +p = new $ref(p) + try { + p.val.pid.on('exit', function (code) { console.log(code) }) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_set_redirect_stdio(p) { +p = new $ref(p) + try { + /** @type {bool} */ + p.val.use_stdio_ctl = new bool(new bool(true)); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function os__Process_stdin_write(p, s) { +p = new $ref(p) + try { + os__Process_check_redirection_call(p.valueOf(),new string("stdin_write")); + p.val.pid.stdin.write(s) + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_stdin_resume(p) { +p = new $ref(p) + try { + p.val.pid.stdin.resume() + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {string} +*/ +function os__Process_stdout_slurp(p) { +p = new $ref(p) + try { + os__Process_check_redirection_call(p.valueOf(),new string("stdout_slurp")); + /** @type {string} */ + let res = new string(new string("")); + p.val.pid.stdout.on('data', function (data) { res = new string(data) }) + return res; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} fn_name + * @returns {void} +*/ +function os__Process_check_redirection_call(p, fn_name) { +p = new $ref(p) + try { + if ((!p.val.use_stdio_ctl.val ).valueOf()) { + builtin__panic (new string(`Call p.set_redirect_stdio() before calling p.${fn_name}`)); + } + if ((new bool(p.val.status.valueOf() == os__ProcessState.not_started.valueOf())).valueOf()) { + builtin__panic (new string(`Call p.${fn_name}() after you have called p.run()`)); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @returns {void} +*/ +function os__Process_close(p) { +p = new $ref(p) + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** @enum {number} */ +const os__ProcessState = { + not_started: 0, + running: 1, + stopped: 2, + exited: 3, + aborted: 4, + closed: 5, +}; + +/* [heap] */ +/** + * @constructor + * @param {{filename?: string, pid?: int, code?: int, status?: os__ProcessState, err?: string, args?: Array_string, work_folder?: string, env_is_custom?: bool, env?: Array_string, use_stdio_ctl?: bool, use_pgroup?: bool, stdio_fd?: Array_fixed_int_3, wdata?: voidptr, create_no_window?: bool}} init +*/ +function os__Process({ filename = new string(""), pid = new int(0), code = new int(-1), status = os__ProcessState.not_started, err = new string(""), args = empty_array(), work_folder = new string(""), env_is_custom = new bool(false), env = empty_array(), use_stdio_ctl = new bool(false), use_pgroup = new bool(false), stdio_fd = undefined, wdata = new voidptr(null), create_no_window = new bool(false) }) { + this.filename = filename + this.pid = pid + this.code = code + this.status = status + this.err = err + this.args = args + this.work_folder = work_folder + this.env_is_custom = env_is_custom + this.env = env + this.use_stdio_ctl = use_stdio_ctl + this.use_pgroup = use_pgroup + this.stdio_fd = stdio_fd + this.wdata = wdata + this.create_no_window = create_no_window +}; +os__Process.prototype = { + toString() { + return `os__Process { filename: "${this["filename"].toString()}", pid: ${this["pid"].toString()} , code: ${this["code"].toString()} , status: ${this["status"].toString()} , err: "${this["err"].toString()}", args: ${this["args"].toString()} , work_folder: "${this["work_folder"].toString()}", env_is_custom: ${this["env_is_custom"].toString()} , env: ${this["env"].toString()} , use_stdio_ctl: ${this["use_stdio_ctl"].toString()} , use_pgroup: ${this["use_pgroup"].toString()} , stdio_fd: ${this["stdio_fd"].toString()} , wdata: ${this["wdata"].toString()} , create_no_window: ${this["create_no_window"].toString()} }` + }, + /** @type {string} */ + filename: new string(""), + /** @type {int} */ + pid: new int(0), + /** @type {int} */ + code: new int(0), + /** @type {os__ProcessState} */ + status: undefined, + /** @type {string} */ + err: new string(""), + /** @type {Array_string} */ + args: empty_array(), + /** @type {string} */ + work_folder: new string(""), + /** @type {bool} */ + env_is_custom: new bool(false), + /** @type {Array_string} */ + env: empty_array(), + /** @type {bool} */ + use_stdio_ctl: new bool(false), + /** @type {bool} */ + use_pgroup: new bool(false), + /** @type {Array_fixed_int_3} */ + stdio_fd: undefined, + /** @type {voidptr} */ + wdata: new voidptr(null), + /** @type {bool} */ + create_no_window: new bool(false), + $toJS() { return this; } + }; + +/** + * @function + * @param {string} filename + * @returns {os__Process} +*/ +function os__pure_v_but_overridden_by_js_new_process(filename) { + try { + return new $ref((function() { + let _tmp44 = new os__Process({}); + _tmp44.filename = filename; + _tmp44.stdio_fd = new array(new array_buffer({arr: [new int(new int(-1)), new int(new int(-1)), new int(new int(-1))], len: new int(3), cap: new int(3)})); + return _tmp44; + })() + ); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Array_string} pargs + * @returns {void} +*/ +function os__Process_set_args(p, pargs) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() != os__ProcessState.not_started.valueOf())).valueOf()) { + return; + } + /** @type {Array_string} */ + p.val.args = pargs; + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} path + * @returns {void} +*/ +function os__Process_set_work_folder(p, path) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() != os__ProcessState.not_started.valueOf())).valueOf()) { + return; + } + /** @type {string} */ + p.val.work_folder = new string(os__real_path(path)); + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {Map_string_string} envs + * @returns {void} +*/ +function os__Process_set_environment(p, envs) { +p = new $ref(p) + try { + if ((new bool(p.val.status.valueOf() != os__ProcessState.not_started.valueOf())).valueOf()) { + return; + } + /** @type {bool} */ + p.val.env_is_custom = new bool(new bool(true)); + /** @type {Array_string} */ + p.val.env = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); + let _tmp45 = envs; + for (var _tmp46 in _tmp45.map) { + let v = _tmp45.map[_tmp46]; + let k = _tmp46; + try { + array_push(p.val.env,new string(`${k}=${v}`),false); + } catch (e) { + if (e instanceof BreakException) { break; } + else if (e instanceof ContinueException) { continue; } + else { throw e; } } + } + + return; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** + * @function + * @param {os__Signal} signal + * @returns {string} +*/ +function os__signal_str(signal) { + try { + /** @type {string} */ + let result = new string(string_to_upper(os__Signal_str(signal),)); + /** @type {string} */ + result = new string(`SIG${result}`); + return result; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {String} str + * @returns {os__Signal} +*/ +function os__signal_from_str(str) { + try { + /** @type {string} */ + const s = new string(new string(str)); + let _tmp47 = undefined; + + if (s.str === new string("SIGHUP").str) { + _tmp47 = os__Signal.hup; + + } + else if (s.str === new string("SIGINT").str) { + _tmp47 = os__Signal.int; + + } + else if (s.str === new string("SIGQUIT").str) { + _tmp47 = os__Signal.quit; + + } + else if (s.str === new string("SIGILL").str) { + _tmp47 = os__Signal.ill; + + } + else if (s.str === new string("SIGTRAP").str) { + _tmp47 = os__Signal.trap; + + } + else if (s.str === new string("SIGABRT").str) { + _tmp47 = os__Signal.abrt; + + } + else if (s.str === new string("SIGBUS").str) { + _tmp47 = os__Signal.bus; + + } + else if (s.str === new string("SIGFPE").str) { + _tmp47 = os__Signal.fpe; + + } + else if (s.str === new string("SIGKILL").str) { + _tmp47 = os__Signal.kill; + + } + else if (s.str === new string("SIGUSR1").str) { + _tmp47 = os__Signal.usr1; + + } + else if (s.str === new string("SIGSEGV").str) { + _tmp47 = os__Signal.segv; + + } + else if (s.str === new string("SIGUSR2").str) { + _tmp47 = os__Signal.usr2; + + } + else if (s.str === new string("SIGPIPE").str) { + _tmp47 = os__Signal.pipe; + + } + else if (s.str === new string("SIGALRM").str) { + _tmp47 = os__Signal.alrm; + + } + else if (s.str === new string("SIGTERM").str) { + _tmp47 = os__Signal.term; + + } + else if (s.str === new string("SIGSTKFLT").str) { + _tmp47 = os__Signal.stkflt; + + } + else if (s.str === new string("SIGCHLD").str) { + _tmp47 = os__Signal.chld; + + } + else if (s.str === new string("SIGCONT").str) { + _tmp47 = os__Signal.cont; + + } + else if (s.str === new string("SIGSTOP").str) { + _tmp47 = os__Signal.stop; + + } + else if (s.str === new string("SIGTSTP").str) { + _tmp47 = os__Signal.tstp; + + } + else if (s.str === new string("SIGTTIN").str) { + _tmp47 = os__Signal.ttin; + + } + else if (s.str === new string("SIGTTOU").str) { + _tmp47 = os__Signal.ttou; + + } + else if (s.str === new string("SIGURG").str) { + _tmp47 = os__Signal.urg; + + } + else if (s.str === new string("SIGXCPU").str) { + _tmp47 = os__Signal.xcpu; + + } + else if (s.str === new string("SIGXFSZ").str) { + _tmp47 = os__Signal.xfsz; + + } + else if (s.str === new string("SIGVTALRM").str) { + _tmp47 = os__Signal.vtalrm; + + } + else if (s.str === new string("SIGPROF").str) { + _tmp47 = os__Signal.prof; + + } + else if (s.str === new string("SIGWINCH").str) { + _tmp47 = os__Signal.winch; + + } + else if (s.str === new string("SIGPOLL").str) { + _tmp47 = os__Signal.poll; + + } + else if (s.str === new string("SIGPWR").str) { + _tmp47 = os__Signal.pwr; + + } + else if (s.str === new string("SIGSYS").str) { + _tmp47 = os__Signal.sys; + + } + else { + _tmp47 = builtin__panic (new string(`unknown signal: ${s}`)); + + }return _tmp47; + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {os__Signal} signum + * @param {os__SignalHandler} handler + * @returns {os__SignalHandler} +*/ +function os__signal_opt(signum, handler) { + try { + /** @type {string} */ + const signame = new string(os__signal_str(signum)); + const _tmp48 = signame; + if (true) + { + $process.on(signame.str,function (sig) { handler(os__signal_from_str(sig));}); + return handler; + } + else if (false) + { + let event = new CustomEvent(signame.str, {detail: signum}); + window.addEventListener(signame.str, function (e) { handler(e.detail); }); + return handler; + } + else + { + return error(new string("signal handlers are not supported on bare JS")); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace os */ +/** @enum {number} */ +const os__Signal = { + hup: 1, + int: 2, + quit: 3, + ill: 4, + trap: 5, + abrt: 6, + bus: 7, + fpe: 8, + kill: 9, + usr1: 10, + segv: 11, + usr2: 12, + pipe: 13, + alrm: 14, + term: 15, + stkflt: 16, + chld: 17, + cont: 18, + stop: 19, + tstp: 20, + ttin: 21, + ttou: 22, + urg: 23, + xcpu: 24, + xfsz: 25, + vtalrm: 26, + prof: 27, + winch: 28, + poll: 29, + pwr: 30, + sys: 31, +}; + +/** @namespace main */ +/** + * @constructor + * @param {{fpath?: string, line_nr?: int, fn_name?: string, src?: string, op?: string, llabel?: string, rlabel?: string, lvalue?: string, rvalue?: string}} init +*/ +function main__VAssertMetaInfo({ fpath = new string(""), line_nr = new int(0), fn_name = new string(""), src = new string(""), op = new string(""), llabel = new string(""), rlabel = new string(""), lvalue = new string(""), rvalue = new string("") }) { + this.fpath = fpath + this.line_nr = line_nr + this.fn_name = fn_name + this.src = src + this.op = op + this.llabel = llabel + this.rlabel = rlabel + this.lvalue = lvalue + this.rvalue = rvalue +}; +main__VAssertMetaInfo.prototype = { + toString() { + return `main__VAssertMetaInfo { fpath: "${this["fpath"].toString()}", line_nr: ${this["line_nr"].toString()} , fn_name: "${this["fn_name"].toString()}", src: "${this["src"].toString()}", op: "${this["op"].toString()}", llabel: "${this["llabel"].toString()}", rlabel: "${this["rlabel"].toString()}", lvalue: "${this["lvalue"].toString()}", rvalue: "${this["rvalue"].toString()}"}` + }, + /** @type {string} */ + fpath: new string(""), + /** @type {int} */ + line_nr: new int(0), + /** @type {string} */ + fn_name: new string(""), + /** @type {string} */ + src: new string(""), + /** @type {string} */ + op: new string(""), + /** @type {string} */ + llabel: new string(""), + /** @type {string} */ + rlabel: new string(""), + /** @type {string} */ + lvalue: new string(""), + /** @type {string} */ + rvalue: new string(""), + $toJS() { return this; } + }; + +/** @constant {bool} */ +let main__use_relative_paths = undefined; + +/** + * @function + * @returns {bool} +*/ +function main__can_use_relative_paths() { + try { + return ((os__getenv(new string("VERROR_PATHS")).str === new string("absolute").str)? (new bool(false)) : (new bool(true))); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {string} s + * @returns {void} +*/ +function main__myeprintln(s) { + try { + builtin__println (s); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {main__VAssertMetaInfo} i + * @returns {void} +*/ +function main__cb_assertion_failed(i) { + try { + /** @type {string} */ + const filepath = new string(((main__use_relative_paths).valueOf() ? i.fpath : os__real_path(i.fpath))); + /** @type {string} */ + let final_filepath = new string(new string( filepath.valueOf() + `:${int_str(new int( i.line_nr.valueOf() + new int(1).valueOf()))}:`.valueOf())); + /** @type {string} */ + let final_funcname = new string(new string( new string("fn ").valueOf() + i.fn_name.valueOf())); + /** @type {string} */ + const final_src = new string(new string( new string("assert ").valueOf() + i.src.valueOf())); + main__myeprintln(new string(`${final_filepath} ${final_funcname}`)); + if ((new bool( new bool(i.op.len.valueOf() > new int(0).valueOf()).valueOf() && new bool(i.op.valueOf() != new string("call").valueOf()).valueOf())).valueOf()) { + /** @type {string} */ + let lvtitle = new string(new string(" Left value:")); + /** @type {string} */ + let rvtitle = new string(new string(" Right value:")); + /** @type {string} */ + let slvalue = new string(`${i.lvalue}`); + /** @type {string} */ + let srvalue = new string(`${i.rvalue}`); + /** @type {int} */ + const cutoff_limit = new int(new int(30)); + if ((new bool( new bool(slvalue.len.valueOf() > cutoff_limit.valueOf()).valueOf() || new bool(srvalue.len.valueOf() > cutoff_limit.valueOf()).valueOf())).valueOf()) { + main__myeprintln(new string(` > ${final_src}`)); + main__myeprintln(lvtitle); + main__myeprintln(new string(` ${slvalue}`)); + main__myeprintln(rvtitle); + main__myeprintln(new string(` ${srvalue}`)); + } else { + main__myeprintln(new string(` > ${final_src}`)); + main__myeprintln(new string(` ${lvtitle} ${slvalue}`)); + main__myeprintln(new string(`${rvtitle} ${srvalue}`)); + } + } else { + main__myeprintln(new string(` ${final_src}`)); + } + main__myeprintln(new string("")); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {main__VAssertMetaInfo} i + * @returns {void} +*/ +function main__cb_assertion_ok(i) { +i = new $ref(i) + try { + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** + * @function + * @param {int} line_nr + * @param {string} file + * @param {string} mod + * @param {string} fn_name + * @param {string} errmsg + * @returns {void} +*/ +function main__cb_propagate_test_error(line_nr, file, mod, fn_name, errmsg) { + try { + /** @type {string} */ + const filepath = new string(((main__use_relative_paths).valueOf() ? file : os__real_path(file))); + /** @type {string} */ + let final_filepath = new string(new string( filepath.valueOf() + `:${int_str(line_nr)}:`.valueOf())); + /** @type {string} */ + let final_funcname = new string(new string( new string("fn ").valueOf() + string_replace(string_replace(fn_name,new string("main."), new string("")),new string("__"), new string(".")).valueOf())); + /** @type {string} */ + const final_msg = new string(errmsg); + main__myeprintln(new string(`${final_filepath} ${final_funcname} failed propagation with error: ${final_msg}`)); + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +/** @namespace main */ +/** @namespace main */ +/** + * @constructor + * @param {{}} init +*/ +function main__Foo({ }) { +}; +main__Foo.prototype = { + toString() { + return `main__Foo {}` + }, + $toJS() { return this; } + }; + +/** + * @function + * @returns {void} +*/ +function main__test_compiles() { + try { + // assert + if( new bool(true).valueOf() ) {let v_assert_meta_info__tmp49 = {} + v_assert_meta_info__tmp49.fpath = new string("vlib/v/tests/interop_test.js.v"); + v_assert_meta_info__tmp49.line_nr = new int("10") + v_assert_meta_info__tmp49.fn_name = new string("main.test_compiles") + v_assert_meta_info__tmp49.src = "true" + g_test_oks++; + main__cb_assertion_ok(v_assert_meta_info__tmp49); + } else { + let v_assert_meta_info__tmp50 = {} + v_assert_meta_info__tmp50.fpath = new string("vlib/v/tests/interop_test.js.v"); + v_assert_meta_info__tmp50.line_nr = new int("10") + v_assert_meta_info__tmp50.fn_name = new string("main.test_compiles") + v_assert_meta_info__tmp50.src = "true" + g_test_fails++; + main__cb_assertion_failed(v_assert_meta_info__tmp50); + builtin__exit(1); + } + } catch (e) { + if (e instanceof ReturnException) { return e.val; } + throw e; + } +} + +async function js_main() { + + globalThis.VTEST=1 + try { let res = main__test_compiles(); if (res instanceof Promise) { await res; } } catch (_e) {} + +} +None__.prototype.msg = function() { + return IError_msg(this) +} +None__.prototype.code = function() { + return IError_code(this) +} +None__.prototype.str = function() { + return None___str(this) +} +Error.prototype.msg = function() { + return Error_msg(this) +} +Error.prototype.code = function() { + return Error_code(this) +} +Error.prototype.str = function() { + return IError_str(this) +} +MessageError.prototype.msg = function() { + return MessageError_msg(this) +} +MessageError.prototype.code = function() { + return MessageError_code(this) +} +MessageError.prototype.str = function() { + return MessageError_str(this) +} +os__ExecutableNotFoundError.prototype.msg = function() { + return os__ExecutableNotFoundError_msg(this) +} +os__ExecutableNotFoundError.prototype.code = function() { + return IError_code(this) +} +os__ExecutableNotFoundError.prototype.str = function() { + return IError_str(this) +} +// Initializations for module strings +// Initializations for module builtin +none__ = new IError(new $ref(new None__({}))); +min_i8 = new int(-128); +max_i8 = new int(127); +min_i16 = new int(-32768); +max_i16 = new int(32767); +min_i32 = new int(-2147483648); +max_i32 = new int(2147483647); +min_int = min_i32; +max_int = max_i32; +min_i64 = new i64(new int_literal( new int(-9223372036854775807).valueOf() - new int(1).valueOf())); +max_i64 = new i64(BigInt(9223372036854775807n)); +min_u8 = new int(0); +max_u8 = new int(255); +min_u16 = new int(0); +max_u16 = new int(65535); +min_u32 = new int(0); +max_u32 = new int(4294967295); +min_u64 = new u64(BigInt(0n)); +max_u64 = new u64(BigInt(18446744073709551615n)); +// Initializations for module strings.textscanner +// Initializations for module os +os__fslash = new u8('/'); +os__bslash = new u8('\\'); +os__dot = new u8('.'); +os__qmark = new u8('?'); +os__path_delimiter = os__get_path_delimiter(); +os__path_separator = os__get_path_separator(); +os__args = new array(new array_buffer({arr: [], len: new int(0), cap: new int(0)})); +os__executable_suffixes = new array(new array_buffer({arr: [new string(new string(""))], len: new int(1), cap: new int(1)})); +os__wd_at_startup = os__getwd(); +os__init(); +// Initializations for module main +main__use_relative_paths = main__can_use_relative_paths(); +loadRoutine().then(_ => js_main()); \ No newline at end of file diff --git a/vlib/v/tests/interop_test.js.v b/vlib/v/tests/interop_test.js.v new file mode 100644 index 0000000000..6530b361cd --- /dev/null +++ b/vlib/v/tests/interop_test.js.v @@ -0,0 +1,12 @@ +// Not real external functions, so we won't call them +// We just want to make sure they compile + +struct Foo {} + +fn JS.e(a string, b ...string) int +fn JS.f(a &Foo) +fn JS.i(...string) + +fn test_compiles() { + assert true +} diff --git a/vlib/v/tests/orm_stmt_wrong_return_checking_test.v b/vlib/v/tests/orm_stmt_wrong_return_checking_test.v index defa201b98..925c7ac31a 100644 --- a/vlib/v/tests/orm_stmt_wrong_return_checking_test.v +++ b/vlib/v/tests/orm_stmt_wrong_return_checking_test.v @@ -2,8 +2,8 @@ import db.sqlite struct Target { pub mut: - id int @[primary; sql: serial] - kind string @[nonull] + id int @[primary; sql: serial] + kind ?string } fn add_target(repo Target) !int { @@ -15,15 +15,13 @@ fn add_target(repo Target) !int { insert repo into Target } or { println(err) + assert true return 1 } - assert true - - return 1 + return 2 } fn test_main() { - add_target(Target{1, 'foo'}) or { println('>> ${err}') } - assert true + assert add_target(Target{1, 'foo'}) or { 3 } == 1 } diff --git a/vlib/v/tests/typeof_test.v b/vlib/v/tests/typeof_test.v index 5e768cd351..c3acd9e096 100644 --- a/vlib/v/tests/typeof_test.v +++ b/vlib/v/tests/typeof_test.v @@ -1,11 +1,11 @@ fn test_typeof_on_simple_expressions() { a := int(123) - assert typeof(int(42)) == 'int' - assert typeof(f64(3.14)) == 'f64' - assert typeof(int(2) + 2 * 10) == 'int' - assert typeof(f64(1.0) * 12.2) == 'f64' + assert unsafe { typeof(int(42)) } == 'int' + assert unsafe { typeof(f64(3.14)) } == 'f64' + assert unsafe { typeof(int(2) + 2 * 10) } == 'int' + assert unsafe { typeof(f64(1.0) * 12.2) } == 'f64' // assert typeof(1.0 * f32(12.2)) == 'f32' - assert typeof(a) == 'int' + assert unsafe { typeof(a) } == 'int' assert typeof(a).name == 'int' // a2 := 123 // assert typeof(a2) == 'int_literal' @@ -18,8 +18,8 @@ fn test_typeof_on_simple_expressions() { fn test_arrays() { aint := []int{} astring := []string{} - assert typeof(aint) == '[]int' - assert typeof(astring) == '[]string' + assert unsafe { typeof(aint) } == '[]int' + assert unsafe { typeof(astring) } == '[]string' assert typeof(aint).name == '[]int' assert typeof(astring).name == '[]string' } @@ -38,12 +38,12 @@ struct FooBar { } fn test_typeof_on_structs() { - assert typeof(FooBar{}) == 'FooBar' + assert unsafe { typeof(FooBar{}) } == 'FooBar' astruct_static := [2]FooBar{} astruct_dynamic := [FooBar{}, FooBar{}] - assert typeof(astruct_static) == '[2]FooBar' + assert unsafe { typeof(astruct_static) } == '[2]FooBar' assert typeof(astruct_static).name == '[2]FooBar' - assert typeof(astruct_dynamic) == '[]FooBar' + assert unsafe { typeof(astruct_dynamic) } == '[]FooBar' assert typeof(astruct_dynamic).name == '[]FooBar' } @@ -64,9 +64,9 @@ fn test_typeof_on_sumtypes() { c := MySumType(FooBar{ x: 43 }) - assert typeof(a) == 'int' - assert typeof(b) == 'f32' - assert typeof(c) == 'FooBar' + assert unsafe { typeof(a) } == 'int' + assert unsafe { typeof(b) } == 'f32' + assert unsafe { typeof(c) } == 'FooBar' assert a.type_name() == 'int' assert b.type_name() == 'f32' assert c.type_name() == 'FooBar' @@ -110,10 +110,10 @@ fn test_typeof_on_sumtypes_of_structs() { b := fexpr(2) c := fexpr(3) d := ExprType(UnaryExpr{}) - assert typeof(a) == 'UnaryExpr' - assert typeof(b) == 'BinExpr' - assert typeof(c) == 'BoolExpr' - assert typeof(d) == 'UnaryExpr' + assert unsafe { typeof(a) } == 'UnaryExpr' + assert unsafe { typeof(b) } == 'BinExpr' + assert unsafe { typeof(c) } == 'BoolExpr' + assert unsafe { typeof(d) } == 'UnaryExpr' assert a.type_name() == 'UnaryExpr' assert b.type_name() == 'BinExpr' assert c.type_name() == 'BoolExpr' @@ -136,10 +136,10 @@ fn myfn4() i8 { } fn test_typeof_on_fn() { - assert typeof(myfn) == 'fn (int) int' - assert typeof(myfn2) == 'fn ()' - assert typeof(myfn3) == 'fn (int, string) u8' - assert typeof(myfn4) == 'fn () i8' + assert unsafe { typeof(myfn) } == 'fn (int) int' + assert unsafe { typeof(myfn2) } == 'fn ()' + assert unsafe { typeof(myfn3) } == 'fn (int, string) u8' + assert unsafe { typeof(myfn4) } == 'fn () i8' assert typeof(myfn).name == typeof(myfn) assert typeof(&myfn).name == '&fn (int) int' assert typeof(myfn2).name == typeof(myfn2) diff --git a/vlib/v/util/version/version_test.v b/vlib/v/util/version/version_test.v index d086e38285..7056740038 100644 --- a/vlib/v/util/version/version_test.v +++ b/vlib/v/util/version/version_test.v @@ -2,6 +2,10 @@ import v.util.version import os fn test_githash() { + if os.getenv('GITHUB_JOB') == '' { + eprintln('> skipping test, since it needs GITHUB_JOB to be defined (it is flaky on development machines, with changing repos and v compiled with `./v self` from uncommited changes).') + return + } if !os.exists(os.join_path(@VMODROOT, '.git')) { eprintln('> skipping test due to missing V .git directory') return diff --git a/vlib/veb/context.v b/vlib/veb/context.v index 42baf795d9..b88ceb18b6 100644 --- a/vlib/veb/context.v +++ b/vlib/veb/context.v @@ -42,8 +42,8 @@ pub: // time.ticks() from start of veb connection handle. // You can use it to determine how much time is spent on your request. page_gen_start i64 - req http.Request pub mut: + req http.Request custom_mime_types map[string]string // TCP connection to client. Only for advanced usage! conn &net.TcpConn = unsafe { nil } diff --git a/vlib/veb/csrf/csrf_test.v b/vlib/veb/csrf/csrf_test.v index b8343d4db2..947940a950 100644 --- a/vlib/veb/csrf/csrf_test.v +++ b/vlib/veb/csrf/csrf_test.v @@ -45,19 +45,15 @@ fn test_protect() { // get cookie value from "name=value;" cookie = cookie.split(' ')[0].all_after('=').replace(';', '') - form := { - csrf_config.token_name: token - } - cookie_map := { - csrf_config.cookie_name: cookie - } ctx = veb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: csrf_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, csrf_config) assert valid == true @@ -82,19 +78,15 @@ fn test_timeout() { // get cookie value from "name=value;" cookie = cookie.split(' ')[0].all_after('=').replace(';', '') - form := { - short_time_config.token_name: token - } - cookie_map := { - short_time_config.cookie_name: cookie - } ctx = veb.Context{ - form: form + form: { + short_time_config.token_name: token + } req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: short_time_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, short_time_config) @@ -105,21 +97,16 @@ fn test_valid_origin() { // valid because both Origin and Referer headers are present token, cookie := get_token_cookie('') - form := { - csrf_config.token_name: token - } - cookie_map := { - csrf_config.cookie_name: cookie - } - mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') req.add_header(.referer, 'http://${allowed_origin}/test') mut ctx := veb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -131,20 +118,15 @@ fn test_invalid_origin() { // invalid because either the Origin, Referer or neither are present token, cookie := get_token_cookie('') - form := { - csrf_config.token_name: token - } - cookie_map := { - csrf_config.cookie_name: cookie - } - mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') mut ctx := veb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -153,11 +135,13 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.referer, 'http://${allowed_origin}/test') ctx = veb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -166,10 +150,12 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) ctx = veb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -288,24 +274,25 @@ fn protect_route_util(path string) { method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: 'altered') res = req.do() or { panic(err) } assert res.status() == .forbidden - // Everything is valid now and the request should succeed - cookies[session_id_cookie_name] = session_id - + // req = http.Request{ method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: session_id) + // Everything is valid now and the request should succeed, since session_id_cookie_name will be session_id res = req.do() or { panic(err) } assert res.status() == .ok } @@ -328,13 +315,8 @@ fn testsuite_end() { // Utility functions fn get_token_cookie(session_id string) (string, string) { - mut ctx := veb.Context{ - req: http.Request{ - cookies: { - session_id_cookie_name: session_id - } - } - } + mut ctx := veb.Context{} + ctx.req.add_cookie(name: session_id_cookie_name, value: session_id) token := csrf.set_token(mut ctx, csrf_config_origin) diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v index 12f2a55a18..7f180aaad5 100644 --- a/vlib/vweb/assets/assets.v +++ b/vlib/vweb/assets/assets.v @@ -182,8 +182,10 @@ pub fn (mut am AssetManager) add(asset_type string, file string) bool { } asset := Asset{ file_path: file - last_modified: time.Time{ - unix: os.file_last_mod_unix(file) + last_modified: unsafe { + time.Time{ + unix: os.file_last_mod_unix(file) + } } } if asset_type == 'css' { diff --git a/vlib/vweb/csrf/csrf_test.v b/vlib/vweb/csrf/csrf_test.v index 84781c14f6..710af1270d 100644 --- a/vlib/vweb/csrf/csrf_test.v +++ b/vlib/vweb/csrf/csrf_test.v @@ -48,16 +48,13 @@ fn test_protect() { form := { csrf_config.token_name: token } - cookie_map := { - csrf_config.cookie_name: cookie - } ctx = vweb.Context{ form: form req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: csrf_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, csrf_config) assert valid == true @@ -85,16 +82,13 @@ fn test_timeout() { form := { short_time_config.token_name: token } - cookie_map := { - short_time_config.cookie_name: cookie - } ctx = vweb.Context{ form: form req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: short_time_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, short_time_config) @@ -104,22 +98,16 @@ fn test_timeout() { fn test_valid_origin() { // valid because both Origin and Referer headers are present token, cookie := get_token_cookie('') - - form := { - csrf_config.token_name: token - } - cookie_map := { - csrf_config.cookie_name: cookie - } - mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') req.add_header(.referer, 'http://${allowed_origin}/test') mut ctx := vweb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -130,21 +118,15 @@ fn test_valid_origin() { fn test_invalid_origin() { // invalid because either the Origin, Referer or neither are present token, cookie := get_token_cookie('') - - form := { - csrf_config.token_name: token - } - cookie_map := { - csrf_config.cookie_name: cookie - } - mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') mut ctx := vweb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -153,11 +135,13 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.referer, 'http://${allowed_origin}/test') ctx = vweb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -166,10 +150,12 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) ctx = vweb.Context{ - form: form + form: { + csrf_config.token_name: token + } req: req } @@ -305,33 +291,27 @@ fn protect_route_util(path string) { // session id is altered: test if session hijacking is possible // if the session id the csrftoken changes so the cookie can't be validated - mut cookies := { - csrf_config.cookie_name: cookie - session_id_cookie_name: 'altered' - } - req = http.Request{ method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: 'altered') res = req.do() or { panic(err) } assert res.status() == .forbidden - // Everything is valid now and the request should succeed - cookies[session_id_cookie_name] = session_id - req = http.Request{ method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } - + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: session_id) + // Everything is valid now and the request should succeed res = req.do() or { panic(err) } assert res.status() == .ok } @@ -358,13 +338,8 @@ fn testsuite_end() { // Utility functions fn get_token_cookie(session_id string) (string, string) { - mut ctx := vweb.Context{ - req: http.Request{ - cookies: { - session_id_cookie_name: session_id - } - } - } + mut ctx := vweb.Context{} + ctx.req.add_cookie(name: session_id_cookie_name, value: session_id) token := csrf.set_token(mut ctx, csrf_config_origin) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 8a056dff9d..e0c580036d 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -153,11 +153,10 @@ mut: content_type string = 'text/plain' status string = '200 OK' ctx context.Context = context.EmptyContext{} -pub: +pub mut: // HTTP Request req http.Request // TODO: Response -pub mut: done bool // time.ticks() from start of vweb connection handle. // You can use it to determine how much time is spent on your request. diff --git a/vlib/x/json2/count_test.v b/vlib/x/json2/count_test.v index 06f955420b..4e8bd34ade 100644 --- a/vlib/x/json2/count_test.v +++ b/vlib/x/json2/count_test.v @@ -9,7 +9,7 @@ const fixed_time = time.Time{ hour: 13 minute: 54 second: 25 - unix: 1647006865 + // unix: 1647006865 } type StringAlias = string diff --git a/vlib/x/json2/decoder2/tests/decode_struct_test.v b/vlib/x/json2/decoder2/tests/decode_struct_test.v index eeeaa64118..0b6b8cd970 100644 --- a/vlib/x/json2/decoder2/tests/decode_struct_test.v +++ b/vlib/x/json2/decoder2/tests/decode_struct_test.v @@ -8,7 +8,7 @@ const fixed_time = time.Time{ hour: 13 minute: 54 second: 25 - unix: 1647006865 + // unix: 1647006865 } type StringAlias = string diff --git a/vlib/x/json2/tests/decode_struct_test.v b/vlib/x/json2/tests/decode_struct_test.v index 6cac67414b..f4fb37fc79 100644 --- a/vlib/x/json2/tests/decode_struct_test.v +++ b/vlib/x/json2/tests/decode_struct_test.v @@ -8,7 +8,7 @@ const fixed_time = time.Time{ hour: 13 minute: 54 second: 25 - unix: 1647006865 + // unix: 1647006865 } type StringAlias = string diff --git a/vlib/x/json2/tests/encode_struct_test.v b/vlib/x/json2/tests/encode_struct_test.v index 7c4f782a8e..5cef9efb96 100644 --- a/vlib/x/json2/tests/encode_struct_test.v +++ b/vlib/x/json2/tests/encode_struct_test.v @@ -8,7 +8,7 @@ const fixed_time = time.Time{ hour: 13 minute: 54 second: 25 - unix: 1647006865 + // unix: 1647006865 } type StringAlias = string diff --git a/vlib/x/json2/tests/encode_struct_todo_test.vv b/vlib/x/json2/tests/encode_struct_todo_test.vv index 9f4d53f2f8..8dcd98f621 100644 --- a/vlib/x/json2/tests/encode_struct_todo_test.vv +++ b/vlib/x/json2/tests/encode_struct_todo_test.vv @@ -8,7 +8,7 @@ const fixed_time = time.Time{ hour: 13 minute: 54 second: 25 - unix: 1647006865 + // unix: 1647006865 } type StringAlias = string diff --git a/vlib/x/vweb/context.v b/vlib/x/vweb/context.v index 532db96f9a..54fd2e36db 100644 --- a/vlib/x/vweb/context.v +++ b/vlib/x/vweb/context.v @@ -42,8 +42,8 @@ pub: // time.ticks() from start of vweb connection handle. // You can use it to determine how much time is spent on your request. page_gen_start i64 - req http.Request pub mut: + req http.Request custom_mime_types map[string]string // TCP connection to client. Only for advanced usage! conn &net.TcpConn = unsafe { nil } diff --git a/vlib/x/vweb/csrf/csrf_test.v b/vlib/x/vweb/csrf/csrf_test.v index fb23dbe440..eb4cf18f02 100644 --- a/vlib/x/vweb/csrf/csrf_test.v +++ b/vlib/x/vweb/csrf/csrf_test.v @@ -48,16 +48,13 @@ fn test_protect() { form := { csrf_config.token_name: token } - cookie_map := { - csrf_config.cookie_name: cookie - } ctx = vweb.Context{ form: form req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: csrf_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, csrf_config) assert valid == true @@ -85,16 +82,13 @@ fn test_timeout() { form := { short_time_config.token_name: token } - cookie_map := { - short_time_config.cookie_name: cookie - } ctx = vweb.Context{ form: form req: http.Request{ method: .post - cookies: cookie_map } } + ctx.req.add_cookie(name: short_time_config.cookie_name, value: cookie) valid := csrf.protect(mut ctx, short_time_config) @@ -108,14 +102,11 @@ fn test_valid_origin() { form := { csrf_config.token_name: token } - cookie_map := { - csrf_config.cookie_name: cookie - } mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') req.add_header(.referer, 'http://${allowed_origin}/test') mut ctx := vweb.Context{ @@ -134,14 +125,10 @@ fn test_invalid_origin() { form := { csrf_config.token_name: token } - cookie_map := { - csrf_config.cookie_name: cookie - } - mut req := http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.origin, 'http://${allowed_origin}') mut ctx := vweb.Context{ form: form @@ -153,8 +140,8 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) req.add_header(.referer, 'http://${allowed_origin}/test') ctx = vweb.Context{ form: form @@ -166,8 +153,8 @@ fn test_invalid_origin() { req = http.Request{ method: .post - cookies: cookie_map } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) ctx = vweb.Context{ form: form req: req @@ -288,24 +275,25 @@ fn protect_route_util(path string) { method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: 'altered') res = req.do() or { panic(err) } assert res.status() == .forbidden - // Everything is valid now and the request should succeed - cookies[session_id_cookie_name] = session_id - + // req = http.Request{ method: .post url: 'http://${localserver}/${path}' data: formdata - cookies: cookies header: header } + req.add_cookie(name: csrf_config.cookie_name, value: cookie) + req.add_cookie(name: session_id_cookie_name, value: session_id) + // Everything is valid now and the request should succeed, since session_id_cookie_name will be session_id res = req.do() or { panic(err) } assert res.status() == .ok } @@ -328,13 +316,8 @@ fn testsuite_end() { // Utility functions fn get_token_cookie(session_id string) (string, string) { - mut ctx := vweb.Context{ - req: http.Request{ - cookies: { - session_id_cookie_name: session_id - } - } - } + mut ctx := vweb.Context{} + ctx.req.add_cookie(name: session_id_cookie_name, value: session_id) token := csrf.set_token(mut ctx, csrf_config_origin)