-module(lightspeed@agent@isa).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/agent/isa.gleam").
-export([opcode/1, is_client_instruction/1, is_server_instruction/1, describe/1]).
-export_type([instruction/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Orthogonal instruction set for the Lightspeed runtime.\n").
-type instruction() :: {mount, binary(), binary()} |
{render, binary()} |
{patch, binary(), binary()} |
{push_event, binary(), binary()} |
{navigate, binary()} |
{subscribe, binary()} |
{unsubscribe, binary()} |
{shutdown, binary()}.
-file("src/lightspeed/agent/isa.gleam", 16).
?DOC(" Stable opcode string for logs, tests, and protocol mapping.\n").
-spec opcode(instruction()) -> binary().
opcode(Instruction) ->
case Instruction of
{mount, _, _} ->
<<"mount"/utf8>>;
{render, _} ->
<<"render"/utf8>>;
{patch, _, _} ->
<<"patch"/utf8>>;
{push_event, _, _} ->
<<"push_event"/utf8>>;
{navigate, _} ->
<<"navigate"/utf8>>;
{subscribe, _} ->
<<"subscribe"/utf8>>;
{unsubscribe, _} ->
<<"unsubscribe"/utf8>>;
{shutdown, _} ->
<<"shutdown"/utf8>>
end.
-file("src/lightspeed/agent/isa.gleam", 30).
?DOC(" True when the instruction is intended for the browser/client runtime.\n").
-spec is_client_instruction(instruction()) -> boolean().
is_client_instruction(Instruction) ->
case Instruction of
{patch, _, _} ->
true;
{navigate, _} ->
true;
_ ->
false
end.
-file("src/lightspeed/agent/isa.gleam", 39).
?DOC(" True when the instruction is intended for the server runtime.\n").
-spec is_server_instruction(instruction()) -> boolean().
is_server_instruction(Instruction) ->
case Instruction of
{mount, _, _} ->
true;
{render, _} ->
true;
{push_event, _, _} ->
true;
{subscribe, _} ->
true;
{unsubscribe, _} ->
true;
{shutdown, _} ->
true;
_ ->
false
end.
-file("src/lightspeed/agent/isa.gleam", 52).
?DOC(" Human-readable instruction summary for traces.\n").
-spec describe(instruction()) -> binary().
describe(Instruction) ->
case Instruction of
{mount, Route, _} ->
<<"mount "/utf8, Route/binary>>;
{render, View_id} ->
<<"render "/utf8, View_id/binary>>;
{patch, Target, _} ->
<<"patch "/utf8, Target/binary>>;
{push_event, Name, _} ->
<<"push_event "/utf8, Name/binary>>;
{navigate, To} ->
<<"navigate "/utf8, To/binary>>;
{subscribe, Topic} ->
<<"subscribe "/utf8, Topic/binary>>;
{unsubscribe, Topic@1} ->
<<"unsubscribe "/utf8, Topic@1/binary>>;
{shutdown, Reason} ->
<<"shutdown "/utf8, Reason/binary>>
end.