Last active
October 12, 2022 16:56
-
-
Save ookiineko/2fdf2a419c98a926d147f5805ba52468 to your computer and use it in GitHub Desktop.
MCC patches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 60a534a77528aedf4d0b4260a82adfa7b108bcdb Mon Sep 17 00:00:00 2001 | |
From: Ookiineko <chiisaineko@protonmail.com> | |
Date: Thu, 13 Oct 2022 00:55:17 +0800 | |
Subject: [PATCH] cbl: operator_mixins: fix typo | |
Signed-off-by: Ookiineko <chiisaineko@protonmail.com> | |
--- | |
cbl/operator_mixins.py | 2 +- | |
1 file changed, 1 insertion(+), 1 deletion(-) | |
diff --git a/cbl/operator_mixins.py b/cbl/operator_mixins.py | |
index a7be6a9..5a43375 100644 | |
--- a/cbl/operator_mixins.py | |
+++ b/cbl/operator_mixins.py | |
@@ -288,7 +288,7 @@ void OP(int src, int *dest) { | |
else: | |
two = self.new_temporary(compiler) | |
self.dispatch_operator(compiler, '=', two, LiteralInt(self, 2)) | |
- loop.add(i.DivScore(dest, as_var(rwo))) | |
+ loop.add(i.DivScore(dest, as_var(two))) | |
cnt = as_var(count) | |
loop.add(i.SubScore(cnt, 1)) | |
loop.add(i.RangeBr(cnt, 0, 0, None, loop)) | |
-- | |
2.38.0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From eb299a0ae8e63d3866c7c2d98fd7025e75b0511b Mon Sep 17 00:00:00 2001 | |
From: Ookiineko <chiisaineko@protonmail.com> | |
Date: Tue, 4 Oct 2022 19:30:32 +0800 | |
Subject: [PATCH] cmd_ir: inst: nbt: add nbt_modify_from_var | |
Signed-off-by: Ookiineko <chiisaineko@protonmail.com> | |
--- | |
cmd_ir/instructions/nbt.py | 30 ++++++++++++++++++++++++++++++ | |
1 file changed, 30 insertions(+) | |
diff --git a/cmd_ir/instructions/nbt.py b/cmd_ir/instructions/nbt.py | |
index bd433ea..2cd222b 100644 | |
--- a/cmd_ir/instructions/nbt.py | |
+++ b/cmd_ir/instructions/nbt.py | |
@@ -381,3 +381,33 @@ class NBTModifyVarFrom(SingleCommandInsn): | |
return c.DataModifyFrom(dest_storage, dest_path, self.action, | |
source, c.NbtPath(str(self.source_path))) | |
+ | |
+class NBTModifyFromVar(SingleCommandInsn): | |
+ """Similar to nbt_modify_from except modifies from an NBT variable.""" | |
+ | |
+ args = [(BlockRef, EntitySelection), VirtualString, str, Variable] | |
+ argnames = 'target target_path action var' | |
+ argdocs = ["Block or entity to modify", "NBT path to modify", "Action, " + \ | |
+ "one of: append|insert|merge|prepend|set", "Variable to modify from"] | |
+ insn_name = 'nbt_modify_from_var' | |
+ | |
+ def validate(self): | |
+ assert self.var.type is VarType.nbt | |
+ assert self.action in ['append', 'insert', 'merge', 'prepend', 'set'] | |
+ assert self.action != 'insert', "TODO" | |
+ | |
+ def declare(self): | |
+ self.var.usage_write() | |
+ | |
+ def get_cmd(self, func): | |
+ if isinstance(self.target, BlockRef): | |
+ target = self.target.as_cmdref() | |
+ elif isinstance(self.target, EntitySelection): | |
+ target = c.EntityReference(self.target.as_resolve()) | |
+ else: | |
+ assert False | |
+ direct = self.var._direct_nbt() | |
+ assert direct is not None, self.var | |
+ source_path, source = direct | |
+ return c.DataModifyFrom(target, c.NbtPath(str(self.target_path)), | |
+ self.action, source, source_path) | |
-- | |
2.37.3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a6bd4848dd10792b5b2668fd390275ca9fdc6cd3 Mon Sep 17 00:00:00 2001 | |
From: Ookiineko <chiisaineko@protonmail.com> | |
Date: Sat, 1 Oct 2022 22:12:17 +0800 | |
Subject: [PATCH 1/2] fix static linking | |
Signed-off-by: Ookiineko <chiisaineko@protonmail.com> | |
--- | |
asm/assembler.py | 2 +- | |
c_comp/asm_writer.py | 7 +++++-- | |
cbl/include/__builtin__Entity | 4 ++-- | |
3 files changed, 8 insertions(+), 5 deletions(-) | |
diff --git a/asm/assembler.py b/asm/assembler.py | |
index 557cfbc..899d3a8 100644 | |
--- a/asm/assembler.py | |
+++ b/asm/assembler.py | |
@@ -28,7 +28,7 @@ class Assembler: | |
self.func = self.top.get_or_create_func('sub_' + name) | |
self.func.preamble.add(ExternInsn()) | |
self.block = self.func.create_block('entry') | |
- if name == '__setup__': | |
+ if name.startswith('__setup__'): | |
self.top.preamble.add(SetupInsn(self.func)) | |
def _predef_const(self, name): | |
diff --git a/c_comp/asm_writer.py b/c_comp/asm_writer.py | |
index 2645c3e..4c36c1d 100644 | |
--- a/c_comp/asm_writer.py | |
+++ b/c_comp/asm_writer.py | |
@@ -1,3 +1,5 @@ | |
+from uuid import uuid4 | |
+ | |
from asm.asm_reader import AsmReader | |
class AsmStringBackend: | |
@@ -120,6 +122,7 @@ class AsmWriter: | |
self.backend_type = backend | |
self.sub = False | |
self._setup = [] | |
+ self._setup_func = '__setup__' + uuid4().hex | |
self.after_sub = [] | |
def fork(self): | |
@@ -150,7 +153,7 @@ class AsmWriter: | |
self.backend.write_entity_local(name, specific) | |
def write_subroutine(self, name): | |
- if name == '__setup__': | |
+ if name == self._setup_func: | |
return | |
self.sub = True | |
self.backend.write_label(name) | |
@@ -179,7 +182,7 @@ class AsmWriter: | |
def get_output(self): | |
assert not self.sub | |
if self._setup: | |
- self.backend.write_label('__setup__') | |
+ self.backend.write_label(self._setup_func) | |
for (insn, args, comment) in self._setup: | |
self.backend.write_instruction(insn, args, comment) | |
return self.backend.get_output() | |
diff --git a/cbl/include/__builtin__Entity b/cbl/include/__builtin__Entity | |
index f29f9f5..31a14db 100644 | |
--- a/cbl/include/__builtin__Entity | |
+++ b/cbl/include/__builtin__Entity | |
@@ -87,14 +87,14 @@ inline vec3d EntityPos::as_vec() { | |
return vec3d(this.x.decval, this.y.decval, this.z.decval); | |
} | |
-EntityPos EntityPos::operator +=(vec3i shift) { | |
+inline EntityPos EntityPos::operator +=(vec3i shift) { | |
this.x += shift.x; | |
this.y += shift.y; | |
this.z += shift.z; | |
return this; | |
} | |
-EntityPos EntityPos::operator =(vec3<decimal> pos) { | |
+inline EntityPos EntityPos::operator =(vec3<decimal> pos) { | |
this.x = pos.x; | |
this.y = pos.y; | |
this.z = pos.z; | |
-- | |
2.37.3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 9906619d5e296156bc247abb1af9039d5a2c3f10 Mon Sep 17 00:00:00 2001 | |
From: Ookiineko <chiisaineko@protonmail.com> | |
Date: Fri, 7 Oct 2022 15:58:58 +0800 | |
Subject: [PATCH] nbt: add nbt_var_insert | |
Signed-off-by: Ookiineko <chiisaineko@protonmail.com> | |
--- | |
cmd_ir/instructions/nbt.py | 41 ++++++++++++++++++++++++++++++++++++++ | |
commands/nbt.py | 21 +++++++++++++++++++ | |
2 files changed, 62 insertions(+) | |
diff --git a/cmd_ir/instructions/nbt.py b/cmd_ir/instructions/nbt.py | |
index 2cd222b..68cef0f 100644 | |
--- a/cmd_ir/instructions/nbt.py | |
+++ b/cmd_ir/instructions/nbt.py | |
@@ -221,6 +221,47 @@ class _ModifyNBTVariable(RuntimeHeldInsn): | |
out.write(c.DataModifyValue(dest_storage, dest_path, | |
self.action, self.nbt)) | |
+class NBTListVarInsert(RuntimeHeldInsn): | |
+ """Inserts NBT data to the given nbt variable. The variable must point | |
+ to an NBT list, else it will fail at runtime.""" | |
+ | |
+ insn_name = 'nbt_var_insert' | |
+ action = 'insert' | |
+ | |
+ args = [Variable, NBTBase, (NBTBase, Variable)] | |
+ access = [WRITE, READ, READ] | |
+ argnames = 'var idx nbt' | |
+ argdocs = ["Variable to set the value on", "List index", "NBT value"] | |
+ | |
+ @property | |
+ def held(self): | |
+ if isinstance(self.nbt, Variable): | |
+ return '' | |
+ return 'nbt' | |
+ | |
+ def validate(self): | |
+ assert self.var.type is VarType.nbt | |
+ assert self.idx.type is NBTType.int | |
+ | |
+ def declare(self): | |
+ self.var.usage_write() | |
+ if isinstance(self.nbt, Variable): | |
+ self.nbt.usage_read() | |
+ else: | |
+ self.nbt.declare() | |
+ | |
+ def apply(self, out, func): | |
+ direct = self.var._direct_nbt() | |
+ assert direct is not None, self.var | |
+ dest_path, dest_storage = direct | |
+ if isinstance(self.nbt, Variable): | |
+ src_path, src_storage = self.nbt.as_nbt_variable(out)._direct_nbt() | |
+ out.write(c.DataModifyListFrom(dest_storage, dest_path, self.action, | |
+ self.idx, src_storage, src_path)) | |
+ else: | |
+ out.write(c.DataModifyListValue(dest_storage, dest_path, | |
+ self.idx, self.action, self.nbt)) | |
+ | |
class NBTAssign(_ModifyNBTVariable): | |
"""Sets NBT data on the given variable (which must have type 'nbt').""" | |
diff --git a/commands/nbt.py b/commands/nbt.py | |
index 46287de..8eebded 100644 | |
--- a/commands/nbt.py | |
+++ b/commands/nbt.py | |
@@ -173,6 +173,27 @@ class DataModifyFrom(DataModify): | |
return '%s from %s %s' % (super().resolve(scope), | |
self.fromref.resolve(scope), self.frompath.resolve(scope)) | |
+class DataModifyListValue(DataModify): | |
+ | |
+ def init(self, idx, val): | |
+ self.idx = idx | |
+ self.val = val | |
+ | |
+ def resolve(self, scope): | |
+ return '%s %s value %s' % (super().resolve(scope), self.idx.resolve(scope), self.val.resolve(scope)) | |
+ | |
+class DataModifyListFrom(DataModify): | |
+ | |
+ def init(self, idx, ref, path): | |
+ self.idx = idx | |
+ assert isinstance(ref, NBTStorable) | |
+ self.fromref = ref | |
+ self.frompath = path | |
+ | |
+ def resolve(self, scope): | |
+ return '%s %s from %s %s' % (super().resolve(scope), | |
+ self.idx.resolve(scope), self.fromref.resolve(scope), self.frompath.resolve(scope)) | |
+ | |
class DataModifyStack(DataModifyValue): | |
def __init__(self, index, key, action, value, namespace=None): | |
-- | |
2.37.3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 40a74bb206fee34a099602211687d413abcdabfa Mon Sep 17 00:00:00 2001 | |
From: Ookiineko <chiisaineko@protonmail.com> | |
Date: Sun, 2 Oct 2022 17:05:54 +0800 | |
Subject: [PATCH 2/2] cmd_ir: fix dynamic linking | |
Signed-off-by: Ookiineko <chiisaineko@protonmail.com> | |
--- | |
cmd_ir/core.py | 4 ++++ | |
1 file changed, 4 insertions(+) | |
diff --git a/cmd_ir/core.py b/cmd_ir/core.py | |
index 4459f98..5a445a8 100644 | |
--- a/cmd_ir/core.py | |
+++ b/cmd_ir/core.py | |
@@ -408,6 +408,8 @@ class TopLevel(VariableHolder): | |
variables = {} | |
for name, var in self.scope.items(): | |
if isinstance(var, VisibleFunction) and var.extern_visibility: | |
+ if isinstance(var, DynLinkFunction): | |
+ continue | |
functions[name] = { | |
'_name': session.scope.function_name(var.global_name), | |
'params': [{'t': p[0].name, 'p': p[1]} for p in var.params], | |
@@ -417,6 +419,8 @@ class TopLevel(VariableHolder): | |
}, | |
} | |
elif isinstance(var, GlobalVariable) and var.is_extern: | |
+ if isinstance(var, ExternVariable): | |
+ continue | |
ref = var._direct_ref() | |
vardesc = None | |
if ref is not None: | |
-- | |
2.37.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment