RodrigoDornelles / 3bc-lang

Low-level language, tiny virtual machine, minimal runtime, intermediate representation, embeddable, easy for beginners. (Friendly Punched cards)
https://3bc-lang.org
GNU General Public License v3.0
242 stars 27 forks source link

use packages to be modular rather than monolithic? #368

Open RodrigoDornelles opened 2 years ago

RodrigoDornelles commented 2 years ago

Please Describe The Problem To Be Solved

an initial idea, of how to organize the structure of the virtual machine's source code to scale in support times and still maintain performance and compatibility.

RodrigoDornelles commented 2 years ago

some ideia

struct tbc_package_link_st {
    tbc_nametable_st package_ptr;
    tbc_anyfunc_ut package_func;
};

struct tbc_package_st {
    tbc_package_link_st package_id;
    tbc_package_link_st package_funcs;
};

struct tbc_nametable_st {
    void*(char*) put;
}

static const tbc_nametable_st = {
    NULL
};

static const tbc_package_link_st tbc_package_empty[] = {
    (tbc_package_st*) &tbc_nametable_st.put, NULL;
};

static const tbc_package_st[] = {
    TBC_PACKAGE_EMPTY, tbc_package_empty,
}
RodrigoDornelles commented 2 years ago
#include "../src/3bc.h"
#include "../src/pkg/nes.h"

int main(int argc, char** argv)
{
    uint8_t appid = app_3bc_temp_init();

    app_3bc_package(appid, TBC_PKG_NES_DEFAULT, tbc_nes_pkg_joystick_input); /** register in pkg **/
    app_3bc_package(appid, TBC_PKG_NES_DEFAULT, tbc_nes_pkg_fullscreen_output); /** register in pkg **/
    app_3bc_install(appid, TBC_PKG_NES_DEFAULT); /** update name tables **/
    app_3bc_package_flush(appid); /** clean list of packages */

    while (app_3bc_running(appid)){
        app_3bc_update(appid);
    }

    app_3bc_destroy(appid);
    return 0;
}
RodrigoDornelles commented 2 years ago

header definition

  1. Enumeratorsenum ___tbc_name_e
  2. Type definitions typedef struct ___tbc_name_s tbc_name_st
  3. Unions union ___tbc_name_u {}
  4. Structures struct ___tbc_name_s {}
  5. Constants #define name ((type)value)
RodrigoDornelles commented 2 years ago
#include <3bc.h>
#include <3bc-pkg-cpp.h>
#include <3bc-pkg-serial/pkg-arduino.h>
#include <3bc-pkg-gpio/pkg-arduino.h>

uint8_t id_3bc;

const static char code[] = "7.0.2,4.0.3,4.0.188";

void setup()
{
    app_3bc_install(NULL, pkg_arduino_gpio);
    app_3bc_install(NULL, pkg_arduino_serial);

    id_3bc = app_3bc_new();
    app_3bc_set(id_3bc, TTY_SOURCE, TTY_ARDUINO_SERIAL, "19200");
    app_3bc_set(id_3bc, TTY_SOURCE, TTY_FROM_BUFFER, code);
}

loop()
{
    app_3bc_update(id_3bc);   
}

-------------------------------------

tbc_class_t app (pkg_arduino_serial, pkg_arduino_gpio);

void setup ()
{
    app.tty.output.baudrate(19600);
    app.tty.source.load_buffer(code);
}

void loop()
{
    app.update();
}
RodrigoDornelles commented 2 years ago
#include <3bc.h>
#include <3bc/pkg/pkg-nes.h>

static tbc_u8_t app;
static const tbc_u8_t prog[] = {
    MODE, NILL, 0x02,
    STRX, NILL, 0x03,
    STRX, NILL, 0xBC
};

void main()
{
    app = app_3bc_new();
    app_3bc_install(app, pkg_nes_ram_512); 
    app_3bc_install(app, pkg_nes_prog_fixed_array);
    app_3bc_install(app, pkg_nes_output_fullscreen); 
    app_3bc_set(app, TTY_SOURCE, TTY_BUFFER, prog);

    for (;;) {
        app_3bc_update(app);
        wait_nmi();
    }
}