Speed up hot reload
This commit is contained in:
parent
1db882c150
commit
9e2f44166c
BIN
8Bitsy.dsk
BIN
8Bitsy.dsk
Binary file not shown.
14
asm/asm.fnl
14
asm/asm.fnl
|
@ -350,15 +350,19 @@
|
|||
self)
|
||||
:read-hotswap
|
||||
(fn [self machine]
|
||||
(let [hotswap {}]
|
||||
(let [addr-to-label {}
|
||||
addr-to-size {}]
|
||||
(each [_ block (pairs self.org-to-block)]
|
||||
(each [label pdat (pairs block.preserved)]
|
||||
(tset hotswap label (machine:read pdat.addr pdat.size))))
|
||||
hotswap))
|
||||
(tset addr-to-label pdat.addr label)
|
||||
(tset addr-to-size pdat.addr pdat.size)))
|
||||
(collect [addr bytes (pairs (machine:read-batch addr-to-size))]
|
||||
(values (. addr-to-label addr) bytes))))
|
||||
:write-hotswap
|
||||
(fn [self machine hotswap]
|
||||
(each [label bytes (pairs hotswap)]
|
||||
(machine:write (self:lookup-addr label) bytes)))
|
||||
(machine:write-batch
|
||||
(collect [label bytes (pairs hotswap)]
|
||||
(values (self:lookup-addr label) bytes))))
|
||||
:upload
|
||||
(fn [self machine]
|
||||
(if machine.upload (machine:upload self)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -88,19 +88,36 @@
|
|||
(when (nrepl:connected?) (nrepl:disconnect))
|
||||
(set self.breakpoints {}))
|
||||
(fn Machine.read [self addr len]
|
||||
(-> (self:coro-eval
|
||||
(.. "(let [bencode (require :bencode)
|
||||
addr " addr "
|
||||
len " len "
|
||||
(var bytes nil)
|
||||
(self:coro-eval
|
||||
"(let [bencode (require :bencode)
|
||||
{: addr : len} (bencode.decode (io.read))
|
||||
mem (. manager.machine.devices ::maincpu :spaces :program)]
|
||||
(var bytes \"\")
|
||||
(print :reading len :from addr)
|
||||
(for [i 1 len]
|
||||
(set bytes (.. bytes (string.char (mem:read_u8 (+ addr i -1))))))
|
||||
bytes)"))
|
||||
; result is piped through fennelview; have to eval it to turn it back into bytes
|
||||
; would be nice if io.write worked
|
||||
(fennel.eval)))
|
||||
(io.write bytes))"
|
||||
(lume.merge
|
||||
(self:input-handler (bencode.encode {: addr : len}))
|
||||
{:out #(set bytes $2)}))
|
||||
bytes)
|
||||
(fn Machine.read-batch [self addr-to-len]
|
||||
(var addr-to-bytes nil)
|
||||
(self:coro-eval
|
||||
"(let [bencode (require :bencode)
|
||||
addr-to-len (bencode.decode (io.read))
|
||||
mem (. manager.machine.devices ::maincpu :spaces :program)
|
||||
addr-to-bytes {}]
|
||||
(each [addr len (pairs addr-to-len)]
|
||||
(var bytes \"\")
|
||||
(for [i 1 len]
|
||||
(set bytes (.. bytes (string.char (mem:read_u8 (+ addr i -1))))))
|
||||
(tset addr-to-bytes addr bytes))
|
||||
(io.write (bencode.encode addr-to-bytes)))"
|
||||
(lume.merge
|
||||
(self:input-handler (bencode.encode addr-to-len))
|
||||
{:out #(set addr-to-bytes (bencode.decode $2))}))
|
||||
addr-to-bytes)
|
||||
(fn Machine.write [self addr bytes]
|
||||
(if (> (bytes:len) 0x1000)
|
||||
(do (self:write addr (bytes:sub 1 0x1000))
|
||||
|
@ -113,6 +130,15 @@
|
|||
(for [i 1 (bytes:len)]
|
||||
(mem:write_u8 (+ addr i -1) (string.byte (bytes:sub i i)))))"
|
||||
(bencode.encode {: addr : bytes}))))
|
||||
(fn Machine.write-batch [self addr-to-bytes]
|
||||
(self:eval-input
|
||||
"(let [bencode (require :bencode)
|
||||
addr-to-bytes (bencode.decode (io.read))
|
||||
mem (. manager.machine.devices ::maincpu :spaces :program)]
|
||||
(each [addr bytes (pairs addr-to-bytes)]
|
||||
(for [i 1 (bytes:len)]
|
||||
(mem:write_u8 (+ addr i -1) (string.byte (bytes:sub i i))))))"
|
||||
(bencode.encode addr-to-bytes)))
|
||||
(fn Machine.launch [self prg]
|
||||
(self:eval "(manager.machine:soft_reset)")
|
||||
(self:eval (string.format "(emu.keypost \"CALL-151\\n %xG\\n\")" (prg:lookup-addr prg.start-symbol))))
|
||||
|
@ -121,7 +147,9 @@
|
|||
(var result nil)
|
||||
(local append-to-result #(set result (.. (or result "") $2)))
|
||||
(self:eval code
|
||||
(self:coro-handlers (coroutine.running) {:value append-to-result :out append-to-result} ?handlers))
|
||||
(self:coro-handlers (coroutine.running)
|
||||
(lume.merge {:value append-to-result :out append-to-result}
|
||||
(or ?handlers {}))))
|
||||
(coroutine.yield)
|
||||
(or result "<no result>"))
|
||||
(fn Machine.dbgcmd [self cmd ?handlers]
|
||||
|
|
5
vendor/jeejah/jeejah/fenneleval.lua
vendored
5
vendor/jeejah/jeejah/fenneleval.lua
vendored
|
@ -36,7 +36,7 @@ local make_repl = function(session, repls)
|
|||
env.io = {}
|
||||
end
|
||||
env.print = print_for(session.write)
|
||||
env.io.write = session.write
|
||||
env.io.write = function(...) return session.io_write(...) end
|
||||
env.io.read = function()
|
||||
session.needinput()
|
||||
local input, done = coroutine.yield()
|
||||
|
@ -63,6 +63,9 @@ return function(conn, msg, session, send, response_for)
|
|||
session.values = function(xs)
|
||||
send(conn, response_for(msg, {value=table.concat(xs, "\n") .. "\n"}))
|
||||
end
|
||||
session.io_write = function(...)
|
||||
send(conn, response_for(msg, {out=table.concat({...})}))
|
||||
end
|
||||
session.done = function()
|
||||
send(conn, response_for(msg, {status={"done"}}))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue