hindiscript-lang
Version:
HindiScript – A tiny Hindi-first toy language that runs .hs files. Created by Atikin Verse.
34 lines (27 loc) • 971 B
JavaScript
// Runtime provides safe globals and utilities HindiScript code can use.
// All exposed functions/values live on __globals.
export function makeRuntime({ print }) {
const timers = new Set();
const __globals = {
// Printing
__print: (...args) => print(...args),
// Timers
__setTimeout: (fn, ms, ...args) => setTimeout(fn, ms, ...args),
__setInterval: (fn, ms, ...args) => {
const id = setInterval(fn, ms, ...args);
timers.add(id);
return id;
},
__clearInterval: (id) => {
clearInterval(id);
timers.delete(id);
},
// Container for user-defined मुख्य
__main: undefined
};
// Clean up intervals on process exit
const cleanup = () => timers.forEach(clearInterval);
process.on('exit', cleanup);
process.on('SIGINT', () => { cleanup(); process.exit(130); });
return { __globals };
}