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

  • Home
  • SEARCH
  • 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 543989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:36:27+00:00 2026-05-13T10:36:27+00:00

I want self-education purpose implement a simple virtual machine for a dynamic language, prefer

  • 0

I want self-education purpose implement a simple virtual machine for a dynamic language, prefer in C. Something like the Lua VM, or Parrot, or Python VM, but simpler. Are there any good resources/tutorials on achieving this, apart from looking at code and design documentations of the existing VMs?

Edit: why close vote? I don’t understand – is this not programming. Please comment if there is specific problem with my question.

  • 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-05-13T10:36:28+00:00Added an answer on May 13, 2026 at 10:36 am

    I assume you want a virtual machine rather than a mere interpreter. I think they are two points on a continuum. An interpreter works on something close to the original representation of the program. A VM works on more primitive (and self-contained) instructions. This means you need a compilation stage to translate the one to the other. I don’t know if you want to work on that first or if you even have an input syntax in mind yet.

    For a dynamic language, you want somewhere that stores data (as key/value pairs) and some operations that act on it. The VM maintains the store. The program running on it is a sequence of instructions (including control flow). You need to define the set of instructions. I’d suggest a simple set to start with, like:

    • basic arithmetic operations, including arithmetic comparisons, accessing the store
    • basic control flow
    • built-in print

    You may want to use a stack-based computation approach to arithmetic, as many VMs do. There isn’t yet much dynamic in the above. To get to that we want two things: the ability to compute the names of variables at runtime (this just means string operations), and some treatment of code as data. This might be as simple as allowing function references.

    Input to the VM would ideally be in bytecode. If you haven’t got a compiler yet this could be generated from a basic assembler (which could be part of the VM).

    The VM itself consists of the loop:

    1. Look at the bytecode instruction pointed to by the instruction pointer.
    2. Execute the instruction:
       * If it's an arithmetic instruction, update the store accordingly.
       * If it's control flow, perform the test (if there is one) and set the instruction pointer.
       * If it's print, print a value from the store.
    3. Advance the instruction pointer to the next instruction.
    4. Repeat from 1.
    

    Dealing with computed variable names might be tricky: an instruction needs to specify which variables the computed names are in. This could be done by allowing instructions to refer to a pool of string constants provided in the input.

    An example program (in assembly and bytecode):

    offset  bytecode (hex)   source
     0      01 05 0E         //      LOAD 5, .x
     3      01 03 10         // .l1: LOAD 3, .y
     6      02 0E 10 0E      //      ADD .x, .y, .x
    10      03 0E            //      PRINT .x
    12      04 03            //      GOTO .l1
    14      78 00            //      .x: "x"
    16      79 00            //      .y: "y"
    

    The instruction codes implied are:

    "LOAD x, k" (01 x k) Load single byte x as an integer into variable named by string constant at offset k.
    "ADD k1, k2, k3" (02 v1 v2 v3) Add two variables named by string constants k1 and k2 and put the sum in variable named by string constant k3.
    "PRINT k" (03 k) Print variable named by string constant k.
    "GOTO a" (04 a) Go to offset given by byte a.
    

    You need variants for when variables are named by other variables, etc. (and the levels of indirection get tricky to reason about). The assembler looks at the arguments like “ADD .x, .y, .x” and generates the correct bytecode for adding from string constants (and not computed variables).

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

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Blogger API is deprecated, use GData API. Documentation contains examples… May 15, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer I've just finished an application that does exactly this, i.e.… May 15, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer You need to return a valid JSON string. You can… May 15, 2026 at 2:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.