Skip to content

Commit 4c7e4c9

Browse files
author
Sebastien Bourdeauducq
committedNov 24, 2011
fpvm: new fpvm_set_bind_callback API
1 parent 81eddbd commit 4c7e4c9

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
 

‎software/include/fpvm/fpvm.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ struct fpvm_tbinding {
4949
char sym[FPVM_MAXSYMLEN];
5050
};
5151

52+
typedef void (*fpvm_bind_callback)(void *, const char *, int);
53+
5254
struct fpvm_fragment {
5355
char last_error[FPVM_MAXERRLEN];
56+
fpvm_bind_callback bind_callback;
57+
void *bind_callback_user;
58+
5459
/* A binding is a link between the FPVM and the user,
5560
* made by permanently allocating a given register for the user.
5661
* Constants fall in this category because they need to be initialized
@@ -93,6 +98,7 @@ struct fpvm_fragment {
9398
const char *fpvm_version();
9499

95100
void fpvm_init(struct fpvm_fragment *fragment, int vector_mode);
101+
void fpvm_set_bind_callback(struct fpvm_fragment *fragment, fpvm_bind_callback callback, void *user);
96102

97103
int fpvm_bind(struct fpvm_fragment *fragment, const char *sym);
98104
void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym);

‎software/libfpvm/fpvm.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const char *fpvm_version()
3333
void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
3434
{
3535
fragment->last_error[0] = 0;
36+
fragment->bind_callback = NULL;
37+
fragment->bind_callback_user = NULL;
3638

3739
fragment->nbindings = 3;
3840
fragment->bindings[0].isvar = 1;
@@ -70,15 +72,26 @@ void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
7072
fragment->vector_mode = vector_mode;
7173
}
7274

75+
void fpvm_set_bind_callback(struct fpvm_fragment *fragment, fpvm_bind_callback callback, void *user)
76+
{
77+
fragment->bind_callback = callback;
78+
fragment->bind_callback_user = user;
79+
}
80+
7381
int fpvm_bind(struct fpvm_fragment *fragment, const char *sym)
7482
{
83+
int r;
84+
7585
if(fragment->nbindings == FPVM_MAXBINDINGS) {
7686
snprintf(fragment->last_error, FPVM_MAXERRLEN, "Failed to allocate register for variable: %s", sym);
7787
return FPVM_INVALID_REG;
7888
}
79-
fragment->bindings[fragment->nbindings].isvar = 1;
80-
strcpy(fragment->bindings[fragment->nbindings].b.v, sym);
81-
return fragment->nbindings++;
89+
r = fragment->nbindings++;
90+
fragment->bindings[r].isvar = 1;
91+
strcpy(fragment->bindings[r].b.v, sym);
92+
if(fragment->bind_callback != NULL)
93+
fragment->bind_callback(fragment->bind_callback_user, sym, r);
94+
return r;
8295
}
8396

8497
void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym)

0 commit comments

Comments
 (0)
Please sign in to comment.