Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedromsilvapt/stack-vm
A simple stack virtual machine simulator
https://github.com/pedromsilvapt/stack-vm
Last synced: 11 days ago
JSON representation
A simple stack virtual machine simulator
- Host: GitHub
- URL: https://github.com/pedromsilvapt/stack-vm
- Owner: pedromsilvapt
- Created: 2017-12-10T20:23:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-18T19:17:14.000Z (over 2 years ago)
- Last Synced: 2024-11-10T20:52:38.269Z (about 2 months ago)
- Language: TypeScript
- Size: 87.9 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stack-vm - A simple stack virtual machine simulator
> **Note** This project can be tested online at [https://npm.runkit.com/stack-vm](https://npm.runkit.com/stack-vm). Currently no graphical functions are implemented.
## Installation
> **Note** Requires a recent version of NodeJS and NPM installed on the systemTo use the program as a command line application, install like so:
```bash
npm install -g stack-vm
```To use the program using the JavaScript API, then run the comman:
```bash
npm install --save stack-vm
```# Command Line
Run the command:
```bash
stack-vm run ./source-code.vm
```If you want to execute the program step by step, execute as follows:
```bash
stack-vm run --step-by-step 1 ./source-code.vm
```# JavaScript API
```typescript
import { StackVM, StdActions, Parser } from "./index";const instructions = Parser.parse( `
start
pushi 2
writei
pushs "\n"
writes
stop
` );const vm = new StackVM( StdActions, instructions );
vm.executeAll()
.catch( error => console.error( error.message, error.stack ) );
```