Skip to content

Commit d89703c

Browse files
committed
Transition to TypeFlags for specific type checks; Optimize logical ops a bit
1 parent fc777b3 commit d89703c

18 files changed

+748
-718
lines changed

src/builtins.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
Compiler,
33
Target,
4-
ConversionKind
4+
ConversionKind,
5+
6+
makeSmallIntegerWrap
57
} from "./compiler";
68

79
import {
@@ -15,7 +17,9 @@ import {
1517
} from "./ast";
1618

1719
import {
18-
Type, TypeKind
20+
Type,
21+
TypeKind,
22+
TypeFlags
1923
} from "./types";
2024

2125
import {
@@ -511,23 +515,10 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
511515

512516
case TypeKind.I8:
513517
case TypeKind.I16:
514-
ret = module.createBinary(BinaryOp.ShrI32,
515-
module.createBinary(BinaryOp.ShlI32,
516-
module.createBinary(BinaryOp.RotlI32, arg0, arg1),
517-
module.createI32(compiler.currentType.smallIntegerShift)
518-
),
519-
module.createI32(compiler.currentType.smallIntegerShift)
520-
);
521-
break;
522-
523518
case TypeKind.U8:
524519
case TypeKind.U16:
525520
case TypeKind.BOOL:
526-
ret = module.createBinary(BinaryOp.AndI32,
527-
module.createBinary(BinaryOp.RotlI32, arg0, arg1),
528-
module.createI32(compiler.currentType.smallIntegerMask)
529-
);
530-
break;
521+
ret = makeSmallIntegerWrap(module.createBinary(BinaryOp.RotlI32, arg0, arg1), compiler.currentType, module);
531522

532523
case TypeKind.I32:
533524
case TypeKind.U32:
@@ -584,22 +575,10 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
584575

585576
case TypeKind.I8:
586577
case TypeKind.I16:
587-
ret = module.createBinary(BinaryOp.ShrI32,
588-
module.createBinary(BinaryOp.ShlI32,
589-
module.createBinary(BinaryOp.RotrI32, arg0, arg1),
590-
module.createI32(compiler.currentType.smallIntegerShift)
591-
),
592-
module.createI32(compiler.currentType.smallIntegerShift)
593-
);
594-
break;
595-
596578
case TypeKind.U8:
597579
case TypeKind.U16:
598580
case TypeKind.BOOL:
599-
ret = module.createBinary(BinaryOp.AndI32,
600-
module.createBinary(BinaryOp.RotrI32, arg0, arg1),
601-
module.createI32(compiler.currentType.smallIntegerMask)
602-
);
581+
ret = makeSmallIntegerWrap(module.createBinary(BinaryOp.RotrI32, arg0, arg1), compiler.currentType, module);
603582
break;
604583

605584
case TypeKind.I32:
@@ -1249,7 +1228,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
12491228

12501229
case TypeKind.F32:
12511230
if (typeArguments) {
1252-
if (!(typeArguments[1].isAnyInteger && typeArguments[1].size == 32)) {
1231+
if (!(typeArguments[1].is(TypeFlags.INTEGER) && typeArguments[1].size == 32)) {
12531232
compiler.error(DiagnosticCode.Type_0_cannot_be_reinterpreted_as_type_1, reportNode.range, typeArguments[0].toString(), typeArguments[1].toString());
12541233
return module.createUnreachable();
12551234
}
@@ -1261,7 +1240,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
12611240

12621241
case TypeKind.F64:
12631242
if (typeArguments) {
1264-
if (!(typeArguments[1].isLongInteger && !typeArguments[1].isReference)) {
1243+
if (!(typeArguments[1].is(TypeFlags.LONG | TypeFlags.INTEGER) && !typeArguments[1].isReference)) {
12651244
compiler.error(DiagnosticCode.Type_0_cannot_be_reinterpreted_as_type_1, reportNode.range, typeArguments[0].toString(), typeArguments[1].toString());
12661245
return module.createUnreachable();
12671246
}
@@ -1390,7 +1369,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
13901369
}
13911370
arg0 = compiler.compileExpression(operands[0], usizeType);
13921371
compiler.currentType = typeArguments[0];
1393-
return module.createLoad(typeArguments[0].size >>> 3, typeArguments[0].isAnySignedInteger, arg0, typeArguments[0].toNativeType());
1372+
return module.createLoad(typeArguments[0].size >>> 3, typeArguments[0].is(TypeFlags.SIGNED | TypeFlags.INTEGER), arg0, typeArguments[0].toNativeType());
13941373

13951374
case "store": // store<T?>(offset: usize, value: T) -> void
13961375
compiler.currentType = Type.void;

0 commit comments

Comments
 (0)