Native shebang: Difference between revisions

m
Line 728:
 
=={{header|zkl}}==
This isn't something that is usually done with zkl as the compiler is fast enough (for scripts) to just run the source and let it get compiled and run. But, it can be done. Note: The binary still "links" against zkl (the VM) so the #! is required.
 
Since the #! parsing is done by a compiler front end and was designed to be used from the command line, we'll do that by forking zkl to compile the source if it is newer than the binary.
<lang zkl>#!/home/craigd/Bin/zkl
// This file: nativeShebang.zkl, compiles to nativeShebang.zsc
 
// This file: nativeShebang.zkl
// zkl --#! . -c nativeShebang -o.
// chmod a+x nativeShebang.z*
// ./nativeShebang.zsc
 
 
// If this [source] file is newer than the compiled version (or the
// compiled file doesn't exist), compile up a new version
 
runningName :=System.argv[1];
srcName :=__FILE__;
compiledNameparts,path :=File.splitFileName(srcNamerunningName),parts[0,-12].concat() +or ".zsc";
srcName :=parts[0,-1].concat() + ".zkl";
compiledName:=parts[0,-1].concat() + ".zsc";
if(not File.exists(compiledName) or
File.info(srcName)[2] > File.info(compiledName)[2]){ // compare modifed dates
System.cmd("zkl --#! . -c %s -o.%s --exit".fmt(srcName,path));
System.cmd("chmod a+x %s".fmt(compiledName));
}
Anonymous user