From 37fc8cec2651112d71d139d19f79b47b16b4261d Mon Sep 17 00:00:00 2001 From: "Marko A. Rodriguez" Date: Mon, 15 Jul 2024 04:01:06 -0600 Subject: [PATCH] tweaks to Kernel bootloader spec. nice push on docs. added color command to console. --- docs/src/fhatos.md | 58 ++++++++++++++++++++++--------- src/main.cpp | 13 +++---- src/structure/console/console.hpp | 8 ++++- src/structure/io/terminal.hpp | 2 +- src/structure/kernel.hpp | 11 ++++-- src/test_fhatos.hpp | 8 ++--- 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/docs/src/fhatos.md b/docs/src/fhatos.md index 3314837c..a0b4d10e 100644 --- a/docs/src/fhatos.md +++ b/docs/src/fhatos.md @@ -9,11 +9,20 @@ processes exist within a single [URI](https://en.wikipedia.org/wiki/Uniform_Reso rides atop [MQTT](https://en.wikipedia.org/wiki/MQTT) with various levels of access from thread local, to machine local and ultimately, globally via cluster remote. -### A Simple mm-ADT Program +### Booting FhatOS -FhatOS software can be written in C/C++ or mm-ADT (multi-model abstract data type). mm-ADT is a cluster-oriented -programming language and virtual machine founded on 5 _mono-types_ (**bool**, **int**, **real**, **uri**, and **str**) -and 2 _poly-types_ (**lst** and **rec**). mm-ADT programs are sent via message to the FhatOS scheduler and then spawned +#### Booting on Linux/Unix/Mac + +#### Booting on ESP32 + +#### Booting on ESP8266 + +### A FhatOS Language + +FhatOS software can be written in C/C++ or mm-ADT (**multi-model abstract data type**). mm-ADT is a cluster-oriented +programming language and virtual machine founded on 5 _mono-types_ (`bool`, `int`, `real`, `uri`, and `str`) +and 2 _poly-types_ (**lst** and **rec**), where `rec` is a `lst` of 2-`obj` `lsts` with particular semantics regarding +key uniqueness. mm-ADT programs are sent via message to the FhatOS scheduler and then spawned as a process accordingly. FhatOS provides a collection of device drivers and new device drivers can be written ( typically in C/C++). Provided drivers include pulse wave modulation, thermometer, gas, H-bridge, etc. sensors and actuators. @@ -27,9 +36,7 @@ thread[[setup => __] ``` ```.cpp -fhatos> __(0).define(/rec/person, - [name=>as(/str/), - age=>is(gt(0))]) +fhatos> define(/rec/person,[name=>as(/str/),age=>is(gt(0))]) ``` The `thread` object is published to the fURI endpoint `esp32@127.0.0.1/scheduler/threads/logger`. The scheduler spawns @@ -38,25 +45,44 @@ thread's id and halts. ```.cpp fhatos> thread[[setup => print('setup complete'), - loop => stop(_)]].to(/abc/)") + loop => stop(/abc/)]].to(/abc/) ``` ```.cpp -fhatos> __(0).from(127.0.0.1/kernel/scheduler/thread/abc) +fhatos> */abc/ ==> thread[[setup => print('setup complete'), - loop => pub(127.0.0.1/kernel/scheduler/thread/abc,Ø)]])") -fhatos> __(0).from(127.0.0.1/kernel/scheduler/thread/abc/loop) -==> __(0).pub(127.0.0.1/kernel/scheduler/thread/abc,Ø) + loop => stop(/abc/)]] +``` + +### A FhatOS Console + +> [!important] +> The FhatOS Console is a composite of 3 other actors: +> 1. The `Terminal` (`/sys/io/terminal/`) provides thread-safe access to hardware I/O. +> 2. The `Parser` (`/sys/lang/parser/`) converts string input to bytecode output. +> 3. The `Processor` (`/sys/lang/processor/`) executes bytecode. + +``` +terminal/in =[str]=> console + =[str]=> parser =bcode<~/abc>=> + processor =[objs]=> ~/abc + <=[objs]= console + =[str]=> terminal/out ``` ### fURI and MQTT [MQTT](https://en.wikipedia.org/wiki/MQTT) is a publish/subscribe message passing protocol that has found extensive -usage in embedded systems. Hierarchically specified _topics_ can be _subscribed_ and _published_ to. In MQTT, there is no direct communication between actors, though such behavior can be simulated if an actor's mailbox is a unique topic. FhatOS leverages MQTT, but from the vantage point of URIs instead of topics with message routing being location-aware. There exist three MQTT routers: +usage in embedded systems. Hierarchically specified _topics_ can be _subscribed_ and _published_ to. In MQTT, there is +no direct communication between actors, though such behavior can be simulated if an actor's mailbox is a unique topic. +FhatOS leverages MQTT, but from the vantage point of URIs instead of topics with message routing being location-aware. +There exist three MQTT routers: -1. `BCodeRouter`: An MQTT router scoped to a single thread of execution. -2. `LocalRouter`: An MQTT router scoped to the set of all threads on a machine. -3. `GlobalRouter`: An MQTT router scoped to the set of all threads across the cluster. +1. `MonadRouter`: An MQTT router scoped to an active monad (**thread**) processing a monoid (**program**). +2. `MonoidRouter`: An MQTT router scoped to a monoid (**program**). +3. `LocalRouter`: An MQTT router scoped to the current host (**machine**). +4. `GlobalRouter`: An MQTT router scoped to the current swarm (**cluster**). +5. `MetaRouter`: An MQTT router dynamically scoped to other routers based on fURI endpoints. > [!note] > The following is a list of common FhatOS fURI endpoints, where `fos:` is the namespace prefix diff --git a/src/main.cpp b/src/main.cpp index 97f785a5..21c077f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #ifndef FOS_ROUTERS #ifdef NATIVE @@ -42,17 +41,15 @@ using namespace fhatos; void setup() { - GLOBAL_OPTIONS->LOGGING = LOG_TYPE::INFO; - GLOBAL_OPTIONS->PRINTING = Ansi<>::singleton(); try { Kernel::build() - // ->log_level() - // ->printer() + ->initialPrinter(Ansi<>::singleton()) + ->initialLogLevel(INFO) ->withSplash(ANSI_ART) ->withNote("Use !bØ!! for noobj") ->withNote("Use !y:help!! for console commands") - ->usingScheduler(Scheduler::singleton("/sys/scheduler/")) - ->onBoot({FOS_ROUTERS, // + ->onBoot(Scheduler::singleton("/sys/scheduler/"), // + {FOS_ROUTERS, // Terminal::singleton("/sys/io/terminal/"), // Types::singleton("/sys/lang/type/"), // Parser::singleton("/sys/lang/parser/"), // @@ -72,7 +69,7 @@ void loop() { } #ifdef NATIVE -int main(int arg, char **argsv) { +int main(int, char **) { setup(); loop(); } diff --git a/src/structure/console/console.hpp b/src/structure/console/console.hpp index 7775bbf2..ada1d6b9 100644 --- a/src/structure/console/console.hpp +++ b/src/structure/console/console.hpp @@ -36,6 +36,8 @@ namespace fhatos { string _line; bool _newInput = true; bool _nesting = false; + bool _color = true; + ///// printers void printException(const std::exception &ex) const { Terminal::out(*this->id(), "!r[ERROR]!! %s", ex.what()); } void printPrompt(const bool blank = false) const { @@ -89,10 +91,14 @@ namespace fhatos { Terminal::currentOut()->toString().c_str(), Terminal::singleton()->id()->extend("out").toString().c_str()); }}}); + _MENU_MAP->insert( + {":color", + {"colorize output", [this](const Bool_p &xbool) { this->_color = xbool->bool_value(); }, + [this] { Terminal::printer<>()->printf("!ycolor!!: %s\n", FOS_BOOL_STR(this->_color)); }}}); _MENU_MAP->insert( {":nesting", {"display poly objs nested", [this](const Bool_p &xbool) { this->_nesting = xbool->bool_value(); }, - [this]() { Terminal::printer<>()->printf("!ynesting!!: %s\n", FOS_BOOL_STR(this->_nesting)); }}}); + [this] { Terminal::printer<>()->printf("!ynesting!!: %s\n", FOS_BOOL_STR(this->_nesting)); }}}); _MENU_MAP->insert({":shutdown", {"destroy scheduler", [this](const Obj_p &) { Scheduler::singleton()->stop(); }, [this]() { Scheduler::singleton()->stop(); }}}); diff --git a/src/structure/io/terminal.hpp b/src/structure/io/terminal.hpp index 57252cd4..9109abbc 100644 --- a/src/structure/io/terminal.hpp +++ b/src/structure/io/terminal.hpp @@ -34,7 +34,7 @@ namespace fhatos { Actor(id, [](Actor *actor) { actor->subscribe("out", [actor](const Message_p &message) { - if (Terminal::singleton()->_currentOutput->equals(message->source)) { + if (message->source.matches(*Terminal::singleton()->_currentOutput)) { const string copy = string(message->payload->str_value()); if (message->target.name() == "no_color") GLOBAL_OPTIONS->printer<>()->print(GLOBAL_OPTIONS->printer<>()->strip(copy.c_str())); diff --git a/src/structure/kernel.hpp b/src/structure/kernel.hpp index cb39e89e..4c5fd850 100644 --- a/src/structure/kernel.hpp +++ b/src/structure/kernel.hpp @@ -32,6 +32,14 @@ namespace fhatos { static Kernel *kernel = new Kernel(); return kernel; } + static Kernel *initialLogLevel(const LOG_TYPE level) { + GLOBAL_OPTIONS->LOGGING = level; + return Kernel::build(); + } + static Kernel *initialPrinter(Ansi<> *ansi) { + GLOBAL_OPTIONS->PRINTING = ansi; + return Kernel::build(); + } static Kernel *withSplash(const char *splash) { Terminal::printer<>()->print(splash); return Kernel::build(); @@ -40,8 +48,7 @@ namespace fhatos { Terminal::printer<>()->printf(FOS_TAB_4 "%s\n", notes); return Kernel::build(); } - static Kernel *usingScheduler(const Scheduler *scheduler) { return Kernel::build(); } - static Kernel *onBoot(const List processes) { + static Kernel *onBoot(const Scheduler* scheduler, const List processes) { bool success = true; for (Process *process: processes) { success = success && Scheduler::singleton()->spawn(process); diff --git a/src/test_fhatos.hpp b/src/test_fhatos.hpp index 9d0bb83b..e033fbf9 100644 --- a/src/test_fhatos.hpp +++ b/src/test_fhatos.hpp @@ -60,14 +60,14 @@ namespace fhatos { #define FOS_RUN_TESTS(x) \ void RUN_UNITY_TESTS() { \ try { \ - GLOBAL_OPTIONS->LOGGING = LOG_TYPE::TRACE; \ - GLOBAL_OPTIONS->PRINTING = Ansi::singleton(); \ Kernel::build() \ + ->initialPrinter(Ansi<>::singleton()) \ + ->initialLogLevel(INFO) \ ->withSplash(ANSI_ART) \ ->withNote("Use !bØ!! for noobj") \ ->withNote("Use :help for console commands") \ - ->usingScheduler(Scheduler::singleton("/sys/scheduler/")) \ - ->onBoot({FOS_TEST_ROUTERS, Types::singleton("/sys/lang/type/"), Parser::singleton("/sys/lang/parser/")}) \ + ->onBoot(Scheduler::singleton("/sys/scheduler/"), \ + {FOS_TEST_ROUTERS, Types::singleton("/sys/lang/type/"), Parser::singleton("/sys/lang/parser/")}) \ ->loadModules({"/ext/process"}); /*->defaultOutput("/home/root/repl/") */ \ UNITY_BEGIN(); \ x; \