mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.0225: compiling lambda not tested yet
Problem: compiling lambda not tested yet. Solution: Add test for lambda and funcref. Drop unused instruction arg.
This commit is contained in:
@@ -278,5 +278,52 @@ def Test_compile_const_expr()
|
|||||||
assert_notmatch('JUMP', instr)
|
assert_notmatch('JUMP', instr)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def WithLambda(): string
|
||||||
|
let F = {a -> "X" .. a .. "X"}
|
||||||
|
return F("x")
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def Test_compile_lambda()
|
||||||
|
assert_equal("XxX", WithLambda())
|
||||||
|
let instr = execute('disassemble WithLambda')
|
||||||
|
assert_match('WithLambda.*'
|
||||||
|
\ .. 'let F = {a -> "X" .. a .. "X"}.*'
|
||||||
|
\ .. ' FUNCREF <lambda>\d\+.*'
|
||||||
|
\ .. 'PUSHS "x".*'
|
||||||
|
\ .. ' LOAD $0.*'
|
||||||
|
\ .. ' PCALL (argc 1).*'
|
||||||
|
\ .. ' CHECKTYPE string stack\[-1].*'
|
||||||
|
\, instr)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def AndOr(arg): string
|
||||||
|
if arg == 1 && arg != 2 || arg == 4
|
||||||
|
return 'yes'
|
||||||
|
endif
|
||||||
|
return 'no'
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def Test_compile_and_or()
|
||||||
|
assert_equal("yes", AndOr(1))
|
||||||
|
assert_equal("no", AndOr(2))
|
||||||
|
assert_equal("yes", AndOr(4))
|
||||||
|
let instr = execute('disassemble AndOr')
|
||||||
|
assert_match('AndOr.*'
|
||||||
|
\ .. 'if arg == 1 && arg != 2 || arg == 4.*'
|
||||||
|
\ .. '\d LOAD arg\[-1].*'
|
||||||
|
\ .. '\d PUSHNR 1.*'
|
||||||
|
\ .. '\d COMPAREANY ==.*'
|
||||||
|
\ .. '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*'
|
||||||
|
\ .. '\d LOAD arg\[-1].*'
|
||||||
|
\ .. '\d PUSHNR 2.*'
|
||||||
|
\ .. '\d COMPAREANY !=.*'
|
||||||
|
\ .. '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*'
|
||||||
|
\ .. '\d LOAD arg\[-1].*'
|
||||||
|
\ .. '\d PUSHNR 4.*'
|
||||||
|
\ .. '\d COMPAREANY ==.*'
|
||||||
|
\ .. '\d JUMP_IF_FALSE -> \d\+.*'
|
||||||
|
\, instr)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -742,6 +742,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
225,
|
||||||
/**/
|
/**/
|
||||||
224,
|
224,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -130,7 +130,6 @@ typedef struct {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JUMP_ALWAYS,
|
JUMP_ALWAYS,
|
||||||
JUMP_IF_TRUE, // pop and jump if true
|
|
||||||
JUMP_IF_FALSE, // pop and jump if false
|
JUMP_IF_FALSE, // pop and jump if false
|
||||||
JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
|
JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
|
||||||
JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
|
JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
|
||||||
|
@@ -1001,8 +1001,7 @@ call_def_function(
|
|||||||
if (when == JUMP_IF_FALSE
|
if (when == JUMP_IF_FALSE
|
||||||
|| when == JUMP_AND_KEEP_IF_FALSE)
|
|| when == JUMP_AND_KEEP_IF_FALSE)
|
||||||
jump = !jump;
|
jump = !jump;
|
||||||
if (when == JUMP_IF_FALSE || when == JUMP_IF_TRUE
|
if (when == JUMP_IF_FALSE || !jump)
|
||||||
|| !jump)
|
|
||||||
{
|
{
|
||||||
// drop the value from the stack
|
// drop the value from the stack
|
||||||
clear_tv(tv);
|
clear_tv(tv);
|
||||||
@@ -1583,15 +1582,14 @@ failed:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISASSEMBLE 1
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":dissassemble".
|
* ":dissassemble".
|
||||||
|
* We don't really need this at runtime, but we do have tests that require it,
|
||||||
|
* so always include this.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ex_disassemble(exarg_T *eap)
|
ex_disassemble(exarg_T *eap)
|
||||||
{
|
{
|
||||||
#ifdef DISASSEMBLE
|
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
ufunc_T *ufunc;
|
ufunc_T *ufunc;
|
||||||
dfunc_T *dfunc;
|
dfunc_T *dfunc;
|
||||||
@@ -1840,9 +1838,6 @@ ex_disassemble(exarg_T *eap)
|
|||||||
case JUMP_ALWAYS:
|
case JUMP_ALWAYS:
|
||||||
when = "JUMP";
|
when = "JUMP";
|
||||||
break;
|
break;
|
||||||
case JUMP_IF_TRUE:
|
|
||||||
when = "JUMP_IF_TRUE";
|
|
||||||
break;
|
|
||||||
case JUMP_AND_KEEP_IF_TRUE:
|
case JUMP_AND_KEEP_IF_TRUE:
|
||||||
when = "JUMP_AND_KEEP_IF_TRUE";
|
when = "JUMP_AND_KEEP_IF_TRUE";
|
||||||
break;
|
break;
|
||||||
@@ -1997,7 +1992,6 @@ ex_disassemble(exarg_T *eap)
|
|||||||
case ISN_DROP: smsg("%4d DROP", current); break;
|
case ISN_DROP: smsg("%4d DROP", current); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user