Harvest Moon: (More) Friends of Mineral Town event script compiler

Overview

mary

This is a script compiler for Harvest Moon: Friends of Mineral Town and Harvest Moon: More Friends of Mineral Town for the GBA. The end goal is for it to be able to recompile decompiled vanilla scripts into the exact same bytecode.

This is a very rough and minimal version that I wrote over the weekend. I think it works, but I haven't had the chance to test or document much of it yet.

If you are looking for my old attempt at writing this in C++, see StanHash/mary_old.

Usage

mary INPUT > OUTPUT

The input is a file written in a custom script syntax. The output is a fragment of C that defines the data objects for the scripts defined in the source file.

Build

Install Rust development tools if you haven't already. (cargo, rustc, etc.)

cargo build --release

You will find the mary executable into the target/release directory.

Example script

// Script 1 of MFoMT

func 0x106 Func106()
func 0x117 Func117(a)
proc 0x105 Func105(a, b, c)
proc 0x01F Func01F()
proc 0x022 Func022(a)
proc 0x021 Func021()
proc 0x011 Func011(a, b, c)

const CONST_36 = 0x36
const MESSAGE = "\xFF%is \r\nprengant!\x05"

script 1 EventScript_1
{
    var var_0 = Func106()
    var var_1 = CONST_36 + var_0

    if Func117(var_0)
    {
        Func105(0, 1, var_0)
    }
    else
    {
        Func105(0, 2, var_0)
    }

    Func01F()
    Func022(MESSAGE)
    Func021()
    Func011(var_1, 1, 0)
}

Script constructs

// line comment

/*
multiline
comment
*/

Toplevel constructs

func ID NAME(PARAM, ...) // defines a native function.
proc ID NAME(PARAM, ...) // procs are functions that do not return a value.

const NAME = VALUE // defines a constant. Constants must be evaluatable at compile-time

script ID NAME { ... } // defines a script

Script body constructs

// define a constant, same rules as toplevel constants
const NAME = VALUE, ...

// define a variable
var NAME, ...
var NAME = VALUE, ...

// assign to a variable
NAME = VALUE

// call a function or procedure
NAME(ARG, ...)

// conditional. Braces are mandatory
if EXPR { ... }
if EXPR { ... } else { ... }

// for loop. Braces are mandatory
for var i = 0; i < 10; i++ { ... }

// do-while loop. Braces are mandatory
do { ... } while EXPR

// switch statement
switch EXPR
{
    case VALUE { ... }
    ...
    default { ... } // optional
}

TODO

  • Unit tests
  • Decompiler (matching and symmetrical with compiler)
  • Test correctness of generated code
  • Better error checking (function/procedure call parameter count coherence)
  • Better error reporting (locations...)

See also

You might also like...
The first cesil transpiler/compiler in 50 years!
The first cesil transpiler/compiler in 50 years!

CesilC CESIL, or Computer Education in Schools Instruction Language, is a programming language designed to introduce pupils in British secondary schoo

ArbOS operating system, to run at Layer 2 on Arbitrum chains. Also a compiler for Mini, the language in which ArbOS is written.

ArbOS and Mini compiler ArbOS is the "operating system" that runs at Layer 2 on an Arbitrum chain, to manage the chain's operation, maintain security,

The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language.

rcc The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language. Compilers Language Co

A rust version of "the super tiny compiler"

The (Rust) super tiny compiler This project is a rust version of the super tiny compiler (the original one (JS) was created by Jamie Kyle). The output

A tool & library to help you with the compiler course.

Compiler Course Helper Support: eliminate left recursion (require grammar with no cycles or ϵ-production) calculate nullable, first sets, follow, sets

Rust lib for fetching official protoc (Protocol Buffer compiler) releases

protoc-fetcher Rust library for fetching official Protocol Buffer compiler (protoc) releases, pegged to a specific version. protoc-fetcher downloads a

A additional Rust compiler pass to detect memory safe bugs of Rust programs.

SafeDrop A additional Rust compiler pass to detect memory safe bugs of Rust programs. SafeDrop performs path-sensitive and field-sensitive inter-proce

The compiler for Gera, a statically typed and garbage collected programming language.

Gera The compiler for Gera, a satically typed and garbage collected programming language. Currently WIP (Work in progress). Progress This is a rough o

A toy event store and event messaging system.

RDeeBee Follow this blog series for more details on this project. This system is inspired by Martin Kleppman's arguments that Event Sourcing system an

syd: siderial and moon tracker

This is code based on the 'minimal' template ca. 2022Q1 (RTIC 1.0). It drives a siderial tracker for the northern hemisphere that can run at three different speeds. It runs on a bluepill (stm32f103).

Fast command-line application to show the moon phase

moon-phases Command-line application to show the moon phase for a given date and time, as a text string, emoji, or numeric value. It can also show the

Play Onitama in your browser, compete with friends or lose to a bot

Play Onitama in your browser, compete with friends or lose to a bot

The Big Cheese a webapp wherein you can share recipes with your friends.

The Big Cheese The Big Cheese a webapp wherein you can share recipes with your friends. Contributing Contributions are what make the open source commu

NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game
NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game

Neos Peeps NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game. It also has a bunch

Answering the question nobody asked: what if you wanted to text your friends using only ARP?
Answering the question nobody asked: what if you wanted to text your friends using only ARP?

arpchat so... you know arp? the protocol your computer uses to find the mac addresses of other computers on your network? yeah. that. i thought it wou

Make friends while searching.
Make friends while searching.

searchbuddy Make friends while searching! Searchbuddy is a browser extension that lets you chat with people that are searching for what you're searchi

Bruteforce connecting to a specific Sea of Thieves server. Useful if you want to be in the same server as your friends.

SoT Server Finder Find which Sea of Thieves server you're connected to. Useful if you want to be in the same server as your friends. Setup Download so

a Solana program for granting friends permissions on your account without revealing your private key.
a Solana program for granting friends permissions on your account without revealing your private key.

Delegatooooor Granting Permission: An account holder (the delegator) decides to grant permission to a delegate. They create and sign a transaction tha

Tools - The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.
Tools - The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.

Rome is currently being rewritten in Rust. Read more about it in our latest blog post. The documentation below is out of date and available for poster

Owner
Nat (Stan)
ROM Hacker
Nat (Stan)
Rust library to facilitate event-driven programming.

Squeak Squeak is a zero-dependency Rust library to facilitate event-driven programming. Examples use squeak::{Delegate, Response}; let on_damage_rece

Antoine Gersant 58 Dec 31, 2022
Domain modeling. Event sourcing. CQRS.

f(model) - Functional Domain Modeling with Rust Publicly available at crates.io and docs.rs When you’re developing an information system to automate t

Fraktalio 12 Oct 7, 2023
Simple Event-Driven Microservice Architecture in Rust

Simple Event-Driven Microservice Architecture in Rust is an open-source project showcasing the simplicity and efficiency of building microservices in Rust. This minimalistic project demonstrates an e-commerce backend system, featuring just two microservices: Catalog and Order.

James Mallon 4 Dec 19, 2023
Leetcode Solutions in Rust, Advent of Code Solutions in Rust and more

RUST GYM Rust Solutions Leetcode Solutions in Rust AdventOfCode Solutions in Rust This project demostrates how to create Data Structures and to implem

Larry Fantasy 635 Jan 3, 2023
Tools to feature more lenient Polonius-based borrow-checker patterns in stable Rust

Though this be madness, yet there is method in 't. More context Hamlet: For yourself, sir, shall grow old as I am – if, like a crab, you could go back

Daniel Henry-Mantilla 52 Dec 26, 2022
Unify your game sources in one place and aquire more of them, using modules made by the community.

Project Black Pearl Unify your game sources in one place by using modules made by the community. What is Project Black Pearl? Project Black Pearl (or

Project Black Pearl 8 Jan 15, 2023
sodiumoxide clone, now with less chlorides and more oxides

sodiumoxide2 Less Chlorides, more Oxides! This package is a fork of sodiumoxide, using rust-native crypto. It's not intended to be easy to use or impl

Conrad Ludgate 3 Apr 16, 2023
Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

PKU Compiler Course 13 Aug 28, 2022
P523 is a classic compiler course taught by R. Kent Dybvig.

P523 is a classic compiler course taught by R. Kent Dybvig. This repo implements the course using Rust, provides a framework to help you master P523.

Sirius Demon 44 Dec 26, 2022
Bril: A Compiler Intermediate Representation for Learning

Bril: A Compiler Intermediate Representation for Learning Bril (the Big Red Intermediate Language) is a compiler IR made for teaching CS 6120, a grad

Lesley Lai 0 Dec 5, 2022