1 #include "portability.h"
9 jsval_t jse_fnc_system_ticks(
struct js *
js, jsval_t *args,
int nargs) {
13 jsval_t js_drawRect(
struct js *
js, jsval_t *args,
int nargs) {
14 if (nargs != 5)
return js_mkundef();
15 int x = jse_getInt(
js,args[0]);
16 int y = jse_getInt(
js,args[1]);
17 int w = jse_getInt(
js,args[2]);
18 int h = jse_getInt(
js,args[3]);
19 int color = jse_getInt(
js,args[4]);
25 static jsval_t js_console_debug(
struct js *
js, jsval_t *args,
int nargs) {
26 for (
int i = 0; i < nargs; i++){
27 int type = js_type(args[i]);
29 printf(
"[Index: %d] [Type:%d] %s\n", i, type, js_str(
js,args[i]));
34 static jsval_t js_console_log(
struct js *
js, jsval_t *args,
int nargs) {
35 for (
int i = 0; i < nargs; i++){
36 qemu_log(
"%s", js_str(
js,args[i]));
41 static jsval_t js_console_note(
struct js *
js, jsval_t *args,
int nargs) {
42 for (
int i = 0; i < nargs; i++){
43 qemu_note(
"%s", js_str(
js, args[i]));
48 static jsval_t js_console_warn(
struct js *
js, jsval_t *args,
int nargs) {
49 for (
int i = 0; i < nargs; i++){
50 qemu_warn(
"%s", js_str(
js,args[i]));
55 static jsval_t js_console_err(
struct js *
js, jsval_t *args,
int nargs) {
56 for (
int i = 0; i < nargs; i++){
57 qemu_err(
"%s", js_str(
js,args[i]));
62 static jsval_t js_print(
struct js *
js, jsval_t *args,
int nargs) {
63 for (
int i = 0; i < nargs; i++){
64 tty_printf(
"%s", js_str(
js,args[i]));
69 static jsval_t js_alert(
struct js *
js, jsval_t *args,
int nargs) {
70 for (
int i = 0; i < nargs; i++){
71 const char* af = js_str(
js,args[i]);
78 static jsval_t js_nop(
struct js *
js, jsval_t *args,
int nargs) {
82 void elk_destroy(
struct js*
js){
83 jse_array_destroy(
js);
84 jse_event_destroy(
js);
85 jse_canvas_destroy(
js);
88 void elk_setup(
struct js*
js){
90 js_set(
js, js_glob(
js),
"console_debug", js_mkfun(js_console_debug));
91 js_set(
js, js_glob(
js),
"console_log", js_mkfun(js_console_log));
92 js_set(
js, js_glob(
js),
"console_warn", js_mkfun(js_console_warn));
93 js_set(
js, js_glob(
js),
"console_err", js_mkfun(js_console_err));
94 js_set(
js, js_glob(
js),
"console_note", js_mkfun(js_console_note));
95 js_set(
js, js_glob(
js),
"nop", js_mkfun(js_nop));
98 js_set(
js, js_glob(
js),
"system_ticks", js_mkfun(jse_fnc_system_ticks));
101 jse_canvas_config(
js);
104 jse_event_config(
js);
107 jse_array_config(
js);
110 js_set(
js, js_glob(
js),
"rect", js_mkfun(js_drawRect));
111 js_set(
js, js_glob(
js),
"print", js_mkfun(js_print));
112 js_set(
js, js_glob(
js),
"alert", js_mkfun(js_alert));
115 int elk_eval(
const char* buf){
116 size_t stack = 32768 +
sizeof(
struct js);
118 char* js_mem = kcalloc(stack, 1);
120 struct js *
js = js_create(js_mem, (stack));
122 qemu_err(
"\n[JSE] Runtime Fatal Error!\n\r Message: %s\n",
"No free RAM");
128 jsval_t result = js_eval(
js, buf,
strlen(buf));
133 printf(
"\n[JSE] Runtime Fatal Error!\n\r Message: %s\n",js_str(
js, result));
135 printf(
"[JSE] Result: %s\n",js_str(
js, result));
140 return (
js->isFatal == 1?0:1);
143 int elk_file(
const char* path){
146 qemu_err(
"[JSE] File no found!");
152 char* buf = kcalloc(
sizeof(
char) * (
filesize+1), 1);
155 jse_file_getBuff(buf);
size_t filesize(const char *Path)
[FileIO] Возвращает размер указанного файла
size_t strlen(const char *str)
Возращает длину строки
void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Рисуем залитый прямоугольник
void fclose(FILE *stream)
Закончить работу с файлом
FILE * fopen(const char *filename, const char *_mode)
Открывает файл
int fsize(FILE *stream)
Получение размера файла в байтах
int fread(FILE *stream, size_t count, size_t size, void *buffer)
Чтение файла
Структура файла. Требуется для работы с VFS.
size_t getTicks()
Получить количество тиков