From fb28349349483c5e1c9523b19c2158cb465cf4e9 Mon Sep 17 00:00:00 2001 From: Vexu Date: Wed, 26 Aug 2020 12:34:41 +0300 Subject: stage2: astgen catch --- src-self-hosted/Module.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src-self-hosted/Module.zig') diff --git a/src-self-hosted/Module.zig b/src-self-hosted/Module.zig index 82029c1e9f..5b5ef656b2 100644 --- a/src-self-hosted/Module.zig +++ b/src-self-hosted/Module.zig @@ -2570,7 +2570,17 @@ pub fn analyzeIsNull( operand: *Inst, invert_logic: bool, ) InnerError!*Inst { - return self.fail(scope, src, "TODO implement analysis of isnull and isnotnull", .{}); + if (operand.value()) |opt_val| { + const is_null = opt_val.isNull(); + return self.constBool(scope, src, invert_logic); + } + const b = try self.requireRuntimeBlock(scope, src); + const inst_tag: Inst.Tag = if (invert_logic) .isnonnull else .isnull; + return self.addUnOp(b, src, Type.initTag(.bool), inst_tag, operand); +} + +pub fn analyzeIsErr(self: *Module, scope: *Scope, src: usize, operand: *Inst) InnerError!*Inst { + return self.fail(scope, src, "TODO implement analysis of iserr", .{}); } /// Asserts that lhs and rhs types are both numeric. -- cgit v1.2.3 From b0995cb9f9540a6d463dcc2722cb3b8918a61e8e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Aug 2020 19:53:36 -0700 Subject: stage2: correct logic for analyzeIsNull --- src-self-hosted/Module.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src-self-hosted/Module.zig') diff --git a/src-self-hosted/Module.zig b/src-self-hosted/Module.zig index 5b5ef656b2..dd4e8fea1e 100644 --- a/src-self-hosted/Module.zig +++ b/src-self-hosted/Module.zig @@ -2572,7 +2572,8 @@ pub fn analyzeIsNull( ) InnerError!*Inst { if (operand.value()) |opt_val| { const is_null = opt_val.isNull(); - return self.constBool(scope, src, invert_logic); + const bool_value = if (invert_logic) !is_null else is_null; + return self.constBool(scope, src, bool_value); } const b = try self.requireRuntimeBlock(scope, src); const inst_tag: Inst.Tag = if (invert_logic) .isnonnull else .isnull; -- cgit v1.2.3