Giter Club home page Giter Club logo

bm's Introduction

bm

Simple compiler ecosystem. Includes the backend and frontend for a couple of languages.

Subprojects

  • bm — VM Bytecode Definitions and Emulators.
  • basm — Assembler for the VM Bytecode.
  • debasm — Disassembler for the VM Bytecode.
  • bdb — Debugger for the VM Bytecode.
  • bang logo — Procedural Programming Language that Compiles to the VM Bytecode.

Quick Start

To build and test the entire project bootstrap the root nobuild and run it like so:

$ cc -o nobuild nobuild.c
$ ./nobuild test

For more info do ./nobuild help

bm's People

Contributors

billkek avatar bit69tream avatar bossek avatar catull avatar ciremun avatar derpandaz avatar drakexorn avatar geilolo avatar herrhotzenplotz avatar kolumb avatar rexim avatar yangelis avatar zhiayang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bm's Issues

Differing definitions of `int64_t` on macos

On macos (no idea about "real" BSD), int64_t is defined as long long, while on linux it's defined as long. This causes issues with the printf formatting generating warnings (it won't actually affect the runtime since long is still also 8 bytes)

There's inttypes.h and PRId64 nonsense, but that might get ugly...

Suggestion: File marker, versioning

The birtual machine file could have a marker, like "BRCH".

That way, the magic(5) database and file(1)command would tell the user that it is a Birtual Machine binary file.
That marker could be followed by a version, say a 32-bit.

Evidently, the bme would have to skip the two fields before executing any instructions.

Instruction handler mapping complexity

Currently, mapping instructions to handlers is done using a switch statement. To my knowledge, because it's basically nested if statements, this will produce an O(log n) complexity mapping at best. You can use an array containing pointers to handlers, using instructions as indices, to achieve O(1) complexity.

I understand this might be beyond the scope of this project, but I still wanted to point this out because of the educational value.

typedef enum
{
    INST_NOP = 0,
    // ...
} Inst;

Err handle_nop(Bm *bm)
{
    bm->ip++;
    return ERR_OK;
}

// ...

Err (*inst_map[])(Bm *) = {
    handle_nop,
    // ...
};

Err bm_execute_inst(Bm *bm)
{
    // ...
    return inst_map[bm->inst.type](bm);
}

Argument passing from CLI

Dear BMers

Imagine an extension of the Fibonacci implementation, where we would pass an argument N (numeric) "into" it.

How would we support it ?

One approach is to have access to argument count and vector, e.g. some form of global variable, like $argc and $argv.

Another way would be to be able to call call some OS input reading function.

A third one would be patching some operand between BM instantiation and its execution.

Say we had the code below, with the initial push instruction to be 10.
Changing this operand to 23 could be accomplished with:

./bme -i examples/fib.bm --patch-at 0 --patch-operand 23

or

./bme -i examples/fib.bm --patch 0:operand 23

Here's an incomplete Fibonacci implementation:

counter:
     push 10   # operand could be changed before execution

# First two Fibonacci numbers
   push 0
   push 1

loop:
   # check is counter is now 0
   # .......
   jmp_if halt
   dup 1
   dup 1
   plusi
   # decrement counter
   # ......
   jmp loop

halt:
   halt

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.