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

G Bulmer gbulmer@REDACTED
Mon Mar 10 13:17:13 CET 2008


Thank you.

> G Bulmer 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.
Thank you. That clears that up.

I would like to make the two predicates (is_dtrace_on/0 and  
is_dtrace_off/0 ) available in guard expressions.
I have them in bif.tab as:
   ubif erlang:is_dtrace_on/0
   ubif erlang:is_dtrace_off/0

but they do not show up as directly usable (without the erlang: syntax).
If I use that erlang:is_dtrace_on() syntax I get a compile-time error,  
e.g. :
    f() when erlang:is_dtrace_on() ->

I noticed e.g. is_tuple() is a ubif, and is_tuple() can be used in  

It's ebif is in erl_pbifs.c, and it's its source is in erl_bif_op.c,  
and there doesn't appear to be anything magic there.
It has an entry in erl_bif_table.c, which is auto-magically generated  
by make_table.

I would like to understand the machinery that enables is_tuple() to  
appear in guard expressions.
It doesn't look different in make_table, and its input bif.tab  
(is_tuple isn't in atom.names).

So I assume that it is possible for us to add new guard predicates,  
and that I am missing some other piece of machinery.

What other things are needed to do enable e.g. is_dtrace_on/0 to work  
in a 'when' guard?

>> 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.
That is very helpful. I had read the entries and the end of bif.tab,  
and have followed that convention, but I felt uncomfortable that I  
didn't understand what was happening.

>> ... snip ...
>> 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.
>> ... snip ...

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

Thank you again for your help.

More information about the erlang-questions mailing list