lean4-htt/library/tools/smt2/builder.lean
2017-03-28 18:42:32 -07:00

48 lines
1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import .syntax
@[reducible] def smt2.builder (α : Type) := state (list smt2.cmd) α
meta def smt2.builder.to_format {α : Type} (build : smt2.builder α) : format :=
format.join $ list.map to_fmt $ (build []).snd
meta instance (α : Type) : has_to_format (smt2.builder α) :=
⟨ smt2.builder.to_format ⟩
namespace smt2
namespace builder
def add_command (c : cmd) : builder unit := do
cs ← state.read,
state.write (c :: cs)
def echo (msg : string) : builder unit :=
add_command (cmd.echo msg)
def check_sat : builder unit :=
add_command cmd.check_sat
def pop (n : nat) : builder unit :=
add_command $ cmd.pop n
def push (n : nat) : builder unit :=
add_command $ cmd.push n
def scope {α} (level : nat) (action : builder α) : builder α :=
do push level,
res ← action,
pop level,
return res
def reset : builder unit :=
add_command cmd.reset
def exit' : builder unit :=
add_command cmd.exit_cmd
def declare_const (sym : string) (s : sort) : builder unit :=
add_command $ cmd.declare_const sym s
end builder
end smt2