Skip to content

Commit 993f2cd

Browse files
committed
chore: RSR sync and mass repository update
1 parent 817a01e commit 993f2cd

5 files changed

Lines changed: 602 additions & 1 deletion

File tree

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ The link:.claude/CLAUDE.md[Hyperpolymath Language Policy] defines the technology
201201
|Category |Allowed |Banned
202202

203203
|**Primary Languages**
204-
|ReScript, Rust, Gleam
204+
|AffineScript, Rust, Gleam
205205
|TypeScript, Go, Java/Kotlin, Python
206206

207207
|**Runtime**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Gemini Audit Report (M2: Pillar Repo Audits)
2+
Date: 2026-04-15
3+
Repository: /var/mnt/eclipse/repos/standards
4+
5+
## Audit Criteria
6+
7+
- **Dangerous Patterns**: **CLEAN** (only meta-references in standards definitions).
8+
- **Standards Check**:
9+
- `.machine_readable/*.a2ml`: `0-AI-MANIFEST.a2ml` present.
10+
- `Justfile`: **PRESENT**.
11+
- `K9.k9` / `coordination.k9`: **PRESENT** (`coordination.k9`).
12+
- **CI/CD Status**: `.github/workflows` **PRESENT**.
13+
- **Documentation Parity**: Standardized repo.
14+
- **Template Residue**: **CLEAN**.
15+
16+
## Verdict
17+
- **CRG Grade**: A
18+
- **Publishable?**: YES
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
# sync-ffi-templates.sh — Sync standard FFI/ABI boilerplate across the estate
3+
#
4+
# This script applies standard templates for Zig FFI and Idris2 ABI to repos
5+
# that use the common hyperpolymath FFI pattern.
6+
#
7+
# SPDX-License-Identifier: PMPL-1.0-or-later
8+
9+
set -e
10+
11+
TEMPLATES_DIR="$(dirname "$0")/../templates"
12+
ZIG_TEMPLATE="$TEMPLATES_DIR/ffi_main.zig.template"
13+
IDR_TEMPLATE="$TEMPLATES_DIR/ffi_foreign.idr.template"
14+
15+
if [ ! -f "$ZIG_TEMPLATE" ] || [ ! -f "$IDR_TEMPLATE" ]; then
16+
echo "Error: Templates not found in $TEMPLATES_DIR"
17+
exit 1
18+
fi
19+
20+
# Function to convert kebab-case to snake_case
21+
to_snake_case() {
22+
echo "$1" | tr '-' '_'
23+
}
24+
25+
# Function to convert kebab-case to SCREAMING_SNAKE_CASE
26+
to_screaming_snake_case() {
27+
echo "$1" | tr '-' '_' | tr '[:lower:]' '[:upper:]'
28+
}
29+
30+
# Function to convert kebab-case to PascalCase
31+
to_pascal_case() {
32+
echo "$1" | sed -r 's/(^|-)([a-z])/\U\2/g'
33+
}
34+
35+
# Process a single repository
36+
sync_repo() {
37+
local repo_path="$1"
38+
local repo_name=$(basename "$repo_path")
39+
40+
local project_snake=$(to_snake_case "$repo_name")
41+
local project_screaming=$(to_screaming_snake_case "$repo_name")
42+
local project_pascal=$(to_pascal_case "$repo_name")
43+
44+
echo "Syncing $repo_name..."
45+
46+
# Sync Zig FFI if it exists
47+
if [ -f "$repo_path/ffi/zig/src/main.zig" ]; then
48+
echo " Updating Zig FFI..."
49+
sed -e "s/{{project}}/$project_snake/g" \
50+
-e "s/{{PROJECT}}/$project_screaming/g" \
51+
"$ZIG_TEMPLATE" > "$repo_path/ffi/zig/src/main.zig"
52+
fi
53+
54+
# Sync Idris2 ABI if it exists
55+
if [ -f "$repo_path/src/abi/Foreign.idr" ]; then
56+
echo " Updating Idris2 ABI..."
57+
sed -e "s/{{project}}/$project_snake/g" \
58+
-e "s/{{PROJECT}}/$project_screaming/g" \
59+
-e "s/{{Project}}/$project_pascal/g" \
60+
"$IDR_TEMPLATE" > "$repo_path/src/abi/Foreign.idr"
61+
fi
62+
}
63+
64+
# Find and process all repos
65+
REPOS_ROOT="/var/mnt/eclipse/repos"
66+
67+
if [ $# -gt 0 ]; then
68+
for repo_path in "$@"; do
69+
# Handle relative or absolute paths
70+
if [[ "$repo_path" != /* ]]; then
71+
repo_path="$REPOS_ROOT/$repo_path"
72+
fi
73+
if [ -d "$repo_path" ]; then
74+
sync_repo "$repo_path"
75+
else
76+
echo "Error: Directory $repo_path not found"
77+
fi
78+
done
79+
else
80+
declare -A processed_repos
81+
find "$REPOS_ROOT" -maxdepth 2 -type d \( -name "ffi" -o -name "src" \) | while read -r dir; do
82+
repo_path=$(dirname "$dir")
83+
if [ -f "$repo_path/ffi/zig/src/main.zig" ] || [ -f "$repo_path/src/abi/Foreign.idr" ]; then
84+
if [ -z "${processed_repos[$repo_path]}" ]; then
85+
sync_repo "$repo_path"
86+
processed_repos["$repo_path"]=1
87+
fi
88+
fi
89+
done
90+
fi
91+
92+
echo "Done."
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
||| SPDX-License-Identifier: PMPL-1.0-or-later
2+
||| Foreign Function Interface Declarations for {{PROJECT}}
3+
|||
4+
||| This module declares all C-compatible functions that will be
5+
||| implemented in the Zig FFI layer.
6+
|||
7+
||| All functions are declared here with type signatures and safety proofs.
8+
||| Implementations live in ffi/zig/
9+
10+
module {{Project}}.ABI.Foreign
11+
12+
import {{Project}}.ABI.Types
13+
import {{Project}}.ABI.Layout
14+
15+
%default total
16+
17+
--------------------------------------------------------------------------------
18+
-- Library Lifecycle
19+
--------------------------------------------------------------------------------
20+
21+
||| Initialize the library
22+
||| Returns a handle to the library instance, or Nothing on failure
23+
export
24+
%foreign "C:{{project}}_init, lib{{project}}"
25+
prim__init : PrimIO Bits64
26+
27+
||| Safe wrapper for library initialization
28+
export
29+
init : IO (Maybe Handle)
30+
init = do
31+
ptr <- primIO prim__init
32+
pure (createHandle ptr)
33+
34+
||| Clean up library resources
35+
export
36+
%foreign "C:{{project}}_free, lib{{project}}"
37+
prim__free : Bits64 -> PrimIO ()
38+
39+
||| Safe wrapper for cleanup
40+
export
41+
free : Handle -> IO ()
42+
free h = primIO (prim__free (handlePtr h))
43+
44+
--------------------------------------------------------------------------------
45+
-- Core Operations
46+
--------------------------------------------------------------------------------
47+
48+
||| Example operation: process data
49+
export
50+
%foreign "C:{{project}}_process, lib{{project}}"
51+
prim__process : Bits64 -> Bits32 -> PrimIO Bits32
52+
53+
||| Safe wrapper with error handling
54+
export
55+
process : Handle -> Bits32 -> IO (Either Result Bits32)
56+
process h input = do
57+
result <- primIO (prim__process (handlePtr h) input)
58+
pure $ case result of
59+
0 => Left Error
60+
n => Right n
61+
62+
--------------------------------------------------------------------------------
63+
-- String Operations
64+
--------------------------------------------------------------------------------
65+
66+
||| Convert C string to Idris String
67+
export
68+
%foreign "support:idris2_getString, libidris2_support"
69+
prim__getString : Bits64 -> String
70+
71+
||| Free C string
72+
export
73+
%foreign "C:{{project}}_free_string, lib{{project}}"
74+
prim__freeString : Bits64 -> PrimIO ()
75+
76+
||| Get string result from library
77+
export
78+
%foreign "C:{{project}}_get_string, lib{{project}}"
79+
prim__getResult : Bits64 -> PrimIO Bits64
80+
81+
||| Safe string getter
82+
export
83+
getString : Handle -> IO (Maybe String)
84+
getString h = do
85+
ptr <- primIO (prim__getResult (handlePtr h))
86+
if ptr == 0
87+
then pure Nothing
88+
else do
89+
let str = prim__getString ptr
90+
primIO (prim__freeString ptr)
91+
pure (Just str)
92+
93+
--------------------------------------------------------------------------------
94+
-- Array/Buffer Operations
95+
--------------------------------------------------------------------------------
96+
97+
||| Process array data
98+
export
99+
%foreign "C:{{project}}_process_array, lib{{project}}"
100+
prim__processArray : Bits64 -> Bits64 -> Bits32 -> PrimIO Bits32
101+
102+
||| Safe array processor
103+
export
104+
processArray : Handle -> (buffer : Bits64) -> (len : Bits32) -> IO (Either Result ())
105+
processArray h buf len = do
106+
result <- primIO (prim__processArray (handlePtr h) buf len)
107+
pure $ case resultFromInt result of
108+
Just Ok => Right ()
109+
Just err => Left err
110+
Nothing => Left Error
111+
where
112+
resultFromInt : Bits32 -> Maybe Result
113+
resultFromInt 0 = Just Ok
114+
resultFromInt 1 = Just Error
115+
resultFromInt 2 = Just InvalidParam
116+
resultFromInt 3 = Just OutOfMemory
117+
resultFromInt 4 = Just NullPointer
118+
resultFromInt _ = Nothing
119+
120+
--------------------------------------------------------------------------------
121+
-- Error Handling
122+
--------------------------------------------------------------------------------
123+
124+
||| Get last error message
125+
export
126+
%foreign "C:{{project}}_last_error, lib{{project}}"
127+
prim__lastError : PrimIO Bits64
128+
129+
||| Retrieve last error as string
130+
export
131+
lastError : IO (Maybe String)
132+
lastError = do
133+
ptr <- primIO prim__lastError
134+
if ptr == 0
135+
then pure Nothing
136+
else pure (Just (prim__getString ptr))
137+
138+
||| Get error description for result code
139+
export
140+
errorDescription : Result -> String
141+
errorDescription Ok = "Success"
142+
errorDescription Error = "Generic error"
143+
errorDescription InvalidParam = "Invalid parameter"
144+
errorDescription OutOfMemory = "Out of memory"
145+
errorDescription NullPointer = "Null pointer"
146+
147+
--------------------------------------------------------------------------------
148+
-- Version Information
149+
--------------------------------------------------------------------------------
150+
151+
||| Get library version
152+
export
153+
%foreign "C:{{project}}_version, lib{{project}}"
154+
prim__version : PrimIO Bits64
155+
156+
||| Get version as string
157+
export
158+
version : IO String
159+
version = do
160+
ptr <- primIO prim__version
161+
pure (prim__getString ptr)
162+
163+
||| Get library build info
164+
export
165+
%foreign "C:{{project}}_build_info, lib{{project}}"
166+
prim__buildInfo : PrimIO Bits64
167+
168+
||| Get build information
169+
export
170+
buildInfo : IO String
171+
buildInfo = do
172+
ptr <- primIO prim__buildInfo
173+
pure (prim__getString ptr)
174+
175+
--------------------------------------------------------------------------------
176+
-- Callback Support
177+
--------------------------------------------------------------------------------
178+
179+
||| Callback function type (C ABI)
180+
public export
181+
Callback : Type
182+
Callback = Bits64 -> Bits32 -> Bits32
183+
184+
||| Register a callback
185+
export
186+
%foreign "C:{{project}}_register_callback, lib{{project}}"
187+
prim__registerCallback : Bits64 -> AnyPtr -> PrimIO Bits32
188+
189+
||| Safe callback registration
190+
export
191+
registerCallback : Handle -> Callback -> IO (Either Result ())
192+
registerCallback h cb = do
193+
result <- primIO (prim__registerCallback (handlePtr h) (cast cb))
194+
pure $ case resultFromInt result of
195+
Just Ok => Right ()
196+
Just err => Left err
197+
Nothing => Left Error
198+
where
199+
resultFromInt : Bits32 -> Maybe Result
200+
resultFromInt 0 = Just Ok
201+
resultFromInt _ = Just Error
202+
203+
--------------------------------------------------------------------------------
204+
-- Utility Functions
205+
--------------------------------------------------------------------------------
206+
207+
||| Check if library is initialized
208+
export
209+
%foreign "C:{{project}}_is_initialized, lib{{project}}"
210+
prim__isInitialized : Bits64 -> PrimIO Bits32
211+
212+
||| Check initialization status
213+
export
214+
isInitialized : Handle -> IO Bool
215+
isInitialized h = do
216+
result <- primIO (prim__isInitialized (handlePtr h))
217+
pure (result /= 0)

0 commit comments

Comments
 (0)