Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fpvm: new fpvm_set_bind_callback API

  • Loading branch information...
commit 4c7e4c9f89efc80daae3f78a359addc54b2cdb23 1 parent 81eddbd
@sbourdeauducq sbourdeauducq authored
Showing with 22 additions and 3 deletions.
  1. +6 −0 software/include/fpvm/fpvm.h
  2. +16 −3 software/libfpvm/fpvm.c
View
6 software/include/fpvm/fpvm.h
@@ -49,8 +49,13 @@ struct fpvm_tbinding {
char sym[FPVM_MAXSYMLEN];
};
+typedef void (*fpvm_bind_callback)(void *, const char *, int);
+
struct fpvm_fragment {
char last_error[FPVM_MAXERRLEN];
+ fpvm_bind_callback bind_callback;
+ void *bind_callback_user;
+
/* A binding is a link between the FPVM and the user,
* made by permanently allocating a given register for the user.
* Constants fall in this category because they need to be initialized
@@ -93,6 +98,7 @@ struct fpvm_fragment {
const char *fpvm_version();
void fpvm_init(struct fpvm_fragment *fragment, int vector_mode);
+void fpvm_set_bind_callback(struct fpvm_fragment *fragment, fpvm_bind_callback callback, void *user);
int fpvm_bind(struct fpvm_fragment *fragment, const char *sym);
void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym);
View
19 software/libfpvm/fpvm.c
@@ -33,6 +33,8 @@ const char *fpvm_version()
void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
{
fragment->last_error[0] = 0;
+ fragment->bind_callback = NULL;
+ fragment->bind_callback_user = NULL;
fragment->nbindings = 3;
fragment->bindings[0].isvar = 1;
@@ -70,15 +72,26 @@ void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
fragment->vector_mode = vector_mode;
}
+void fpvm_set_bind_callback(struct fpvm_fragment *fragment, fpvm_bind_callback callback, void *user)
+{
+ fragment->bind_callback = callback;
+ fragment->bind_callback_user = user;
+}
+
int fpvm_bind(struct fpvm_fragment *fragment, const char *sym)
{
+ int r;
+
if(fragment->nbindings == FPVM_MAXBINDINGS) {
snprintf(fragment->last_error, FPVM_MAXERRLEN, "Failed to allocate register for variable: %s", sym);
return FPVM_INVALID_REG;
}
- fragment->bindings[fragment->nbindings].isvar = 1;
- strcpy(fragment->bindings[fragment->nbindings].b.v, sym);
- return fragment->nbindings++;
+ r = fragment->nbindings++;
+ fragment->bindings[r].isvar = 1;
+ strcpy(fragment->bindings[r].b.v, sym);
+ if(fragment->bind_callback != NULL)
+ fragment->bind_callback(fragment->bind_callback_user, sym, r);
+ return r;
}
void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym)
Please sign in to comment.
Something went wrong with that request. Please try again.