@@ -135,6 +135,8 @@ int jit_edict(EMITTER emit,void *data,int len)
135
135
return status ;
136
136
}
137
137
138
+ int jit_edict2 (EMITTER emit , void * data , int len ) { return jit_edict (emit , data , len ); }
139
+
138
140
int jit_xml (EMITTER emit , void * data , int len ) { printf ("jit_xml not implemented\n" ); }
139
141
140
142
/*
@@ -254,76 +256,76 @@ int jit_json(EMITTER emit, void *data, int len)
254
256
}
255
257
*/
256
258
257
- LTV * compile (COMPILER compiler ,void * data ,int len )
258
- {
259
- TSTART (0 ,"compile" );
260
- char * buf = NULL ;
261
- size_t flen = 0 ;
262
- FILE * stream = open_memstream (& buf ,& flen );
259
+ LTV * compile (COMPILER compiler , void * data , int len ) {
260
+ TSTART (0 , "compile" );
261
+ char * buf = NULL ;
262
+ size_t flen = 0 ;
263
+ FILE * stream = open_memstream (& buf , & flen );
263
264
264
- int emit (VM_CMD * cmd ) {
265
+ int emit (VM_CMD * cmd ) {
265
266
unsigned unsigned_val ;
266
- fwrite (& cmd -> op ,1 , 1 , stream );
267
- if (cmd -> op == VMOP_EXT ) {
267
+ fwrite (& cmd -> op , 1 , 1 , stream );
268
+ if (cmd -> op == VMOP_EXT ) {
268
269
switch (cmd -> len ) {
269
270
case -1 :
270
- cmd -> len = strlen (cmd -> data ); // rewrite len and...
271
+ cmd -> len = strlen (cmd -> data ); // rewrite len and...
271
272
// ...fall thru!
272
273
default :
273
- unsigned_val = htonl (cmd -> len );
274
- fwrite (& unsigned_val ,sizeof (unsigned ),1 , stream );
275
- unsigned_val = htonl (cmd -> flags );
276
- fwrite (& unsigned_val ,sizeof (unsigned ),1 , stream );
277
- fwrite (cmd -> data ,1 , cmd -> len ,stream );
274
+ unsigned_val = htonl (cmd -> len );
275
+ fwrite (& unsigned_val , sizeof (unsigned ), 1 , stream );
276
+ unsigned_val = htonl (cmd -> flags );
277
+ fwrite (& unsigned_val , sizeof (unsigned ), 1 , stream );
278
+ fwrite (cmd -> data , 1 , cmd -> len , stream );
278
279
break ;
279
280
}
280
281
}
281
282
}
282
283
283
- if (len == -1 )
284
- len = strlen ((char * ) data );
285
- compiler (emit ,data ,len );
284
+ if (len == -1 )
285
+ len = strlen ((char * ) data );
286
+ compiler (emit , data , len );
286
287
fclose (stream );
287
- TFINISH (0 ,"compile" );
288
- return LTV_init (NEW (LTV ),buf ,flen ,LT_BC | LT_OWN | LT_BIN | LT_LIST );
288
+ TFINISH (0 , "compile" );
289
+ return LTV_init (NEW (LTV ), buf , flen , LT_BC | LT_OWN | LT_BIN | LT_LIST );
289
290
}
290
291
291
- LTV * compile_ltv (COMPILER compiler ,LTV * ltv )
292
- {
292
+ LTV * compile_ltv (COMPILER compiler , LTV * ltv ) {
293
293
// print_ltv(stdout,CODE_RED "compile: ",ltv,CODE_RESET "\n",0);
294
- if (ltv -> flags & (LT_CVAR | LT_BC ))
295
- return ltv ; // FFI or pre-compiled
296
- LTV * bc = compile (compiler ,ltv -> data ,ltv -> len );
294
+ if (ltv -> flags & (LT_CVAR | LT_BC ))
295
+ return ltv ; // FFI or pre-compiled
296
+ LTV * bc = compile (compiler , ltv -> data , ltv -> len );
297
297
return bc ;
298
298
}
299
299
300
- char * opcode_name [] = { "RESET" ,"YIELD" ,"EXT" ,"THROW" ,"CATCH" ,"PUSHEXT" ,"EVAL" ,"REF" ,"DEREF" ,"ASSIGN" ,"REMOVE" ,"CTX_PUSH" ,"CTX_POP" ,"FUN_PUSH" ,"FUN_EVAL" ,"FUN_POP" ,
301
- "S2S" ,"D2S" ,"E2S" ,"F2S" ,"S2D" ,"S2E" ,"S2F" };
302
-
303
- void disassemble (FILE * ofile ,LTV * ltv )
304
- {
305
- TSTART (0 ,"disassemble" );
306
- unsigned char * data ,* code = (unsigned char * ) ltv -> data ;
307
- int i = 0 ,length = 0 ,flags = 0 ;
308
- fprintf (ofile ,"BYTECODE: " );
309
- while (i < ltv -> len ) {
310
- unsigned char opcode = code [i ++ ];
311
- switch (opcode ) {
300
+ char * opcode_name [] = {"RESET" , "YIELD" , "EXT" , "THROW" , "CATCH" , "PUSHEXT" , "EVAL" , "REF" , "DEREF" , "ASSIGN" , "REMOVE" , "CTX_PUSH" , "CTX_POP" , "FUN_PUSH" , "FUN_EVAL" , "FUN_POP" ,
301
+ "S2S" , "D2S" , "E2S" , "F2S" , "S2D" , "S2E" , "S2F" };
302
+
303
+ void disassemble (FILE * ofile , LTV * ltv ) {
304
+ TSTART (0 , "disassemble" );
305
+ unsigned char * data , * code = (unsigned char * ) ltv -> data ;
306
+ int i = 0 , length = 0 , flags = 0 ;
307
+ fprintf (ofile , "BYTECODE: " );
308
+ while (i < ltv -> len ) {
309
+ unsigned char opcode = code [i ++ ];
310
+ switch (opcode ) {
312
311
case VMOP_EXT :
313
- length = ntohl (* (unsigned * ) (code + i )); i += sizeof (unsigned );
314
- flags = ntohl (* (unsigned * ) (code + i )); i += sizeof (unsigned );
315
- data = code + i ; i += length ;
316
- //fprintf(ofile, "\n" CODE_BLUE);
312
+ length = ntohl (* (unsigned * ) (code + i ));
313
+ i += sizeof (unsigned );
314
+ flags = ntohl (* (unsigned * ) (code + i ));
315
+ i += sizeof (unsigned );
316
+ data = code + i ;
317
+ i += length ;
318
+ // fprintf(ofile, "\n" CODE_BLUE);
317
319
fprintf (ofile , CODE_BLUE );
318
- fstrnprint (ofile ,data ,length );
320
+ fstrnprint (ofile , data , length );
319
321
fprintf (ofile , ":%x " CODE_RESET , flags );
320
322
break ;
321
323
case VMOP_RESET :
322
- //fprintf(ofile,"\n");
324
+ // fprintf(ofile,"\n");
323
325
default :
324
- fprintf (ofile ,"%s " ,opcode_name [opcode ]);
326
+ fprintf (ofile , "%s " , opcode_name [opcode ]);
325
327
}
326
328
}
327
- fprintf (ofile ,"\n" );
328
- TFINISH (0 ,"disassemble" );
329
+ fprintf (ofile , "\n" );
330
+ TFINISH (0 , "disassemble" );
329
331
}
0 commit comments