Speculative improvements to compile system.

* Automatically detect whether compiled or source is smaller and use that.
* Automatically find included dependencies and include them.
This commit is contained in:
Anna Rose 2021-08-19 02:25:20 +00:00
parent ea90d0b22c
commit b9206f8480

View File

@ -1,21 +1,39 @@
function Bootstrap { function Bootstrap {
parameter bootfile, init, compiled, copied, debug. parameter bootFile, init, programs, debug.
compileInit(init, debug).
compileLibs(compiled, debug).
copyLibs(copied).
// 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 { if debug {
// Open a terminal and run init. // Open a terminal and run init.
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
if init <> "" { if init <> "" {
run "/init". run "/init".
} }
// ... or delete the bootstrapping file, set init to the bootfile,
// and reboot.
} else { } else {
DeletePath("1:" + bootfile). DeletePath("1:" + bootfile).
// Set OS to boot and restart. // Set OS to boot and restart.
if init = "" { if init = "" {
set CORE:BOOTFILENAME to init. set CORE:BOOTFILENAME to "".
} else { } else {
set CORE:BOOTFILENAME to "/init". set CORE:BOOTFILENAME to "/init".
} }
@ -23,54 +41,38 @@ function Bootstrap {
} }
} }
function compileLibs { // compile the target ('src') file on volume 0, compare compiled size with source size,
parameter libs, debug. // copy the smaller file to 'dest' on volume 1.
if debug { // if debug is true, instead just copies src (volume 0) to dest (volume 1).
CopyLibs(libs). function compileFile {
return. parameter src, dest, debug is false.
}
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.
}
if debug { if debug {
copypath("0:" + init, "1:/init"). CopyPath("0:" + src + ".ks", "1:" + dest + ".ks").
return.
} }
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)).
}
}
} }