|
@@ -44,16 +44,18 @@ extern char *line_eof;
|
|
|
|
|
|
|
|
|
|
|
|
|
__arch_templ static int new_var(char *p, struct arch *);
|
|
__arch_templ static int new_var(char *p, struct arch *);
|
|
|
-__arch_templ static int set_name(char *p, struct arch *);
|
|
|
|
|
-__arch_templ static int math_set_name(char *p, struct arch *);
|
|
|
|
|
|
|
+__arch_templ static int set_name(char *p, struct arch *, long *out);
|
|
|
|
|
+__arch_templ static int math_set_name(char *p, struct arch *, long *out);
|
|
|
__arch_templ static int declare_object(char *p, struct arch *);
|
|
__arch_templ static int declare_object(char *p, struct arch *);
|
|
|
-__arch_templ static int interp_in_interp(char *p, struct arch *);
|
|
|
|
|
|
|
+__arch_templ static int interp_in_interp(char *p, struct arch *, long *out);
|
|
|
|
|
|
|
|
__arch_templ int cstyle_declare(char *p, struct arch *);
|
|
__arch_templ int cstyle_declare(char *p, struct arch *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
__arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
|
|
|
+ long ignored;
|
|
|
|
|
+
|
|
|
psave = p;
|
|
psave = p;
|
|
|
|
|
|
|
|
if (unlikely(p == line_eof))
|
|
if (unlikely(p == line_eof))
|
|
@@ -92,20 +94,20 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
|
case '`':
|
|
case '`':
|
|
|
/* running code in another interpreter */
|
|
/* running code in another interpreter */
|
|
|
|
|
|
|
|
- interp_in_interp(p, arch_fn);
|
|
|
|
|
|
|
+ interp_in_interp(p, arch_fn, &ignored);
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
case '+':
|
|
|
case '-':
|
|
case '-':
|
|
|
- if (!math_set_name(p, arch_fn))
|
|
|
|
|
|
|
+ if (!math_set_name(p, arch_fn, &ignored))
|
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
- if (unlikely(!set_name(p, arch_fn) &&
|
|
|
|
|
- !math_set_name(p, arch_fn) &&
|
|
|
|
|
|
|
+ if (unlikely(!set_name(p, arch_fn, &ignored) &&
|
|
|
|
|
+ !math_set_name(p, arch_fn, &ignored) &&
|
|
|
!cstyle_declare(p, arch_fn)))
|
|
!cstyle_declare(p, arch_fn)))
|
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
|
|
|
|
|
@@ -116,6 +118,7 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
struct klist_node *find_name(char *name) {
|
|
struct klist_node *find_name(char *name) {
|
|
|
struct klist_node *n;
|
|
struct klist_node *n;
|
|
|
|
|
|
|
@@ -192,8 +195,24 @@ __arch_templ static int new_var(char *p, struct arch *arch_fn) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int getrightvalue(char *p, struct arch *arch_fn) {
|
|
|
|
|
+ long res;
|
|
|
|
|
+
|
|
|
|
|
+ if (*p == '`') {
|
|
|
|
|
+ if (!interp_in_interp(p, arch_fn, &res))
|
|
|
|
|
+ /* actually, it never be here */
|
|
|
|
|
+ exit(generic_error("invalid right-value", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else if (!set_name(p, arch_fn, &res)
|
|
|
|
|
+ && !math_set_name(p, arch_fn, &res))
|
|
|
|
|
+ exit(generic_error("invalid right-value", psave, lno));
|
|
|
|
|
|
|
|
-static int set_name(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
+ return res;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static int set_name(char *p, struct arch *arch_fn, long *res) {
|
|
|
char *name;
|
|
char *name;
|
|
|
int type, out;
|
|
int type, out;
|
|
|
|
|
|
|
@@ -217,12 +236,13 @@ static int set_name(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
|
getword(p, &type, &out);
|
|
getword(p, &type, &out);
|
|
|
|
|
|
|
|
- if (unlikely(type != WORDTYPE_NR))
|
|
|
|
|
- exit(generic_error("a number required", psave, lno));
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (type != WORDTYPE_NR)
|
|
|
|
|
+ out = getrightvalue(p, arch_fn);
|
|
|
|
|
|
|
|
arch_fn->arch_set_var(name, out, 0);
|
|
arch_fn->arch_set_var(name, out, 0);
|
|
|
|
|
|
|
|
|
|
+ *res = out;
|
|
|
|
|
+
|
|
|
free(name);
|
|
free(name);
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -231,9 +251,10 @@ static int set_name(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-/* 9 -> a; */
|
|
|
|
|
|
|
+/* 9 -> a; and warning that math_set_name doesn't support instructions
|
|
|
|
|
+ * such as 'a = 0 -> b' */
|
|
|
|
|
|
|
|
-static int math_set_name(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
+static int math_set_name(char *p, struct arch *arch_fn, long *res) {
|
|
|
char *name;
|
|
char *name;
|
|
|
int type, out, nr;
|
|
int type, out, nr;
|
|
|
|
|
|
|
@@ -268,6 +289,7 @@ static int math_set_name(char *p, struct arch *arch_fn) {
|
|
|
name = strndup(p, out);
|
|
name = strndup(p, out);
|
|
|
|
|
|
|
|
arch_fn->arch_set_var(name, nr, 0);
|
|
arch_fn->arch_set_var(name, nr, 0);
|
|
|
|
|
+ *res = nr;
|
|
|
|
|
|
|
|
free(name);
|
|
free(name);
|
|
|
|
|
|
|
@@ -497,7 +519,7 @@ static int iini_run(char *interp_path, char *code) {
|
|
|
if (WIFEXITED(stat))
|
|
if (WIFEXITED(stat))
|
|
|
printf("%s exited normally with status %d\n", interp_path, WEXITSTATUS(stat));
|
|
printf("%s exited normally with status %d\n", interp_path, WEXITSTATUS(stat));
|
|
|
|
|
|
|
|
- else if (WIFSIGNALED(stat))
|
|
|
|
|
|
|
+ else if (WIFSIGNALED(stat)) {
|
|
|
error("%s terminated by signal %d%s\n", interp_path, WTERMSIG(stat),
|
|
error("%s terminated by signal %d%s\n", interp_path, WTERMSIG(stat),
|
|
|
|
|
|
|
|
#ifdef WCOREDUMP
|
|
#ifdef WCOREDUMP
|
|
@@ -505,15 +527,18 @@ static int iini_run(char *interp_path, char *code) {
|
|
|
#else
|
|
#else
|
|
|
""
|
|
""
|
|
|
#endif
|
|
#endif
|
|
|
- );
|
|
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ exit(generic_error("interp-in-interp failed", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return WEXITSTATUS(stat);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-static int interp_in_interp(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
+static int interp_in_interp(char *p, struct arch *arch_fn, long *res) {
|
|
|
int type, out;
|
|
int type, out;
|
|
|
char *interp, *code, *end;
|
|
char *interp, *code, *end;
|
|
|
|
|
|
|
@@ -550,7 +575,7 @@ static int interp_in_interp(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
|
/* now let's do something interesting */
|
|
/* now let's do something interesting */
|
|
|
|
|
|
|
|
- iini_run(interp, code);
|
|
|
|
|
|
|
+ *res = iini_run(interp, code);
|
|
|
|
|
|
|
|
free(code);
|
|
free(code);
|
|
|
free(interp);
|
|
free(interp);
|
|
@@ -560,7 +585,7 @@ static int interp_in_interp(char *p, struct arch *arch_fn) {
|
|
|
/* this, parse_line will not bark. */
|
|
/* this, parse_line will not bark. */
|
|
|
line_buffer = end;
|
|
line_buffer = end;
|
|
|
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|