GithubHelp home page GithubHelp logo

djiq / riasm Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 20 KB

RIASM is a basic, asm-like language interpreter that allows you to write your own instructions and define your own registers

License: Other

Rust 100.00%

riasm's Introduction

RIASM

RIASM stands for Rust Interpreter for ASM. It is a basic, asm-like language interpreter that allows you to write your own instructions and define your own registers, allowing you to embed this in for example some kind of game, allowing users to interface with a basic interpreter. The big benefit of using RIASM is that it is extremely bare bones, it posses no native instructions of it's own, and has no default registers, the end user must define every single one of these, allowing you to leverage it to define each instruction to mean whatever you like.

TODO

  • Make a String to AST scanner
  • Unshit *mut ASTDefinition to not use a raw pointer, but something like Rc or Arc
  • Add labels
  • Figure out how to make defining instructions not complete shit

How to build

cargo build --release

How To Use

Simply import

riasm::asm_definition::*;

and then use provided builder functions to construct and execute the asm interpreter you just built. Example:

use riasm::asm_definition::*;

fn main() {
    let text: String = "
MOV [R1] 0
MOV [R2] 1
loop:
ADD [R1] [R2]
ADD [R2] [R1]
PRINT [R1]
PRINT [R2]
JMP loop
"
    .into();

    ASMDefinition::new()
        .insert_register("R1")
        .insert_register("R2")
        .insert_register("R3")
        .insert_instruction("MOV", |state, arg| {
            arg[0].try_modify_register(arg[1].resolve())
        })
        .insert_instruction("ADD", |state, arg| {
            arg[0].try_modify_register(arg[0].resolve() + arg[1].resolve())
        })
        .insert_instruction("PRINT", |state, arg| println!("{}", arg[0].resolve()))
        .insert_instruction("JMP", |state, arg| state.jump_to_label(arg[0].resolve()))
        .interpret(text);
}

this will print the fibonnaci sequence till the program crashes due to rusts safety preventing the integer overflow

riasm's People

Contributors

djiq avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.