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

[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) {}
 }



reply via email to

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