Skip to content

Free42 program compiler and some miscellaneous programs.

Notifications You must be signed in to change notification settings

connorslade/dm42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Free42 program compiler and some miscellaneous programs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages