Skip to content

Commit

Permalink
Merge pull request #9 from n7space/feature-TMC#144-floats-in-channels
Browse files Browse the repository at this point in the history
Feature tmc#144 floats in channels
  • Loading branch information
Lurkerpas authored Oct 14, 2022
2 parents 9385fc9 + e13f22a commit cac9f12
Show file tree
Hide file tree
Showing 45 changed files with 42,335 additions and 233 deletions.
12 changes: 10 additions & 2 deletions Src/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,16 @@ valid_name(Lextok *a3, Lextok *a5, Lextok *a8, char *tp)
|| a3->sym->isarray != 0)
{ fatal("bad index in for-construct %s", a3->sym->name);
}
if (a5->ntyp == CONST && a8->ntyp == CONST && a5->val > a8->val) // TODO: PG - validate CONST type? should be INT?
{ non_fatal("start value for %s exceeds end-value", a3->sym->name);
if (a5->ntyp == CONST && a8->ntyp == CONST)
{
if (a5->constValKind == VALUE_INT && a8->constValKind == VALUE_INT)
{
if (a5->val > a8->val)
{ non_fatal("start value for %s exceeds end-value", a3->sym->name);
}
}
else
fatal("Floats not handled in %s", a3->sym->name);
}
}

Expand Down
98 changes: 68 additions & 30 deletions Src/mesg.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ static int sa_snd(Queue *, Lextok *);
static int s_snd(Queue *, Lextok *);
extern Lextok **find_mtype_list(const char *);
extern char *which_mtype(const char *);
extern void sr_buf(int, int, const char *);
extern void sr_mesg(FILE *, int, int, const char *);
void sr_buf(int, int, const char *);
void sr_mesg(FILE *, int, int, const char *);
void sr_mesg_value(FILE *, Value, int, const char *);
extern void putarrow(int, int);
static void sr_talk(Lextok *, int, char *, char *, int, Queue *);
static void sr_talk(Lextok *, Value, char *, char *, int, Queue *);

int
cnt_mpars(Lextok *n)
Expand Down Expand Up @@ -328,14 +329,14 @@ a_snd(Queue *q, Lextok *n)
{ mtype_ck(q->mtp[i+j], m->lft); /* 6.4.8 */
}
if ((verbose&16) && depth >= jumpsteps)
{ sr_talk(n, getInt(New), "Send ", "->", j, q); /* XXX j was i+j in 6.4.8 */
{ sr_talk(n, New, "Send ", "->", j, q); /* XXX j was i+j in 6.4.8 */
}
typ_ck(q->fld_width[i+j], Sym_typ(m->lft), "send");
}

if ((verbose&16) && depth >= jumpsteps)
{ for (i = j; i < q->nflds; i++)
{ sr_talk(n, 0, "Send ", "->", i, q);
{ sr_talk(n, intValue(0), "Send ", "->", i, q);
}
if (j < q->nflds)
{ printf("%3d: warning: missing params in send\n",
Expand Down Expand Up @@ -428,7 +429,7 @@ a_rcv(Queue *q, Lextok *n, int full)
{ if (columns && !full) /* was columns == 1 */
continue;
if ((verbose&8) && !Rvous && depth >= jumpsteps)
{ sr_talk(n, getInt(q->contents[i*q->nflds+j]),
{ sr_talk(n, (q->contents[i*q->nflds+j]),
(full && n->val < 2)?"Recv ":"[Recv] ", "<-", j, q);
}
if (!full)
Expand All @@ -449,7 +450,7 @@ a_rcv(Queue *q, Lextok *n, int full)
if ((!columns || full)
&& (verbose&8) && !Rvous && depth >= jumpsteps)
for (i = j; i < q->nflds; i++)
{ sr_talk(n, 0,
{ sr_talk(n, intValue(0),
(full && n->val < 2)?"Recv ":"[Recv] ", "<-", i, q);
}
if (columns == 2 && full && !Rvous && depth >= jumpsteps)
Expand All @@ -464,7 +465,8 @@ static int
s_snd(Queue *q, Lextok *n)
{ Lextok *m;
RunList *rX, *sX = X_lst; /* rX=recvr, sX=sendr */
int i, j = 0; /* q field# */
int j = 0; /* q field# */
Value i;

for (m = n->rgt; m && j < q->nflds; m = m->rgt, j++)
{ q->contents[j] = cast_val(q->fld_width[j], evalValue(m->lft), 0);
Expand All @@ -489,11 +491,11 @@ s_snd(Queue *q, Lextok *n)
rX = X_lst; X_lst = sX;

for (j = 0; m && j < q->nflds; m = m->rgt, j++)
{ sr_talk(n, eval(m->lft), "Sent ", "->", j, q);
{ sr_talk(n, evalValue(m->lft), "Sent ", "->", j, q);
}

for (i = j; i < q->nflds; i++)
{ sr_talk(n, 0, "Sent ", "->", i, q);
int tmp;
for (tmp = j; tmp < q->nflds; tmp++)
{ sr_talk(n, intValue(0), "Sent ", "->", tmp, q);
}

if (j < q->nflds)
Expand All @@ -517,16 +519,17 @@ s_snd(Queue *q, Lextok *n)

if (m->lft->ntyp != NAME
|| strcmp(m->lft->sym->name, "_") != 0)
{ i = eval(m->lft);
{ i = evalValue(m->lft);
} else
{ i = 0;
{ i = intValue(0);
}
if (verbose&8)
sr_talk(n_rem,i,"Recv ","<-",j,q_rem);
sr_talk(n_rem,i,"Recv ","<-",j,q_rem);
}
if (verbose&8)
for (i = j; i < q->nflds; i++)
sr_talk(n_rem, 0, "Recv ", "<-", j, q_rem);

for (tmp = j; tmp < q->nflds; tmp++)
sr_talk(n_rem, intValue(0), "Recv ", "<-", j, q_rem);
if (columns == 2)
putarrow(depth, depth);
}
Expand Down Expand Up @@ -612,7 +615,7 @@ docolumns(Lextok *n, char *tr, int v, int j, Queue *q)
} else
printf(",");
if (tr[0] == '[') printf("[");
sr_mesg(stdout, v, q->fld_width[j] == MTYPE, q->mtp[j]);
sr_mesg(stdout, v, q->fld_width[j] == MTYPE, q->mtp[j]); // TODO PG - find proper scenario to activate and verify
if (j == q->nflds - 1)
{ if (tr[0] == '[') printf("]");
printf("\n");
Expand All @@ -637,25 +640,38 @@ qishidden(int q)
}

static void
sr_talk(Lextok *n, int v, char *tr, char *a, int j, Queue *q)
sr_talk(Lextok *n, Value v, char *tr, char *a, int j, Queue *q)
{ char s[128];

if (qishidden(eval(n->lft)))
return;

if (columns)
{ if (columns == 2)
difcolumns(n, tr, v, j, q);
difcolumns(n, tr, getInt(v), j, q); // TODO PG - handle Value in v
else
docolumns(n, tr, v, j, q);
docolumns(n, tr, getInt(v), j, q);
return;
}
if (xspin)
{ if ((verbose&4) && tr[0] != '[')
sprintf(s, "(state -)\t[values: %d",
eval(n->lft));
{
Value val = evalValue(n->lft);
if (val.kind == VALUE_FLOAT)
sprintf(s, "(state -)\t[values: %f",
val.value.floatValue);
else
sprintf(s, "(state -)\t[values: %d",
val.value.intValue);
}
else
sprintf(s, "(state -)\t[%d", eval(n->lft));
{
Value val = evalValue(n->lft);
if (val.kind == VALUE_FLOAT)
sprintf(s, "(state -)\t[%f", val.value.floatValue);
else
sprintf(s, "(state -)\t[%d", val.value.intValue);
}
if (strncmp(tr, "Sen", 3) == 0)
strcat(s, "!");
else
Expand All @@ -682,7 +698,7 @@ sr_talk(Lextok *n, int v, char *tr, char *a, int j, Queue *q)
} else
{ printf(",");
}
sr_mesg(stdout, v, q->fld_width[j] == MTYPE, q->mtp[j]);
sr_mesg_value(stdout, v, q->fld_width[j] == MTYPE, q->mtp[j]); // TODO PG - find scenario to activate and verify

if (j == q->nflds - 1)
{ if (xspin)
Expand All @@ -698,6 +714,8 @@ sr_talk(Lextok *n, int v, char *tr, char *a, int j, Queue *q)
fflush(stdout);
}

/* TODO sr_buf_f and sr_buf should be refactored
- however, more investigation needed on for loop meaning */
void
sr_buf_f(float v, int j, const char *s)
{ int cnt = 1; Lextok *n;
Expand Down Expand Up @@ -760,6 +778,26 @@ sr_mesg(FILE *fd, int v, int j, const char *s)
fprintf(fd, GBuf, (char *) 0); /* prevent compiler warning */
}

void
sr_mesg_const_token(FILE *fd, const Lextok *token, const char *s)
{ if (token->constValKind == VALUE_FLOAT)
sr_mesg_f(fd, getFloatTokenValue(token), token->ismtyp, s);
else
sr_mesg(fd, token->val, token->ismtyp, s);
}

void
sr_mesg_value(FILE *fd, const Value val, int isMTYPE, const char *s)
{ if (val.kind == VALUE_FLOAT)
{ sr_mesg_f(fd, val.value.floatValue,
isMTYPE, s);
}
else
{ sr_mesg(fd, val.value.intValue,
isMTYPE, s);
}
}

void
doq(Symbol *s, int n, RunList *r)
{ Queue *q;
Expand Down Expand Up @@ -790,13 +828,13 @@ doq(Symbol *s, int n, RunList *r)
}

for (k = 0; k < q->qlen; k++)
{ printf("[");
{ printf("["); // dumping of queue content
for (j = 0; j < q->nflds; j++)
{ if (j > 0) printf(",");
sr_mesg(stdout,
getInt(q->contents[k*q->nflds+j]), // TODO PG - handle float in queues?
q->fld_width[j] == MTYPE,
q->mtp[j]);
Value content = q->contents[k*q->nflds+j];
sr_mesg_value(stdout, content,
q->fld_width[j] == MTYPE,
q->mtp[j] );
}
printf("]");
}
Expand Down
19 changes: 14 additions & 5 deletions Src/pangen1.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,17 @@ c_chandump(FILE *fd)
{ fprintf(fd, ", 0");
}
} else
{ fprintf(fd, "\tprintf(\"%%d,\", %scontents[slot].fld%d",
{
if (q->fld_width[i] == FLOAT)
{
fprintf(fd, "\tprintf(\"%%f,\", %scontents[slot].fld%d",
buf, i);
}
else
{
fprintf(fd, "\tprintf(\"%%d,\", %scontents[slot].fld%d",
buf, i);
}
}
fprintf(fd, ");\n\t\t");
}
Expand Down Expand Up @@ -1403,7 +1412,7 @@ qlen_type(int qmax)
}

void
genaddqueue(void)
genaddqueue(void) // TODO PG - queues generation for pan
{ char buf0[256];
int j, qmax = 0;
Queue *q;
Expand Down Expand Up @@ -1517,8 +1526,8 @@ genaddqueue(void)

fprintf(fd_tc, "#if NQS>0\n");
fprintf(fd_tc, "void\nqsend(int into, int sorted");
for (j = 0; j < Mpars; j++)
fprintf(fd_tc, ", int fld%d", j);
for (j = 0; j < Mpars; j++)
fprintf(fd_tc, ", double fld%d", j); // TODO PG - apply proper type for each field - not necessary int
fprintf(fd_tc, ", int args_given)\n");
ntimes(fd_tc, 0, 1, Addq11);

Expand Down Expand Up @@ -1637,7 +1646,7 @@ genaddqueue(void)

fprintf(fd_th, "void qsend(int, int");
for (j = 0; j < Mpars; j++)
fprintf(fd_th, ", int");
fprintf(fd_th, ", double");
fprintf(fd_th, ", int);\n\n");

fprintf(fd_th, "#define Addproc(x,y) addproc(256, y, x");
Expand Down
32 changes: 16 additions & 16 deletions Src/pangen1.h
Original file line number Diff line number Diff line change
Expand Up @@ -6752,32 +6752,32 @@ static const char *Code2d[] = {
" stack = stack->lst;",
"}",

"typedef struct IntChunks {",
" int *ptr;",
" struct IntChunks *nxt;",
"} IntChunks;",
"IntChunks *filled_chunks[512];",
"IntChunks *empty_chunks[512];",

"int *",
"grab_ints(int nr)",
"{ IntChunks *z;",
" if (nr >= 512) Uerror(\"cannot happen grab_int\");",
"typedef struct ValueChunks {",
" double *ptr;",
" struct ValueChunks *nxt;",
"} ValueChunks;",
"ValueChunks *filled_chunks[512];",
"ValueChunks *empty_chunks[512];",

"double *",
"grab_values(int nr)",
"{ ValueChunks *z;",
" if (nr >= 512) Uerror(\"cannot happen grab_value\");",
" if (filled_chunks[nr])",
" { z = filled_chunks[nr];",
" filled_chunks[nr] = filled_chunks[nr]->nxt;",
" } else ",
" { z = (IntChunks *) emalloc(sizeof(IntChunks));",
" z->ptr = (int *) emalloc(nr * sizeof(int));",
" { z = (ValueChunks *) emalloc(sizeof(ValueChunks));",
" z->ptr = (double *) emalloc(nr * sizeof(double));",
" }",
" z->nxt = empty_chunks[nr];",
" empty_chunks[nr] = z;",
" return z->ptr;",
"}",
"void",
"ungrab_ints(int *p, int nr)",
"{ IntChunks *z;",
" if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_int\");",
"ungrab_values(double *p, int nr)",
"{ ValueChunks *z;",
" if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_value\");",
" z = empty_chunks[nr];",
" empty_chunks[nr] = empty_chunks[nr]->nxt;",
" z->ptr = p;",
Expand Down
Loading

0 comments on commit cac9f12

Please sign in to comment.