1- use super :: { helpers:: * , interpret:: * , interpreter_env:: * , types:: * } ;
2- use crate :: { ast:: expr:: * , env:: * , token:: * } ;
1+ use super :: {
2+ env:: InterpreterEnvironment ,
3+ helpers:: {
4+ assume_identifier,
5+ bind_function,
6+ confirm_arity,
7+ construct_lox_defined_function,
8+ extract_subscription_index,
9+ guard_function,
10+ map_arguments,
11+ unwrap_list,
12+ } ,
13+ interpret:: { eval_expression, eval_statements} ,
14+ types:: { InterpreterFunction , InterpreterValue , RuntimeError } ,
15+ } ;
16+ use crate :: {
17+ ast:: expr:: {
18+ AssignmentValue ,
19+ BinaryValue ,
20+ CallValue ,
21+ Expr ,
22+ FunctionValue ,
23+ GetAccessor ,
24+ GetValue ,
25+ IdentifierValue ,
26+ LiteralValue ,
27+ ObjectValue ,
28+ SetValue ,
29+ SuperAccessor ,
30+ SuperValue ,
31+ ThisValue ,
32+ UnaryValue ,
33+ } ,
34+ env:: { DeclaredValue , EnvironmentWrapper } ,
35+ token:: { Location , Token , TokenType } ,
36+ } ;
337
438use std:: { cell:: RefCell , collections:: HashMap , rc:: Rc } ;
539
640
741// inlining because it's used only once, but i wanted to take it
842// out of the context, to make it less cluttery
9- #[ inline( always ) ]
43+ #[ inline]
1044pub fn literal_expression (
1145 v : & LiteralValue ,
1246 env : & InterpreterEnvironment ,
1347) -> Result < InterpreterValue , RuntimeError > {
1448 match v {
15- LiteralValue :: String ( s) => Ok ( InterpreterValue :: String ( Rc :: clone ( & s) ) ) ,
49+ LiteralValue :: String ( s) => Ok ( InterpreterValue :: String ( Rc :: clone ( s) ) ) ,
1650 LiteralValue :: Number ( n) => Ok ( InterpreterValue :: Number ( * n) ) ,
1751 LiteralValue :: True => Ok ( InterpreterValue :: True ) ,
1852 LiteralValue :: False => Ok ( InterpreterValue :: False ) ,
@@ -29,7 +63,7 @@ pub fn literal_expression(
2963 }
3064}
3165
32- #[ inline( always ) ]
66+ #[ inline]
3367pub fn identifier_expression < E , T > (
3468 v : & IdentifierValue ,
3569 env : & E ,
4074 Ok ( env. read ( v. env_distance . get ( ) , & v. name ) ?. value )
4175}
4276
43- #[ inline( always ) ]
77+ #[ inline]
4478pub fn assignment_expression < E , T > (
4579 expr_evaluator : fn ( & Expr , & E ) -> Result < T , RuntimeError > ,
4680 v : & AssignmentValue ,
5690 )
5791}
5892
59- #[ inline( always ) ]
93+ #[ inline]
6094pub fn call_expression (
6195 v : & CallValue ,
6296 env : & InterpreterEnvironment ,
@@ -90,7 +124,7 @@ pub fn execute_call(
90124 let fun_env = & enclosing_env. fork ( ) ;
91125
92126 if let Some ( params) = & fv. params {
93- map_arguments ( params, & arguments, fun_env)
127+ map_arguments ( params, & arguments, fun_env) ;
94128 }
95129
96130 if let Some ( statements) = & fv. body {
@@ -128,11 +162,11 @@ pub fn execute_call(
128162 }
129163}
130164
131- #[ inline( always ) ]
165+ #[ inline]
132166pub fn function_expression (
133167 v : & FunctionValue ,
134168 env : & InterpreterEnvironment ,
135- ) -> Result < InterpreterValue , RuntimeError > {
169+ ) -> InterpreterValue {
136170 let fun = construct_lox_defined_function ( v, env) ;
137171
138172 if let Some ( t) = & v. name {
@@ -147,7 +181,7 @@ pub fn function_expression(
147181 ) ;
148182 }
149183
150- Ok ( fun)
184+ fun
151185}
152186
153187pub fn unary_expression (
@@ -228,7 +262,7 @@ pub fn binary_experssion(
228262 TokenType :: LessEqual => Ok ( ( n1 <= n2) . into ( ) ) ,
229263 TokenType :: Modulo => Ok ( InterpreterValue :: Number ( n1 % n2) ) ,
230264
231- _ => unreachable ! ( "Scanner did a bad job 😎 ." ) ,
265+ _ => unreachable ! ( "Scanner did a bad job \u{1f60e} ." ) ,
232266 }
233267 }
234268 ( InterpreterValue :: String ( s1) , InterpreterValue :: String ( s2) ) => {
@@ -273,7 +307,7 @@ fn find_method(
273307 {
274308 ( methods, superclass)
275309 } else {
276- unreachable ! ( "Class is not a class? 🤔 " )
310+ unreachable ! ( "Class is not a class? \u{1f914} " )
277311 } ;
278312
279313 if let Some ( method) = methods. get ( key) {
@@ -297,7 +331,7 @@ fn get_dot(
297331) -> Result < InterpreterValue , RuntimeError > {
298332 // auxiliary function used only once down below, that's why inlining is
299333 // completely justified 🥺
300- #[ inline( always ) ]
334+ #[ inline]
301335 fn get_property (
302336 key : & str ,
303337 properties : & HashMap < String , InterpreterValue > ,
@@ -336,18 +370,12 @@ fn get_dot(
336370
337371 match & v. key {
338372 GetAccessor :: DotName ( iden) => {
339- get_property ( iden, & borrowed_props, & class, & getee, & v. blame )
373+ get_property ( iden, & borrowed_props, class, & getee, & v. blame )
340374 }
341375 GetAccessor :: DotEval ( expr) => {
342376 let key = eval_expression ( expr, env) ?. to_string ( ) ;
343377
344- get_property (
345- & key. as_str ( ) ,
346- & borrowed_props,
347- & class,
348- & getee,
349- & v. blame ,
350- )
378+ get_property ( key. as_str ( ) , & borrowed_props, class, & getee, & v. blame )
351379 }
352380 _ => unreachable ! ( "Wrong accessor in dot" ) ,
353381 }
@@ -365,9 +393,9 @@ fn get_subscription(
365393 extract_subscription_index ( & v. key , & v. blame , s. len ( ) , env) ?;
366394
367395 unsafe {
368- Ok ( InterpreterValue :: Char (
369- * s. as_bytes ( ) . get_unchecked ( index) as char
370- ) )
396+ Ok ( InterpreterValue :: Char ( char :: from (
397+ * s. as_bytes ( ) . get_unchecked ( index) ,
398+ ) ) )
371399 }
372400 }
373401 InterpreterValue :: List ( l) => {
@@ -389,7 +417,7 @@ fn get_subscription(
389417 }
390418}
391419
392- #[ inline( always ) ]
420+ #[ inline]
393421pub fn get_expression (
394422 v : & GetValue ,
395423 env : & InterpreterEnvironment ,
@@ -463,7 +491,7 @@ fn set_subscription(
463491 Ok ( value)
464492}
465493
466- #[ inline( always ) ]
494+ #[ inline]
467495pub fn set_expression (
468496 v : & SetValue ,
469497 env : & InterpreterEnvironment ,
@@ -475,7 +503,7 @@ pub fn set_expression(
475503 }
476504}
477505
478- #[ inline( always ) ]
506+ #[ inline]
479507pub fn this_expression < E , T > ( v : & ThisValue , env : & E ) -> Result < T , RuntimeError >
480508where
481509 E : EnvironmentWrapper < T > ,
@@ -518,7 +546,9 @@ pub fn super_expression(
518546 {
519547 constructor
520548 } else {
521- unreachable ! ( "Superclass should be a class like come on 🤦" )
549+ unreachable ! (
550+ "Superclass should be a class like come on \u{1f926} "
551+ )
522552 } ;
523553
524554 let constructor = constructor. ok_or_else ( || RuntimeError {
@@ -528,7 +558,7 @@ pub fn super_expression(
528558
529559 let constructor = bind_function ( & constructor, instance) ;
530560
531- execute_call ( & constructor, & args, & v. blame , env)
561+ execute_call ( & constructor, args, & v. blame , env)
532562 }
533563 }
534564}
0 commit comments