Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
MythicCraft
MEG MoLang Extension
Commits
555dc5dd
Commit
555dc5dd
authored
2 years ago
by
Ticxo
Browse files
Options
Download
Email Patches
Plain Diff
Directly move everything to this repo
parent
2ff9eb39
Changes
93
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1271 additions
and
25 deletions
+1271
-25
.gitignore
.gitignore
+1
-1
LICENSE
LICENSE
+674
-0
pom.xml
pom.xml
+0
-24
src/main/java/com/bedrockk/molang/ExprFinder.java
src/main/java/com/bedrockk/molang/ExprFinder.java
+30
-0
src/main/java/com/bedrockk/molang/ExprTraverser.java
src/main/java/com/bedrockk/molang/ExprTraverser.java
+187
-0
src/main/java/com/bedrockk/molang/ExprVisitor.java
src/main/java/com/bedrockk/molang/ExprVisitor.java
+20
-0
src/main/java/com/bedrockk/molang/Expression.java
src/main/java/com/bedrockk/molang/Expression.java
+23
-0
src/main/java/com/bedrockk/molang/MoLang.java
src/main/java/com/bedrockk/molang/MoLang.java
+51
-0
src/main/java/com/bedrockk/molang/ast/ArrayAccessExpression.java
...n/java/com/bedrockk/molang/ast/ArrayAccessExpression.java
+28
-0
src/main/java/com/bedrockk/molang/ast/AssignExpression.java
src/main/java/com/bedrockk/molang/ast/AssignExpression.java
+21
-0
src/main/java/com/bedrockk/molang/ast/BinaryOpExpression.java
...main/java/com/bedrockk/molang/ast/BinaryOpExpression.java
+15
-0
src/main/java/com/bedrockk/molang/ast/BooleanExpression.java
src/main/java/com/bedrockk/molang/ast/BooleanExpression.java
+19
-0
src/main/java/com/bedrockk/molang/ast/BooleanNotExpression.java
...in/java/com/bedrockk/molang/ast/BooleanNotExpression.java
+19
-0
src/main/java/com/bedrockk/molang/ast/BreakExpression.java
src/main/java/com/bedrockk/molang/ast/BreakExpression.java
+18
-0
src/main/java/com/bedrockk/molang/ast/ContinueExpression.java
...main/java/com/bedrockk/molang/ast/ContinueExpression.java
+18
-0
src/main/java/com/bedrockk/molang/ast/ForEachExpression.java
src/main/java/com/bedrockk/molang/ast/ForEachExpression.java
+42
-0
src/main/java/com/bedrockk/molang/ast/FuncCallExpression.java
...main/java/com/bedrockk/molang/ast/FuncCallExpression.java
+29
-0
src/main/java/com/bedrockk/molang/ast/LoopExpression.java
src/main/java/com/bedrockk/molang/ast/LoopExpression.java
+34
-0
src/main/java/com/bedrockk/molang/ast/NameExpression.java
src/main/java/com/bedrockk/molang/ast/NameExpression.java
+23
-0
src/main/java/com/bedrockk/molang/ast/NumberExpression.java
src/main/java/com/bedrockk/molang/ast/NumberExpression.java
+19
-0
No files found.
.gitignore
View file @
555dc5dd
...
...
@@ -32,7 +32,7 @@ replay_pid*
# Intellij
/.idea
/out
*/
target
target
# Server
server-*/
...
...
This diff is collapsed.
Click to expand it.
LICENSE
0 → 100644
View file @
555dc5dd
This diff is collapsed.
Click to expand it.
pom.xml
View file @
555dc5dd
...
...
@@ -21,23 +21,6 @@
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.0
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
3.3.1-SNAPSHOT
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<minimizeJar>
true
</minimizeJar>
<createDependencyReducedPom>
false
</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
...
...
@@ -88,13 +71,6 @@
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
com.bedrockk
</groupId>
<artifactId>
molang
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
<!-- Spigot -->
<dependency>
<groupId>
org.spigotmc
</groupId>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ExprFinder.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang
;
import
com.bedrockk.molang.visitor.FindingVisitor
;
import
com.bedrockk.molang.visitor.FirstFindingVisitor
;
import
java.util.List
;
import
java.util.function.Predicate
;
public
class
ExprFinder
{
public
static
List
<
Expression
>
find
(
List
<
Expression
>
expressions
,
Predicate
<
Expression
>
predicate
)
{
ExprTraverser
traverser
=
new
ExprTraverser
();
FindingVisitor
visitor
=
new
FindingVisitor
(
predicate
);
traverser
.
getVisitors
().
add
(
visitor
);
traverser
.
traverse
(
expressions
);
return
visitor
.
getFoundExpressions
();
}
public
static
Expression
findFirst
(
List
<
Expression
>
expressions
,
Predicate
<
Expression
>
predicate
)
{
ExprTraverser
traverser
=
new
ExprTraverser
();
FirstFindingVisitor
visitor
=
new
FirstFindingVisitor
(
predicate
);
traverser
.
getVisitors
().
add
(
visitor
);
traverser
.
traverse
(
expressions
);
return
visitor
.
getFound
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ExprTraverser.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang
;
import
lombok.Getter
;
import
lombok.NonNull
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.List
;
@Getter
public
class
ExprTraverser
{
private
boolean
stopTraversal
=
false
;
private
final
List
<
ExprVisitor
>
visitors
=
new
LinkedList
<>();
public
void
traverse
(
List
<
Expression
>
expressions
)
{
for
(
ExprVisitor
visitor
:
visitors
)
{
visitor
.
beforeTraverse
(
expressions
);
}
stopTraversal
=
false
;
traverseArray
(
expressions
);
for
(
ExprVisitor
visitor
:
visitors
)
{
visitor
.
afterTraverse
(
expressions
);
}
}
private
void
traverseArray
(
List
<
Expression
>
expressions
)
{
List
<
Expression
>
list
=
new
ArrayList
<>(
expressions
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Expression
expression
=
list
.
get
(
i
);
boolean
removeCurrent
=
false
;
boolean
traverseChildren
=
true
;
boolean
traverseCurrent
=
true
;
for
(
ExprVisitor
visitor
:
visitors
)
{
Object
result
=
visitor
.
onVisit
(
expression
);
if
(
result
instanceof
ActionType
)
{
switch
((
ActionType
)
result
)
{
case
REMOVE_CURRENT:
removeCurrent
=
true
;
break
;
case
STOP_TRAVERSAL:
stopTraversal
=
true
;
break
;
case
DONT_TRAVERSE_CURRENT_AND_CHILDREN:
traverseCurrent
=
false
;
case
DONT_TRAVERSE_CHILDREN:
traverseChildren
=
false
;
break
;
}
}
else
if
(
result
instanceof
Expression
)
{
expression
=
(
Expression
)
result
;
}
}
if
(!
traverseCurrent
)
{
break
;
}
else
if
(
traverseChildren
&&
!
removeCurrent
)
{
traverseExpr
(
expression
);
}
for
(
ExprVisitor
visitor
:
visitors
)
{
visitor
.
onLeave
(
expression
);
}
if
(
removeCurrent
)
{
expressions
.
remove
(
i
);
}
else
{
expressions
.
set
(
i
,
expression
);
}
if
(
stopTraversal
)
{
break
;
}
}
}
private
void
traverseExpr
(
@NonNull
Expression
expression
)
{
for
(
Field
field
:
getAllFields
(
expression
.
getClass
()))
{
field
.
setAccessible
(
true
);
Object
fieldValue
=
getFieldValue
(
field
,
expression
);
if
(
fieldValue
instanceof
Expression
subExpr
)
{
boolean
removeCurrent
=
false
;
boolean
traverseChildren
=
true
;
boolean
traverseCurrent
=
true
;
for
(
ExprVisitor
visitor
:
visitors
)
{
Object
result
=
visitor
.
onVisit
(
subExpr
);
if
(
result
instanceof
ActionType
)
{
switch
((
ActionType
)
result
)
{
case
REMOVE_CURRENT:
removeCurrent
=
true
;
break
;
case
STOP_TRAVERSAL:
stopTraversal
=
true
;
break
;
case
DONT_TRAVERSE_CURRENT_AND_CHILDREN:
traverseCurrent
=
false
;
case
DONT_TRAVERSE_CHILDREN:
traverseChildren
=
false
;
break
;
}
}
else
if
(
result
instanceof
Expression
)
{
subExpr
=
(
Expression
)
result
;
}
}
if
(!
traverseCurrent
)
{
break
;
}
else
if
(
traverseChildren
&&
!
removeCurrent
)
{
traverseExpr
(
subExpr
);
}
for
(
ExprVisitor
visitor
:
visitors
)
{
visitor
.
onLeave
(
subExpr
);
}
if
(
removeCurrent
)
{
setFieldValue
(
field
,
expression
,
null
);
}
else
{
setFieldValue
(
field
,
expression
,
subExpr
);
}
if
(
stopTraversal
)
{
break
;
}
}
else
if
(
fieldValue
!=
null
&&
fieldValue
.
getClass
().
isArray
())
{
Object
[]
array
=
(
Object
[])
fieldValue
;
List
<
Expression
>
exprs
=
new
ArrayList
<>();
for
(
Object
i
:
array
)
{
if
(
i
instanceof
Expression
)
{
exprs
.
add
((
Expression
)
i
);
}
}
traverseArray
(
exprs
);
setFieldValue
(
field
,
expression
,
exprs
.
toArray
(
new
Expression
[
0
]));
}
}
}
public
static
List
<
Field
>
getAllFields
(
Class
<?>
type
)
{
List
<
Field
>
fields
=
new
ArrayList
<>();
for
(
Class
<?>
c
=
type
;
c
!=
null
;
c
=
c
.
getSuperclass
())
{
fields
.
addAll
(
Arrays
.
asList
(
c
.
getDeclaredFields
()));
}
return
fields
;
}
private
Object
getFieldValue
(
Field
field
,
Object
obj
)
{
try
{
return
field
.
get
(
obj
);
}
catch
(
Throwable
throwable
)
{
// noop
}
return
null
;
}
private
void
setFieldValue
(
Field
field
,
Object
obj
,
Object
value
)
{
try
{
field
.
set
(
obj
,
value
);
}
catch
(
Throwable
throwable
)
{
// noop
}
}
public
enum
ActionType
{
REMOVE_CURRENT
,
STOP_TRAVERSAL
,
DONT_TRAVERSE_CURRENT_AND_CHILDREN
,
DONT_TRAVERSE_CHILDREN
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ExprVisitor.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang
;
import
java.util.List
;
public
interface
ExprVisitor
{
default
void
beforeTraverse
(
List
<
Expression
>
expressions
)
{
// noop
}
Object
onVisit
(
Expression
expression
);
default
void
onLeave
(
Expression
expression
)
{
// noop
}
default
void
afterTraverse
(
List
<
Expression
>
expressions
)
{
// noop
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/Expression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
java.util.HashMap
;
import
java.util.Map
;
public
interface
Expression
{
Map
<
String
,
Object
>
attributes
=
new
HashMap
<>();
default
Map
<
String
,
Object
>
getAttributes
()
{
return
attributes
;
}
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
);
default
void
assign
(
MoScope
scope
,
MoLangEnvironment
environment
,
MoValue
value
)
{
throw
new
RuntimeException
(
"Cannot assign a value to "
+
this
.
getClass
());
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/MoLang.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang
;
import
com.bedrockk.molang.parser.MoLangParser
;
import
com.bedrockk.molang.parser.tokenizer.TokenIterator
;
import
com.bedrockk.molang.runtime.MoLangRuntime
;
import
com.bedrockk.molang.utils.FileUtils
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.List
;
public
class
MoLang
{
public
static
List
<
Expression
>
parse
(
String
code
)
{
return
(
createParser
(
code
)).
parse
();
}
public
static
List
<
Expression
>
parse
(
Path
path
)
{
return
(
createParser
(
path
)).
parse
();
}
public
static
List
<
Expression
>
parse
(
InputStream
stream
)
throws
IOException
{
return
(
createParser
(
stream
)).
parse
();
}
public
static
MoLangParser
createParser
(
String
code
)
{
return
new
MoLangParser
(
new
TokenIterator
(
code
));
}
public
static
MoLangParser
createParser
(
Path
path
)
{
byte
[]
fileBytes
;
try
{
fileBytes
=
Files
.
readAllBytes
(
path
);
}
catch
(
IOException
e
)
{
fileBytes
=
new
byte
[
0
];
}
return
new
MoLangParser
(
new
TokenIterator
(
new
String
(
fileBytes
,
StandardCharsets
.
UTF_8
)));
}
public
static
MoLangParser
createParser
(
InputStream
stream
)
throws
IOException
{
return
new
MoLangParser
(
new
TokenIterator
(
FileUtils
.
readFile
(
stream
)));
}
public
static
MoLangRuntime
createRuntime
()
{
return
new
MoLangRuntime
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/ArrayAccessExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
ArrayAccessExpression
implements
Expression
{
Expression
array
;
Expression
index
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
String
name
=
array
instanceof
NameExpression
?
((
NameExpression
)
array
).
getName
()
:
array
.
evaluate
(
scope
,
environment
).
asString
();
return
environment
.
getValue
(
name
+
"."
+
(
int
)
index
.
evaluate
(
scope
,
environment
).
asDouble
());
}
@Override
public
void
assign
(
MoScope
scope
,
MoLangEnvironment
environment
,
MoValue
value
)
{
String
name
=
array
instanceof
NameExpression
?
((
NameExpression
)
array
).
getName
()
:
array
.
evaluate
(
scope
,
environment
).
asString
();
environment
.
setValue
(
name
+
"."
+
(
int
)
index
.
evaluate
(
scope
,
environment
).
asDouble
(),
value
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/AssignExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
AssignExpression
implements
Expression
{
Expression
variable
;
Expression
expr
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
var
value
=
expr
.
evaluate
(
scope
,
environment
);
variable
.
assign
(
scope
,
environment
,
value
);
return
value
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/BinaryOpExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
@Getter
@RequiredArgsConstructor
abstract
public
class
BinaryOpExpression
implements
Expression
{
protected
final
Expression
left
;
protected
final
Expression
right
;
public
abstract
String
getSigil
();
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/BooleanExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
BooleanExpression
implements
Expression
{
boolean
value
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
return
new
DoubleValue
(
value
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/BooleanNotExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
BooleanNotExpression
implements
Expression
{
Expression
expression
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
return
expression
.
evaluate
(
scope
,
environment
).
equals
(
DoubleValue
.
ONE
)
?
DoubleValue
.
ZERO
:
DoubleValue
.
ONE
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/BreakExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
BreakExpression
implements
Expression
{
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
scope
.
setBreak
(
true
);
return
DoubleValue
.
ZERO
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/ContinueExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
ContinueExpression
implements
Expression
{
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
scope
.
setContinue
(
true
);
return
DoubleValue
.
ZERO
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/ForEachExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.struct.VariableStruct
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
import
java.util.ArrayList
;
@Value
public
class
ForEachExpression
implements
Expression
{
Expression
variable
;
Expression
array
;
Expression
body
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
MoValue
array
=
this
.
array
.
evaluate
(
scope
,
environment
);
if
(
array
instanceof
VariableStruct
)
{
VariableStruct
struct
=
(
VariableStruct
)
array
;
MoScope
scope2
=
new
MoScope
();
for
(
MoValue
value
:
new
ArrayList
<>(
struct
.
getMap
().
values
()))
{
variable
.
assign
(
scope2
,
environment
,
value
);
body
.
evaluate
(
scope2
,
environment
);
if
(
scope2
.
getReturnValue
()
!=
null
)
{
return
scope2
.
getReturnValue
();
}
else
if
(
scope2
.
isBreak
())
{
break
;
}
}
}
return
DoubleValue
.
ZERO
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/FuncCallExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoParams
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Value
public
class
FuncCallExpression
implements
Expression
{
Expression
name
;
Expression
[]
args
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
List
<
Expression
>
params
=
Arrays
.
asList
(
args
);
String
name
=
this
.
name
instanceof
NameExpression
?
((
NameExpression
)
this
.
name
).
getName
()
:
this
.
name
.
evaluate
(
scope
,
environment
).
asString
();
return
environment
.
getValue
(
name
,
new
MoParams
(
params
.
stream
().
map
(
e
->
e
.
evaluate
(
scope
,
environment
)).
collect
(
Collectors
.
toList
())
));
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/LoopExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
LoopExpression
implements
Expression
{
Expression
count
;
Expression
body
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
int
loop
=
(
int
)
count
.
evaluate
(
scope
,
environment
).
asDouble
();
MoScope
subScope
=
new
MoScope
();
while
(
loop
>
0
)
{
body
.
evaluate
(
subScope
,
environment
);
loop
--;
if
(
subScope
.
getReturnValue
()
!=
null
)
{
return
subScope
.
getReturnValue
();
}
else
if
(
subScope
.
isBreak
())
{
break
;
}
}
return
DoubleValue
.
ZERO
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/NameExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
NameExpression
implements
Expression
{
String
name
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
return
environment
.
getValue
(
name
);
}
@Override
public
void
assign
(
MoScope
scope
,
MoLangEnvironment
environment
,
MoValue
value
)
{
environment
.
setValue
(
name
,
value
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/bedrockk/molang/ast/NumberExpression.java
0 → 100644
View file @
555dc5dd
package
com.bedrockk.molang.ast
;
import
com.bedrockk.molang.Expression
;
import
com.bedrockk.molang.runtime.MoLangEnvironment
;
import
com.bedrockk.molang.runtime.MoScope
;
import
com.bedrockk.molang.runtime.value.DoubleValue
;
import
com.bedrockk.molang.runtime.value.MoValue
;
import
lombok.Value
;
@Value
public
class
NumberExpression
implements
Expression
{
double
number
;
@Override
public
MoValue
evaluate
(
MoScope
scope
,
MoLangEnvironment
environment
)
{
return
new
DoubleValue
(
number
);
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment