1 ;;; ob-vala.el --- Babel functions for Vala evaluation -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017-2019 Free Software Foundation, Inc.
5 ;; Author: Christian Garbs <mitch@cgarbs.de>
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: https://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
28 ;; ob-vala.el provides Babel support for the Vala language
29 ;; (see http://live.gnome.org/Vala for details)
33 ;; - Vala compiler binary (valac)
34 ;; - Vala development environment (Vala libraries etc.)
36 ;; vala-mode.el is nice to have for code formatting, but is not needed
45 (add-to-list 'org-babel-tangle-lang-exts
'("vala" .
"vala"))
47 ;; Header arguments empty by default.
48 (defvar org-babel-default-header-args
:vala
'())
50 (defcustom org-babel-vala-compiler
"valac"
51 "Command used to compile a C source code file into an executable.
52 May be either a command in the path, like \"valac\"
53 or an absolute path name, like \"/usr/local/bin/valac\".
54 Parameters may be used like this: \"valac -v\""
57 :package-version
'(Org .
"9.1")
60 ;; This is the main function which is called to evaluate a code
63 ;; - run Vala compiler and create a binary in a temporary file
64 ;; - compiler/linker flags can be set via :flags header argument
65 ;; - if compilation succeeded, run the binary
66 ;; - commandline parameters to the binary can be set via :cmdline
68 ;; - stdout will be parsed as RESULT (control via :result-params
71 ;; There is no session support because Vala is a compiled language.
73 ;; This function is heavily based on ob-C.el
74 (defun org-babel-execute:vala
(body params
)
75 "Execute a block of Vala code with Babel.
76 This function is called by `org-babel-execute-src-block'."
77 (message "executing Vala source code block")
78 (let* ((tmp-src-file (org-babel-temp-file
81 (tmp-bin-file (org-babel-temp-file "vala-bin-" org-babel-exeext
))
82 (cmdline (cdr (assq :cmdline params
)))
83 (flags (cdr (assq :flags params
))))
84 (with-temp-file tmp-src-file
(insert body
))
86 (format "%s %s -o %s %s"
87 org-babel-vala-compiler
89 (if (listp flags
) flags
(list flags
)) " ")
90 (org-babel-process-file-name tmp-bin-file
)
91 (org-babel-process-file-name tmp-src-file
)) "")
92 (when (file-executable-p tmp-bin-file
)
96 (concat tmp-bin-file
(if cmdline
(concat " " cmdline
) "")) ""))))
97 (org-babel-reassemble-table
98 (org-babel-result-cond (cdr (assq :result-params params
))
99 (org-babel-read results
)
100 (let ((tmp-file (org-babel-temp-file "vala-")))
101 (with-temp-file tmp-file
(insert results
))
102 (org-babel-import-elisp-from-file tmp-file
)))
104 (cdr (assq :colname-names params
)) (cdr (assq :colnames params
)))
106 (cdr (assq :rowname-names params
)) (cdr (assq :rownames params
))))))))
108 (defun org-babel-prep-session:vala
(_session _params
)
110 This function does nothing as Vala is a compiled language with no
111 support for sessions."
112 (error "Vala is a compiled language -- no support for sessions"))
116 ;;; ob-vala.el ends here