Don't keep rebuilding class object that tracks compiler state for gc...

This commit is contained in:
K. Lange 2022-08-03 22:22:50 +09:00
parent 6d8d33c020
commit 0df346fb9b
4 changed files with 14 additions and 13 deletions

View File

@ -3719,6 +3719,16 @@ static int maybeSingleExpression(struct GlobalState * state) {
return 0;
}
_noexport
void _createAndBind_compilerClass(void) {
KrkClass * CompilerState = ADD_BASE_CLASS(KRK_BASE_CLASS(CompilerState), "CompilerState", KRK_BASE_CLASS(object));
CompilerState->allocSize = sizeof(struct GlobalState);
CompilerState->_ongcscan = _GlobalState_gcscan;
CompilerState->_ongcsweep = _GlobalState_gcsweep;
CompilerState->obj.flags |= KRK_OBJ_FLAGS_NO_INHERIT;
krk_finalizeClass(CompilerState);
}
/**
* @brief Compile a source string to bytecode.
*
@ -3733,17 +3743,7 @@ static int maybeSingleExpression(struct GlobalState * state) {
* @exception SyntaxError if @p src could not be compiled.
*/
KrkCodeObject * krk_compile(const char * src, char * fileName) {
KrkClass * GlobalState = krk_newClass(S("GlobalState"), KRK_BASE_CLASS(object));
krk_push(OBJECT_VAL(GlobalState));
GlobalState->allocSize = sizeof(struct GlobalState);
GlobalState->_ongcscan = _GlobalState_gcscan;
GlobalState->_ongcsweep = _GlobalState_gcsweep;
GlobalState->obj.flags |= KRK_OBJ_FLAGS_NO_INHERIT;
krk_finalizeClass(GlobalState);
struct GlobalState * state = (void*)krk_newInstance(GlobalState);
struct GlobalState * state = (void*)krk_newInstance(KRK_BASE_CLASS(CompilerState));
krk_push(OBJECT_VAL(state));
/* Point a new scanner at the source. */
@ -3787,8 +3787,6 @@ KrkCodeObject * krk_compile(const char * src, char * fileName) {
if (state->parser.hadError) function = NULL;
krk_pop();
krk_pop();
return function;
}

View File

@ -143,6 +143,7 @@ struct BaseClasses {
KrkClass * setiteratorClass; /**< Iterator over values in a set */
KrkClass * ThreadClass; /**< Threading.Thread */
KrkClass * LockClass; /**< Threading.Lock */
KrkClass * CompilerStateClass; /**< Compiler global state */
};
/**

View File

@ -22,6 +22,7 @@ extern void _createAndBind_builtins(void);
extern void _createAndBind_type(void);
extern void _createAndBind_exceptions(void);
extern void _createAndBind_longClass(void);
extern void _createAndBind_compilerClass(void);
/**
* @brief Index numbers for always-available interned strings representing important method and member names.

View File

@ -1001,6 +1001,7 @@ void krk_initVM(int flags) {
_createAndBind_exceptions();
_createAndBind_generatorClass();
_createAndBind_longClass();
_createAndBind_compilerClass();
if (!(vm.globalFlags & KRK_GLOBAL_NO_DEFAULT_MODULES)) {
#ifndef KRK_NO_SYSTEM_MODULES