Skip to content

Commit bc6eafe

Browse files
Merge pull request #79 from subrange/error-span-type
Update inline LLVM doc examples for opaque pointers
2 parents 88d11cd + 877692a commit bc6eafe

28 files changed

Lines changed: 306 additions & 270 deletions

File tree

compiler/CMakeLists.txt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,34 @@ add_executable(ceramicdoc ${CERAMICDOC_SOURCES})
6161
add_executable(ut ${UT_SOURCES})
6262

6363
# compiler flags
64-
target_compile_options(compiler PRIVATE ${LLVM_CXXFLAGS})
65-
target_compile_options(ceramic PRIVATE ${LLVM_CXXFLAGS})
66-
target_compile_options(ceramicdoc PRIVATE ${LLVM_CXXFLAGS})
67-
target_compile_options(ut PRIVATE ${LLVM_CXXFLAGS})
64+
target_compile_options(compiler PRIVATE ${LLVM_CXXFLAGS})
65+
target_compile_options(ceramic PRIVATE ${LLVM_CXXFLAGS})
66+
target_compile_options(ceramicdoc PRIVATE ${LLVM_CXXFLAGS})
67+
target_compile_options(ut PRIVATE ${LLVM_CXXFLAGS})
6868

6969
# include directories
70-
target_include_directories(compiler PRIVATE ${LLVM_INCLUDEDIR})
71-
target_include_directories(ceramic PRIVATE ${LLVM_INCLUDEDIR})
72-
target_include_directories(ceramicdoc PRIVATE ${LLVM_INCLUDEDIR})
73-
target_include_directories(ut PRIVATE ${LLVM_INCLUDEDIR})
70+
target_include_directories(compiler PRIVATE ${LLVM_INCLUDEDIR})
71+
target_include_directories(ceramic PRIVATE ${LLVM_INCLUDEDIR})
72+
target_include_directories(ceramicdoc PRIVATE ${LLVM_INCLUDEDIR})
73+
target_include_directories(ut PRIVATE ${LLVM_INCLUDEDIR})
7474

7575
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
76-
target_compile_definitions(compiler PRIVATE UNDEBUG)
77-
target_compile_definitions(ceramic PRIVATE UNDEBUG)
78-
target_compile_definitions(ceramicdoc PRIVATE UNDEBUG)
79-
target_compile_definitions(ut PRIVATE UNDEBUG)
76+
target_compile_definitions(compiler PRIVATE UNDEBUG)
77+
target_compile_definitions(ceramic PRIVATE UNDEBUG)
78+
target_compile_definitions(ceramicdoc PRIVATE UNDEBUG)
79+
target_compile_definitions(ut PRIVATE UNDEBUG)
8080
else()
81-
target_compile_definitions(compiler PRIVATE NDEBUG)
82-
target_compile_definitions(ceramic PRIVATE NDEBUG)
83-
target_compile_definitions(ceramicdoc PRIVATE NDEBUG)
84-
target_compile_definitions(ut PRIVATE NDEBUG)
81+
target_compile_definitions(compiler PRIVATE NDEBUG)
82+
target_compile_definitions(ceramic PRIVATE NDEBUG)
83+
target_compile_definitions(ceramicdoc PRIVATE NDEBUG)
84+
target_compile_definitions(ut PRIVATE NDEBUG)
8585
endif()
8686

8787
if(NOT MSVC)
88-
target_compile_options(compiler PRIVATE -fexceptions)
89-
target_compile_options(ceramic PRIVATE -fexceptions)
90-
target_compile_options(ceramicdoc PRIVATE -fexceptions)
91-
target_compile_options(ut PRIVATE -fexceptions)
88+
target_compile_options(compiler PRIVATE -fexceptions)
89+
target_compile_options(ceramic PRIVATE -fexceptions)
90+
target_compile_options(ceramicdoc PRIVATE -fexceptions)
91+
target_compile_options(ut PRIVATE -fexceptions)
9292
endif()
9393

9494
set(ENABLE_PCH False CACHE BOOL
@@ -99,21 +99,21 @@ if(ENABLE_PCH)
9999
endif(ENABLE_PCH)
100100

101101
if (UNIX)
102-
target_link_options(compiler PRIVATE ${LLVM_LDFLAGS})
103-
target_link_options(ceramic PRIVATE ${LLVM_LDFLAGS})
104-
target_link_options(ceramicdoc PRIVATE ${LLVM_LDFLAGS})
105-
target_link_options(ut PRIVATE ${LLVM_LDFLAGS})
102+
target_link_options(compiler PRIVATE ${LLVM_LDFLAGS})
103+
target_link_options(ceramic PRIVATE ${LLVM_LDFLAGS})
104+
target_link_options(ceramicdoc PRIVATE ${LLVM_LDFLAGS})
105+
target_link_options(ut PRIVATE ${LLVM_LDFLAGS})
106106
endif()
107107

108108
# Libraries
109-
target_link_libraries(ceramic PRIVATE compiler ${LLVM_LIBS})
110-
target_link_libraries(ceramicdoc PRIVATE compiler ${LLVM_LIBS})
111-
target_link_libraries(ut PRIVATE compiler ${LLVM_LIBS})
109+
target_link_libraries(ceramic PRIVATE compiler ${LLVM_LIBS})
110+
target_link_libraries(ceramicdoc PRIVATE compiler ${LLVM_LIBS})
111+
target_link_libraries(ut PRIVATE compiler ${LLVM_LIBS})
112112

113113
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
114-
target_link_libraries(ceramic PRIVATE rt dl pthread)
115-
target_link_libraries(ceramicdoc PRIVATE rt dl pthread)
116-
target_link_libraries(ut PRIVATE pthread)
114+
target_link_libraries(ceramic PRIVATE rt dl pthread)
115+
target_link_libraries(ceramicdoc PRIVATE rt dl pthread)
116+
target_link_libraries(ut PRIVATE pthread)
117117
endif()
118118

119119
# Install

compiler/analyzer_op.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,14 @@ MultiPValuePtr analyzePrimOp(PrimOpPtr x, MultiPValuePtr args) {
813813
ModulePtr m = staticModule(moduleObj);
814814
assert(m != nullptr);
815815

816-
MultiPValuePtr result = new MultiPValue();
816+
vector<llvm::StringRef> keys;
817+
for (auto const &entry : m->publicGlobals)
818+
keys.push_back(entry.getKey());
819+
std::sort(keys.begin(), keys.end());
817820

818-
for (llvm::StringMap<ObjectPtr>::const_iterator
819-
i = m->publicGlobals.begin(),
820-
end = m->publicGlobals.end();
821-
i != end; ++i) {
822-
result->add(staticPValue(Identifier::get(i->getKey())));
823-
}
821+
MultiPValuePtr result = new MultiPValue();
822+
for (auto const &key : keys)
823+
result->add(staticPValue(Identifier::get(key)));
824824
return result;
825825
}
826826

compiler/externals.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ llvm::FunctionType *ExternalFunction::getLLVMFunctionType() const {
5454
retType = retInfo.ext.type ? retInfo.ext.type : llvmType(retInfo.type);
5555
}
5656

57+
size_t argLimit =
58+
isVarArg ? std::min(numReqArg, argInfos.size()) : argInfos.size();
5759
for (vector<ArgInfo>::const_iterator it = argInfos.begin(),
58-
ie = argInfos.end();
60+
ie = argInfos.begin() + (long)argLimit;
5961
it != ie; ++it) {
6062
llvm::Type *type;
6163
if (it->ext.isIndirect()) {

doc/language-reference/compilation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Ceramic uses **whole-program compilation**. Starting from an entry-point source
99

1010
### Entry Points
1111

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.
1313

1414
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.
1515

@@ -38,8 +38,8 @@ define bar;
3838
3939
define pattern;
4040
[T]
41-
overload pattern(static T) { println("a"); }
42-
overload pattern(static bar) { println("b"); }
41+
overload pattern(#T) { println("a"); }
42+
overload pattern(#bar) { println("b"); }
4343
4444
testPattern() {
4545
pattern(foo); // prints a

doc/language-reference/expressions.md

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
Ceramic's expression hierarchy, from highest to lowest precedence:
44

5-
| Level | Forms | Operator functions |
6-
|-------|-------|--------------------|
7-
| Atomic | names, literals, `()`, `[]`, `__FILE__` etc., `eval` | (none) |
8-
| Suffix | `a(b)` `a[b]` `a.0` `a.field` `a^` | `call` `index` `staticIndex` `fieldRef` `dereference` |
9-
| Prefix | `+a` `-a` `&a` `*a` | `plus` `minus`, address and dispatch are primitive |
10-
| Multiplicative | `a*b` `a/b` `a%b` | `multiply` `divide` `remainder` |
11-
| Additive | `a+b` `a-b` | `add` `subtract` |
12-
| Ordered comparison | `<=` `<` `>` `>=` | `lesserEquals?` `lesser?` `greater?` `greaterEquals?` |
13-
| Equality | `==` `!=` | `equals?` `notEquals?` |
14-
| Boolean | `not a` `a and b` `a or b` | primitive, not overloadable |
15-
| Low-precedence prefix | `if (a) b else c`, `name: a`, `static a`, `..a`, `a -> b` | (none) |
16-
| Multiple value | `a, b, c` | (none) |
5+
| Level | Forms | Operator functions |
6+
| --------------------- | ---------------------------------------------------- | ----------------------------------------------------- |
7+
| Atomic | names, literals, `()`, `[]`, `__FILE__` etc., `eval` | (none) |
8+
| Suffix | `a(b)` `a[b]` `a.0` `a.field` `a^` | `call` `index` `staticIndex` `fieldRef` `dereference` |
9+
| Prefix | `+a` `-a` `&a` `*a` | `plus` `minus`, address and dispatch are primitive |
10+
| Multiplicative | `a*b` `a/b` `a%b` | `multiply` `divide` `remainder` |
11+
| Additive | `a+b` `a-b` | `add` `subtract` |
12+
| Ordered comparison | `<=` `<` `>` `>=` | `lesserEquals?` `lesser?` `greater?` `greaterEquals?` |
13+
| Equality | `==` `!=` | `equals?` `notEquals?` |
14+
| Boolean | `not a` `a and b` `a or b` | primitive, not overloadable |
15+
| Low-precedence prefix | `if (a) b else c`, `name: a`, `#a`, `..a`, `a -> b` | (none) |
16+
| Multiple value | `a, b, c` | (none) |
1717

1818
### Atomic Expressions
1919

@@ -42,14 +42,14 @@ foo(..xs:TT) {
4242

4343
#### Literal Expressions
4444

45-
| Literal | Default type | Type suffix examples |
46-
|---------|-------------|----------------------|
47-
| `true` / `false` | `Bool` | (none) |
48-
| `1`, `0xFF` | `Int32` (or module default) | `ss` `s` `i` `l` `ll` `uss` `us` `u` `ul` `ull` |
49-
| `1.0`, `1e2` | `Float64` (or module default) | `f` `ff` `fl` `fj` `j` `ffj` `flj` |
50-
| `'x'` | via `Char` operator | (none) |
51-
| `"hello"` | via `StringConstant` operator | (none) |
52-
| `#foo`, `#"foo"` | `Static[#foo]` | (none) |
45+
| Literal | Default type | Type suffix examples |
46+
| ---------------- | ----------------------------- | ----------------------------------------------- |
47+
| `true` / `false` | `Bool` | (none) |
48+
| `1`, `0xFF` | `Int32` (or module default) | `ss` `s` `i` `l` `ll` `uss` `us` `u` `ul` `ull` |
49+
| `1.0`, `1e2` | `Float64` (or module default) | `f` `ff` `fl` `fj` `j` `ffj` `flj` |
50+
| `'x'` | via `Char` operator | (none) |
51+
| `"hello"` | via `StringConstant` operator | (none) |
52+
| `#foo`, `#"foo"` | `Static[#foo]` | (none) |
5353

5454
```ceramic
5555
println(Type(1)); // Int32
@@ -72,11 +72,11 @@ Integer type suffixes may be applied to floating-point literal tokens to produce
7272

7373
These are only valid inside **alias functions**:
7474

75-
| Operator | Evaluates to |
76-
|----------|-------------|
77-
| `__FILE__` | Static string: the source file of the call site |
78-
| `__LINE__` | `Int32`: the source line |
79-
| `__COLUMN__` | `Int32`: the source column |
75+
| Operator | Evaluates to |
76+
| -------------- | ----------------------------------------------------------------------- |
77+
| `__FILE__` | Static string: the source file of the call site |
78+
| `__LINE__` | `Int32`: the source line |
79+
| `__COLUMN__` | `Int32`: the source column |
8080
| `__ARG__ name` | Static string. Textual representation of argument `name`, not evaluated |
8181

8282
```ceramic
@@ -156,12 +156,12 @@ Desugars to `dereference(a)`. Used to get a reference to the value behind a poin
156156

157157
### Prefix Operators
158158

159-
| Operator | Behavior |
160-
|----------|----------|
161-
| `+a` | desugars to `plus(a)` |
162-
| `-a` | desugars to `minus(a)` |
163-
| `&a` | primitive: returns `Pointer[T]` to `a`, which must be an lvalue. Not overloadable |
164-
| `*a` | dispatch operator. Only valid as an argument to a call expression |
159+
| Operator | Behavior |
160+
| -------- | --------------------------------------------------------------------------------- |
161+
| `+a` | desugars to `plus(a)` |
162+
| `-a` | desugars to `minus(a)` |
163+
| `&a` | primitive: returns `Pointer[T]` to `a`, which must be an lvalue. Not overloadable |
164+
| `*a` | dispatch operator. Only valid as an argument to a call expression |
165165

166166
#### Dispatch (`*a`)
167167

@@ -181,36 +181,54 @@ drawShapes(ss:Vector[Shape]) {
181181

182182
### Arithmetic Operators
183183

184-
| Operator | Desugars to |
185-
|----------|-------------|
186-
| `a * b` | `multiply(a, b)` |
187-
| `a / b` | `divide(a, b)` |
188-
| `a % b` | `remainder(a, b)` |
189-
| `a + b` | `add(a, b)` |
190-
| `a - b` | `subtract(a, b)` |
184+
| Operator | Desugars to |
185+
| -------- | ----------------- |
186+
| `a * b` | `multiply(a, b)` |
187+
| `a / b` | `divide(a, b)` |
188+
| `a % b` | `remainder(a, b)` |
189+
| `a + b` | `add(a, b)` |
190+
| `a - b` | `subtract(a, b)` |
191191

192192
All arithmetic operators are left-associative within their precedence group.
193193

194194
### Comparison Operators
195195

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)` |
201201
| `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)` |
204204

205205
All comparison operators are left-associative within their precedence group.
206206

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+
207225
### Boolean Operators
208226

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 |
227+
| Operator | Behavior |
228+
| --------- | ------------------------------------------------ |
229+
| `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 |
214232

215233
Both `and` and `or` require `Bool` operands and are not overloadable.
216234

@@ -229,10 +247,10 @@ Both branches must have the same type. Unlike `if` statements, the `else` clause
229247

230248
#### Static Expressions
231249

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.
233251

234252
```ceramic
235-
log(static LOG, "starting program");
253+
log(#LOG, "starting program");
236254
```
237255

238256
#### Unpack (`..a`)

0 commit comments

Comments
 (0)