[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt c88196439f 211/323: Support Zig 0.9
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt c88196439f 211/323: Support Zig 0.9 |
Date: |
Thu, 9 Mar 2023 10:58:32 -0500 (EST) |
branch: externals/beardbolt
commit c88196439f968700774e13d47e337a18e2f1c5c6
Author: Erik Arvstedt <erik.arvstedt@gmail.com>
Commit: Erik Arvstedt <erik.arvstedt@gmail.com>
Support Zig 0.9
This supports both Zig 0.9 (the latest release) and the current master
branch.
Use `build-obj` and `-O ReleaseFast` by default, like godbolt.
`build-exe` is less suitable because it generates large amounts of
boilerplate assembly.
Zig 0.9 no longer allows specifying the ASM format and always uses the
Intel syntax.
---
doc/rmsbolt.texi | 13 +++++++------
rmsbolt.el | 42 +++++++++++-------------------------------
starters/rmsbolt.zig | 41 +++++++++++++++++++++++++----------------
3 files changed, 43 insertions(+), 53 deletions(-)
diff --git a/doc/rmsbolt.texi b/doc/rmsbolt.texi
index e550986d0a..5f4788effe 100644
--- a/doc/rmsbolt.texi
+++ b/doc/rmsbolt.texi
@@ -315,14 +315,15 @@ supported at the moment, with @code{sbcl} giving much
better results.
Assembly is generated through the @code{zig} compiler. Due to large binary
sizes,
disassembly is discouraged.
-Zig embeds a panic handler which inflates the size of binaries. In order to
-reduce this to a manageable level, you can add the following snippet to your
-file:
+In some cases, Zig embeds a panic handler which inflates the size of binaries.
+In order to reduce this to a manageable level, you can add the following
snippet to
+your file:
@example
-pub fn panic(msg: []const u8, error_return_trace:
?*@@import("builtin").StackTrace) noreturn @{
- while (true) @{
- @}
+pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace)
noreturn @{
+ _ = msg;
+ _ = error_return_trace;
+ while (true) @{@}
@}
@end example
diff --git a/rmsbolt.el b/rmsbolt.el
index 1f1c796bb6..69cd577ec5 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -657,37 +657,17 @@ https://github.com/derickr/vld"
"Process a compile command for zig."
(rmsbolt--with-files
src-buffer
- (let* ((asm-format (buffer-local-value 'rmsbolt-asm-format src-buffer))
- (predicted-asm-filename (shell-quote-argument
- (concat (file-name-directory
output-filename)
- (file-name-as-directory "zig-cache")
- (file-name-sans-extension
(file-name-nondirectory (buffer-file-name)))
- ".s")))
- (disass (buffer-local-value 'rmsbolt-disassemble src-buffer))
+ (let* ((disass (buffer-local-value 'rmsbolt-disassemble src-buffer))
(cmd (buffer-local-value 'rmsbolt-command src-buffer))
- (cmd (mapconcat #'identity
- (list cmd
- "build-exe"
- src-filename
- "--emit"
- (if disass
- "bin"
- "asm")
- (when (and (not (booleanp asm-format))
- (not disass))
- (concat "-mllvm --x86-asm-syntax="
asm-format))
- (mapconcat #'identity
- (cond
- (disass
- (list "--output" output-filename))
- ((equal predicted-asm-filename
output-filename)
- nil)
- (t
- (list "&&" "mv"
- predicted-asm-filename
- output-filename)))
- " "))
- " ")))
+ (cmd (string-join
+ (list cmd
+ src-filename
+ "--cache-dir" (expand-file-name "zig-cache"
rmsbolt--temp-dir)
+ (concat (if disass
+ "-femit-bin="
+ "-fno-emit-bin -femit-asm=")
+ output-filename))
+ " ")))
cmd)))
(cl-defun rmsbolt--swift-compile-cmd (&key src-buffer)
@@ -904,7 +884,7 @@ return t if successful."
lines)
:elisp-compile-override
#'rmsbolt--elisp-compile-override))
(zig-mode
- . ,(make-rmsbolt-lang :compile-cmd "zig"
+ . ,(make-rmsbolt-lang :compile-cmd "zig build-obj -O ReleaseFast"
:supports-asm t
:supports-disass t
:objdumper 'objdump
diff --git a/starters/rmsbolt.zig b/starters/rmsbolt.zig
index 60527742ee..ace2786ec6 100644
--- a/starters/rmsbolt.zig
+++ b/starters/rmsbolt.zig
@@ -3,29 +3,38 @@ const std = @import("std");
// Zig rmsbolt starter file
// Local Variables:
-// rmsbolt-command: "zig"
+// rmsbolt-command: "zig build-obj -O ReleaseFast"
// rmsbolt-disassemble: nil
// End:
-fn isRMS(a: u8) u8 {
- switch (a) {
- 'R' => {return 1;},
- 'M' => {return 2;},
- 'S' => {return 3;},
- else => {return 0;},
- }
+export fn isRMS(a: u8) u8 {
+ return switch (a) {
+ 'R' => 1,
+ 'M' => 2,
+ 'S' => 3,
+ else => 0,
+ };
}
-pub fn main() void {
- const a: u8 = 1 + 1;
- if (isRMS(a) != 0) {
- std.debug.warn("{c}\n", a);
+// Functions marked with `export` use the C calling convention, so its
parameters and
+// return value can only have C types.
+// To export a native Zig fn, use the following pattern:
+fn zigFn(xs: []u8) []u8 {
+ for (xs) |*x| {
+ x.* *= 2;
}
+ return xs;
+}
+
+export fn exportZigFn() usize {
+ return @ptrToInt(zigFn);
}
-// Zig embeds a panic handler that prints stack traces, causing a disassembly
much larger than normal.
+// In some cases, Zig embeds a panic handler that prints stack traces, causing
a
+// disassembly much larger than normal.
// You can optionally place this function in files you disassemble to make
them easier to digest.
-pub fn panic(msg: []const u8, error_return_trace:
?*@import("builtin").StackTrace) noreturn {
- while (true) {
- }
+pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace)
noreturn {
+ _ = msg;
+ _ = error_return_trace;
+ while (true) {}
}
- [elpa] externals/beardbolt c655e2af39 186/323: Add check for dead buffers in compilation finish fn, (continued)
- [elpa] externals/beardbolt c655e2af39 186/323: Add check for dead buffers in compilation finish fn, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt d51e71f894 188/323: Use special named buffer for compilation, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 712981e16c 187/323: Remove langauges godbolt has added support for, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt ff496660cc 205/323: Migrate irc channel to libera, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 42edd955ae 201/323: Move filename massaging out of hot loop, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 972e6f41a2 207/323: Merge branch 'faerryn-master-patch-16796' into 'master', ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt bc0652e56e 197/323: Add support for indirect buffers, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt df7451ee35 191/323: Avoid insert on new file creation, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 95130c1421 203/323: Update copyright and headers, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f098a467c5 206/323: Add missing `:keymap' key to `define-minor-mode rmsbolt'., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c88196439f 211/323: Support Zig 0.9,
ELPA Syncer <=
- [elpa] externals/beardbolt 0f3293c607 224/323: Early-exit `when-let` if output-buffer has no window, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt fffadc0b86 214/323: Allow configuring objdump binary in disassembly mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 68af010f02 064/323: Add support for haskell, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f0be36f4b5 063/323: Update link, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 8213e24af3 070/323: Update README, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e71061f509 075/323: Fix readme, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c442960f16 076/323: Add an easy way to turn off automatic recompilation, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt a191eb9c73 071/323: Add basic Java support, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 77398fec4f 078/323: Clarify starter/ folder message, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 8cfb5b1968 086/323: Upgrade information and docs for melpa, ELPA Syncer, 2023/03/09