@@ -127,13 +127,15 @@ async function doLoadCompiler(
127127) : Promise < TRubyCompiler > {
128128 try {
129129 // Step 1: Load Ruby WASM module
130+ console . log ( '[T-Ruby] Step 1: Loading Ruby WASM module from' , RUBY_WASM_CDN ) ;
130131 onProgress ?.( {
131132 state : 'loading' ,
132133 message : 'Loading Ruby runtime...' ,
133134 progress : 10
134135 } ) ;
135136
136137 const { DefaultRubyVM } = await import ( /* webpackIgnore: true */ RUBY_WASM_CDN ) ;
138+ console . log ( '[T-Ruby] Step 1 complete: DefaultRubyVM loaded' ) ;
137139
138140 onProgress ?.( {
139141 state : 'loading' ,
@@ -142,8 +144,11 @@ async function doLoadCompiler(
142144 } ) ;
143145
144146 // Step 2: Fetch and compile WASM binary
147+ console . log ( '[T-Ruby] Step 2: Fetching WASM binary from' , RUBY_WASM_BINARY ) ;
145148 const response = await fetch ( RUBY_WASM_BINARY ) ;
149+ console . log ( '[T-Ruby] Step 2: WASM fetch response status:' , response . status ) ;
146150 const wasmModule = await WebAssembly . compileStreaming ( response ) ;
151+ console . log ( '[T-Ruby] Step 2 complete: WASM module compiled' ) ;
147152
148153 onProgress ?.( {
149154 state : 'loading' ,
@@ -152,8 +157,10 @@ async function doLoadCompiler(
152157 } ) ;
153158
154159 // Step 3: Initialize Ruby VM
160+ console . log ( '[T-Ruby] Step 3: Initializing Ruby VM...' ) ;
155161 const { vm } = await DefaultRubyVM ( wasmModule ) ;
156162 rubyVM = vm ;
163+ console . log ( '[T-Ruby] Step 3 complete: Ruby VM initialized' ) ;
157164
158165 onProgress ?.( {
159166 state : 'loading' ,
@@ -162,11 +169,15 @@ async function doLoadCompiler(
162169 } ) ;
163170
164171 // Step 4: Load T-Ruby library
165- // For now, we'll use a simplified approach that works without VFS mounting
166- // In production, the T-Ruby lib files should be bundled or fetched
172+ console . log ( '[T-Ruby] Step 4: Loading T-Ruby compiler bootstrap...' ) ;
167173
168174 // Initialize the compiler bootstrap
169175 vm . eval ( BOOTSTRAP_CODE ) ;
176+ console . log ( '[T-Ruby] Step 4 complete: Bootstrap code evaluated' ) ;
177+
178+ // Health check
179+ const healthResult = vm . eval ( '__trb_health_check__' ) ;
180+ console . log ( '[T-Ruby] Health check:' , healthResult . toString ( ) ) ;
170181
171182 onProgress ?.( {
172183 state : 'ready' ,
@@ -177,8 +188,18 @@ async function doLoadCompiler(
177188 // Return compiler interface
178189 return {
179190 compile ( code : string ) : CompileResult {
180- const resultJson = vm . eval ( `__trb_compile__(${ JSON . stringify ( code ) } )` ) ;
181- return JSON . parse ( resultJson . toString ( ) ) ;
191+ console . log ( '[T-Ruby] Compiling code:' , code . substring ( 0 , 100 ) + ( code . length > 100 ? '...' : '' ) ) ;
192+ try {
193+ const resultJson = vm . eval ( `__trb_compile__(${ JSON . stringify ( code ) } )` ) ;
194+ const resultStr = resultJson . toString ( ) ;
195+ console . log ( '[T-Ruby] Raw compile result:' , resultStr ) ;
196+ const result = JSON . parse ( resultStr ) ;
197+ console . log ( '[T-Ruby] Parsed compile result:' , result ) ;
198+ return result ;
199+ } catch ( e ) {
200+ console . error ( '[T-Ruby] Compile error:' , e ) ;
201+ throw e ;
202+ }
182203 } ,
183204
184205 healthCheck ( ) {
@@ -192,6 +213,7 @@ async function doLoadCompiler(
192213 }
193214 } ;
194215 } catch ( error ) {
216+ console . error ( '[T-Ruby] Loading error:' , error ) ;
195217 onProgress ?.( {
196218 state : 'error' ,
197219 message : error instanceof Error ? error . message : 'Unknown error'
0 commit comments