Telecomms Refactor & CodeMirror

This commit does the following:
 - A lot of shit I am really too tired to fucking write about
 - Absolute pathed telecomms scripting
 - Browser Datum traffic control
  - Absolutely lovely replacement for the fucking skin TCS window, using
    codemirror
 - CodeMirror integration for nanoUI
  - Sorta, I didn't work on this as much as I wanted to, because IT TOOK
    11 FUCKING HOURS TO GET THE BROWSER DATUM TO WORK
This commit is contained in:
Tigercat2000
2015-10-28 17:19:18 -07:00
parent f76109ca5c
commit c244a0fe15
38 changed files with 13973 additions and 2155 deletions
+61 -71
View File
@@ -12,128 +12,118 @@
Articles:
- <http://en.wikipedia.org/wiki/Abstract_syntax_tree>
*/
var
const
/*
Constants: Operator Precedence
OOP_OR - Logical or
OOP_AND - Logical and
OOP_BIT - Bitwise operations
OOP_EQUAL - Equality checks
OOP_COMPARE - Greater than, less then, etc
OOP_COMPARE - Greater than, less then, etc
OOP_ADD - Addition and subtraction
OOP_MULTIPLY - Multiplication and division
OOP_MULTIPLY - Multiplication and division
OOP_POW - Exponents
OOP_UNARY - Unary Operators
OOP_GROUP - Parentheses
*/
OOP_OR = 1 //||
OOP_AND = OOP_OR + 1 //&&
OOP_BIT = OOP_AND + 1 //&, |
OOP_EQUAL = OOP_BIT + 1 //==, !=
OOP_COMPARE = OOP_EQUAL + 1 //>, <, >=, <=
OOP_ADD = OOP_COMPARE + 1 //+, -
OOP_MULTIPLY= OOP_ADD + 1 //*, /, %
OOP_POW = OOP_MULTIPLY+ 1 //^
OOP_UNARY = OOP_POW + 1 //!
OOP_GROUP = OOP_UNARY + 1 //()
/var/const/OOP_OR = 1 //||
/var/const/OOP_AND = OOP_OR + 1 //&&
/var/const/OOP_BIT = OOP_AND + 1 //&, |
/var/const/OOP_EQUAL = OOP_BIT + 1 //==, !=
/var/const/OOP_COMPARE = OOP_EQUAL + 1 //>, <, >=, <=
/var/const/OOP_ADD = OOP_COMPARE + 1 //+, -
/var/const/OOP_MULTIPLY= OOP_ADD + 1 //*, /, %
/var/const/OOP_POW = OOP_MULTIPLY + 1 //^
/var/const/OOP_UNARY = OOP_POW + 1 //!
/var/const/OOP_GROUP = OOP_UNARY + 1 //()
/*
Class: node
*/
/node
proc
ToString()
return "[src.type]"
/datum/node/proc/ToString()
return "[src.type]"
/*
Class: identifier
*/
/node/identifier
var
id_name
/datum/node/identifier
var/id_name
New(id)
.=..()
src.id_name=id
/datum/node/identifier/New(id)
. = ..()
src.id_name = id
ToString()
return id_name
/datum/node/identifier/ToString()
return id_name
/*
Class: expression
*/
/node/expression
/datum/node/expression
/*
Class: operator
See <Binary Operators> and <Unary Operators> for subtypes.
*/
/node/expression/operator
var
node/expression/exp
tmp
name
precedence
/datum/node/expression/operator
var/datum/node/expression/exp
var/token = "" // Used when giving type mismatches.
var/tmp/name
var/tmp/precedence
New()
.=..()
if(!src.name) src.name="[src.type]"
/datum/node/expression/operator/New()
.=..()
if(!src.name)
src.name = "[src.type]"
ToString()
return "operator: [name]"
/datum/node/expression/operator/ToString()
return "operator: [name]"
/*
Class: FunctionCall
*/
/node/expression/FunctionCall
/datum/node/expression/FunctionCall
//Function calls can also be expressions or statements.
var
func_name
node/identifier/object
list/parameters=new
var/func_name
var/datum/node/identifier/object
var/list/parameters = list()
/*
Class: literal
*/
/node/expression/value/literal
var
value
/datum/node/expression/value/literal
var/value
New(value)
.=..()
src.value=value
/datum/node/expression/value/literal/New(value)
. = ..()
src.value = value
ToString()
return src.value
/datum/node/expression/value/literal/ToString()
return src.value
/*
Class: variable
*/
/node/expression/value/variable
var
node
object //Either a node/identifier or another node/expression/value/variable which points to the object
node/identifier
id
/datum/node/expression/value/variable
var/datum/node/object //Either a node/identifier or another node/expression/value/variable which points to the object
var/datum/node/identifier/id
New(ident)
.=..()
id=ident
if(istext(id))id=new(id)
/datum/node/expression/value/variable/New(ident)
. = ..()
id = ident
if(istext(id))
id = new(id)
ToString()
return src.id.ToString()
/datum/node/expression/value/variable/ToString()
return src.id.ToString()
/*
Class: reference
*/
/node/expression/value/reference
var
datum/value
/datum/node/expression/value/reference
var/datum/value
New(value)
.=..()
src.value=value
/datum/node/expression/value/reference/New(value)
. = ..()
src.value = value
ToString()
return "ref: [src.value] ([src.value.type])"
/datum/node/expression/value/reference/ToString()
return "ref: [src.value] ([src.value.type])"
+10 -13
View File
@@ -8,13 +8,11 @@
it is possible to have a function definition inside of any type of block (such as in an if statement or another function),
and not just in the global scope as in many languages.
*/
/node/BlockDefinition
var/list
statements = new
functions = new
initial_variables = new
/datum/node/BlockDefinition
var/list/statements = new
var/list/functions = new
var/list/initial_variables = new
proc
/*
Proc: SetVar
Defines a permanent variable. The variable will not be deleted when it goes out of scope.
@@ -26,8 +24,8 @@
See Also:
- <n_Interpreter.SetVar()>
*/
SetVar(name, value)
initial_variables[name]=value
/datum/node/BlockDefinition/proc/SetVar(name, value)
initial_variables[name] = value
/*
@@ -35,14 +33,13 @@
A block object representing the global scope.
*/
//
GlobalBlock
New()
initial_variables["null"]=null
return ..()
/datum/node/BlockDefinition/GlobalBlock/New()
initial_variables["null"] = null
return ..()
/*
Class: FunctionBlock
A block representing a function body.
*/
//
FunctionBlock
/datum/node/BlockDefinition/FunctionBlock
@@ -7,8 +7,8 @@
Class: binary
Represents a binary operator in the AST. A binary operator takes two operands (ie x and y) and returns a value.
*/
/node/expression/operator/binary
var/node/expression/exp2
/datum/node/expression/operator/binary
var/datum/node/expression/exp2
////////// Comparison Operators //////////
/*
@@ -16,159 +16,176 @@
Returns true if x = y.
*/
//
Equal
precedence=OOP_EQUAL
/datum/node/expression/operator/binary/Equal
token = "=="
precedence = OOP_EQUAL
/*
Class: NotEqual
Returns true if x and y aren't equal.
Class: NotEqual
Returns true if x and y aren't equal.
*/
//
NotEqual
precedence=OOP_EQUAL
/datum/node/expression/operator/binary/NotEqual
token = "!="
precedence = OOP_EQUAL
/*
Class: Greater
Returns true if x > y.
Class: Greater
Returns true if x > y.
*/
//
Greater
precedence=OOP_COMPARE
/datum/node/expression/operator/binary/Greater
token = ">"
precedence = OOP_COMPARE
/*
Class: Less
Returns true if x < y.
Class: Less
Returns true if x < y.
*/
//
Less
precedence=OOP_COMPARE
/datum/node/expression/operator/binary/Less
token = "<"
precedence = OOP_COMPARE
/*
Class: GreaterOrEqual
Returns true if x >= y.
Class: GreaterOrEqual
Returns true if x >= y.
*/
//
GreaterOrEqual
precedence=OOP_COMPARE
/datum/node/expression/operator/binary/GreaterOrEqual
token = ">="
precedence = OOP_COMPARE
/*
Class: LessOrEqual
Returns true if x <= y.
Class: LessOrEqual
Returns true if x <= y.
*/
//
LessOrEqual
precedence=OOP_COMPARE
/datum/node/expression/operator/binary/LessOrEqual
token = "<="
precedence = OOP_COMPARE
////////// Logical Operators //////////
/*
Class: LogicalAnd
Returns true if x and y are true.
Class: LogicalAnd
Returns true if x and y are true.
*/
//
LogicalAnd
precedence=OOP_AND
/datum/node/expression/operator/binary/LogicalAnd
token = "&&"
precedence = OOP_AND
/*
Class: LogicalOr
Returns true if x, y, or both are true.
Class: LogicalOr
Returns true if x, y, or both are true.
*/
//
LogicalOr
precedence=OOP_OR
/datum/node/expression/operator/binary/LogicalOr
token = "||"
precedence = OOP_OR
/*
Class: LogicalXor
Returns true if either x or y but not both are true.
Class: LogicalXor
Returns true if either x or y but not both are true.
*/
//
LogicalXor //Not implemented in nS
precedence=OOP_OR
/datum/node/expression/operator/binary/LogicalXor //Not implemented in nS
precedence = OOP_OR
////////// Bitwise Operators //////////
/*
Class: BitwiseAnd
Performs a bitwise and operation.
Class: BitwiseAnd
Performs a bitwise and operation.
Example:
011 & 110 = 010
Example:
011 & 110 = 010
*/
//
BitwiseAnd
precedence=OOP_BIT
/datum/node/expression/operator/binary/BitwiseAnd
token = "&"
precedence = OOP_BIT
/*
Class: BitwiseOr
Performs a bitwise or operation.
Class: BitwiseOr
Performs a bitwise or operation.
Example:
011 | 110 = 111
Example:
011 | 110 = 111
*/
//
BitwiseOr
precedence=OOP_BIT
/datum/node/expression/operator/binary/BitwiseOr
token = "|"
precedence = OOP_BIT
/*
Class: BitwiseXor
Performs a bitwise exclusive or operation.
Class: BitwiseXor
Performs a bitwise exclusive or operation.
Example:
011 xor 110 = 101
Example:
011 xor 110 = 101
*/
//
BitwiseXor
precedence=OOP_BIT
/datum/node/expression/operator/binary/BitwiseXor
token = "`"
precedence = OOP_BIT
////////// Arithmetic Operators //////////
/*
Class: Add
Returns the sum of x and y.
Class: Add
Returns the sum of x and y.
*/
//
Add
precedence=OOP_ADD
/datum/node/expression/operator/binary/Add
token = "+"
precedence = OOP_ADD
/*
Class: Subtract
Returns the difference of x and y.
Class: Subtract
Returns the difference of x and y.
*/
//
Subtract
precedence=OOP_ADD
/datum/node/expression/operator/binary/Subtract
token = "-"
precedence = OOP_ADD
/*
Class: Multiply
Returns the product of x and y.
Class: Multiply
Returns the product of x and y.
*/
//
Multiply
precedence=OOP_MULTIPLY
/datum/node/expression/operator/binary/Multiply
token = "*"
precedence = OOP_MULTIPLY
/*
Class: Divide
Returns the quotient of x and y.
Class: Divide
Returns the quotient of x and y.
*/
//
Divide
precedence=OOP_MULTIPLY
/datum/node/expression/operator/binary/Divide
token = "/"
precedence = OOP_MULTIPLY
/*
Class: Power
Returns x raised to the power of y.
Class: Power
Returns x raised to the power of y.
*/
//
Power
precedence=OOP_POW
/datum/node/expression/operator/binary/Power
token = "^"
precedence = OOP_POW
/*
Class: Modulo
Returns the remainder of x / y.
Class: Modulo
Returns the remainder of x / y.
*/
//
Modulo
precedence=OOP_MULTIPLY
/datum/node/expression/operator/binary/Modulo
token = "%"
precedence = OOP_MULTIPLY
@@ -5,8 +5,8 @@
Class: unary
Represents a unary operator in the AST. Unary operators take a single operand (referred to as x below) and return a value.
*/
/node/expression/operator/unary
precedence=OOP_UNARY
/datum/node/expression/operator/unary
precedence = OOP_UNARY
/*
Class: LogicalNot
@@ -16,8 +16,8 @@
!true = false and !false = true
*/
//
LogicalNot
name="logical not"
/datum/node/expression/operator/unary/LogicalNot
name = "logical not"
/*
Class: BitwiseNot
@@ -27,25 +27,25 @@
~10 (decimal 2) = 01 (decimal 1).
*/
//
BitwiseNot
name="bitwise not"
/datum/node/expression/operator/unary/BitwiseNot
name = "bitwise not"
/*
Class: Minus
Returns -x.
*/
//
Minus
name="minus"
/datum/node/expression/operator/unary/Minus
name = "minus"
/*
Class: group
A special unary operator representing a value in parentheses.
*/
//
group
precedence=OOP_GROUP
/datum/node/expression/operator/unary/group
precedence = OOP_GROUP
New(node/expression/exp)
src.exp=exp
return ..()
/datum/node/expression/operator/unary/New(var/datum/node/expression/exp)
src.exp = exp
return ..()
+60 -72
View File
@@ -5,118 +5,106 @@
Class: statement
An object representing a single instruction run by an interpreter.
*/
/node/statement
/datum/node/statement
/*
Class: FunctionCall
Represents a call to a function.
*/
//
FunctionCall
var
func_name
node/identifier/object
list/parameters=new
/datum/node/statement/FunctionCall
var/func_name
var/datum/node/identifier/object
var/list/parameters = new
/*
Class: FunctionDefinition
Defines a function.
Class: FunctionDefinition
Defines a function.
*/
//
FunctionDefinition
var
func_name
list/parameters=new
node/BlockDefinition/FunctionBlock/block
/datum/node/statement/FunctionDefinition
var/func_name
var/list/parameters = new
var/datum/node/BlockDefinition/FunctionBlock/block
/*
Class: VariableAssignment
Sets a variable in an accessible scope to the given value if one exists, otherwise initializes a new local variable to the given value.
Class: VariableAssignment
Sets a variable in an accessible scope to the given value if one exists, otherwise initializes a new local variable to the given value.
Notes:
If a variable with the same name exists in a higher block, the value will be assigned to it. If not,
a new variable is created in the current block. To force creation of a new variable, use <VariableDeclaration>.
Notes:
If a variable with the same name exists in a higher block, the value will be assigned to it. If not,
a new variable is created in the current block. To force creation of a new variable, use <VariableDeclaration>.
See Also:
- <VariableDeclaration>
See Also:
- <VariableDeclaration>
*/
//
VariableAssignment
var
node
identifier
object
var_name
expression/value
/datum/node/statement/VariableAssignment
var/datum/node/identifier/object
var/datum/node/identifier/var_name
var/datum/node/expression/value
/*
Class: VariableDeclaration
Intializes a local variable to a null value.
Class: VariableDeclaration
Intializes a local variable to a null value.
See Also:
- <VariableAssignment>
See Also:
- <VariableAssignment>
*/
//
VariableDeclaration
var
node
identifier
object
var_name
/datum/node/statement/VariableDeclaration
var/datum/node/identifier/object
var/datum/node/identifier/var_name
/*
Class: IfStatement
Class: IfStatement
*/
//
IfStatement
var
node
BlockDefinition
block
else_block //may be null
expression/cond
/datum/node/statement/IfStatement
var/skip = 0
var/datum/node/BlockDefinition/block
var/datum/node/BlockDefinition/else_block //may be null
var/datum/node/expression/cond
var/datum/node/statement/else_if
/datum/node/statement/IfStatement/ElseIf
/*
Class: WhileLoop
Loops while a given condition is true.
Class: WhileLoop
Loops while a given condition is true.
*/
//
WhileLoop
var
node
BlockDefinition/block
expression/cond
/datum/node/statement/WhileLoop
var/datum/node/BlockDefinition/block
var/datum/node/expression/cond
/*
Class: ForLoop
Loops while test is true, initializing a variable, increasing the variable
Class: ForLoop
Loops while test is true, initializing a variable, increasing the variable
*/
ForLoop
var
node
BlockDefinition/block
expression/test
expression/init
expression/increment
/datum/node/statement/ForLoop
var/datum/node/BlockDefinition/block
var/datum/node/expression/test
var/datum/node/expression/init
var/datum/node/expression/increment
/*
Class: BreakStatement
Ends a loop.
Class: BreakStatement
Ends a loop.
*/
//
BreakStatement
/datum/node/statement/BreakStatement
/*
Class: ContinueStatement
Skips to the next iteration of a loop.
Class: ContinueStatement
Skips to the next iteration of a loop.
*/
//
ContinueStatement
/datum/node/statement/ContinueStatement
/*
Class: ReturnStatement
Ends the function and returns a value.
Class: ReturnStatement
Ends the function and returns a value.
*/
//
ReturnStatement
var
node/expression/value
/datum/node/statement/ReturnStatement
var/datum/node/expression/value