Adding my own BIF

From Erlang Community

(Difference between revisions)
Revision as of 15:47, 31 July 2006 (edit)
Massemanet (Talk | contribs)

← Previous diff
Revision as of 15:54, 31 July 2006 (edit) (undo)
Massemanet (Talk | contribs)

Next diff →
Line 2: Line 2:
1) add your bifs to erts/emulator/beam/bif.tab 1) add your bifs to erts/emulator/beam/bif.tab
- +<code>
-e.g.+
bif re:grep/2 bif re:grep/2
bif re:compile/1 bif re:compile/1
 +</code>
2) create a C file 2) create a C file
- +<code>
-e.g.+
erts/emulator/beam/erl_bif_re.c erts/emulator/beam/erl_bif_re.c
- +</code>
3) add your C file to erts/emulator/<arch>/Makefile 3) add your C file to erts/emulator/<arch>/Makefile
- +<code>
-e.g.+
RUN_OBJS = $(OBJDIR)/erl_bif_re.o \ RUN_OBJS = $(OBJDIR)/erl_bif_re.o \
- +</code>
4) implement your bifs by stealing bits from existing erl_bif_*.c files 4) implement your bifs by stealing bits from existing erl_bif_*.c files
- +<code>
-e.g.+
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>
5) run make; make install 5) run make; make install
Line 31: Line 28:
note that if you add note that if you add
 +<code>
bif re:grep/2 bif re:grep/2
- +</code>
to bif.tab there should be a to bif.tab there should be a
 +<code>
erl_bif_re.c erl_bif_re.c
- +</code>
that implements that implements
 +<code>
BIF_RETTYPE re_grep_2(BIF_ALIST_2); BIF_RETTYPE re_grep_2(BIF_ALIST_2);
 +</code>
 +[[Category:HowTo]]

Revision as of 15:54, 31 July 2006

0) run configure
1) add your bifs to erts/emulator/beam/bif.tab
bif re:grep/2
bif re:compile/1
2) create a C file
erts/emulator/beam/erl_bif_re.c
3) add your C file to erts/emulator/<arch>/Makefile
RUN_OBJS = $(OBJDIR)/erl_bif_re.o \
4) 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);
}
5) 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);
Erlang/OTP Projects
Personal tools