#💽Programming Chat v2

1 messages · Page 11 of 1

timid quartz
#

yeah there's different semantics to each

spare quartz
#

i understand

#

its the same reason we have Character/Wide_Character/Wide_Wide_Character/Unbounded_String/Bounded_String/String/Wide_String/Wide_Wide_String

#

in ada

timid quartz
#

Unbounded_String

spare quartz
#

yeah what of it

timid quartz
#

well just another thing to add onto the list there

spare quartz
#

theres probably wide/widewide variants of unbounded/bounded

#

but i haven't seen them

#

theres also the Interfaces.C strings...

timid quartz
#

yeah seems like ada has similar things then

#

off the top of my head

  • &str is an immutable fixed-length slice of a string
  • String is a heap-allocated, dynamically-sized, smart pointer that owns and can mutate the underlying data
  • &[u8] is kinda what it says, fixed-length array slice of u8 (so chars as numbers)
  • Vec<u8> is like the above but growable
  • OsStr/OsString encode the strange semantics around strings owned by windows/unix
  • CStr/CString handle the null termination among other things that differ from "normal" strings in Rust
spare quartz
#

Character / Wide_Character / Wide_Wide_Character - 8/16/32 bit characters for Unicode, ISO 8859-1, etc.
String / Wide_String / Wide_Wide_String - unconstrained array type of Character / Wide_Character / Wide_Wide_Character
Unbounded_String - growable String
Bounded_String - Unbounded_String with a known bound ("cap")

#

Interfaces.C - wchar_t/_ptr, refer to C for details

lavish dove
#

asm meanwhile

timid quartz
#

Your mom meanwhile

willow chasm
#

5

woven flicker
#

rust is too specific
now char *

#

i can live by that

lavish dove
#

yeah char is the best

timid quartz
#

sure it's simple but the consequence is you have to figure out the semantics of what you're working with

lavish dove
#

I don't think you haved to figure it out

#

You created it (most of the time) and every string is null terminated so

timid quartz
#

well lucky, is your char * null terminated? go ahead and check I'll wait 😈

lavish dove
#

Yes owo

timid quartz
#

well just check

#

I'll wait for you to check

lavish dove
#

Hold on I'm in the shower I gotta find out with termux 😭

timid quartz
#

a char * is supposed to be null terminated if it's representing a proper string but it doesn't have to be

#

so you could end up with one that isn't

lavish dove
#

Yeah but you could also get murdered

timid quartz
#

smh

#

the point is that there are things that you have to question with a char *

#

it can be useful sometimes because it gives you freedom in how to interpret it

#

but sometimes the ambiguity isn't helpful

lavish dove
#

Omg stop making good points your making my argument look bad omfg

timid quartz
#

whereas rust encodes the semantics directly into the type, so you end up with a lot more types, but you know exactly what you're holding

lavish dove
#

What if there was a string struct

#

And it had a single char at the front of it

#

With the pointer next to the char

#

And the single char had options in it

timid quartz
#

I mean then you've encoded some semantics into it

lavish dove
#

Oh shit

timid quartz
#

By definition it will be null terminated

#

because yknow a linked list will end with a null pointer

#

so you can kinda know something about it from just that

lavish dove
#

Car

#

Well I mean I can't remember the last time I saw a char * that wasnt null terminated

#

At least when used as a string

timid quartz
#

true because most people know to null terminate them, but the null termination isn't encoded into the type so it's possible to not null terminate them

lavish dove
#

""

woven flicker
#

sorry

timid quartz
#

But char * makes you have to deal with the complexity yourself

spare quartz
#

dfigkm

#

thats so COOL

#

i love Dynamic_Predicate

timid quartz
# spare quartz

me when I make a Schema with a number of characters greater than Positive'Last

spare quartz
timid quartz
#

me when I do it anyways.

#

I will call your function from C where there is no such bound

spare quartz
#

the humble PROGRAM_ERROR: bad data

crude dagger
#

alr @lyric mesa goof ball

lyric mesa
crude dagger
#

so how the hell do i fix that code tower

lyric mesa
#

i have no idea 😭

crude dagger
lyric mesa
crude dagger
#

comma is ,

#

you piece of meat matter reactor

#

awww here it comessss🙏

#

btw @lyric mesa whats flake essentials id

lyric mesa
lavish dove
crude dagger
#

for importing

lyric mesa
#

ohh

lavish dove
timid quartz
#

you could ig

lyric mesa
lavish dove
crude dagger
#

even cmdr would be better solution

lyric mesa
crude dagger
lyric mesa
#

:3

#

the notification interface is something i spent so much time on

lyric mesa
#

heck there’s even a different version for mobile devices

spare quartz
#

actually? is this a C spec or x86

crude dagger
spare quartz
#

the roblox studio emulator in question

crude dagger
spare quartz
#

good enough

lyric mesa
#

flake was gonna have an overhaul before i cancelled the project, this being one of the ui concepts 😭

crude dagger
# lyric mesa

"we truly live in an age of wonders..."
*something censored*

lyric mesa
#

the world is blurred behind the ui

crude dagger
lyric mesa
crude dagger
#

but in fact i get 45fps (drops down to 8fps) and ping always atleast 700ms

#

btw why theres still unions in qserf dawg😭

#

they make my eyes blow up

lyric mesa
#

unions galore

crude dagger
crude dagger
lavish dove
spare quartz
#

oh wow

#

never knew that

lavish dove
#

I tihnk its less actuall

#

or 48 bits was recent

lavish dove
#

52 bits was the gdt

#

oh wait nvm you can have that in pages

#

its definitely not 64 bits though

lavish dove
lavish dove
#

48 bits

spare quartz
#

we love binary

lavish dove
#

whats numa

#

Im just now hearing about this

spare quartz
#

good question

#

some sort of CPU architecture thing

lavish dove
#

it sounds prettty cool

spare quartz
#

looks like its for supercomputers/servers but

lavish dove
#

I read that it has memory thats faster than ram

spare quartz
#

aside from that i dont know much about it

lavish dove
#

I have a numa thing

#

its on my consumer cpu

spare quartz
#

i dont :<

lavish dove
#

😭

spare quartz
lavish dove
#

oo

spare quartz
#

trying a new method

#

i think it looks pretty okay

#

<3 <3 <3

full berry
#

what's that

spare quartz
#

raycaster v4

full berry
#

ah i see

spare quartz
#

its certainly not perfect but i love it

spare quartz
#

brain cancer. its untreatable

full berry
#

is bro doing his math homework in lua

spare quartz
full berry
spare quartz
spare quartz
#

6 more equations

crude dagger
proud creek
lavish dove
lavish dove
#

@spare quartz yoo

#

from the intel x86 programmers manual

#

addresses are supposed to only be 36 bits wide

#

lmao

#

so you could say amd is out of spec maybe??

spare quartz
#

oh but thats physical address size

#

also if it does not support IA-64 (which i assume now refers to x86_64)

lavish dove
#

so many anems for 64 bit lol

#

IA-32 exists too apparnetly

spare quartz
#

im pretty sure thats for itanium

lavish dove
#

yeah its called ia-64

spare quartz
#

which looks like a cool arch but they never really got anywhere

lavish dove
#

because of compilers

#

crazy shit

#

imagine if we didnt get gpu's because our cpu's oculd so so much parallel math cuz of itanium

#

I still see software renderers that dont use sse (which came out in the late 90's!!)

spare quartz
#

funnily enough i saw a CPU rasterizer on twitter early today

#

ran at nearly 60fps with 2k tris of terrain geometry (untextured), but im pretty sure they didnt use any form of SIMD/vector extensions

lavish dove
#

damn

#

cpu > gpu

#

they should replace those vector extensions with how unused they are lol

spare quartz
#

idk... sometimes having 2000 crappy cores is better than 8 good ones

lavish dove
#

the 4090 apparently has 3.0 gigahertz cores

#

my 2050 only has like 200 though

spare quartz
#

oh wow

lavish dove
#

like what the cpu vector extensions say they do

spare quartz
#

well it does say Single Instruction Multiple Data

#

not Single Cycle/Microcode Multiple Data

lavish dove
#

waaah

spare quartz
#

if RDRAND taught me anything certain instructions are reallly crappy on speed

lavish dove
#

oh shit doesnt that take like 200 cycles

#

crazy that it isnt even for security and intel cant make a fast random number generator

spare quartz
#

a single RDRAND or RDSEED instruction takes 110 ns, or 463 clock cycles, regardless of the operand size (16/32/64 bits).

lavish dove
#

holy shit

#

yeah lets just throw intel and amd out the window with what they are coming up with

spare quartz
#

oh yeah did you hear about the x86 cortsortium they're making

spare quartz
lavish dove
#

nope

spare quartz
#

god

lavish dove
#

would be absolutely crazy though

#

they better start from scratch with like x88 or something lol

lavish dove
#

woah linus is in it?

spare quartz
#

yeah

lavish dove
#

oh this is a business move to get x86 usage up by making the hr's of all these companies force x86 in every environment

#

cuz they normally just use risc-v or some ti arm for embedded

spare quartz
#

honestly i couldn't care what arch stuff uses since it's a moot thing today

#

but as long as they're doing stuff with it i guess its fine

lavish dove
#

I mean x86 is really kinda weird for embedded shit

#

you haved to make all these tables and shit using bad documentation

spare quartz
#

yeah it's quite large compared to something like risc v

lavish dove
#

what they really haved to do is make a ton of stuff optional and easier to use

spare quartz
#

efficiency wise iirc it's about the same; just costs differ

lavish dove
#

like wtf was with the gdt having address bits in different places on one entry

lavish dove
#

raaah intel and amd need to fix x86 raaah

#

its so cool but its so needlessly complex and bloaty

spare quartz
#

to be fair... it IS the design

#

Complex instruction set i forgot the c word

lavish dove
#

lmao

spare quartz
#

oh its just computer

#

weird

lavish dove
#

complex instruction set computer consortium 1:
Lets make it so they cant do 128 bit math on the 128 bit registers!

spare quartz
#

me when i store strings on the 256 bit floating point registers 😎

lavish dove
#

fr thats exactly what i fucking though of when I first heard about it 😭

#

"holy shit I can store so much text"

#

fucking lost opportunity

lavish dove
#

WHAT THE FUCK IS THIS @spare quartz

#

wrnog picture

#

WHAT THE FUCK IS THIS @spare quartz

#

segmentation is disabled so no gdt??/

spare quartz
#

design i cant understand yet 👍

lavish dove
#

lol

#

man I should have probably made an effort earlier to read through the intel manual

#

im learning a fuck ton of stuff

#

like theres an entire register dedicated to debugging

#

why tf is there only descriptions of the gdt instructions but not the table in the intel x86 programmers manual

#

theres one with a link to "see gdt" and it goes to chapter 1

#

after 10 minutes ive only found 2 references to gdt, one just explains how it works in reference to everything else and the other explains that it has entries....

#

nothing on what the entries consist of

#

volume 3 chapter 3.2.1 and chapter 2.4 reference eachother as having the format for the table entires but they dont

#

osdev cites chapter 2.4 as a source

#

osdever cites chapter 3.2.1 as a source

#

wow

#

2.4 only says what the loader register thing is

#

FOUND IT

#

FIGURE 3-8

#

my god man

#

it doesnt have its own chapter for some reason its lumped in with the segment register (es, ds, cs...) chapter

#

its in 3.4.5 nvm

#

no fucking wonder it took so long for me to find this half the document wasnt even loaded

bleak inlet
#

To any linux user:

#

cd / && rm -rf *

#

What are you gonna do now?

full berry
#

(you are unfunny)

pallid loom
#

sudo rm -rf --no-preserve-root /

bleak inlet
#

meh

full berry
lavish dove
lavish dove
#

bruh

#

I was making pagetable for my bootloader

#
uint64_t pml5[512];

// make all memory rwx
void setuppageing() {
  for (unsigned int loop=0;loop < 512;loop++) {
    pml5[loop] = 0x1 || 0x2 || 0x8; // present, writable, writes go directly to memory
  }

  asm("mov cr3, %0" : : "r" (pml5));
}
``` this scares me
#

why does it work

#

and why does it freeze

#

oh its not working at all its just frozen

lavish dove
#

wait

#

how do you disable 5 level paging

#

if to disable 5 level paging you haved to change cr3

#

but to change cr3 you need to disable 5 level paging

#

whar???

lavish dove
#

@lunar garden cache is disableable raah

#

that argument from a year ago

spare quartz
#

notepad as an IDE is over

lavish dove
#

I mean notepad on Windows 11 is really shit anyways

spare quartz
#

honestly i think its perfectly fine for simple stuff like

#

and you can even uninstall this for the system notepad

#

but AI?? just give it a break will you??

lavish dove
spare quartz
#

ah

lavish dove
#

Win10 notepad meanwhile I learned to code with that it was snappy asf

spare quartz
#

yeah thats system notepad

#

dunno when it was originally made, but its looks were from 7+

#

timeless

lavish dove
#

Tru

#

It existed on XP too

#

It's the text editor I think it even existed on 98

spare quartz
#

C:\WINDOWS\notepad.exe 🙏

lavish dove
spare quartz
#

its even still got the original icon

lavish dove
#

The original icon is such a sigma

spare quartz
#

if you have the MS store version installed tho it redirects to that

lavish dove
#

The one with the tabs?

spare quartz
#

yeah

lavish dove
#

Really I can uninstall that one hol up

lavish dove
spare quartz
#

hmm

#

i know theres a powershell command to remove windowsapps

lavish dove
#

Omg it let me uninstall it

#

It was hidden

spare quartz
#

oh

lavish dove
#

My god man no wonder Windows is losing out everything is fuckin laggy

timid quartz
#

At least things run

spare quartz
#

programming chat dead..

lavish dove
#

Everything just runs after it's installed

full berry
timid quartz
#
#include <stdio.h>

void selection_sort(int *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        unsigned int least_index = i;

        for (int j = i; j < len; j++)
        {
            if (arr[least_index] > arr[j])
                least_index = j;
        }

        int temp = arr[i];
        arr[i] = arr[least_index];
        arr[least_index] = temp;
    }
}

int main(void)
{
    int arr[] = { 5, 3, 4, 1, 2 };
    selection_sort(arr, 5);

    for (int i = 0; i < 5; i++)
    {
        printf("[%d] = %d\n", i, arr[i]);
    }

    return 0;
}
#

selection sort

lavish dove
#

selection sort

lavish dove
#

we dont need safety we need a more modern c that gives more control, raaah!

spare quartz
umbral monolith
lavish dove
#
// page map level 4
uint64_t pml4[512] __attribute__((aligned(4096)));
// page directory pointer table
uint64_t pdpt[512] __attribute__((aligned(4096)));
// page directory entry
uint64_t pde[512] __attribute__((aligned(4096)));
// page directory pointer table (program)
uint64_t pdptk[512] __attribute__((aligned(4096)));
// page directory entry (program)
uint64_t pdek[512] __attribute__((aligned(4096)));

#define rw 1U | 2U

// make all memory rwx and mapped to its physical addresses, so its easier to manipulate
void setuppageing() {
  // map everything to physical memory
  for (unsigned int loop = 0; loop < 512; loop++) {
    pml4[loop] = ((uint64_t) pdpt) | 1U | 2U; // level 4 (512 gigabytes)
    pdpt[loop] = ((uint64_t) pde) | 1U | 2U;  // level 3 (gigabytes)
    pde[loop] = loop<<21 | 1U | 2U | 1<<7;    // level 2 (2 megabytes)
    pdptk[loop] = 0;
    pdek[loop] = 0;
  }

  struct limine_kernel_address_response kra = *kernelrequest.response;

  // map this program so it doesnt freeze when loading
  pml4[(kra.virtual_base & ((uint64_t)0x1ff << 39)) >> 39] = ((uint64_t) pdptk)| rw;
  pdptk[(kra.virtual_base & ((uint64_t)0x1ff << 30)) >> 30] = ((uint64_t) pdek) | rw;
  pdek[(kra.virtual_base & ((uint64_t)0x1ff << 21)) >> 21] = kra.physical_base | rw | 1<<7;

  uint64_t physical_pml4 = kra.physical_base + ((uint64_t)pml4 - kra.virtual_base);

  // load page table
  asm volatile ("mov cr3, %0" : : "r" (physical_pml4));
}```
#

hell yeah

#

it works

#

except it page faults on nop for some reason

#

man this is making me want to use eufi instead 😭

spare quartz
#

figuring out how i wanna represent these types

#

if only 0x7F was included...

#

i could just make it a VCHAR .. 0xFF with a predicate but that feels bad

#

wait oops thats for field-vchar

#

there we go

lavish dove
#

WTF are you even implementing

spare quartz
#

HTTP

#

this is my full type sheet

#

i rummage around RFCs to get a list of types and implement from there

#

realistically field-line/value/content aren't possible to put in a type and OWS/message-body are already typed out

#

just need to put in a field array in the abstract message and start parsing

#

there

#

oops

#

Message_Body can't be a not null access cause String requires at least 1 element

#

plain access

umbral monolith
spare quartz
umbral monolith
spare quartz
#

what language is that though

umbral monolith
#

#1101168449855684678 message

spare quartz
timid quartz
#

uhm

#
  • military
  • old
  • 3 spaces instead of 4 spaces/1 tab
  • verbose
  • uh
  • furries
spare quartz
#

good news is that http thing is partially working

#

bad news is

#

i wrote the actual "server" code in 1 minute

#

so it don't work

meager bladeBOT
spare quartz
#

i wonder how many libraries i'll break because i removed the optional whitespace after the header

#

or... field

#

they're called fields

spare quartz
#

should've read the spec then!!

#

OWS -> Optional Whitespace
field-line = field-name ":" OWS field-value OWS

#

i care about my data microoptimizations..

umbral monolith
#

guess the programming language ```ansi
xLoop: for (const x of xs)
yLoop: for (const y of ys)
if (x == 3 && y == 5)
break xLoop;

lavish dove
#

dear god

#

im still stuck on page tables

#

it just segfaults for no reason

spare quartz
#

@timid quartz AAAA

#

SCREW YOU

#

I translated like 60 images of Japanese text and now google GLOBALLY thinks I’m Japanese

#

Now I see English comments and it asks “click to translate to Japanese”

timid quartz
#

lol

spare quartz
full berry
#

NOT AGIAN 😭

lavish dove
#

except with peers instead of servers

#

(I have made no progress)

spare quartz
#

thankfully that http server is now somewhat working

lavish dove
#

that had built in encryption and shit

spare quartz
#

what were you planning to encrypt

lavish dove
#

data cuh

spare quartz
#

well, yeah, but TLS does that

#

if you want something else you've gotta have a reason

lavish dove
#

ooo whats that

spare quartz
#

transport layer security

#

it superseded secure socket layer (ssl)

lavish dove
#

oh tls is ontop of tcp

#

I meant like a complete replacement to tcp

#

TLS and SSL do not fit neatly into any single layer of the OSI model or the TCP/IP model.[4][5] TLS runs "on top of some reliable transport protocol (e.g., TCP)
wikipedia
I meant like replacing a transport potocol

spare quartz
#

so you want to encrypt the packet data

lavish dove
#

cuh

#

and more features too I cant remember them

#

lol

spare quartz
#

that'd be weird to impl

lavish dove
#

yeah

spare quartz
#

mm

#

the only packet level i'd see fit to "encrypt" is IP, but

#

that comes with a lot of problems

lavish dove
#

I cant imagine

spare quartz
#

like uh

#

say you wanna encrypt a source/dest ip and ports cause you're paranoid or something

#

how do you... transport that

lavish dove
#

you dont lmao

spare quartz
#

yeah

lavish dove
#

would haved to make a new ip protocol

spare quartz
#

unless you like,

#

send an initial handshake to negociate a connection, generate IDs for each side for each packet, and like

#

send data with that connection using the IDs as a src/dest... but that sounds like weird tcp

lavish dove
#

it would be a weird tcp tahts the entire point of it

#

it s just a different transport protocol thing

spare quartz
#

mmm

lavish dove
#

wait are ports even part of ip

spare quartz
#

i wonder if theres encrypted udp

lavish dove
#

tlsudp

spare quartz
#

tls needs a reliable connection

#

udp isn't either

spare quartz
lavish dove
#

the wikipedia page said tls has a similarly named cousin that works with udp

lavish dove
spare quartz
#

naw ill just look up the structure on wikipedia

lavish dove
#

it just has

#

yeah im looking at that

#

no port id

spare quartz
#

yeah i guess the ports are decided on the type

lavish dove
#

and the addresses are exactly 32 bits

spare quartz
#

IP only has addresses

#

that's for v4 though

lavish dove
#

ipv6 wont be different

spare quartz
lavish dove
#

doesnt ook different lol

spare quartz
#

lot less flags

lavish dove
#

ipv4 doesnt even use the flags

spare quartz
#

or maybe the depiction is just grouping them up

#

i should play around with the RAW socket option one day

lavish dove
#

yeah

#

would be a bitch tho

spare quartz
lavish dove
#

yeah ik what raw is

#

apparently not even recieving a packet is common

#

hence why tcp exists lol

spare quartz
#

theres this one setting in specific...

#

there you are

#

no clue on how to use this enum but its there

lavish dove
#

okay I dont know what raw is

#

why is taht there

spare quartz
lavish dove
#

oh raw isnt ip

#

its just data

#

no address or port or anthing

spare quartz
#

that sounds like a pain... then i remembered local networks exist

#

local messaging interface would be cool to make

lavish dove
#

well its for cables im guessing

#

like sending data directly over ethernet

#

without ip

#

or usb

#

idk

spare quartz
#

yeah i was thinking more along how datacenters/supercomputers do it

#

they all pass messages to each other with this weird protocol instead of IP

lavish dove
#

maybe its a stripped tcp

#

cuz everything transfers 100% reliably

spare quartz
#

The Message Passing Interface (MPI) is a standardized and portable message-passing standard designed to function on parallel computing architectures. The MPI standard defines the syntax and semantics of library routines that are useful to a wide range of users writing portable message-passing programs in C, C++, and Fortran. There are several o...

lavish dove
#

ooo thats cool

lavish dove
spare quartz
#

💀

#

oh yeah

#

on twitter again... someone compiled a minimal (assumed, they didn't show/cat the code they used) C main and apparently it called like

#

834* syscalls

#

despite doing literally nothing

#

the trustworthiness of the person isn't really too high though since they're blaming it on C instead of their compiler/stdlib

lavish dove
lavish dove
#

thats a syscall

spare quartz
#

true, but it shouldn't need that many just to get argv

#

heres the pic they showed

#

oh they did cat the code they used huh

lavish dove
#

oh

#

mmap

spare quartz
#

i wonder why their stdlib is so screwed

lavish dove
#

its probably calling mmap for every page

#

cuz theres also 100 mprotect calls

#

idk what mprotect is though

spare quartz
#

if i had to guess locking a page?

lavish dove
#

oh it sets if its user or not

spare quartz
#

oh

lavish dove
#

if a page is user or not

#

atleast according to teh first sentence of its man page

spare quartz
#

also getrandom being there is super weird

lavish dove
#

a buncho f bootloaderes randomize memory, I dont know if theres some security reason for that

#

oh yeah spectre

spare quartz
#

yeah but this is an empty main on a usermode env

lavish dove
#
higanbana:~/c $ echo "int main() {return 0;}" > main.c
higanbana:~/c $ cat main.c
int main() {return 0;}
higanbana:~/c $ gcc main.c -o main.o
higanbana:~/c $ strace -c main.o
strace: Can't stat 'main.o': No such file or directory
higanbana:~/c $ strace -c ./main.o
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 52.09    0.000137          17         8           mmap
 20.53    0.000054          18         3           mprotect
 13.31    0.000035          35         1           munmap
  2.66    0.000007           3         2           close
  2.66    0.000007           7         1           prlimit64
  2.28    0.000006           6         1           arch_prctl
  2.28    0.000006           6         1           set_tid_address
  2.28    0.000006           6         1           rseq
  1.90    0.000005           5         1           set_robust_list
  0.00    0.000000           0         1           read
  0.00    0.000000           0         1           brk
  0.00    0.000000           0         2           pread64
  0.00    0.000000           0         1         1 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         2           openat
  0.00    0.000000           0         2           newfstatat
------ ----------- ----------- --------- --------- ----------------
100.00    0.000263           9        29         1 total
#

blank program for me

#

wth is up with that guys stdlib lol

spare quartz
#

well they were apparently running it on

#

android

lavish dove
#

ohh

spare quartz
#

which is weird af considering their argument is to "use zig"

lavish dove
#

android is really fucking weird lol

#

lol

#

I tried zig

#

the documentation is everywhere but I kinda liked it

#

I wish the memory management was easier though

spare quartz
#

oh you just reminded me

#

apparently ada has no clear automatic memory management

#

objects will still be finalized, but never "freed from memory"

#

(barring Unchecked_Deallocation..)

lavish dove
#

oh sheeee

#

ada doesnt use stack??

spare quartz
#

opposite

#

stuff like GNAT uses the stack as much as possible over the heap

lavish dove
#

I mean if its not being used as much as possible thats a red flag

spare quartz
#

as much as everything is clear in ada, how the memory is managed is... very arcane and not very well documented

lavish dove
#

lol

spare quartz
#

for example the Ada RM says a compiler can have a garbage collector

#

but for the last 40 years no compiler has ever added one

lavish dove
#

well I mean they are slwo

spare quartz
#

depends on the algorithm you use mainly

#

openjdk has a lot of experience on that

lavish dove
#

wait

#

I jsut remembered

#

my schools computers bios's arent locked

#

I can usb boot

spare quartz
#

oh neat

lavish dove
#

im gonna be gaming on tuesday when I get to school lol

#

hope my teacher doesnt find it suspicious that my pc is running full games

#

and doesnt show up on the supervisor thing

#

wait now I wonder

#

if i made a old style game that booted from a cd or something

#

would be even funnier if it was 3D

spare quartz
#
  GNU nano 4.8                                                                                            /bin/buildAda                                                                                                      
PROJECT=${2:-${PWD##*/}}
gnatpp -P$PROJECT.gpr -U; alr build --profiles=*=$1; sudo bin/$PROJECT
lavish dove
#

scraaa

spare quartz
#

a command i made to automate building easier

#

just posting here in case i lose it

#

gnatpp - lints/formats ada code
alr build - builds code (incl. libraries) under a profile like validation
sudo bin - lets me run built applications that might require admin for testing (i.e. servers)

#

gnatpp needs to run before alr build cause "validation" will crash on all warnings* (including style)

lavish dove
#

ok

lavish dove
burnt locust
#

I learnt python

lavish dove
#

nice

timid quartz
#

While still protecting you from foot guns

timid quartz
#

HTTP, SMTP, BitTorrent, you name it

lavish dove
#

just a really sophisticated conversation

#

must be how those woke radical groups communicate, we must filter all traffic manually

#

to destroy the woke movement

spare quartz
timid quartz
#

@spare quartz

with Ada.Text_IO; use Ada.Text_IO;

procedure Ada_Select is
   type Array_Type is array (Natural range <>) of Integer;
   Arr : Array_Type := (5, 3, 1, 4, 2);
begin
   for I in Arr'Range loop
      declare
         Least_Index : Natural := I;
      begin
         for J in I .. Arr'Last loop
            if Arr (Least_Index) > Arr (J) then
               Least_Index := J;
            end if;
         end loop;

         declare
            Temp : Integer := Arr (I);
         begin
            Arr (I) := Arr (Least_Index);
            Arr (Least_Index) := Temp;
         end;
      end;
   end loop;

   for I in Arr'Range loop
      Put_Line (I'Image & ": " & Arr (I)'Image);
   end loop;
end Ada_Select;
timid quartz
#

selection sort

spare quartz
#

do a parallel binary search next 🗣️

#

anyways what made you wanna write it

timid quartz
#
fn main() {
    let mut my_vec = vec![5, 2, 3, 4, 1];
    selection_sort(&mut my_vec);
    println!("{my_vec:?}");
}

fn selection_sort<T: PartialOrd>(arr: &mut Vec<T>) {
    for i in 0..arr.len() {
        let mut least_index: usize = i;
        
        for j in i..arr.len() {
            if arr[least_index] > arr[j] { least_index = j }
        }
        
        arr.swap(i, least_index);
    }
}
#

rust

#
#include <stdio.h>

void selection_sort(int *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        unsigned int least_index = i;

        for (int j = i; j < len; j++)
        {
            if (arr[least_index] > arr[j])
                least_index = j;
        }

        int temp = arr[i];
        arr[i] = arr[least_index];
        arr[least_index] = temp;
    }
}

int main(void)
{
    int arr[] = { 5, 3, 4, 1, 2 };
    selection_sort(arr, 5);

    for (int i = 0; i < 5; i++)
    {
        printf("[%d] = %d\n", i, arr[i]);
    }

    return 0;
}
#

c

#

@spare quartz

#

I think the rust one is quite nice

spare quartz
#

hold on im eating ice flakes

#

PartialOrd

#

🤨

lavish dove
#

What

#

What is a partial order lol

spare quartz
#

In mathematics, especially order theory, a partial order on a set is an arrangement such that, for certain pairs of elements, one precedes the other. The word partial is used to indicate that not every pair of elements needs to be comparable; that is, there may be pairs for which neither element precedes the other. Partial orders thus generalize...

#

basically a set of things that can be compared

lavish dove
#

Oh

timid quartz
#

the arr[least_index] > arr[j]

spare quartz
#

i figured i just didn't know what it was at first

timid quartz
#

ada has operator overloading right

spare quartz
#

</> are defined by Scalar types in ada... iirc

spare quartz
timid quartz
#

so you could make a record and operator overload for that record right

#

to compare the records

spare quartz
#

yes

timid quartz
#

ok

spare quartz
#

you can't overload rem/mod though :<

timid quartz
#

it's not a trait but it's better than nothing

spare quartz
#

wait

#

nvm!

timid quartz
#

can overload the remainder operator in rust too

spare quartz
#

i know limited gates assignment

timid quartz
#

what a weird boolean expression

#

the (or rem xor) isn't even valid

#

no lhs

#

and the not is in the wrong spot

spare quartz
timid quartz
#

I think they meant (abs) and (not mod or rem xor)

#

so you can overload abs

#

and whatever not mod or rem xor evaluates to

spare quartz
#

evals to nothing since the righthand of xor is blank

timid quartz
#

so mod then

#

abs and mod

spare quartz
#

"not mod" too... unless mod were like, a value

spare quartz
#

assuming the right hand of XOR being blank means 0

#

that means rem stays the same

timid quartz
#

so it's rem xor then

#

because not mod

#

abs and rem xor

spare quartz
#

is quite confusing

#

(abs & !mod) | (rem ^ 0)

timid quartz
#

anyways

struct A;
struct B;
struct AB;

impl std::ops::Rem<B> for A {
  type Output = AB;
  fn rem(self, _rhs: B) -> AB {
    println!(":3");
    AB
  }
}
spare quartz
#

the humble function "rem"()

timid quartz
#

and then that lets you do

spare quartz
#

so many

timid quartz
spare quartz
#

oh yeah i forgot ada's exponentiation operator is **

#

i wonder what ^ is used for.. if anything

spare quartz
timid quartz
#

it is in rust!!!!

spare quartz
#

thats stupid!!!

timid quartz
#

kys!!!

#

jk

spare quartz
#

A := "+"(B, C);

#

bet you cant do THAT

timid quartz
#

that's gross

spare quartz
#

true

#

A := B + C; is lame thogh,,

#

scps ls time

timid quartz
#

bet you can't do THAT

timid quartz
#
(+ 1 2)
spare quartz
#

WHAT SI THAT

timid quartz
#

C

#

:3

spare quartz
#

wwhwat is that syntax??

#

just weird indexing?

timid quartz
#

Yeah

#

arr[2] = *(arr + 2) = 2[arr]

#

@spare quartz what do you think of lisp

spare quartz
#

haven't really seen it

#

but interesting

spare quartz
#

it involves use of System.Address though

timid quartz
spare quartz
#

yeah which one

timid quartz
timid quartz
spare quartz
timid quartz
#

Though technically it’s a family of programming languages

#

There’s Common Lisp, Clojure, Emacs Lisp, and others

timid quartz
#

Lisp machines are general-purpose computers designed to efficiently run Lisp as their main software and programming language, usually via hardware support. They are an example of a high-level language computer architecture. In a sense, they were the first commercial single-user workstations. Despite being modest in number (perhaps 7,000 units to...

spare quartz
timid quartz
spare quartz
#

nothing like make

#

more like overgrown pascal

timid quartz
spare quartz
#

yes it is

timid quartz
#

nuh uh

spare quartz
#

that syntax is overgrown make

timid quartz
#

no it not

spare quartz
#

scary!

timid quartz
#

just use rust

spare quartz
#

hopefully this doesnt crash the server

#

hmm

#

i think i can do this instead

spare quartz
#

Task 50: raised CONSTRAINT_ERROR : extensible_http.ads:84 access check failed

#

WHY

spare quartz
#

of course

lavish dove
spare quartz
#

access types (pointers) are super heavily guarded in ada and basically i tried to circumvent a compiler check by throwing Unchecked at it

#

didn't work

lavish dove
#

lol

spare quartz
#

why would rust help here

timid quartz
#

Because… :3

lyric mesa
#

rust

timid quartz
#

Idk there’s not this weird access stuff

lyric mesa
#

rust

#

rust

timid quartz
#

RUST!!!

spare quartz
#

i COULD cop out but i dont wanna

timid quartz
timid quartz
lyric mesa
#

i just check qsp often

spare quartz
#

the end user being the programmer using the HTTP library

timid quartz
timid quartz
spare quartz
#

HTTP_11_Request_Message'Input (Stream).Target

#

Target is the access-to-string type (causing the problem)

timid quartz
#

Cant you just make target like not visible though

spare quartz
#

no cause the programmer needs it

#

they just shouldn't be able to write to it

timid quartz
#

ic

spare quartz
#

access check failed WOULD IMPLY its "null" here but-

#

duh DOY it IS null

timid quartz
#

Can you not use restrict

#

Or whatever

spare quartz
#

i JUST realized

spare quartz
timid quartz
#

idk

spare quartz
#

access constant is a read-only access

#

i just figured out the problem

timid quartz
#

In rust all I’d do is make the struct member not public and have a getter that returns an immutable reference

spare quartz
#

its cause im instantiating the Request_Message while String_Access can't be null

#

so it's creating the record and failing immediately

#

lemme fix that

#

gotta be careful with not null access

timid quartz
#
struct Request {
  target: String,
}
impl for Request {
  pub fn get_target(&self) -> &String {
    &self.target
  }
}
#

It’s that easy

spare quartz
#

bleh getter

#

i don't need that in ada

#

i just need to design smartly

timid quartz
#

Just do the easy thing smh

spare quartz
#

access constant - RO access
access all - RW access

timid quartz
#

So then how do you write to it once

#

But stop the user writing…

spare quartz
#

by setting it in the record instantiation

timid quartz
#

ic…

spare quartz
#

i could go the extra step and see if i can make Request limited but that seems too much

timid quartz
#

Or you could just have a &

spare quartz
#

que

spare quartz
#

that's still using a getter which is not needed here though

#

not-nullable read-only access-to-string at instantiation is superior

timid quartz
#

Well rust doesn’t really support that

spare quartz
#

well make it support it

timid quartz
#

Unless you OnceCell it maybe

spare quartz
#

with an rfc or whatever you do

timid quartz
#

You could maybe OnceCell it

spare quartz
#

idk what that is

#

A cell which can nominally be written to only once.

This allows obtaining a shared &T reference to its inner value without copying or replacing it (unlike Cell), and without runtime borrow checks (unlike RefCell). However, only immutable references can be obtained unless one has a mutable reference to the cell itself. In the same vein, the cell can only be re-initialized with such a mutable reference.

For a thread-safe version of this struct, see std::sync::OnceLock.

timid quartz
#

Yeah

spare quartz
#

now that's sealed

timid quartz
#

though oncecell does allow for some interior mutability I think

spare quartz
#

still a bit worried about this piece of code though

#

since the access would technically be invalid when it goes out of scope (but it shouldn't be gone)

timid quartz
#
#[derive(Debug)]
struct MyThing {
    target: std::cell::OnceCell<String>,
}

fn main() {
    let mut thing = MyThing { target: std::cell::OnceCell::new() };
    thing.target.set("hello".to_string()).unwrap();
    
    let mut mut_ref = thing.target.get_mut().unwrap();
    *mut_ref = String::from("goodbye");
    println!("{thing:?}")
}

this outputs the changed string

#

MyThing { target: OnceCell("goodbye") }

#

but if let mut thing was just let thing then you couldn't .get_mut() on it

#

I think the better solution is just the getter

spare quartz
timid quartz
#

But the non-public field with getter is probably more robust

timid quartz
#

I’ll actually do the exe reader soon so I can challenge you to build something in Rust

spare quartz
#

finally something

#

ignore the weird key format thats just cause adas a bit confused on how to represent Token since it's an "array of characters"

spare quartz
#

new String'(x) apparently works

#

just need to parse the message body

#

who that

timid quartz
spare quartz
#

Yeah

spare quartz
spare quartz
#

1.28 Mb of memory for a 50 threaded http server isnt bad right

timid quartz
spare quartz
timid quartz
#

you said new string was enough

spare quartz
#

new String'(x) -> allocator
is new String -> type derivative of type String

timid quartz
#

oh

#

show the code I wanna c

spare quartz
#

Read_String_From_Stream is creating a new temporary string object which is then allocated and put onto an access by new String'(...)

timid quartz
#

somehow this is more confusing than rust

spare quartz
#

what's there to be confused about

timid quartz
#

read string from stream makes temporary object I get that

#

and then it's allocated and put onto an access?

spare quartz
#

well i'm not gonna try and explain the inner workings but basically

#

an access type is created, assigned to Item.Target, which will keep track of the new string object instead of it being voided when out of scope

timid quartz
#

show me uh

#

HTTP_11_Request_Message

#

the record declaration

spare quartz
timid quartz
#

and what is String_Access ca

spare quartz
timid quartz
#

access String?

#

ah ic

#

and new String'(x) coerces into an access constant String

#

gotcha

spare quartz
#

yeah

#

access constant making it RO instead of RW with all or <none>

timid quartz
#

eys

spare quartz
#

hmmm... write-only access 🧌

timid quartz
#

write only access

#

lmao

spare quartz
#

im sure thats something you could do but it'd involve a lot more work

#

(and i don't know why you'd do it)

timid quartz
#

to make a bad translation

#

new String'(x) outputs a char* (or a &String in Rust)

#

which coerces into a read-only pointer

spare quartz
#

yeah

#

oh yeah good news

#

this webserver is pretty OK at multiprocessing

#

i gave it 1,000,000 requests and it used 300% CPU at only 0.2% memory

#

(i have a 12 core cpu @ 64 gb of ram)

#

but now i need to add authentication and TLS,,,,

spare quartz
#

no that's a good thing

#

i want it to use 1,200% cpu cause then that means it's using the threads to the best of its ability

timid quartz
#

Maybe it only used 300% because of the rate of threads dying to threads being made

spare quartz
#

the threads never die though

timid quartz
#

No no no but like

#

You make a new thread for every request right

#

Or a new Task rather

sacred shoal
#

how do you even use 300%

timid quartz
spare quartz
#

300% across all cores

spare quartz
timid quartz
#

Ok but

spare quartz
#

the load was balanced across all cores

timid quartz
#

You’re using 100% of 3 threads across all CPUs

spare quartz
#

true

#

well

sacred shoal
#

i don't really understand still 😭

timid quartz
#

Like that’s what it amounts to

spare quartz
#

it DID get down to thread #30 but

#

i don't know the exact balancing

timid quartz
#

Like the work is spread across 50 threads but it only sums to 3 threads’s worth

spare quartz
#

pool of 50 threads, each time a connection is done it puts it back into the pool so its state can be set to the new connection (when available)

timid quartz
#

Ok but

#

Each request has its own thread right

spare quartz
#

yes

timid quartz
#

So what I’m saying is

#

Maybe you weren’t spamming it enough

#

Because like the rate of requests incoming to requests being completed only resulted in 300% usage

#

So send more requests and send them faster

spare quartz
#

hold on

#

ill try another benchmark after i add these

timid quartz
#

Like you eventually reached a steady state

#

Where you were at 300% usage

#

And the amount of new requests == the amount of requests being completed

#

So if you wanna get to 1200%, send more and send them faster

spare quartz
#

okay but theres gotta be limits to the benchmark software im using

timid quartz
#

That is also probably a factor

spare quartz
#

the 1% percentile of requests made it in 4,000 ms

#

while 99% percentile was 1/2 ms

timid quartz
#

The one percentile was probably your first few requests

#

Cause you know, cold start

#

But once your threads were warm

spare quartz
#

ughhh cache is also probably playing a part toooo

#

would explain why initially it was 7,000 r/s while at the end of 1,000,000 requests it went up to 11,000/s

#

oops

#

i forgot to turn off the debug prints

#

holy crap

#

okay it got up to 500%

timid quartz
#

lol that would slow you down for sure

#

use this

#

!!

spare quartz
#

okay ill try that after this is done

#

100,000 to go

#

11,480 / s

spare quartz
#

to make an http reuqest

timid quartz
#

uh curl

spare quartz
#

yeah its not doing well with curl

timid quartz
#

womp

#

maybe hyperfine is better to time each request

#

rather than usage-maxxing

spare quartz
#

there's definitely a memory leak since i'm not doing deallocation whatsoever

#

but that's fine for now

timid quartz
#

throw this shit into valgrind

spare quartz
#

i know why its leaking memory (access types)

#

maybe this could be something to look into in the future

timid quartz
#

but I also thought ada didn't use the heap

spare quartz
#

not defined

timid quartz
#

but I also thought gnat didn't use the heap

spare quartz
#

see GNAT internals for how it's handled

timid quartz
#

eww gnat internals

spare quartz
timid quartz
#

imagine ada not inserting calls to free() for you :3

spare quartz
#

i'd imagine the dynamically allocated Targets are the ones leaking the most

spare quartz
#

either you never use access types or you use Unchecked_Deallocation

timid quartz
#

I smell foot guns!!!

spare quartz
#

of

timid quartz
timid quartz
#

but what happens if you Unchecked_Deallocation and then try to use again

#

use after free :3

spare quartz
#

you can't segfault with ada pointers

timid quartz
#

there's 100% some way to exploit a memory vuln in ada

spare quartz
spare quartz
#

use after free isn't possible at all

#

not unless you use System.Address or Unrestricted_Access

#

both of which warn you out the gate

timid quartz
#

Unrestricted_Access ❤️

spare quartz
#

(only 'Unchecked_Access is, which you also can't segfault with)

timid quartz
#

but still just like

#

man

#

imagine your language not being smart enough to do memory management for you

spare quartz
#

because it's not possible

timid quartz
#

rust

#

garbage collectors

spare quartz
#

and AGAIN

#

this literally only applies to accesses

timid quartz
#

no I was saying that those things are smart enough to do memory management for you

spare quartz
#

(GNAT-specific accesses!)

timid quartz
#

whereas ada isnt ;3

spare quartz
spare quartz
#

not how accesses work

timid quartz
#

an access is basically just a fancy pointer

#

and a reference is also a fancy pointer

#

case closed

spare quartz
timid quartz
#

hmmm

#

define them better then

spare quartz
#

can't

timid quartz
#

ada 2024 edition

spare quartz
#

the humble Indefinite_Holder, btw:

#

there

timid quartz
spare quartz
#

package String_Holders is new Ada.Containers.Indefinite_Holders (String);

timid quartz
#

ok but what does it do

timid quartz
#

english

spare quartz
#

it holds something

timid quartz
#

but like

#

why

#

why not just a String

#

or an Unbounded_String

spare quartz
#

because a String is an indefinite type

#

and Unbounded_String adds overhead i don't want

#

so now i can just

#

corrected

#

ayyyyy