File tree Expand file tree Collapse file tree 3 files changed +18
-14
lines changed
starlark/src/eval/fragment Expand file tree Collapse file tree 3 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -48,20 +48,26 @@ pub(crate) type ExprCompiled = Box<
48
48
pub ( crate ) enum ExprCompiledValue {
49
49
Value ( FrozenValue ) ,
50
50
Compiled ( ExprCompiled ) ,
51
+ /// `type(x)`
52
+ Type ( ExprCompiled ) ,
51
53
}
52
54
53
55
impl ExprCompiledValue {
54
56
pub fn as_value ( & self ) -> Option < FrozenValue > {
55
57
match self {
56
58
Self :: Value ( x) => Some ( * x) ,
57
- Self :: Compiled ( _ ) => None ,
59
+ _ => None ,
58
60
}
59
61
}
60
62
61
63
pub fn as_compiled ( self ) -> ExprCompiled {
62
64
match self {
63
65
Self :: Value ( x) => box move |_| Ok ( x. to_value ( ) ) ,
64
66
Self :: Compiled ( x) => x,
67
+ Self :: Type ( x) => expr ! ( "type" , |eval| {
68
+ x( eval) ?. get_ref( ) . get_type_value( ) . to_value( )
69
+ } )
70
+ . as_compiled ( ) ,
65
71
}
66
72
}
67
73
}
Original file line number Diff line number Diff line change @@ -22,10 +22,9 @@ use crate::{
22
22
eval:: {
23
23
compiler:: { scope:: CstExpr , Compiler } ,
24
24
fragment:: expr:: { ExprCompiled , ExprCompiledValue } ,
25
- Evaluator ,
26
25
} ,
27
26
syntax:: ast:: ExprP ,
28
- values:: { dict:: Dict , list:: List , Value } ,
27
+ values:: { dict:: Dict , list:: List } ,
29
28
} ;
30
29
31
30
/// Convert a list into a tuple. In many cases (iteration, `in`) these types
@@ -72,11 +71,11 @@ impl Compiler<'_> {
72
71
Conditional :: False
73
72
}
74
73
}
75
- ExprCompiledValue :: Compiled ( v ) => {
74
+ v => {
76
75
if expect {
77
- Conditional :: Normal ( v)
76
+ Conditional :: Normal ( v. as_compiled ( ) )
78
77
} else {
79
- Conditional :: Negate ( v)
78
+ Conditional :: Negate ( v. as_compiled ( ) )
80
79
}
81
80
}
82
81
}
@@ -99,11 +98,7 @@ impl Compiler<'_> {
99
98
}
100
99
match self . expr ( expr) {
101
100
ExprCompiledValue :: Value ( x) => ExprCompiledValue :: Value ( x. to_value ( ) . get_type_value ( ) ) ,
102
- ExprCompiledValue :: Compiled ( x) => {
103
- expr ! ( "type" , |eval| {
104
- x( eval) ?. get_ref( ) . get_type_value( ) . to_value( )
105
- } )
106
- }
101
+ x => ExprCompiledValue :: Type ( x. as_compiled ( ) ) ,
107
102
}
108
103
}
109
104
}
Original file line number Diff line number Diff line change @@ -435,9 +435,12 @@ impl Compiler<'_> {
435
435
fn stmt_expr_compiled ( & mut self , span : Span , expr : ExprCompiledValue ) -> StmtsCompiled {
436
436
match expr {
437
437
ExprCompiledValue :: Value ( _) => StmtsCompiled :: empty ( ) ,
438
- ExprCompiledValue :: Compiled ( e) => stmt ! ( self , "expr" , span, |eval| {
439
- e( eval) ?;
440
- } ) ,
438
+ e => {
439
+ let e = e. as_compiled ( ) ;
440
+ stmt ! ( self , "expr" , span, |eval| {
441
+ e( eval) ?;
442
+ } )
443
+ }
441
444
}
442
445
}
443
446
You can’t perform that action at this time.
0 commit comments