Giter VIP home page Giter VIP logo

dm42's Introduction

dm42 Build

Various programs for the Swissmicros DM42 and a preprocessor / transpiler for creating them.

Programs

  • Statistics — Various statistics functions for use on N×1 matrices
  • Fractions — Operations for working with exact fractions
  • Unit converter — A simple unit convertor
  • Boombox — Collection of songs you can play through the buzzer
  • Keyboard — Play music using your calculator's built in buzzer
  • Physical Constants — Lets you push various physical constants onto the stack
  • Miscellaneous Functions — Miscellaneous mathematical functions missing from the 42s
  • Matrix Sorter — Sorts a matrix column, used in the statistics program

Preprocessor

This code makes uses of function definitions, if statements, and while loops and can be compiled down into plain 42s instructions. If you decide to work with this language and use vs code, consider installing the language grammars for pretty syntax highlighting.

export def sort {
    if { MAT? } else {
        "X is not a matrix", AVIEW
        STOP
    }

    STO "A"
    INDEX "A"
    1, 1, STOIJ
    DROPN 2

    while { FC? 76 } {
        [MIN]
        DROP
        RCLIJ
        DROP
        R<>R
        DROPN 2
        I+
    }

    RCL "A"
}

Documentation

This is for when I inevitability forget all of this syntax that I totally put so much thought into. Anyway, there are currently four things added by this transpiler / preprocessor, Functions, Function calls, If statements, and While (or Do-while) loops. Below are some examples of each.

// Zeros out the X reg by repeatedly subtracting 1
// Because the function is being exported, it will be globally accessibly (in the EXQ menu)
export def zero {
    // Each block here must return one value by putting it in X
    // The value will be dropped before any other user code is run
    // To use a do-while loop, one must simple replace "while" with "do while"
    while { DUP } > { 0 } {
        // This expands to "1\n"
        1, -
    }
}

export def cmat {
    // This kind of condition without the comparison lets you bring your own instruction to selectively execute the following instruction
    // Also notice the missing then case, this was done to basically invert the result of MAT?
    if { MAT? } else {
        "X is not a matrix", AVIEW
        // Calls the "zero" function from above
        zero()
        STOP
    }
}

Todo

  • Finish parser / tokenizer
    • Base
    • Functions
    • If
    • Raw-If
    • While
    • Do While
  • Finish codegen
    • Functions
    • If-statements
    • While loops
    • Do While
  • Future Ideas
    • For loops
    • Decent error reporting
    • Inline functions
    • vscode lang grammer
    • Basic documentation
    • Macros
    • Imports
    • CLI
    • Automatically cut strings
    • Figure out reusing functions across exported functions
    • Comments
    • Anonyms functions
    • Label keyword

dm42's People

Contributors

connorslade 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.