Setup initial repo
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
result
|
||||
p.vim
|
||||
compile_commands.json
|
||||
|
||||
bin/
|
||||
build/
|
||||
.cache/
|
||||
@@ -0,0 +1,103 @@
|
||||
SRC_DIR := src
|
||||
BIN_DIR := bin
|
||||
OBJ_DIR := build
|
||||
INCLUDE_DIR := include
|
||||
|
||||
TARGET_DEBUG := $(BIN_DIR)/crib-dbg
|
||||
TARGET_RELEASE := $(BIN_DIR)/crib
|
||||
|
||||
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
|
||||
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
|
||||
|
||||
CXX ?= g++
|
||||
CC ?= gcc
|
||||
|
||||
PCRE_CFLAGS := $(shell pkg-config --cflags libpcre2-8)
|
||||
PCRE_LIBS := $(shell pkg-config --static --libs libpcre2-8)
|
||||
|
||||
LIBGRAPHEME_CFLAGS := $(shell pkg-config --cflags libgrapheme)
|
||||
LIBGRAPHEME_LIBS := $(shell pkg-config --static --libs libgrapheme)
|
||||
|
||||
MRUBY_CFLAGS ?= ./libs/mruby/build/host/include
|
||||
MRUBY_LIBS ?= ./libs/mruby/build/host/lib/libmruby.a
|
||||
|
||||
CFLAGS_DEBUG :=\
|
||||
-std=c++20 -Wall -Wextra -static \
|
||||
-O0 -fno-inline -gsplit-dwarf \
|
||||
-g -fno-omit-frame-pointer \
|
||||
-I./include -I./libs/unicode_width
|
||||
|
||||
CFLAGS_RELEASE :=\
|
||||
-std=c++20 -O3 -march=x86-64 -mtune=generic -fno-rtti \
|
||||
-fvisibility=hidden -static \
|
||||
-fomit-frame-pointer -DNDEBUG -s \
|
||||
-I./include -I./libs/unicode_width
|
||||
|
||||
CFLAGS_DEBUG += $(PCRE_CFLAGS) $(LIBGRAPHEME_CFLAGS) $(MRUBY_CFLAGS) $(C_SANITIZER)
|
||||
CFLAGS_RELEASE += $(PCRE_CFLAGS) $(LIBGRAPHEME_CFLAGS) $(MRUBY_CFLAGS)
|
||||
|
||||
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
|
||||
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
|
||||
|
||||
UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
|
||||
|
||||
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
|
||||
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
|
||||
|
||||
LIBS := $(PCRE_LIBS) $(LIBGRAPHEME_LIBS) $(MRUBY_LIBS)
|
||||
|
||||
SRC := $(wildcard $(SRC_DIR)/**/*.cc) $(wildcard $(SRC_DIR)/*.cc)
|
||||
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
|
||||
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
|
||||
|
||||
DEP_DEBUG := $(OBJ_DEBUG:.o=.d)
|
||||
DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
|
||||
|
||||
.PHONY: all debug release clean
|
||||
|
||||
all: release
|
||||
|
||||
debug: $(TARGET_DEBUG)
|
||||
|
||||
release: $(TARGET_RELEASE)
|
||||
|
||||
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(PCH_CFLAGS_DEBUG) -o $@ $<
|
||||
|
||||
$(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(PCH_CFLAGS_RELEASE) -o $@ $<
|
||||
|
||||
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
|
||||
mkdir -p $(BIN_DIR)
|
||||
$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS)
|
||||
|
||||
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
|
||||
mkdir -p $(BIN_DIR)
|
||||
$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS)
|
||||
|
||||
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG) $(GENERATED_HEADER)
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||
|
||||
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE) $(GENERATED_HEADER)
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||
|
||||
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) -MMD -MP -c $< -o $@
|
||||
|
||||
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) -MMD -MP -c $< -o $@
|
||||
|
||||
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
|
||||
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)
|
||||
|
||||
-include $(DEP_DEBUG)
|
||||
-include $(DEP_RELEASE)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR) $(BIN_DIR)
|
||||
@@ -62,6 +62,7 @@
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
libgrapheme
|
||||
pcre2
|
||||
|
||||
mruby
|
||||
];
|
||||
@@ -69,8 +70,8 @@
|
||||
buildPhase = ''
|
||||
make \
|
||||
MRBC=${mruby}/bin/mrbc \
|
||||
MRUBY_INCLUDE=${mruby}/include \
|
||||
MRUBY_LIB=${mruby}/lib/libmruby.a
|
||||
MRUBY_CFLAGS=-I${mruby}/include \
|
||||
MRUBY_LIBS=-L${mruby}/lib -lmruby
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
@@ -105,12 +106,12 @@
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export CC="ccache gcc"
|
||||
export CXX="ccache g++"
|
||||
export CC="ccache $CC"
|
||||
export CXX="ccache $CXX"
|
||||
|
||||
export MRBC=${mruby}/bin/mrbc
|
||||
export MRUBY_INCLUDE=${mruby}/include
|
||||
export MRUBY_LIB=${mruby}/lib/libmruby.a
|
||||
export MRUBY_CFLAGS=-I${mruby}/include
|
||||
export MRUBY_LIBS="-L${mruby}/lib -lmruby"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#define PCRE_WORKSPACE_SIZE 512
|
||||
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/compile.h"
|
||||
#include "mruby/hash.h"
|
||||
#include "mruby/irep.h"
|
||||
#include "mruby/string.h"
|
||||
#include <pcre2.h>
|
||||
extern "C" {
|
||||
#include "unicode_width.h"
|
||||
#include <grapheme.h>
|
||||
}
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <immintrin.h>
|
||||
#include <limits.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <poll.h>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <shared_mutex>
|
||||
#include <signal.h>
|
||||
#include <stack>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
/* Generated by unicode-width generator.
|
||||
*
|
||||
* Unicode 16.0.0 data.
|
||||
* For terminal width calculation.
|
||||
*
|
||||
* Copyright 2025 Dair Aidarkhanov
|
||||
* SPDX-License-Identifier: 0BSD
|
||||
*/
|
||||
|
||||
#ifndef UNICODE_WIDTH_H
|
||||
#define UNICODE_WIDTH_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Version of Unicode data.
|
||||
*/
|
||||
#define UNICODE_WIDTH_VERSION_MAJOR 16
|
||||
#define UNICODE_WIDTH_VERSION_MINOR 0
|
||||
#define UNICODE_WIDTH_VERSION_PATCH 0
|
||||
|
||||
/* Width state values.
|
||||
*/
|
||||
typedef enum {
|
||||
WIDTH_STATE_DEFAULT = 0,
|
||||
WIDTH_STATE_LINE_FEED = 1,
|
||||
WIDTH_STATE_EMOJI_MODIFIER = 2,
|
||||
WIDTH_STATE_REGIONAL_INDICATOR = 3,
|
||||
WIDTH_STATE_SEVERAL_REGIONAL_INDICATOR = 4,
|
||||
WIDTH_STATE_EMOJI_PRESENTATION = 5,
|
||||
WIDTH_STATE_ZWJ_EMOJI_PRESENTATION = 6,
|
||||
WIDTH_STATE_KEYCAP_ZWJ_EMOJI_PRESENTATION = 7,
|
||||
WIDTH_STATE_REGIONAL_INDICATOR_ZWJ_PRESENTATION = 8,
|
||||
WIDTH_STATE_TAG_END_ZWJ_EMOJI_PRESENTATION = 9,
|
||||
WIDTH_STATE_ZWJ_SEQUENCE_MEMBER = 10,
|
||||
} width_state_t;
|
||||
|
||||
/* State for the width calculation state machine.
|
||||
*/
|
||||
typedef struct {
|
||||
width_state_t state;
|
||||
uint_least32_t previous_codepoint;
|
||||
} unicode_width_state_t;
|
||||
|
||||
/* Initialize a unicode width state.
|
||||
* Must be called before any other function.
|
||||
*
|
||||
* @param state Pointer to state to initialize
|
||||
*/
|
||||
void unicode_width_init(unicode_width_state_t *state);
|
||||
|
||||
/* Process a Unicode codepoint and return its width.
|
||||
* Width is 0, 1, 2, or 3, or -1 for control characters.
|
||||
*
|
||||
* Control characters (0x00-0x1F except newlines, 0x7F, and 0x80-0x9F) return
|
||||
* -1, allowing the caller to decide how to display them. For readline-like
|
||||
* applications, control characters are typically displayed using caret notation
|
||||
* (^X) with width 2. Use unicode_width_control_char() to get this width.
|
||||
*
|
||||
* Newlines (LF, CR, CRLF) return width 0 as they don't consume horizontal space
|
||||
* in terminal displays.
|
||||
*
|
||||
* Note that the width of a codepoint may depend on context (preceding/following
|
||||
* codepoints), so this function keeps track of context in the provided state.
|
||||
*
|
||||
* @param state Pointer to state
|
||||
* @param codepoint Unicode codepoint to process
|
||||
* @return Width of the codepoint in columns, or -1 for control characters
|
||||
*/
|
||||
int unicode_width_process(unicode_width_state_t *state,
|
||||
uint_least32_t codepoint);
|
||||
|
||||
/* Get the display width of a control character in caret notation (e.g., ^A).
|
||||
* This is useful for applications like readline that display control chars.
|
||||
*
|
||||
* @param codepoint The Unicode codepoint to check
|
||||
* @return The display width (usually 2 for ^X notation), or -1 if not a control
|
||||
* char
|
||||
*/
|
||||
int unicode_width_control_char(uint_least32_t codepoint);
|
||||
|
||||
/* Reset a unicode width state to its initial state.
|
||||
*
|
||||
* @param state Pointer to state to reset
|
||||
*/
|
||||
void unicode_width_reset(unicode_width_state_t *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* UNICODE_WIDTH_H */
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "pch.h"
|
||||
|
||||
int main() { return 0; }
|
||||
Reference in New Issue
Block a user