From be6c84ee7492cd713c280e7944d94a720cf16d22 Mon Sep 17 00:00:00 2001 From: Peter M Date: Sun, 22 Sep 2024 21:51:43 +0200 Subject: [PATCH] System.ex monotonic_time/1 system_time/1 Carbon copy from elixir with :native time unit removed, as it's not supported by current erlang implementation. Signed-off-by: Peter M --- libs/exavmlib/lib/CMakeLists.txt | 1 + libs/exavmlib/lib/System.ex | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 libs/exavmlib/lib/System.ex diff --git a/libs/exavmlib/lib/CMakeLists.txt b/libs/exavmlib/lib/CMakeLists.txt index 70749cfef..80c33f9b0 100644 --- a/libs/exavmlib/lib/CMakeLists.txt +++ b/libs/exavmlib/lib/CMakeLists.txt @@ -49,6 +49,7 @@ set(ELIXIR_MODULES Process Protocol.UndefinedError Range + System Tuple ArithmeticError diff --git a/libs/exavmlib/lib/System.ex b/libs/exavmlib/lib/System.ex new file mode 100644 index 000000000..97f64eb61 --- /dev/null +++ b/libs/exavmlib/lib/System.ex @@ -0,0 +1,50 @@ +# +# This file is part of elixir-lang. +# +# Copyright 2012-2024 Elixir Contributors +# https://github.com/elixir-lang/elixir/blob/v1.17/lib/elixir/lib/system.ex +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +defmodule System do + @type time_unit :: + :second + | :millisecond + | :microsecond + + @doc """ + Returns the current monotonic time in the given time unit. + + This time is monotonically increasing and starts in an unspecified + point in time. + """ + @spec monotonic_time(time_unit) :: integer + def monotonic_time(unit) do + :erlang.monotonic_time(unit) + end + + @doc """ + Returns the current system time in the given time unit. + + It is the VM view of the `os_time/0`. They may not match in + case of time warps although the VM works towards aligning + them. This time is not monotonic. + """ + @spec system_time(time_unit) :: integer + def system_time(unit) do + :erlang.system_time(unit) + end +end