From b9206f84806e1b2b8cefc7dbc5d9ebc78de76165 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 19 Aug 2021 02:25:20 +0000 Subject: [PATCH] Speculative improvements to compile system. * Automatically detect whether compiled or source is smaller and use that. * Automatically find included dependencies and include them. --- lib/boot.ks | 104 ++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/lib/boot.ks b/lib/boot.ks index 9db96c6..0b520e5 100644 --- a/lib/boot.ks +++ b/lib/boot.ks @@ -1,21 +1,39 @@ function Bootstrap { - parameter bootfile, init, compiled, copied, debug. - compileInit(init, debug). - compileLibs(compiled, debug). - copyLibs(copied). + parameter bootFile, init, programs, debug. + // create a list of libraries that we need to compile + local libs is UniqueSet(). + addLibs(libs, init). + for program in programs { + addLibs(libs, program). + } + + // compile the main program files + compileFile(init, "/init", debug). + for program in programs { + compileFile(program, program:Replace("/prog", ""), debug). + } + + // compile the libraries + for lib in libs { + compileFile(program, program, debug). + } + + // Either run init with a terminal open... if debug { // Open a terminal and run init. CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). if init <> "" { run "/init". } + // ... or delete the bootstrapping file, set init to the bootfile, + // and reboot. } else { DeletePath("1:" + bootfile). // Set OS to boot and restart. if init = "" { - set CORE:BOOTFILENAME to init. + set CORE:BOOTFILENAME to "". } else { set CORE:BOOTFILENAME to "/init". } @@ -23,54 +41,38 @@ function Bootstrap { } } -function compileLibs { - parameter libs, debug. - if debug { - CopyLibs(libs). - return. - } - - for lib in libs { - local tgt is lib. - if lib:StartsWith("/prog") { - set tgt to lib:Remove(0, 5). - } - local res is true. - compile "0:" + lib. - set res to copypath("0:" + lib + ".ksm", "1:" + tgt). - deletepath("0:" + lib + ".ksm"). - if not res { - print "Can't copy compiled file '" + lib + "', aborting.". - print ERR. // intentional error to trap execution - } - } -} - -function copyLibs { - parameter libs. - for lib in libs { - local tgt is lib. - if lib:StartsWith("/prog") { - set tgt to lib:Remove(0, 5). - } - if not copypath("0:" + lib, "1:" + tgt) { - print "Can't copy file '" + lib + "', aborting.". - print ERR. // intentional error to trap execution - } - } -} - -function compileInit { - parameter init, debug is false. - - if init = "" { - return. - } +// compile the target ('src') file on volume 0, compare compiled size with source size, +// copy the smaller file to 'dest' on volume 1. +// if debug is true, instead just copies src (volume 0) to dest (volume 1). +function compileFile { + parameter src, dest, debug is false. if debug { - copypath("0:" + init, "1:/init"). - return. + CopyPath("0:" + src + ".ks", "1:" + dest + ".ks"). } - compile "0:" + init to "1:/init". + compile "0:" + src. + local srcVF is Open(src + ".ks"). + local compiledVF is Open(src + ".ksm"). + if srcVF:SIZE < compiledVF:SIZE { + CopyPath("0:" + src + ".ks", "1:" + dest + ".ks"). + } else { + CopyPath("0:" + src + ".ksm", "1:" + dest + ".ksm"). + } + + DeletePath(compiledVF). +} + +function addLibs { + parameter libs, src. + + local srcVF is Open("0:" + src). + local contents is srcVF:ReadAll(). + for line in contents { + if line:Contains("RunOncePath") { + local start is line:Find("\""). + local end is line:FindLast("\""). + libs:Add(line:Substring(start, end - start)). + } + } }