Skip to content

Commit

Permalink
Merge pull request #30 from wrapl/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rajamukherji authored Jul 23, 2018
2 parents 085e454 + b2cb982 commit 4c1162e
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 481 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ all: rabs
sources = \
minilang/sha256.c \
minilang/minilang.c \
minilang/ml_compiler.c \
minilang/ml_runtime.c \
minilang/ml_types.c \
minilang/ml_file.c \
minilang/ml_console.c \
minilang/stringmap.c \
minilang/linenoise.c \
cache.c \
Expand All @@ -20,8 +24,15 @@ sources = \

VERSION = test

CFLAGS += -std=gnu99 -fstrict-aliasing -Wstrict-aliasing -I. -Iminilang -pthread -DSQLITE_THREADSAFE=0 -DGC_THREADS -D_GNU_SOURCE -g -O2
LDFLAGS += -lm -ldl -lgc -lsqlite3 -g
CFLAGS += -std=gnu99 -fstrict-aliasing -Wstrict-aliasing -I. -Iminilang -pthread -DSQLITE_THREADSAFE=0 -DGC_THREADS -D_GNU_SOURCE
LDFLAGS += -lm -ldl -lgc -lsqlite3

ifdef DEBUG
CFLAGS += -g
LDFLAGS += -g
else
CFLAGS += -O2
endif

rabs: Makefile $(sources) *.h
gcc $(CFLAGS) $(sources) $(LDFLAGS) -o $@
Expand Down
67 changes: 22 additions & 45 deletions cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ static sqlite3_stmt *HashBuildGetStatement;
static sqlite3_stmt *HashBuildSetStatement;
static sqlite3_stmt *LastCheckSetStatement;
static sqlite3_stmt *DependsGetStatement;
static sqlite3_stmt *DependsDeleteStatement;
static sqlite3_stmt *DependsInsertStatement;
static sqlite3_stmt *DependsSetStatement;
static sqlite3_stmt *ScanGetStatement;
static sqlite3_stmt *ScanDeleteStatement;
static sqlite3_stmt *ScanInsertStatement;
static sqlite3_stmt *ScanSetStatement;
static sqlite3_stmt *ExprGetStatement;
static sqlite3_stmt *ExprSetStatement;
int CurrentVersion = 0;
Expand All @@ -41,7 +39,7 @@ void cache_open(const char *RootPath) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "PRAGMA journal_mode = PERSIST", 0, 0, 0) != SQLITE_OK) {
if (sqlite3_exec(Cache, "PRAGMA journal_mode = MEMORY", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
Expand All @@ -57,31 +55,15 @@ void cache_open(const char *RootPath) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE INDEX IF NOT EXISTS hashes_idx ON hashes(id);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE TABLE IF NOT EXISTS builds(id TEXT PRIMARY KEY, build BLOB);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE INDEX IF NOT EXISTS builds_idx ON builds(id);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE TABLE IF NOT EXISTS scans(id TEXT, scan BLOB);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE INDEX IF NOT EXISTS scans_idx ON scans(id);", 0, 0, 0) != SQLITE_OK) {
if (sqlite3_exec(Cache, "CREATE TABLE IF NOT EXISTS scans(id TEXT PRIMARY KEY, scan BLOB);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE TABLE IF NOT EXISTS depends(id TEXT, depend BLOB);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_exec(Cache, "CREATE INDEX IF NOT EXISTS depends_idx ON depends(id);", 0, 0, 0) != SQLITE_OK) {
if (sqlite3_exec(Cache, "CREATE TABLE IF NOT EXISTS depends(id TEXT PRIMARY KEY, depend BLOB);", 0, 0, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
Expand Down Expand Up @@ -113,23 +95,15 @@ void cache_open(const char *RootPath) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_prepare_v2(Cache, "DELETE FROM scans WHERE id = ?", -1, &ScanDeleteStatement, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_prepare_v2(Cache, "INSERT INTO scans(id, scan) VALUES(?, ?)", -1, &ScanInsertStatement, 0) != SQLITE_OK) {
if (sqlite3_prepare_v2(Cache, "REPLACE INTO scans(id, scan) VALUES(?, ?)", -1, &ScanSetStatement, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_prepare_v2(Cache, "SELECT depend FROM depends WHERE id = ?", -1, &DependsGetStatement, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_prepare_v2(Cache, "DELETE FROM depends WHERE id = ?", -1, &DependsDeleteStatement, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
if (sqlite3_prepare_v2(Cache, "INSERT INTO depends(id, depend) VALUES(?, ?)", -1, &DependsInsertStatement, 0) != SQLITE_OK) {
if (sqlite3_prepare_v2(Cache, "REPLACE INTO depends(id, depend) VALUES(?, ?)", -1, &DependsSetStatement, 0) != SQLITE_OK) {
printf("Sqlite error: %s\n", sqlite3_errmsg(Cache));
exit(1);
}
Expand Down Expand Up @@ -159,12 +133,15 @@ void cache_open(const char *RootPath) {
void cache_close() {
sqlite3_finalize(HashGetStatement);
sqlite3_finalize(HashSetStatement);
sqlite3_finalize(HashBuildGetStatement);
sqlite3_finalize(HashBuildSetStatement);
sqlite3_finalize(LastCheckSetStatement);
sqlite3_finalize(DependsGetStatement);
sqlite3_finalize(DependsDeleteStatement);
sqlite3_finalize(DependsInsertStatement);
sqlite3_finalize(DependsSetStatement);
sqlite3_finalize(ScanGetStatement);
sqlite3_finalize(ScanDeleteStatement);
sqlite3_finalize(ScanInsertStatement);
sqlite3_finalize(ScanSetStatement);
sqlite3_finalize(ExprGetStatement);
sqlite3_finalize(ExprSetStatement);
sqlite3_close(Cache);
}

Expand Down Expand Up @@ -311,10 +288,10 @@ void cache_depends_set(target_t *Target, targetset_t *Depends) {
char *Next = Buffer;
targetset_foreach(Depends, &Next, (void *)cache_target_set_append);
*Next = 0;
sqlite3_bind_text(DependsInsertStatement, 1, Target->Id, Target->IdLength, SQLITE_STATIC);
sqlite3_bind_blob(DependsInsertStatement, 2, Buffer, Size, SQLITE_STATIC);
sqlite3_step(DependsInsertStatement);
sqlite3_reset(DependsInsertStatement);
sqlite3_bind_text(DependsSetStatement, 1, Target->Id, Target->IdLength, SQLITE_STATIC);
sqlite3_bind_blob(DependsSetStatement, 2, Buffer, Size, SQLITE_STATIC);
sqlite3_step(DependsSetStatement);
sqlite3_reset(DependsSetStatement);
sqlite3_exec(Cache, "COMMIT TRANSACTION", 0, 0, 0);
}

Expand All @@ -337,10 +314,10 @@ void cache_scan_set(target_t *Target, targetset_t *Scans) {
char *Next = Buffer;
targetset_foreach(Scans, &Next, (void *)cache_target_set_append);
*Next = 0;
sqlite3_bind_text(ScanInsertStatement, 1, Target->Id, Target->IdLength, SQLITE_STATIC);
sqlite3_bind_blob(ScanInsertStatement, 2, Buffer, Size, SQLITE_STATIC);
sqlite3_step(ScanInsertStatement);
sqlite3_reset(ScanInsertStatement);
sqlite3_bind_text(ScanSetStatement, 1, Target->Id, Target->IdLength, SQLITE_STATIC);
sqlite3_bind_blob(ScanSetStatement, 2, Buffer, Size, SQLITE_STATIC);
sqlite3_step(ScanSetStatement);
sqlite3_reset(ScanSetStatement);
sqlite3_exec(Cache, "COMMIT TRANSACTION", 0, 0, 0);
}

Expand Down
1 change: 0 additions & 1 deletion context.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <gc.h>
#include <unistd.h>

__thread context_t *CurrentContext = 0;
static stringmap_t ContextCache[1] = {STRINGMAP_INIT};
static ml_value_t *DefaultString;

Expand Down
2 changes: 1 addition & 1 deletion minilang
Submodule minilang updated 14 files
+6 −5 Makefile
+1 −4,158 minilang.c
+4 −147 minilang.h
+3 −2 minipp.c
+2 −1 ml.c
+1,694 −0 ml_compiler.c
+101 −0 ml_compiler.h
+74 −0 ml_console.c
+8 −0 ml_console.h
+39 −0 ml_macros.h
+378 −0 ml_runtime.c
+76 −0 ml_runtime.h
+2,036 −0 ml_types.c
+163 −0 ml_types.h
62 changes: 35 additions & 27 deletions rabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include "cache.h"
#include "minilang.h"
#include "ml_file.h"
#include "ml_console.h"
#include "rabs.h"
#include "minilang/stringmap.h"

#define VERSION_STRING "1.0.3"
#define VERSION_STRING "1.1.0"

const char *SystemName = "/_minibuild_";
const char *RootPath = 0;
Expand Down Expand Up @@ -108,14 +109,14 @@ ml_value_t *subdir(void *Data, int Count, ml_value_t **Args) {
FileName = vfs_resolve(CurrentContext->Mounts, FileName);
target_t *ParentDefault = CurrentContext->Default;
context_push(Path);
target_depends_add(ParentDefault, CurrentContext->Default);
targetset_insert(ParentDefault->Depends, CurrentContext->Default);
load_file(FileName);
context_pop();
return MLNil;
}

ml_value_t *scope(void *Data, int Count, ml_value_t **Args) {
ML_CHECK_ARG_COUNT(1);
ML_CHECK_ARG_COUNT(2);
ML_CHECK_ARG_TYPE(0, MLStringT);
const char *Name = ml_string_value(Args[0]);
context_scope(Name);
Expand Down Expand Up @@ -155,7 +156,8 @@ ml_value_t *vmount(void *Data, int Count, ml_value_t **Args) {
const char *Target = ml_string_value(Args[1]);
CurrentContext->Mounts = vfs_mount(CurrentContext->Mounts,
concat(CurrentContext->Path, "/", Path, NULL),
concat(CurrentContext->Path, "/", Target, NULL)
concat(CurrentContext->Path, "/", Target, NULL),
Target[0] == '/'
);
return MLNil;
}
Expand All @@ -173,9 +175,9 @@ ml_value_t *execute(void *Data, int Count, ml_value_t **Args) {
if (Result != MLNil) ml_stringbuffer_add(Buffer, " ", 1);
}
const char *Command = ml_stringbuffer_get(Buffer);
if (EchoCommands) printf("\e[34m%s: %s\e[0m\n", CurrentContext->FullPath, Command);
if (EchoCommands) printf("\e[34m%s: %s\e[0m\n", CurrentDirectory, Command);
clock_t Start = clock();
chdir(CurrentContext->FullPath);
chdir(CurrentDirectory);
FILE *File = popen(Command, "r");
pthread_mutex_unlock(GlobalLock);
char Chars[120];
Expand Down Expand Up @@ -208,9 +210,9 @@ ml_value_t *shell(void *Data, int Count, ml_value_t **Args) {
if (Result != MLNil) ml_stringbuffer_add(Buffer, " ", 1);
}
const char *Command = ml_stringbuffer_get(Buffer);
if (EchoCommands) printf("\e[34m%s\e[0m\n", Command);
if (EchoCommands) printf("\e[34m%s: %s\e[0m\n", CurrentDirectory, Command);
clock_t Start = clock();
chdir(CurrentContext->FullPath);
chdir(CurrentDirectory);
FILE *File = popen(Command, "r");
pthread_mutex_unlock(GlobalLock);
char Chars[ML_STRINGBUFFER_NODE_SIZE];
Expand Down Expand Up @@ -252,6 +254,18 @@ ml_value_t *rabs_mkdir(void *Data, int Count, ml_value_t **Args) {
return MLNil;
}

ml_value_t *rabs_chdir(void *Data, int Count, ml_value_t **Args) {
ML_CHECK_ARG_COUNT(1);
ml_stringbuffer_t Buffer[1] = {ML_STRINGBUFFER_INIT};
for (int I = 0; I < Count; ++I) {
ml_value_t *Result = ml_inline(AppendMethod, 2, Buffer, Args[I]);
if (Result->Type == MLErrorT) return Result;
}
if (CurrentDirectory) GC_free((void *)CurrentDirectory);
CurrentDirectory = ml_stringbuffer_get_uncollectable(Buffer);
return Args[0];
}

ml_value_t *rabs_open(void *Data, int Count, ml_value_t **Args) {
ML_CHECK_ARG_COUNT(2);
ml_stringbuffer_t Buffer[1] = {ML_STRINGBUFFER_INIT};
Expand Down Expand Up @@ -359,6 +373,7 @@ int main(int Argc, char **Argv) {
stringmap_insert(Globals, "execute", ml_function(0, execute));
stringmap_insert(Globals, "shell", ml_function(0, shell));
stringmap_insert(Globals, "mkdir", ml_function(0, rabs_mkdir));
stringmap_insert(Globals, "chdir", ml_function(0, rabs_chdir));
stringmap_insert(Globals, "scope", ml_function(0, scope));
stringmap_insert(Globals, "print", ml_function(0, print));
stringmap_insert(Globals, "open", ml_function(0, rabs_open));
Expand All @@ -383,18 +398,16 @@ int main(int Argc, char **Argv) {
case 'h': {
printf("Usage: %s { options } [ target ]\n", Argv[0]);
puts(" -h display this message");
puts(" -v print version and exit");
puts(" -Dkey[=value] add a define");
puts(" -c print shell commands");
puts(" -q target print dependencies for target");
puts(" -l lists all targets");
puts(" -p n run n threads");
puts(" -w watch for file changes");
exit(0);
break;
}
case 'v': {
printf("rabs version %s\n", VERSION_STRING);
exit(0);
break;
}
case 'D': {
char *Define = concat(Argv[I] + 2, NULL);
Expand Down Expand Up @@ -456,6 +469,7 @@ int main(int Argc, char **Argv) {
char *Path = snew(1024);
getcwd(Path, 1024);
#endif
CurrentDirectory = Path;
RootPath = find_root(Path);
if (!RootPath) {
puts("\e[31mError: could not find project root\e[0m");
Expand All @@ -478,7 +492,7 @@ int main(int Argc, char **Argv) {
target_t *Target;
if (TargetName) {
int HasPrefix = !strncmp(TargetName, "meta:", strlen("meta:"));
HasPrefix |= !strncmp(TargetName, "meta:", strlen("file:"));
HasPrefix |= !strncmp(TargetName, "file:", strlen("file:"));
if (!HasPrefix) {
TargetName = concat("meta:", match_prefix(Path, RootPath), "::", TargetName, NULL);
}
Expand All @@ -495,20 +509,14 @@ int main(int Argc, char **Argv) {
}
Target = Context->Default;
}
if (ListTargets) {
target_list();
} else if (QueryOnly) {
target_query(Target);
} else {
target_update(Target);
target_threads_wait(NumThreads);
if (InteractiveMode) {
target_interactive_start(NumThreads);
ml_console(rabs_ml_global, Globals);
} else if (MonitorFiles) {
target_interactive_start(NumThreads);
targetwatch_wait();
}
target_update(Target);
target_threads_wait(NumThreads);
if (InteractiveMode) {
target_interactive_start(NumThreads);
ml_console(rabs_ml_global, Globals);
} else if (MonitorFiles) {
target_interactive_start(NumThreads);
targetwatch_wait();
}
return 0;
}
2 changes: 1 addition & 1 deletion rabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "minilang.h"

extern const char *RootPath, *SystemName;
extern __thread const char *CurrentPath;
extern __thread const char *CurrentDirectory;
void restart();

#endif
Loading

0 comments on commit 4c1162e

Please sign in to comment.