Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/daScript/ast/ast_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace das
vector<string> fieldsInOrder;
mutable DebugInfoHelper helpA;
mutable StructInfo * sti = nullptr;
mutable StructInfo * sti_gc = nullptr;
ModuleLibrary * mlib = nullptr;
vector<TypeAnnotation*> parents;
bool validationNeverFails = false;
Expand Down
1 change: 1 addition & 0 deletions include/daScript/simulate/aot_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace das {

DAS_API bool is_compiling ( );
DAS_API bool is_compiling_macros ( );
DAS_API uint64_t get_context_share_counter ( Context * context );

DAS_API char * builtin_das_root ( Context * context, LineInfoArg * at );
DAS_API void builtin_throw ( char * text, Context * context, LineInfoArg * at );
Expand Down
1 change: 1 addition & 0 deletions include/daScript/simulate/data_walker.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace das {
struct DAS_API DataWalker : ptr_ref_count {
// we doing what?
class Context * context = nullptr;
bool collecting = false;
bool reading = false;
bool _cancel = false;
// helpers
Expand Down
29 changes: 27 additions & 2 deletions src/ast/ast_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ namespace das {
auto debugInfo = helpA.debugInfo;
sti = debugInfo->template makeNode<StructInfo>();
sti->name = debugInfo->allocateName(name);
sti_gc = debugInfo->template makeNode<StructInfo>();
sti_gc->name = sti->name;
// flags
sti->flags = 0;
sti_gc->flags = 0;
// count fields
sti->count = 0;
for ( auto & fi : fields ) {
Expand All @@ -182,7 +185,9 @@ namespace das {
}
}
// and allocate
sti_gc->count = 0;
sti->size = (uint32_t) getSizeOf();
sti_gc->size = sti->size;
sti->fields = (VarInfo **) debugInfo->allocate( sizeof(VarInfo *) * sti->count );
int i = 0;
for ( const auto & fn : fieldsInOrder ) {
Expand All @@ -195,17 +200,37 @@ namespace das {
vi->name = debugInfo->allocateName(fn);
vi->offset = var.offset;
sti->fields[i++] = vi;
if ( vi->flags & (TypeInfo::flag_heapGC | TypeInfo::flag_stringHeapGC) ) {
sti_gc->count++;
}
}
}
}
if ( sti_gc->count ) {
sti_gc->fields = (VarInfo **) debugInfo->allocate( sizeof(VarInfo *) * sti_gc->count );
int j = 0;
for ( uint32_t n=0; n!=sti->count; ++n ) {
auto & fi = sti->fields[n];
if ( fi->flags & (TypeInfo::flag_heapGC | TypeInfo::flag_stringHeapGC) ) {
sti_gc->fields[j++] = fi;
}
}
} else {
sti_gc->fields = nullptr;
}
sti->module_name = debugInfo->allocateCachedName(this->module->name);
}

}

void BasicStructureAnnotation::walk ( DataWalker & walker, void * data ) {
updateTypeInfo();
walker.walk_struct((char *)data, sti);
if ( walker.collecting ) {
if ( sti_gc->count ) {
walker.walk_struct((char *)data, sti_gc);
}
} else {
walker.walk_struct((char *)data, sti);
}
}

void BasicStructureAnnotation::from ( BasicStructureAnnotation * ann ) {
Expand Down
7 changes: 7 additions & 0 deletions src/builtin/module_builtin_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,10 @@ namespace das

}

DAS_API uint64_t get_context_share_counter ( Context * context ) {
return (uint64_t) context->code.use_count();
}

bool is_compiling_macros ( ) {
if ( daScriptEnvironment::getBound() && daScriptEnvironment::getBound()->g_Program ) {
return daScriptEnvironment::getBound()->g_Program->isCompilingMacros;
Expand Down Expand Up @@ -1662,6 +1666,9 @@ namespace das
->args({"name"});
addExtern<DAS_BIND_FUN(is_reporting_compilation_errors)>(*this, lib, "is_reporting_compilation_errors",
SideEffects::accessExternal, "is_reporting_compilation_errors");
addExtern<DAS_BIND_FUN(get_context_share_counter)>(*this, lib, "get_context_share_counter",
SideEffects::accessExternal, "get_context_share_counter")
->arg("context");
// iterator functions
addExtern<DAS_BIND_FUN(builtin_iterator_first)>(*this, lib, "_builtin_iterator_first",
SideEffects::modifyArgumentAndExternal, "builtin_iterator_first")
Expand Down
4 changes: 4 additions & 0 deletions src/simulate/simulate_gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace das
int32_t gcFlags = TypeInfo::flag_stringHeapGC | TypeInfo::flag_heapGC;
int32_t gcStructFlags = StructInfo::flag_stringHeapGC | StructInfo::flag_heapGC;

BaseGcDataWalker() {
collecting = true;
reading = false;
}
virtual bool canVisitStructure ( char * /*ps*/, StructInfo * info ) override {
if ( !(info->flags & gcStructFlags) ) return false;
return true;
Expand Down