Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Libc #51

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Partial Libc #51

wants to merge 7 commits into from

Conversation

Voidler-cell
Copy link

libc

Parts added

math.h (fenv.h)

Added support for all functions except lgamma and tgamma.
Also function for long double just use the double variant, as js has no support for long double. This is within c spec.

stdlib

Added a very basic allocator, that allocates a specifiable number of blocks per js memory page.
The blocks are then combined or separated to form continuous memory of different sizes.

string.h

Complete implementation in c, so no JS is needed for it

time.h

Used UTC and Local time of JS to implement the functions.

stdio.h

This one is only partially implemented and is, for example, missing implementations for the scanf family and only supports the 'rb' mode for opening files on the server. Also no stdin support.
Could look into supporting this better with async.
I am still including it because the printf family support is important.

Examples

Added some basic examples with functions from the lib.
For example, displaying the local time, and calculating the result of cos/sin.

Correctness

Please use this knowing that it is not completely C-compliant and also in no way bug-free.
I hope we can all test it thoroughly and report bugs or even fix them.

@Voidler-cell Voidler-cell changed the title Libc Partial Libc Feb 26, 2024
@RobLoach
Copy link

Are you looking to re-implement a bunch of the standard C library to make porting legacy code easier? raylib does provide some helpful libraries around using a bunch of these directly, like MemAlloc(), and LoadFileData(). May be better to target the raylib API first before bringing in the whole C library.

@Voidler-cell
Copy link
Author

Yes, implementing parts of the standard C library to make porting code easier, but also to just allow its use, is the goal.
Using MemAlloc() for memory allocation is not very common, as malloc works on basically every platform that is far enough to support graphical applications.

Many functions such as MemAlloc() and LoadFileData() are implemented using the standard C library in raylib, so it may even be possible to compile parts of raylib to wasm, to forgo re-implementing every function.

@RobLoach
Copy link

Taking this approach does break the pattern introduced, where the WASM calls the target methods. Implementing a subset of these methods in JavaScript will keep the WASM compilation process minimal, but perhaps that's not your goal.

If you're porting an existing legacy app over to the web, it's likely easier to use emscsripten via https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)

Many functions such as MemAlloc() and LoadFileData() are implemented using the standard C library in raylib

Remember that this is not raylib 😉 It's a reimplementation of the raylib API that makes WASM call JavaScript functions.

@Voidler-cell
Copy link
Author

Voidler-cell commented Feb 27, 2024

The description does not contain, that every method has to be implemented in JS.
This is just the thing people are doing at the moment.

Tsoding himself has mentioned a few times, that it is not necessary to implement every function in JS if we manage to implement all base functions. Example.

I know it is not raylib, but who said we can't use code from raylib. If we can get parts of the source to compile, by implementing everything it needs in JS, it would make it a lot easier for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants