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

Function tutorial

tests/daS/dasTestAnnotation/test_annotation.cpp:7–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 8

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

Tested by

no test coverage detected