branch: externals/beardbolt
commit b56d3b6cdbfa828144d3d8e559472064b0908d0e
Merge: 3fe322e573 d257e51fce
Author: Jay Kamat <[email protected]>
Commit: Jay Kamat <[email protected]>
Merge branch 'improve-starters' into 'master'
Improve starters
See merge request jgkamat/rmsbolt!15
---
starters/rmsbolt-starter.el | 3 +--
starters/rmsbolt.zig | 25 +++++++++++++++++++------
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/starters/rmsbolt-starter.el b/starters/rmsbolt-starter.el
index 230ef2fa13..0ed5c54c8f 100644
--- a/starters/rmsbolt-starter.el
+++ b/starters/rmsbolt-starter.el
@@ -13,8 +13,7 @@
"Check to see if a LETTER is RMS."
(pcase letter
((or "R" "M" "S") t)
- (_ nil)
- (_ "I will never run!")))
+ (_ nil)))
(defun main ()
"Main entrypoint."
diff --git a/starters/rmsbolt.zig b/starters/rmsbolt.zig
index ace2786ec6..4f4ad1c52e 100644
--- a/starters/rmsbolt.zig
+++ b/starters/rmsbolt.zig
@@ -16,20 +16,33 @@ export fn isRMS(a: u8) u8 {
};
}
-// 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 {
+// Exported by `exportFns` below
+pub fn zigFn(xs: []u8) []u8 {
for (xs) |*x| {
x.* *= 2;
}
return xs;
}
-export fn exportZigFn() usize {
- return @ptrToInt(zigFn);
+// Export all public, non-generic functions in this file.
+// This is needed because functions that accept or return Zig-specific types
can't be marked
+// with `export`.
+// `export` is limited to functions that only accept or return C types, which
makes them
+// compatible with the C calling convention.
+export fn exportPubFns() usize {
+ var fns: usize = 0;
+ inline for (@typeInfo((@This())).Struct.decls) |decl| {
+ if (!decl.is_pub) continue;
+ const field = @field(@This(), decl.name);
+ const info = @typeInfo(@TypeOf(field));
+ if (info == .Fn and !info.Fn.is_generic) {
+ fns += @ptrToInt(field);
+ }
+ }
+ return fns;
}
+
// 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.