about summary refs log tree commit diff stats
path: root/subx/apps
diff options
context:
space:
mode:
Diffstat (limited to 'subx/apps')
-rwxr-xr-xsubx/apps/packbin22273 -> 22467 bytes
-rw-r--r--subx/apps/pack.subx81
2 files changed, 74 insertions, 7 deletions
diff --git a/subx/apps/pack b/subx/apps/pack
index a5f8eda3..fda8cb03 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/pack.subx b/subx/apps/pack.subx
index d25405ab..28de82c0 100644
--- a/subx/apps/pack.subx
+++ b/subx/apps/pack.subx
@@ -1396,8 +1396,9 @@ test-has-metadata-multiple-false:
     5d/pop-to-EBP
     c3/return
 
-# if the name of 'word' is all hex digits, parse and print its value in 'width' bytes of hex, least significant first
-# otherwise just print the entire word
+# If value of 'word' is not a valid name, it must be a hex int. Parse and print
+# it in 'width' bytes of hex, least significant first.
+# Otherwise just print the entire word including metadata.
 emit:  # out : (address buffered-file), word : (address slice), width : int
     # . prolog
     55/push-EBP
@@ -1422,17 +1423,17 @@ emit:  # out : (address buffered-file), word : (address slice), width : int
     e8/call  next-token-from-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
-    # if (!is-hex-int?(name)) write-slice(out, word) and return
-    # . is-hex-int?(name)
+    # if (is-valid-name?(name)) write-slice(out, word) and return
+    # . EAX = is-valid-name?(name)
     # . . push args
     57/push-EDI
     # . . call
-    e8/call  is-hex-int?/disp32
+    e8/call  is-valid-name?/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # . if (EAX == 0)
+    # . if (EAX != 0)
     81          7/subop/compare     3/mod/direct    0/rm32/EAX    .           .             .           .           .               0/imm32           # compare EAX
-    75/jump-if-not-equal  $emit:hex-int/disp8
+    74/jump-if-equal  $emit:hex-int/disp8
     # . write-slice(out, word)
     # . . push args
     56/push-ESI
@@ -1444,6 +1445,10 @@ emit:  # out : (address buffered-file), word : (address slice), width : int
     # . return
     eb/jump  $emit:end/disp8
     # otherwise emit-hex(out, parse-hex-int(name), width)
+    #   (Weird shit can happen here if the value of 'word' isn't either a valid
+    #   name or a hex number, but we're only going to be passing in real legal
+    #   programs. We just want to make sure that valid names aren't treated as
+    #   (valid) hex numbers.)
 $emit:hex-int:
     # . n/EAX = parse-hex-int(name)
     # . . push args
@@ -1694,6 +1699,61 @@ test-emit-non-number-with-metadata:
     5d/pop-to-EBP
     c3/return
 
+test-emit-non-number-with-all-hex-digits-and-metadata:
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # setup
+    # . clear-stream(_test-stream)
+    # . . push args
+    68/push  _test-stream/imm32
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . clear-stream(_test-buffered-file+4)
+    # . . push args
+    b8/copy-to-EAX  _test-buffered-file/imm32
+    05/add-to-EAX  4/imm32
+    50/push-EAX
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # var slice/ECX = "abcd/xyz"
+    68/push  _test-slice-hexlike-non-number-word-metadata-end/imm32/end
+    68/push  _test-slice-hexlike-non-number-word/imm32/start
+    89/copy                         3/mod/direct    1/rm32/ECX    .           .             .           4/r32/ESP   .               .                 # copy ESP to ECX
+    # emit(_test-buffered-file, slice, 2)
+    # . . push args
+    68/push  2/imm32
+    51/push-ECX
+    68/push  _test-buffered-file/imm32
+    # . . call
+    e8/call  emit/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # flush(_test-buffered-file)
+    # . . push args
+    68/push  _test-buffered-file/imm32
+    # . . call
+    e8/call  flush/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # check-stream-equal(_test-stream, "abcd/xyz")
+    # . . push args
+    68/push  "F - test-emit-non-number-with-all-hex-digits"/imm32
+    68/push  "abcd/xyz"/imm32
+    68/push  _test-stream/imm32
+    # . . call
+    e8/call  check-stream-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
 # conditions for 'valid' names that are not at risk of looking like hex numbers
 # keep in sync with the rules in labels.cc
 #: - if it starts with a digit, it's treated as a number. If it can't be
@@ -2230,6 +2290,13 @@ _test-output-buffered-file:
     # data
     00 00 00 00 00 00  # 6 bytes
 
+_test-slice-hexlike-non-number-word:
+    61/a 62/b 63/c 64/d
+_test-slice-hexlike-non-number-word-end:
+    2f/slash
+    78/x 79/y 7a/z
+_test-slice-hexlike-non-number-word-metadata-end:
+
 _test-slice-with-slash-prefix:
   2f/slash 30/0 33/3
 _test-slice-with-slash-prefix-end:
ef='#n356'>356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559