aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker2009-06-12 14:24:39 -0500
committerDoug Zongker2009-06-12 16:05:03 -0500
commitd9c9d10d9da76f067d3955bea71f7bb39e859fa5 (patch)
tree1e49a3a616c3147f871e79b1b15e2b2a63379cc1 /edify/expr.h
parent8edb00c990e563e6f91b278a212f2edf877cf763 (diff)
downloadplatform-bootable-recovery-d9c9d10d9da76f067d3955bea71f7bb39e859fa5.tar.gz
platform-bootable-recovery-d9c9d10d9da76f067d3955bea71f7bb39e859fa5.tar.xz
platform-bootable-recovery-d9c9d10d9da76f067d3955bea71f7bb39e859fa5.zip
fixes to edify and updater script
A few more changes to edify: - fix write_raw_image(); my last change neglected to close the write context, so the written image was corrupt. - each expression tracks the span of the source code from which it was compiled, so that assert()'s error message can include the source of the expression that failed. - the 'cookie' argument to each Function is replaced with a State object, which contains the cookie, the source script (for use with the above spans), and the current error message (replacing the global variables that were used for this purpose). - in the recovery image, a new command "ui_print" can be sent back through the command pipe to cause text to appear on the screen. Add a new ui_print() function to print things from scripts. Rename existing "print" function to "stdout".
Diffstat (limited to 'edify/expr.h')
-rw-r--r--edify/expr.h61
1 files changed, 40 insertions, 21 deletions
diff --git a/edify/expr.h b/edify/expr.h
index cfbef903..671b499b 100644
--- a/edify/expr.h
+++ b/edify/expr.h
@@ -17,45 +17,64 @@
17#ifndef _EXPRESSION_H 17#ifndef _EXPRESSION_H
18#define _EXPRESSION_H 18#define _EXPRESSION_H
19 19
20#include "yydefs.h"
21
20#define MAX_STRING_LEN 1024 22#define MAX_STRING_LEN 1024
21 23
22typedef struct Expr Expr; 24typedef struct Expr Expr;
23 25
24typedef char* (*Function)(const char* name, void* cookie, 26typedef struct {
27 // Optional pointer to app-specific data; the core of edify never
28 // uses this value.
29 void* cookie;
30
31 // The source of the original script. Must be NULL-terminated,
32 // and in writable memory (Evaluate may make temporary changes to
33 // it but will restore it when done).
34 char* script;
35
36 // The error message (if any) returned if the evaluation aborts.
37 // Should be NULL initially, will be either NULL or a malloc'd
38 // pointer after Evaluate() returns.
39 char* errmsg;
40} State;
41
42typedef char* (*Function)(const char* name, State* state,
25 int argc, Expr* argv[]); 43 int argc, Expr* argv[]);
26 44
27struct Expr { 45struct Expr {
28 Function fn; 46 Function fn;
29 char* name; 47 char* name;
30 int argc; 48 int argc;
31 Expr** argv; 49 Expr** argv;
50 int start, end;
32}; 51};
33 52
34char* Evaluate(void* cookie, Expr* expr); 53char* Evaluate(State* state, Expr* expr);
35 54
36// Glue to make an Expr out of a literal. 55// Glue to make an Expr out of a literal.
37char* Literal(const char* name, void* cookie, int argc, Expr* argv[]); 56char* Literal(const char* name, State* state, int argc, Expr* argv[]);
38 57
39// Functions corresponding to various syntactic sugar operators. 58// Functions corresponding to various syntactic sugar operators.
40// ("concat" is also available as a builtin function, to concatenate 59// ("concat" is also available as a builtin function, to concatenate
41// more than two strings.) 60// more than two strings.)
42char* ConcatFn(const char* name, void* cookie, int argc, Expr* argv[]); 61char* ConcatFn(const char* name, State* state, int argc, Expr* argv[]);
43char* LogicalAndFn(const char* name, void* cookie, int argc, Expr* argv[]); 62char* LogicalAndFn(const char* name, State* state, int argc, Expr* argv[]);
44char* LogicalOrFn(const char* name, void* cookie, int argc, Expr* argv[]); 63char* LogicalOrFn(const char* name, State* state, int argc, Expr* argv[]);
45char* LogicalNotFn(const char* name, void* cookie, int argc, Expr* argv[]); 64char* LogicalNotFn(const char* name, State* state, int argc, Expr* argv[]);
46char* SubstringFn(const char* name, void* cookie, int argc, Expr* argv[]); 65char* SubstringFn(const char* name, State* state, int argc, Expr* argv[]);
47char* EqualityFn(const char* name, void* cookie, int argc, Expr* argv[]); 66char* EqualityFn(const char* name, State* state, int argc, Expr* argv[]);
48char* InequalityFn(const char* name, void* cookie, int argc, Expr* argv[]); 67char* InequalityFn(const char* name, State* state, int argc, Expr* argv[]);
49char* SequenceFn(const char* name, void* cookie, int argc, Expr* argv[]); 68char* SequenceFn(const char* name, State* state, int argc, Expr* argv[]);
50 69
51// Convenience function for building expressions with a fixed number 70// Convenience function for building expressions with a fixed number
52// of arguments. 71// of arguments.
53Expr* Build(Function fn, int count, ...); 72Expr* Build(Function fn, YYLTYPE loc, int count, ...);
54 73
55// Global builtins, registered by RegisterBuiltins(). 74// Global builtins, registered by RegisterBuiltins().
56char* IfElseFn(const char* name, void* cookie, int argc, Expr* argv[]); 75char* IfElseFn(const char* name, State* state, int argc, Expr* argv[]);
57char* AssertFn(const char* name, void* cookie, int argc, Expr* argv[]); 76char* AssertFn(const char* name, State* state, int argc, Expr* argv[]);
58char* AbortFn(const char* name, void* cookie, int argc, Expr* argv[]); 77char* AbortFn(const char* name, State* state, int argc, Expr* argv[]);
59 78
60 79
61// For setting and getting the global error string (when returning 80// For setting and getting the global error string (when returning
@@ -91,13 +110,13 @@ Function FindFunction(const char* name);
91// Evaluate the expressions in argv, giving 'count' char* (the ... is 110// Evaluate the expressions in argv, giving 'count' char* (the ... is
92// zero or more char** to put them in). If any expression evaluates 111// zero or more char** to put them in). If any expression evaluates
93// to NULL, free the rest and return -1. Return 0 on success. 112// to NULL, free the rest and return -1. Return 0 on success.
94int ReadArgs(void* cookie, Expr* argv[], int count, ...); 113int ReadArgs(State* state, Expr* argv[], int count, ...);
95 114
96// Evaluate the expressions in argv, returning an array of char* 115// Evaluate the expressions in argv, returning an array of char*
97// results. If any evaluate to NULL, free the rest and return NULL. 116// results. If any evaluate to NULL, free the rest and return NULL.
98// The caller is responsible for freeing the returned array and the 117// The caller is responsible for freeing the returned array and the
99// strings it contains. 118// strings it contains.
100char** ReadVarArgs(void* cookie, int argc, Expr* argv[]); 119char** ReadVarArgs(State* state, int argc, Expr* argv[]);
101 120
102 121
103#endif // _EXPRESSION_H 122#endif // _EXPRESSION_H