hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
runtime.cpp
Go to the documentation of this file.
1#include "runtime.h"
4
5// mimalloc requirement
6#ifdef _WIN32
7#pragma comment(lib, "Advapi32.lib")
8#endif
9
10#include <cstdio>
11#include <cstring>
12
13const char ** yoi_argv{};
15
16int elysia_main(int argc, char *argv[]) {
17 yoi_argv = (const char **)argv;
18 yoi_argc = argc;
19 #if defined(ELYSIA_RUNTIME_HPERF_ENABLE)
20 char *enable_hperf = nullptr;
21 for (int i = 0; i < argc; i++) {
22 if (strcmp(argv[i], "--perf") == 0) {
23 printf("[ELysia/INFO] hoshi-lang runtime: hperf enabled.\n");
24 if (i + 1 >= argc) {
25 printf("[Elysia/ERROR] hoshi-lang runtime: --perf option requires an argument.\n");
26 return -1;
27 }
28 enable_hperf = argv[i + 1];
29 }
30 }
31 if (enable_hperf)
32 hperf_init(enable_hperf);
33 #endif
34 #if defined(ELYSIA_RUNTIME_BUILD_TYPE_DEBUG) || defined(ELYSIA_RUNTIME_BUILD_PRESERVE_BASIC_INFORMATION)
35 printf("[Elysia/DEBUG] hoshi-lang descriptor: %s, build_type: %llu. Runtime linked, invoking yoimiya_entry()...\n", &yoi_desc, yoi_build_type);
36 #endif
38 int resultVal = static_cast<int>(result->value);
39 basic_int_gc_refcount_decrease(result);
40 #if defined(ELYSIA_RUNTIME_BUILD_TYPE_DEBUG) || defined(ELYSIA_RUNTIME_BUILD_PRESERVE_BASIC_INFORMATION)
41 printf("[Elysia/DEBUG] hoshi-lang runtime finished, result: %d.\n", resultVal);
42 #endif
43#if defined(ELYSIA_RUNTIME_ENABLE_BUILTIN_MEMORY_LEAK_DETECTOR)
44 if (runtime_object_allocated > 0) {
45 printf("[Elysia/WARNING] hoshi-lang runtime finished with %lld objects allocated, memory leaks detected!\nargv[0]: %s\n", runtime_object_allocated, argv[0]);
46#if defined(ELYSIA_RUNTIME_BUILD_TYPE_DEBUG)
47 runtime_debug_print_current_allocated_memory();
48#endif
49 return -11;
50 }
51#endif
52 #if defined(ELYSIA_RUNTIME_HPERF_ENABLE)
53 if (enable_hperf) {
55 }
56 #endif
57 return resultVal;
58}
59
61 auto *argv = (YoiObjectArray *)runtime_object_alloc(sizeof(YoiObjectArray) + yoi_argc * sizeof(char *));
62 argv->gc_refcount = 1;
63 argv->type_id = 11;
64 argv->length = yoi_argc;
65 auto **argv_start = (const char **)((char *)&argv->data);
66 for (int i = 0; i < yoi_argc; i++) {
67 argv_start[i] = yoi_argv[i];
68 }
69 return argv;
70}
71
72void runtime_panic(char *message) {
73 fprintf(stderr, "%s\n", message);
74 exit(1);
75}
76
78 return stdin;
79}
80
82 return stdout;
83}
84
86 return stderr;
87}
char hperf_report_filename[2048]
Definition hperf.cpp:14
void hperf_write_report(const char *filename)
Definition hperf.cpp:118
void hperf_init(const char *filename)
Definition hperf.cpp:202
void * runtime_object_alloc(unsigned long size)
Definition memory.cpp:96
int elysia_main(int argc, char *argv[])
Definition runtime.cpp:16
void * runtime_get_stdin_fp()
Definition runtime.cpp:77
const char ** yoi_argv
Definition runtime.cpp:13
YoiObjectArray * runtime_get_argv()
Definition runtime.cpp:60
void * runtime_get_stdout_fp()
Definition runtime.cpp:81
int yoi_argc
Definition runtime.cpp:14
void runtime_panic(char *message)
Definition runtime.cpp:72
void * runtime_get_stderr_fp()
Definition runtime.cpp:85
char yoi_desc
Definition runtime.h:21
YoiIntegerObject * yoimiya_entry()
const unsigned long long yoi_build_type
Definition runtime.h:23
long long value
Definition memory.h:28
unsigned long long gc_refcount
Definition memory.h:19