Skip to content

Commit 3a465c1

Browse files
committed
Merged with Google's internal repo.
These changes start to build out the HIR from the AST.
1 parent a5b18e4 commit 3a465c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1611
-544
lines changed

benchmarks/binary_trees.rn

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Node(self) {
2121
left = self.leftNode
2222
right = self.rightNode
2323
if !isnull(left) {
24-
sum += left!.check()
24+
sum += left.check()
2525
}
2626
if !isnull(right) {
27-
sum += right!.check()
27+
sum += right.check()
2828
}
2929
return sum
3030
}

benchmarks/fh.rn

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for i in range(10u32) {
4848
do {
4949
elem2 = root.popHeapElement()
5050
} while !isnull(elem2) {
51-
totalHash = hashValues(totalHash, elem2!.cost)
51+
totalHash = hashValues(totalHash, elem2.cost)
5252
}
5353
println totalHash
5454
}

bind/bindexpr.c

+12-14
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static void bindBinaryArithmeticExpression(deBlock scopeBlock, deExpression expr
372372

373373
// Bind a bitwise OR expression. This is different from the other bitwise
374374
// operators because it also used in type unions, such as "a: Uint | Int".
375-
static void bindBitwiseOrExpression(deBlock scopeBlock, deExpression expression) {
375+
static void bindBitwiseOrExpression(deBlock scopeBlock, deExpression expression, bool isTypeExpr) {
376376
deExpression left = deExpressionGetFirstExpression(expression);
377377
deExpression right = deExpressionGetNextExpression(left);
378378
if (deExpressionIsType(left) && deExpressionIsType(right)) {
@@ -381,10 +381,7 @@ static void bindBitwiseOrExpression(deBlock scopeBlock, deExpression expression)
381381
}
382382
deDatatype leftType, rightType;
383383
checkBinaryExpression(scopeBlock, expression, &leftType, &rightType, false);
384-
if (deExpressionIsType(left)) {
385-
if (!deExpressionIsType(right)) {
386-
deExprError(expression, "Non-equal types passed to binary operator");
387-
}
384+
if (isTypeExpr) {
388385
deExpressionSetIsType(expression, true);
389386
deExpressionSetDatatype(expression, deNoneDatatypeCreate());
390387
} else {
@@ -1023,8 +1020,8 @@ static void bindCastExpression(deExpression expression) {
10231020
leftDatatype = deSetDatatypeSecret(leftDatatype, deDatatypeSecret(rightDatatype));
10241021
if (deDatatypeGetType(leftDatatype) == DE_TYPE_ENUMCLASS) {
10251022
// If the cast is to an ENUMCLASS, instead cast to an ENUM.
1026-
deBlock enumBlock = deFunctionGetSubBlock(deDatatypeGetFunction(leftDatatype));
1027-
leftDatatype = deFindEnumIntType(enumBlock);
1023+
deFunction enumFunc = deDatatypeGetFunction(leftDatatype);
1024+
leftDatatype = deEnumDatatypeCreate(enumFunc);
10281025
}
10291026
verifyCast(expression, leftDatatype, rightDatatype, line);
10301027
deExpressionSetDatatype(expression, leftDatatype);
@@ -1559,10 +1556,9 @@ static bool bindDotExpression(deBlock scopeBlock, deExpression expression) {
15591556
deBlock classBlock;
15601557
if (type == DE_TYPE_CLASS) {
15611558
if (deDatatypeNullable(datatype)) {
1562-
deString string = deMutableStringCreate();
1563-
deDumpExpressionStr(string, expression);
1564-
deExprError(expression, "Cannot use dot operator on nullable type: %s.",
1565-
deStringGetCstr(string));
1559+
// Infer the ! operator.
1560+
datatype = deSetDatatypeNullable(datatype, false);
1561+
deExpressionSetDatatype(accessExpr, datatype);
15661562
}
15671563
classBlock = deClassGetSubBlock(deDatatypeGetClass(datatype));
15681564
} else if (type == DE_TYPE_TEMPLATE) {
@@ -1659,7 +1655,7 @@ static void bindTemplateInst(deBlock scopeBlock, deExpression expression) {
16591655
}
16601656

16611657
// Bind the expression's expression.
1662-
static deBindRes bindExpression(deBlock scopeBlock, deExpression expression) {
1658+
static deBindRes bindExpression(deBlock scopeBlock, deExpression expression, bool isTypeExpr) {
16631659
deDatatype oldDatatype = deExpressionGetDatatype(expression);
16641660
if (oldDatatype != deDatatypeNull && deDatatypeGetType(oldDatatype) == DE_TYPE_MODINT) {
16651661
// TODO: Add support for operator overloading in modular expressions.
@@ -1701,7 +1697,7 @@ static deBindRes bindExpression(deBlock scopeBlock, deExpression expression) {
17011697
break;
17021698
case DE_EXPR_BITOR :
17031699
case DE_EXPR_BITOR_EQUALS:
1704-
bindBitwiseOrExpression(scopeBlock, expression);
1700+
bindBitwiseOrExpression(scopeBlock, expression, isTypeExpr);
17051701
break;
17061702
case DE_EXPR_ADD:
17071703
case DE_EXPR_SUB:
@@ -2001,7 +1997,9 @@ void deBindStatement(deBinding binding) {
20011997
deExpression expression = deBindingGetFirstExpression(binding);
20021998
deBlock scopeBlock = deGetBindingBlock(binding);
20031999
while (expression != deExpressionNull) {
2004-
deBindRes result = bindExpression(scopeBlock, expression);
2000+
deBindingType type = deBindingGetType(binding);
2001+
bool isTypeExpr = type == DE_BIND_VAR_CONSTRAINT || type == DE_BIND_FUNC_CONSTRAINT;
2002+
deBindRes result = bindExpression(scopeBlock, expression, isTypeExpr);
20052003
if (result == DE_BINDRES_BLOCKED) {
20062004
return;
20072005
} else if (result == DE_BINDRES_REBIND) {

0 commit comments

Comments
 (0)