diff options
Diffstat (limited to 'js/baba-yaga/debug-interpreter.js')
-rw-r--r-- | js/baba-yaga/debug-interpreter.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/js/baba-yaga/debug-interpreter.js b/js/baba-yaga/debug-interpreter.js new file mode 100644 index 0000000..05d817b --- /dev/null +++ b/js/baba-yaga/debug-interpreter.js @@ -0,0 +1,45 @@ +// debug-interpreter.js - Debug the interpreter JS bridge setup + +import { createLexer } from './src/core/lexer.js'; +import { createParser } from './src/core/parser.js'; +import { createInterpreter } from './src/core/interpreter.js'; + +const code = ` + result : io.callJS "Math.abs" [-5]; +`; + +const lexer = createLexer(code); +const tokens = lexer.allTokens(); +const parser = createParser(tokens); +const ast = parser.parse(); + +const host = { + jsBridgeConfig: { + allowedFunctions: new Set([ + 'JSON.parse', 'JSON.stringify', + 'Math.abs', 'Math.floor', 'Math.ceil', 'Math.round', + 'Math.min', 'Math.max', 'Math.random', + 'console.log', 'console.warn', 'console.error', + 'Date.now', 'performance.now' + ]) + }, + io: { + out: (...args) => console.log('[OUT]', ...args), + debug: (...args) => console.log('[DEBUG]', ...args) + } +}; + +console.log('Host config:', host.jsBridgeConfig); + +const interpreter = createInterpreter(ast, host); +console.log('Interpreter created'); + +// Let's see if we can access the bridge +console.log('Interpreter scope has io?', interpreter.scope.has('io')); +const ioObj = interpreter.scope.get('io'); +console.log('IO object:', ioObj); +console.log('IO properties:', Array.from(ioObj.properties.keys())); + +interpreter.interpret(); +const result = interpreter.scope.get('result'); +console.log('Final result:', result); |