Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:53:13+00:00 2026-06-18T02:53:13+00:00

I’ve got a c++ library with a class that implements a virtual machine (called

  • 0

I’ve got a c++ library with a class that implements a virtual machine (called ‘VM’) of a custom programming language. This language have some different instructions that can be executed, among which there is “read value from input” instruction. The VM can be run in two modes: execute single instructions step by step (until machine is done) or execute all instructions at once. It can be also used in two applications: console and a GUI application.

Until now I had only a console application. When the “read value from input” instruction was executed, it just used std::cin to read the value, so the virtual machine stopped until the input was submitted. The problem occurs when I’m trying to create a GUI for the VM. I’ll use a typical text input instead of std::cin.

The question is: what do you think is the best way to model such problem from the point of executing instructions? How should the VM behave when the “read value from input” instruction is executed? Before a user click “execute single instruction” he doesn’t know what kind of instruction is it going to be, so he can’t submit the input before the instruction is executed.

I was thinking about adding a new state property to the VM: {working|awaiting_input}. During the “read” instruction runtime the machine should suspend until it gets the input. And when the GUI layer fetches the input from the user, it’d call VM’s passInput(inputValue) new method which additionally wakes VM up (to either finish the single instruction or all of them). Can you think of an easier solution (e.g. without adding a state property)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:53:14+00:00Added an answer on June 18, 2026 at 2:53 am

    The first step is to break out your “input” from being an integral part of the VM engine [which it sounds like it is now], so that when you get the “read value from input”, you just call a “do_input” function – a virtual function implemented in the “user_interface” class – which could be either UI or iostream.

    Whether it’s running in single-stop or “full speed” shouldn’t make any difference, the “instruction” doesn’t complete until the input has been gathered, right?

    Now, GUI can be quite tricky, as it tends to be event-driven, and input is just another event. However, if you implement your “do_input” function as a function that only return when input has been read, then it’s not really any big deal. You just need some (part of a) window as “this is where you enter input” and the user will have to type something to that. When the user hits enter (or clicks a button, etc), then you have your completed input.

    You may also want to have a mode where input is read from a file… 😉

    It probably is a bit more complicated than I’ve just described, but shouldn’t be a huge amount more than that. [I’ve done similar things in instruction simulators before, where one instruction can effectively take an “infinite” amount of time, because it waits for input].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.