More optimizing

This commit is contained in:
tigercat2000
2018-04-05 15:29:08 -07:00
parent 354cf75cb7
commit c3c6c9caba
7 changed files with 54 additions and 41 deletions

View File

@@ -19,3 +19,4 @@
#define VV_NULL "NULL"
#define VV_RESTORE_DEFAULT "Restore to Default"
#define VV_MARKED_DATUM "Marked Datum"
#define VV_REGEX "Regex"

View File

@@ -547,5 +547,3 @@ proc/checkhtml(var/t)
text = replacetext(text, "<td>", "\[cell\]")
text = replacetext(text, "<img src = ntlogo.png>", "\[logo\]")
return text
#define string2charlist(string) (splittext(string, regex("(.)")) - splittext(string, ""))

View File

@@ -436,7 +436,7 @@ var/global/list/obj/machinery/telecomms/telecomms_list = list()
var/totaltraffic = 0 // gigabytes (if > 1024, divide by 1024 -> terrabytes)
var/list/memory = list() // stored memory
var/rawcode = "" // the code to compile (raw text)
var/list/rawcode = list() // the code to compile (list of characters)
var/datum/TCS_Compiler/Compiler // the compiler that compiles and runs the code
var/autoruncode = 0 // 1 if the code is set to run every time a signal is picked up
@@ -516,10 +516,9 @@ var/global/list/obj/machinery/telecomms/telecomms_list = list()
relay_information(signal, "/obj/machinery/telecomms/broadcaster")
/obj/machinery/telecomms/server/proc/setcode(var/t)
if(t)
if(istext(t))
rawcode = t
/obj/machinery/telecomms/server/proc/setcode(var/list/code)
if(istype(code))
rawcode = code
/obj/machinery/telecomms/server/proc/compile(mob/user as mob)
if(Compiler)
@@ -548,8 +547,8 @@ var/global/list/obj/machinery/telecomms/telecomms_list = list()
/obj/machinery/telecomms/server/proc/admin_log(var/mob/mob)
var/msg="[key_name(mob)] has compiled a script to server [src]:"
diary << msg
diary << rawcode
src.investigate_log("[msg]<br>[rawcode]", "ntsl")
diary << rawcode.Join("")
src.investigate_log("[msg]<br>[rawcode.Join("")]", "ntsl")
if(length(rawcode)) // Let's not bother the admins for empty code.
message_admins("[key_name_admin(mob)] has compiled and uploaded a NTSL script to [src.id] (<A HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[x];Y=[y];Z=[z]'>JMP</a>)")

View File

@@ -117,6 +117,7 @@
function compileCode() {
var codeText = cMirror_fSubmit.getValue();
document.getElementById("cMirrorPost").value = codeText;
document.getElementById("cMirrorPostList").value = JSON.stringify(codeText.split(''));
document.getElementById("theform").submit();
}
@@ -135,6 +136,7 @@
<input type="hidden" name="choice" value="Compile">
<input type="hidden" name="src" value="[UID()]">
<input type="hidden" id="cMirrorPost" name="cMirror" value="">
<input type="hidden" id="cMirrorPostList" name="cMirrorList" value="">
</form>
"}
else
@@ -189,6 +191,10 @@
if(code)
storedcode = code
var/list/codelist = href_list["cMirrorList"]
if(istext(codelist))
codelist = json_decode(codelist)
add_fingerprint(user)
user.set_machine(src)
@@ -198,14 +204,14 @@
switch(href_list["choice"])
if("Compile")
if(!code)
if(!istype(codelist))
return 0
if(user != editingcode)
return 0 //only one editor
if(SelectedServer)
var/obj/machinery/telecomms/server/Server = SelectedServer
Server.setcode(code)
Server.setcode(codelist)
spawn(0)
// Output all the compile-time errors
@@ -234,7 +240,7 @@
updateUsrDialog()
for(var/obj/machinery/telecomms/server/Server in servers)
Server.setcode(code)
Server.setcode(codelist)
var/list/compileerrors = Server.compile(user)
if(!telecomms_check(user))
return

View File

@@ -46,6 +46,8 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
else if(isfile(var_value))
. = VV_FILE
else if(istype(var_value, /regex))
. = VV_REGEX
else
. = VV_NULL
@@ -66,6 +68,7 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
VV_DATUM_TYPE,
VV_TYPE,
VV_MATRIX,
VV_REGEX,
VV_FILE,
VV_NEW_ATOM,
VV_NEW_DATUM,
@@ -141,6 +144,14 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
.["class"] = null
return
if(VV_REGEX)
var/reg = input("Enter regex", "Regex", "") as null|text
if(!reg)
return
.["value"] = regex(reg)
if(.["value"] == null)
.["class"] = null
if(VV_ATOM_REFERENCE)
var/type = pick_closest_path(FALSE)

View File

@@ -34,7 +34,7 @@
/* -- Compile a raw block of text -- */
/datum/TCS_Compiler/proc/Compile(code as message)
/datum/TCS_Compiler/proc/Compile(list/code)
options = new()
scanner = new(code, options)
tokens = scanner.Scan()

View File

@@ -6,8 +6,7 @@
An object responsible for breaking up source code into tokens for use by the parser.
*/
/datum/n_Scanner
var/code
var/list/charlist
var/list/code
/*
Var: errors
A list of fatal errors found by the scanner. If there are any items in this list, then it is not safe to parse the returned tokens.
@@ -26,9 +25,8 @@
Proc: LoadCode
Loads source code.
*/
/datum/n_Scanner/proc/LoadCode(var/c)
/datum/n_Scanner/proc/LoadCode(var/list/c)
code=c
charlist=string2charlist(code)
/*
Proc: LoadCodeFromFile
@@ -102,18 +100,18 @@
code - The source code to tokenize.
options - An <nS_Options> object used to configure the scanner.
*/
/datum/n_Scanner/nS_Scanner/New(var/code, var/datum/n_scriptOptions/nS_Options/options)
/datum/n_Scanner/nS_Scanner/New(var/list/c, var/datum/n_scriptOptions/nS_Options/options)
. = ..()
ignore += ascii2text(13) //Carriage return
delim += ignore + options.symbols + end_stmt + string_delim
src.options = options
LoadCode(code)
LoadCode(c)
/datum/n_Scanner/nS_Scanner/Scan() //Creates a list of tokens from source code
var/list/tokens = new
for(, src.codepos <= charlist.len, src.codepos++)
var/char = charlist[codepos]
var/nextchar = TCOMMS_SAFE_INDEX(charlist, codepos + 1)
for(, src.codepos <= code.len, src.codepos++)
var/char = code[codepos]
var/nextchar = TCOMMS_SAFE_INDEX(code, codepos + 1)
if(char == "\n")
line++
linepos = codepos
@@ -157,12 +155,12 @@
*/
/datum/n_Scanner/nS_Scanner/proc/ReadString(start)
var/buf
for(, codepos <= charlist.len, codepos++)//codepos to length(code))
var/char = charlist[codepos]
for(, codepos <= code.len, codepos++)//codepos to length(code))
var/char = code[codepos]
switch(char)
if("\\") //Backslash (\) encountered in string
codepos++ //Skip next character in string, since it was escaped by a backslash
char = TCOMMS_SAFE_INDEX(charlist, codepos)
char = TCOMMS_SAFE_INDEX(code, codepos)
switch(char)
if("\\") //Double backslash
buf += "\\"
@@ -192,13 +190,13 @@
Reads characters separated by an item in <delim> into a token.
*/
/datum/n_Scanner/nS_Scanner/proc/ReadWord()
var/char = charlist[codepos]
var/char = code[codepos]
var/buf
while(!delim.Find(char))
buf += char
if(++codepos > length(code)) break
char = charlist[codepos]
if(++codepos > code.len) break
char = code[codepos]
codepos-- //allow main Scan() proc to read the delimiter
if(options.keywords.Find(buf))
@@ -211,13 +209,13 @@
Reads a symbol into a token.
*/
/datum/n_Scanner/nS_Scanner/proc/ReadSymbol()
var/char = charlist[codepos]
var/char = code[codepos]
var/buf
while(options.symbols.Find(buf + char))
buf += char
if(++codepos > length(code)) break
char = charlist[codepos]
if(++codepos > code.len) break
char = code[codepos]
codepos-- //allow main Scan() proc to read the next character
return new /datum/token/symbol(buf, line, COL)
@@ -227,7 +225,7 @@
Reads a number into a token.
*/
/datum/n_Scanner/nS_Scanner/proc/ReadNumber()
var/char = charlist[codepos]
var/char = code[codepos]
var/buf
var/dec = 0
@@ -237,7 +235,7 @@
buf += char
codepos++
char = TCOMMS_SAFE_INDEX(charlist, codepos)
char = TCOMMS_SAFE_INDEX(code, codepos)
var/datum/token/number/T = new(buf, line, COL)
if(isnull(text2num(buf)))
@@ -253,8 +251,8 @@
*/
/datum/n_Scanner/nS_Scanner/proc/ReadComment()
var/char = charlist[codepos]
var/nextchar = TCOMMS_SAFE_INDEX(charlist, codepos + 1)
var/char = code[codepos]
var/nextchar = TCOMMS_SAFE_INDEX(code, codepos + 1)
var/charstring = char + nextchar
var/comm = 1
// 1: single-line comment
@@ -266,23 +264,23 @@
comm = 2 // starts a multi-line comment
while(comm)
if(++codepos > charlist.len)
if(++codepos > code.len)
break
if(expectedend) // ending statement expected...
char = charlist[codepos]
char = code[codepos]
if(char == "/") // ending statement found - beak the comment
comm = 0
break
if(comm == 2)
// multi-line comments are broken by ending statements
char = charlist[codepos]
char = code[codepos]
if(char == "*")
expectedend = 1
continue
else
char = charlist[codepos]
char = code[codepos]
if(char == "\n")
comm = 0
break