@@ -487,7 +487,7 @@ pub unsafe fn compile_primary_expression(l: *mut Lexer, c: *mut Compiler) -> Opt
487
487
get_and_expect_token_but_continue ( l, c, Token :: CBracket ) ?;
488
488
489
489
let result = allocate_auto_var ( & mut ( * c) . auto_vars_ator ) ;
490
- let word_size = Arg :: Literal ( target_word_size ( ( * c) . target ) ) ;
490
+ let word_size = Arg :: Literal ( ( * c) . target . word_size ( ) ) ;
491
491
// TODO: Introduce Op::Index instruction that indices values without explicitly emit Binop::Mult and uses efficient multiplication by the size of the word at the codegen level.
492
492
push_opcode ( Op :: Binop { binop : Binop :: Mult , index : result, lhs : offset, rhs : word_size} , ( * l) . loc , c) ;
493
493
push_opcode ( Op :: Binop { binop : Binop :: Plus , index : result, lhs : arg, rhs : Arg :: AutoVar ( result) } , ( * l) . loc , c) ;
@@ -1139,9 +1139,9 @@ pub unsafe fn compile_program(l: *mut Lexer, c: *mut Compiler) -> Option<()> {
1139
1139
}
1140
1140
1141
1141
pub unsafe fn include_path_if_exists ( input_paths : & mut Array < * const c_char > , path : * const c_char ) -> Option < ( ) > {
1142
- let path_exists = file_exists ( path) ;
1143
- if path_exists < 0 { return None ; }
1144
- if path_exists > 0 { da_append ( input_paths , path ) ; }
1142
+ if file_exists ( path) ? {
1143
+ da_append ( input_paths , path ) ;
1144
+ }
1145
1145
Some ( ( ) )
1146
1146
}
1147
1147
@@ -1158,7 +1158,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1158
1158
}
1159
1159
1160
1160
let default_target_name = if let Some ( default_target) = default_target {
1161
- name_of_target ( default_target) . expect ( "default target name not found" )
1161
+ default_target. name ( )
1162
1162
} else {
1163
1163
ptr:: null ( )
1164
1164
} ;
@@ -1205,13 +1205,13 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1205
1205
1206
1206
if strcmp ( * target_name, c ! ( "list" ) ) == 0 {
1207
1207
fprintf ( stderr ( ) , c ! ( "Compilation targets:\n " ) ) ;
1208
- for i in 0 ..TARGET_NAMES . len ( ) {
1209
- fprintf ( stderr ( ) , c ! ( " %s\n " ) , ( * TARGET_NAMES ) [ i] . name ) ;
1208
+ for i in 0 ..TARGET_ORDER . len ( ) {
1209
+ fprintf ( stderr ( ) , c ! ( " %s\n " ) , ( * TARGET_ORDER ) [ i] . name ( ) ) ;
1210
1210
}
1211
1211
return Some ( ( ) ) ;
1212
1212
}
1213
1213
1214
- let Some ( target) = target_by_name ( * target_name) else {
1214
+ let Some ( target) = Target :: by_name ( * target_name) else {
1215
1215
usage ( ) ;
1216
1216
fprintf ( stderr ( ) , c ! ( "ERROR: unknown target `%s`\n " ) , * target_name) ;
1217
1217
return None ;
@@ -1238,9 +1238,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1238
1238
//
1239
1239
// - rexim (2025-06-12 20:56:08)
1240
1240
let libb_path = c ! ( "./libb" ) ;
1241
- let libb_path_exist = file_exists ( libb_path) ;
1242
- if libb_path_exist < 0 { return None ; }
1243
- if libb_path_exist == 0 {
1241
+ if !file_exists ( libb_path) ? {
1244
1242
fprintf ( stderr ( ) , c ! ( "ERROR: No standard library path %s found. Please run the compiler from the same folder where %s is located. Or if you don't want to use the standard library pass the -%s flag.\n " ) , libb_path, libb_path, flag_name ( nostdlib) ) ;
1245
1243
return None ;
1246
1244
}
@@ -1272,7 +1270,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1272
1270
let input_path = * input_paths. items . add ( i) ;
1273
1271
1274
1272
input. count = 0 ;
1275
- if ! read_entire_file ( input_path, & mut input) { return None ; }
1273
+ read_entire_file ( input_path, & mut input) ? ;
1276
1274
1277
1275
let mut l: Lexer = lexer:: new ( input_path, input. items , input. items . add ( input. count ) , * historical) ;
1278
1276
@@ -1310,7 +1308,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1310
1308
}
1311
1309
1312
1310
let output_asm_path = temp_sprintf ( c ! ( "%s.s" ) , effective_output_path) ;
1313
- if ! write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) { return None ; }
1311
+ write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) ? ;
1314
1312
printf ( c ! ( "INFO: Generated %s\n " ) , output_asm_path) ;
1315
1313
1316
1314
let ( gas, cc) = if cfg ! ( target_arch = "aarch64" ) && ( cfg ! ( target_os = "linux" ) || cfg ! ( target_os = "android" ) ) {
@@ -1351,7 +1349,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1351
1349
}
1352
1350
if !cmd_run_sync_and_reset ( & mut cmd) { return None ; }
1353
1351
if * run {
1354
- runner:: gas_aarch64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) ) ?;
1352
+ runner:: gas_aarch64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) , None ) ?;
1355
1353
}
1356
1354
}
1357
1355
Target :: Gas_x86_64_Linux => {
@@ -1369,7 +1367,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1369
1367
}
1370
1368
1371
1369
let output_asm_path = temp_sprintf ( c ! ( "%s.s" ) , effective_output_path) ;
1372
- if ! write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) { return None ; }
1370
+ write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) ? ;
1373
1371
printf ( c ! ( "INFO: Generated %s\n " ) , output_asm_path) ;
1374
1372
1375
1373
if !( cfg ! ( target_arch = "x86_64" ) && cfg ! ( target_os = "linux" ) ) {
@@ -1402,7 +1400,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1402
1400
}
1403
1401
if !cmd_run_sync_and_reset ( & mut cmd) { return None ; }
1404
1402
if * run {
1405
- runner:: gas_x86_64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) ) ?
1403
+ runner:: gas_x86_64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) , None ) ?
1406
1404
}
1407
1405
}
1408
1406
Target :: Gas_x86_64_Windows => {
@@ -1426,7 +1424,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1426
1424
let effective_output_path = temp_sprintf ( c ! ( "%s.exe" ) , base_path) ;
1427
1425
1428
1426
let output_asm_path = temp_sprintf ( c ! ( "%s.s" ) , base_path) ;
1429
- if ! write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) { return None ; }
1427
+ write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) ? ;
1430
1428
printf ( c ! ( "INFO: Generated %s\n " ) , output_asm_path) ;
1431
1429
1432
1430
let cc = if cfg ! ( target_arch = "x86_64" ) && cfg ! ( target_os = "windows" ) {
@@ -1459,7 +1457,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1459
1457
}
1460
1458
if !cmd_run_sync_and_reset ( & mut cmd) { return None ; }
1461
1459
if * run {
1462
- runner:: gas_x86_64_windows:: run ( & mut cmd, effective_output_path, da_slice ( run_args) ) ?;
1460
+ runner:: gas_x86_64_windows:: run ( & mut cmd, effective_output_path, da_slice ( run_args) , None ) ?;
1463
1461
}
1464
1462
}
1465
1463
Target :: Fasm_x86_64_Linux => {
@@ -1477,7 +1475,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1477
1475
}
1478
1476
1479
1477
let output_asm_path = temp_sprintf ( c ! ( "%s.asm" ) , effective_output_path) ;
1480
- if ! write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) { return None ; }
1478
+ write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) ? ;
1481
1479
printf ( c ! ( "INFO: Generated %s\n " ) , output_asm_path) ;
1482
1480
1483
1481
if !( cfg ! ( target_arch = "x86_64" ) && cfg ! ( target_os = "linux" ) ) {
@@ -1510,7 +1508,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1510
1508
}
1511
1509
if !cmd_run_sync_and_reset ( & mut cmd) { return None ; }
1512
1510
if * run {
1513
- runner:: fasm_x86_64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) ) ?
1511
+ runner:: fasm_x86_64_linux:: run ( & mut cmd, effective_output_path, da_slice ( run_args) , None ) ?
1514
1512
}
1515
1513
}
1516
1514
Target :: Fasm_x86_64_Windows => {
@@ -1534,7 +1532,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1534
1532
let effective_output_path = temp_sprintf ( c ! ( "%s.exe" ) , base_path) ;
1535
1533
1536
1534
let output_asm_path = temp_sprintf ( c ! ( "%s.asm" ) , base_path) ;
1537
- if ! write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) { return None ; }
1535
+ write_entire_file ( output_asm_path, output. items as * const c_void , output. count ) ? ;
1538
1536
printf ( c ! ( "INFO: Generated %s\n " ) , output_asm_path) ;
1539
1537
1540
1538
let cc = if cfg ! ( target_arch = "x86_64" ) && cfg ! ( target_os = "windows" ) {
@@ -1567,7 +1565,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1567
1565
}
1568
1566
if !cmd_run_sync_and_reset ( & mut cmd) { return None ; }
1569
1567
if * run {
1570
- runner:: fasm_x86_64_windows:: run ( & mut cmd, effective_output_path, da_slice ( run_args) ) ?;
1568
+ runner:: fasm_x86_64_windows:: run ( & mut cmd, effective_output_path, da_slice ( run_args) , None ) ?;
1571
1569
}
1572
1570
}
1573
1571
Target :: Uxn => {
@@ -1582,10 +1580,10 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1582
1580
effective_output_path = * output_path;
1583
1581
}
1584
1582
1585
- if ! write_entire_file ( effective_output_path, output. items as * const c_void , output. count ) { return None ; }
1583
+ write_entire_file ( effective_output_path, output. items as * const c_void , output. count ) ? ;
1586
1584
printf ( c ! ( "INFO: Generated %s\n " ) , effective_output_path) ;
1587
1585
if * run {
1588
- runner:: uxn:: run ( & mut cmd, c ! ( "uxnemu" ) , effective_output_path, da_slice ( run_args) ) ?;
1586
+ runner:: uxn:: run ( & mut cmd, c ! ( "uxnemu" ) , effective_output_path, da_slice ( run_args) , None ) ?;
1589
1587
}
1590
1588
}
1591
1589
Target :: Mos6502 => {
@@ -1601,10 +1599,10 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
1601
1599
effective_output_path = * output_path;
1602
1600
}
1603
1601
1604
- if ! write_entire_file ( effective_output_path, output. items as * const c_void , output. count ) { return None ; }
1602
+ write_entire_file ( effective_output_path, output. items as * const c_void , output. count ) ? ;
1605
1603
printf ( c ! ( "INFO: Generated %s\n " ) , effective_output_path) ;
1606
1604
if * run {
1607
- runner:: mos6502:: run ( & mut output, config, effective_output_path) ?;
1605
+ runner:: mos6502:: run ( & mut output, config, effective_output_path, None ) ?;
1608
1606
}
1609
1607
}
1610
1608
}
0 commit comments