Erlang Central

Difference between revisions of "Adding my own BIF"

From ErlangCentral Wiki

Line 1: Line 1:
0) run configure
+
:1. run configure
 
+
:2. add your bifs to erts/emulator/beam/bif.tab
1) add your bifs to erts/emulator/beam/bif.tab
+
<tt>
<code>
+
 
bif re:grep/2
 
bif re:grep/2
 
bif re:compile/1
 
bif re:compile/1
</code>
+
</tt>
 
+
:3. create a C file
2) create a C file
+
<tt>
<code>
+
 
erts/emulator/beam/erl_bif_re.c
 
erts/emulator/beam/erl_bif_re.c
</code>
+
</tt>
3) add your C file to erts/emulator/<arch>/Makefile
+
:4. add your C file to erts/emulator/<arch>/Makefile
<code>
+
<tt>
 
RUN_OBJS = $(OBJDIR)/erl_bif_re.o \
 
RUN_OBJS = $(OBJDIR)/erl_bif_re.o \
</code>
+
</tt>
4) implement your bifs by stealing bits from existing erl_bif_*.c files
+
:5. implement your bifs by stealing bits from existing erl_bif_*.c files
<code>
+
<tt>
 
BIF_RETTYPE re_grep_2(BIF_ALIST_2){
 
BIF_RETTYPE re_grep_2(BIF_ALIST_2){
  Eterm result;
+
Eterm result;
  result = magic_function();  
+
result = magic_function();  
  BIF_RET(result);
+
BIF_RET(result);
 
}
 
}
</code>
+
</tt>
5) run make; make install
+
:6. run make; make install
  
 
steps 0-3 need only be done once.
 
steps 0-3 need only be done once.
  
 
note that if you add
 
note that if you add
<code>
+
<tt>
 
bif re:grep/2
 
bif re:grep/2
</code>
+
</tt>
 
to bif.tab there should be a  
 
to bif.tab there should be a  
<code>
+
<tt>
 
erl_bif_re.c
 
erl_bif_re.c
</code>
+
</tt>
 
that implements
 
that implements
<code>
+
<tt>
 
BIF_RETTYPE re_grep_2(BIF_ALIST_2);
 
BIF_RETTYPE re_grep_2(BIF_ALIST_2);
</code>
+
</tt>
 
[[Category:HowTo]]
 
[[Category:HowTo]]

Revision as of 16:56, 31 July 2006

1. run configure
2. add your bifs to erts/emulator/beam/bif.tab

bif re:grep/2 bif re:compile/1

3. create a C file

erts/emulator/beam/erl_bif_re.c

4. add your C file to erts/emulator/<arch>/Makefile

RUN_OBJS = $(OBJDIR)/erl_bif_re.o \

5. implement your bifs by stealing bits from existing erl_bif_*.c files

BIF_RETTYPE re_grep_2(BIF_ALIST_2){ Eterm result; result = magic_function(); BIF_RET(result); }

6. run make; make install

steps 0-3 need only be done once.

note that if you add bif re:grep/2 to bif.tab there should be a erl_bif_re.c that implements BIF_RETTYPE re_grep_2(BIF_ALIST_2);