https://github.com/connorslade/dm42
Free42 program compiler and some miscellaneous programs.
https://github.com/connorslade/dm42
dm42 free42 hp42s swissmicros
Last synced: 2 months ago
JSON representation
Free42 program compiler and some miscellaneous programs.
- Host: GitHub
- URL: https://github.com/connorslade/dm42
- Owner: connorslade
- Created: 2023-11-09T16:12:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-02T01:04:41.000Z (5 months ago)
- Last Synced: 2025-02-10T13:43:36.426Z (4 months ago)
- Topics: dm42, free42, hp42s, swissmicros
- Language: Rust
- Homepage:
- Size: 105 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dm42 [](https://github.com/Basicprogrammer10/dm42/actions/workflows/rust.yml)
Various programs for the [Swissmicros DM42](https://www.swissmicros.com/product/dm42) and a preprocessor / transpiler for creating them.
## Programs
- [Statistics](bin#statistics) — Various statistics functions for use on N×1 matrices
- [Fractions](bin#fractions) — Operations for working with exact fractions
- [Unit converter](bin#unit-converter) — A simple unit convertor
- [Boombox](bin#boombox) — Collection of songs you can play through the buzzer
- [Keyboard](bin#keyboard) — Play music using your calculator's built in buzzer
- [Physical Constants](bin#physical-constants) — Lets you push various physical constants onto the stack
- [Miscellaneous Functions](bin#miscellaneous-functions) — Miscellaneous mathematical functions missing from the 42s
- [Matrix Sorter](bin#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](grammer) for pretty syntax highlighting.```cpp
export def sort {
if { MAT? } else {
"X is not a matrix", AVIEW
STOP
}STO "A"
INDEX "A"
1, 1, STOIJ
DROPN 2while { 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.```cpp
// 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
- [x] Finish parser / tokenizer
- [x] Base
- [x] Functions
- [x] If
- [x] Raw-If
- [x] While
- [x] Do While
- [x] Finish codegen
- [x] Functions
- [x] If-statements
- [x] While loops
- [x] Do While
- [ ] Future Ideas
- [ ] For loops
- [ ] Decent error reporting
- [ ] Inline functions
- [ ] vscode lang grammer
- [ ] Basic documentation
- [ ] Macros
- [ ] Imports
- [x] CLI
- [ ] Automatically cut strings
- [ ] Figure out reusing functions across exported functions
- [x] Comments
- [ ] Anonyms functions
- [ ] Label keyword