about summary refs log tree commit diff stats
path: root/run_one_test.subx
blob: def4c430039be9c57f3284504fbfa5e8c007baf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# run a single test

== code
#   instruction                     effective address                                                   register    displacement    immediate
# . op          subop               mod             rm32          base        index         scale       r32
# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes

Entry:
    # Heap = new-segment(64KB)
    # . . push args
    68/push  Heap/imm32
    68/push  0x10000/imm32/64KB
    # . . call
    e8/call  new-segment/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # initialize-trace-stream(256KB)
    # . . push args
    68/push  0x40000/imm32/256KB
    # . . call
    e8/call  initialize-trace-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # for debugging: run a single test
    e8/call $TEST_NAME/disp32
    8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/ebx   Num-test-failures/disp32          # copy *Num-test-failures to ebx
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8

# . . vim:nowrap:textwidth=0
@dict, Str $str --> List ) is export { # $lower, $upper hold the lower and upper index of the range # respectively. my Int ($lower, $upper); # Lookup the whole dictionary. my Int ($start, $end) = (0, @dict.end); # Loop until we end up on the lower index of range. while $start < $end { # Divide the list into 2 parts. my Int $mid = ($start + $end) div 2; # Check if $mid word is le (less than or equal to) $str. If # true then discard the bottom end of the list, if not then # discard the top end. if $str le @dict[$mid].substr(0, $str.chars).lc { $end = $mid; } else { $start = $mid + 1; } } # Found the lower index. $lower = $start; # Set $end to the end of list but keep $start at the lower index. $end = @dict.end; # Loop until we end up on the upper index of range. while $start < $end { # Divide the list into 2 parts. Adds 1 because we have to find # the upper index in this part. `div' performs Interger # division, output is floor'ed. my Int $mid = (($start + $end) div 2) + 1; # Check if $mid word is lt (less than) $str. If true then # discard the bottom end of the list, if not then discard the # top end. if $str lt @dict[$mid].substr(0, $str.chars).lc { $end = $mid - 1; } else { $start = $mid; } } # Found the upper index. $upper = $end; with @dict[$lower..$upper] -> @list { # Maybe the word doesn't exist in the list, in that case there # will be a single element in @list. We return an empty list # unless that single element starts with $str. if @list.elems == 1 { return () unless @list[0].starts-with($str); } return @list; } }