<commit_before>import Multiboot, Panic

Bitmap: class {
    size: UInt
    data: UInt32*

    init: func (=size) {
        data = gc_malloc(sizeof(UInt32) * size) as UInt32*
        memset(data, 0 as UInt32, sizeof(UInt32) * size)
    }

    set: func (index, bit: UInt) {
        data[index] |= (1 << bit)
    }

    isSet: func (index, bit: UInt) -> Bool {
        data[index] & (1 << bit)
    }

    // This is a quick way to check if all the bits in an element are set.
    allSet: func (index: UInt) -> Bool {
        data[index] == 0xFFFFFFFF
    }

    clear: func (index, bit: UInt) {
        data[index] &= ~(1 << bit)
    }
}

PMM: class {
    FRAME_SIZE := static 4096 // 4kB

    memorySize: static UInt
    lastElement: static UInt
    bitmap: static Bitmap

    setup: static func {
        // memUpper is given in kB, but we want B
        memorySize = multiboot memUpper * 1024

        frameCount := memorySize / FRAME_SIZE

        // 4 bytes equals 32 bits, use 1 bit per frame.
        elementCount := frameCount / 32

        // Add an extra element for the remainder of the frames if not aligned
        if(frameCount % 32) {
            elementCount += 1
        }

        bitmap = Bitmap new(elementCount)

        // If the last element used less than 32 bits, set the other bits to
        // make sure the allocator doesn't try to use them.
        for(i in (frameCount % 32)..32) {
            bitmap set(bitmap size - 1, i)
        }
    }

    allocFrame: func -> UInt {
        for(elem in lastElement..Bitmap size) {
            if(bitmap allSet(elem)) continue

            for(bit in 0..32) {
                if(bitmap isSet(elem, bit)) {
                    // We've found ourselves a free bit, allocate and return it.
                    bitmap set(elem, bit)
                    lastElement = elem
                    return elem * 32 + bit
                }
            }

            lastElement += 1<commit_msg>PMM.ooc line 65.. "if(bitmap..." -> "if(!bitmap..." (typo)<commit_after>import Multiboot, Panic

Bitmap: class {
    size: UInt
    data: UInt32*

    init: func (=size) {
        data = gc_malloc(sizeof(UInt32) * size) as UInt32*
        memset(data, 0 as UInt32, sizeof(UInt32) * size)
    }

    set: func (index, bit: UInt) {
        data[index] |= (1 << bit)
    }

    isSet: func (index, bit: UInt) -> Bool {
        data[index] & (1 << bit)
    }

    // This is a quick way to check if all the bits in an element are set.
    allSet: func (index: UInt) -> Bool {
        data[index] == 0xFFFFFFFF
    }

    clear: func (index, bit: UInt) {
        data[index] &= ~(1 << bit)
    }
}

PMM: class {
    FRAME_SIZE := static 4096 // 4kB

    memorySize: static UInt
    lastElement: static UInt
    bitmap: static Bitmap

    setup: static func {
        // memUpper is given in kB, but we want B
        memorySize = multiboot memUpper * 1024

        frameCount := memorySize / FRAME_SIZE

        // 4 bytes equals 32 bits, use 1 bit per frame.
        elementCount := frameCount / 32

        // Add an extra element for the remainder of the frames if not aligned
        if(frameCount % 32) {
            elementCount += 1
        }

        bitmap = Bitmap new(elementCount)

        // If the last element used less than 32 bits, set the other bits to
        // make sure the allocator doesn't try to use them.
        for(i in (frameCount % 32)..32) {
            bitmap set(bitmap size - 1, i)
        }
    }

    allocFrame: func -> UInt {
        for(elem in lastElement..Bitmap size) {
            if(bitmap allSet(elem)) continue

            for(bit in 0..32) {
                if(!bitmap isSet(elem, bit)) {
                    // We've found ourselves a free bit, allocate and return it.
                    bitmap set(elem, bit)
                    lastElement = elem
                    return elem * 32 + bit
                }
            }

            lastElement += 1
{'fraction_non_alphanumeric': 0.10151898734177216, 'fraction_numerical': 0.02379746835443038, 'mean_word_length': 1.6357571714476318, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7621571', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1163, 'n_words': 418}