about summary refs log blame commit diff stats
path: root/subx.el
blob: 8d92c78e08a6e8505fc205ba76192edab0b7beda (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                                       
                                                             



























                                                                                           
;;; Emacs major mode for editing SubX files. -*- coding: utf-8; lexical-binding: t; -*-

;; Author: Kartik Agaram (subx.el@akkartik.com)
;; Version: 0.0.1
;; Created: 28 Dec 2019
;; Keywords: languages
;; Homepage: https://github.com/akkartik/mu

;;; Commentary:

;; I don't know how to define new faces in an emacs package, so I'm
;; cannibalizing existing faces.
;;
;; I load this file like so in my .emacs:
;;    (load "/absolute/path/to/subx.el")
;;    (add-to-list 'auto-mode-alist '("\\.subx" . subx-mode))
;;
;; Education on the right way to do this most appreciated.

(setq subx-font-lock-keywords
  '(
    ; tests
    ("^test-[^ ]*:" . font-lock-type-face)
    ; functions
    ("^[a-z][^ ]*:" . font-lock-function-name-face)
    ; globals
    ("^[A-Z][^ ]*:" . font-lock-variable-name-face)
    ; minor labels
    ("^[^a-zA-Z#( ][^ ]*:" . font-lock-doc-face)
    ; string literals
    ; ("\"[^\"]*\"" . font-lock-constant-face)  ; strings colorized already, albeit buggily
    ; 4 colors for comments; ugly but functional
    ("# \\. \\. .*" . font-lock-doc-face)
    ("# \\. .*" . font-lock-constant-face)
    ("# - .*" . font-lock-comment-face)
    ("#.*" . font-lock-preprocessor-face)
    ))

(define-derived-mode subx-mode fundamental-mode "subx mode"
  "Major mode for editing SubX (Mu project)"
  (setq font-lock-defaults '((subx-font-lock-keywords)))
  )

(provide 'subx-mode)
. . . . 4/imm32 # add to esp # . f->read must now be 0; update its cache at ecx 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . . # clear ecx # . eax = read(f->fd, stream = f+4) # . . push args 50/push-eax ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . . # push *esi # . . call e8/call read/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # if (f->write == 0) break # since f->read was initially 0, eax is the same as f->write # . if (eax == 0) return true 3d/compare-eax-and 0/imm32 74/jump-if-equal $slurp:end/disp8 $slurp:from-stream: # AL = f->data[f->read] 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0x10/disp8 . # copy byte at *(esi+ecx+16) to AL # s->data[s->write] = AL 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/edi 2/index/edx . 0/r32/AL 0xc/disp8 . # copy AL to *(edi+edx+12) # ++f->read 41/increment-ecx # ++s->write 42/increment-edx eb/jump $slurp:loop/disp8 $slurp:end: # save f->read 89/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 8/disp8 . # copy ecx to *(esi+8) # save s->write 89/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . . # copy edx to *edi # . restore registers 5f/pop-to-edi 5e/pop-to-esi 5a/pop-to-edx 59/pop-to-ecx 58/pop-to-eax # . epilog 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return $slurp:abort: # . _write(2/stderr, error) # . . push args 68/push "slurp: destination too small\n"/imm32 68/push 2/imm32/stderr # . . call e8/call _write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . syscall(exit, 1) bb/copy-to-ebx 1/imm32 b8/copy-to-eax 1/imm32/exit cd/syscall 0x80/imm8 # never gets here test-slurp: # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream(_test-buffered-file+4) # . . push args b8/copy-to-eax _test-buffered-file/imm32 05/add-to-eax 4/imm32 50/push-eax # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream(_test-tmp-stream) # . . push args 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # write(_test-stream, "ab\ncd") # . . push args 68/push "ab\ncd"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # read a line from _test-stream (buffered by _test-buffered-file) into _test-tmp-stream # . eax = slurp(_test-buffered-file, _test-tmp-stream) # . . push args 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call e8/call slurp/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-stream-equal(_test-tmp-stream, "ab\ncd", msg) # . . push args 68/push "F - test-slurp"/imm32 68/push "ab\ncd"/imm32 68/push _test-tmp-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # end c3/return # . . vim:nowrap:textwidth=0