#Nexirol&Renirol

2417 messages · Page 3 of 3 (latest)

deft kestrel
#

hm
why can't I use static.defaultEngine to differentiate between a local and a static var

#

I mean I can do that with this for instance vars, why not static for static?

lapis turtle
#

Yup

deft kestrel
#

... how is rider alone so much larger than intellij plus all the assorted plugins I have?

#

I mean over here it's not but like
why is the size so different in the above screenshot

#

ok the difference in the second one comes down to caches

#

speaking of which, I should probably clear caches to clean up some space on my laptop I guess

#

or at least I'm assuming it's caches

deft kestrel
#

tomorrow, I'm setting up a readInt function for debug purposes
from there, I'm probably gonna setup arrays and make a snake game in my IR builder

azure zinc
#

Clangd + VSCode does a good job btw

deft kestrel
#

(I do not do C/C++ dev stuff much)

#

also vscode just feels
off to me
I’ve done my best to configure it but it just never quite feels right for some reason

#

especially on windows
feels better to me on linux for some reason KEKW

lapis turtle
#

I should prolly get clangd lsp running on nvim but thats for lame people

deft kestrel
#

KEKW so in theory, my readInt function works
in practice, I haven't tested any of it yet (read text from console, nor string to int)
so we'll see how much of a headache that becomes, considering I didn't even refer to compiled C/C++; I literally just wrote the ir builder generation from experience

#

KEKW trying to write instructions after the end of a method creates a new block, thus crashing the compiler if the method is not a void and the block is unterminated, incredible

#

and trying to write my module to the disk segfaults the compiler, wha

#

Failed to acquire targetTriple: Unable to find target for this triple (no targets are registered)
oh

#

ah nice
readint segfaults the compiler frOK

#

actually read segfaults the compiler

#

KEKW I'm stupid (I passed just the text as the argument instead of the list of arguments)

#

ok I now have like a bajillion validation errors but that's fine

deft kestrel
#

huh
my optimization pass set (which worked on int to string) segfaults it

#

Basic Block in function 'stringToInt' does not have terminator!
label %header
Failed to verify function stringToInt
yeah that explains it

#

and I think this is now my problem

#

... nope

#

bleaker_kekw okay I'm gonna have to refer to actual compilation results I think

#
declare dso_local %struct._iobuf* @__acrt_iob_func(i32) #2

define dso_local void @test() #0 !dbg !132 {
  %6 = call %struct._iobuf* @__acrt_iob_func(i32 0), !dbg !140
  %7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i32 0, i32 0, !dbg !140
  %8 = call i8* @fgets(i8* %7, i32 100, %struct._iobuf* %6), !dbg !140```claude does not disappoint
#

took a four step back and forth to get here but 🤷

#

KEKW okay so there's a bug somewhere between reading the string and printing the integer version of the string

#

and I can eliminate the bug being in intToString, because that function is known to work
so it's either read string or stringToInt

#

I can narrow it down to stringToInt; printing the string repr works

#

okay qwhat

#

ah I was incorrectly allocating an extra string
makes sense tbh

#

eh that's close

#

yipee!

#

next:

  • arrays so that I can represent strings
  • snake game
#
        if (!feof(stdin) && _kbhit()) {
            fgets(chars, 100, stdin);
            puts(chars);
        }```where has this been my whole life ![bleaker_kekw](https://cdn.discordapp.com/emojis/1271044788086509619.webp?size=128 "bleaker_kekw")
#

(detecting if there's console input currently available)

#

declare dso_local i32 @_kbhit() local_unnamed_addr #3
declare dso_local i32 @feof(%struct._iobuf* nocapture) local_unnamed_addr #2

oh AND it's a direct translation to llvm ir, sweet

lapis turtle
deft kestrel
#

KEKW nope, I still don't need msvc yet

#

reason: ucrt is an actual functional alternative to msvc for windows it seems

#

actually clangrt builtins alone is enough, huh

#

either that or these are working now

                        "/defaultlib:msvcrt /defaultlib:ucrt /subsystem:console /verbose"
#

oh they are

#

but yeah ucrt is enough

deft kestrel
#

or is there a different way I should do that? or what

lapis turtle
deft kestrel
#

incredible
O3-5 is aggressive enough that it can cause LLVM to segfault when validating the module KEKW

#

or maybe it just doesn't like validating modules after optimization passes

#

lld-link: error: undefined symbol: __chkstk
but it also can't link

#

but msvc does solve that one

#

context: O3-5 basically tells llvm go do whatever the heck you want essentially KEKW

deft kestrel
#

I'm also sorta making a machine learning library for java in the background
using pytorch behind the scenes but I'm actually manually going through backpropagation, so I should be able to eventually switch to tensorrt or onnxruntime and still have the ability to train my models

#
        error.ref();
        Tensor scalar = value.compute().getEngine().create(DataType.FLOAT, 1);
        scalar.set(value.compute().shape().size(axis), 0);
        SymbolicTensor mulRes = error.div(scalar);
        value.backward(mulRes);
        mulRes.close();
        scalar.close();
        error.refLater();```manually as in manually telling my own api to tell pytorch to do it from within in my api
#

ok tensorrt might not be as viable for this KEKW
onnx however maybe

deft kestrel
#

KEKW library doesn't initialize properly, I need to do it manually using reflection, that's a new one

deft kestrel
deft kestrel
#

I just realized I "need" a random number generator KEKW

deft kestrel
#

if this works first try, I will be concerned KEKW

#

yeah I had some illegal code

deft kestrel
#

👍 it does not work properly either

deft kestrel
#

0 -> x+
1 -> y+
2 -> x-
3 -> y-

deft kestrel
#

KEKW why I keep getting smiley faces, I do not know

#

I feel like I remember this thonk

#

block_1:                                          ; preds = %head
  br label %dir_out

block_2:                                          ; preds = %head
  br label %dir_out

block_3:                                          ; preds = %head
  br label %dir_out```~~I love llvm~~
#

like why even have those branches?

#

switch i32 %4, label %block_3 [
i32 0, label %dir_out
i32 1, label %block_1
i32 2, label %block_2
]

block_1: ; preds = %head
br label %dir_out

block_2: ; preds = %head
br label %dir_out

block_3: ; preds = %head
br label %dir_out

dir_out: ; preds = %head, %block_3, %block_2, %block_1
%var66.0 = phi i32 [ 0, %block_3 ], [ -1, %block_2 ], [ 0, %block_1 ], [ 1, %head ]
%var67.0 = phi i32 [ -1, %block_3 ], [ 0, %block_2 ], [ 1, %block_1 ], [ %4, %head ]

oh maybe I understand

#

why does it jump back and then go forward thonk

#

and also why does it skip a row thonk

lethal axle
#

That’s how snakes go 🐍

deft kestrel
#

oh because I'm using size2 and summing one

#

instead of size and sum 2

#

nvm

#

oh actually I prevented myself from compiling because the program was open KEKW

#

answer: my board was messed up

#

had my new lines being filled in at the wrong offsets

#

that's a lot easier to see what's wrong

deft kestrel
#

the TODO:

  • make tail not segfault game
  • apple
  • make snake grow
  • make game loop not wait on input but instead happen at an interval
deft kestrel
#

writing this takes SO MUCH MORE THOUGHT
than the TI84 calculator equivalent holy heck

#
            isLoss = function.compare(CompareOp.EQ,
                    function.compare(CompareOp.EQ, isLoss, CONST_1),
                    fTurn.get()
            );```me when I don't have boolean math
#

great, but there's a random tile that kills the player when the player goes over it

#

this single specific tile for no apparent reason

#

oh there's more than that

#

oh
my first turn logic also isn't working, given the fact that I never set it to not the first turn

#

ok boolean op time

deft kestrel
#

... and there's still random tiles that kill me :yipee:

#

I think it's just two specific ones even

#

forgetting to reset loop indices moment

deft kestrel
#

glad I can at least use RLX level 4 optimization 🤷

#

(RLX L4 is, a decent bit of optimization, not quite as aggressive as O3, but it's meant as an assistant optimizer sorta thing)

#

gets logic of abs perfectly implement first try, except it always returns a negative instead of a positive

lethal axle
#

so you wrote the programming language you used to make this game?

deft kestrel
#
        VarInstr i0 = function.makeVar(RlxTypes.INT);
        ValueInstr CONST_0 = new ConstInstr<>(0, RlxTypes.INT);
        ValueInstr diff = function.sub(right, left);
        RlxBlock blockL = function.makeBlock("block_l");
        RlxBlock blockR = function.makeBlock("block_r");
        RlxBlock blockD = function.makeBlock("block_d");
        ValueInstr cmp = function.compare(CompareOp.GE, diff, CONST_0);
        function.jumpIf(cmp, blockL, blockR);
        i0.set(diff);
        function.jump(blockD);
        function.buildBlock(blockL);
        i0.set(function.sub(CONST_0, diff));
        function.jump(blockD);
        return i0.get();```
deft kestrel
#

but yeah

lethal axle
#

pretty impressive

deft kestrel
#

still pretty close but it just deals with more stuff for me than llvm does by default

#

huh that's-
interesting
not sure what just happened there KEKW

#

smth smth recompiled program while closing ig, idk

deft kestrel
lethal axle
#

I bet

deft kestrel
#

buffer overflow attack performed!

#

180x180
my screen is not tall enough
it took many moves to get down here

#

I made 1 missinput, and said input was discarded because it was invalid

#

only thing remaining is abble

#

and also validating when the player moves out of bounds

#

:car: you cannot make a 102864x102864 board

#

715 is the limit

#

511225
yeah that makes sense ig

#

actually no it doesn't, what

#
514088```
that's just an arbitrary value that doesn't even seem to correlate to anything-
#

huh?????

#

whatever

deft kestrel
#

let's see what claude has to say about rng

#

... not sure if what it said is real KEKW

#

I'mma just make the call to capi

deft kestrel
#

according to claude, I am probably correct

#

declare dso_local i32 @rand() #1

frOK another nice&simple function

#

although C's random impl is a huge disappointment to me, so another one for the debug purposes pile

#

(I just don't like how I have to go out of my way to seed it compared to just using it normally, would rather have to go out of my way to use it in the first place so that seeding is the same amount of out of my way)

deft kestrel
#

(also I like control and I feel like I don't have that with C's impl KEKW)

#

oh what a joke

#

(may be my fault but it's always returning 5 for bounds 0->5)

#

ok it's just C's impl being shoddy

#

start of apple

#

I don't even want to image programming pong like this KEKW

#

that seems like a nightmare

#

snake's nice and simple

lethal axle
#

Yup

#

I started with a snake game

#

Pong has a little vector math in it, just some dot product for the bounce and multiplying a vector

#

Otherwise similar

deft kestrel
#

which is a significant amount when you're dealing with this low level of a syntax KEKW

lethal axle
#

Yeah I bet

deft kestrel
#

I mean it'd probably take less time tbf

#

but also like

lethal axle
#

Also have to normalize I forgot

deft kestrel
#

I may not be able to eat the apple, but I sure can eat the line breaks KEKW

deft kestrel
#

ignore that todo, I just hadn't gotten around to removing it

#

remaining ir features:

  • calls
  • ! operator
  • short circuit builder
    remaining backend features:
  • linkage
  • xor, nor
    remaining frontend features:
  • everything between ast and rlxir KEKW
#

somewhere in there a gc is needed

#

which...
I will probably have as just a required package sorta thing

#

Probably written in none other than ralux

#

And impls for any broken intrinsics I run into KEKW

deft kestrel
#

My favorite thing about the jvm
is that there is a solution within the jvm to absolutely every problem the jvm creates

awt is poorly optimized?
you can reimplement it yourself
but wait there’s a problem — java 9 modules get in the way
but there’s most assuredly a way to bypass the entirety of the jvm’s security nonsense to optimize it anyway KEKW

#

it’s fun doing these ridiculously over engineered things to get around jvm limitations

lapis turtle
lethal axle
#

Kotlin is a great language

#

super fun to build with

deft kestrel
#

Especially modern versions of the JVM

lapis turtle
deft kestrel
deft kestrel
#

Granted, I also have not looked at kotlin in a while
so maybe the compiler has changed

#

Unless you’re doing something oddly specific, the JVM is usually not the bottle neck/limiting factor

#

SIMD is the main thing that the JVM doesn’t support afaik

deft kestrel
#

Also
Dear LORD WHAT THE HECK IS SCALA’S BYTECODE OUTPUT bleakekw
working with a scala library drove me insane bleaker_kekw

#

How scuffed does your bytecode need to be to get an IDE to generate this bleaker_kekw

#

Whatever the heck scala is doing
The jvm was NOT the right choice bleaker_kekw

deft kestrel
#

probably would be cleaner if I wasn't using antlr but like
meh

#

I don’t really wanna handroll a parser

deft kestrel
#
    return ((left < right) * (right - left)) + left;

kinda tempted to setup the compiler to optimize stuff like this

#
  %zext_int1_to_int32 = zext i1 %si_cmp to i32
  %si_product = mul i32 %zext_int1_to_int32, %si_diff```ig basically just if detect cast bool->int followed by mul, convert to branch
deft kestrel
#

ok so I managed to eliminate all symbol not found problems except for __fixtfsi it seems

#

ig I'll just have to manually implement specifically that one

#
pkg comptest;

use ralux.debug.Debug;

public class IOViaDebug {
    public static int main() {
        Debug.write(5);
        long lng = Debug.readInt64();
        Debug.write(lng);

        return 0;
    }
}```but I can compile stuff like this class!
#

which, does not do much, but it's good progress

#

next comes writing a horrible garbage collector implementation in C++ frOK

#

(I can't really, do much in the way of the standard library without arrays, and I kinda need some kinda basic garbage collection for arrays just so this way I don't have to rewrite like half the compiler later on)

deft kestrel
#

So __fixtfsi is for float128 to int32
and it seems like none of the __fixtf** functions exist
So I guess those were just not implemented into any of the runtime libraries for some reason?

Haven’t run into any other broken intrinsics than those after linking to all of

  • msvcrt
  • ucrt
  • libcmt
  • compilerrt builtins
    at once
lapis turtle
#

You werent linking them at once????!!!??!!

deft kestrel
#

I was but I guess I must’ve been missing one

lapis turtle
deft kestrel
#

yeah

#

Guess I’ll just have to include intrinsics for tf->** conversions in my own lib

#

‘Cuz wides and quadruples are syntax features of ralux

lapis turtle
#

The only reason to link with the c std lib is for easy os calls, of course implementing your own std lib is extremely hard which is why a lot of compilers dont do it

deft kestrel
#

rlxrt is mostly gonna be like
gc and whatever broken intrinsics I encounter

deft kestrel
lapis turtle
deft kestrel
#

I’m honestly considering making my own linker ‘cuz like
this is a bit ridiculous KEKW

lapis turtle
#

Mold is fast

#

Lld is also plenty good

deft kestrel
#

I’m honestly not actually sure what version of lld I’m using

deft kestrel
lapis turtle
deft kestrel
#

oo mit too
Might actually use mold then

deft kestrel
#

lld-link: error: undefined symbol: __std_exception_destroy
though msvc strikes again!
linking against my own runtime library doesn't work because msvc seems to be using symbols that are not included in msvcrt

#

solution: cstdlib

#

incredible

#
                    "/libpath:\"C:/Program Files/LLVM-13.0.1/lib/clang/13.0.1/lib/windows\" " +
                    "/defaultlib:msvcrt " +
                    "/defaultlib:libcmt " +
                    "/defaultlib:ucrt " +
                    "/defaultlib:cstdlib " +
                    "/defaultlib:kernel32 " +```what it takes to compile a program in windows
deft kestrel
deft kestrel
#

oh nvm cstdlib doesn't exist

#

so apparently
my library is using vcruntime
which causes lld to also generate a lib file in addition to the exe

#

... what the heck

deft kestrel
#

oh halves don't even exist in C/C++, incredible

#

okay probably going to have to write my intrinsics in something even lower level then

deft kestrel
#
declare void* @tfc_ralux_runtime_GC_allocate(void* %0, i32 %1)
declare void* @tfc_ralux_runtime_GC_collect(void* %0, i32 %1)
declare void @__rlxrt_init()
declare void* @__rlxrt_get_global_gc()
declare void @__rlxrt_obj_created(void* %0)
declare void @__rlxrt_free_obj(void* %0)```

ok so order of operations:
hook up gc->implement object orientation->test gc->instance functions->fields->compiler hints->standard library->remaining syntax features

deft kestrel
#

after writing some of the world's most cursed C++ code...

#

and it segfaulted after printing that 0

#
    int hc = o.#;

was supposed to get the hash code so I think I know why it segfaulted

#

my gep is wrong

#
            puts("allocate obj");
            puts(std::to_string(size).c_str());
            puts(std::to_string(sizeof(rlxObj)).c_str());
            void* data = tfc_ralux_runtime_GC_allocate(gc, size + sizeof(rlxObj));
            void** obj = static_cast<void**>(calloc(1, sizeof(void*)));
            obj[0] = data;
            
            puts("buf_alloc'd");
            ((RlxObj) obj)->tfc_ralux_runtime_Object_hashCode = __rlxrt_default_hash;
            puts("hash_code_set");
            __rlxrt_obj_created((RlxObj) obj, gc);
            puts("obj_marked");
            return obj;```^ to define "some of the world's most cursed C++ code"
#

so an object is actually a void** in C++
interesting, I can abuse that

#

explains why geps go two steps instead of one too

deft kestrel
#
  %call7 = call i8* @tfc_ralux_runtime_GC_allocate(%"struct.ralux::rlxGC"* poison, i32 noundef %add)
  %call8 = call noalias dereferenceable_or_null(8) i8* @calloc(i64 noundef 1, i64 noundef 8)
  %2 = bitcast i8* %call8 to i8**
  store i8* %call7, i8** %2, align 8
  %call9 = call i32 @puts(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @"??_C@_0M@JPCHMAAE@buf_alloc?8d?$AA@", i64 0, i64 0))
  %3 = bitcast i8* %call8 to i8***
  %4 = load i8**, i8*** %3, align 8
  %arrayidx11 = getelementptr inbounds i8*, i8** %4, i64 2
  store i8* bitcast (i32 (%"struct.ralux::rlxObj"*)* @__rlxrt_default_hash to i8*), i8** %arrayidx11, align 8```lovely (I have no idea what the heck I'm looking at but I need to figure it out so I can reproduce it over in the ralux compiler)
deft kestrel
#

still. I can abuse it

#

I can store ref counting and gc related data in the first pointer instead of having that be part of the object
which is the sorta thing C++ would do (it seems)

#

or smth idk I still need to figure out why my code segfaults the compiler

deft kestrel
#
            ((int (*)(void**)) ((void**) ptr[0])[2])(ptr);
```ok so this is the C++ equivalent of what I want
#
  %0 = load %"struct.ralux::rlxGC"*, %"struct.ralux::rlxGC"** @"?tfc_ralux_runtime_GC_GLOBAL_GC@ralux@@3PEAUrlxGC@1@EA", align 8, !dbg !4198, !tbaa !3907
  %call = tail call i8** @tfc_ralux_runtime_GC_allocateObj(%"struct.ralux::rlxGC"* noundef %0, i32 noundef 0), !dbg !4198
  call void @llvm.dbg.value(metadata i8** %call, metadata !4197, metadata !DIExpression()), !dbg !4199
  %1 = bitcast i8** %call to i8***, !dbg !4200
  %2 = load i8**, i8*** %1, align 8, !dbg !4200, !tbaa !3907
  %arrayidx1 = getelementptr inbounds i8*, i8** %2, i64 2, !dbg !4200
  %3 = bitcast i8** %arrayidx1 to i32 (i8**)**, !dbg !4200
  %4 = load i32 (i8**)*, i32 (i8**)** %3, align 8, !dbg !4200, !tbaa !3907
  %call2 = tail call noundef i32 %4(i8** noundef %call) #18, !dbg !4200
  ret void, !dbg !4201```which compiles to this
#

which is subpar but currently I just want stuff to work

deft kestrel
#

Or maybe it’s not subpar
Hard to tell

#
%1 = cast void** to i8***
%2 = load i8** from %1
%3 = gep i8* from %2 at 2
%4 = cast %3 to fnct
%5 = call %4
deft kestrel
deft kestrel
#

So
I think plan is
[[fields&method refs], rlxClass*, rlxGCInfo*, interfaceExtensions*…]
super calls just call a static function which is the super method (as per standard language logic)

#

When casting to an interface, lookup in the class instance what said interface’s offset is
When casting back to the object, interface extension instance stores its own offset so just subtract that from the pointer

#

This also seems to be, to an extent, how C++ handles stuff, but not entirely

#

C++ implements super classes as a field, which definitely makes sense for a library but for an exported program it’s unnecessary

But I’ll probably want an interop mode I guess because my way seems, probably better for performance while C++’s seems better for native libraries

#

Though I should probably also look into dlls a bit more before deciding on how I wanna deal with libraries tbh

deft kestrel
#

holy cow

#

it did it

#

how about O3-5

#

yep

deft kestrel
#

so apparently having my ide open and set for working on ralux makes my ide use up 40% of my RAM
I only have 20% RAM free at any given moment without my IDE open
working on ralux brings my laptop use 120% RAM

deft kestrel
#

I can tell it worked because the program closes essentially instantly after starting frOK

deft kestrel
#

I think the first thing I’ll try to make with ralux is a graphing calculator

deft kestrel
#

So after attempting to use a loop
C++ has decided it wants to be so extremely riddled with undefined behavior that it’s somehow calling ref from ref from rt init
only function rt init calls is init gc, which doesn’t even call ref
… so I’m not sure how it’s getting to ref
wbhuh I have no idea what’s going on

#

At least whatever’s happening happens both with and without gdb unlike what I had before where it would randomly segfault but ONLY if I don’t attach gdb

#

probably gonna have to rewrite the gc entirely because what the heck

#

none of this makes sense wbhuh

deft kestrel
#

ok so apparently libucrt causes everything to have a stroke I guess

deft kestrel
#

oh hey
it's exactly the thing I don't like about C++
things seem to just get freed for no apparent reason sometimes

#

C++ stack memory my enemy

deft kestrel
#

or smth
idk

#

I’ve tried making the code more cursed, I’ve tried making it less cursed, nothing seems to change the behavior
closest I got to a behavior change was making the program not load at all

#

every time I deal with C++ I seem to end up with stuff just arbitrarily being freed

lapis turtle
#

Things destructors are called when they go out of scope

deft kestrel
lapis turtle
#

Making the things not go out of scope

#

And stack variables are invalidated when out of scope as well

deft kestrel
#

… is malloc not off stack?

lapis turtle
#

Yes

#

Raii deals with classes though

#

It deals with your constructor and desctructor

deft kestrel
#

What is raii

deft kestrel
#

new keyword?

lapis turtle
deft kestrel
#

I don’t know where I even have a stack object other than my unordered sets

lapis turtle
#

RAII doesn't deal with stack

#

stack variables are invalidated purely because of how the CPU works, RAII is a memory management concept introduced by c++

lapis turtle
#

cppref has a good thing on RAII

deft kestrel
#

I don’t
use constructors or destructors

lapis turtle
deft kestrel
#

other than with the new keyword

lapis turtle
#

the new keyword is a malloc

#

on destruction your memory will be freed

#

by default

deft kestrel
#

Ok but why th is it being destroyed then

lapis turtle
#

it goes out of scope

lapis turtle
#

the default destructor is called, deallocating your memory

deft kestrel
#

ok but it was allocated using new, not using the default initialization

#

RlxObj is a pointer type to rlxObj

lapis turtle
#

might be worth to talk to someone who is more of a cpp person, they'd prolly explain this better

deft kestrel
#

ok then how do I prevent it from being deleted when going out of scope because it’s only going into a field and not meaningful in scope

deft kestrel
#

That would be the thing that I don’t want it to be in the scope of because this is so that that doesn’t have to deal with it

#

… so I guess you’re getting at me needing to make my own allocator in that case?

lapis turtle
#

nope

#

this is a language feature

deft kestrel
#

one which I really wish didn’t exist

lapis turtle
#

stack allocation is always preferred

#

the new keyword in c++ is extremely different than in java

deft kestrel
#

… does malloc do this raii behavior or no

lapis turtle
#

every class has raii

#

new in c++ allocates memory using the constructor whereas in java the new keyword is just calling the constructor

deft kestrel
#

ok so malloc will avoid this?

lapis turtle
#

if you have a pointer to a class it will free it at the end of scope

deft kestrel
#

oh
so it needs to remain as a void** the entire time

lapis turtle
#
{
classtypething *thing = new classtypething; // allocated here
} // freed here
lapis turtle
lapis turtle
#

just will free for you

#

this is likely a project structure issue

#

either that or its not that things are being freed and you have heap corruption

deft kestrel
#

incredible

lapis turtle
#

maybe dont try to make a program where everything is local scope :p

deft kestrel
#

I’m trying to make everything not local scope

#

is my goal

lapis turtle
#

thats also a bad practice

#

a bunch of global mutable state is a shitshow

deft kestrel
#

… not what I meant

#

I’m trying to recreate how java object orientation works

#

but C++ aggressively wants to delete everything that is allocated in a scope
which is, distinctly the dead opposite of what I want

#

given the fact that I have a library which has the sole purpose of managing allocations and garbage collection

lapis turtle
#

c++ oop is different for a reason, c++ is not like java, java is not like c++

deft kestrel
#

which is, also not what I want to do

lapis turtle
#

then dont try to use c++ like java

#

they're completely different

deft kestrel
#

I’m not even trying to use C++ really
I’m trying to just get a thing going to act as a garbage collector because doing in llvm ir would be painful

#

I would do this in C if C had unordered_set, but unfortunately it does not
But maybe I need to

lapis turtle
deft kestrel
#

yeah I’m not really interested in fully learning C++ just to then move off of C++ after my language is more developed or something
this is most likely going to be a temporary throwaway codebase for testing stuff

lapis turtle
#

you also dont have to use c++ either, c doesn't have RAII

deft kestrel
#

C lacks unordered set

lapis turtle
#

make your own hashmap then

#

or use a premade one

deft kestrel
#

I don’t know how hashmaps work behind the scenes

lapis turtle
#

you dont have to with a premade one

#

but also you definitely should

#

learn it

#

its an extremely useful pattern

deft kestrel
#

Particularly I don’t understand what the heck to do if the bucket count needs to change or does it ever change or what

lapis turtle
#

realloc

#

anyways

#

like I've stated im not the best person to console about c++ issues, as I myself, am not a c++ programmer

deft kestrel
deft kestrel
lapis turtle
#

your issue is either heap corruption or incorrect raii

deft kestrel
lapis turtle
#

Join the cult

deft kestrel
# lapis turtle No?

… how?
bucket index (based on my last time googling how hash maps work) is hashCode%bucketCount, which if bucket count increases by 1, a hashcode that might’ve modulated to 1 might now be 2 or smth?

lapis turtle
deft kestrel
deft kestrel
#

froge_sad it happens in C too it seems

#

ok but maybe I know why

#

wait no I don't

#

er

#

no

lapis turtle
deft kestrel
#

also yeah I am infact having a logical error

#
            void* data = tfc_ralux_runtime_GC_allocate(gc, size + sizeof(rlxObj));
            void** obj = static_cast<void**>(calloc(1, sizeof(void*))); // this is the cause of my problems
            obj[0] = data;```
#

annoying that it ever works instead of just always failing

#

I'm sticking with C though

#
            void* obj = tfc_ralux_runtime_GC_allocate(gc, size + sizeof(rlxObj));
```should've been this
deft kestrel
#

I'm going to use a linked array set for now
because it's the simplest type of set to implement
and I'll rewrite it to a hash set later

#

er

#

no I'll go with regular arr-
oh I could d-
eh-
yeah binary tree map based on memory address seems good enough for now

#

eh no I'll just go linked list

#

✨ indecision ✨

deft kestrel
#

array set

deft kestrel
#

ok so stuff is working, but running the gc breaks the gc KEKW
like it works, until the gc runs a second time

#

reason: the objects that are freed don't get removed from being roots... I think

#

which is my fault; I never implemented that
but i think I need to test my array set's remove method outside of ralux so that I don't have an absolute mess every time I try to test it

#

well not removed from being roots; it's already not a root elsewise it wouldn't be freed
removed from being tracked by the gc

deft kestrel
#
pkg comptest;

use ralux.debug.Debug;
use tfc.ralux.runtime.GC;

public class ObjectOrientation {
    public static int main() {
        for (int i = 0; i < 32000; i++) {
            ObjectOrientation o0 = new ObjectOrientation();
            ObjectOrientation o1 = new ObjectOrientation();
            int hc = o0.#;
            Debug.write(hc);
            Debug.write(i);
            o0 = null;
            o1 = null;
        }
        GC gc = GC.getGlobalGC();
        GC.collect(gc);
        Debug.write(100);
        return 0;
    }
}
```![frOK](https://cdn.discordapp.com/emojis/1096202041069686784.webp?size=128 "frOK") array set works properly
#

yeah onto the next problem now frOK

#

nice, roots work too

deft kestrel
#

8KB binary, RlxRt.lib is 18KB
not entirely sure how that works but frOK

#

(rlxrt can be shrunken down to 7kb dependent upon llvm switches)

#
3200000
1652646
1547354```
program runs pretty fast too
halfway through 3200000 iterations
#

28????? at this point

#

not timing this obviously but like
yeah that's a decent speed

#

just finished

deft kestrel
#

I'd imagine it'd be faster if I had a heap and also used a hash set

deft kestrel
#

the array set was infact atrociously slow, so I implemented a binary search based array set
this will stay for now 🤷
will need to be redone later though

deft kestrel
#

okay so it looks like I'm not freeing everything

#

wait that's probably the array sets, lol

#

yeah looks to be a reasonable size for being the array sets I'm using to track objects

deft kestrel
#

shoot I need to update my parser to support fields

deft kestrel
#

I think fields are the last thing before ralux is usable

#

Eh I need to do arrays at some point too

deft kestrel
#

I can now get values from fields
only problem
I can't set values in fields

#

should be simple enough to implement though 🤷

deft kestrel
#

5368713536
10
20
10
30
5368713536
22
10
track root
obj addr: 5836320
Marking object
489324
Marking object
track indrect root
obj addr: 5836416
Marking object
489324
Marking object
An obj was freed
An obj was freed
reference tracking works

deft kestrel
#

made my binary search array set impl be a single header library so that LLVM could go completely insane with inlining
the IR is now completely incomprehensible