Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Adds support for static dm libraries #19

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions MoMMI/Modules/CodeHandling/StaticLibs/util.dm
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions MoMMI/Modules/CodeHandling/dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're gonna want to do Path(...).parent.

# 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
Expand All @@ -68,6 +69,10 @@ async def make_project(self, code: str, path: Path) -> Path:
continue

lines[index] = "\t" + line
if line.find('#include "'):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using regex and finditer so you can make the parsing easier and allow multiple files.

library = line[10:-1]; # Fetch the library name within the ""
libToCopy = libsDir.glob(library+".dm")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should sanitize to make sure the path is actually in there and there's no hackery with like ../

copyfile(libToCopy, path/library+".dm")

output += "\n".join(lines)

Expand Down