11// SPDX-License-Identifier: MPL-2.0
2- // Ported via Harvard Engine mechanical processor
2+ // Ported via Harvard Engine (Semantic pass)
33
44module bunsenite;
55
6- // TODO: Complete semantic implementation
7-
8- /* === ORIGINAL TYPESCRIPT CONTEXT ===
96// SPDX-License-Identifier: MPL-2.0
107// Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
118// Bunsenite Deno FFI Bindings
@@ -16,18 +13,18 @@ module bunsenite;
1613//
1714// Usage:
1815// import { parseNickel, validateNickel } from "./bunsenite.ts";
19- // const result = parseNickel('{ foo = 42 }', "config.ncl");
16+ // let result = parseNickel('{ foo = 42 }', "config.ncl");
2017// console.log(result);
2118
2219// Detect library path based on platform
23- function getLibraryPath(): string {
24- const platform = Deno.build.os;
25- const libName = platform === "windows" ? "bunsenite.dll"
20+ fn getLibraryPath(): string {
21+ let platform = Deno.build.os;
22+ let libName = platform === "windows" ? "bunsenite.dll"
2623 : platform === "darwin" ? "libbunsenite.dylib"
2724 : "libbunsenite.so";
2825
2926 // Try common locations
30- const paths = [
27+ let paths = [
3128 `../../target/release/${libName}`,
3229 `./target/release/${libName}`,
3330 `./${libName}`,
@@ -49,7 +46,7 @@ function getLibraryPath(): string {
4946
5047// FFI symbol definitions
5148// These match the C ABI exported by the Zig layer
52- const symbols = {
49+ let symbols = {
5350 // Parse Nickel string to JSON
5451 // char* parse_nickel(const char* source, const char* name)
5552 parse_nickel: {
@@ -96,27 +93,27 @@ const symbols = {
9693// Load the native library
9794let lib: Deno.DynamicLibrary<typeof symbols> | null = null;
9895
99- function getLib(): Deno.DynamicLibrary<typeof symbols> {
96+ fn getLib(): Deno.DynamicLibrary<typeof symbols> {
10097 if (!lib) {
101- const libPath = getLibraryPath();
98+ let libPath = getLibraryPath();
10299 lib = Deno.dlopen(libPath, symbols);
103100 }
104101 return lib;
105102}
106103
107104// Helper: Convert JS string to C string (null-terminated)
108- function toCString(str: string): Uint8Array {
109- const encoder = new TextEncoder();
110- const encoded = encoder.encode(str + "\0");
105+ fn toCString(str: string): Uint8Array {
106+ let encoder = new TextEncoder();
107+ let encoded = encoder.encode(str + "\0");
111108 return encoded;
112109}
113110
114111// Helper: Convert C string pointer to JS string
115- function fromCString(ptr: Deno.UnsafePointer): string {
112+ fn fromCString(ptr: Deno.UnsafePointer): string {
116113 if (!ptr) {
117114 throw new Error("Null pointer received from C");
118115 }
119- const view = new Deno.UnsafePointerView(ptr);
116+ let view = new Deno.UnsafePointerView(ptr);
120117 return view.getCString();
121118}
122119
@@ -130,17 +127,17 @@ function fromCString(ptr: Deno.UnsafePointer): string {
130127 *
131128 * @example
132129 * ```typescript
133- * const config = parseNickel('{ name = "example", port = 8080 }', "config.ncl");
130+ * let config = parseNickel('{ name = "example", port = 8080 }', "config.ncl");
134131 * console.log(config.port); // 8080
135132 * ```
136133 */
137- export function parseNickel(source: string, name: string): unknown {
138- const library = getLib();
134+ fn parseNickel(source: string, name: string): unknown {
135+ let library = getLib();
139136
140- const sourceBytes = toCString(source);
141- const nameBytes = toCString(name);
137+ let sourceBytes = toCString(source);
138+ let nameBytes = toCString(name);
142139
143- const resultPtr = library.symbols.parse_nickel(
140+ let resultPtr = library.symbols.parse_nickel(
144141 sourceBytes,
145142 nameBytes,
146143 ) as Deno.UnsafePointer;
@@ -150,7 +147,7 @@ export function parseNickel(source: string, name: string): unknown {
150147 }
151148
152149 try {
153- const jsonString = fromCString(resultPtr);
150+ let jsonString = fromCString(resultPtr);
154151 return JSON.parse(jsonString);
155152 } finally {
156153 // Free the string allocated by Rust
@@ -176,13 +173,13 @@ export function parseNickel(source: string, name: string): unknown {
176173 * }
177174 * ```
178175 */
179- export function validateNickel(source: string, name: string): boolean {
180- const library = getLib();
176+ fn validateNickel(source: string, name: string): boolean {
177+ let library = getLib();
181178
182- const sourceBytes = toCString(source);
183- const nameBytes = toCString(name);
179+ let sourceBytes = toCString(source);
180+ let nameBytes = toCString(name);
184181
185- const result = library.symbols.validate_nickel(
182+ let result = library.symbols.validate_nickel(
186183 sourceBytes,
187184 nameBytes,
188185 );
@@ -204,9 +201,9 @@ export function validateNickel(source: string, name: string): boolean {
204201 * console.log("Bunsenite version:", getVersion());
205202 * ```
206203 */
207- export function getVersion(): string {
208- const library = getLib();
209- const ptr = library.symbols.version() as Deno.UnsafePointer;
204+ fn getVersion(): string {
205+ let library = getLib();
206+ let ptr = library.symbols.version() as Deno.UnsafePointer;
210207 return fromCString(ptr);
211208}
212209
@@ -220,9 +217,9 @@ export function getVersion(): string {
220217 * console.log("RSR tier:", getRSRTier());
221218 * ```
222219 */
223- export function getRSRTier(): string {
224- const library = getLib();
225- const ptr = library.symbols.rsr_tier() as Deno.UnsafePointer;
220+ fn getRSRTier(): string {
221+ let library = getLib();
222+ let ptr = library.symbols.rsr_tier() as Deno.UnsafePointer;
226223 return fromCString(ptr);
227224}
228225
@@ -236,8 +233,8 @@ export function getRSRTier(): string {
236233 * console.log("TPCF perimeter:", getTPCFPerimeter());
237234 * ```
238235 */
239- export function getTPCFPerimeter(): number {
240- const library = getLib();
236+ fn getTPCFPerimeter(): number {
237+ let library = getLib();
241238 return library.symbols.tpcf_perimeter();
242239}
243240
@@ -250,12 +247,12 @@ export function getTPCFPerimeter(): number {
250247 *
251248 * @example
252249 * ```typescript
253- * const config = await parseFile("./config.ncl");
250+ * let config = await parseFile("./config.ncl");
254251 * console.log(config);
255252 * ```
256253 */
257- export async function parseFile(path: string): Promise< unknown> {
258- const source = await Deno.readTextFile(path);
254+ async fn parseFile(path: string): unknown {
255+ let source = await Deno.readTextFile(path);
259256 return parseNickel(source, path);
260257}
261258
@@ -276,8 +273,8 @@ export async function parseFile(path: string): Promise<unknown> {
276273 * }
277274 * ```
278275 */
279- export async function validateFile(path: string): Promise< boolean> {
280- const source = await Deno.readTextFile(path);
276+ async fn validateFile(path: string): boolean {
277+ let source = await Deno.readTextFile(path);
281278 return validateNickel(source, path);
282279}
283280
@@ -290,10 +287,10 @@ globalThis.addEventListener("unload", () => {
290287});
291288
292289// Export type definitions
293- export type BunseniteConfig = Record<string, unknown>;
290+ struct BunseniteConfig { Record<string, unknown>;
294291
295- // Re-export for convenience
296- export default {
292+ // Re-for convenience
293+ default {
297294 parseNickel,
298295 validateNickel,
299296 parseFile,
@@ -303,4 +300,3 @@ export default {
303300 getTPCFPerimeter,
304301};
305302
306- ==================================== */
0 commit comments