Load Ruby modules

This commit is contained in:
Alex Kotov 2022-11-28 23:14:50 +04:00
parent 02205d777f
commit 3640e169fb
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,8 @@ MIT License
Copyright (c) 2022 Alex Kotov Copyright (c) 2022 Alex Kotov
Copyright (c) 2010-2022 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights

View File

@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -12,7 +13,9 @@
#include <kernaux/multiboot2.h> #include <kernaux/multiboot2.h>
#include <mruby.h> #include <mruby.h>
#include <mruby/compile.h>
#include <mruby/presym.h> #include <mruby/presym.h>
#include <mruby/proc.h>
#include <mruby/string.h> #include <mruby/string.h>
#define PANIC(msg) (assert(__FILE__, __LINE__, msg)) #define PANIC(msg) (assert(__FILE__, __LINE__, msg))
@ -22,6 +25,7 @@ static struct KernAux_FreeList allocator;
static uint8_t memory[1024 * 128]; // 128 KiB static uint8_t memory[1024 * 128]; // 128 KiB
static mrb_state *mrb = NULL; static mrb_state *mrb = NULL;
static mrbc_context *context = NULL;
static void assert(const char *file, int line, const char *str); static void assert(const char *file, int line, const char *str);
@ -73,6 +77,8 @@ void main(
kernaux_drivers_console_print(RSTRING_CSTR(mrb, hello)); kernaux_drivers_console_print(RSTRING_CSTR(mrb, hello));
} }
ASSERT(context = mrbc_context_new(mrb));
{ {
const char *cmdline = ""; const char *cmdline = "";
@ -110,6 +116,20 @@ void main(
kernaux_drivers_console_print("----------------------------------------\n"); kernaux_drivers_console_print("----------------------------------------\n");
kernaux_drivers_console_write(source, size); kernaux_drivers_console_write(source, size);
if (source[size - 1] != '\n') kernaux_drivers_console_putc('\n'); if (source[size - 1] != '\n') kernaux_drivers_console_putc('\n');
const int arena = mrb_gc_arena_save(mrb);
__attribute__((unused))
const bool status = !mrb_undef_p(
mrb_load_nstring_cxt(mrb, source, size, context)
);
struct REnv *const env = mrb_vm_ci_env(mrb->c->cibase);
mrb_vm_ci_env_set(mrb->c->cibase, NULL);
mrb_env_unshare(mrb, env, FALSE);
mrbc_cleanup_local_variables(mrb, context);
mrb_gc_arena_restore(mrb, arena);
} }
} }