Adding my own BIF
From Erlang Community
(Difference between revisions)
| Revision as of 15:44, 31 July 2006 (edit) Massemanet (Talk | contribs) (How to add a new bif to the emulator) ← Previous diff |
Revision as of 15:45, 31 July 2006 (edit) (undo) Massemanet (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| - | |||
| 0) run configure | 0) run configure | ||
| Line 5: | Line 4: | ||
| e.g. | e.g. | ||
| + | { | ||
| bif re:grep/2 | bif re:grep/2 | ||
| bif re:compile/1 | bif re:compile/1 | ||
| - | + | } | |
| 2) create a C file | 2) create a C file | ||
Revision as of 15:45, 31 July 2006
0) run configure
1) add your bifs to erts/emulator/beam/bif.tab
e.g. { bif re:grep/2 bif re:compile/1 } 2) create a C file
e.g. erts/emulator/beam/erl_bif_re.c
3) add your C file to erts/emulator/<arch>/Makefile
e.g. RUN_OBJS = $(OBJDIR)/erl_bif_re.o \
4) implement your bifs by stealing bits from existing erl_bif_*.c files
e.g. 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);

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

