/*
   3BC Language - Low level language,
   tiny virtual machine that works on computers and microcontrollers.
   release: v0.1.0
   https://github.com/RodrigoDornelles/3bc-lang
*/

#define _3BC_DISABLE_INTERPRETER
#define BLINK_DELAY_MS 1000
#define LED_RED        12

#include <3bc.h>

app_3bc_t VM;

void setup() {
  VM = lang_3bc_init();

  Serial.begin(9600);

  lang_3bc_print(VM, tty_output, [](char* output) {
    Serial.write(output);
  });

  lang_3bc_line(VM, MODE, NILL, 2);
  lang_3bc_line(VM, STRC, NILL, 'H');
  lang_3bc_line(VM, STRC, NILL, 'e');
  lang_3bc_line(VM, STRC, NILL, 'l');
  lang_3bc_line(VM, STRC, NILL, 'l');
  lang_3bc_line(VM, STRC, NILL, 'o');
  lang_3bc_line(VM, STRC, NILL, ',');
  lang_3bc_line(VM, STRC, NILL, ' ');
  lang_3bc_line(VM, STRC, NILL, '3');
  lang_3bc_line(VM, STRC, NILL, 'b');
  lang_3bc_line(VM, STRC, NILL, 'c');
  lang_3bc_line(VM, STRC, NILL, '-');
  lang_3bc_line(VM, STRC, NILL, 'l');
  lang_3bc_line(VM, STRC, NILL, 'a');
  lang_3bc_line(VM, STRC, NILL, 'n');
  lang_3bc_line(VM, STRC, NILL, 'g');
  lang_3bc_line(VM, STRC, NILL, '!');
  lang_3bc_line(VM, STRC, NILL, '\n');

  lang_3bc_line(VM, MODE, NILL, MODE_MEMORY);
  lang_3bc_line(VM, MUSE, LED_RED, MEM_CONFIG_GPIO_SEND);
  lang_3bc_line(VM, NILL, NILL, LED_RED);
  lang_3bc_line(VM, ALOC, LED_RED, HIGH);
  lang_3bc_line(VM, MODE, NILL, MODE_SLEEP);
  lang_3bc_line(VM, MILI, NILL, BLINK_DELAY_MS);
  lang_3bc_line(VM, MODE, NILL, MODE_MEMORY);
  lang_3bc_line(VM, ALOC, LED_RED, LOW);
  lang_3bc_line(VM, MODE, NILL, MODE_SLEEP);
  lang_3bc_line(VM, MILI, NILL, BLINK_DELAY_MS);
  lang_3bc_line(VM, MODE, NILL, MODE_JUMP);
  lang_3bc_line(VM, GOTO, NILL, LED_RED);
}

void loop() {
  lang_3bc_update(VM);
}