From 5aa31fdd8979654668bec3360ca63ed15525ad87 Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Fri, 2 Apr 2021 08:40:32 +0200 Subject: [PATCH] bytecode: Do not treat perfect type matches as conditional When matching [write "Hello"] with [write X:text], we don't want to consider the generated code as conditional when it is not. This changes the generated code from: Compiled write "false" as Constants: C0 = "false" C1 = false C2 = true Locals: L0 = [write "false"] L1 = ["false"] Types: write "false" as nil "false" as character Opcodes (2 locals, 0 parameters, 2 temporaries) 0: native #41=xl_write_text, (1) 0: C0 => L0 5: branch +12=19 7: character_typecheck L1, +7=17 10: native #39=xl_write_character, (1) 0: C0 => L0 15: branch +2=19 17: form_error L0 19: ret L0 to: Compiled write "false" as Constants: C0 = "false" C1 = false C2 = true Locals: L0 = [write "false"] Types: write "false" as nil "false" as text Opcodes (1 locals, 0 parameters, 1 temporaries) 0: native #41=xl_write_text, (1) 0: C0 => L0 5: ret L0 Signed-off-by: Christophe de Dinechin --- src/bytecode.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/bytecode.cpp b/src/bytecode.cpp index 786677601..b8c07c51e 100644 --- a/src/bytecode.cpp +++ b/src/bytecode.cpp @@ -2164,6 +2164,7 @@ strength BytecodeBindings::Do(Infix *what) if (outermost) { type = want; + have = want; } else if (want != have) { @@ -2190,7 +2191,7 @@ strength BytecodeBindings::Do(Infix *what) OP(check_input_type, want, ValueIndex(test), CHECK); } bytecode->Type(value, want); - return Possible(); + return want == have ? Perfect() : Possible(); } // Make sure names bind to values @@ -2349,8 +2350,6 @@ inline Context::LookupMode lookupMode(Bytecode *bytecode) } -static void debug(Tree *expr, Tree *decl) {} - static Tree *lookupCandidate(Scope *evalScope, Scope *declScope, Tree *expr, @@ -2366,12 +2365,6 @@ static Tree *lookupCandidate(Scope *evalScope, Tree *pattern = decl->Pattern(); XL_ASSERT(bindings.Self() == expr); -if (Prefix *prefix = expr->AsPrefix()) - if (Name *name = prefix->left->AsName()) - if (name->value == "write") - if (Text *text = prefix->right->AsText()) - debug(expr, decl); - // Add bytecode to check argument against parameters and create locals Bytecode::Attempt attempt(bytecode); bindings.Candidate(decl, evalScope, declScope);