|
@@ -34,17 +34,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
char *psave;
|
|
char *psave;
|
|
|
|
|
+struct klist_node names_list = KLIST_NODE_INIT(&names_list);
|
|
|
|
|
+
|
|
|
|
|
+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 set_name(char *p, struct arch *);
|
|
|
__arch_templ static int math_set_name(char *p, struct arch *);
|
|
__arch_templ static int math_set_name(char *p, struct arch *);
|
|
|
-__arch_templ static int check_condition(char *p, struct arch *);
|
|
|
|
|
|
|
+__arch_templ static int declare_object(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) {
|
|
|
psave = p;
|
|
psave = p;
|
|
|
|
|
|
|
|
|
|
+ if (p == line_eof)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
switch (*p) {
|
|
switch (*p) {
|
|
|
case '$':
|
|
case '$':
|
|
|
/* '$ asdf = 0;' --- asdf = 0
|
|
/* '$ asdf = 0;' --- asdf = 0
|
|
@@ -67,8 +75,13 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
|
|
+ case '<':
|
|
|
|
|
+ declare_object(p, arch_fn);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
default:
|
|
default:
|
|
|
- if (set_name(p, arch_fn) + math_set_name(p, arch_fn) + check_condition(p, arch_fn) == 0)
|
|
|
|
|
|
|
+ if (set_name(p, arch_fn) + math_set_name(p, arch_fn) == 0)
|
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
exit(generic_error("unknow keyword", psave, lno));
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
@@ -219,4 +232,188 @@ static int math_set_name(char *p, struct arch *arch_fn) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
+ * 1.
|
|
|
|
|
+ * < "libfoo.a" @ dynalib;
|
|
|
|
|
+ * 2.
|
|
|
|
|
+ * < fn @ fn;
|
|
|
|
|
+ *
|
|
|
|
|
+ * 3.
|
|
|
|
|
+ * < fn 2 @ fn;
|
|
|
|
|
+ *
|
|
|
|
|
+ * 4.
|
|
|
|
|
+ * < fn (a, b) @ fn;
|
|
|
|
|
+ *
|
|
|
|
|
+ * 5.
|
|
|
|
|
+ * < age @ var;
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
|
|
+static int declare_object(char *p, struct arch *arch_fn) {
|
|
|
|
|
+ char *name;
|
|
|
|
|
+ int type, out, attr;
|
|
|
|
|
+
|
|
|
|
|
+ enum { SHARED, NAMES, FUNCTION } guess;
|
|
|
|
|
+ struct klist_node *n;
|
|
|
|
|
+
|
|
|
|
|
+ /* skip '<' */
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!getword(p, &type, &out))
|
|
|
|
|
+ exit(generic_error("a module name or object name required", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case WORDTYPE_STR:
|
|
|
|
|
+ /* it must be a dynamic library */
|
|
|
|
|
+
|
|
|
|
|
+ name = strndup(p + 1, out);
|
|
|
|
|
+ guess = SHARED;
|
|
|
|
|
+
|
|
|
|
|
+ if (arch_fn->arch_import_shared)
|
|
|
|
|
+ arch_fn->arch_import_shared(name);
|
|
|
|
|
+
|
|
|
|
|
+ p += out + 2;
|
|
|
|
|
+
|
|
|
|
|
+ free(name);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case WORDTYPE_NAME:
|
|
|
|
|
+ /* functions or variables */
|
|
|
|
|
+
|
|
|
|
|
+ name = strndup(p, out);
|
|
|
|
|
+
|
|
|
|
|
+ /* join to the name list */
|
|
|
|
|
+
|
|
|
|
|
+ n = malloc(sizeof(struct klist_node));
|
|
|
|
|
+ klist_init(n);
|
|
|
|
|
+
|
|
|
|
|
+ n->payload = name;
|
|
|
|
|
+ klist_add(&names_list, n);
|
|
|
|
|
+
|
|
|
|
|
+ guess = NAMES;
|
|
|
|
|
+
|
|
|
|
|
+ p += out;
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ exit(generic_error("invalid type for '<'", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ if (guess == SHARED)
|
|
|
|
|
+ goto skip;
|
|
|
|
|
+
|
|
|
|
|
+ /* try to getword */
|
|
|
|
|
+
|
|
|
|
|
+ getword(p, &type, &out);
|
|
|
|
|
+
|
|
|
|
|
+ if (type == WORDTYPE_KWORD && out == '@')
|
|
|
|
|
+ goto skip;
|
|
|
|
|
+
|
|
|
|
|
+ /* can just be a function define */
|
|
|
|
|
+
|
|
|
|
|
+ guess = FUNCTION;
|
|
|
|
|
+
|
|
|
|
|
+ if (type == WORDTYPE_NR) {
|
|
|
|
|
+ /* only number of arguments */
|
|
|
|
|
+ if (!out)
|
|
|
|
|
+ /* special case */
|
|
|
|
|
+ n->value = DECLARE_NOARG;
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ n->value = out;
|
|
|
|
|
+
|
|
|
|
|
+ _skip_word(p);
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ goto skip;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* argument list */
|
|
|
|
|
+
|
|
|
|
|
+ if (type == WORDTYPE_KWORD && out == '(') {
|
|
|
|
|
+ n->value = 0;
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ for (;;) {
|
|
|
|
|
+ if (!getword(p, &type, &out))
|
|
|
|
|
+ /* end but no ')' */
|
|
|
|
|
+ exit(generic_error("argument list terminated with no ')'", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case WORDTYPE_KWORD:
|
|
|
|
|
+ if (out != ')' && out != ',')
|
|
|
|
|
+ exit(generic_error("invalid operators between arguments", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+ if (out == ')') {
|
|
|
|
|
+ if (!n->value)
|
|
|
|
|
+ n->value = DECLARE_NOARG;
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ goto skip;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case WORDTYPE_NAME:
|
|
|
|
|
+ n->value++;
|
|
|
|
|
+
|
|
|
|
|
+ p += out;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ exit(generic_error("invalid type between arguments", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!n->value)
|
|
|
|
|
+ n->value = DECLARE_NOARG;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+skip: attr = getattrmask(p, declare_attrtab);
|
|
|
|
|
+
|
|
|
|
|
+ if (!attr && guess != SHARED)
|
|
|
|
|
+ exit(generic_error("you must give attributes for declares", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+ if (guess != SHARED) {
|
|
|
|
|
+ if (attr & 2)
|
|
|
|
|
+ n->value |= DECLARE_FN;
|
|
|
|
|
+
|
|
|
|
|
+ else if (attr & 4) {
|
|
|
|
|
+ if (guess == FUNCTION)
|
|
|
|
|
+ exit(generic_error("you gave us a function declare but told us this is a variable declare? ",
|
|
|
|
|
+ psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+ /* variable */
|
|
|
|
|
+ n->value = DECLARE_VAR;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ exit(generic_error("one of 'fn' or 'var' must be gave", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|