changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: forp: change indexing to verilog-like semantics

changeset 6943: a62d8d9eda33
parent 6942: b76d6262d1e3
child 6944: d7b5eba4bbc4
author: aiju
date: Thu, 06 Dec 2018 10:56:32 +0000
files: sys/man/1/forp sys/src/cmd/forp/cvt.c
description: forp: change indexing to verilog-like semantics
     1.1--- a/sys/man/1/forp
     1.2+++ b/sys/man/1/forp
     1.3@@ -89,8 +89,9 @@ Expressions can be formed just as in C, 
     1.4 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.
     1.5 .TP "\w'\fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR  'u"
     1.6 \fL[]\fR
     1.7-Array indexing. The syntax is \fIvar\fL[\fIidx\fL:\fIn\fR] to address \fIn\fR bits with the least-significant bit at \fIidx\fR.
     1.8-Omiting \fL:\fIn\fR addresses a single bit.
     1.9+Array indexing. The syntax is \fIvar\fL[\fIa\fL:\fIb\fR], with \fIa\fR denoting the MSB and \fIb\fR denoting the LSB.
    1.10+Omiting \fL:\fIb\fR addresses a single bit.
    1.11+The result is always treated as unsigned.
    1.12 .TP
    1.13 \fL!\fR, \fL~\fR, \fL+\fR, \fL-\fR
    1.14 (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.
     2.1--- a/sys/src/cmd/forp/cvt.c
     2.2+++ b/sys/src/cmd/forp/cvt.c
     2.3@@ -251,9 +251,9 @@ opidx(Node *rn, Node *n1, Node *n2, Node
     2.4 {
     2.5 	int i, j, k, s;
     2.6 	
     2.7-	j = mptoi(n2->num);
     2.8-	if(n3 == nil) k = j;
     2.9-	else k = mptoi(n3->num);
    2.10+	k = mptoi(n2->num);
    2.11+	if(n3 == nil) j = k;
    2.12+	else j = mptoi(n3->num);
    2.13 	if(j > k){
    2.14 		nodevars(rn, 1);
    2.15 		return;
    2.16@@ -492,7 +492,7 @@ convert(Node *n, uint sz)
    2.17 	case ASTIDX:
    2.18 		if(n->n2->type != ASTNUM || n->n3 != nil && n->n3->type != ASTNUM)
    2.19 			error(n, "non-constant in indexing expression");
    2.20-		convert(n->n1, (n->n3 != nil ? mptoi(n->n3->num) : mptoi(n->n2->num)) + 1);
    2.21+		convert(n->n1, n->n3 != nil ? mptoi(n->n3->num) - mptoi(n->n2->num) + 1 : 1);
    2.22 		opidx(n, n->n1, n->n2, n->n3);
    2.23 		break;
    2.24 	case ASTTERN: