MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / part1_problem

Function part1_problem

tutorials/integration/c/13_shared_module.c:96–145  ·  view source on GitHub ↗

----------------------------------------------------------------------- Part 1: The Problem — non-shared module across FileAccess boundaries Demonstrates that a module introduced into one FileAccess is NOT automatically available to compilations using a different FileAccess. -----------------------------------------------------------------------

Source from the content-addressed store, hash-verified

94// automatically available to compilations using a different FileAccess.
95// -----------------------------------------------------------------------
96static void part1_problem(void) {
97 printf("=== Part 1: The Problem -- non-shared module across FileAccess boundaries ===\n\n");
98
99 // --- 1a: Both files in the same FileAccess — works fine ---
100 {
101 das_text_writer * tout = das_text_make_printer();
102 das_module_group * libgrp = das_modulegroup_make();
103 das_file_access * fa = das_fileaccess_make_default();
104
105 das_fileaccess_introduce_file(fa, "my_helpers.das", MODULE_NOT_SHARED, 0);
106 das_fileaccess_introduce_file(fa, "user_script.das", USER_SCRIPT, 0);
107
108 das_program * program = das_program_compile("user_script.das", fa, tout, libgrp);
109 int err_count = das_program_err_count(program);
110 printf("Part 1a: same FileAccess -- compilation %s (%d error%s)\n\n",
111 err_count ? "FAILED" : "succeeded", err_count, err_count == 1 ? "" : "s");
112
113 das_program_release(program);
114 das_fileaccess_release(fa);
115 das_modulegroup_release(libgrp);
116 das_text_release(tout);
117 }
118
119 // --- 1b: Module NOT in this FileAccess — fails ---
120 {
121 das_text_writer * tout = das_text_make_writer();
122 das_module_group * libgrp = das_modulegroup_make();
123 das_file_access * fa = das_fileaccess_make_default();
124
125 // Only introduce the user script — NOT the module.
126 das_fileaccess_introduce_file(fa, "user_script.das", USER_SCRIPT, 0);
127
128 das_program * program = das_program_compile("user_script.das", fa, tout, libgrp);
129 int err_count = das_program_err_count(program);
130 printf("Part 1b: different FileAccess, module file missing -- compilation failed (%d error%s):\n",
131 err_count, err_count == 1 ? "" : "s");
132 for (int i = 0; i < err_count; i++) {
133 das_error * error = das_program_get_error(program, i);
134 char buf[1024];
135 das_error_report(error, buf, sizeof(buf));
136 printf(" error %d: %s\n", i, buf);
137 }
138 printf("\n");
139
140 das_program_release(program);
141 das_fileaccess_release(fa);
142 das_modulegroup_release(libgrp);
143 das_text_release(tout);
144 }
145}
146
147// -----------------------------------------------------------------------
148// Part 2: The Solution — `module my_helpers shared`

Callers 1

mainFunction · 0.85

Calls 14

printfFunction · 0.85
das_text_make_printerFunction · 0.85
das_modulegroup_makeFunction · 0.85
das_program_compileFunction · 0.85
das_program_err_countFunction · 0.85
das_program_releaseFunction · 0.85
das_fileaccess_releaseFunction · 0.85
das_modulegroup_releaseFunction · 0.85
das_text_releaseFunction · 0.85
das_text_make_writerFunction · 0.85

Tested by

no test coverage detected