You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/language-reference/compilation.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Ceramic uses **whole-program compilation**. Starting from an entry-point source
9
9
10
10
### Entry Points
11
11
12
-
If the entry-point module contains a public symbol named `main`, it is passed to the `callMain` operator function. `callMain` is responsible for calling `main` with its command-line arguments. The instantiated `callMain(static main)` becomes the program's entry point and corresponds to the C ABI `main` symbol.
12
+
If the entry-point module contains a public symbol named `main`, it is passed to the `callMain` operator function. `callMain` is responsible for calling `main` with its command-line arguments. The instantiated `callMain(#main)` becomes the program's entry point and corresponds to the C ABI `main` symbol.
13
13
14
14
For a `main` entry point, the `setArgcArgv(argc:Int32, argv:Pointer[Pointer[Int8]])` operator function is also instantiated. It is called with the `argc` and `argv` parameters from the C `main` function before `callMain` runs.
All arithmetic operators are left-associative within their precedence group.
193
193
194
194
### Comparison Operators
195
195
196
-
| Operator | Desugars to |
197
-
|----------|-------------|
198
-
|`a <= b`|`lesserEquals?(a, b)`|
199
-
|`a < b`|`lesser?(a, b)`|
200
-
|`a > b`|`greater?(a, b)`|
196
+
| Operator | Desugars to |
197
+
|--------| ---------------------- |
198
+
|`a <= b`|`lesserEquals?(a, b)`|
199
+
|`a < b`|`lesser?(a, b)`|
200
+
|`a > b`|`greater?(a, b)`|
201
201
|`a >= b`|`greaterEquals?(a, b)`|
202
-
|`a == b`|`equals?(a, b)`|
203
-
|`a != b`|`notEquals?(a, b)`|
202
+
|`a == b`|`equals?(a, b)`|
203
+
|`a != b`|`notEquals?(a, b)`|
204
204
205
205
All comparison operators are left-associative within their precedence group.
206
206
207
+
### User-Defined Operators
208
+
209
+
Any sequence of the characters `= ! < > + - * / \ % ~ | &` forms a valid operator token. The sequences `<--`, `-->`, `=>`, `->`, `~>`, and `=` are reserved and cannot be used as operator names.
210
+
211
+
`a op b` desugars to `infixOperator(a, #op, b)`, which calls `op(a, b)` by default. `op a` desugars to `prefixOperator(#op, a)`, which calls `op(a)` by default. Declare the operator with `define` and provide an implementation with `overload`:
212
+
213
+
```ceramic
214
+
define (**);
215
+
overload (**)(base:Int32, exp:Int32) : Int32 {
216
+
var result = 1;
217
+
for (i in range(exp))
218
+
result *: base;
219
+
return result;
220
+
}
221
+
222
+
println(2 ** 10); // 1024
223
+
```
224
+
207
225
### Boolean Operators
208
226
209
-
| Operator | Behavior |
210
-
|----------|----------|
211
-
|`not a`| Complement. `a` must be `Bool`. Not overloadable |
212
-
|`a and b`| Short-circuit conjunction. Right-associative |
213
-
|`a or b`| Short-circuit disjunction. Right-associative |
|`not a`| Complement. `a` must be `Bool`. Not overloadable |
230
+
|`a and b`| Short-circuit conjunction. Right-associative |
231
+
|`a or b`| Short-circuit disjunction. Right-associative|
214
232
215
233
Both `and` and `or` require `Bool` operands and are not overloadable.
216
234
@@ -229,10 +247,10 @@ Both branches must have the same type. Unlike `if` statements, the `else` clause
229
247
230
248
#### Static Expressions
231
249
232
-
`static expr` evaluates `expr` at compile time and wraps the result in `Static[result]`. Used to pass compile-time values to [static arguments](functions.md#static-arguments). Applied to a symbol or static string, it is a no-op.
250
+
`#expr` evaluates `expr` at compile time and wraps the result in `Static[result]`. Used to pass compile-time values to [static arguments](functions.md#static-arguments). Applied to a symbol or static string, it is a no-op.
0 commit comments