MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / tutorial

Function tutorial

tests/daS/dasCo/main.cpp:9–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#define TUTORIAL_NAME u8"/scripts/daSCo/co.das"
8
9int tutorial () {
10 // output stream for all compiler messages (stdout. for stringstream use TextWriter)
11 auto tout_desc = make_zeroed<skr::das::TextPrinterDescriptor>();
12 auto tout = skr::das::TextPrinter::Create(tout_desc);
13
14 // module group for compiled program
15 auto lib_desc = make_zeroed<skr::das::LibraryDescriptor>();
16 auto library = skr::das::Library::Create(lib_desc);
17
18 // default file access
19 auto faccess_desc = make_zeroed<skr::das::FileAccessDescriptor>();
20 auto faccess = skr::das::FileAccess::Create(faccess_desc);
21
22 skr::das::CompileDescriptor policies; // compiler setup
23#ifdef AOT
24 policies.aot = true;
25#endif
26 // compile program
27 skr::String script_path = skr::das::Environment::GetRootDir();
28 script_path += TUTORIAL_NAME;
29 auto program = skr::das::Environment::compile_dascript(
30 script_path.u8_str(), faccess, tout, library, &policies);
31 if (!program) return -1;
32
33 // create context
34 auto ctx_desc = make_zeroed<skr::das::ContextDescriptor>();
35 ctx_desc.stack_size = program->get_ctx_stack_size();
36 auto ctx = skr::das::Context::Create(ctx_desc);
37 if ( !program->simulate(ctx, tout) ) return -2;
38
39 // find function. its up to application to check, if function is not null
40 auto function = ctx->find_function(u8"test");
41 if ( !function )
42 {
43 tout->print(u8"function 'test' not found\n");
44 return -3;
45 }
46
47 // evaluate 'test' function in the context
48 skr::das::Sequence seq;
49 ctx->eval_with_catch(function, nullptr, &seq);
50
51 while ( seq.dispatch(ctx) ) { tout->print(u8"...\n"); }
52
53 skr::das::Context::Free(ctx);
54 skr::das::Program::Free(program);
55 skr::das::Library::Free(library);
56 skr::das::TextPrinter::Free(tout);
57 skr::das::FileAccess::Free(faccess);
58 return 0;
59}
60
61int main( int argc, char **argv ) {
62 // Initialize modules

Callers 1

mainFunction · 0.70

Calls 9

FreeFunction · 0.85
get_ctx_stack_sizeMethod · 0.80
find_functionMethod · 0.80
eval_with_catchMethod · 0.80
CreateFunction · 0.50
u8_strMethod · 0.45
simulateMethod · 0.45
printMethod · 0.45
dispatchMethod · 0.45

Tested by

no test coverage detected