Skip to content

Commit 288aaa8

Browse files
committed
new module is now an extension function
1 parent 1ca7f6b commit 288aaa8

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

compiler/cbi/bindings/BuildContextCBI.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ AnnotationController* BuildContextgetAnnotationController(LabBuildContext* self)
2222
return &self->compiler.controller;
2323
}
2424

25-
LabModule* BuildContextnew_module(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleSpan* dependencies) {
26-
return self->new_module(*scope_name, *name, dependencies->ptr, dependencies->size);
27-
}
28-
2925
LabModule* BuildContextget_cached(LabBuildContext* self, LabJob* job, chem::string_view* scope_name, chem::string_view* name) {
3026
return self->get_cached(job, *scope_name, *name);
3127
}
@@ -324,7 +320,7 @@ static DependencySymbolInfo* allocate_dep_info(ASTAllocator& allocator, Dependen
324320
return info;
325321
}
326322

327-
LabModule* BuildContextnew_module_and_deps(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleDependencyCBISpan* dependencies) {
323+
LabModule* BuildContextnew_module(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleDependencyCBISpan* dependencies) {
328324
auto& allocator = self->compiler.global_allocator;
329325
auto mod = new LabModule(LabModuleType::Directory, chem::string(*scope_name), chem::string(*name));
330326
self->storage.insert_module_ptr_dangerous(mod);

compiler/cbi/bindings/BuildContextCBI.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ extern "C" {
8181

8282
AnnotationController* BuildContextgetAnnotationController(LabBuildContext* self);
8383

84-
LabModule* BuildContextnew_module(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleSpan* dependencies);
85-
86-
LabModule* BuildContextnew_module_and_deps(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleDependencyCBISpan* dependencies);
84+
LabModule* BuildContextnew_module(LabBuildContext* self, chem::string_view* scope_name, chem::string_view* name, ModuleDependencyCBISpan* dependencies);
8785

8886
void BuildContextset_module_symbol_info(LabBuildContext* self, LabModule* module, unsigned int index, DependencySymbolInfoCBI* info);
8987

compiler/cbi/bindings/CBI.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
const std::pair<chem::string_view, void*> BuildContextSymMap[] = {
2323
{ "lab_BuildContextgetAnnotationController", (void*) BuildContextgetAnnotationController },
2424
{ "lab_BuildContextnew_module", (void*) BuildContextnew_module },
25-
{ "lab_BuildContextnew_module_and_deps", (void*) BuildContextnew_module_and_deps },
2625
{ "lab_BuildContextset_module_symbol_info", (void*) BuildContextset_module_symbol_info },
2726
{ "lab_BuildContextget_cached", (void*) BuildContextget_cached },
2827
{ "lab_BuildContextset_cached", (void*) BuildContextset_cached },

compiler/lab/mod_conv/ModToLabConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void convertToBuildLab(const ModuleFileData& data, std::ostream& output) {
163163
}
164164

165165
output << " ];\n";
166-
output << "\tconst mod = ctx.new_module_and_deps(\"" << data.scope_name << "\", \"" << data.module_name << "\", std::span<ModuleDependency>(deps, " << deps_size << "));\n";
166+
output << "\tconst mod = ctx.new_module(\"" << data.scope_name << "\", \"" << data.module_name << "\", std::span<ModuleDependency>(deps, " << deps_size << "));\n";
167167
output << "\tctx.set_cached(__chx_job, mod)\n";
168168

169169
// Now handle remote imports

lang/libs/lab/src/lab.ch

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ public interface BuildContext {
102102

103103
func getAnnotationController(&self) : *mut AnnotationController
104104

105-
func new_module(&self, scope_name : &std::string_view, name : &std::string_view, dependencies : std::span<*Module>) : *mut Module
106-
107-
func new_module_and_deps(&self, scope_name : &std::string_view, name : &std::string_view, dependencies : std::span<ModuleDependency>) : *mut Module
105+
func new_module(&self, scope_name : &std::string_view, name : &std::string_view, dependencies : std::span<ModuleDependency>) : *mut Module
108106

109107
func set_module_symbol_info(&self, module : *mut Module, index : uint, info : &DependencySymbolInfo);
110108

@@ -220,9 +218,21 @@ public interface BuildContext {
220218

221219
}
222220

221+
public func (ctx : &BuildContext) new_module_with_deps(scope_name : &std::string_view, name : &std::string_view, dependencies : std::span<*mut Module>) : *mut Module {
222+
var vec = std::vector<ModuleDependency>()
223+
vec.reserve(dependencies.size())
224+
var start = dependencies.data()
225+
const end = start + dependencies.size()
226+
while(start != end) {
227+
vec.push(ModuleDependency { module : *start as *mut Module, info : null })
228+
start++;
229+
}
230+
return ctx.new_module(scope_name, name, std::span<ModuleDependency>(vec.data(), vec.size()))
231+
}
232+
223233
// directory module
224234
public func (ctx : &BuildContext) chemical_dir_module (scope_name : &std::string_view, name : &std::string_view, path : &std::string_view, dependencies : std::span<*Module>) : *mut Module {
225-
const mod = ctx.new_module(scope_name, name, dependencies);
235+
const mod = ctx.new_module_with_deps(scope_name, name, dependencies);
226236
ctx.add_path(mod, path);
227237
return mod;
228238
}

lang/tests/build.lab

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ func get_main_module(ctx : *mut AppBuildContext, job : *mut LabJob) : *mut Modul
7070
const ext_cpp_module = ctx.cpp_file_module(std::string_view(""), std::string_view("ext_cpp"), std::string_view(ext_cpp_path), zero_deps)
7171

7272
const submod_path = lab::rel_path_to("submod")
73-
const submod = ctx.new_module(std::string_view(""), std::string_view("submod"), zero_deps)
74-
ctx.add_path(submod, std::string_view(submod_path))
73+
const submod = ctx.chemical_dir_module(std::string_view(""), std::string_view("submod"), std::string_view(submod_path), zero_deps)
7574

7675
// the std module
7776
var cstd_module = cstdMod.build(ctx, job)

0 commit comments

Comments
 (0)