Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fpvm: new fpvm_set_bind_callback API

  • Loading branch information...
commit 4c7e4c9f89efc80daae3f78a359addc54b2cdb23 1 parent 81eddbd
Sébastien Bourdeauducq authored
6  software/include/fpvm/fpvm.h
@@ -49,8 +49,13 @@ struct fpvm_tbinding {
49 49
 	char sym[FPVM_MAXSYMLEN];
50 50
 };
51 51
 
  52
+typedef void (*fpvm_bind_callback)(void *, const char *, int);
  53
+
52 54
 struct fpvm_fragment {
53 55
 	char last_error[FPVM_MAXERRLEN];
  56
+	fpvm_bind_callback bind_callback;
  57
+	void *bind_callback_user;
  58
+	
54 59
 	/* A binding is a link between the FPVM and the user,
55 60
 	 * made by permanently allocating a given register for the user.
56 61
 	 * Constants fall in this category because they need to be initialized
@@ -93,6 +98,7 @@ struct fpvm_fragment {
93 98
 const char *fpvm_version();
94 99
 
95 100
 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);
96 102
 
97 103
 int fpvm_bind(struct fpvm_fragment *fragment, const char *sym);
98 104
 void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym);
19  software/libfpvm/fpvm.c
@@ -33,6 +33,8 @@ const char *fpvm_version()
33 33
 void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
34 34
 {
35 35
 	fragment->last_error[0] = 0;
  36
+	fragment->bind_callback = NULL;
  37
+	fragment->bind_callback_user = NULL;
36 38
 
37 39
 	fragment->nbindings = 3;
38 40
 	fragment->bindings[0].isvar = 1;
@@ -70,15 +72,26 @@ void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
70 72
 	fragment->vector_mode = vector_mode;
71 73
 }
72 74
 
  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
+
73 81
 int fpvm_bind(struct fpvm_fragment *fragment, const char *sym)
74 82
 {
  83
+	int r;
  84
+	
75 85
 	if(fragment->nbindings == FPVM_MAXBINDINGS) {
76 86
 		snprintf(fragment->last_error, FPVM_MAXERRLEN, "Failed to allocate register for variable: %s", sym);
77 87
 		return FPVM_INVALID_REG;
78 88
 	}
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;
82 95
 }
83 96
 
84 97
 void fpvm_set_xin(struct fpvm_fragment *fragment, const char *sym)

0 notes on commit 4c7e4c9

Please sign in to comment.
Something went wrong with that request. Please try again.