@@ -24,6 +24,7 @@ enum DebugBytecode {
24
24
DBC_DELAY = 7 ,
25
25
DBC_PC_KEY = 8 ,
26
26
DBC_PC_MOUSE = 9 ,
27
+ DBC_CZ = 10 , // this one is special because DBC_FLAG_NOCOMMA applies to it
27
28
28
29
// Flags
29
30
DBC_FLAG_NOCOMMA = 0x01 ,
@@ -37,6 +38,7 @@ enum DebugBytecode {
37
38
// Output type
38
39
DBC_TYPE_STR = 0x20 | DBC_SIZE_BYTE ,
39
40
DBC_TYPE_FLP = 0x20 , // Note the overlap with the signed flag and the string type
41
+ DBC_TYPE_BOL = 0x20 , // etc, etc
40
42
DBC_TYPE_DEC = 0x40 ,
41
43
DBC_TYPE_HEX = 0x80 ,
42
44
DBC_TYPE_BIN = 0xC0 ,
@@ -55,6 +57,9 @@ static struct DebugFunc debug_func_table[] = {
55
57
{"dly" ,DBC_DELAY },
56
58
{"pc_key" ,DBC_PC_KEY },
57
59
{"pc_mouse" ,DBC_PC_MOUSE },
60
+ {"c_z" ,DBC_CZ },
61
+
62
+ {"bool" ,DBC_TYPE_BOL },
58
63
59
64
{"zstr" ,DBC_TYPE_STR },
60
65
{"lstr" ,DBC_TYPE_STR |DBC_FLAG_ARRAY },
@@ -256,80 +261,87 @@ int AsmDebug_CodeGen(AST *ast, BackendDebugEval evalFunc, void *evalArg) {
256
261
if (simple && noExpr ) {
257
262
ERROR (item ,"Cannot use underscore on simple functions" );
258
263
}
259
- if (!simple && !needcomma ) opcode |= DBC_FLAG_NOCOMMA ;
264
+ if (( !simple || opcode == DBC_CZ ) && !needcomma ) opcode |= DBC_FLAG_NOCOMMA ;
260
265
if (!simple && noExpr ) opcode |= DBC_FLAG_NOEXPR ;
261
266
262
- int expectedArgs = (func -> opcode & DBC_FLAG_ARRAY ) ? 2 : 1 ;
263
- int gotArgs = 0 ;
264
- ASSERT_AST_KIND (item -> right ,AST_EXPRLIST ,break ;);
265
- for (AST * arglist = item -> right ;arglist ;arglist = arglist -> right ) {
266
- if (gotArgs == 0 ) {
267
- flexbuf_putc (opcode ,f );
268
- DEBUG (item ,"Emitting DEBUG opcode %02X" ,opcode );
269
- }
270
- gotArgs ++ ;
271
- AST * arg = arglist -> left ;
272
- int addrKind , addr ;
273
-
274
- if (gotArgs == 1 && !simple && !noExpr ) {
275
- // TOOD: Yoink expression string from source buffer
276
- AST * exprAst = arg ;
277
- if (exprAst -> kind == AST_IMMHOLDER ) {
278
- flexbuf_putc ('#' ,f );
279
- exprAst = exprAst -> left ;
280
- }
281
- if (IsIdentifier (exprAst )) {
282
- const char * expr = GetUserIdentifierName (exprAst );
283
- flexbuf_addstr (f ,expr );
284
- } else {
285
- PrintExpr (f , exprAst , PRINTEXPR_DEBUG );
267
+ if ((opcode & ~DBC_FLAG_NOCOMMA ) == DBC_CZ ) {
268
+ // Special no-argument function C_Z (I hate what I have brought upon myself)
269
+ if (item -> right && item -> right -> left ) ERROR (item ,"C_Z takes no arguments" );
270
+ flexbuf_putc (opcode ,f );
271
+ DEBUG (item ,"Emitting DEBUG opcode %02X" ,opcode );
272
+ } else {
273
+ int expectedArgs = (func -> opcode & DBC_FLAG_ARRAY ) ? 2 : 1 ;
274
+ int gotArgs = 0 ;
275
+ ASSERT_AST_KIND (item -> right ,AST_EXPRLIST ,break ;);
276
+ for (AST * arglist = item -> right ;arglist ;arglist = arglist -> right ) {
277
+ if (gotArgs == 0 ) {
278
+ flexbuf_putc (opcode ,f );
279
+ DEBUG (item ,"Emitting DEBUG opcode %02X" ,opcode );
286
280
}
287
- flexbuf_putc (0 ,f );
288
- }
289
-
290
- addrKind = (* evalFunc )(arg , regNum , & addr , evalArg );
291
- switch (addrKind ) {
292
- case PASM_EVAL_ISCONST :
293
- emitAsmConstant (f , addr );
294
- break ;
295
- case PASM_EVAL_ISREG :
296
- emitAsmRegref (f , addr );
297
- regNum ++ ;
298
- break ;
299
- case PASM_EVAL_ISREG_2 :
300
- case PASM_EVAL_ISREG_3 :
301
- case PASM_EVAL_ISREG_4 :
302
- emitAsmRegref (f , addr );
303
- regNum ++ ;
304
- addr ++ ;
305
- for (int n = PASM_EVAL_ISREG ; n < addrKind ; n ++ ) {
306
- if (gotArgs == expectedArgs ) {
307
- opcode &= ~DBC_FLAG_NOCOMMA ;
308
- flexbuf_putc (opcode |DBC_FLAG_NOEXPR , f );
309
- DEBUG (item ,"Emitting DEBUG opcode %02X" ,opcode |DBC_FLAG_NOEXPR );
310
- gotArgs = 1 ;
281
+ gotArgs ++ ;
282
+ AST * arg = arglist -> left ;
283
+ int addrKind , addr ;
284
+
285
+ if (gotArgs == 1 && !simple && !noExpr ) {
286
+ // TOOD: Yoink expression string from source buffer
287
+ AST * exprAst = arg ;
288
+ if (exprAst -> kind == AST_IMMHOLDER ) {
289
+ flexbuf_putc ('#' ,f );
290
+ exprAst = exprAst -> left ;
291
+ }
292
+ if (IsIdentifier (exprAst )) {
293
+ const char * expr = GetUserIdentifierName (exprAst );
294
+ flexbuf_addstr (f ,expr );
311
295
} else {
312
- gotArgs ++ ;
296
+ PrintExpr ( f , exprAst , PRINTEXPR_DEBUG ) ;
313
297
}
298
+ flexbuf_putc (0 ,f );
299
+ }
300
+
301
+ addrKind = (* evalFunc )(arg , regNum , & addr , evalArg );
302
+ switch (addrKind ) {
303
+ case PASM_EVAL_ISCONST :
304
+ emitAsmConstant (f , addr );
305
+ break ;
306
+ case PASM_EVAL_ISREG :
307
+ emitAsmRegref (f , addr );
308
+ regNum ++ ;
309
+ break ;
310
+ case PASM_EVAL_ISREG_2 :
311
+ case PASM_EVAL_ISREG_3 :
312
+ case PASM_EVAL_ISREG_4 :
314
313
emitAsmRegref (f , addr );
315
- addr ++ ; regNum ++ ;
314
+ regNum ++ ;
315
+ addr ++ ;
316
+ for (int n = PASM_EVAL_ISREG ; n < addrKind ; n ++ ) {
317
+ if (gotArgs == expectedArgs ) {
318
+ opcode &= ~DBC_FLAG_NOCOMMA ;
319
+ flexbuf_putc (opcode |DBC_FLAG_NOEXPR , f );
320
+ DEBUG (item ,"Emitting DEBUG opcode %02X" ,opcode |DBC_FLAG_NOEXPR );
321
+ gotArgs = 1 ;
322
+ } else {
323
+ gotArgs ++ ;
324
+ }
325
+ emitAsmRegref (f , addr );
326
+ addr ++ ; regNum ++ ;
327
+ }
328
+ needcomma = true;
329
+ break ;
330
+ default :
331
+ ERROR (arg , "Unknown address kind returned by back end" );
332
+ break ;
333
+ }
334
+ if (gotArgs == expectedArgs ) {
335
+ // consumed them all
336
+ gotArgs = 0 ;
337
+ needcomma = true;
338
+ opcode &= ~DBC_FLAG_NOCOMMA ;
316
339
}
317
- needcomma = true;
318
- break ;
319
- default :
320
- ERROR (arg , "Unknown address kind returned by back end" );
321
- break ;
322
340
}
323
- if (gotArgs == expectedArgs ) {
324
- // consumed them all
325
- gotArgs = 0 ;
326
- needcomma = true;
327
- opcode &= ~DBC_FLAG_NOCOMMA ;
341
+ if (gotArgs ) {
342
+ ERROR (item ,"%s expects %d args, got %d" ,name ,expectedArgs ,gotArgs );
328
343
}
329
344
}
330
- if (gotArgs ) {
331
- ERROR (item ,"%s expects %d args, got %d" ,name ,expectedArgs ,gotArgs );
332
- }
333
345
needcomma = true;
334
346
} break ;
335
347
case AST_IDENTIFIER :
0 commit comments