blob: 3967e8ea97e3d3a21bc4aeb2d6f2de771c09239b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
.TH MPC 1
.SH NAME
mpc \- extended precision arithmetic code generator
.SH SYNOPSIS
.B mpc
[
.I file ...
]
.SH DESCRIPTION
.I Mpc
generates C functions from a simple language that operates on
extended precision integers using the
.IR mp (2)
library.
.SH LANGUAGE
The language consists of a series of function definitions of the form:
.IP
.I name
(
.I "parameter list"
) {
.I statements
}
.PP
All variables and parameters are extended precision integers and are
passed by reference. Statements are separated by semicolon and the
following statemens are defined:
.IP
.I name
.B =
.I expression
.IP
.B if
(
.I condition
) {
.I statements
}
.B "else if"
(
.I condition
) {
.I statements
}
.B else
{
.I statements
}
.IP
.B while
(
.I condition
) {
.I statements
}
.IP
.B break
.IP
.I
name
(
.I "parameter list"
)
.IP
.B
mod
(
.I modulus
) {
.I statements
}
.PP
There is no distinction between input and output parameters, but
conventionally, the outputs are put at the end of the
.I "parameter list"
and the language allows one to write
.IP
.I F
(
.IR X ,
.IR Y ,
.I Z
)
as
.IR Y ,
.I Z
.B =
.I F
(
.I X
)
.PP
Expressions are composed out of the following arithmetic operations:
.RS
.TF _____________
.TP
.B +
addition.
.TP
.B -
subtraction.
.TP
.B *
multiplication.
.TP
.B /
division, or multiplicative inverse when enclosed in
.B mod
block.
.TP
.B %
division remainder.
.TP
.B ^
exponentiation.
.TP
.BI >> constant
right shift by a constant.
.TP
.BI << constant
left shift by a constant.
.TP
.IB condition ? a : b
pick
.I a
when
.I condition is true, otherwise
.I b
when false.
.RE
.PD
.PP
Conditions can use the following operations:
.RS
.TF _____________
.TP
.B ==
equality.
.TP
.B !=
inequality.
.TP
.B >
bigger than.
.TP
.B <
smaller than.
.TP
.BI ! condition
negation.
.RE
.SH SOURCE
.B /sys/src/cmd/mpc.y
.SH "SEE ALSO"
.IR mp (2)
|