Compare commits
15 Commits
4.0.1
...
4.0.1-hotf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0233b796e | ||
|
|
99b45cac7b | ||
|
|
ee212a5156 | ||
|
|
dfe42c3991 | ||
|
|
c895266f34 | ||
|
|
6881075fc8 | ||
|
|
09cd6e2bd1 | ||
|
|
23cc913bf2 | ||
|
|
eb3fc13385 | ||
|
|
35a6bd9b41 | ||
|
|
e87301e160 | ||
|
|
e96ea63479 | ||
|
|
c24e028960 | ||
|
|
5a12d0c120 | ||
|
|
785549a9c8 |
4
Makefile
4
Makefile
@@ -113,9 +113,9 @@ $(BUILDDIR)/$(TARGET)/script/builtin.c: scripts/*.te
|
|||||||
@mkdir -p "$(@D)"
|
@mkdir -p "$(@D)"
|
||||||
@mkdir -p "$(BUILDDIR)/$(TARGET)/scripts"
|
@mkdir -p "$(BUILDDIR)/$(TARGET)/scripts"
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
@py ts-minifier.py -d "$(BUILDDIR)/$(TARGET)/scripts" $(wildcard scripts/*.te)
|
@py ts-minifier.py --such-meme -d "$(BUILDDIR)/$(TARGET)/scripts" $(wildcard scripts/*.te)
|
||||||
@py te2c.py "$(BUILDDIR)/$(TARGET)/script/builtin" "$(BUILDDIR)/$(TARGET)/scripts"
|
@py te2c.py "$(BUILDDIR)/$(TARGET)/script/builtin" "$(BUILDDIR)/$(TARGET)/scripts"
|
||||||
else
|
else
|
||||||
@python3 ts-minifier.py -d "$(BUILDDIR)/$(TARGET)/scripts" $(wildcard scripts/*.te)
|
@python3 ts-minifier.py --such-meme -d "$(BUILDDIR)/$(TARGET)/scripts" $(wildcard scripts/*.te)
|
||||||
@python3 te2c.py "$(BUILDDIR)/$(TARGET)/script/builtin" "$(BUILDDIR)/$(TARGET)/scripts"
|
@python3 te2c.py "$(BUILDDIR)/$(TARGET)/script/builtin" "$(BUILDDIR)/$(TARGET)/scripts"
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ static const pkg1_id_t _pkg1_ids[] = {
|
|||||||
{ "20210129", 10}, //12.0.0 - 12.0.1
|
{ "20210129", 10}, //12.0.0 - 12.0.1
|
||||||
{ "20210422", 10}, //12.0.2 - 12.0.3
|
{ "20210422", 10}, //12.0.2 - 12.0.3
|
||||||
{ "20210607", 11}, //12.1.0
|
{ "20210607", 11}, //12.1.0
|
||||||
{ "20210805", 11 },
|
{ "20210805", 12}, //13.0.0 - 13.2.0
|
||||||
|
{ "20220105", 12}, //13.2.1
|
||||||
|
{ "20220209", 13}, //14.0.0 - 14.1.2
|
||||||
|
{ "20220801", 14}, //15.0.0 - 15.0.1
|
||||||
|
{ "20230111", 15}, //16.0.0+
|
||||||
{ NULL } //End.
|
{ NULL } //End.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -180,11 +180,11 @@ ClassFunction(arrayContains) {
|
|||||||
|
|
||||||
if (caller->variableType == StringArrayClass) {
|
if (caller->variableType == StringArrayClass) {
|
||||||
if (!strcmp(arg->string.value, iter.string.value))
|
if (!strcmp(arg->string.value, iter.string.value))
|
||||||
return newIntVariablePtr(1);
|
return newIntVariablePtr(i + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (arg->integer.value == iter.integer.value)
|
if (arg->integer.value == iter.integer.value)
|
||||||
return newIntVariablePtr(1);
|
return newIntVariablePtr(i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,13 +234,8 @@ char *powNames[] = {
|
|||||||
"volminus",
|
"volminus",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Takes [int]. Returns dict[a,b,x,y,down,up,right,left,power,volplus,volminus,raw]. int: mask for hidWaitMask
|
Variable_t *hidToVar(u32 raw){
|
||||||
ClassFunction(stdPauseMask){
|
|
||||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
|
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
|
||||||
Input_t *i = hidWaitMask((u32)getIntValue(*args));
|
|
||||||
|
|
||||||
u32 raw = i->buttons;
|
|
||||||
|
|
||||||
addIntToDict(&ret, "raw", raw);
|
addIntToDict(&ret, "raw", raw);
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(abxyNames); i++){
|
for (int i = 0; i < ARRAY_SIZE(abxyNames); i++){
|
||||||
@@ -265,6 +260,19 @@ ClassFunction(stdPauseMask){
|
|||||||
return copyVariableToPtr(ret);
|
return copyVariableToPtr(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassFunction(stdRead){
|
||||||
|
Input_t *i = hidRead();
|
||||||
|
u32 raw = i->buttons;
|
||||||
|
return hidToVar(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Takes [int]. Returns dict[a,b,x,y,down,up,right,left,power,volplus,volminus,raw]. int: mask for hidWaitMask
|
||||||
|
ClassFunction(stdPauseMask){
|
||||||
|
Input_t *i = hidWaitMask((u32)getIntValue(*args));
|
||||||
|
u32 raw = i->buttons;
|
||||||
|
return hidToVar(raw);
|
||||||
|
}
|
||||||
|
|
||||||
// Takes none. Returns dict (same as stdPauseMask).
|
// Takes none. Returns dict (same as stdPauseMask).
|
||||||
ClassFunction(stdPause){
|
ClassFunction(stdPause){
|
||||||
Variable_t a = {.integer.value = 0xFFFFFFFF};
|
Variable_t a = {.integer.value = 0xFFFFFFFF};
|
||||||
@@ -482,6 +490,7 @@ STUBBED(stdMkdir)
|
|||||||
STUBBED(stdGetMemUsage)
|
STUBBED(stdGetMemUsage)
|
||||||
STUBBED(stdGetNcaType)
|
STUBBED(stdGetNcaType)
|
||||||
STUBBED(stdPause)
|
STUBBED(stdPause)
|
||||||
|
STUBBED(stdRead)
|
||||||
STUBBED(stdPauseMask)
|
STUBBED(stdPauseMask)
|
||||||
STUBBED(stdColor)
|
STUBBED(stdColor)
|
||||||
STUBBED(stdMenuFull)
|
STUBBED(stdMenuFull)
|
||||||
@@ -541,6 +550,7 @@ ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
|||||||
{"timer", stdGetMs, 0, 0},
|
{"timer", stdGetMs, 0, 0},
|
||||||
{"pause", stdPauseMask, 1, threeIntsStd},
|
{"pause", stdPauseMask, 1, threeIntsStd},
|
||||||
{"pause", stdPause, 0, 0},
|
{"pause", stdPause, 0, 0},
|
||||||
|
{"hidread", stdRead, 0, 0},
|
||||||
{"color", stdColor, 1, threeIntsStd},
|
{"color", stdColor, 1, threeIntsStd},
|
||||||
{"menu", stdMenuFull, 3, menuArgsStd},
|
{"menu", stdMenuFull, 3, menuArgsStd},
|
||||||
{"menu", stdMenuFull, 2, menuArgsStd},
|
{"menu", stdMenuFull, 2, menuArgsStd},
|
||||||
|
|||||||
@@ -152,7 +152,12 @@ Variable_t createUnsolvedArrayVariable(Function_t* f) {
|
|||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassFunction(retZero){
|
||||||
|
return newIntVariablePtr(0);
|
||||||
|
}
|
||||||
|
|
||||||
u8 anotherOneVarArg[] = { VARARGCOUNT };
|
u8 anotherOneVarArg[] = { VARARGCOUNT };
|
||||||
|
u8 unsolvedArrayStr[] = { StringClass };
|
||||||
|
|
||||||
ClassFunction(createTypedArray) {
|
ClassFunction(createTypedArray) {
|
||||||
Vector_t v = { 0 };
|
Vector_t v = { 0 };
|
||||||
@@ -180,6 +185,7 @@ ClassFunction(createTypedArray) {
|
|||||||
ClassFunctionTableEntry_t unsolvedArrayFunctions[] = {
|
ClassFunctionTableEntry_t unsolvedArrayFunctions[] = {
|
||||||
{"+", createTypedArray, 1, anotherOneVarArg},
|
{"+", createTypedArray, 1, anotherOneVarArg},
|
||||||
{"add", createTypedArray, 1, anotherOneVarArg},
|
{"add", createTypedArray, 1, anotherOneVarArg},
|
||||||
|
{"len", retZero, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
Variable_t getUnsolvedArrayMember(Variable_t* var, char* memberName) {
|
Variable_t getUnsolvedArrayMember(Variable_t* var, char* memberName) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# Copyright (c) 2021 bleck9999
|
# Copyright (c) 2021 bleck9999
|
||||||
# https://github.com/bleck9999/ts-minifier
|
# https://github.com/bleck9999/ts-minifier
|
||||||
# Version: 339183b2
|
# Version: 49befe92
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
@@ -14,7 +13,7 @@ stdlib = ['if', 'while', 'print', 'println', 'mountsys', 'mountemu', 'readsave',
|
|||||||
'readdir', 'copyfile', 'mkdir', 'ncatype', 'pause', 'color', 'menu', 'emu', 'clear', 'timer', 'deldir',
|
'readdir', 'copyfile', 'mkdir', 'ncatype', 'pause', 'color', 'menu', 'emu', 'clear', 'timer', 'deldir',
|
||||||
'fsexists', 'delfile', 'copydir', 'movefile', 'payload', 'readfile', 'writefile', 'setpixels', 'printpos',
|
'fsexists', 'delfile', 'copydir', 'movefile', 'payload', 'readfile', 'writefile', 'setpixels', 'printpos',
|
||||||
'emmcread', 'emmcwrite', 'emummcread', 'emummcwrite', 'escapepath', 'combinepath', 'cwd', 'power',
|
'emmcread', 'emmcwrite', 'emummcread', 'emummcwrite', 'escapepath', 'combinepath', 'cwd', 'power',
|
||||||
'fuse_patched', 'fuse_hwtype']
|
'fuse_patched', 'fuse_hwtype', 'hidread']
|
||||||
|
|
||||||
|
|
||||||
class Code:
|
class Code:
|
||||||
@@ -153,12 +152,12 @@ def minify(script: Code, userobjects, usages):
|
|||||||
# minus the amount of characters it would take to define an alias (len(alias)+len(func)+2), with the 2 being for the
|
# minus the amount of characters it would take to define an alias (len(alias)+len(func)+2), with the 2 being for the
|
||||||
# equals and the whitespace needed for a definition
|
# equals and the whitespace needed for a definition
|
||||||
# the same principle also applies to introducing a variable for string literals, though since a literal requires
|
# the same principle also applies to introducing a variable for string literals, though since a literal requires
|
||||||
# having "s around it then it's uses*(len(str)+2) - (len(minName)+len(str)+4)
|
# having "s around it then it's uses*(len(str)+2) - (len(minName)+len(str)+4) instead
|
||||||
# ^ 2 for = and whitespace, 2 for ""
|
# ^ 2 for = and whitespace, 2 for ""
|
||||||
#
|
#
|
||||||
# obviously for a rename you're already defining it so it's just the difference between lengths multiplied by uses
|
# obviously for a rename you're already defining it so it's just the difference between lengths multiplied by uses
|
||||||
short_idents = [x for x in (ascii_letters + '_')] + [x[0] + x[1] for x in
|
short_idents = [x for x in (ascii_letters + '_')] + \
|
||||||
itertools.product(ascii_letters + '_', repeat=2)]
|
[x[0] + x[1] for x in itertools.product(ascii_letters + '_', repeat=2)]
|
||||||
short_idents.pop(short_idents.index("if"))
|
short_idents.pop(short_idents.index("if"))
|
||||||
mcode = script.rawcode
|
mcode = script.rawcode
|
||||||
aliases = []
|
aliases = []
|
||||||
@@ -267,6 +266,10 @@ def minify(script: Code, userobjects, usages):
|
|||||||
logging.info("Introducing variables for reused literals" if auto_replace else
|
logging.info("Introducing variables for reused literals" if auto_replace else
|
||||||
"Checking for reused literals")
|
"Checking for reused literals")
|
||||||
for string in str_reuse:
|
for string in str_reuse:
|
||||||
|
if string == '"BYTE[]"':
|
||||||
|
# the type specifier for byte arrays is special because it has to be a literal
|
||||||
|
# if it's a variable then it tries to treat it as a string array then shits the bed if the other items are not strings
|
||||||
|
continue
|
||||||
tmpcode = ""
|
tmpcode = ""
|
||||||
candidates = short_idents
|
candidates = short_idents
|
||||||
minName = ""
|
minName = ""
|
||||||
@@ -341,13 +344,13 @@ def minify(script: Code, userobjects, usages):
|
|||||||
mcode = tmpcode + mcode[bound + diff + len(minName):]
|
mcode = tmpcode + mcode[bound + diff + len(minName):]
|
||||||
aliases.append(f"{minName}={uint} ")
|
aliases.append(f"{minName}={uint} ")
|
||||||
else:
|
else:
|
||||||
logging.warning(f"Not introducing variable for string {uint} reused {uses} times "
|
logging.warning(f"Not introducing variable for integer {uint} reused {uses} times "
|
||||||
f"(would save {savings} bytes)")
|
f"(would save {savings} bytes)")
|
||||||
else:
|
else:
|
||||||
logging.info(f"Not introducing variable for string {uint} reused {uses} times "
|
logging.info(f"Not introducing variable for integer {uint} reused {uses} times "
|
||||||
f"(would save {savings} bytes)")
|
f"(would save {savings} bytes)")
|
||||||
else:
|
else:
|
||||||
logging.info(f"Not introducing variable for int {uint} (only used once)")
|
logging.info(f"Not introducing variable for integer {uint} (only used once)")
|
||||||
|
|
||||||
logging.info("Reintroducing REQUIREs")
|
logging.info("Reintroducing REQUIREs")
|
||||||
mcode = "".join([x[2] for x in script.comments]) + "".join(aliases) + mcode
|
mcode = "".join([x[2] for x in script.comments]) + "".join(aliases) + mcode
|
||||||
@@ -427,6 +430,8 @@ if __name__ == '__main__':
|
|||||||
"and attempt to generate shorter names for reused variables \ndefault: false")
|
"and attempt to generate shorter names for reused variables \ndefault: false")
|
||||||
argparser.add_argument("-v", action="store_true", default=False,
|
argparser.add_argument("-v", action="store_true", default=False,
|
||||||
help="prints even more information to the console than usual")
|
help="prints even more information to the console than usual")
|
||||||
|
argparser.add_argument("--such-meme", action="store_true", default=False,
|
||||||
|
help="replaces destination file if it already exists \ndefault: false")
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
files = args.source
|
files = args.source
|
||||||
@@ -448,7 +453,7 @@ if __name__ == '__main__':
|
|||||||
logging.info("Stripping whitespace (pass 2)")
|
logging.info("Stripping whitespace (pass 2)")
|
||||||
r = whitespacent(r)
|
r = whitespacent(r)
|
||||||
file = path.splitext(path.basename(file))[0]
|
file = path.splitext(path.basename(file))[0]
|
||||||
if path.exists(path.join(dest, f"{file}.te")):
|
if path.exists(path.join(dest, f"{file}.te")) and not args.such_meme:
|
||||||
f = open(path.join(dest, f"{file}_min.te"), 'w')
|
f = open(path.join(dest, f"{file}_min.te"), 'w')
|
||||||
else:
|
else:
|
||||||
f = open(path.join(dest, f"{file}.te"), 'w')
|
f = open(path.join(dest, f"{file}.te"), 'w')
|
||||||
|
|||||||
Reference in New Issue
Block a user