v0.0.51

August 2024


View WebAssembly source (2419 bytes compiled)
(module $CalendarGrid
  (type $SilverOrb.StringBuilder (func (result i32 i32)))
  (memory (export "memory") 5)
  (global $bump_offset (mut i32) (i32.const 65536))
  (global $bump_mark (mut i32) (i32.const 0))
  (global $bump_write_level (mut i32) (i32.const 0))
  (global $OrbShowcase.Widgets.CalendarGrid.Output.bump_offset (mut i32) (i32.const 131072))
  (global $OrbShowcase.Widgets.CalendarGrid.States.bump_offset (mut i32) (i32.const 196608))
  (global $open? (mut i32) (i32.const 0))
  (global $focus_clock (mut i32) (i32.const 0))
  (global $text_html_clock (mut i32) (i32.const 0))
  (global $id_suffix (export "id_suffix") (mut i32) (i32.const 1))
  (global $year (export "year") (mut i32) (i32.const 2024))
  (global $month (export "month") (mut i32) (i32.const 8))
  (global $day (export "day") (mut i32) (i32.const 21))
  (; constants 662 bytes ;)
  (data (i32.const 255) "<tr>")
  (data (i32.const 260) "</tr>")
  (data (i32.const 266) "calendar:table:")
  (data (i32.const 282) "<td role=\"gridcell\" aria-hidden=\"true\"></td>")
  (data (i32.const 327) "<td role=\"gridcell\">")
  (data (i32.const 348) "<button>")
  (data (i32.const 357) "</button>")
  (data (i32.const 367) "</td>")
  (data (i32.const 373) "<table id=\"")
  (data (i32.const 385) "\" role=\"grid\">")
  (data (i32.const 400) "<thead aria-hidden=\"true\"'><tr><th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th></tr></thead>")
  (data (i32.const 519) "<tbody>")
  (data (i32.const 527) "</tbody>")
  (data (i32.const 536) "</table>")
  (data (i32.const 545) "<button data-action=\"previous_month\">Previous month</button>")
  (data (i32.const 606) "<button data-action=\"next_month\">Next month</button>")
  (data (i32.const 659) "January")
  (data (i32.const 667) "February")
  (data (i32.const 676) "March")
  (data (i32.const 682) "April")
  (data (i32.const 688) "May")
  (data (i32.const 692) "June")
  (data (i32.const 697) "July")
  (data (i32.const 702) "August")
  (data (i32.const 709) "September")
  (data (i32.const 719) "October")
  (data (i32.const 727) "November")
  (data (i32.const 736) "December")
  (data (i32.const 745) "<lipid-calendar-grid>\n")
  (data (i32.const 768) "<golden-orb>\n")
  (data (i32.const 782) "<source type=\"application/wasm\" src=\"/calendar-grid.wasm\">\n")
  (data (i32.const 842) "<h1>")
  (data (i32.const 847) " ")
  (data (i32.const 849) "</h1>")
  (data (i32.const 855) "<fieldset>")
  (data (i32.const 866) "</fieldset>")
  (data (i32.const 878) "</golden-orb>\n")
  (data (i32.const 893) "</lipid-calendar-grid>\n")
  (func $decimal_u32_char_count (param $value i32) (result i32)
    (local $digit_count i32)
    (loop $Digits
      (i32.add (local.get $digit_count) (i32.const 1))
      (local.set $digit_count)
      (i32.div_u (local.get $value) (i32.const 10))
      (local.set $value)
      (i32.gt_u (local.get $value) (i32.const 0))
      (br_if $Digits)
    )
    (local.get $digit_count)
  )
  (func $decimal_u32 (param $value i32) (param $str_ptr i32) (result i32 i32)
    (local $working_offset i32)
    (local $len i32)
    (local $digit i32)
    (call $decimal_u32_char_count (local.get $value))
    (local.set $len)
    (i32.add (local.get $str_ptr) (local.get $len))
    (local.set $working_offset)
    (loop $Digits
      (i32.sub (local.get $working_offset) (i32.const 1))
      (local.set $working_offset)
      (i32.rem_u (local.get $value) (i32.const 10))
      (local.set $digit)
      (i32.div_u (local.get $value) (i32.const 10))
      (local.set $value)
      (i32.store8 (local.get $working_offset) (i32.add (i32.const 48) (local.get $digit)))
      (i32.gt_u (local.get $value) (i32.const 0))
      (br_if $Digits)
    )
    (local.get $str_ptr)
    (local.get $len)
  )
  (func $bump_write_start
    (i32.eqz (global.get $bump_write_level))
    (if
      (then
        (i32.const 65536)
        (global.set $bump_offset)
        (global.get $bump_offset)
        (global.set $bump_mark)
      )
    )
    (i32.add (global.get $bump_write_level) (i32.const 1))
    (global.set $bump_write_level)
  )
  (func $bump_write_done (result i32 i32)
    (i32.gt_s (global.get $bump_write_level) (i32.const 0))
    (if
      (then
        nop      )
      (else
        unreachable      )
    )
    (i32.sub (global.get $bump_write_level) (i32.const 1))
    (global.set $bump_write_level)
    (global.get $bump_mark)
    (i32.sub (global.get $bump_offset) (global.get $bump_mark))
  )
  (func $bump_write_str (param $str_ptr i32) (param $len i32)
    (local $i i32)
    (local $char i32)
    (i32.or (i32.eq (local.get $str_ptr) (global.get $bump_mark)) (i32.eqz (local.get $len)))
    (if
      (then
        return      )
    )
    (loop $EachChar
      (i32.load8_u (i32.add (local.get $str_ptr) (local.get $i)))
      (local.set $char)
      (i32.store8 (i32.add (global.get $bump_offset) (local.get $i)) (local.get $char))
      (i32.lt_s (local.get $i) (local.get $len))
      (if
        (then
          (i32.add (local.get $i) (i32.const 1))
          (local.set $i)
          (br $EachChar)
        )
      )
    )
    (i32.add (global.get $bump_offset) (local.get $len))
    (global.set $bump_offset)
  )
  (func $bump_written? (result i32)
    (i32.gt_s (global.get $bump_offset) (global.get $bump_mark))
  )
  (func $leap_year? (param $year i32) (result i32)
    (i32.and (i32.eq (i32.rem_u (local.get $year) (i32.const 4)) (i32.const 0)) (i32.or (i32.ne (i32.rem_u (local.get $year) (i32.const 100)) (i32.const 0)) (i32.eq (i32.rem_u (local.get $year) (i32.const 400)) (i32.const 0))))
  )
  (func $days_in_month (param $year i32) (param $month i32) (result i32)
    (i32.eq (local.get $month) (i32.const 2))
    (if
      (then
        (return (i32.add (i32.const 28) (call $leap_year? (local.get $year))))
      )
    )
    (i32.or (i32.eq (i32.const 11) (local.get $month)) (i32.or (i32.eq (i32.const 9) (local.get $month)) (i32.or (i32.eq (i32.const 6) (local.get $month)) (i32.eq (i32.const 4) (local.get $month)))))
    (if (result i32)
      (then
        (i32.const 30)
      )
      (else
        (i32.const 31)
      )
    )
  )
  (func $day_of_week (param $year i32) (param $month i32) (param $day i32) (result i32)
    (local $k i32)
    (local $j i32)
    (local $weekday i32)
    (i32.lt_s (local.get $month) (i32.const 3))
    (if
      (then
        (i32.add (local.get $month) (i32.const 12))
        (local.set $month)
        (i32.sub (local.get $year) (i32.const 1))
        (local.set $year)
      )
    )
    (i32.rem_u (local.get $year) (i32.const 100))
    (local.set $k)
    (i32.div_u (local.get $year) (i32.const 100))
    (local.set $j)
    (i32.rem_u (i32.add (i32.add (i32.add (i32.add (i32.add (local.get $day) (i32.div_s (i32.mul (i32.const 13) (i32.add (local.get $month) (i32.const 1))) (i32.const 5))) (local.get $k)) (i32.div_s (local.get $k) (i32.const 4))) (i32.div_s (local.get $j) (i32.const 4))) (i32.mul (i32.const 5) (local.get $j))) (i32.const 7))
    (local.set $weekday)
    (i32.add (i32.rem_u (i32.add (local.get $weekday) (i32.const 5)) (i32.const 7)) (i32.const 1))
  )
  (func $string_equal_impl (param $lhs i32) (param $rhs i64) (result i32)
    (local $i i32)
    (local $byte_a i32)
    (local $byte_b i32)
    (loop $EachByte (result i32)
      (i32.load8_u (i32.add (local.get $lhs) (local.get $i)))
      (local.set $byte_a)
      (i32.load8_u (i32.add (i32.wrap_i64 (local.get $rhs)) (local.get $i)))
      (local.set $byte_b)
      (i32.eqz (local.get $byte_a))
      (if
        (then
          (return (i32.eqz (local.get $byte_b)))
        )
      )
      (i32.eq (local.get $byte_a) (local.get $byte_b))
      (if
        (then
          (i32.add (local.get $i) (i32.const 1))
          (local.set $i)
          (br $EachByte)
        )
      )
      (return (i32.const 0))
    )
  )
  (func $OrbShowcase.Widgets.CalendarGrid.Output.alloc! (param $byte_count i32) (result i32)
    (local $new_ptr i32)
    (global.get $OrbShowcase.Widgets.CalendarGrid.Output.bump_offset)
    (local.set $new_ptr)
    (i32.gt_u (i32.add (local.get $new_ptr) (local.get $byte_count)) (i32.const 196608))
    (if
      (then
        unreachable
      )
    )
    (i32.gt_u (i32.add (local.get $new_ptr) (local.get $byte_count)) (i32.mul (memory.size) (i32.const 65536)))
    (if
      (then
        (memory.grow (i32.const 1))
        drop
      )
    )
    (i32.add (local.get $new_ptr) (local.get $byte_count))
    (global.set $OrbShowcase.Widgets.CalendarGrid.Output.bump_offset)
    (local.get $new_ptr)
  )
  (func $OrbShowcase.Widgets.CalendarGrid.Output.rewind
    (i32.const 131072)
    (global.set $OrbShowcase.Widgets.CalendarGrid.Output.bump_offset)
  )
  (func $OrbShowcase.Widgets.CalendarGrid.Output.string_equal? (param $slice i64) (result i32)
    (call $string_equal_impl (i32.const 131072) (local.get $slice))
  )
  (func $OrbShowcase.Widgets.CalendarGrid.States.alloc! (param $byte_count i32) (result i32)
    (local $new_ptr i32)
    (global.get $OrbShowcase.Widgets.CalendarGrid.States.bump_offset)
    (local.set $new_ptr)
    (i32.gt_u (i32.add (local.get $new_ptr) (local.get $byte_count)) (i32.const 262144))
    (if
      (then
        unreachable
      )
    )
    (i32.gt_u (i32.add (local.get $new_ptr) (local.get $byte_count)) (i32.mul (memory.size) (i32.const 65536)))
    (if
      (then
        (memory.grow (i32.const 1))
        drop
      )
    )
    (i32.add (local.get $new_ptr) (local.get $byte_count))
    (global.set $OrbShowcase.Widgets.CalendarGrid.States.bump_offset)
    (local.get $new_ptr)
  )
  (func $OrbShowcase.Widgets.CalendarGrid.States.rewind
    (i32.const 196608)
    (global.set $OrbShowcase.Widgets.CalendarGrid.States.bump_offset)
  )
  (func $OrbShowcase.Widgets.CalendarGrid.States.string_equal? (param $slice i64) (result i32)
    (call $string_equal_impl (i32.const 196608) (local.get $slice))
  )
  (func $table_id (export "table_id") (result i32 i32)
    (call $bump_write_start)
    (i32.const 266) (i32.const 15)
    (call $bump_write_str (;i32;) (;i32;))
    (call $decimal_u32 (global.get $id_suffix) (global.get $bump_offset))
    (i32.add (global.get $bump_offset))
    (global.set $bump_offset)
    nop
    drop
    (call $bump_write_done)
  )
  (func $previous_month (export "previous_month")
    (i32.sub (global.get $month) (i32.const 1))
    (global.set $month)
    (i32.eq (global.get $month) (i32.const 0))
    (if
      (then
        (i32.sub (global.get $year) (i32.const 1))
        (global.set $year)
        (i32.const 12)
        (global.set $month)
      )
    )
  )
  (func $next_month (export "next_month")
    (i32.add (global.get $month) (i32.const 1))
    (global.set $month)
    (i32.gt_s (global.get $month) (i32.const 12))
    (if
      (then
        (i32.add (global.get $year) (i32.const 1))
        (global.set $year)
        (i32.const 1)
        (global.set $month)
      )
    )
  )
  (func $weekday (param $week i32) (param $weekday_index i32) (param $weekday_offset i32) (param $max_days i32) (result i32 i32)
    (local $day i32)
    (i32.add (i32.add (i32.sub (local.get $weekday_index) (local.get $weekday_offset)) (i32.const 1)) (i32.mul (i32.sub (local.get $week) (i32.const 1)) (i32.const 7)))
    (local.set $day)
    (i32.or (i32.and (i32.eq (local.get $week) (i32.const 1)) (i32.lt_s (local.get $weekday_index) (local.get $weekday_offset))) (i32.gt_s (local.get $day) (local.get $max_days)))
    (if (result i32 i32)
      (then
        (call $bump_write_start)
        (i32.const 282) (i32.const 44)
        (call $bump_write_str (;i32;) (;i32;))
        (call $bump_write_done)
      )
      (else
        (call $bump_write_start)
        (i32.const 327) (i32.const 20)
        (call $bump_write_str (;i32;) (;i32;))
        (i32.const 348) (i32.const 8)
        (call $bump_write_str (;i32;) (;i32;))
        (call $decimal_u32 (local.get $day) (global.get $bump_offset))
        (i32.add (global.get $bump_offset))
        (global.set $bump_offset)
        nop
        drop
        (i32.const 357) (i32.const 9)
        (call $bump_write_str (;i32;) (;i32;))
        (i32.const 367) (i32.const 5)
        (call $bump_write_str (;i32;) (;i32;))
        (call $bump_write_done)
      )
    )
  )
  (func $table (result i32 i32)
    (local $weekday_offset i32)
    (local $max_days i32)
    (local $week_index i32)
    (local $weekday_index i32)
    (call $day_of_week (global.get $year) (global.get $month) (i32.const 1))
    (local.set $weekday_offset)
    (call $days_in_month (global.get $year) (global.get $month))
    (local.set $max_days)
    (call $bump_write_start)
    (i32.const 373) (i32.const 11)
    (call $bump_write_str (;i32;) (;i32;))
    (call $table_id)
    drop
    drop
    (i32.const 385) (i32.const 14)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 400) (i32.const 118)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 519) (i32.const 7)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 255) (i32.const 4)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 1)
    (local.set $week_index)
    (loop $EachWeek (result i32 i32)
      (i32.const 1)
      (local.set $weekday_index)
      (loop $EachWeekday (result i32 i32)
        (i32.eq (local.get $weekday_index) (i32.const 1))
        (if
          (then
            (i32.const 255) (i32.const 4)
            (call $bump_write_str (;i32;) (;i32;))
          )
        )
        (call $weekday (local.get $week_index) (local.get $weekday_index) (local.get $weekday_offset) (local.get $max_days))
        (i32.eq (local.get $weekday_index) (i32.const 7))
        (if
          (then
            (i32.const 260) (i32.const 5)
            (call $bump_write_str (;i32;) (;i32;))
          )
        )
        (i32.add (local.get $weekday_index) (i32.const 1))
        (local.set $weekday_index)
        (i32.le_s (local.get $weekday_index) (i32.const 7))
        (if
          (then
            (br $EachWeekday)
          )
        )
      )
      (i32.add (local.get $week_index) (i32.const 1))
      (local.set $week_index)
      (i32.le_s (local.get $week_index) (i32.const 6))
      (if
        (then
          (br $EachWeek)
        )
      )
    )
    drop
    drop
    (i32.const 1)
    (local.set $weekday_index)
    (i32.const 260) (i32.const 5)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 527) (i32.const 8)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 536) (i32.const 8)
    (call $bump_write_str (;i32;) (;i32;))
    (call $bump_write_done)
  )
  (func $previous_month_button (result i32 i32)
    (call $bump_write_start)
    (i32.const 545) (i32.const 60)
    (call $bump_write_str (;i32;) (;i32;))
    (call $bump_write_done)
  )
  (func $next_month_button (result i32 i32)
    (call $bump_write_start)
    (i32.const 606) (i32.const 52)
    (call $bump_write_str (;i32;) (;i32;))
    (call $bump_write_done)
  )
  (func $month_name (param $month i32) (result i32 i32)
    (i32.eq (local.get $month) (i32.const 1))
    (if
      (then
        (return (i32.const 659) (i32.const 7))
      )
    )
    (i32.eq (local.get $month) (i32.const 2))
    (if
      (then
        (return (i32.const 667) (i32.const 8))
      )
    )
    (i32.eq (local.get $month) (i32.const 3))
    (if
      (then
        (return (i32.const 676) (i32.const 5))
      )
    )
    (i32.eq (local.get $month) (i32.const 4))
    (if
      (then
        (return (i32.const 682) (i32.const 5))
      )
    )
    (i32.eq (local.get $month) (i32.const 5))
    (if
      (then
        (return (i32.const 688) (i32.const 3))
      )
    )
    (i32.eq (local.get $month) (i32.const 6))
    (if
      (then
        (return (i32.const 692) (i32.const 4))
      )
    )
    (i32.eq (local.get $month) (i32.const 7))
    (if
      (then
        (return (i32.const 697) (i32.const 4))
      )
    )
    (i32.eq (local.get $month) (i32.const 8))
    (if
      (then
        (return (i32.const 702) (i32.const 6))
      )
    )
    (i32.eq (local.get $month) (i32.const 9))
    (if
      (then
        (return (i32.const 709) (i32.const 9))
      )
    )
    (i32.eq (local.get $month) (i32.const 10))
    (if
      (then
        (return (i32.const 719) (i32.const 7))
      )
    )
    (i32.eq (local.get $month) (i32.const 11))
    (if
      (then
        (return (i32.const 727) (i32.const 8))
      )
    )
    (i32.eq (local.get $month) (i32.const 12))
    (if
      (then
        (return (i32.const 736) (i32.const 8))
      )
    )
    unreachable
  )
  (func $text_html (export "text_html") (result i32 i32)
    (call $bump_write_start)
    (i32.const 745) (i32.const 22)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 768) (i32.const 13)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 782) (i32.const 59)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 842) (i32.const 4)
    (call $bump_write_str (;i32;) (;i32;))
    (call $month_name (global.get $month))
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 847) (i32.const 1)
    (call $bump_write_str (;i32;) (;i32;))
    (call $decimal_u32 (global.get $year) (global.get $bump_offset))
    (i32.add (global.get $bump_offset))
    (global.set $bump_offset)
    nop
    drop
    (i32.const 849) (i32.const 5)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 855) (i32.const 10)
    (call $bump_write_str (;i32;) (;i32;))
    (call $previous_month_button)
    drop
    drop
    (call $next_month_button)
    drop
    drop
    (i32.const 866) (i32.const 11)
    (call $bump_write_str (;i32;) (;i32;))
    (call $table)
    drop
    drop
    (i32.const 878) (i32.const 14)
    (call $bump_write_str (;i32;) (;i32;))
    (i32.const 893) (i32.const 23)
    (call $bump_write_str (;i32;) (;i32;))
    (call $bump_write_done)
  )
)