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

@@ -18,4 +18,5 @@
#define VV_NEW_LIST "New List" #define VV_NEW_LIST "New List"
#define VV_NULL "NULL" #define VV_NULL "NULL"
#define VV_RESTORE_DEFAULT "Restore to Default" #define VV_RESTORE_DEFAULT "Restore to Default"
#define VV_MARKED_DATUM "Marked Datum" #define VV_MARKED_DATUM "Marked Datum"
#define VV_REGEX "Regex"

View File

@@ -546,6 +546,4 @@ proc/checkhtml(var/t)
text = replacetext(text, "</td><tr>", "\[row\]") text = replacetext(text, "</td><tr>", "\[row\]")
text = replacetext(text, "<td>", "\[cell\]") text = replacetext(text, "<td>", "\[cell\]")
text = replacetext(text, "<img src = ntlogo.png>", "\[logo\]") text = replacetext(text, "<img src = ntlogo.png>", "\[logo\]")
return text 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/totaltraffic = 0 // gigabytes (if > 1024, divide by 1024 -> terrabytes)
var/list/memory = list() // stored memory 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/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 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") relay_information(signal, "/obj/machinery/telecomms/broadcaster")
/obj/machinery/telecomms/server/proc/setcode(var/t) /obj/machinery/telecomms/server/proc/setcode(var/list/code)
if(t) if(istype(code))
if(istext(t)) rawcode = code
rawcode = t
/obj/machinery/telecomms/server/proc/compile(mob/user as mob) /obj/machinery/telecomms/server/proc/compile(mob/user as mob)
if(Compiler) 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) /obj/machinery/telecomms/server/proc/admin_log(var/mob/mob)
var/msg="[key_name(mob)] has compiled a script to server [src]:" var/msg="[key_name(mob)] has compiled a script to server [src]:"
diary << msg diary << msg
diary << rawcode diary << rawcode.Join("")
src.investigate_log("[msg]<br>[rawcode]", "ntsl") src.investigate_log("[msg]<br>[rawcode.Join("")]", "ntsl")
if(length(rawcode)) // Let's not bother the admins for empty code. 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>)") 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() { function compileCode() {
var codeText = cMirror_fSubmit.getValue(); var codeText = cMirror_fSubmit.getValue();
document.getElementById("cMirrorPost").value = codeText; document.getElementById("cMirrorPost").value = codeText;
document.getElementById("cMirrorPostList").value = JSON.stringify(codeText.split(''));
document.getElementById("theform").submit(); document.getElementById("theform").submit();
} }
@@ -135,6 +136,7 @@
<input type="hidden" name="choice" value="Compile"> <input type="hidden" name="choice" value="Compile">
<input type="hidden" name="src" value="[UID()]"> <input type="hidden" name="src" value="[UID()]">
<input type="hidden" id="cMirrorPost" name="cMirror" value=""> <input type="hidden" id="cMirrorPost" name="cMirror" value="">
<input type="hidden" id="cMirrorPostList" name="cMirrorList" value="">
</form> </form>
"} "}
else else
@@ -189,6 +191,10 @@
if(code) if(code)
storedcode = code storedcode = code
var/list/codelist = href_list["cMirrorList"]
if(istext(codelist))
codelist = json_decode(codelist)
add_fingerprint(user) add_fingerprint(user)
user.set_machine(src) user.set_machine(src)
@@ -198,14 +204,14 @@
switch(href_list["choice"]) switch(href_list["choice"])
if("Compile") if("Compile")
if(!code) if(!istype(codelist))
return 0 return 0
if(user != editingcode) if(user != editingcode)
return 0 //only one editor return 0 //only one editor
if(SelectedServer) if(SelectedServer)
var/obj/machinery/telecomms/server/Server = SelectedServer var/obj/machinery/telecomms/server/Server = SelectedServer
Server.setcode(code) Server.setcode(codelist)
spawn(0) spawn(0)
// Output all the compile-time errors // Output all the compile-time errors
@@ -234,7 +240,7 @@
updateUsrDialog() updateUsrDialog()
for(var/obj/machinery/telecomms/server/Server in servers) for(var/obj/machinery/telecomms/server/Server in servers)
Server.setcode(code) Server.setcode(codelist)
var/list/compileerrors = Server.compile(user) var/list/compileerrors = Server.compile(user)
if(!telecomms_check(user)) if(!telecomms_check(user))
return return

View File

@@ -46,6 +46,8 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
else if(isfile(var_value)) else if(isfile(var_value))
. = VV_FILE . = VV_FILE
else if(istype(var_value, /regex))
. = VV_REGEX
else else
. = VV_NULL . = VV_NULL
@@ -66,6 +68,7 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
VV_DATUM_TYPE, VV_DATUM_TYPE,
VV_TYPE, VV_TYPE,
VV_MATRIX, VV_MATRIX,
VV_REGEX,
VV_FILE, VV_FILE,
VV_NEW_ATOM, VV_NEW_ATOM,
VV_NEW_DATUM, VV_NEW_DATUM,
@@ -141,6 +144,14 @@ var/list/VVpixelmovement = list("step_x", "step_y", "step_size", "bound_height",
.["class"] = null .["class"] = null
return 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) if(VV_ATOM_REFERENCE)
var/type = pick_closest_path(FALSE) var/type = pick_closest_path(FALSE)

View File

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

View File

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