From 3ca74ec614ddf5b0e31b45a3e971d9fba35e236e Mon Sep 17 00:00:00 2001 From: Carbonhell Date: Wed, 23 Jan 2019 12:54:12 +0100 Subject: [PATCH 1/2] Adds support for static dm libraries --- MoMMI/Modules/CodeHandling/StaticLibs/util.dm | 111 ++++++++++++++++++ MoMMI/Modules/CodeHandling/dm.py | 5 + 2 files changed, 116 insertions(+) create mode 100644 MoMMI/Modules/CodeHandling/StaticLibs/util.dm diff --git a/MoMMI/Modules/CodeHandling/StaticLibs/util.dm b/MoMMI/Modules/CodeHandling/StaticLibs/util.dm new file mode 100644 index 0000000..580e7d0 --- /dev/null +++ b/MoMMI/Modules/CodeHandling/StaticLibs/util.dm @@ -0,0 +1,111 @@ + +#define ceil(x) (-round(-(x))) +#define floor(x) round(x) +#define clamp(x, low, high) max((low),min((high),(x))) + +#define BENCH(NAME, ITERS, CODE) \ + do{ \ + var/s = world.timeofday ;\ + for(var/i = 1 to (ITERS)) {\ + CODE ;\ + } ;\ + var/e = world.timeofday ;\ + world.log << "[NAME]: [e-s] ds" ;\ + } while(0) +#define BENCHK(NAME, ITERS, CODE) \ + do{ \ + var/s = world.timeofday ;\ + for(var/j = 1 to 1000) {\ + for(var/i = 1 to (ITERS)) {\ + CODE ;\ + } ;\ + } ;\ + var/e = world.timeofday ;\ + world.log << "[NAME]: [e-s] ds" ;\ + } while(0) +#define BENCHM(NAME, ITERS, CODE) \ + do{ \ + var/s = world.timeofday ;\ + for(var/j = 1 to 1000000) {\ + for(var/i = 1 to (ITERS)) {\ + CODE ;\ + } ;\ + } ;\ + var/e = world.timeofday ;\ + world.log << "[NAME]: [e-s] ds" ;\ + } while(0) + +/proc/ffold() return ffoldl(arglist(args)) +/proc/ffoldl(proc, list/L, initial=L) + var/x = initial + var/start = 1 + if(x == L) + x = L[1] + start = 2 + + for(var/i = start to L.len) + x = call(proc)(x, L[i]) + + return x + +/proc/ffoldr(proc, list/L, initial=L) + var/x = initial + var/start = L.len + if(x == L) + x = L[L.len] + start = L.len - 1 + + for(var/i = start to 1 step -1) + x = call(proc)(x, L[i]) + + return x + +/proc/fmap(proc, list/L) + for(var/x = 1 to L.len) + L[x] = call(proc)(L[x]) + return L + +/proc/ffilter(proc, list/L) + var/x = 1 + while(x <= L.len) + if(call(proc)(L[x])) + x++ + else + L.Cut(x, x+1) + return L + +/proc/stars(n, pr) + if (pr == null) + pr = 25 + if (pr < 0) + return null + else + if (pr >= 100) + return n + var/te = n + var/t = "" + n = length(n) + var/p = null + p = 1 + var/intag = 0 + while(p <= n) + var/char = copytext(te, p, p + 1) + if (char == "<") //let's try to not break tags + intag = !intag + if (intag || char == " " || prob(pr)) + t = text("[][]", t, char) + else + t = text("[]*", t) + if (char == ">") + intag = !intag + p++ + return t + +/proc/seq(lo, hi, st=1) + if(isnull(hi)) + hi = lo + lo = 1 + + . = list() + for(var/x in lo to hi step st) + . += x \ No newline at end of file diff --git a/MoMMI/Modules/CodeHandling/dm.py b/MoMMI/Modules/CodeHandling/dm.py index dde9700..a722ac6 100644 --- a/MoMMI/Modules/CodeHandling/dm.py +++ b/MoMMI/Modules/CodeHandling/dm.py @@ -60,6 +60,7 @@ async def make_project(self, code: str, path: Path) -> Path: output = "" if code.find("/proc/main") == -1: + libsDir = Path(os.path.realpath(__file__)) / 'StaticLibs' # Create a global variable and make it new the dummy type, so it instantly executes on world start. output = "var/a/b=new\n/a/New()\n" # Indent each line by one so we can put it as a datum's New().s @@ -68,6 +69,10 @@ async def make_project(self, code: str, path: Path) -> Path: continue lines[index] = "\t" + line + if line.find('#include "'): + library = line[10:-1]; # Fetch the library name within the "" + libToCopy = libsDir.glob(library+".dm") + copyfile(libToCopy, path/library".dm") output += "\n".join(lines) From ef64d48248b99764f1a4cebaf34db5a34bf31733 Mon Sep 17 00:00:00 2001 From: Carbonhell Date: Wed, 23 Jan 2019 14:38:06 +0100 Subject: [PATCH 2/2] Fixes typo --- MoMMI/Modules/CodeHandling/dm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MoMMI/Modules/CodeHandling/dm.py b/MoMMI/Modules/CodeHandling/dm.py index a722ac6..da6d119 100644 --- a/MoMMI/Modules/CodeHandling/dm.py +++ b/MoMMI/Modules/CodeHandling/dm.py @@ -72,7 +72,7 @@ async def make_project(self, code: str, path: Path) -> Path: if line.find('#include "'): library = line[10:-1]; # Fetch the library name within the "" libToCopy = libsDir.glob(library+".dm") - copyfile(libToCopy, path/library".dm") + copyfile(libToCopy, path/library+".dm") output += "\n".join(lines)