mirror of
https://github.com/HigherOrderCO/Kind.git
synced 2024-09-11 16:25:54 +03:00
initially, I wanted Kind2 to be bootstrapped, but I'm facing difficulties, because pure hvm parser is still much slower than the typescript parser; a few seconds vs instant to parse the entire codebase. I think HVM2 will need to have proper immutable strings (i.e., nodes that expand as if they were cons-strings, but are stored as buffers) before it can have fast parsers. as such, I'm making the decision to NOT bootstrap it now. that is a tough decision becase, honestly, if we don't do it as soon as possible in the development process, it is very unlikely we'll ever do it. but the tech isn't ready for it, and we need to move forward, so, that's the only solution. as such, I'll be rewritting the typescript to Rust, and we'll have a very similar design to former Kind2, with Rust doing the parsing, IO and error reporting, and a checker.hvm1 / checker.hvm2 file doing the actual type-checking (and HOAS-based type-level evaluation). also, I believe we'll not even generate .hvm from a .kind bootstrap. while losing types is significant, being able to manually edit the HVM is very helpful to debugging, it simplifies and accelerates the development process and removes many complications that are bought by bootstrapping
114 lines
3.7 KiB
Plaintext
114 lines
3.7 KiB
Plaintext
Kind.Term.to_hvm.go
|
|
: ∀(term: Kind.Term)
|
|
∀(dep: Nat)
|
|
∀(inc: Bool)
|
|
∀(tab: Nat)
|
|
String.Concatenator
|
|
= λterm λdep λinc λtab
|
|
let P = λx String.Concatenator
|
|
let all = λnam λinp λbod λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "0")
|
|
nil))
|
|
let lam = λnam λbod λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "λ")
|
|
//((Kind.Text.show.go (U60.name (U60.from_nat dep)))
|
|
((Kind.Text.show.go (String.cons '_' nam))
|
|
((Kind.Text.show.go " "
|
|
((Kind.Term.to_hvm.go (bod (Kind.var nam dep)) (Nat.succ dep) Bool.true tab)
|
|
nil))))))
|
|
let app = λfun λarg λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "(")
|
|
((Kind.Term.to_hvm.go fun dep Bool.true tab)
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Term.to_hvm.go arg dep Bool.true tab)
|
|
((Kind.Text.show.go ")")
|
|
nil))))))
|
|
let ann = λval λtyp λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Term.to_hvm.go val dep Bool.true tab)
|
|
nil))
|
|
let slf = λnam λbod λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "0")
|
|
nil))
|
|
let ins = λval λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Term.to_hvm.go val dep Bool.true tab)
|
|
nil))
|
|
let ref = λnam λval λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "(F.")
|
|
((Kind.Text.show.go nam)
|
|
((Kind.Text.show.go ")")
|
|
nil))))
|
|
let def = λnam λval λbod λnil
|
|
let tab = ((~inc λx∀(x:Nat)Nat Nat.succ λx(x)) tab)
|
|
((Kind.Text.show.go String.newline)
|
|
((Kind.Text.show.go (String.indent tab))
|
|
((Kind.Text.show.go "let ")
|
|
//((Kind.Text.show.go (U60.name (U60.from_nat dep)))
|
|
((Kind.Text.show.go (String.cons '_' nam))
|
|
((Kind.Text.show.go " = ")
|
|
((Kind.Term.to_hvm.go val dep Bool.true tab)
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Term.to_hvm.go (bod (Kind.var nam dep)) (Nat.succ dep) Bool.false tab)
|
|
nil))))))))
|
|
let set = λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "0")
|
|
nil))
|
|
let u60 = λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "0")
|
|
nil))
|
|
let num = λval λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((U60.show.go val)
|
|
nil))
|
|
let op2 = λopr λfst λsnd λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "(")
|
|
((Kind.Oper.show.go opr) // TODO: Kind.Oper.to_hvm
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Term.to_hvm.go fst dep Bool.true tab)
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Term.to_hvm.go snd dep Bool.true tab)
|
|
((Kind.Text.show.go ")")
|
|
nil))))))))
|
|
let mat = λnam λx λz λs λp λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "(U60.match ")
|
|
((Kind.Term.to_hvm.go x dep Bool.true tab)
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Term.to_hvm.go z dep Bool.true tab)
|
|
((Kind.Text.show.go " ")
|
|
((Kind.Text.show.go "λ")
|
|
((Kind.Text.show.go (String.cons '_' (String.concat nam "_1")))
|
|
//((Kind.Text.show.go (U60.name (U60.from_nat dep)))
|
|
((Kind.Text.show.go "(")
|
|
((Kind.Term.to_hvm.go (s (Kind.var (String.concat nam "_1") dep)) (Nat.succ dep) Bool.true tab)
|
|
((Kind.Text.show.go ")")
|
|
((Kind.Text.show.go ")")
|
|
nil))))))))))))
|
|
let txt = λtxt λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "(Str ")
|
|
((Kind.Text.show.go String.quote)
|
|
((Kind.Text.show.go txt)
|
|
((Kind.Text.show.go String.quote)
|
|
((Kind.Text.show.go ")")
|
|
nil))))))
|
|
let hol = λnam λctx λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
((Kind.Text.show.go "0")
|
|
nil))
|
|
let var = λnam λidx λnil
|
|
((Kind.Term.to_hvm.nl inc tab)
|
|
//((Kind.Text.show.go (U60.name (U60.from_nat idx)))
|
|
((Kind.Text.show.go (String.cons '_' nam))
|
|
nil))
|
|
(~term P all lam app ann slf ins ref def set u60 num op2 mat txt hol var)
|