From b88027c19181f24584d5ad1c46fb2443d65edece Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 14 Nov 2017 20:03:14 -0400 Subject: - Fixed some bugs. - new-luxc can now fully compile lux.lux! --- stdlib/source/lux.lux | 57 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 15 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 70563181a..0da0a628a 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -4281,30 +4281,57 @@ (#Some [def-type def-meta def-value]) (#Right [state [def-type def-value]]))))) +(def: (find-type-var idx bindings) + (-> Nat (List [Nat (Maybe Type)]) (Maybe Type)) + (case bindings + #;Nil + #;Nil + + (#;Cons [var bound] bindings') + (if (n.= idx var) + bound + (find-type-var idx bindings')))) + (def: (find-type ident) (-> Ident (Meta Type)) (do Monad [#let [[module name] ident] current-module current-module-name] - (function [state] - (if (text/= "" module) - (case (find-in-env name state) - (#Some struct-type) - (#Right state struct-type) + (function [compiler] + (let [temp (if (text/= "" module) + (case (find-in-env name compiler) + (#Some struct-type) + (#Right [compiler struct-type]) - _ - (case (find-def-type [current-module name] state) - (#Some struct-type) - (#Right state struct-type) + _ + (case (find-def-type [current-module name] compiler) + (#Some struct-type) + (#Right [compiler struct-type]) - _ - (#Left ($_ text/compose "Unknown var: " (ident/encode ident))))) - (case (find-def-type ident state) - (#Some struct-type) - (#Right state struct-type) + _ + (#Left ($_ text/compose "Unknown var: " (ident/encode ident))))) + (case (find-def-type ident compiler) + (#Some struct-type) + (#Right [compiler struct-type]) + + _ + (#Left ($_ text/compose "Unknown var: " (ident/encode ident)))))] + (case temp + (#Right [compiler (#Var type-id)]) + (let [{#info _ #source _ #current-module _ #modules _ + #scopes _ #type-context type-context #host _ + #seed _ #expected _ #cursor _ + #scope-type-vars _} compiler + {#ex-counter _ #var-counter _ #var-bindings var-bindings} type-context] + (case (find-type-var type-id var-bindings) + #;None + temp + + (#;Some actualT) + (#Right [compiler actualT]))) _ - (#Left ($_ text/compose "Unknown var: " (ident/encode ident))))) + temp)) ))) (def: (zip2 xs ys) -- cgit v1.2.3