Implementation of my own BIF function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementation of my own BIF function

Sergey Loguntsov
Hi, everybody.

I tried to implement my own BIF-function which is implemented inside Erlang sources.

So i made sources of this function in erts/emulator/beam/bif.c and i have changed erts/emulator/beam/bif.tab
i found also i must change erts_internal.erl module in /erts/preloaded/src folder.
My problem is .. there are prebuilded files based on erts/preloaded/ebin and actually they are not updating every time what i'm building Erlang. They are committed as part of sources (seems this is big crutch).
So my question is what is right way to update preloaded modules (beam files) ?
May be there is another way to have BIF function outside from Erlang sources ? and building them together ?

Regards.
Reply | Threaded
Open this post in threaded view
|

Re: Implementation of my own BIF function

Andrew Thompson-2
On Thu, Mar 12, 2020 at 09:44:11PM +0300, Sergey Loguntsov wrote:
> Hi, everybody.
>
> I tried to implement my own BIF-function which is implemented inside Erlang
> sources.

You should use a NIF not a BIF.

>
> So i made sources of this function in erts/emulator/beam/bif.c and i have
> changed erts/emulator/beam/bif.tab
> (
> https://github.com/loguntsov/otp/commit/7a28a3d99b0c7795d956caec5e4e397183dd1ea9
> )
> i found also i must change erts_internal.erl module in /erts/preloaded/src
> folder.
> So i made it:
> https://github.com/loguntsov/otp/commit/84c4bfb8c372ade9d92c4a20515f91fe33062b1d
>
> My problem is .. there are prebuilded files based on erts/preloaded/ebin
> and actually they are not updating every time what i'm building Erlang.
> They are committed as part of sources (seems this is big crutch).
> So my question is what is right way to update preloaded modules (beam
> files) ?
> May be there is another way to have BIF function outside from Erlang
> sources ? and building them together ?

You can use `./otp_build update_preloaded` if you really want to do this
which will recompile the precompiled beams for you. However be careful
as it will also make a git commit for you(??).

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: Implementation of my own BIF function

Sergey Loguntsov
> You should use a NIF not a BIF.
Actually i can't use it as i needs internal representation of information from Erlang process which is available only from BIF. NIF hides it from me and i forced to include Erlang sources to NIF code. I don't like it.

> You can use `./otp_build update_preloaded`
It works for me. Thank you very much.

пт, 13 мар. 2020 г. в 02:04, Andrew Thompson <[hidden email]>:
On Thu, Mar 12, 2020 at 09:44:11PM +0300, Sergey Loguntsov wrote:
> Hi, everybody.
>
> I tried to implement my own BIF-function which is implemented inside Erlang
> sources.

You should use a NIF not a BIF.
>
> So i made sources of this function in erts/emulator/beam/bif.c and i have
> changed erts/emulator/beam/bif.tab
> (
> https://github.com/loguntsov/otp/commit/7a28a3d99b0c7795d956caec5e4e397183dd1ea9
> )
> i found also i must change erts_internal.erl module in /erts/preloaded/src
> folder.
> So i made it:
> https://github.com/loguntsov/otp/commit/84c4bfb8c372ade9d92c4a20515f91fe33062b1d
>
> My problem is .. there are prebuilded files based on erts/preloaded/ebin
> and actually they are not updating every time what i'm building Erlang.
> They are committed as part of sources (seems this is big crutch).
> So my question is what is right way to update preloaded modules (beam
> files) ?
> May be there is another way to have BIF function outside from Erlang
> sources ? and building them together ?

You can use `./otp_build update_preloaded` if you really want to do this
which will recompile the precompiled beams for you. However be careful
as it will also make a git commit for you(??).

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: Implementation of my own BIF function

Raimo Niskanen-11
In reply to this post by Andrew Thompson-2
On Thu, Mar 12, 2020 at 07:04:20PM -0400, Andrew Thompson wrote:
> On Thu, Mar 12, 2020 at 09:44:11PM +0300, Sergey Loguntsov wrote:
> > Hi, everybody.
: :
> > They are committed as part of sources (seems this is big crutch).
> > So my question is what is right way to update preloaded modules (beam
> > files) ?
> > May be there is another way to have BIF function outside from Erlang
> > sources ? and building them together ?
>
> You can use `./otp_build update_preloaded` if you really want to do this
> which will recompile the precompiled beams for you. However be careful
> as it will also make a git commit for you(??).

There is a flag for that:

    ./otp_build update_preloaded --no-commit

I use it constantly.  Then add the files that I have affected, commit,
reset --hard HEAD, build emulator.

>
> Andrew

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB