-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from jakbyte/unary-ops
feat: unary operators
- Loading branch information
Showing
9 changed files
with
270 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
crates/mun_codegen/src/snapshots/test__unary_expressions.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
source: crates/mun_codegen/src/test.rs | ||
expression: "pub fn negf(x: float) -> float {\n -x\n}\n\npub fn negi(x: int) -> int {\n -x\n}\n\npub fn notb(x: bool) -> bool {\n !x\n}\n\npub fn noti(x: int) -> int {\n !x\n}" | ||
--- | ||
; == FILE IR ===================================== | ||
; ModuleID = 'main.mun' | ||
source_filename = "main.mun" | ||
|
||
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } | ||
|
||
@global_type_table = external global [3 x %struct.MunTypeInfo addrspace(4)*] | ||
|
||
define double @negf(double) { | ||
body: | ||
%neg = fsub double -0.000000e+00, %0 | ||
ret double %neg | ||
} | ||
|
||
define i64 @negi(i64) { | ||
body: | ||
%neg = sub i64 0, %0 | ||
ret i64 %neg | ||
} | ||
|
||
define i1 @notb(i1) { | ||
body: | ||
%not = xor i1 %0, true | ||
ret i1 %not | ||
} | ||
|
||
define i64 @noti(i64) { | ||
body: | ||
%not = xor i64 %0, -1 | ||
ret i64 %not | ||
} | ||
|
||
|
||
; == GROUP IR ==================================== | ||
; ModuleID = 'group_name' | ||
source_filename = "group_name" | ||
|
||
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } | ||
|
||
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00" | ||
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 } | ||
@"type_info::<core::f64>::name" = private unnamed_addr constant [10 x i8] c"core::f64\00" | ||
@"type_info::<core::f64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"`\DBF\9C?YJ%G\AD4\9F\D5\92%A", [10 x i8]* @"type_info::<core::f64>::name", i32 64, i8 8, i8 0 } | ||
@"type_info::<core::bool>::name" = private unnamed_addr constant [11 x i8] c"core::bool\00" | ||
@"type_info::<core::bool>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"x\82\81m t7\03\CB\F8k\81-;\C9\84", [11 x i8]* @"type_info::<core::bool>::name", i32 1, i8 1, i8 0 } | ||
@global_type_table = global [3 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::bool>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
crates/mun_hir/src/ty/snapshots/tests__infer_unary_ops.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
source: crates/mun_hir/src/ty/tests.rs | ||
expression: "fn foo(a: int, b: bool) {\n a = -a;\n b = !b;\n}" | ||
--- | ||
[7; 8) 'a': int | ||
[15; 16) 'b': bool | ||
[24; 51) '{ ... !b; }': nothing | ||
[30; 31) 'a': int | ||
[30; 36) 'a = -a': nothing | ||
[34; 36) '-a': int | ||
[35; 36) 'a': int | ||
[42; 43) 'b': bool | ||
[42; 48) 'b = !b': nothing | ||
[46; 48) '!b': bool | ||
[47; 48) 'b': bool |
19 changes: 19 additions & 0 deletions
19
crates/mun_hir/src/ty/snapshots/tests__invalid_unary_ops.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: crates/mun_hir/src/ty/tests.rs | ||
expression: "fn bar(a: float, b: bool) {\n a = !a; // mismatched type\n b = -b; // mismatched type\n}" | ||
--- | ||
[37; 38): cannot apply unary operator | ||
[36; 38): mismatched type | ||
[68; 69): cannot apply unary operator | ||
[67; 69): mismatched type | ||
[7; 8) 'a': float | ||
[17; 18) 'b': bool | ||
[26; 91) '{ ...type }': nothing | ||
[32; 33) 'a': float | ||
[32; 38) 'a = !a': nothing | ||
[36; 38) '!a': {unknown} | ||
[37; 38) 'a': float | ||
[63; 64) 'b': bool | ||
[63; 69) 'b = -b': nothing | ||
[67; 69) '-b': {unknown} | ||
[68; 69) 'b': bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters