Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
/ Abstract-VM Public archive

A Virtual Machine that uses a stack to compute simple arithmetic expressions.

Notifications You must be signed in to change notification settings

omiroshn/Abstract-VM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract-VM

AbstractVM is a machine that uses a stack to compute simple arithmetic expressions. These arithmetic expressions are provided to the machine as basic assembly programs.

The project

As for any assembly language, the language of AbstractVM is composed of a series of instructions, with one instruction per line. However, AbstractVM’s assembly language has a limited type system, which is a major difference from other real world assembly languages.

Compile

Just execute the make command to launch the compilation.

Tests

Some tests are provided, run sh run_error_tests.sh and magic happens.

About

Abstract-VM is a 42 school project.

Instructions

Instruction Details
push value Pushes the value v at the top of the stack. The value must have one of the following form:
  • int8(n) : Creates an 8-bit integer with value n.
  • int16(n) : Creates a 16-bit integer with value n.
  • int32(n) : Creates a 32-bit integer with value n.
  • float(z) : Creates a float with value z.
  • double(z) : Creates a double with value z.
pop Unstacks the value from the top of the stack.
dump Displays each value of the stack, from the most recent one to the oldest one.
assert value Asserts that the value at the top of the stack is equal to the one passed as parameter for this instruction.
add Unstacks the first two values on the stack, adds them together and stacks the result.
sub Unstacks the first two values on the stack, subtracts them, then stacks the result.
mul Unstacks the first two values on the stack, multiplies them, then stacks the result.
div Unstacks the first two values on the stack, divides them, then stacks the result.
mod Unstacks the first two values on the stack, calculates the modulus, then stacks the result.
print Asserts that the value at the top of the stack is an 8-bit integer. (If not, see the instruction assert), then interprets it as an ASCII value and displays the corresponding character on the standard output.
exit Terminate the execution of the current program.
Comments Comments start with a ’;’ and finish with a newline.

Bonuses

  • Color output
  • Doesn't stop at the first error met
  • Advanced parsing: regex are used
  • Сustom exceptions, which are inherited from a more specific class than std::exception
  • 5 Instructions
Instruction Details
sum Summarizes the values on the stack and prints the result.
avg Displays average value of the stack.
sort Sorts the stack, from minimum to maximum.
min Displays minimum value of the stack.
max Displays maximum value of the stack.

** Message to 42/Unit Factory students **

You are free to copy, modify and share under your name my exercises. But you will learn nothing, or will have the impression to understand without be able to do it again alone. Be responsible and simply ask for help.

                                                                                           omiroshn

About

A Virtual Machine that uses a stack to compute simple arithmetic expressions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published