Skip to content

Commit

Permalink
bytecode: Do not treat perfect type matches as conditional
Browse files Browse the repository at this point in the history
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 <christophe@dinechin.org>
  • Loading branch information
c3d committed Jul 1, 2021
1 parent 77752e5 commit d1d694d
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ strength BytecodeBindings::Do(Infix *what)
if (outermost)
{
type = want;
have = want;
}
else if (want != have)
{
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit d1d694d

Please sign in to comment.