[erlang-questions] Help: What's the correct way to add new BIFs?

Bjorn Gustavsson bjorn@REDACTED
Mon Mar 10 12:30:18 CET 2008


G Bulmer <gbulmer@REDACTED> writes:

> I want to add a few new BIFs to erts for some DTrace experiments, and  
> I'd like some pointers/advice.
> (They may not end up in the solution, so please don't panic yet:-)
> 
> Is there a document which describes the correct approach? (I thought  
> I'd seen it a few months ago, but I, google and spotlight can't find  
> it :-(
> 
> The questions I'd like some help/advice with are:
> 1. I read (in bif.tab) that ubifs are bif's without trace wrappers. Is  
> this a critical decision, or is it okay to use ubifs, and decide later?

You should use bif; ubifs are only for guard BIFs.

> This example seems to define the same bif twice. What is this doing  
> really? What is the atom 'erl.lang.number' or 'erl.lang.binary' for?
> (I've read the make_tables script, but my perl is bad, so it isn't  
> clearto me, sorry.)

You only need to define one name for your BIF. The other type of name
is for the package system, which is currently unsupported. If you
look at the end of the file, you can see that we no longer add duplicate
names.
        
> Small point, I read the the syntax productions as <C-name> is  
> optional, but:
> bif erlang:atom_to_list/1
> bif 'erl.lang.atom':to_string/1		ebif_atom_to_string_1 atom_to_list_1
> 
> has two. I think the syntax in the bif.tab comment maybe should read:  
> <bif-decl> ::= "bif" <bif> {<C-name>} | "ubif" <bif> {<C-name>}
> as {...} is conventionally 0 or more.

Yers, the comment is out-of-date.

> 3. To be clean and tidy, I feel I should put our new bifs in a new set  
> of source files (rather than mx them into the existing bif source  
> files).

Yes.

> Are there some naming conventions I should follow to align with the  
> OTP team?

We generally use "erl_" prefix for all new source code files.

> I assume that the new bifs should be put in a section at the end of  
> bif.tab.

Yes.

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list