Skip to content

Commit

Permalink
tweaks to Kernel bootloader spec. nice push on docs. added color comm…
Browse files Browse the repository at this point in the history
…and to console.
  • Loading branch information
okram committed Jul 15, 2024
1 parent a4cd3ac commit 37fc8ce
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
58 changes: 42 additions & 16 deletions docs/src/fhatos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <language/types.hpp>
#include <structure/console/console.hpp>
#include <structure/io/terminal.hpp>
#include <util/options.hpp>

#ifndef FOS_ROUTERS
#ifdef NATIVE
Expand All @@ -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/"), //
Expand All @@ -72,7 +69,7 @@ void loop() {
}

#ifdef NATIVE
int main(int arg, char **argsv) {
int main(int, char **) {
setup();
loop();
}
Expand Down
8 changes: 7 additions & 1 deletion src/structure/console/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(); }}});
Expand Down
2 changes: 1 addition & 1 deletion src/structure/io/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
11 changes: 9 additions & 2 deletions src/structure/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<Process *> processes) {
static Kernel *onBoot(const Scheduler* scheduler, const List<Process *> processes) {
bool success = true;
for (Process *process: processes) {
success = success && Scheduler::singleton()->spawn(process);
Expand Down
8 changes: 4 additions & 4 deletions src/test_fhatos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CPrinter>::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; \
Expand Down

0 comments on commit 37fc8ce

Please sign in to comment.