# Tokenize by whitespace. == 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 # (re)compute the bounds of the next word in the line # return empty string on reaching end of file next-word: # line: (addr stream byte), out: (addr slice) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 51/push-ecx 56/push-esi 57/push-edi # esi = line 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # edi = out 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 . # copy *(ebp+12) to edi # skip-chars-matching-whitespace(line) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call skip-chars-matching-whitespace/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp $next-word:check0: # if (line->read >= line->write) clear out and return # . eax = line->read 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 . # copy *(esi+4) to eax # . if (eax < line->write) goto next check 3b/compare 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . . # compare eax with *esi 7c/jump-if-< $next-word:check-for-comment/disp8 # . return out c7 0/subop/copy 0/mod/direct 7/rm32/edi . . . . . 0/imm32 # copy to *edi c7 0/subop/copy 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 0/imm32 # copy to *(edi+4) eb/jump $next-word:end/disp8 $next-word:check-for-comment: # out->start = &line->data[line->read] 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 . # copy esi+ecx+12 to eax 89/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # copy eax to *edi # if (line->data[line->read] == '#') out->end = &line->data[line->write]), skip rest of stream and return # . eax = line->data[line->read] 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 . # copy byte at *(esi+ecx+12) to AL # . compare 3d/compare-eax-and 0x23/imm32/pound 75/jump-if-!= $next-word:regular-word/disp8 $next-word:comment: # . out->end = &line->data[line->write] 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . . # copy *esi to eax 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy esi+eax+12 to eax 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 . # copy eax to *(edi+4) # . line->read = line->write 89/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 . # copy eax to *(esi+4) # . return eb/jump $next-word:end/disp8 $next-word:regular-word: # otherwise skip-chars-not-matching-whitespace(line) # including trailing newline # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call skip-chars-not-matching-whitespace/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # out->end = &line->data[line->read] 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 . # copy esi+ecx+12 to eax 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 . # copy eax to *(edi+4) $next-word:end: # . restore registers 5f/pop-to-edi 5e/pop-to-esi 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-word: # . prologue 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 # var slice/ecx: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # write(_test-stream, " ab") # . . push args 68/push " ab"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard arg
parse/0: instruction: 37
parse/0:   ingredient: {name: "location", value: 0, type: 0, properties: ["location": "type"]}
parse/0:   ingredient: {name: "30", value: 0, type: 0, properties: ["30": "literal"]}
parse/0:   product: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]}
parse/0: instruction: 1001
parse/0:   product: {name: "1", value: 0, type: 2-5-1, properties: ["1": "address":"array":"location", "names": "init-counter"]}
parse/0: instruction: 1002
parse/0:   ingredient: {name: "1", value: 0, type: 2-5-1, properties: ["1": "address":"array":"location", "names": "init-counter"]}
parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer", "raw": ]}
parse/0: instruction: 1002
parse/0:   ingredient: {name: "1", value: 0, type: 2-5-1, properties: ["1": "address":"array":"location", "names": "init-counter"]}
parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer", "raw": ]}
parse/0: instruction: 37
parse/0:   ingredient: {name: "location", value: 0, type: 0, properties: ["location": "type"]}
parse/0:   ingredient: {name: "30", value: 0, type: 0, properties: ["30": "literal"]}
parse/0:   product: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
parse/0:   product: {name: "x", value: 0, type: 1, properties: ["x": "integer"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "3", value: 0, type: 0, properties: ["3": "literal"]}
parse/0:   product: {name: "y", value: 0, type: 1, properties: ["y": "integer"]}
parse/0: instruction: 28
parse/0:   ingredient: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]}
parse/0: instruction: 37
parse/0:   ingredient: {name: "space", value: 0, type: 0, properties: ["space": "literal"]}
parse/0:   ingredient: {name: "30", value: 0, type: 0, properties: ["30": "literal"]}
parse/0:   product: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]}
parse/0: instruction: 25
parse/0:   product: {name: "0", value: 0, type: 2-5-1, properties: ["0": "address":"array":"location", "names": "init-counter"]}
parse/0: instruction: 2
parse/0:   ingredient: {name: "y", value: 0, type: 1, properties: ["y": "integer", "space": "1"]}
parse/0:   ingredient: {name: "1", value: 0, type: 0, properties: ["1": "literal"]}
parse/0:   product: {name: "y", value: 0, type: 1, properties: ["y": "integer", "space": "1"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "234", value: 0, type: 0, properties: ["234": "literal"]}
parse/0:   product: {name: "y", value: 0, type: 1, properties: ["y": "integer"]}
parse/0: instruction: 28
parse/0:   ingredient: {name: "y", value: 0, type: 1, properties: ["y": "integer", "space": "1"]}
name/0: recipe increment-counter is surrounded by init-counter
new/0: location -> 1
new/0: location -> 1
name/0: assign x 1
name/0: assign y 2
new/0: space -> 0
name/0: assign y 1
after-brace/0: recipe main
after-brace/0: new ...
after-brace/0: init-counter ...
after-brace/0: increment-counter ...
after-brace/0: increment-counter ...
after-brace/0: recipe init-counter
after-brace/0: new ...
after-brace/0: copy ...
after-brace/0: copy ...
after-brace/0: reply ...
after-brace/0: recipe increment-counter
after-brace/0: new ...
after-brace/0: next-ingredient ...
after-brace/0: add ...
after-brace/0: copy ...
after-brace/0: reply ...
new/0: routine allocated memory from 1000 to 101000
schedule/0: main
run/0: instruction main/0
mem/0: array size is 30
mem/0: new alloc: 1000
run/0: instruction main/1
run/0: instruction init-counter/0
mem/0: array size is 30
mem/0: new alloc: 1030
run/0: instruction init-counter/1
run/0: ingredient 0 is 23
mem/0: storing 23 in location 1032
run/0: instruction init-counter/2
run/0: ingredient 0 is 3
mem/0: storing 3 in location 1033
run/0: instruction init-counter/3
run/0: result 0 is 1030
mem/0: storing 1030 in location 1002
run/0: instruction main/2
mem/0: location 1002 is 1030
run/0: