@@ -76,7 +76,6 @@ static bool immutable_globals[UINT8_MAX];
7676
7777Parser parser ;
7878Compiler * current = NULL ;
79- Chunk * compiling_chunk ;
8079
8180static Chunk * current_chunk ()
8281{
@@ -216,7 +215,7 @@ static void patch_jump(int offset)
216215static void init_compiler (Compiler * compiler , FunctionType type )
217216{
218217 compiler -> enclosing = current ;
219- compiler -> function = NULL ;
218+ compiler -> function = new_function () ;
220219 compiler -> type = type ;
221220 compiler -> local_count = 0 ;
222221 compiler -> scope_depth = 0 ;
@@ -462,8 +461,9 @@ static void or_(bool can_assign)
462461
463462static void string (bool can_assign )
464463{
465- emit_constant (OBJ_VAL (
466- copy_string (parser .previous .start + 1 , parser .previous .length - 2 )));
464+ ObjString * str =
465+ copy_string (parser .previous .start + 1 , parser .previous .length - 2 );
466+ emit_constant (OBJ_VAL (str ));
467467}
468468
469469static void named_variable (Token name , bool can_assign )
@@ -857,12 +857,11 @@ static inline void init_parser()
857857 parser .panic_mode = false;
858858}
859859
860- ObjFunction * compile (const char * source , Chunk * chunk )
860+ ObjFunction * compile (const char * source )
861861{
862862 init_scanner (source );
863863 Compiler compiler ;
864864 init_compiler (& compiler , TYPE_SCRIPT );
865- compiling_chunk = chunk ;
866865 init_parser ();
867866
868867 advance ();
@@ -871,7 +870,6 @@ ObjFunction* compile(const char* source, Chunk* chunk)
871870 declaration ();
872871 }
873872
874- end_compiler ();
875873 ObjFunction * function = end_compiler ();
876874 return parser .had_error ? NULL : function ;
877875}
0 commit comments