pmake/src/js/core.js

102 lines
2 KiB
JavaScript
Raw Normal View History

2026-05-08 05:18:35 +09:00
const pmake = {
2026-05-08 19:07:45 +09:00
VERSION : "0.0",
2026-05-09 03:16:12 +09:00
compilers : {},
options : {},
projects : []
2026-05-08 05:18:35 +09:00
};
2026-05-09 03:16:12 +09:00
pmake.inherit = function(base, call) {
const func = (function() {});
2026-05-08 05:18:35 +09:00
Object.setPrototypeOf(func.prototype, base.prototype);
return func;
};
2026-05-08 05:35:07 +09:00
pmake.inherited = function(base, parent) {
2026-05-08 05:18:35 +09:00
var proto = base.prototype;
2026-05-08 05:35:07 +09:00
while(proto) {
2026-05-08 05:18:35 +09:00
if(proto == parent.prototype) return true;
proto = Object.getPrototypeOf(proto);
}
return false;
2026-05-08 05:35:07 +09:00
};
2026-05-08 05:18:35 +09:00
2026-05-08 05:35:07 +09:00
pmake.register = function(base) {
2026-05-09 03:16:12 +09:00
if(base instanceof pmake.Compiler) {
2026-05-08 19:07:45 +09:00
pmake.compilers[base.target] = base;
2026-05-09 03:16:12 +09:00
} else if(base instanceof pmake.Option) {
if(!pmake.options[base.category]) pmake.options[base.category] = {};
pmake.options[base.category][base.target] = base;
} else if(base instanceof pmake.Project) {
pmake.projects.push(base);
}
};
2026-05-09 03:16:20 +09:00
pmake.resolveProjects = function(arr) {
2026-05-09 03:16:12 +09:00
var r = [];
2026-05-09 03:16:20 +09:00
for(var i = 0; i < arr.length; i++) {
if(arr[i] instanceof pmake.Project) {
2026-05-09 03:16:12 +09:00
r = r.concat(pmake.resolveProjects(arr[i].libraries));
r.push(arr[i]);
}
2026-05-08 05:18:35 +09:00
}
2026-05-09 03:16:12 +09:00
return r;
};
(function() {
const Compiler = function() {};
const POSIXCompiler = pmake.inherit(Compiler);
const Option = function() {};
const Project = function(target) {
2026-05-09 03:16:20 +09:00
this.target = target;
this.files = [];
2026-05-09 03:16:12 +09:00
this.libraries = [];
2026-05-08 05:35:07 +09:00
};
2026-05-08 05:18:35 +09:00
2026-05-09 03:16:12 +09:00
Project.prototype.generate = function() {
2026-05-08 19:07:45 +09:00
};
2026-05-09 03:16:12 +09:00
const File = function(filename, mode) {
this.fp = fs.open(filename, mode);
2026-05-08 19:07:45 +09:00
};
2026-05-09 03:16:12 +09:00
File.prototype.write = function(string) {
fs.write(this.fp, string);
};
File.prototype.close = function() {
fs.close(this.fp);
};
pmake.Compiler = Compiler;
pmake.POSIXCompiler = POSIXCompiler;
pmake.Option = Option;
pmake.Project = Project;
pmake.File = File;
})();
/*** Option ***/
(function() {
const Compiler = new pmake.Option();
Compiler.category = "General";
Compiler.target = "compiler";
Compiler.description = "Choose a compiler set; one of:";
Compiler.option = "VALUE";
Compiler.options = function() {
return Object.keys(pmake.compilers);
};
pmake.register(Compiler);
})();