Use embedded mruby for portablity

This commit is contained in:
2026-01-29 13:52:46 +00:00
parent 9757a8db31
commit eafed64bea
204 changed files with 234 additions and 40822 deletions

View File

@@ -4,11 +4,12 @@
#define PCRE2_CODE_UNIT_WIDTH 8
#define PCRE_WORKSPACE_SIZE 512
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include "ruby/ruby.h"
#pragma clang diagnostic pop
#include <magic.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/compile.h>
#include <mruby/hash.h>
#include <mruby/string.h>
#include <nlohmann/json.hpp>
#include <pcre2.h>
extern "C" {

View File

@@ -4,7 +4,7 @@
#include "syntax/decl.h"
#include "utils/utils.h"
extern std::unordered_map<std::string, std::pair<VALUE, VALUE>>
extern std::unordered_map<std::string, std::pair<mrb_value, mrb_value>>
custom_highlighters;
void ruby_start();
@@ -14,9 +14,9 @@ void load_theme();
void load_languages_info();
uint8_t read_line_endings();
void load_custom_highlighters();
VALUE parse_custom(std::vector<Token> *tokens, VALUE parser_block,
const char *line, uint32_t len, VALUE state,
uint32_t line_num);
bool custom_compare(VALUE match_block, VALUE state1, VALUE state2);
mrb_value parse_custom(std::vector<Token> *tokens, mrb_value parser_block,
const char *line, uint32_t len, mrb_value state,
uint32_t c_line);
bool custom_compare(mrb_value match_block, mrb_value state1, mrb_value state2);
#endif

View File

@@ -38,10 +38,7 @@ constexpr const char tokens_def[] = "module Tokens\n"
"end";
constexpr const char crib_module[] = {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc23-extensions"
#embed "libcrib.rb"
#pragma clang diagnostic pop
, '\0'};
extern std::array<Highlight, TOKEN_KIND_COUNT> highlights;
@@ -59,9 +56,8 @@ struct LineData {
};
struct CustomState {
VALUE state;
CustomState(VALUE s) : state(s) { rb_gc_register_address(&state); }
~CustomState() { rb_gc_unregister_address(&state); }
mrb_value state;
CustomState(mrb_value s) : state(s) {}
};
#endif

View File

@@ -14,8 +14,8 @@ struct Parser {
uint32_t line_num);
bool (*state_match_func)(std::shared_ptr<void> state_1,
std::shared_ptr<void> state_2);
VALUE parser_block = Qnil;
VALUE match_block = Qnil;
mrb_value parser_block = mrb_nil_value();
mrb_value match_block = mrb_nil_value();
bool is_custom{false};
std::atomic<uint32_t> scroll_max{UINT32_MAX - 2048};
std::atomic<bool> scroll_dirty{false};