emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/beardbolt e6081fae6b 032/323: Add unrefined support for


From: ELPA Syncer
Subject: [elpa] externals/beardbolt e6081fae6b 032/323: Add unrefined support for ocaml
Date: Thu, 9 Mar 2023 10:57:56 -0500 (EST)

branch: externals/beardbolt
commit e6081fae6b65447542648bc29e17ca57e8e5631e
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>

    Add unrefined support for ocaml
---
 rmsbolt.el           | 55 ++++++++++++++++++++++++++++++++++++++++++++++------
 starters/rmsbolt.c   |  4 +++-
 starters/rmsbolt.cpp |  4 +++-
 starters/rmsbolt.ml  | 22 +++++++++++++++++++++
 4 files changed, 77 insertions(+), 8 deletions(-)

diff --git a/rmsbolt.el b/rmsbolt.el
index de142cae19..4a227cf105 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -73,6 +73,11 @@
   :type 'boolean
   :safe 'booleanp
   :group 'rmsbolt)
+(defcustom rmsbolt-ignore-binary-limit nil
+  "Whether to ignore the binary limit. Could hang emacs..."
+  :type 'boolean
+  :safe 'booleanp
+  :group 'rmsbolt)
 
 ;;;; Faces
 
@@ -209,7 +214,7 @@
    :documentation "A function which takes in a compile command (could be the 
default) and adds needed args to it."))
 
 
-(defun rmsbolt--c-compile-cmd (src-buffer)
+(cl-defun rmsbolt--c-compile-cmd (&key src-buffer)
   "Process a compile command for gcc/clang."
   (let* ((cmd (buffer-local-value 'rmsbolt-command src-buffer))
          (cmd (mapconcat 'identity
@@ -224,6 +229,35 @@
                                  "-masm=intel"))
                          " ")))
     cmd))
+(cl-defun rmsbolt--ocaml-compile-cmd (&key src-buffer)
+  "Process a compile command for gcc/clang.
+
+Needed as ocaml cannot output asm to a non-hardcoded file"
+  (let* ((diss (buffer-local-value 'rmsbolt-dissasemble src-buffer))
+         (output-filename (rmsbolt-output-filename src-buffer))
+         (predicted-asm-filename (concat (file-name-sans-extension 
(buffer-file-name)) ".s"))
+         (cmd (buffer-local-value 'rmsbolt-command src-buffer))
+         (cmd (mapconcat 'identity
+                         (list cmd
+                               "-g"
+                               (if (buffer-local-value 'rmsbolt-dissasemble 
src-buffer)
+                                   ""
+                                 "-S")
+                               (buffer-file-name)
+                               (mapconcat #'identity
+                                          (cond
+                                           (diss
+                                            (list "-o" output-filename))
+                                           ((equal predicted-asm-filename 
output-filename)
+                                            nil)
+                                           (t
+                                            (list "&&" "mv"
+                                                  (concat 
(file-name-sans-extension (buffer-file-name))
+                                                          ".s")
+                                                  output-filename)))
+                                          " "))
+                         " ")))
+    cmd))
 (defvar rmsbolt--hidden-func-c (rx bol (or (and "__" (0+ any))
                                            (and "_" (or "init" "start" "fini"))
                                            (and (opt "de") 
"register_tm_clones")
@@ -248,9 +282,16 @@
                           :supports-asm t
                           :starter-file-name "rmsbolt.cpp"
                           :compile-cmd-function #'rmsbolt--c-compile-cmd
+                          :dissas-hidden-funcs rmsbolt--hidden-func-c))
+   ;; In order to parse ocaml files, you need the emacs ocaml mode, tuareg
+   (tuareg-mode
+    . ,(make-rmsbolt-lang :mode 'tuareg-mode
+                          :compile-cmd "ocamlopt"
+                          :supports-asm t
+                          :starter-file-name "rmsbolt.ml"
+                          :compile-cmd-function #'rmsbolt--ocaml-compile-cmd
                           :dissas-hidden-funcs rmsbolt--hidden-func-c))))
 
-
 ;;;; Macros
 
 (defmacro rmsbolt-with-display-buffer-no-window (&rest body)
@@ -363,7 +404,8 @@
          (source-linum nil))
     (dolist (line asm-lines)
       (cl-tagbody
-       (when (> (length result) rmsbolt-binary-asm-limit)
+       (when (and (> (length result) rmsbolt-binary-asm-limit)
+                  (not (buffer-local-value 'rmsbolt-ignore-binary-limit 
src-buffer)))
          (cl-return-from rmsbolt--process-dissasembled-lines
            '("Aborting processing due to exceeding the binary limit.")))
        (when (string-match rmsbolt-dissas-line line)
@@ -527,7 +569,7 @@
     (let* ((src-buffer (current-buffer))
            (lang (rmsbolt--get-lang))
            (func (rmsbolt-l-compile-cmd-function lang))
-           (cmd (funcall func src-buffer)))
+           (cmd (funcall func :src-buffer src-buffer)))
 
       (when (buffer-local-value 'rmsbolt-dissasemble src-buffer)
         (pcase
@@ -590,6 +632,7 @@
      (rmsbolt-starter ,mode)))
 (rmsbolt-defstarter "c" 'c-mode)
 (rmsbolt-defstarter "c++" 'c++-mode)
+(rmsbolt-defstarter "ocaml" 'tuareg-mode)
 
 ;;;; Font lock matcher
 (defun rmsbolt--goto-line (line)
@@ -615,8 +658,8 @@
              (if (eq (current-buffer) src-buffer)
                  current-line
                (get-text-property (point) 'rmsbolt-src-line)))
-            (asm-lines (gethash src-current-line
-                                (buffer-local-value 'rmsbolt-line-mapping 
src-buffer)))
+            (hash-table (buffer-local-value 'rmsbolt-line-mapping src-buffer))
+            (asm-lines (gethash src-current-line hash-table))
             ;; TODO also consider asm
             (src-pts
              (with-current-buffer src-buffer
diff --git a/starters/rmsbolt.c b/starters/rmsbolt.c
index ea7b750eff..63dc6d69cc 100644
--- a/starters/rmsbolt.c
+++ b/starters/rmsbolt.c
@@ -1,7 +1,9 @@
 #include <stdio.h>
 
+// C rmsbolt starter file
+
 // Local Variables:
-// rmsbolt-command: "gcc -O3"
+// rmsbolt-command: "gcc -O0"
 // rmsbolt-dissasemble: nil
 // End:
 
diff --git a/starters/rmsbolt.cpp b/starters/rmsbolt.cpp
index 49e401e021..aa4dee0f0e 100644
--- a/starters/rmsbolt.cpp
+++ b/starters/rmsbolt.cpp
@@ -1,7 +1,9 @@
 #include <iostream>
 
+// C++ rmsbolt starter file
+
 // Local Variables:
-// rmsbolt-command: "g++ -O3"
+// rmsbolt-command: "g++ -O0"
 // rmsbolt-dissasemble: nil
 // End:
 
diff --git a/starters/rmsbolt.ml b/starters/rmsbolt.ml
new file mode 100644
index 0000000000..deee3757a5
--- /dev/null
+++ b/starters/rmsbolt.ml
@@ -0,0 +1,22 @@
+
+
+(* OCaml rmsbolt starter *)
+
+(*
+Local Variables:
+rmsbolt-command: "ocamlopt"
+rmsbolt-dissasemble: nil
+End:
+*)
+
+
+let rec fib num =
+  if num <= 1 then
+       num
+  else
+       fib (num - 1) + fib (num - 2);;
+
+let print_fib num =
+  Printf.printf "Fibonacci result of %d is %d.\n" num (fib 20);;
+
+print_fib 20



reply via email to

[Prev in Thread] Current Thread [Next in Thread]