3eb7b58e1003 — Vesa Norilo 5 months ago
repl will now import files by -i argument into the interactive context
M .hgsubstate +1 -1
@@ 1,5 1,5 @@ 
 7e4ee7ddce2d2b7bd163389079343850f7174c0e library
-4185c9abec9fbd4329f94197a68d70533424236e src/lithe
+8b4b21f3c6f21d1e6eb60d7b0debfb74597ca2f5 src/lithe
 5a97797856da2c6b1a18bf9fe591a64d58b04e19 src/pad
 29a29937ee1095e5ddf1655902f1ed09c810bbf3 src/paf
 719dafae1a727094abcf28b315b4ed712150c0f7 src/pcoll

          
M src/driver/krepl.cpp +7 -1
@@ 72,7 72,13 @@ int krepl_main(CmdLine::IRegistry& CLOpt
 
 		cx = CreateContext(Packages::DefaultClient::ResolverCallback, &bbClient);
 
-		for (auto import : CL::import()) cx.ImportFile(import);
+		for (auto import : CL::import()) {
+			std::ifstream file{ import };
+			std::stringstream code;
+			code << file.rdbuf();
+			cx.ImportBuffer(code.str(), true);
+//			cx.ImportFile(import);
+		}
 
 		if (CL::interactive() && repl_args.empty()) {
 			std::stringstream banner;

          
M src/k3/CodeRepository.cpp +11 -5
@@ 415,7 415,8 @@ namespace K3 {
 				parseTree,
 				node->incremental,
 				[this, node](BufferKey imp) -> Err<void> {
-					return CreateImportTask(node, imp, { });
+					CHECK_ERR(CreateImportTask(node, imp, { }));
+					return { };
 				},
 				[imm](const char* sym, CGRef expr) -> Err<void> { 
 					if (imm) imm(sym, expr);

          
@@ 564,7 565,8 @@ namespace K3 {
 		Err<void> Repository::ImportTree(BufferKey fromLeaf, immediate_handler_t imm) {	
 			assert(importQueue.empty());
 			CHECK_ERR(CreateImportTask(&root, fromLeaf, imm));
-			return PerformQueue();
+			CHECK_ERR(PerformQueue());
+			return {};
 		}
 
 		Repository::Repository() {

          
@@ 583,7 585,10 @@ namespace K3 {
 
 		Err<void> Repository::ImportFile(const char* path, bool canOverwrite) {
 			relativeImportBase = { "#LOCAL", "", "" };
-			return Transaction([=](){ return ImportTree({ "#LOCAL", "", path }, { }); });
+			return Transaction([=]() -> Err<void> { 
+				BufferKey uri{ "#LOCAL", "", path };
+				return ImportTree(uri, { });
+			});
 		}
 
 		Err<void> Repository::ImportBuffer(const char* sourceCode, bool canOverwrite, immediate_handler_t imm) {

          
@@ 604,9 609,10 @@ namespace K3 {
 		}
 
 		Err<void> Repository::ImportCoreLib(const char* file) {
-			return Transaction([=]() {
+			return Transaction([=]() -> Err<void> {
 				relativeImportBase = { "#CORE", "", "" };
-				return ImportTree({ "#CORE", "", file }, { });
+				CHECK_ERR(ImportTree({ "#CORE", "", file }, { }));
+				return { };
 			});
 		}
 

          
M src/website/makehtml.cpp +2 -1
@@ 265,7 265,7 @@ std::unordered_map<std::string, std::fun
 				render_link(os, domid, element[1].to_str(), "#Reference:" + urlenc(element[1].to_str()));
 				break;
 			default:
-				std::cerr << "malformed link" << std::endl;
+				std::cerr << "malformed link" << picojson::value{ element } << std::endl;
 				exit(-1);
 			}
 		}

          
@@ 736,6 736,7 @@ int link_page(const char **files, int nu
 			auto err = picojson::parse(unit, json);
 			if (!err.empty()) {
 				std::cerr << "\n" << err;
+				std::cerr << unit << "\n";
 				exit(-1);
 			}
 

          
M src/website/md2json.cpp +10 -5
@@ 57,6 57,8 @@ static lithe::node consolidate_paragraph
 	lithe::node consolidated;
 	consolidated.strbeg = e.strbeg;
 	consolidated.strend = e.strend;
+	consolidated.src_begin = e.src_begin;
+	consolidated.src_end = e.src_end;
 	for (auto &c : e.children) {
 		if (consolidated.children.size() 
 			&& c.children.empty()

          
@@ 366,7 368,6 @@ picojson::value render_kronos_code(std::
 		
 		node_to_span(codeblock, cursor, c);
 
-		if (begin && end)
 		if (c.strbeg == tag::function ||
 			c.strbeg == tag::infix ||
 			c.strbeg == tag::list ||

          
@@ 399,8 400,8 @@ picojson::value render_kronos_code(std::
 				repl.eval.emplace_back(std::string{ begin,end });
 			}
 		}
-		while (isspace(*end)) ++end;
-		repl.code += {begin, end};
+		auto snippet = " "s + std::string{ begin,end } + "\n";
+		repl.code += snippet;
 		repl.code += "\n";
 	}
 	return codeblock;

          
@@ 410,8 411,8 @@ picojson::value convert(const lithe::nod
 	picojson::array children;
 	children.reserve(n.children.size() + 1);
 	if (n.strbeg) {
-		if (n.strbeg == md::code) {
-			if (n[0].strbeg == md::code_syntax) {
+		if (n.strbeg == md::code && n.size()) {
+			if (n[0].strbeg == md::code_syntax && n[0].size()) {
 				if (n[0][0].get_string() == "Kronos") {
 					std::stringstream code;
 					for (int i = 1;i < n.size();++i) {

          
@@ 460,10 461,12 @@ int compile_page(const char *in, const c
 
 	Packages::MakeMultiLevelPath(out);
 
+#ifdef NDEBUG
 	if (is_fresh(in, out)) {
 		std::clog << "(not modified)\n";
 		return 0;
 	}
+#endif
 	
 	std::ifstream read(in);
 

          
@@ 615,6 618,8 @@ int compile_page(const char *in, const c
 		}
 	} catch (std::exception & e) {
 		std::clog << e.what() << "\n";
+		writeFile.close();
+		if (strcmp(out,"-")) remove(out);
 		exit(-1);
 	}
 

          
M src/website/subrepl.cpp +4 -1
@@ 19,7 19,9 @@ std::string subrepl_state::evaluate(std:
 	dumpCode.close();
 
 	std::string escaped;
-
+#ifndef NDEBUG
+	std::clog << code;
+#endif
 	std::clog << "> " << immediate << "\n";
 
 	std::stringstream output;

          
@@ 42,6 44,7 @@ std::string subrepl_state::evaluate(std:
 	} catch (...) {
 		std::cerr.rdbuf(oldCerr);
 		std::cout.rdbuf(oldCout);
+		std::clog << output.str();
 		throw;
 	}
 	std::cerr.rdbuf(oldCerr);