about summary refs log blame commit diff stats
path: root/browse_slack/main.mu
blob: c3e351d21da60a1970a25ee129a477b5aa24d820 (plain) (tree)
parse/0: instruction: 1
parse/0:   ingredient: {name: "34", value: 0, type: 0, properties: ["34": "literal"]}
parse/0:   product: {name: "12", value: 0, type: 1, properties: ["12": "integer"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "35", value: 0, type: 0, properties: ["35": "literal"]}
parse/0:   product: {name: "13", value: 0, type: 1, properties: ["13": "integer"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "5", value: 0, type: 0, properties: ["5": "literal"]}
parse/0:   product: {name: "1000", value: 0, type: 1, properties: ["1000": "integer"]}
parse/0: instruction: 1
parse/0:   ingredient: {name: "1000", value: 0, type: 0, properties: ["1000": "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: "12", value: 0, type: 0, properties: ["12": "literal"]}
parse/0:   product: {name: "1", value: 0, type: 2-6, properties: ["1": "address":"point"]}
parse/0: instruction: 19
parse/0:   ingredient: {name: "1", value: 0, type: 2-6, properties: ["1": "address":"point", "deref": ]}
parse/0:   ingredient: {name: "1", value: 0, type: 0, properties: ["1": "offset"]}
parse/0:   product: {name: "9", value: 0, type: 1, properties: ["9": "integer", "raw": ]}
after-brace/0: recipe main
after-brace/0: copy ...
after-brace/0: copy ...
after-brace/0: copy ...
after-brace/0: copy ...
after-brace/0: copy ...
after-brace/0: get ...
run/0: instruction main/0
run/0: ingredient 0 is 34
mem/0: storing 34 in location 12
run/0: instruction main/1
run/0: ingredient 0 is 35
mem/0: storing 35 in location 13
run/0: instruction main/2
run/0: ingredient 0 is 5
mem/0: storing 5 in location 1000
run/0: instruction main/3
run/0: ingredient 0 is 1000
run/0: instruction main/4
run/0: ingredient 0 is 12
mem/0: storing 12 in location 1002
run/0: instruction main/5
run/0: ingredient 0 is 1
mem/0: location 1002 is 12
run/0: ingredient 1 is 1
run/0: address to copy is 13
run/0: its type is 1
mem/0: location 13 is 35
run/0: product 0 is 35
mem/0: storing 35 in location 9
artik/mu/blame/browse_slack/main.mu?h=hlt&id=74dad4c484df86c03037deaaf683fd6d86e05119'>^



















                                           
                              








                                    
                          
                    
                            




                                                                                  


                                                                              
                                                                                                          

                                                

                                                      
































                                                                                           
                                                                                                                     








                                                                          
                                           

                                                                                                          
                       


















                                                                 





























                                               


                                                              









                                                          






                                                                                                                   
 



























                                                                      
type channel {
  id: (handle array byte)
  name: (handle array byte)
  posts: (handle array int)  # item indices
  newest-post-index: int
}

type user {
  id: (handle array byte)
  name: (handle array byte)
  real-name: (handle array byte)
  avatar: (handle image)
}

type item {
  id: (handle array byte)
  channel: (handle array byte)
  by: int  # user index
  text: (handle array byte)
  parent: int  # item index
  comments: (handle array int)
}

# globals:
#   users: (handle array user)
#   channels: (handle array channel)
#   items: (handle array item)
#
# flows:
#   channel -> posts
#   user -> posts|comments
#   post -> comments
#   comment -> post|comments
#   keywords -> posts|comments

# I try to put all the static buffer sizes in this function.
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
  # load entire disk contents to a single enormous stream
  var s-h: (handle stream byte)  # the stream is too large to put on the stack
  var s-ah/eax: (addr handle stream byte) <- address s-h
  populate-stream s-ah, 0x4000000
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "loading data disk..", 3/fg 0/bg
  var _s/eax: (addr stream byte) <- lookup *s-ah
  var s/ebx: (addr stream byte) <- copy _s
#?   load-sectors data-disk, 0/lba, 0x20000/sectors, s
  load-sectors data-disk, 0/lba, 0x7000/sectors, s
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "done", 3/fg 0/bg
  # parse global data structures out of the stream
  var users-h: (handle array user)
  var users-ah/eax: (addr handle array user) <- address users-h
  populate users-ah, 0x800
  var _users/eax: (addr array user) <- lookup *users-ah
  var users/edi: (addr array user) <- copy _users
  var channels-h: (handle array channel)
  var channels-ah/eax: (addr handle array channel) <- address channels-h
  populate channels-ah, 0x20
  var _channels/eax: (addr array channel) <- lookup *channels-ah
  var channels/esi: (addr array channel) <- copy _channels
  var items-h: (handle array item)
  var items-ah/eax: (addr handle array item) <- address items-h
  populate items-ah, 0x10000
  var _items/eax: (addr array item) <- lookup *items-ah
  var items/edx: (addr array item) <- copy _items
  parse s, users, channels, items
  # render
  var env-storage: environment
  var env/ebx: (addr environment) <- address env-storage
  {
    render-environment env, users, channels, items
    {
      var key/eax: byte <- read-key keyboard
      compare key, 0
      loop-if-=
      update-environment env, key
    }
    loop
  }
}

fn parse in: (addr stream byte), users: (addr array user), channels: (addr array channel), items: (addr array item) {
  # 'in' consists of a long, flat sequence of records surrounded by parens
  var record-storage: (stream byte 0x18000)
  var record/ecx: (addr stream byte) <- address record-storage
  var user-idx/edx: int <- copy 0
  var item-idx/ebx: int <- copy 0
  {
    var done?/eax: boolean <- stream-empty? in
    compare done?, 0/false
    break-if-!=
    set-cursor-position 0/screen, 0x20 0x20
    draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, user-idx, 3/fg 0/bg
    draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, item-idx, 4/fg 0/bg
    clear-stream record
    parse-record in, record
    var user?/eax: boolean <- user-record? record
    {
      compare user?, 0/false
      break-if-=
      parse-user record, users, user-idx
      user-idx <- increment
    }
    {
      compare user?, 0/false
      break-if-!=
      parse-item record, channels, items, item-idx
      item-idx <- increment
    }
    loop
  }
}

fn parse-record in: (addr stream byte), out: (addr stream byte) {
  var paren/eax: byte <- read-byte in
  compare paren, 0x28/open-paren
  {
    break-if-=
    abort "parse-record: ("
  }
  var paren-int/eax: int <- copy paren
  append-byte out, paren-int
  {
    {
      var eof?/eax: boolean <- stream-empty? in
      compare eof?, 0/false
      break-if-=
      abort "parse-record: truncated"
    }
    var c/eax: byte <- read-byte in
    {
      var c-int/eax: int <- copy c
      append-byte out, c-int
    }
    compare c, 0x29/close-paren
    break-if-=
    compare c, 0x22/double-quote
    {
      break-if-!=
      slurp-json-string in, out
    }
    loop
  }
  skip-chars-matching-whitespace in
}

fn user-record? record: (addr stream byte) -> _/eax: boolean {
  rewind-stream record
  var c/eax: byte <- read-byte record  # skip paren
  var c/eax: byte <- read-byte record  # skip double quote
  var c/eax: byte <- read-byte record
  compare c, 0x55/U
  {
    break-if-!=
    return 1/true
  }
  rewind-stream record
  return 0/false
}

fn parse-user record: (addr stream byte), users: (addr array user), user-idx: int {
}

fn parse-item record: (addr stream byte), channels: (addr array channel), items: (addr array item), item-idx: int {
}

fn slurp-json-string in: (addr stream byte), out: (addr stream byte) {
  # open quote is already slurped
  {
    {
      var eof?/eax: boolean <- stream-empty? in
      compare eof?, 0/false
      break-if-=
      abort "slurp-json-string: truncated"
    }
    var c/eax: byte <- read-byte in
    {
      var c-int/eax: int <- copy c
      append-byte out, c-int
    }
    compare c, 0x22/double-quote
    break-if-=
    compare c, 0x5c/backslash
    {
      break-if-!=
      # read next byte raw
      c <- read-byte in
      var c-int/eax: int <- copy c
      append-byte out, c-int
    }
    loop
  }
}