Compare commits

...

15 Commits

Author SHA1 Message Date
bleck9999
b0233b796e Merge pull request #78 from FlyingBananaTree/patch-1
Add 16.0.0 pkg1
2023-02-21 21:25:49 +00:00
FlyingBananaTree
99b45cac7b Correct indent 2023-02-21 20:44:30 +00:00
FlyingBananaTree
ee212a5156 Add 16.0.0 pkg1 2023-02-21 19:50:24 +00:00
suchmememanyskill
dfe42c3991 Merge pull request #71 from FlyingBananaTree/patch-1
Add 15.0.0 pkg1
2022-10-11 23:32:33 +02:00
FlyingBananaTree
c895266f34 Add 15.0.0 pkg1
Just a quick pr for new pkg1
2022-10-11 16:01:54 +01:00
bleck9999
6881075fc8 fix auto-replace breaking byte arrays
also sneak some wording changes in
2022-04-30 19:58:42 +01:00
suchmememanyskill
09cd6e2bd1 Merge pull request #65 from dezem/master
Add 14.0.0 pkg1
2022-03-22 22:06:38 +01:00
dezem
23cc913bf2 Add 14.0.0 pkg1 2022-03-22 21:55:58 +01:00
suchmememanyskill
eb3fc13385 Add 13.2.1 pkg1 2022-01-21 11:12:04 +01:00
suchmememanyskill
35a6bd9b41 [Script] Return index on array.contains 2022-01-21 11:05:09 +01:00
bleck9999
e87301e160 gotta save those 2.9 seconds 2021-10-16 11:43:26 +01:00
suchmememanyskill
e96ea63479 add .len to unsolved array 2021-10-16 12:41:08 +02:00
bleck9999
c24e028960 fix compiling abadidea 2021-09-25 14:27:47 +01:00
bleck9999
5a12d0c120 add hidread to script
but not that script the other script
2021-09-17 17:10:20 +01:00
suchmememanyskill
785549a9c8 add hidread function to script 2021-09-16 23:44:20 +02:00
6 changed files with 46 additions and 21 deletions

View File

@@ -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

View File

@@ -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.
}; };

View File

@@ -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);
} }
} }

View File

@@ -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},

View File

@@ -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) {

View File

@@ -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')