summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/assembler.c86
-rw-r--r--lib/hash.c2
-rw-r--r--lib/meta.c2
3 files changed, 84 insertions, 6 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index 513a6be..34ee48a 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -969,6 +969,7 @@ static void evaluate(expression_t * e)
t = (expression_t *) Emalloc(sizeof(expression_t));
t->e_type = t->e_subtype = E_VALUE;
t->avalue = 0;
+ t->pattern = NULL;
t->next = t->child = NULL;
t->prev = e->child;
e->child->next = t;
@@ -986,6 +987,7 @@ void act_pile(int o)
int i, nbargs;
e = Emalloc(sizeof(expression_t));
+ e->pattern = NULL;
e->op = o;
e->avalue = 0;
e->symbol = NULL;
@@ -1133,7 +1135,7 @@ static void super_pattern(pattern_t * patterns, expression_t * e)
if (e->e_subtype == E_OPERATION) {
if (((e->op == OP_DIRECT) && (e->child->e_subtype == E_VALUE))
|| ((e->op == OP_DECAL)
- && (e->child->next->e_subtype = E_VALUE))) {
+ && (e->child->next->e_subtype == E_VALUE))) {
e->pattern = patterns;
e->index = i;
}
@@ -1322,6 +1324,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
t->e_type = t->e_subtype = E_VALUE;
t->avalue = e->index;
t->symbol = NULL;
+ t->pattern = NULL;
InsererVarDansTab(it, CreerElement(m->name, t));
free(t);
}
@@ -1346,6 +1349,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
}
pushdword(tv, e->child);
} else {
+ exception(1, _("Logical error in meta language"));
}
}
m = n;
@@ -1362,6 +1366,8 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
t = (expression_t *) Emalloc(sizeof(expression_t));
t->next = t->child = t->prev = t->father = NULL;
t->e_type = t->e_subtype = E_VALUE;
+ t->pattern = NULL;
+
if (e->child->next->e_subtype == E_PATTERN) {
t->avalue = e->child->next->index;
} else {
@@ -1392,6 +1398,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
t->e_type = t->e_subtype = E_VALUE;
t->avalue = e->child->index;
t->symbol = NULL;
+ t->pattern = NULL;
InsererVarDansTab(it, CreerElement(m->name, t));
free(t);
}
@@ -1401,11 +1408,49 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
}
}
+static int evaluate_field(_TableauVariable it, char * field, field_t * fields) {
+ int i, r, e, n;
+ char trouve;
+ expression_t * t;
+
+ for (fields = fields->next; fields; fields = fields->next) {
+ if (!strcmp(field + 1, fields->name)) {
+ break;
+ }
+ }
+
+ if (!(fields)) {
+ exception(1, _("Unknow field in metalanguage"));
+ }
+
+ r = 0;
+ n = 0;
+
+ for (i = 0; i < fields->nbr; i++) {
+ t = (expression_t *) NomVarToVar(fields->names[i], it, &trouve);
+ e = 0;
+ if (trouve) {
+ if (t->e_subtype == E_VALUE) {
+ exception(1, _("Can't evaluate directly expression"));
+ }
+ e = t->avalue;
+ }
+ n = fields->sizes[i];
+ if ((e & (n - 1)) != e) {
+ exception(1, _("Value too large for field"));
+ }
+ r = (r << n) | e;
+ }
+
+ return r;
+}
+
void asm_eol(void)
{
instruct_t *instr;
expression_t *t;
int i;
+ char trouve;
bytestream_t *pi;
_TableauVariable it;
@@ -1424,6 +1469,7 @@ void asm_eol(void)
fprintf(stderr, "Fin de ligne sur:\n");
debug_print_expression(e_line);
+ fprintf(stderr, "-----\n");
e_current = e_line;
/* Est-ce que le premier mot est un label terminant par ':' ? */
@@ -1448,6 +1494,7 @@ void asm_eol(void)
}
}
+
switch (e_current->e_subtype) {
case E_INTERNAL:
switch (e_current->op) {
@@ -1533,6 +1580,7 @@ void asm_eol(void)
t->e_type = t->e_subtype = E_VALUE;
t->avalue = e_current->index;
t->child = t->next = NULL;
+ t->pattern = NULL;
InsererVarDansTab(&it, CreerElement(instr->names[i], t));
free(t);
evaluate_pattern(&it, e_current);
@@ -1548,13 +1596,43 @@ void asm_eol(void)
e_current = e_line;
}
- fprintf(stderr, "Variables explicites:\n");
+ for (i = 0; i < instr->nbimplicit; i++) {
+ switch(instr->itypes[i]) {
+ case 0: /* type direct */
+ t = (expression_t *) NomVarToVar(instr->istrings[i], it, &trouve);
+ if (!trouve) {
+ exception(1, _("Syntax error in meta language"));
+ }
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
+ break;
+ case 1: /* type prédéfinit */
+ t = (expression_t *) Emalloc(sizeof(expression_t));
+ t->e_type = t->e_subtype = E_VALUE;
+ if (instr->istrings[i][0] != 'F') {
+ exception(1, _("Logical error in meta language"));
+ }
+ t->avalue = evaluate_field(it, instr->istrings[i], fields);;
+ t->child = t->next = NULL;
+ t->pattern = NULL;
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
+ break;
+ case 2: /* type valeur */
+ t = (expression_t *) Emalloc(sizeof(expression_t));
+ t->e_type = t->e_subtype = E_VALUE;
+ t->avalue = instr->ivalues[i];
+ t->child = t->next = NULL;
+ t->pattern = NULL;
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
+ break;
+ }
+ }
+
+ fprintf(stderr, "Variables\n");
AfficheTableau(it);
+ pushdword(evaluate_field(it, "FI", fields), NULL);
DetruitTab(&it);
-
-
break;
default:
exception(1, _("Unknow instruction"));
diff --git a/lib/hash.c b/lib/hash.c
index bd406c8..6d890f7 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -140,7 +140,7 @@ _TypeVariable NomVarToVar(char *Nom, _TableauVariable t, char *trouve)
void AfficheListe(_ListeChaine l)
{
while (l != NULL) {
- printf("%s\n", l->Elem.NomVar);
+ fprintf(stderr, "%s\n", l->Elem.NomVar);
l = l->Suivant;
}
}
diff --git a/lib/meta.c b/lib/meta.c
index 0bc6f48..be13434 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -617,7 +617,7 @@ void main(void)
instruct->istrings[i]);
break;
case 1:
- fprintf(stderr, " + %s <= %i (type prédéfinit)\n", instruct->implicits[i],
+ fprintf(stderr, " + %s <= %s (type prédéfinit)\n", instruct->implicits[i],
instruct->istrings[i]);
break;
case 2: