PicoBlaze Simulator in JavaScript

  • 18 Replies
  • 7270 Views
*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
PicoBlaze Simulator in JavaScript
« on: November 08, 2020, 06:01:14 AM »
As a part of a school project, I've been developing my PicoBlaze Simulator in JavaScript. What do you think about it? How can I make it better in a way that isn't too difficult to program?
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

markjo

  • Content Nazi
  • 45082
  • +87/-109
Re: Does the Bible say that Earth is Stationary
« Reply #1 on: November 09, 2020, 08:57:48 AM »
Hi, how does AutoTrade picks its trades?

Does it pick the most profitable one from a list it scanned trades?

Does it pick up the first trade it finds?

Does it pick the trade with the biggest volume?

...

What does that have to do with anything?

By the way, the page you linked to isn't working, I get Error 403.
Don't you know a spambot when you see one?
Science is what happens when preconception meets verification.
Quote from: Robosteve
Besides, perhaps FET is a conspiracy too.
Quote from: bullhorn
It is just the way it is, you understanding it doesn't concern me.

?

Jamie

  • 1723
  • +0/-0
  • Retired
Re: PicoBlaze Simulator in JavaScript
« Reply #2 on: November 09, 2020, 11:10:13 AM »
The Bible says a lot of things.
"Conspiracy theorists actually believe in the conspiracy because that is more comforting." - Alan Moore

*

markjo

  • Content Nazi
  • 45082
  • +87/-109
Re: PicoBlaze Simulator in JavaScript
« Reply #3 on: November 09, 2020, 12:52:50 PM »
I believe that the Bible is a source of spiritual truth, not scientific truth.
Science is what happens when preconception meets verification.
Quote from: Robosteve
Besides, perhaps FET is a conspiracy too.
Quote from: bullhorn
It is just the way it is, you understanding it doesn't concern me.

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: Does the Bible say that Earth is Stationary
« Reply #4 on: November 10, 2020, 10:31:38 AM »
Hi, how does AutoTrade picks its trades?

Does it pick the most profitable one from a list it scanned trades?

Does it pick up the first trade it finds?

Does it pick the trade with the biggest volume?

...

What does that have to do with anything?

By the way, the page you linked to isn't working, I get Error 403.
Don't you know a spambot when you see one?
If it is a spambot, how did it pass the CAPTCHA?
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

boydster

  • Assistant to the Regional Manager
  • 17774
  • +6/-4
Re: Does the Bible say that Earth is Stationary
« Reply #5 on: November 10, 2020, 10:56:18 AM »
Hi, how does AutoTrade picks its trades?

Does it pick the most profitable one from a list it scanned trades?

Does it pick up the first trade it finds?

Does it pick the trade with the biggest volume?

...

What does that have to do with anything?

By the way, the page you linked to isn't working, I get Error 403.
Don't you know a spambot when you see one?
If it is a spambot, how did it pass the CAPTCHA?
How can you claim to be a developer and you let something as obvious as that fool you? In fact, the very question you asked in this post that I'm replying to is also a weird thing for a developer to ask. AND YOU CLICKED THE LINK??????????

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #6 on: November 10, 2020, 11:30:15 PM »
I believe that the Bible is a source of spiritual truth, not scientific truth.
I am quite sure it's not a source of spiritual truth either. Ask yourself, if Jesus was alive in the 20th century, wouldn't he support Communism? I think he would. In the Bible, he despised private property (he said poppies and birds live a lot better than humans because they don't care about private property), he said that taxation was ethical (that coins with emperor's image rightfully belong to the emperor), that rich will naturally become richer and poor poorer and that violent rebellion was a solution to the world's problems. Doesn't that sound like preaching Communism in the language of the 1st century?
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: Does the Bible say that Earth is Stationary
« Reply #7 on: November 10, 2020, 11:40:13 PM »
Hi, how does AutoTrade picks its trades?

Does it pick the most profitable one from a list it scanned trades?

Does it pick up the first trade it finds?

Does it pick the trade with the biggest volume?

...

What does that have to do with anything?

By the way, the page you linked to isn't working, I get Error 403.
Don't you know a spambot when you see one?
If it is a spambot, how did it pass the CAPTCHA?
How can you claim to be a developer and you let something as obvious as that fool you? In fact, the very question you asked in this post that I'm replying to is also a weird thing for a developer to ask. AND YOU CLICKED THE LINK??????????
Well, whether I am a developer depends on what you mean by developer. I am not making money by programming (though I hope to be soon), but I do write pieces of software. "FlatAssembler" here and "FlatAssembler" on GitHub are the same person, here is a link to a thread about my programming language on this forum on GitHub. Why is my question weird. I myself often have trouble passing the CAPTCHAs that this website poses to me, and I am having trouble believing a bot can do that. What's wrong with clicking the link in a modern browser?
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

boydster

  • Assistant to the Regional Manager
  • 17774
  • +6/-4
Re: PicoBlaze Simulator in JavaScript
« Reply #8 on: November 11, 2020, 05:20:32 AM »
A developer is one that develops software, which you claim to do. CAPTCHAs are solved by AI all the time. There are services dedicated to it, check your googlemachine. Recognizing spam bots like the one you replied to after clicking the link it fed you is something a developer should be able to do more proficiently than someone who just goes on the internet to post memes. And clicking their links is the pinnacle of irresponsible end user behavior.

I wonder, if it had linked to a Domino's Pizza coupon, would you have given it your personal information? ::)

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #9 on: July 25, 2023, 06:27:37 AM »
There are, as far as I can see, three problems with my syntax-highlighter for PicoBlaze Assembly.
1. (most critical one) It cannot highlight programs containing the characters `<`, `>` and `&`, beccause it inserts `;` (the comment sign) after them, making programs that use those operators syntactically invalid.
2. It incorrectly highlights hexadecimal constants `a`, `b`, and `c` as flags.
3. It has to be invoked by pressing a button called "Highlight Assembly", rather than highlighting the code as the user is typing it.
Here is the source code of it:
Code: [Select]
function highlightToken(token) {
  if (token[0] === ";")
    return `<span class="comment">${token}</span>`;
  for (const mnemonic of mnemonics)
    if (RegExp("^" + mnemonic + "$", "i").test(token) ||
        /^interrupt$/i.test(token))
      return `<span class="mnemonic">${token}</span>`;
  for (const directive of preprocessor)
    if (RegExp("^" + directive + "$", "i").test(token))
      return `<span class="directive">${token}</span>`;
  if (/^s(\d|[a-f])$/i.test(token))
    return `<span class="register">${token}</span>`;
  if (/^N?[CZAB]$/i.test(token))
    // TODO: This actually sometimes incorrectly highlights "a" as
    // a flag, when it is in fact a hexadecimal constant. You can
    // read more about it here:
    // https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/issues/6
    return `<span class="flag">${token}</span>`;
  if (/:$/.test(token))
    return `<span class="label">${token}</span>`;
  if (token[0] === '"')
    return `<span class="string">${token}</span>`;
  if (/^(\d|[a-f])+$/i.test(token) || /\'d$/.test(token) || /\'b$/.test(token))
    return `<span class="number">${token}</span>`;
  return token;
}
function syntaxHighlighter(/*edit*/) {
  //"edit" should contain the cursor position, but that seems not to work.
  // I have opened a StackOverflow question about that:
  // https://stackoverflow.com/q/76566400/8902065
  if (areWeHighlighting)
    return;
  areWeHighlighting = true;
  const assemblyCodeDiv = document.getElementById("assemblyCode");
  const assemblyCode =
      assemblyCodeDiv.innerText.replace(/&/g, "&amp;")
          .replace(
              /</g,
              "&lt;") // This appears to cause this bug:
                      // https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/issues/7
          .replace(/>/g, "&gt;");
  // const start=edit.selectionStart,
  //  end=edit.selectionEnd; //Cursor position.
  if (assemblyCode.indexOf("&") != -1) {
    alert(
        "Sorry about that, but syntax highlighting of the programs containing `<`, `&`, and `>` is not supported yet.");
    areWeHighlighting = false;
    return;
  }
  let areWeInAString = false;
  let areWeInAComment = false;
  let currentToken = "";
  let highlightedText = "";
  for (let i = 0; i < assemblyCode.length; i++) {
    if (assemblyCode[i] === ";" && !areWeInAString) {
      highlightedText += highlightToken(currentToken);
      currentToken = ";";
      areWeInAComment = true;
      continue;
    }
    if (areWeInAComment && assemblyCode[i] !== "\n") {
      currentToken += assemblyCode[i];
      continue;
    }
    if (assemblyCode[i] === "\n") {
      areWeInAString = false;
      areWeInAComment = false;
      highlightedText += highlightToken(currentToken) + "<br/>";
      currentToken = "";
      continue;
    }
    if (assemblyCode[i] === ":" && !areWeInAString) {
      highlightedText += highlightToken(currentToken + assemblyCode[i]);
      currentToken = "";
      continue;
    }
    if ((assemblyCode[i] === " " || assemblyCode[i] === "\t" ||
         assemblyCode[i] === "," || assemblyCode[i] === "+" ||
         assemblyCode[i] === "-" || assemblyCode[i] === "*" ||
         assemblyCode[i] === "/" || assemblyCode[i] === "^") &&
        !areWeInAString) {
      highlightedText += highlightToken(currentToken) + assemblyCode[i];
      currentToken = "";
      continue;
    }
    if (assemblyCode[i] === '"' && !areWeInAString) {
      highlightedText += highlightToken(currentToken);
      currentToken = '"';
      areWeInAString = true;
      continue;
    }
    if ((assemblyCode[i] === "(" || assemblyCode[i] === ")" ||
         assemblyCode[i] === "[" || assemblyCode[i] === "]" ||
         assemblyCode[i] === "{" || assemblyCode[i] === "}") &&
        !areWeInAString) {
      highlightedText += highlightToken(currentToken) +
                         '<span class="parenthesis">' + assemblyCode[i] +
                         "</span>";
      currentToken = "";
      continue;
    }
    if (assemblyCode[i] !== '"') {
      currentToken += assemblyCode[i];
      continue;
    }
    if (assemblyCode[i] === '"' && areWeInAString) {
      highlightedText += highlightToken(currentToken + '"');
      currentToken = "";
      areWeInAString = false;
    }
  }
  highlightedText += highlightToken(currentToken);
  assemblyCodeDiv.innerHTML = highlightedText;
  // The following code is supposed to move the cursor to the correct
  // position, but it doesn't work.
  /*
  const range=document.createRange();
  range.setStart(assemblyCodeDiv,start);
  range.setEnd(assemblyCodeDiv,end);
  const selection=window.getSelection();
  selection.removeAllRanges();
  selection.addRange(range);
  */
  setUpLineNumbers();
  areWeHighlighting = false;
}
Any help is welcome!
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

JimmyTheLobster

  • 1588
  • +29/-56
Re: PicoBlaze Simulator in JavaScript
« Reply #10 on: July 25, 2023, 10:18:56 AM »
My poor eyes.

You know JavaScript has a switch statement?
"I'm not entirely sure who this guy is, but JimmyTheLobster is clearly a genius.  Probably one of the smartest arthropods  of his generation." - JimmyTheCrab

Quote from: bulmabriefs144
The woke left have tried to erase photosynthesis

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #11 on: July 25, 2023, 11:35:12 AM »
My poor eyes.

You know JavaScript has a switch statement?

Sure. I used the switch statement extensively in the core of my simulator: https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/blob/2390e425f3f7d5bcc435c5dd1ff54b4f2a85b6a5/simulator.js#L28
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #12 on: August 10, 2023, 09:34:04 AM »
This night, it occurred to me how I could simplify the algorithm I use to parse if-else-branches and while-loops in PicoBlaze Assembly. So, today, I implemented that simplified algorithm: https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/blob/master/parser.js
The resulting AST is, unless I am mistaken, the same for every possible input to the parser.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #13 on: August 16, 2023, 10:48:31 AM »
Yesterday, I tried to reproduce this weird bug in the preprocessor in a minimal reproducible example, but failed: https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/issues/8
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #14 on: August 21, 2023, 02:14:20 PM »
I just merged the first pull request I got on my PicoBlaze Simulator: https://github.com/FlatAssembler/PicoBlaze_Simulator_in_JS/pull/10
Apparently, there was a bug in the way I implemented the `sra` bit-shifting directive. Still, GitHub forks and stars won't help me pass my cybernetics test next week.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #15 on: September 10, 2023, 06:59:22 PM »
A few days ago, I noticed that the "Download Hexadecimal" feature of my PicoBlaze Simulator doesn't work in WebPositive on HaikuOS. Which is bad not only because it makes my PicoBlaze Simulator much less useful on HaikuOS (WebPositive being the only browser on HaikuOS which supports enough JavaScript to run my PicoBlaze Simulator), but because it suggests that maybe it doesn't work in Safari either. Namely, both Safari and WebPositive are based on WebKit. The MacBook Air my grandmother bought me back in 2013 stopped working in 2021, so I cannot test that myself. I sent a Viber message to my mentor Ivan Aleksi about that, because he has a Mac in his office, but he is not responding to me.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #16 on: September 15, 2023, 01:15:17 AM »
I modified the header of my PicoBlaze assembler and emulator to mention Agustin Izaguirre as an author. I guess it looks more professional if it's immediately obvious that it's an international open-source project. Maybe it motivates somebody else to join us.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #17 on: September 17, 2023, 11:58:55 AM »
I've tried to speed things up in my PicoBlaze Simulator by adding a checkbox enabling the user to disable updating registers and flags on every step. The "Fibonacci Sequence" example, on my machine, runs in 54 seconds if displaying registers and flags is enabled, and it runs in 27 seconds if they are disabled. That's a significant speed-up, but not as much as 12 times (down to 5 seconds) as Agustin Izaguirre claimed was possible to speed it up by disabling DOM manipulation.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory:

*

FlatAssembler

  • 775
  • +2/-7
  • Not a FE-er
Re: PicoBlaze Simulator in JavaScript
« Reply #18 on: October 01, 2023, 02:37:17 AM »
I regret choosing to do this thing as my Bachelor Thesis. My mentor is constantly asking me to add something or edit something, and he is demanding me to do that now. In my opinion, he is demanding way too much. If 4'000 lines of code and 29 pages of documentation, plus the fact that my program is used not only at my university, but also at a college in Argentine, is not enough, then nothing is. This is just a Bachelor Thesis, not a PhD.
In my opinion, the academics are trying to create the illusion of objectivity by using some sciency style. Which is ridiculous, as programming is not objective.
Fan of Stephen Wolfram.
This is my parody of the conspiracy theorists:
https://www.theflatearthsociety.org/forum/index.php?topic=71184.0
This is my attempt to refute the Flat-Earth theory: