6#include <vcruntime_startup.h>
46 auto now = std::chrono::steady_clock::now();
47 auto duration = now.time_since_epoch();
48 double millis = std::chrono::duration<double, std::milli>(duration).count();
55 std::string format = args[0].asString();
57 auto now = std::chrono::system_clock::now();
58 std::time_t t = std::chrono::system_clock::to_time_t(now);
68 if (std::strftime(buffer,
sizeof(buffer), format.c_str(), &tm) == 0)
73 return std::string(buffer);
79 int64_t ms = args[0].asInt();
80 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
87 return io_prints(std::vector<Value>{
"\033[2J\033[H"}, vm);
94 return Value(
"win32");
95#elif defined(__linux__)
96 return Value(
"Linux");
97#elif defined(__APPLE__)
98 return Value(
"Darwin");
99#elif defined(__FreeBSD__)
100 return Value(
"FreeBSD");
101#elif defined(__unix__)
102 return Value(
"UNIX");
104 return Value(
"Unknown");
112 std::string key = args[0].asString();
120 if (args.size() == 0)
122 auto l_argv = std::make_shared<Value::StructInstance>();
124 for (
size_t i = 0; i < static_cast<size_t>(
argc); i++)
126 l_argv->fields[
"arg" + std::to_string(i)] =
Value(
argv[i]);
129 return Value(l_argv);
133 int64_t index = args[0].asInt();
183 throw std::runtime_error(args[0].asString());
198 int ret =
static_cast<int>(args[0].asInt());
207 return static_cast<int64_t
>(GetCurrentProcessId());
209 return static_cast<int64_t
>(getpid());
static Value sys_clear(const std::vector< Value > &args, VM *vm)
Clear the console.
static Value sys_env(const std::vector< Value > &args, VM *vm)
Get the current environment variables.
static Value sys_reset(const std::vector< Value > &args, VM *vm)
Reset the VM.
static Value sys_exec_get_output(const std::vector< Value > &args, VM *vm)
Run a shell command and get output.
static Value sys_exec_get_error(const std::vector< Value > &args, VM *vm)
Run a shell command and get error output.
static char ** argv
Command line arguments.
static Value sys_time(const std::vector< Value > &args, VM *vm)
Current time.
static Value sys_argc(const std::vector< Value > &args, VM *vm)
Get the current number of command line arguments.
static Value sys_crash(const std::vector< Value > &args, VM *vm)
Crash the VM / Program.
static Value io_prints(const std::vector< Value > &args, VM *vm)
Print string without newline.
static Value system_get_free_memory(const std::vector< Value > &args, VM *vm)
Get current free memory.
static Value sys_os(const std::vector< Value > &args, VM *vm)
Get the current OS.
static void checkArgCount(const std::vector< Value > &args, size_t minimumArguments, const std::string &name, bool allowMoreArguments=false)
static Value sys_argv(const std::vector< Value > &args, VM *vm)
Get the current command line arguments.
static int argc
Number of command line arguments.
static Value sys_wait_for_input(const std::vector< Value > &args, VM *vm)
Wait for input.
static Value sys_shutdown(const std::vector< Value > &args, VM *vm)
Shutdown the VM.
static Value registerSysFunctions(const std::vector< Value > &args, VM *vm)
static Value sys_pid(const std::vector< Value > &args, VM *vm)
Get the current process ID.
static Value sys_sleep(const std::vector< Value > &args, VM *vm)
Sleep for a specified amount of time.
static char ** envp
Environment variables.
static Value sys_time_formatted(const std::vector< Value > &args, VM *vm)
Current time formatted.
static Value io_gets(const std::vector< Value > &args, VM *vm)
Get string.
static int dupenv(std::string &out, const char *name, char *const argp[])
static Value sys_exec(const std::vector< Value > &args, VM *vm)
Run a shell command.
void registerNativeFunction(const std::string &name, NativeFunction fn)
Register a native function.
void setRegister(uint8_t index, const Value &value)
Set a register value.
Value operation(const OpCode &op, const int &operand1=0, const int &operand2=0, const int &operand3=0, const int &operand4=0, const int &operand5=0)
Execute a single operation.
void reset(const bool &resetStack=true, const bool &resetFunctions=true, const bool &resetVariables=true)
Reset the virtual machine.
A value in the Phasor VM.
The Phasor Programming Language and Runtime.
@ SYSTEM_R
Run an operating system shell command: system(R[rA]).
@ SYSTEM_ERR_R
Run shell command and get output: system_out(R[rA], R[rB]).
size_t getAvailableMemory()