AdeptLanguage / Adept

The Adept Programming Language
GNU General Public License v3.0
119 stars 9 forks source link

Make it possible to create a DLL in Adept #78

Closed ghost closed 1 year ago

ghost commented 1 year ago

I believe there isn't a way to do this at the moment.

You can generate an object file with adept -c main.adept and then link it, but it will have a main function.

Since global and static variables are initialized and de-initialized inside of main, it would take a little reworking before this is viable.

Originally posted by @IsaacShelton in https://github.com/AdeptLanguage/Adept/discussions/76#discussioncomment-6898564

IsaacShelton commented 1 year ago

This should be supported now with the latest nightly build

(once it finishes CI/CD, it's cold so might take an hour or two for the nightly release to be updated)

The easiest way to create a dynamic library is by adding

pragma dylib my_library_init my_library_deinit

to the top of your root file, as well as define the externally visible initialization and deinitialization functions:

external func my_library_init(){
    print("Initialize called")
}

external func my_library_deinit(){
    print("Deinitialize called")
}

And then all regular Adept features should be supported, including initialization/deinitialization of global variables and static variables.

See https://github.com/AdeptLanguage/Adept/tree/master/tests/e2e/src/dylib for full example

IsaacShelton commented 1 year ago

The nightly build is updated now