Skip to content

Commit 542ecc2

Browse files
committed
修复编译问题,修复了文件命名空间不能正确识别的问题,修复了模板继承问题,修复了函数不能从父类选取的问题,修复了JsonText的类型错误的问题
1 parent 7af7774 commit 542ecc2

File tree

90 files changed

+510
-813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+510
-813
lines changed

.mclib

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
"namespaces":[
33
{
44
"id":"default",
5+
"functions":[
6+
7+
],
8+
"classes":[
9+
10+
],
11+
"template":[
12+
13+
],
14+
"enum":[
15+
16+
]
17+
},
18+
{
19+
"id":"test",
520
"functions":[
621
{
722
"id":"main",
@@ -16,81 +31,38 @@
1631
}
1732
],
1833
"classes":[
34+
35+
],
36+
"template":[
1937
{
2038
"id":"Test",
2139
"parents":[
22-
"mcfpp.lang:any"
40+
"mcfpp.lang:DataObject"
2341
],
2442
"field":{
2543
"vars":[
2644
{
27-
"id":"i",
45+
"id":"a",
2846
"type":"int"
29-
}
30-
],
31-
"functions":[
47+
},
3248
{
33-
"id":"_class_preinit_Test",
34-
"normalParams":[
35-
36-
],
37-
"returnType":"void",
38-
"isAbstract":false,
39-
"tags":[
40-
41-
]
49+
"id":"b",
50+
"type":"int"
4251
},
4352
{
44-
"id":"_init_test_0_lead",
45-
"normalParams":[
46-
47-
],
48-
"returnType":"void",
49-
"isAbstract":false,
50-
"tags":[
51-
52-
]
53-
}
54-
]
55-
},
56-
"constructors":[
57-
{
58-
"normalParams":[
59-
60-
]
61-
}
62-
]
63-
},
64-
{
65-
"id":"Test$",
66-
"parents":[
67-
"mcfpp.lang:any"
68-
],
69-
"field":{
70-
"vars":[
53+
"id":"c",
54+
"type":"int"
55+
},
7156
{
72-
"id":"id",
57+
"id":"d",
7358
"type":"int"
7459
}
7560
],
7661
"functions":[
77-
{
78-
"id":"_class_preinit_Test",
79-
"normalParams":[
80-
81-
],
82-
"returnType":"void",
83-
"isAbstract":false,
84-
"tags":[
85-
86-
]
87-
}
62+
8863
]
8964
}
9065
}
91-
],
92-
"template":[
93-
9466
],
9567
"enum":[
9668

mcfpp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"files": [
33
"src/main/mcfpp/**"
44
],
5+
"sourcePath": "src/main/mcfpp",
56
"description": "",
67
"namespace": "mcfpp",
78
"targetPath": "src/main/resources/lib",

src/main/antlr/mcfppParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ var
367367

368368
identifierSuffix
369369
: '[' conditionalExpression ']'
370+
| '[' Identifier '=' expression (',' basicExpression '=' expression)* ']'
370371
;
371372

372373
selector
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package top.mcfpp.mni;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import top.mcfpp.annotations.MNIRegister;
5+
import top.mcfpp.lang.DataTemplateObject;
6+
import top.mcfpp.lang.DataTemplateObjectConcrete;
7+
import top.mcfpp.lang.JsonTextConcrete;
8+
import top.mcfpp.lib.ListChatComponent;
9+
import top.mcfpp.lib.NBTChatComponent;
10+
import top.mcfpp.lib.PlainChatComponent;
11+
import top.mcfpp.util.ValueWrapper;
12+
13+
public class DataObjectData {
14+
15+
@MNIRegister(caller = "DataObject", returnType = "text", override = true)
16+
public static void toText(@NotNull DataTemplateObject caller, ValueWrapper<JsonTextConcrete> returnValue){
17+
var l = new ListChatComponent();
18+
if(caller instanceof DataTemplateObjectConcrete callerC){
19+
l.getComponents().add(new PlainChatComponent(callerC.getValue().valueToString()));
20+
}else {
21+
l.getComponents().add(new NBTChatComponent(caller.toNBTVar(), false, null));
22+
}
23+
returnValue.setValue(new JsonTextConcrete(l, "re"));
24+
}
25+
26+
}

src/main/java/top/mcfpp/mni/System.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.jetbrains.annotations.NotNull;
44
import top.mcfpp.annotations.InsertCommand;
55
import top.mcfpp.annotations.MNIRegister;
6+
import top.mcfpp.command.Command;
67
import top.mcfpp.lang.*;
78
import top.mcfpp.lib.ScoreChatComponent;
89
import top.mcfpp.model.function.Function;
@@ -19,6 +20,15 @@ public static void typeOf(@NotNull Var<?> value, ValueWrapper<MCFPPTypeVar> retu
1920
returnValue.setValue(re);
2021
}
2122

23+
@InsertCommand
24+
@MNIRegister(normalParams = {"text t"})
25+
public static void print(@NotNull JsonText text){
26+
if(text instanceof JsonTextConcrete textC){
27+
Function.Companion.addCommand(new Command("tellraw @a").build(textC.getValue().toCommandPart(), true));
28+
}else {
29+
//TODO
30+
}
31+
}
2232

2333
@InsertCommand
2434
@MNIRegister(normalParams = {"any a"})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
package top.mcfpp.mni.resource;
4+
5+
import top.mcfpp.annotations.MNIRegister;
6+
7+
public class FunctionIDConcreteData {
8+
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
package top.mcfpp.mni.resource;
3+
4+
import top.mcfpp.annotations.MNIRegister;
5+
6+
public class FunctionIDData {
7+
8+
}

src/main/kotlin/top/mcfpp/Project.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ object Project {
116116
//源代码根目录
117117
config.sourcePath = Path.of(jsonObject.getString("sourcePath")?: ".")
118118

119-
//代码文件
120-
config.files = ArrayList()
121-
val filesJson: JSONArray = jsonObject.getJSONArray("files")
122-
for (o in filesJson) {
123-
MCFPPFile.findFiles(o.toString()).forEach {
124-
config.files.add(MCFPPFile(it.toFile()))
125-
}
126-
}
127-
128119
//版本
129120
config.version = jsonObject.getString("version")?:"1.21"
130121

@@ -150,6 +141,15 @@ object Project {
150141
//是否生成数据包
151142
config.noDatapack = jsonObject.getBooleanValue("noDatapack")
152143

144+
//代码文件
145+
config.files = ArrayList()
146+
val filesJson: JSONArray = jsonObject.getJSONArray("files")
147+
for (o in filesJson) {
148+
MCFPPFile.findFiles(o.toString()).forEach {
149+
config.files.add(MCFPPFile(it.toFile()))
150+
}
151+
}
152+
153153
} catch (e: Exception) {
154154
LogProcessor.error("Error while reading project from file \"$path\"")
155155
e.printStackTrace()

src/main/kotlin/top/mcfpp/antlr/McfppExprVisitor.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
469469
//是范围
470470
val left = ctx.range().num1?.let { visit(it) }
471471
val right = ctx.range().num2?.let { visit(it) }
472-
if(left is MCNumber? && right is MCNumber?){
472+
if(left is MCNumber<*>? && right is MCNumber<*>?){
473473
if(left is MCFPPValue<*>? && right is MCFPPValue<*>?){
474474
val leftValue = left?.value.toString().toFloatOrNull()
475475
val rightValue = right?.value.toString().toFloatOrNull()
@@ -537,8 +537,14 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
537537
} else {
538538
if(re is Indexable<*>){
539539
for (value in ctx.identifierSuffix()) {
540-
val index = visit(value.conditionalExpression())!!
541-
re = (re as Indexable<*>).getByIndex(index)
540+
if(value.conditionalExpression() != null){
541+
//索引
542+
val index = visit(value.conditionalExpression())!!
543+
re = (re as Indexable<*>).getByIndex(index)
544+
}else{
545+
//初始化
546+
TODO()
547+
}
542548
}
543549
}else{
544550
throw IllegalArgumentException("Cannot index ${re.type}")
@@ -554,7 +560,7 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
554560
v.storeToStack()
555561
}
556562
//函数的调用
557-
Function.addCommand("#" + ctx.text)
563+
Function.addComment(ctx.text)
558564
//参数获取
559565
val normalArgs: ArrayList<Var<*>> = ArrayList()
560566
val readOnlyArgs: ArrayList<Var<*>> = ArrayList()
@@ -588,8 +594,8 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
588594
}
589595
//可能是构造函数
590596
if (cls == null) {
591-
LogProcessor.error("Function ${func.identifier}<${readOnlyArgs.map { it.type.typeName }.joinToString(",")}>(${normalArgs.map { it.type.typeName }.joinToString(",")}) not defined")
592-
Function.addCommand("[Failed to Compile]${ctx.text}")
597+
LogProcessor.error("Function ${func.identifier}<${readOnlyArgs.joinToString(",") { it.type.typeName }}>(${normalArgs.map { it.type.typeName }.joinToString(",")}) not defined")
598+
Function.addComment("[Failed to Compile]${ctx.text}")
593599
func.invoke(normalArgs,currSelector)
594600
return func.returnVar
595601
}
@@ -612,10 +618,10 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
612618
//获取对象
613619
val ptr = cls.newInstance()
614620
//调用构造函数
615-
val constructor = cls.getConstructor(FunctionParam.getArgTypeNames(normalArgs))
621+
val constructor = cls.getConstructorByString(FunctionParam.getArgTypeNames(normalArgs))
616622
if (constructor == null) {
617623
LogProcessor.error("No constructor like: " + FunctionParam.getArgTypeNames(normalArgs) + " defined in class " + ctx.namespaceID().text)
618-
Function.addCommand("[Failed to compile]${ctx.text}")
624+
Function.addComment("[Failed to compile]${ctx.text}")
619625
}else{
620626
constructor.invoke(normalArgs, callerClassP = ptr)
621627
}

0 commit comments

Comments
 (0)