cluna 1.1.0

Tool to convert Lua code into Clue code Made by MarkosTh09
Documentation
---
source: src/main.rs
expression: compiled
input_file: test-data/lua5.2-tests/checktable.lua
---
assert(rawget(_G, "stat") == nil);
if T == nil {
    stat = fn () {
        print("`querytab' not active");
    }
    return
}
global fn checktable(t) {
    local asize, hsize, ff = T.querytab(t)
    local l = {}
    for i = 0, hsize - 1 {
        local key, val, next = T.querytab(t, i + asize)
        if key == nil {
            assert(l[(i)] == nil && val == nil && next == nil);
        } elseif if key == "<undef>" {
            assert(val == nil);
        } else {
            assert(t[(key)] == val);
            local mp = T.hash(key, t)
            if l[(i)] {
                assert(l[(i)] == mp);
            } elseif if mp != i {
                l[(i)] = mp
            } else {
                l[(mp)] = {
                    mp
                }
                while next {
                    assert(ff <= next && next < hsize);
                    if l[(next)] {
                        assert(l[(next)] == mp);
                    } else {
                        l[(next)] = mp
                    }
                    table.insert(l[(mp)], next);
                    key, val, next = T.querytab(t, next)
                    assert(key);
                }
            }
        }
    }
    l.asize = asize
    l.hsize = hsize
    l.ff = ff
    return l
}
global fn mostra(t) {
    local asize, hsize, ff = T.querytab(t)
    print(asize, hsize, ff);
    print('------');
    for i = 0, asize - 1 {
        local _, v = T.querytab(t, i)
        print(string.format("[%d] -", i), v);
    }
    print('------');
    for i = 0, hsize - 1 {
        print(i, T.querytab(t, i + asize));
    }
    print('-------------');
}
global fn stat(t) {
    t = checktable(t)
    local nelem, nlist = 0, 0
    local maxlist = {}
    for i = 0, t.hsize - 1 {
        if type(t[(i)]) == 'table' {
            local n = table.getn(t[(i)])
            nlist = nlist + 1
            nelem = nelem + n
            if !maxlist[(n)] {
                maxlist[(n)] = 0
            }
            maxlist[(n)] = maxlist[(n)] + 1
        }
    }
    print(string.format("hsize=%d  elements=%d  load=%.2f  med.len=%.2f (asize=%d)", t.hsize, nelem, nelem / t.hsize, nelem / nlist, t.asize));
    for i = 1, table.getn(maxlist) {
        local n = maxlist[(i)] || 0
        print(string.format("%5d %10d %.2f%%", i, n, n * 100 / nlist));
    }
}