Jelajahi Sumber

ncd: NCDInterpProcess: retry simple module lookups when a statement is about to be instantiated, this is needed for dynamic module loading

ambrop7 13 tahun lalu
induk
melakukan
675f8100b7
3 mengubah file dengan 11 tambahan dan 4 penghapusan
  1. 9 2
      ncd/NCDInterpProcess.c
  2. 1 1
      ncd/NCDInterpProcess.h
  3. 1 1
      ncd/NCDInterpreter.c

+ 9 - 2
ncd/NCDInterpProcess.c

@@ -357,14 +357,21 @@ void NCDInterpProcess_StatementObjNames (NCDInterpProcess *o, int i, const NCD_s
     *out_num_objnames = o->stmts[i].num_objnames;
 }
 
-const struct NCDInterpModule * NCDInterpProcess_StatementGetSimpleModule (NCDInterpProcess *o, int i)
+const struct NCDInterpModule * NCDInterpProcess_StatementGetSimpleModule (NCDInterpProcess *o, int i, NCDStringIndex *string_index, NCDModuleIndex *module_index)
 {
     DebugObject_Access(&o->d_obj);
     ASSERT(i >= 0)
     ASSERT(i < o->num_stmts)
     ASSERT(!o->stmts[i].objnames)
     
-    return o->stmts[i].binding.simple_module;
+    struct NCDInterpProcess__stmt *e = &o->stmts[i];
+    
+    if (!e->binding.simple_module) {
+        const char *cmdname = NCDStringIndex_Value(string_index, e->cmdname);
+        e->binding.simple_module = NCDModuleIndex_FindModule(module_index, cmdname);
+    }
+    
+    return e->binding.simple_module;
 }
 
 const struct NCDInterpModule * NCDInterpProcess_StatementGetMethodModule (NCDInterpProcess *o, int i, NCD_string_id_t obj_type, NCDModuleIndex *module_index)

+ 1 - 1
ncd/NCDInterpProcess.h

@@ -84,7 +84,7 @@ void NCDInterpProcess_Free (NCDInterpProcess *o);
 int NCDInterpProcess_FindStatement (NCDInterpProcess *o, int from_index, NCD_string_id_t name);
 const char * NCDInterpProcess_StatementCmdName (NCDInterpProcess *o, int i, NCDStringIndex *string_index);
 void NCDInterpProcess_StatementObjNames (NCDInterpProcess *o, int i, const NCD_string_id_t **out_objnames, size_t *out_num_objnames);
-const struct NCDInterpModule * NCDInterpProcess_StatementGetSimpleModule (NCDInterpProcess *o, int i);
+const struct NCDInterpModule * NCDInterpProcess_StatementGetSimpleModule (NCDInterpProcess *o, int i, NCDStringIndex *string_index, NCDModuleIndex *module_index);
 const struct NCDInterpModule * NCDInterpProcess_StatementGetMethodModule (NCDInterpProcess *o, int i, NCD_string_id_t obj_type, NCDModuleIndex *module_index);
 int NCDInterpProcess_CopyStatementArgs (NCDInterpProcess *o, int i, NCDValMem *out_valmem, NCDValRef *out_val, NCDValReplaceProg *out_prog) WARN_UNUSED;
 void NCDInterpProcess_StatementBumpAllocSize (NCDInterpProcess *o, int i, int alloc_size);

+ 1 - 1
ncd/NCDInterpreter.c

@@ -853,7 +853,7 @@ void process_advance (struct process *p)
     
     if (!objnames) {
         // not a method; module is already known by NCDInterpProcess
-        module = NCDInterpProcess_StatementGetSimpleModule(p->iprocess, p->ap);
+        module = NCDInterpProcess_StatementGetSimpleModule(p->iprocess, p->ap, &p->interp->string_index, &p->interp->mindex);
         
         if (!module) {
             const char *cmdname_str = NCDInterpProcess_StatementCmdName(p->iprocess, p->ap, &p->interp->string_index);