format
This commit is contained in:
parent
ece62938a9
commit
a523a42e6e
10 changed files with 78 additions and 52 deletions
24
.clang-format
Normal file
24
.clang-format
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
UseTab: Always
|
||||||
|
TabWidth: 8
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: true
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: true
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
NamespaceIndentation: All
|
||||||
|
IndentWidth: 8
|
||||||
|
PointerAlignment: Left
|
||||||
|
ColumnLimit: 0
|
||||||
|
AllowShortIfStatementsOnASingleLine: Always
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: true
|
||||||
|
SpaceBeforeParens: Never
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
SortIncludes: false
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
#IndentPPDirectives: AfterHash
|
||||||
22
GNUmakefile
22
GNUmakefile
|
|
@ -32,7 +32,7 @@ OBJS += external/duktape/duktape.o external/stb/stb_ds.o
|
||||||
|
|
||||||
NAME = rev | cut -d/ -f1 | rev | cut -d. -f1
|
NAME = rev | cut -d/ -f1 | rev | cut -d. -f1
|
||||||
|
|
||||||
.PHONY: all clean mk maint
|
.PHONY: all clean mk format maint
|
||||||
.SUFFIXES: .c .o
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
all: pmake$(EXE)
|
all: pmake$(EXE)
|
||||||
|
|
@ -52,6 +52,9 @@ mk/js.mk:
|
||||||
|
|
||||||
mk: mk/js.mk
|
mk: mk/js.mk
|
||||||
|
|
||||||
|
format:
|
||||||
|
clang-format --verbose -i src/*/*.js `find src -name "*.c" -or -name "*.h"`
|
||||||
|
|
||||||
maint:
|
maint:
|
||||||
rm -f mk/*.mk
|
rm -f mk/*.mk
|
||||||
$(MAKE) mk
|
$(MAKE) mk
|
||||||
|
|
@ -62,16 +65,13 @@ src/config.h:
|
||||||
echo "#ifndef __CONFIG_H__" > $@
|
echo "#ifndef __CONFIG_H__" > $@
|
||||||
echo "#define __CONFIG_H__" >> $@
|
echo "#define __CONFIG_H__" >> $@
|
||||||
echo "" >> $@
|
echo "" >> $@
|
||||||
echo "#define COMPILERS \\" >> $@
|
for i in compiler action; do \
|
||||||
find src/compiler -name "*.js" | while read js; do \
|
echo "#define `echo $$i | tr '[:lower:]' '[:upper:]'`S \\" >> $@ ; \
|
||||||
echo " X(`echo $$js | $(NAME)`) \\" ; \
|
find src/$$i -name "*.js" | while read js; do \
|
||||||
done >> $@
|
echo " X(`echo $$js | $(NAME)`, $$i) \\" ; \
|
||||||
echo "" >> $@
|
done >> $@ ; \
|
||||||
echo "#define ACTIONS \\" >> $@
|
echo "" >> $@ ; \
|
||||||
find src/action -name "*.js" | while read js; do \
|
done
|
||||||
echo " X(`echo $$js | $(NAME)`) \\" ; \
|
|
||||||
done >> $@
|
|
||||||
echo "" >> $@
|
|
||||||
echo "#define JS \\" >> $@
|
echo "#define JS \\" >> $@
|
||||||
echo " COMPILERS \\" >> $@
|
echo " COMPILERS \\" >> $@
|
||||||
echo " ACTIONS" >> $@
|
echo " ACTIONS" >> $@
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
const GCC = pmake.inherit(Compiler);
|
const GCC = pmake.inherit(Compiler);
|
||||||
|
|
||||||
|
GCC.name = "GCC";
|
||||||
GCC.description = "GCC/Clang";
|
GCC.description = "GCC/Clang";
|
||||||
|
|
||||||
pmake.register(GCC);
|
pmake.register(GCC);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
const Watcom = pmake.inherit(Compiler);
|
const Watcom = pmake.inherit(Compiler);
|
||||||
|
|
||||||
|
Watcom.name = "Watcom";
|
||||||
Watcom.description = "Open Watcom";
|
Watcom.description = "Open Watcom";
|
||||||
|
|
||||||
pmake.register(Watcom);
|
pmake.register(Watcom);
|
||||||
|
|
|
||||||
6
src/config.h
generated
6
src/config.h
generated
|
|
@ -2,11 +2,11 @@
|
||||||
#define __CONFIG_H__
|
#define __CONFIG_H__
|
||||||
|
|
||||||
#define COMPILERS \
|
#define COMPILERS \
|
||||||
X(watcom) \
|
X(watcom, compiler) \
|
||||||
X(gcc) \
|
X(gcc, compiler)
|
||||||
|
|
||||||
#define ACTIONS \
|
#define ACTIONS \
|
||||||
X(gmake) \
|
X(gmake, action)
|
||||||
|
|
||||||
#define JS \
|
#define JS \
|
||||||
COMPILERS \
|
COMPILERS \
|
||||||
|
|
|
||||||
36
src/js.c
36
src/js.c
|
|
@ -5,20 +5,20 @@ duk_context* js_ctx;
|
||||||
LOAD(js_core);
|
LOAD(js_core);
|
||||||
LOAD(js_cmdline);
|
LOAD(js_cmdline);
|
||||||
|
|
||||||
static duk_ret_t js_console_log(duk_context* self){
|
static duk_ret_t js_console_log(duk_context* self) {
|
||||||
printf("%s\n", duk_to_string(self, 0));
|
printf("%s\n", duk_to_string(self, 0));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void js_argv_init(int argc, char** argv){
|
static void js_argv_init(int argc, char** argv) {
|
||||||
int arr;
|
int arr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
duk_push_global_object(js_ctx);
|
||||||
arr = duk_push_array(js_ctx);
|
arr = duk_push_array(js_ctx);
|
||||||
|
|
||||||
for(i = 0; i < argc; i++){
|
for(i = 0; i < argc; i++) {
|
||||||
duk_push_string(js_ctx, argv[i]);
|
duk_push_string(js_ctx, argv[i]);
|
||||||
duk_put_prop_index(js_ctx, arr, i);
|
duk_put_prop_index(js_ctx, arr, i);
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ static void js_argv_init(int argc, char** argv){
|
||||||
duk_pop(js_ctx);
|
duk_pop(js_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void js_console_init(void){
|
static void js_console_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
duk_push_global_object(js_ctx);
|
||||||
|
|
@ -42,24 +42,24 @@ static void js_console_init(void){
|
||||||
duk_pop(js_ctx);
|
duk_pop(js_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static duk_ret_t js_process_exit(duk_context* self){
|
static duk_ret_t js_process_exit(duk_context* self) {
|
||||||
duk_idx_t argc = duk_get_top(self);
|
duk_idx_t argc = duk_get_top(self);
|
||||||
int ex;
|
int ex;
|
||||||
|
|
||||||
if(argc > 1){
|
if(argc > 1) {
|
||||||
return duk_error(self, DUK_ERR_TYPE_ERROR, "needs 0 or 1 argument(s)");
|
return duk_error(self, DUK_ERR_TYPE_ERROR, "needs 0 or 1 argument(s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc == 1){
|
if(argc == 1) {
|
||||||
ex = duk_to_number(self, 0);
|
ex = duk_to_number(self, 0);
|
||||||
}else{
|
} else {
|
||||||
ex = 0;
|
ex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(ex);
|
exit(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void js_process_init(void){
|
static void js_process_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
duk_push_global_object(js_ctx);
|
||||||
|
|
@ -73,27 +73,27 @@ static void js_process_init(void){
|
||||||
duk_pop(js_ctx);
|
duk_pop(js_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int js_init(int argc, char** argv){
|
int js_init(int argc, char** argv) {
|
||||||
js_ctx = duk_create_heap_default();
|
js_ctx = duk_create_heap_default();
|
||||||
|
|
||||||
js_argv_init(argc, argv);
|
js_argv_init(argc, argv);
|
||||||
js_console_init();
|
js_console_init();
|
||||||
js_process_init();
|
js_process_init();
|
||||||
|
|
||||||
if(duk_peval_lstring(js_ctx, js_core, js_core_len) != 0){
|
if(duk_peval_lstring(js_ctx, js_core, js_core_len) != 0) {
|
||||||
printf("error: js/core.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
printf("error: js/core.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define X(name) \
|
#define X(name, prefix) \
|
||||||
if(duk_peval_lstring(js_ctx, compiler_ ## name, compiler_ ## name ## _len) != 0){ \
|
if(duk_peval_lstring(js_ctx, prefix##_##name, prefix##_##name##_len) != 0) { \
|
||||||
printf("error: %s: %s\n", "compiler/" #name ".js", duk_safe_to_string(js_ctx, -1)); \
|
printf("error: %s: %s\n", #prefix "/" #name ".js", duk_safe_to_string(js_ctx, -1)); \
|
||||||
return 1; \
|
return 1; \
|
||||||
}
|
}
|
||||||
COMPILERS;
|
JS;
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
if(duk_peval_lstring(js_ctx, js_cmdline, js_cmdline_len) != 0){
|
if(duk_peval_lstring(js_ctx, js_cmdline, js_cmdline_len) != 0) {
|
||||||
printf("error: js/cmdline.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
printf("error: js/cmdline.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -101,6 +101,6 @@ int js_init(int argc, char** argv){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void js_uninit(void){
|
void js_uninit(void) {
|
||||||
duk_destroy_heap(js_ctx);
|
duk_destroy_heap(js_ctx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
if(ARGV.length == 1){
|
if(ARGV.length == 1) {
|
||||||
console.log("Type '" + ARGV[0] + " --help' for help");
|
console.log("Type '" + ARGV[0] + " --help' for help");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = 1; i < ARGV.length; i++){
|
for(var i = 1; i < ARGV.length; i++) {
|
||||||
if(ARGV[i] == "--help"){
|
if(ARGV[i] == "--help") {
|
||||||
console.log("PMake " + pmake.VERSION + " - Pyrite's build script generator");
|
console.log("PMake " + pmake.VERSION + " - Pyrite's build script generator");
|
||||||
console.log("");
|
console.log("");
|
||||||
console.log("Usage: " + ARGV[0] + " [options] action [arguments]");
|
console.log("Usage: " + ARGV[0] + " [options] action [arguments]");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}else if(ARGV[i].startsWith("--")){
|
} else if(ARGV[i].startsWith("--")) {
|
||||||
console.log("Error: invalid option '" + ARGV[i].substr(2) + "'");
|
console.log("Error: invalid option '" + ARGV[i].substr(2) + "'");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}else{
|
} else {
|
||||||
console.log("Error: no such action '" + ARGV[i] + "'");
|
console.log("Error: no such action '" + ARGV[i] + "'");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
const pmake = {
|
const pmake = {
|
||||||
VERSION: "0.0"
|
VERSION : "0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
pmake.inherit = function(base){
|
pmake.inherit = function(base) {
|
||||||
const func = function(){};
|
const func = function() {};
|
||||||
|
|
||||||
Object.setPrototypeOf(func.prototype, base.prototype);
|
Object.setPrototypeOf(func.prototype, base.prototype);
|
||||||
|
|
||||||
return func;
|
return func;
|
||||||
};
|
};
|
||||||
|
|
||||||
pmake.inherited = function(base, parent){
|
pmake.inherited = function(base, parent) {
|
||||||
var proto = base.prototype;
|
var proto = base.prototype;
|
||||||
|
|
||||||
while(proto){
|
while(proto) {
|
||||||
if(proto == parent.prototype) return true;
|
if(proto == parent.prototype) return true;
|
||||||
|
|
||||||
proto = Object.getPrototypeOf(proto);
|
proto = Object.getPrototypeOf(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
pmake.register = function(base){
|
pmake.register = function(base) {
|
||||||
if(pmake.inherited(base, Compiler)){
|
if(pmake.inherited(base, Compiler)) {
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function Compiler(){
|
function Compiler() {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "pmake.h"
|
#include "pmake.h"
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv) {
|
||||||
int st;
|
int st;
|
||||||
|
|
||||||
if((st = js_init(argc, argv)) != 0) return st;
|
if((st = js_init(argc, argv)) != 0) return st;
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,15 @@
|
||||||
|
|
||||||
#define LOAD(name) \
|
#define LOAD(name) \
|
||||||
extern unsigned char name[]; \
|
extern unsigned char name[]; \
|
||||||
extern unsigned int name ## _len;
|
extern unsigned int name##_len;
|
||||||
|
|
||||||
#define X(name) LOAD(compiler_ ## name)
|
#define X(name, prefix) LOAD(prefix##_##name)
|
||||||
JS;
|
JS;
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
/* js.c */
|
/* js.c */
|
||||||
extern duk_context* js_context;
|
extern duk_context* js_context;
|
||||||
int js_init(int argc, char** argv);
|
int js_init(int argc, char** argv);
|
||||||
void js_uninit(void);
|
void js_uninit(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue