Skip to content

Commit d6e7245

Browse files
committed
vec concrete属性的的自动调整
1 parent 19b581c commit d6e7245

Some content is hidden

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

73 files changed

+384
-1090
lines changed

ResourceIDGenerator.jar

-120 Bytes
Binary file not shown.

src/main/antlr/mcfppParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ genericClassImplement
140140

141141
//数据模板
142142
templateDeclaration
143-
: FINAL? OBJECT? DATA classWithoutNamespace (COLON className)? templateBody
143+
: FINAL? DATA classWithoutNamespace (COLON className)? templateBody
144144
;
145145

146146
//数据模板
@@ -497,6 +497,7 @@ expressionList
497497

498498
type
499499
: normalType
500+
| VecType
500501
| LIST '<' type '>'
501502
| className readOnlyArgs?
502503
| Identifier
@@ -513,7 +514,6 @@ normalType
513514
| NBT
514515
| TYPE
515516
| ANY
516-
| VecType //向量
517517
| MAP
518518
| DICT
519519
;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import java.util.UUID;
1313

1414
public class MCAnyData {
15-
@MNIRegister(normalParams = {"any a"}, returnType = "JavaVar")
16-
public static void getJavaVar(@NotNull Var<?> value, ValueWrapper<Var<?>> returnValue){
17-
var re = new JavaVar(value, UUID.randomUUID().toString());
15+
@MNIRegister(caller = "any", returnType = "JavaVar")
16+
public static void getJavaVar(@NotNull Var<?> caller, ValueWrapper<Var<?>> returnValue){
17+
var re = new JavaVar(caller, UUID.randomUUID().toString());
1818
returnValue.setValue(re);
1919
}
2020

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import top.mcfpp.lang.type.MCFPPType
1111
import top.mcfpp.lang.value.MCFPPValue
1212
import top.mcfpp.model.CanSelectMember
1313
import top.mcfpp.model.Class
14-
import top.mcfpp.model.CompoundDataCompanion
1514
import top.mcfpp.model.Namespace
1615
import top.mcfpp.model.field.GlobalField
1716
import top.mcfpp.model.function.Function
@@ -415,28 +414,8 @@ class McfppExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
415414
currSelector = visit(ctx.primary())
416415
}
417416
if(currSelector is UnknownVar){
418-
if(ctx.primary() != null || ctx.type().className() != null){
419-
namespaceID = if(ctx.primary() != null){
420-
null to ctx.primary().text
421-
} else{
422-
StringHelper.splitNamespaceID(ctx.type().text)
423-
}
424-
val o = GlobalField.getObject(namespaceID.first, namespaceID.second)
425-
if(o != null) {
426-
currSelector = o.getType()
427-
} else{
428-
LogProcessor.error("Undefined type: ${namespaceID.second}")
429-
currSelector = UnknownVar("${ctx.type().className().text}_type_" + UUID.randomUUID())
430-
}
431-
}else{
432-
currSelector = CompoundDataCompanion(
433-
//基本类型
434-
when(ctx.type().text){
435-
"int" -> MCInt.data
436-
else -> TODO()
437-
}
438-
)
439-
}
417+
val type = MCFPPType.parseFromIdentifier(ctx.type().text, Function.currFunction.field)
418+
currSelector = type
440419
}
441420
for (selector in ctx.selector()){
442421
visit(selector)

src/main/kotlin/top/mcfpp/command/Commands.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package top.mcfpp.command
33
import net.querz.nbt.io.SNBTUtil
44
import net.querz.nbt.tag.Tag
55
import top.mcfpp.Project
6-
import top.mcfpp.lang.*
7-
import top.mcfpp.lang.type.MCFPPClassType
6+
import top.mcfpp.lang.ClassPointer
7+
import top.mcfpp.lang.MCInt
88
import top.mcfpp.lib.NBTPath
99
import top.mcfpp.model.CanSelectMember
10+
import top.mcfpp.model.ObjectClass
1011
import top.mcfpp.model.function.Function
1112
import top.mcfpp.model.function.NoStackFunction
1213
import java.util.*
@@ -111,8 +112,8 @@ object Commands {
111112
Command.build("execute as ${ClassPointer.tempItemEntityUUID} on origin").build("run","run").build(command)
112113
)
113114
}
114-
is MCFPPClassType -> {
115-
arrayOf(Command.build("execute as ${a.cls.uuid} run").build(command))
115+
is ObjectClass -> {
116+
arrayOf(Command.build("execute as ${a.uuid} run").build(command))
116117
}
117118
else -> TODO()
118119
}
@@ -127,8 +128,8 @@ object Commands {
127128
Command.build("execute as ${ClassPointer.tempItemEntityUUID} on origin").build("run","run")
128129
)
129130
}
130-
is MCFPPClassType -> {
131-
arrayOf(Command.build("execute as ${a.cls.uuid}").build("run","run"))
131+
is ObjectClass -> {
132+
arrayOf(Command.build("execute as ${a.uuid}").build("run","run"))
132133
}
133134
else -> TODO()
134135
}

src/main/kotlin/top/mcfpp/commandline/Main.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package top.mcfpp.commandline
33
import org.apache.logging.log4j.core.config.ConfigurationSource
44
import org.apache.logging.log4j.core.config.Configurator
55
import top.mcfpp.MCFPP
6-
import top.mcfpp.Project
7-
import top.mcfpp.io.LibReader
86
import top.mcfpp.lang.UnresolvedVar
97
import top.mcfpp.model.field.GlobalField
108
import top.mcfpp.util.UwU
@@ -19,10 +17,6 @@ fun main(){
1917
}catch (e:Exception){
2018
println("Failed to load log4j2.xml")
2119
}
22-
//导入基础库
23-
for (include in Project.config.stdLib) {
24-
LibReader.read(include)
25-
}
2620
for(namespace in GlobalField.libNamespaces.values){
2721
namespace.field.forEachClass { c ->
2822
run {
@@ -35,7 +29,6 @@ fun main(){
3529
}
3630
}
3731
GlobalField.init()
38-
GlobalField.importedLibNamespaces["mcfpp.sys"] = GlobalField.libNamespaces["mcfpp.sys"]
3932
println("MCFPP ${MCFPP.version} (${Instant.now()})")
4033
println("Tips: " + UwU.tip) //生成tips
4134
val compiler = LineCompiler()
@@ -44,9 +37,20 @@ fun main(){
4437
if(compiler.leftBraces == 0){
4538
print("> ")
4639
}
47-
when(val line = readln()){
40+
val line = readln()
41+
if(line.startsWith("get ")){
42+
val name = line.substring(4)
43+
val v = compiler.defaultFile.topFunction.field.getVar(name)
44+
if(v == null){
45+
println("No such variable")
46+
}else{
47+
println(v)
48+
}
49+
continue
50+
}
51+
when(line){
4852
"help" -> printHelp()
49-
"exit" -> return
53+
"quit" -> return
5054
"version" -> println("MCFPP ${MCFPP.version}")
5155
else -> {
5256
try {

src/main/kotlin/top/mcfpp/lang/DataTemplateObject.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import net.querz.nbt.io.SNBTUtil
44
import net.querz.nbt.tag.CompoundTag
55
import top.mcfpp.command.Command
66
import top.mcfpp.command.Commands
7-
import top.mcfpp.lang.type.MCFPPClassType
87
import top.mcfpp.lang.type.MCFPPDataTemplateType
98
import top.mcfpp.lang.type.MCFPPNBTType
109
import top.mcfpp.lang.type.MCFPPType
1110
import top.mcfpp.lang.value.MCFPPValue
1211
import top.mcfpp.model.DataTemplate
1312
import top.mcfpp.model.Member
13+
import top.mcfpp.model.ObjectClass
1414
import top.mcfpp.model.field.CompoundDataField
1515
import top.mcfpp.model.function.Function
1616
import top.mcfpp.model.function.UnknownFunction
@@ -68,7 +68,7 @@ open class DataTemplateObject : Var<DataTemplateObject> {
6868
}
6969

7070
is DataTemplateObjectConcrete -> {
71-
if (b.type.compoundData.canCastTo(this.templateType)) {
71+
if (b.type.objectData.canCastTo(this.templateType)) {
7272
this.assignMembers(b.value)
7373
return this
7474
} else {
@@ -276,8 +276,8 @@ class DataTemplateObjectConcrete: DataTemplateObject, MCFPPValue<CompoundTag>{
276276
is ClassPointer -> {
277277
Commands.selectRun(parent)
278278
}
279-
is MCFPPClassType -> {
280-
arrayOf(Command.build("execute as ${parent.cls.uuid} run "))
279+
is ObjectClass -> {
280+
arrayOf(Command.build("execute as ${parent.uuid} run "))
281281
}
282282
else -> TODO()
283283

src/main/kotlin/top/mcfpp/lang/EntityVar.kt

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ package top.mcfpp.lang
22

33
import net.querz.nbt.io.SNBTUtil
44
import net.querz.nbt.tag.IntArrayTag
5-
import net.querz.nbt.tag.Tag
6-
import top.mcfpp.Project
75
import top.mcfpp.command.Command
86
import top.mcfpp.command.Commands
9-
import top.mcfpp.exception.VariableConverseException
107
import top.mcfpp.lang.type.MCFPPBaseType.BaseEntity
11-
import top.mcfpp.lang.type.MCFPPBaseType
12-
import top.mcfpp.lang.type.MCFPPClassType
13-
import top.mcfpp.lang.type.MCFPPNBTType
148
import top.mcfpp.lang.type.MCFPPType
159
import top.mcfpp.lang.value.MCFPPValue
1610
import top.mcfpp.model.CompoundData
@@ -20,7 +14,7 @@ import top.mcfpp.model.function.Function
2014
import top.mcfpp.util.LogProcessor
2115
import top.mcfpp.util.TextTranslator
2216
import top.mcfpp.util.TextTranslator.translate
23-
import java.util.UUID
17+
import java.util.*
2418

2519

2620
/**
@@ -114,21 +108,8 @@ class EntityVarConcrete: EntityVar, MCFPPValue<IntArrayTag>{
114108
override fun toDynamic(replace: Boolean): Var<*> {
115109
val parent = parent
116110
if (parentClass() != null) {
117-
val cmd = when(parent){
118-
is ClassPointer -> {
119-
Commands.selectRun(parent)
120-
}
121-
is MCFPPClassType -> {
122-
arrayOf(Command.build("execute as ${parent.cls.uuid} run "))
123-
}
124-
else -> TODO()
125-
}
126-
if(cmd.size == 2){
127-
Function.addCommand(cmd[0])
128-
}
129-
Function.addCommand(cmd.last().build(
130-
"data modify entity @s data.${identifier} set value ${SNBTUtil.toSNBT(value)}")
131-
)
111+
val cmd = Commands.selectRun(parent!!, "data modify entity @s data.${identifier} set value ${SNBTUtil.toSNBT(value)}")
112+
Function.addCommands(cmd)
132113
} else {
133114
val cmd = Command.build("data modify")
134115
.build(nbtPath.toCommandPart())

src/main/kotlin/top/mcfpp/lang/EnumVar.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import top.mcfpp.command.Command
55
import top.mcfpp.command.Commands
66
import top.mcfpp.exception.VariableConverseException
77
import top.mcfpp.lang.type.MCFPPBaseType
8-
import top.mcfpp.lang.type.MCFPPClassType
98
import top.mcfpp.lang.type.MCFPPType
109
import top.mcfpp.lang.value.MCFPPValue
1110
import top.mcfpp.lib.SbObject
@@ -174,20 +173,9 @@ class EnumVarConcrete : EnumVar, MCFPPValue<Int>{
174173
//避免错误 Smart cast to 'ClassPointer' is impossible, because 'parent' is a mutable property that could have been changed by this time
175174
val parent = parent
176175

177-
if (parent != null) {
178-
val cmd = when(parent){
179-
is ClassPointer -> {
180-
Commands.selectRun(parent)
181-
}
182-
is MCFPPClassType -> {
183-
arrayOf(Command.build("execute as ${parent.cls.uuid} run "))
184-
}
185-
else -> TODO()
186-
}
187-
if(cmd.size == 2){
188-
Function.addCommand(cmd[0])
189-
}
190-
Function.addCommand(cmd.last().build("scoreboard players set @s ${SbObject.MCFPP_default} $value"))
176+
if (parentClass() != null) {
177+
val cmd = Commands.selectRun(parent!!, "scoreboard players set @s ${SbObject.MCFPP_default} $value")
178+
Function.addCommands(cmd)
191179
} else {
192180
val cmd = if (!isTemp)
193181
Command("execute store result").build(nbtPath.toCommandPart()).build("int 1 run ")

src/main/kotlin/top/mcfpp/lang/JsonText.kt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import net.querz.nbt.tag.CompoundTag
44
import top.mcfpp.command.Command
55
import top.mcfpp.command.Commands
66
import top.mcfpp.lang.type.MCFPPBaseType
7-
import top.mcfpp.lang.type.MCFPPClassType
87
import top.mcfpp.lang.type.MCFPPType
98
import top.mcfpp.lang.value.MCFPPValue
109
import top.mcfpp.lib.ChatComponent
@@ -151,23 +150,12 @@ class JsonTextConcrete : MCFPPValue<ChatComponent>, JsonText {
151150

152151
override fun toDynamic(replace: Boolean): Var<*> {
153152
val parent = parent
154-
if (parent != null) {
155-
val cmd = when(parent){
156-
is ClassPointer -> {
157-
Commands.selectRun(parent)
158-
}
159-
is MCFPPClassType -> {
160-
arrayOf(Command.build("execute as ${parent.cls.uuid} run "))
161-
}
162-
else -> TODO()
163-
}
164-
if(cmd.size == 2){
165-
Function.addCommand(cmd[0])
166-
}
167-
Function.addCommand(cmd.last().build(
168-
"data modify entity @s data.${identifier} set value ")
169-
.build(value.toCommandPart())
153+
if (parentClass() != null) {
154+
val cmd = Commands.selectRun(parent!!,
155+
Command("data modify entity @s data.${identifier} set value ")
156+
.build(value.toCommandPart())
170157
)
158+
Function.addCommands(cmd)
171159
} else {
172160
val cmd = Command.build("data modify")
173161
.build(nbtPath.toCommandPart())

0 commit comments

Comments
 (0)