diff --git a/alt/big.py b/alt/big.py index e68fddb..d27a455 100755 --- a/alt/big.py +++ b/alt/big.py @@ -321,7 +321,7 @@ def assemble(f, min_static=16, max_static=1023, builtins=BUILTIN_SYMBOLS): CYCLES_PER_CALL = 100 # Number of cycles to run in the tight loop (when not tracing) -def run(program, chip=BigComputer, simulator="codegen", name="Flat!", font="monaco-9", halt_addr=None, trace=None, verbose_tty=True): +def run(program, chip=BigComputer, simulator="codegen", name="Flat!", font="monaco-9", halt_addr=None, trace=None, verbose_tty=True, meters=None): """Run with keyboard and text-mode graphics.""" # TODO: font @@ -407,7 +407,8 @@ def run_trace(): cps = (cycles - last_cycle_count)/(now - last_cycle_time) msgs.append(f"{cps/1000:0,.1f}k/s") msgs.append(f"@{computer.pc}") - # TODO: let the caller add meters (e.g. Ribbit heap consumption) + if meters: + msgs.extend(meters(computer, cycles)) pygame.display.set_caption(f"{name}: {'; '.join(msgs)}") last_cycle_time = now diff --git a/alt/scheme/rvm.py b/alt/scheme/rvm.py index 9f2a55b..16ea55a 100755 --- a/alt/scheme/rvm.py +++ b/alt/scheme/rvm.py @@ -154,12 +154,23 @@ def trace(computer, cycles): elif trace_level >= TRACE_ALL: print(f"{cycles:3,d}: {computer.pc}") + def meters(computer, cycles): + inspector = Inspector(computer, symbols, stack_loc) + next_rib = unsigned(inspector.peek(next_rib_loc)) + current_ribs = (next_rib - big.HEAP_BASE)//3 + max_ribs = (big.HEAP_TOP - big.HEAP_BASE)//3 + return { + f"mem: {100*current_ribs/max_ribs:0.1f}%" + } + + big.run(program=instrs, simulator=simulator, name="Scheme", halt_addr=halt_loop_addr, trace=trace if trace_level > TRACE_NONE else None, - verbose_tty=verbose_tty) + verbose_tty=verbose_tty, + meters=meters) def compile(src):