Hello, everyone, and I am happy to announce that a joint project between myself and SM84CE is pretty much done!

This site does some basic optimizations to your code (as per the title), making it useful even if you don't use his libraries, and may shave off a byte or two! (or three, or 500)

It also helps helps programmers using SM84CE's awesome developer kit remove their dependencies on the kit, to make it more suitable for release. (which was the initial concept for the project)
Who really wants to download a slow, bulky subprogram for use with one or two programs

If anyone has suggestions for optimizations for me to add, please do post/make a PR/make an issue tagged with 'suggestion'/etc!

Site is here! GitHub repo is here with the interesting stuff here!

Believe it or not, every single line of code in that site was written in the past ~3 hours, as I am posting this Smile
hmmm, interesting project... I've got a few questions:
    1) Any specifications on what the site does with your code?
    2) What is the goal of this, are you optimizing for speed or size?
    3) What language is the parsing and manipulating done in?
    4) What basic languages are supported? Presumably, 83-84 basic, but even that has changed slightly over the years...

Also, if you guys want some help styling the webpage, I would be happy to help out, because it's really garbage rn (not in a mean way of course, it's just very uhhh plain?) Evil or Very Mad
It does this to your code: Razz <-- linked smiley It does a simple find and replace for the conversion, and currently removes end parenthesis, quotes, and curly braces at the ends of lines where they are directly stored into a variable, and also replaces 0-> with DelVar. As stated above, I want to add more.

I am optimizing for speed, but the optimizations are currently very light.

It is all done in JS, besides the parsing, as there is exactly zero parsing...

It should work with all TI-Basic languages/variants.
I was going to do some CSS, but I quickly ran out of time.

While you are at it, fix my JS, too <3
Started the CSS, try it out Razz

Also, what JS do you need help with exactly?
I tried to optimize a large program, and received this message: "Error: URI Too Long"
Have some more optimizations:

Code:
<?php
//Optimizations Start

   //minor things

   $match = array('While 0=', '(1/2)', '(1/4)', '(1/5)', '(1/10)', '(1/20)', '(1/30)', '(1/40)', '3^3', '4^3', '^2', '^3');//keep going, find a better way
   $replace = array('��While not(׵', '��.5׵', '��.75׵', '��.2׵', '��.1׵', '��.2׵', '��.3׵', '��.4׵', '��27׵', '��64׵', '���׵', '���׵');
   $string = repstr($match, $replace, $string);

   $match = array ('@([0-9])\*([A-Z|�])@', '@([A-Z|�])\*([0-9])@', '@([0-9|A-Z|�])/\(([0-9|A-Z|�])\)@', '@�\^\(?@', '@10\^\(?@', '@Output\(1,1,"([[:alnum:]]{1,16})@');
   $replace = array ('��\1\2׵', '��\1\2׵', '��\1/\2׵', '���^(׵', '���^(׵', '��Disp "\1׵');
   $string = repreg($match, $replace, $string);

   // Extra zeros to E^
      //positive
   $match = array('@([2-9])000([�|�|:|\)|/|\*|,|\^])@', '@([2-9])0000([�|�|:|\)|/|\*|,|\^])@', '@([2-9])00000([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('��\1�3\2׵', '��\1�4\2׵', '��\1�5\2׵');
    $string = repreg($match, $replace, $string);

   $match = array('@100([�|�|:|\)|/|\*|,|\^])@', '@1000([�|�|:|\)|/|\*|,|\^])@', '@10000([�|�|:|\)|/|\*|,|\^])@', '@100000([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('���2\1׵', '���3\1׵', '���4\1׵', '���5\1׵');
    $string = repreg($match, $replace, $string);

      //negative
   $match = array('@([�|�|:|\)|/|\*|,|\^])\.001([�|�|:|\)|/|\*|,|\^])@', '@([�|�|:|\)|/|\*|,|\^])\.0001([�|�|:|\)|/|\*|,|\^])@', '@([�|�|:|\)|/|\*|,|\^])\.00001([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('��\1��3\2׵', '��\1��4\2׵', '��\1��5\2׵');
   $string = repreg($match, $replace, $string);

   $match = array('@([�|�|:|\)|\(|/|\*|,|\^])\.000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@', '@([�|�|:|\)|\(|/|\*|,|\^])\.0000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@', '@([�|�|:|\(|\)|/|\*|,|\^])\.00000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@');
   $replace = array('��\1\2��4\3׵', '��\1\2��5\3׵', '��\1\2��6׵\3');
   $string = repreg($match, $replace, $string);

   //For 1 inc, if h, reciprocal
    $match = array ('@For\(([A-Z|�]),([[:alnum:]]{0,7}),([[:alnum:]]{0,7}),1@', '@([[:alnum:]]{0,})/([A-Z|�])\^([[:alnum:]{0,}])@');
    $replace = array ('��For(\1,\2,\3׵', '��\1\2^�\3׵');
    $string = repreg($match, $replace, $string);

   //extra multiplication and division characters
   $match = array ('@([0-9])\*([A-Z|�])@', '@([A-Z|�])\*([0-9])@', '@([0-9|A-Z|�])/\(([0-9|A-Z|�])\)@', '@([�|�|:|\)|/|\*|,|\^])1([A-Z|�])@');
   $replace = array ('��\1\2׵', '��\1\2׵', '��\1/\2׵', '��\1\2׵');
   $string = repreg($match, $replace, $string);

   //end$ or ^start of prog
    $match = array ('@Output\(1,1," $@');
    $replace = array ('��Output(1,1,"׵');
    $string = repreg($match, $replace, $string);

   //Delvars, if X!=0, removal of lagging "}), if not
   $match = array ('@([:|�])0�(.*?)[:|�]@', '@(DelVar [0-9|A-Z|�])[:|�](DelVar [0-9|A-Z|�])[:|�|[:blank:]]@', '@(If [A-Z|�])�0@', '@If not\(([A-Z|�])=([A-Z|�]) and ([A-Z|�])=([A-Z|�])@');
   $replace = array ('\1��Delvar \2׵', '��\1\2׵', '��\1׵', '��If \1�\2 or \3�\4׵', '��\2׵');
   $string = repreg($match, $replace, $string);

   //Disps
//   $match = array ('@(Disp "(.*?)):Disp ([["(.*?)|[A-Z]|�|!])@', '@Disp ([["(.*?)|[A-Z]|�|!])[:|�]Pause ([:|�])@');
   $replace = array ('��\1",\3׵', '��Pause \1\2׵');
   $string = repreg($match, $replace, $string);

   //Disp numbers, -A+B, A^(1/B
      $match = array('@Disp "([[:digit:]]{1,})(")?(:|�)@', '@�([A-Z|�])\+([A-Z|�])�([A-Z|�])@', '@(�|�|:|\()([A-Z|�])\^\(1\/([A-Z|�])(�|�|:)@');
   $replace = array('��Disp \1\3׵', '��\2-\1�\3׵', '��\1\3��(\2׵');
    $string = repreg($match, $replace, $string);

   //2A/(2BA, 1/(4/A, If not(A) and not(B
      $match = array('@(�|�|:|\()([1-9])([A-Z|�])/\(\2([A-Z|�])\3(�|�|:)@', '@(�|�|:)1/\(([A-Z|�|1-9])/([A-Z|�|1-9])(�|�|:)@', '@(If|While|Repeat) not\((.*?)\) and not\((.*?)(�|�|:)@');
   $replace = array('��\1\4�\5׵', '��\1\3/\2\4׵', '��\1 not(\2 or \3׵');
    $string = repreg($match, $replace, $string);

   //If not(A=B is not working
 //     $match = array('@(If|While|Repeat) not\((.*?)\=(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)\�(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)\�(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)�(.*?)(�|�|:)@');
   $replace = array('��\1 \2�\3\4׵', '��If \1=\2\3׵', '��\1 \2>\3\4׵', '��\1 \2<\3\4׵');
    $string = repreg($match, $replace, $string);

   //7112->A:7112->B, Disp "Guess?:Prompt A, If (A) or (X)
      $match = array('@(�|:)([[:alnum:]]{0,})�([A-Z|�])(�|:)\2�([A-Z|�])@', '@Disp "(.*?):Prompt ([A-Z|�])@', '@(If|While|Repeat) \((.*?)\) (and|or|xor) \((.*?)\)@');
   $replace = array('��\1\2�\3\4\3�\5׵', '��Input "\1",\2׵', '��\1 \2 \3 \4׵');
    $string = repreg($match, $replace, $string);

   //If A and|or B
      $match = array('@(If|While|Repeat) (.*?) and (.*?)(:|�)@', '@(If|While|Repeat) (.*?) or (.*?)(:|�)@', '@(If|While|Repeat) (.*?)=([0-9]) and (.*?)�\3 or \2�\3 and \4=\3(:|�)@');
   $replace = array('��\1 \2\3\4׵', '��\1 \2/\3\4׵', '��\1 \2=\3 xor \4=\3׵');
    $string = repreg($match, $replace, $string);

   //If A=10 and|or B=10, If A>B or A<B
      $match = array('@(If|While|Repeat) (.*?)=(.*?) and (.*?)=\3@', '@(If|While|Repeat) (.*?)=(.*?) or (.*?)=\3@', '@(If|While|Repeat) (.*?)=(.*?) and (.*?)=(.*?) or \2=(.*?) and \4=(.*?)@', '@(If|While|Repeat) (.*?)>(.*?) or \2<\3@');
   $replace = array('��\1 min(\3={\2,\4׵', '��\1 max(\3={\2,\4׵', '��\1 max(\2={\3,\6} and \3={\4,\7׵', '��If \2�\3׵');
    $string = repreg($match, $replace, $string);


   //If B:Then:"Str1 etc, Input "X" X,
   $match = array ('@If ([A-Z|�])(:|�)Then(:|�)(.*?)�(A-Z|�)(:|�)Else(:|�)(.*?)�\5(:|�)End@', '@Input "([A-Z|�])(�|=?)",\1@');
   $replace = array ('��\8�\5\3If \1\2\8�\5׵', '��Prompt \1׵');
   $string = repreg($match, $replace, $string);

   //For(X,5,1,-1
   $match = array ('@For\((.*?),(.*?),(.*?),�1(:|�)@');
   $replace = array ('��For(\1,\3,\2\4׵');
   $string = repreg($match, $replace, $string);

   //stuff with del, or not
   $string = repreg('@Disp "(:|�)@', 'Disp ""\1', $string);
   $string = repreg('@(["|\)|\}])(��|׵)@', '��[del]׵', $string);

   $match = array ('@[:|�]$@', '@Stop$@', '@(["|\)|\}])(�|:|�|$)@','@:(:+)@');
   $replace = array ('��[del]׵', '��[del]׵', '��[del]\2׵',':');
   $string = repreg($match, $replace, $string);


//Optimizations End
?>


Also, "replace(/0->/g,"DelVar ");" is really dangerous when you set a list with only the element 0, like {0->L1.
PT_ wrote:
Have some more optimizations:

Code:
<?php
//Optimizations Start

   //minor things

   $match = array('While 0=', '(1/2)', '(1/4)', '(1/5)', '(1/10)', '(1/20)', '(1/30)', '(1/40)', '3^3', '4^3', '^2', '^3');//keep going, find a better way
   $replace = array('��While not(׵', '��.5׵', '��.75׵', '��.2׵', '��.1׵', '��.2׵', '��.3׵', '��.4׵', '��27׵', '��64׵', '���׵', '���׵');
   $string = repstr($match, $replace, $string);

   $match = array ('@([0-9])\*([A-Z|�])@', '@([A-Z|�])\*([0-9])@', '@([0-9|A-Z|�])/\(([0-9|A-Z|�])\)@', '@�\^\(?@', '@10\^\(?@', '@Output\(1,1,"([[:alnum:]]{1,16})@');
   $replace = array ('��\1\2׵', '��\1\2׵', '��\1/\2׵', '���^(׵', '���^(׵', '��Disp "\1׵');
   $string = repreg($match, $replace, $string);

   // Extra zeros to E^
      //positive
   $match = array('@([2-9])000([�|�|:|\)|/|\*|,|\^])@', '@([2-9])0000([�|�|:|\)|/|\*|,|\^])@', '@([2-9])00000([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('��\1�3\2׵', '��\1�4\2׵', '��\1�5\2׵');
    $string = repreg($match, $replace, $string);

   $match = array('@100([�|�|:|\)|/|\*|,|\^])@', '@1000([�|�|:|\)|/|\*|,|\^])@', '@10000([�|�|:|\)|/|\*|,|\^])@', '@100000([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('���2\1׵', '���3\1׵', '���4\1׵', '���5\1׵');
    $string = repreg($match, $replace, $string);

      //negative
   $match = array('@([�|�|:|\)|/|\*|,|\^])\.001([�|�|:|\)|/|\*|,|\^])@', '@([�|�|:|\)|/|\*|,|\^])\.0001([�|�|:|\)|/|\*|,|\^])@', '@([�|�|:|\)|/|\*|,|\^])\.00001([�|�|:|\)|/|\*|,|\^])@');
   $replace = array('��\1��3\2׵', '��\1��4\2׵', '��\1��5\2׵');
   $string = repreg($match, $replace, $string);

   $match = array('@([�|�|:|\)|\(|/|\*|,|\^])\.000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@', '@([�|�|:|\)|\(|/|\*|,|\^])\.0000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@', '@([�|�|:|\(|\)|/|\*|,|\^])\.00000([1-9])([�|�|:|\(|\)|/|\*|,|\^])@');
   $replace = array('��\1\2��4\3׵', '��\1\2��5\3׵', '��\1\2��6׵\3');
   $string = repreg($match, $replace, $string);

   //For 1 inc, if h, reciprocal
    $match = array ('@For\(([A-Z|�]),([[:alnum:]]{0,7}),([[:alnum:]]{0,7}),1@', '@([[:alnum:]]{0,})/([A-Z|�])\^([[:alnum:]{0,}])@');
    $replace = array ('��For(\1,\2,\3׵', '��\1\2^�\3׵');
    $string = repreg($match, $replace, $string);

   //extra multiplication and division characters
   $match = array ('@([0-9])\*([A-Z|�])@', '@([A-Z|�])\*([0-9])@', '@([0-9|A-Z|�])/\(([0-9|A-Z|�])\)@', '@([�|�|:|\)|/|\*|,|\^])1([A-Z|�])@');
   $replace = array ('��\1\2׵', '��\1\2׵', '��\1/\2׵', '��\1\2׵');
   $string = repreg($match, $replace, $string);

   //end$ or ^start of prog
    $match = array ('@Output\(1,1," $@');
    $replace = array ('��Output(1,1,"׵');
    $string = repreg($match, $replace, $string);

   //Delvars, if X!=0, removal of lagging "}), if not
   $match = array ('@([:|�])0�(.*?)[:|�]@', '@(DelVar [0-9|A-Z|�])[:|�](DelVar [0-9|A-Z|�])[:|�|[:blank:]]@', '@(If [A-Z|�])�0@', '@If not\(([A-Z|�])=([A-Z|�]) and ([A-Z|�])=([A-Z|�])@');
   $replace = array ('\1��Delvar \2׵', '��\1\2׵', '��\1׵', '��If \1�\2 or \3�\4׵', '��\2׵');
   $string = repreg($match, $replace, $string);

   //Disps
//   $match = array ('@(Disp "(.*?)):Disp ([["(.*?)|[A-Z]|�|!])@', '@Disp ([["(.*?)|[A-Z]|�|!])[:|�]Pause ([:|�])@');
   $replace = array ('��\1",\3׵', '��Pause \1\2׵');
   $string = repreg($match, $replace, $string);

   //Disp numbers, -A+B, A^(1/B
      $match = array('@Disp "([[:digit:]]{1,})(")?(:|�)@', '@�([A-Z|�])\+([A-Z|�])�([A-Z|�])@', '@(�|�|:|\()([A-Z|�])\^\(1\/([A-Z|�])(�|�|:)@');
   $replace = array('��Disp \1\3׵', '��\2-\1�\3׵', '��\1\3��(\2׵');
    $string = repreg($match, $replace, $string);

   //2A/(2BA, 1/(4/A, If not(A) and not(B
      $match = array('@(�|�|:|\()([1-9])([A-Z|�])/\(\2([A-Z|�])\3(�|�|:)@', '@(�|�|:)1/\(([A-Z|�|1-9])/([A-Z|�|1-9])(�|�|:)@', '@(If|While|Repeat) not\((.*?)\) and not\((.*?)(�|�|:)@');
   $replace = array('��\1\4�\5׵', '��\1\3/\2\4׵', '��\1 not(\2 or \3׵');
    $string = repreg($match, $replace, $string);

   //If not(A=B is not working
 //     $match = array('@(If|While|Repeat) not\((.*?)\=(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)\�(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)\�(.*?)(�|�|:)@', '@(If|While|Repeat) not\((.*?)�(.*?)(�|�|:)@');
   $replace = array('��\1 \2�\3\4׵', '��If \1=\2\3׵', '��\1 \2>\3\4׵', '��\1 \2<\3\4׵');
    $string = repreg($match, $replace, $string);

   //7112->A:7112->B, Disp "Guess?:Prompt A, If (A) or (X)
      $match = array('@(�|:)([[:alnum:]]{0,})�([A-Z|�])(�|:)\2�([A-Z|�])@', '@Disp "(.*?):Prompt ([A-Z|�])@', '@(If|While|Repeat) \((.*?)\) (and|or|xor) \((.*?)\)@');
   $replace = array('��\1\2�\3\4\3�\5׵', '��Input "\1",\2׵', '��\1 \2 \3 \4׵');
    $string = repreg($match, $replace, $string);

   //If A and|or B
      $match = array('@(If|While|Repeat) (.*?) and (.*?)(:|�)@', '@(If|While|Repeat) (.*?) or (.*?)(:|�)@', '@(If|While|Repeat) (.*?)=([0-9]) and (.*?)�\3 or \2�\3 and \4=\3(:|�)@');
   $replace = array('��\1 \2\3\4׵', '��\1 \2/\3\4׵', '��\1 \2=\3 xor \4=\3׵');
    $string = repreg($match, $replace, $string);

   //If A=10 and|or B=10, If A>B or A<B
      $match = array('@(If|While|Repeat) (.*?)=(.*?) and (.*?)=\3@', '@(If|While|Repeat) (.*?)=(.*?) or (.*?)=\3@', '@(If|While|Repeat) (.*?)=(.*?) and (.*?)=(.*?) or \2=(.*?) and \4=(.*?)@', '@(If|While|Repeat) (.*?)>(.*?) or \2<\3@');
   $replace = array('��\1 min(\3={\2,\4׵', '��\1 max(\3={\2,\4׵', '��\1 max(\2={\3,\6} and \3={\4,\7׵', '��If \2�\3׵');
    $string = repreg($match, $replace, $string);


   //If B:Then:"Str1 etc, Input "X" X,
   $match = array ('@If ([A-Z|�])(:|�)Then(:|�)(.*?)�(A-Z|�)(:|�)Else(:|�)(.*?)�\5(:|�)End@', '@Input "([A-Z|�])(�|=?)",\1@');
   $replace = array ('��\8�\5\3If \1\2\8�\5׵', '��Prompt \1׵');
   $string = repreg($match, $replace, $string);

   //For(X,5,1,-1
   $match = array ('@For\((.*?),(.*?),(.*?),�1(:|�)@');
   $replace = array ('��For(\1,\3,\2\4׵');
   $string = repreg($match, $replace, $string);

   //stuff with del, or not
   $string = repreg('@Disp "(:|�)@', 'Disp ""\1', $string);
   $string = repreg('@(["|\)|\}])(��|׵)@', '��[del]׵', $string);

   $match = array ('@[:|�]$@', '@Stop$@', '@(["|\)|\}])(�|:|�|$)@','@:(:+)@');
   $replace = array ('��[del]׵', '��[del]׵', '��[del]\2׵',':');
   $string = repreg($match, $replace, $string);


//Optimizations End
?>


Also, "replace(/0->/g,"DelVar ");" is really dangerous when you set a list with only the element 0, like {0->L1.


Good point.

Unfortunately, one cannot use PHP on GitHub pages (all front-end), which sucks, but I am attempting to extract the ReGex that you used, as I can use that.

A good portion of characters are not showing up (replacement character), can someone tell me what they are? �

jonbush: Yes, that’s because I’m a lazy idiot who forgot to change his form request method.

Also, feel free to submit more optimizations (that aren’t in any of the above posts, or currently on the site) here.
Battlesquid and mr womp womp (especially the former) helped me a ton with the CSS and HTML formatting of the site, so a huge thanks to them.

I fixed what PT_ noted, with the DelVar optimization being dangerous, and I learned quite a bit more about RegEx in JS.

It also tells you how many characters (not bytes!) long your input is, and how long your output is, which is quite nice.

I'm in the process of adding the optimizations PT_ suggested.

Thanks, everyone!
I've made a pull request; with the new code it's much easier to add new RegEx expressions, and the code is a bit cleaner and smaller Smile
Interesting.

This project could be even better for end-users if they could directly "upload" their 8xp and get the optimized 8xp back ;D

Something something tivars_lib_cpp (the js build).
(it's already used (both php and JS versions) in cases like this, for instance on z80->ce converters, game level generators, text viewer generators, etc.)
PT_ wrote:
I've made a pull request; with the new code it's much easier to add new RegEx expressions, and the code is a bit cleaner and smaller Smile


Thanks! (Merged)

Adriweb wrote:
Interesting.

This project could be even better for end-users if they could directly "upload" their 8xp and get the optimized 8xp back ;D

Something something tivars_lib_cpp (the js build).
(it's already used (both php and JS versions) in cases like this, for instance on z80->ce converters, game level generators, text viewer generators, etc.)


That’s awesome, I’ll definitely take a look at that.

I was going to do something like that, but I had no idea how to do the required upload of the file, much less how to actually interpret the file!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement