M2libc icon indicating copy to clipboard operation
M2libc copied to clipboard

Eliminate `bootstrappable.c`

Open fosslinux opened this issue 11 months ago • 6 comments

bootstrappable.c has a number of functions from the early years of the M2* projects that were helpful at the time. However, we have gradually moved away from these towards more standard C library interfaces (as per this project).

We should eliminate the remaining non-standard functions from bootstrappable.c, first by introducing the new interfaces where they do not already exist, then replacing existing code with the standard interfaces, then removing the old functions.

  • [ ] require -> assert
    • [ ] implemented
    • [ ] replaced
    • [ ] removed
  • [ ] match -> strcmp
    • [x] implemented
    • [ ] replaced
    • [ ] removed
  • [ ] in_set -> strchr
    • [x] implemented
    • [ ] replaced
    • [ ] removed
  • [ ] strtoint -> atoi
    • [ ] implemented
    • [ ] replaced
    • [ ] removed
  • int2str is probably not removable at this time

fosslinux avatar Mar 21 '25 02:03 fosslinux

Not sure if all of these can be replaced. We can only replace them if replacements are written in cc_* subset.

stikonas avatar Apr 03 '25 23:04 stikonas

@fosslinux As far as I understand the cc_* compilers only include the bootstrappable.* files by manually adding them to the command line (include directives do nothing). With this we would either need to make the entire string parsing files buildable by cc_* or add a define (do the cc_* compilers handle ifdefs?).

IMO match that basically returns a bool also has a better interface than strcmp which can return positive, negative or zero.

assert raising an interrupt rather than exiting would be nice for when using a debugger though.

gtker avatar Apr 04 '25 18:04 gtker

I just checked in M2-Mesoplanet and it doesn't use any of the boostrappable functions. Should all these just be moved out of M2libc and into M2-Planet instead, possibly into cc_core.c?

Also @fosslinux I implemented atoi in https://github.com/oriansj/M2libc/pull/84.

gtker avatar Apr 24 '25 19:04 gtker

There is also hex2 and M1. Are they using these functions?

stikonas avatar Apr 24 '25 20:04 stikonas

There is also hex2 and M1. Are they using these functions?

Hadn't checked the C versions of those since I forgot they existed. They both use bootstrappable. That complicates things a little.

IMO custom headers/files don't belong in a "libc" since it's a portability nightmare but the unnecessary duplication is also annoying. I guess we'll leave it as it is currently.

gtker avatar Apr 24 '25 20:04 gtker

Actually, we could port hex2 away, there are no issues there.

There is still M1 and blood-elf though. I think they need bootstrap mode because full M2libc uses lowercase hex immediate numbers and at the moment M0 only supports lowercase. Also initial debugging of M2 on new arches is easier with smaller libc.

stikonas avatar Apr 24 '25 21:04 stikonas