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

Function main

tests/daS/dasStackwalk/main.cpp:7–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#define TUTORIAL_NAME u8"/scripts/dasStackWalk/stackwalk.das"
6
7int main(int argc, char** argv) {
8 auto env_desc = make_zeroed<skr::das::EnvironmentDescriptor>();
9 env_desc.argc = argc;
10 env_desc.argv = argv;
11 skr::das::Environment::Initialize(env_desc);
12 // make file access, introduce string as if it was a file
13 auto faccess_desc = make_zeroed<skr::das::FileAccessDescriptor>();
14 auto faccess = skr::das::FileAccess::Create(faccess_desc);
15
16 // output stream for all compiler messages (stdout. for stringstream use TextWriter)
17 auto tout_desc = make_zeroed<skr::das::TextPrinterDescriptor>();
18 auto tout = skr::das::TextPrinter::Create(tout_desc);
19
20 // module group for compiled program
21 auto lib_desc = make_zeroed<skr::das::LibraryDescriptor>();
22 auto library = skr::das::Library::Create(lib_desc);
23
24 // compile script
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);
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"main");
39 if ( !function ) return -3;
40
41 // call context function
42 ctx->eval(function);
43
44 skr::das::Context::Free(ctx);
45 skr::das::Program::Free(program);
46 skr::das::Library::Free(library);
47 skr::das::TextPrinter::Free(tout);
48 skr::das::FileAccess::Free(faccess);
49 skr::das::Environment::Finalize();
50 return 0;
51}

Callers

nothing calls this directly

Calls 8

InitializeFunction · 0.85
FreeFunction · 0.85
get_ctx_stack_sizeMethod · 0.80
find_functionMethod · 0.80
CreateFunction · 0.50
u8_strMethod · 0.45
simulateMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected