Skip to content

Commit 879c7aa

Browse files
committed
Added HIR database design doc. This is initial, and will change.
1 parent 40f8f56 commit 879c7aa

12 files changed

+1883
-10
lines changed

TODO

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Support tuple unpacking.
5252
Support overloading modular operations, so we can support modular polynomials, etc.
5353
Add multi-threading support.
5454
Add schema-level reuse statements
55+
Write a schema generator for Rune similar to the dataview program for DataDraw schemas.
5556
Flush out generator's Rune code interpreter.
5657
Finish transition to memory pools, and allocation of global arrays with mmap of the memory available on the machine so large arrays never move.
5758

bind/bind.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void deBindAllSignatures(void) {
542542
deBinding binding = deRootGetFirstBinding(deTheRoot);
543543
while (binding != deBindingNull) {
544544
deRootRemoveBinding(deTheRoot, binding);
545-
deBindStatement2(binding);
545+
deBindStatement(binding);
546546
if (deBindingGetFirstExpression(binding) == deExpressionNull) {
547547
// The expression tree is now fully bound.
548548
deSignature signature = deBindingGetSignature(binding);
@@ -641,9 +641,14 @@ static void reportEvent(deEvent event) {
641641
// exit if any exist.
642642
void deReportEvents(void) {
643643
deEvent event;
644-
deForeachRootEvent(deTheRoot, event) {
645-
reportEvent(event);
646-
} deEndRootEvent;
644+
deSafeForeachRootEvent(deTheRoot, event) {
645+
if (deEventGetFirstBinding(event) == deBindingNull) {
646+
// This can happen if we destroy the statements that were blocked.
647+
deEventDestroy(event);
648+
} else {
649+
reportEvent(event);
650+
}
651+
} deEndSafeRootEvent;
647652
if (deRootGetFirstEvent(deTheRoot) != deEventNull) {
648653
utExit("Exiting due to errors...");
649654
}

bind/bindexpr.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,21 @@ static void refineAccessExpressionDatatype(deBlock scopeBlock, deExpression targ
14951495
}
14961496
}
14971497

1498+
// Check the type constraint on the assignment expression.
1499+
static void checkAssignmentTypeConstraint(deBlock scopeBlock, deExpression expression) {
1500+
deExpression access = deExpressionGetFirstExpression(expression);
1501+
deExpression value = deExpressionGetNextExpression(access);
1502+
deExpression constraint = deExpressionGetNextExpression(value);
1503+
if (constraint == deExpressionNull) {
1504+
return;
1505+
}
1506+
deDatatype datatype = deExpressionGetDatatype(value);
1507+
if (!deDatatypeMatchesTypeExpression(scopeBlock, datatype, constraint)) {
1508+
error(expression, "Violation of type constraint: %s",
1509+
deDatatypeGetDefaultValueString(datatype));
1510+
}
1511+
}
1512+
14981513
// Bind an assignment expression.
14991514
static deBindRes bindAssignmentExpression(deBlock scopeBlock, deExpression expression) {
15001515
deExpression access = deExpressionGetFirstExpression(expression);
@@ -1524,11 +1539,12 @@ static deBindRes bindAssignmentExpression(deBlock scopeBlock, deExpression expre
15241539
refineAccessExpressionDatatype(scopeBlock, access, valueDatatype);
15251540
}
15261541
deExpressionSetDatatype(expression, valueDatatype);
1542+
checkAssignmentTypeConstraint(scopeBlock, expression);
15271543
return DE_BINDRES_OK;
15281544
}
15291545

15301546
// Bind the array expression.
1531-
static void bindArrayExpression(deBlock scopeBlock, deExpression expression) {
1547+
static void bindArrayExpression(deBlock scopeBlock, deExpression expression) {
15321548
deLine line = deExpressionGetLine(expression);
15331549
deExpression firstElement = deExpressionGetFirstExpression(expression);
15341550
deDatatype datatype = deExpressionGetDatatype(firstElement);
@@ -2000,7 +2016,7 @@ static void rebuildBinding(deBinding binding) {
20002016
}
20012017

20022018
// Bind or continue expression the statement.
2003-
void deBindStatement2(deBinding binding) {
2019+
void deBindStatement(deBinding binding) {
20042020
deExpression expression = deBindingGetFirstExpression(binding);
20052021
deBlock scopeBlock = deGetBindingBlock(binding);
20062022
while (expression != deExpressionNull) {
@@ -2045,6 +2061,6 @@ void deBindStatement2(deBinding binding) {
20452061
}
20462062
if (deBindingGetFirstExpression(binding) != deExpressionNull) {
20472063
// We must have queued more expressions during post-processing.
2048-
deBindStatement2(binding);
2064+
deBindStatement(binding);
20492065
}
20502066
}

builtin/hashed.rn

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ generator Hashed(A: Class, B: Class, cascadeDelete: bool = false,
210210
}
211211
}
212212
} else {
213-
appendcode A.destroy {
213+
prependcode A.destroy {
214214
for x$labelB$B in range(self.$labelB$B_Table.length()) {
215215
$labelB$B_Entry = self.$labelB$B_Table[x$labelB$B]
216216
while !isnull($labelB$B_Entry) {
@@ -229,7 +229,7 @@ generator Hashed(A: Class, B: Class, cascadeDelete: bool = false,
229229
self.nextHashed$A$labelB$B = null(self)
230230
}
231231
// Remove self from A on destruction.
232-
appendcode B.destroy {
232+
prependcode B.destroy {
233233
if !isnull(self.$labelA$A) {
234234
self.$labelA$A!.remove$labelB$B(self)
235235
}

errortests/typeconstraint.rn

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 Google LLC.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
a: i32 = 123u32

0 commit comments

Comments
 (0)