Skip to content

Instantly share code, notes, and snippets.

View MrSmith33's full-sized avatar

Andrey Penechko MrSmith33

View GitHub Profile
@MrSmith33
MrSmith33 / sublime_d_error_regex.txt
Last active January 31, 2023 21:43
Sublime text regexp for matching D error messages
Regular expression for matching error messages in Sublime Text.
Insert into `file_regex` parameter of `.sublime-project` file. Then clicking the line with error message opens correct source file.
--- Escaped for file_regex (\ -> \\)
^(?:\\s*)(?:.*(?: at |@))?((?:[^\\(: ]|:(?!\\d))+)(?:\\(|:)(\\d+)(?:(?:,|:)(\\d+))?\\)?(?:: (.*))?
--- Raw regex (developed with https://regexr.com, used flags: global, multiline)
^(?:\s*)(?:.*(?: at |@))?((?:[^\(: ]|:(?!\d))+)(?:\(|:)(\d+)(?:(?:,|:)(\d+))?\)?(?:: (.*))?
--- Matches
import std.stdio;
void main() {
foreach(kw; keyword_strings) {
TokenType t = identifier_to_keyword(kw);
writefln("%s %s", kw, t);
}
}
TokenType identifier_to_keyword(const(char[]) tok) {
@MrSmith33
MrSmith33 / lex4.d
Created November 20, 2021 12:45
FSA based lexer for Vox
import std.stdio;
import std.format;
// First attribute goes into IN_TOKEN table
enum State : ubyte {
// intermediate states
@(1) i_invalid,
@(1) i_id1, // _a-zA-Z
@(1) i_id2, // _a-zA-Z0-9
@MrSmith33
MrSmith33 / hello_vox.vx
Last active November 16, 2021 20:56
Cross-platform Vox hello world
// > vox hello_vox.vx && hello_vox
// hello windows
// > vox hello_vox.vx --target=linux-x64
// > wsl ./hello_vox
// hello linux
#version(windows) {
@extern(module, "kernel32"):
enum u32 stdin = 0xFFFFFFF6;
import std.array;
import std.format;
import std.string;
import std.file : write;
void main()
{
string dir = `D:/sources/my_sources/tiny_jit/test_work_dir`;
foreach(s; [10,100,1000,10_000,100_000,1000_000]) {
//make_source_c(dir, s);
//make_source_d(dir, s);

Binding an external function definition to a dynamic/shared library

How it works now:

User defines an external function:

noreturn ExitProcess(u32 uExitCode);
void main() {
 ExitProcess(0);

Compressing token info

I measured my biggest code base written in Vox (which is mostly Vulkan bindings atm) and got the following numbers:

  • 88140 tokens
  • 17771 lines
  • 4.95977 tokens/line on average
  • 1 305 227 bytes of source code
  • 1 410 240 bytes of token information

Source code: https://github.com/MrSmith33/voxelman/blob/master/source/voxelman/gui

Core widget components (https://github.com/MrSmith33/voxelman/blob/master/source/voxelman/gui/components.d):

  • WidgetTransform - main component of any widget. Stores parent reference, relative position, absolute position, size, min size, measured size, and extra flags
  • WidgetStyle - color and border color
  • WidgetName - string of widget name
  • WidgetType - string of widget type (for debugging)
  • WidgetContainer - children widgets
  • WidgetIsFocusable - if set becomes focusedWidget on pointer press. focusedWidget will receive key and char events.
  • WidgetEvents - stores handlers for any event for the widget. Typical events:
@MrSmith33
MrSmith33 / fib.vx
Last active July 13, 2021 22:49
Vox fibonacci
// Windows> vox fib.vx C:\Windows\System32\kernel32.dll
// Linux> vox fib.vx
i64 fibR(i64 n)
{
if (n < 2) return n;
return (fibR(n-2) + fibR(n-1));
}
void main()
@MrSmith33
MrSmith33 / vector.d
Created May 7, 2021 22:59
Vector thingy
import std.stdio;
void main()
{
/*
(vec2(1,5)-ivec2(9,9)).writeln;
vec2 v;
enum size = v.data.length;
*/
import std.math;