feat: initial commit

This commit is contained in:
2023-10-11 21:51:24 +02:00
commit 8709837ef1
128 changed files with 2464 additions and 0 deletions

0
.emacs.local/.gitkeep Executable file
View File

75
.emacs.local/basm-mode.el Executable file
View File

@@ -0,0 +1,75 @@
;;; basm-mode.el --- Major Mode for editing BASM Assembly Code -*- lexical-binding: t -*-
;; Copyright (C) 2021 Alexey Kutepov <reximkut@gmail.com>
;; Author: Alexey Kutepov <reximkut@gmail.com>
;; URL: http://github.com/tsoding/bm
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;
;; Major Mode for editing BASM Assembly Code. The language for a
;; simple Virtual Machine.
(defconst basm-mode-syntax-table
(with-syntax-table (copy-syntax-table)
(modify-syntax-entry ?\; "<")
(modify-syntax-entry ?\n ">")
(modify-syntax-entry ?\" "\"")
(modify-syntax-entry ?\' "\"")
(syntax-table))
"Syntax table for `basm-mode'.")
(eval-and-compile
(defconst basm-instructions
'("nop" "push" "drop" "dup"
"plusi" "minusi" "multi" "divi" "modi"
"multu" "divu" "modu"
"plusf" "minusf" "multf" "divf"
"jmp" "jmp_if" "halt" "swap" "not"
"eqi" "gei" "gti" "lei" "lti" "nei"
"equ" "geu" "gtu" "leu" "ltu" "neu"
"eqf" "gef" "gtf" "lef" "ltf" "nef"
"ret" "call" "native"
"andb" "orb" "xor" "shr" "shl" "notb"
"read8u" "read16u" "read32u" "read64u"
"read8i" "read16i" "read32i" "read64i"
"write8" "write16" "write32" "write64"
"i2f" "u2f" "f2i" "f2u")))
(defconst basm-highlights
`(("%[[:word:]_]+" . font-lock-preprocessor-face)
("[[:word:]_]+\\:" . font-lock-constant-face)
(,(regexp-opt basm-instructions 'symbols) . font-lock-keyword-face)))
;;;###autoload
(define-derived-mode basm-mode fundamental-mode "basm"
"Major Mode for editing BASM Assembly Code."
(setq font-lock-defaults '(basm-highlights))
(set-syntax-table basm-mode-syntax-table))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.\\(b\\|h\\)asm\\'" . basm-mode))
(provide 'basm-mode)
;;; basm-mode.el ends here

214
.emacs.local/jai-mode.el Executable file
View File

@@ -0,0 +1,214 @@
;; jai-mode.el - very basic jai mode
(require 'cl)
(require 'rx)
(require 'js)
(require 'compile)
(defconst jai-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?\\ "\\" table)
;; additional symbols
(modify-syntax-entry ?_ "w" table)
(modify-syntax-entry ?' "." table)
(modify-syntax-entry ?: "." table)
(modify-syntax-entry ?+ "." table)
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?% "." table)
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?| "." table)
(modify-syntax-entry ?^ "." table)
(modify-syntax-entry ?! "." table)
(modify-syntax-entry ?$ "/" table)
(modify-syntax-entry ?= "." table)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?? "." table)
;; Modify some syntax entries to allow nested block comments
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23n" table)
(modify-syntax-entry ?\n "> b" table)
(modify-syntax-entry ?\^m "> b" table)
table))
(defconst jai-builtins
'("cast" "it" "type_info" "size_of"))
(defconst jai-keywords
'("if" "ifx" "else" "then" "while" "for" "switch" "case" "struct" "enum"
"return" "new" "remove" "continue" "break" "defer" "inline" "no_inline"
"using" "SOA"))
(defconst jai-constants
'("null" "true" "false"))
(defconst jai-typenames
'("int" "u64" "u32" "u16" "u8"
"s64" "s32" "s16" "s8" "float"
"float32" "float64" "string"
"bool"))
(defun jai-wrap-word-rx (s)
(concat "\\<" s "\\>"))
(defun jai-keywords-rx (keywords)
"build keyword regexp"
(jai-wrap-word-rx (regexp-opt keywords t)))
(defconst jai-hat-type-rx (rx (group (and "^" (1+ word)))))
(defconst jai-dollar-type-rx (rx (group "$" (or (1+ word) (opt "$")))))
(defconst jai-number-rx
(rx (and
symbol-start
(or (and (+ digit) (opt (and (any "eE") (opt (any "-+")) (+ digit))))
(and "0" (any "xX") (+ hex-digit)))
(opt (and (any "_" "A-Z" "a-z") (* (any "_" "A-Z" "a-z" "0-9"))))
symbol-end)))
(defconst jai-font-lock-defaults
`(
;; Keywords
(,(jai-keywords-rx jai-keywords) 1 font-lock-keyword-face)
;; single quote characters
("\\('[[:word:]]\\)\\>" 1 font-lock-constant-face)
;; Variables
(,(jai-keywords-rx jai-builtins) 1 font-lock-variable-name-face)
;; Constants
(,(jai-keywords-rx jai-constants) 1 font-lock-constant-face)
;; Hash directives
("#\\w+" . font-lock-preprocessor-face)
;; At directives
("@\\w+" . font-lock-preprocessor-face)
;; Strings
("\\\".*\\\"" . font-lock-string-face)
;; Numbers
(,(jai-wrap-word-rx jai-number-rx) . font-lock-constant-face)
;; Types
(,(jai-keywords-rx jai-typenames) 1 font-lock-type-face)
(,jai-hat-type-rx 1 font-lock-type-face)
(,jai-dollar-type-rx 1 font-lock-type-face)
("---" . font-lock-constant-face)
))
;; add setq-local for older emacs versions
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
`(set (make-local-variable ',var) ,val)))
(defconst jai--defun-rx "\(.*\).*\{")
(defmacro jai-paren-level ()
`(car (syntax-ppss)))
(defun jai-line-is-defun ()
"return t if current line begins a procedure"
(interactive)
(save-excursion
(beginning-of-line)
(let (found)
(while (and (not (eolp)) (not found))
(if (looking-at jai--defun-rx)
(setq found t)
(forward-char 1)))
found)))
(defun jai-beginning-of-defun (&optional count)
"Go to line on which current function starts."
(interactive)
(let ((orig-level (jai-paren-level)))
(while (and
(not (jai-line-is-defun))
(not (bobp))
(> orig-level 0))
(setq orig-level (jai-paren-level))
(while (>= (jai-paren-level) orig-level)
(skip-chars-backward "^{")
(backward-char))))
(if (jai-line-is-defun)
(beginning-of-line)))
(defun jai-end-of-defun ()
"Go to line on which current function ends."
(interactive)
(let ((orig-level (jai-paren-level)))
(when (> orig-level 0)
(jai-beginning-of-defun)
(end-of-line)
(setq orig-level (jai-paren-level))
(skip-chars-forward "^}")
(while (>= (jai-paren-level) orig-level)
(skip-chars-forward "^}")
(forward-char)))))
(defalias 'jai-parent-mode
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
;; imenu hookup
(add-hook 'jai-mode-hook
(lambda ()
(setq imenu-generic-expression
'(
("type" "^\\(.*:*.*\\) : " 1)
("function" "^\\(.*\\) :: " 1)
("struct" "^\\(.*\\) *:: *\\(struct\\)\\(.*\\){" 1)
)
)
)
)
;; NOTE: taken from the scala-indent package and modified for Jai.
;; Still uses the js-indent-line as a base, which will have to be
;; replaced when the language is more mature.
(defun jai--indent-on-parentheses ()
(when (and (= (char-syntax (char-before)) ?\))
(= (save-excursion (back-to-indentation) (point)) (1- (point))))
(js-indent-line)))
(defun jai--add-self-insert-hooks ()
(add-hook 'post-self-insert-hook
'jai--indent-on-parentheses)
)
;;;###autoload
(define-derived-mode jai-mode jai-parent-mode "Jai"
:syntax-table jai-mode-syntax-table
:group 'jai
(setq bidi-paragraph-direction 'left-to-right)
(setq-local require-final-newline mode-require-final-newline)
(setq-local parse-sexp-ignore-comments t)
(setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
(setq-local comment-start "/*")
(setq-local comment-end "*/")
(setq-local indent-line-function 'js-indent-line)
(setq-local font-lock-defaults '(jai-font-lock-defaults))
(setq-local beginning-of-defun-function 'jai-beginning-of-defun)
(setq-local end-of-defun-function 'jai-end-of-defun)
;; add indent functionality to some characters
(jai--add-self-insert-hooks)
(font-lock-fontify-buffer))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.jai\\'" . jai-mode))
(defconst jai--error-regexp
"^\\([^ :]+\\):\\([0-9]+\\),\\([0-9]+\\):")
(push `(jai ,jai--error-regexp 1 2 3 2) compilation-error-regexp-alist-alist)
(push 'jai compilation-error-regexp-alist)
(provide 'jai-mode)

86
.emacs.local/noq-mode.el Executable file
View File

@@ -0,0 +1,86 @@
;;; noq-mode.el --- Major Mode for editing Noq source code -*- lexical-binding: t -*-
;; Copyright (C) 2021 Alexey Kutepov <reximkut@gmail.com>
;; Author: Alexey Kutepov <reximkut@gmail.com>
;; URL: https://github.com/tsoding/noq
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;
;; Major Mode for editing Noq source code
(defconst noq-mode-syntax-table
(with-syntax-table (copy-syntax-table)
;; Python-style comments
(modify-syntax-entry ?# "<")
(modify-syntax-entry ?\n ">")
;; C/C++ style comments
(modify-syntax-entry ?/ ". 124b")
(modify-syntax-entry ?* ". 23")
(modify-syntax-entry ?\n "> b")
;; (modify-syntax-entry ?/ ". 124b")
;; (modify-syntax-entry ?* ". 23")
;; (modify-syntax-entry ?\n "> b")
;; Chars are the same as strings
(modify-syntax-entry ?' "\"")
(syntax-table))
"Syntax table for `noq-mode'.")
(eval-and-compile
(defconst noq-apply-strategies
'("all" "deep")))
(eval-and-compile
(defconst noq-keywords
'("undo" "quit" "delete" "load" "save")))
(defconst noq-highlights
`((
;; Keywords
,(regexp-opt noq-keywords 'words) . 'font-lock-keyword-face)
;; `Apply` strategies
(,(format "\\(%s\\)[\t ]*|" (mapconcat 'regexp-quote noq-apply-strategies "\\|"))
1 'font-lock-type-face)
("\\([0-9]+\\)[\t ]*|" 1 'font-lock-type-face)
;; Variables
("\\(^\\|[^a-zA-Z0-9_]\\)\\([_A-Z][_a-zA-Z0-9]*\\)" 2 'font-lock-variable-name-face)
;; Functor names
("\\([^\n\| ]*\\)[\t ]*::" 1 'font-lock-function-name-face)
))
;;;###autoload
(define-derived-mode noq-mode prog-mode "noq"
"Major Mode for editing Noq source code."
:syntax-table noq-mode-syntax-table
(setq font-lock-defaults '(noq-highlights))
(setq-local comment-start "// "))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.noq\\'" . noq-mode))
(provide 'noq-mode)
;;; noq-mode.el ends here

26
.emacs.local/nothings-mode.el Executable file
View File

@@ -0,0 +1,26 @@
(require 'subr-x)
(defvar nothings-mode-syntax-table
(let ((table (make-syntax-table)))
;; C/C++ style comments
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23" table)
(modify-syntax-entry ?\n "> b" table)
;; Preprocessor stuff?
(modify-syntax-entry ?# "." table)
;; Chars are the same as strings
(modify-syntax-entry ?' "\"" table)
table))
(defun nothings-font-lock-keywords ()
(list
`("# *[a-zA-Z0-9_]+" . font-lock-preprocessor-face)
`("#.*include \\(\\(<\\|\"\\).*\\(>\\|\"\\)\\)" . (1 font-lock-string-face))))
(define-derived-mode nothings-mode prog-mode "Nothings"
"Simple major mode for editing C files."
:syntax-table nothings-mode-syntax-table
(setq-local font-lock-defaults '(nothings-font-lock-keywords))
(setq-local comment-start "//"))
(provide 'nothings-mode)

70
.emacs.local/porth-mode.el Executable file
View File

@@ -0,0 +1,70 @@
;;; porth-mode.el --- Major Mode for editing Porth source code -*- lexical-binding: t -*-
;; Copyright (C) 2021 Alexey Kutepov <reximkut@gmail.com>
;; Author: Alexey Kutepov <reximkut@gmail.com>
;; URL: https://github.com/tsoding/porth
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;
;; Major Mode for editing Porth source code. It's Forth but written in Python.
;; TODO: jump to the opposite side of the blocks with C-M-f and C-M-b
;; I think tuareg-mode can do that with similar end-like block, we try
;; to steal their approach
;; TODO: color the names of definitions in const, memory, proc, etc differently
(defconst porth-mode-syntax-table
(with-syntax-table (copy-syntax-table)
;; C/C++ style comments
(modify-syntax-entry ?/ ". 124b")
(modify-syntax-entry ?* ". 23")
(modify-syntax-entry ?\n "> b")
;; Chars are the same as strings
(modify-syntax-entry ?' "\"")
(syntax-table))
"Syntax table for `porth-mode'.")
(eval-and-compile
(defconst porth-keywords
'("if" "else" "while" "do" "include" "memory" "proc"
"const" "end" "offset" "reset" "assert" "in" "inline"
"here" "addr-of" "call-like" "let" "peek" "return"
"var" "cast" "struct")))
(defconst porth-highlights
`((,(regexp-opt porth-keywords 'symbols) . font-lock-keyword-face)))
;;;###autoload
(define-derived-mode porth-mode prog-mode "porth"
"Major Mode for editing Porth source code."
:syntax-table porth-mode-syntax-table
(setq font-lock-defaults '(porth-highlights))
(setq-local comment-start "// "))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.porth\\'" . porth-mode))
(provide 'porth-mode)
;;; porth-mode.el ends here

99
.emacs.local/simpc-mode.el Executable file
View File

@@ -0,0 +1,99 @@
(require 'subr-x)
(defvar simpc-mode-syntax-table
(let ((table (make-syntax-table)))
;; C/C++ style comments
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23" table)
(modify-syntax-entry ?\n "> b" table)
;; Preprocessor stuff?
(modify-syntax-entry ?# "." table)
;; Chars are the same as strings
(modify-syntax-entry ?' "\"" table)
;; Treat <> as punctuation (needed to highlight C++ keywords
;; properly in template syntax)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?% "." table)
table))
(defun simpc-types ()
'("char" "int" "long" "short" "void" "bool" "float" "double" "signed" "unsigned"
"char16_t" "char32_t" "char8_t"
"int8_t" "uint8_t" "int16_t" "uint16_t" "int32_t" "uint32_t" "int64_t" "uint64_t"
"uintptr_t"
"size_t"))
(defun simpc-keywords ()
'("auto" "break" "case" "const" "continue" "default" "do"
"else" "enum" "extern" "for" "goto" "if" "register"
"return" "sizeof" "static" "struct" "switch" "typedef"
"union" "volatile" "while" "alignas" "alignof" "and"
"and_eq" "asm" "atomic_cancel" "atomic_commit" "atomic_noexcept" "bitand"
"bitor" "catch" "class" "co_await"
"co_return" "co_yield" "compl" "concept" "const_cast" "consteval" "constexpr"
"constinit" "decltype" "delete" "dynamic_cast" "explicit" "export" "false"
"friend" "inline" "mutable" "namespace" "new" "noexcept" "not" "not_eq"
"nullptr" "operator" "or" "or_eq" "private" "protected" "public" "reflexpr"
"reinterpret_cast" "requires" "static_assert" "static_cast" "synchronized"
"template" "this" "thread_local" "throw" "true" "try" "typeid" "typename"
"using" "virtual" "wchar_t" "xor" "xor_eq"))
(defun simpc-font-lock-keywords ()
(list
`("# *[#a-zA-Z0-9_]+" . font-lock-preprocessor-face)
`("#.*include \\(\\(<\\|\"\\).*\\(>\\|\"\\)\\)" . (1 font-lock-string-face))
`(,(regexp-opt (simpc-keywords) 'symbols) . font-lock-keyword-face)
`(,(regexp-opt (simpc-types) 'symbols) . font-lock-type-face)))
;;; TODO: try to replace simpc--space-prefix-len with current-indentation
(defun simpc--space-prefix-len (line)
(- (length line)
(length (string-trim-left line))))
(defun simpc--previous-non-empty-line ()
(save-excursion
(forward-line -1)
(while (and (not (bobp))
(string-empty-p
(string-trim-right
(thing-at-point 'line t))))
(forward-line -1))
(thing-at-point 'line t)))
(defun simpc--desired-indentation ()
(let ((cur-line (string-trim-right (thing-at-point 'line t)))
(prev-line (string-trim-right (simpc--previous-non-empty-line)))
(indent-len 4))
(cond
((and (string-suffix-p "{" prev-line)
(string-prefix-p "}" (string-trim-left cur-line)))
(simpc--space-prefix-len prev-line))
((string-suffix-p "{" prev-line)
(+ (simpc--space-prefix-len prev-line) indent-len))
((string-prefix-p "}" (string-trim-left cur-line))
(max (- (simpc--space-prefix-len prev-line) indent-len) 0))
(t (simpc--space-prefix-len prev-line)))))
;;; TODO: customizable indentation (amount of spaces, tabs, etc)
(defun simpc-indent-line ()
(interactive)
(when (not (bobp))
(let* ((current-indentation
(simpc--space-prefix-len (thing-at-point 'line t)))
(desired-indentation
(simpc--desired-indentation))
(n (max (- (current-column) current-indentation) 0)))
(indent-line-to desired-indentation)
(forward-char n))))
(define-derived-mode simpc-mode prog-mode "Simple C"
"Simple major mode for editing C files."
:syntax-table simpc-mode-syntax-table
(setq-local font-lock-defaults '(simpc-font-lock-keywords))
(setq-local indent-line-function 'simpc-indent-line)
(setq-local comment-start "// "))
(provide 'simpc-mode)