summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2018-12-06 10:56:32 +0000
committeraiju <devnull@localhost>2018-12-06 10:56:32 +0000
commit4415dde6d3345b21d49848fd7e76b2860f58512e (patch)
tree354fb80977b95e883d2939306285ff762c9b1e5d
parent023f5eca58471db968aee3de7729c1c9b0540952 (diff)
forp: change indexing to verilog-like semantics
-rw-r--r--sys/man/1/forp5
-rw-r--r--sys/src/cmd/forp/cvt.c8
2 files changed, 7 insertions, 6 deletions
diff --git a/sys/man/1/forp b/sys/man/1/forp
index a0dcd3ab9..972d6a71e 100644
--- a/sys/man/1/forp
+++ b/sys/man/1/forp
@@ -89,8 +89,9 @@ Expressions can be formed just as in C, however when used in an expression, all
The valid operators are listed below, in decreasing precedence. Note that logical operations treat all non-zero values as 1, whereas bitwise operators operate on all bits independently.
.TP "\w'\fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR 'u"
\fL[]\fR
-Array indexing. The syntax is \fIvar\fL[\fIidx\fL:\fIn\fR] to address \fIn\fR bits with the least-significant bit at \fIidx\fR.
-Omiting \fL:\fIn\fR addresses a single bit.
+Array indexing. The syntax is \fIvar\fL[\fIa\fL:\fIb\fR], with \fIa\fR denoting the MSB and \fIb\fR denoting the LSB.
+Omiting \fL:\fIb\fR addresses a single bit.
+The result is always treated as unsigned.
.TP
\fL!\fR, \fL~\fR, \fL+\fR, \fL-\fR
(Unary operators) Logical and bitwise "not", unary plus (no-op), arithmetic negation. Because of promotion, \fL~\fR and \fL-\fR operate beyond the width of variables.
diff --git a/sys/src/cmd/forp/cvt.c b/sys/src/cmd/forp/cvt.c
index f0b9308fd..86fb7a92e 100644
--- a/sys/src/cmd/forp/cvt.c
+++ b/sys/src/cmd/forp/cvt.c
@@ -251,9 +251,9 @@ opidx(Node *rn, Node *n1, Node *n2, Node *n3)
{
int i, j, k, s;
- j = mptoi(n2->num);
- if(n3 == nil) k = j;
- else k = mptoi(n3->num);
+ k = mptoi(n2->num);
+ if(n3 == nil) j = k;
+ else j = mptoi(n3->num);
if(j > k){
nodevars(rn, 1);
return;
@@ -492,7 +492,7 @@ convert(Node *n, uint sz)
case ASTIDX:
if(n->n2->type != ASTNUM || n->n3 != nil && n->n3->type != ASTNUM)
error(n, "non-constant in indexing expression");
- convert(n->n1, (n->n3 != nil ? mptoi(n->n3->num) : mptoi(n->n2->num)) + 1);
+ convert(n->n1, n->n3 != nil ? mptoi(n->n3->num) - mptoi(n->n2->num) + 1 : 1);
opidx(n, n->n1, n->n2, n->n3);
break;
case ASTTERN: