Skip to content

Commit

Permalink
Fixed RishkaVM class usage on examples. GH-3
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Mar 10, 2024
1 parent 483027f commit cd52c6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
15 changes: 8 additions & 7 deletions examples/ili9341_example/ili9341_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
fabgl::ILI9341Controller DisplayController;
fabgl::Terminal Terminal;

// Rishka virtual machine instance
rishka_virtual_machine vm;
// SPI instance for SD card
SPIClass sdSpi(HSPI);

Expand All @@ -63,15 +61,18 @@ void setup() {
return;
}

// Rishka virtual machine instance
RishkaVM* vm = new RishkaVM();
// Initialize Rishka VM
rishka_vm_initialize(&vm, &Terminal);
if(!rishka_vm_loadfile(&vm, "/sysinfo.bin"))
rishka_vm_panic(&vm, "Failed to load specified file.");
vm->initialize(&Terminal);

if(!vm->loadFile("/sysinfo.bin"))
vm->panic("Failed to load specified file.");

// Run loaded program
rishka_vm_run(&vm, 0, NULL);
vm->run(0, NULL);
// Reset VM after program execution
rishka_vm_reset(&vm);
vm->reset();
}

void loop() {
Expand Down
15 changes: 9 additions & 6 deletions examples/shell_example/shell_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
fabgl::ILI9341Controller DisplayController;
fabgl::Terminal Terminal;

// Rishka virtual machine instance
rishka_virtual_machine vm;
// SPI instance for SD card
SPIClass sdSpi(HSPI);

Expand Down Expand Up @@ -88,21 +86,26 @@ void loop() {
Terminal.print(input);
Terminal.print("\r\e[97m");

// Rishka virtual machine instance
RishkaVM* vm = new RishkaVM();
// Initialize Rishka virtual machine
rishka_vm_initialize(&vm, &Terminal);
vm->initialize(&Terminal);

// Attempt to load specified file into Rishka virtual machine
if(!rishka_vm_loadfile(&vm, input.c_str())) {
if(!vm->loadFile(input.c_str())) {
// If loading file fails, print error message and return
Terminal.print("Failed to \e[94mload\e[97m specified file: " + input);
Terminal.print("\r\e[32m#~\e[97m ");
return;
}

// Run loaded program on Rishka virtual machine
rishka_vm_run(&vm, 0, NULL);
vm->run(0, NULL);
// Reset Rishka virtual machine for next execution
rishka_vm_reset(&vm);
vm->reset();

// Delete VM instance.
delete vm;

// Print prompt for next input
Terminal.print("\e[32m#~\e[97m ");
Expand Down

0 comments on commit cd52c6a

Please sign in to comment.