ref: c2f922830897fb3dee6c271860a28985726d7c0f
dir: /libstd/test.myr/
use std const main = {args : byte[:][:] var x : byte#[1024] var sz var i var ctx var o var a std.put("args.len = %i\n", args.len) for i = 0; i < args.len; i++ std.put("args[%i] = %s\n", i, args[i]) ;; ctx = std.optinit("asdf:g?", args) std.put("arglen = %i\n", ctx.args.len) while !std.optdone(ctx) (o, a) = std.optnext(ctx) std.put("option %c, arg = %s\n", o, a) ;; for i = 0; i < ctx.args.len; i++ std.put("arg %s\n", ctx.args[i]) ;; /* try the byte allocator for large variety of sizes. */ for sz = 1; sz < 65536; sz *= 2 for i = 0; i < 1024; i++ x[i] = std.bytealloc(sz) ;; for i = 0; i < 1024; i++ std.bytefree(x[i], sz) ;; ;; /* make sure the generic allocator works */ for i = 0; i < 1024; i++ x[i] = std.alloc() ;; for i = 0; i < 1024; i++ std.free(x[i]) ;; std.write(1, "Hello, 世界\n") chartypes() testrng() std.put("format output %i %i %s %s\n", 123, 321, "asdf", "מִלָּה") std.put("format with no args\n") } const chartypes = { var s var c var buf : byte[32] s = " 1世界 äa\n" while s.len != 0 (c, s) = std.striter(s) if std.isspace(c) std.write(1, "Space\n") elif std.isalpha(c) std.write(1, "Alpha\n") elif std.isnum(c) std.write(1, "Num\n") else std.write(1, "Dunno\n") ;; if !std.encode(buf[:std.charlen(c)], c) std.write(1, "couldn't encode\n") ;; std.write(1, buf[:std.charlen(c)]) std.write(1, "\n") ;; if !std.encode(buf[0:3], -1) std.write(1, "couldn't encode\n") ;; } const testrng = { var r var i r = std.mksrng(10) for i = 0; i < 10; i++ std.put("r[%i] = %l\n", i, std.rand32(r) castto(int64)) ;; std.put("\n"); }