aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/compiler/version.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/version.lux')
-rw-r--r--stdlib/source/library/lux/meta/compiler/version.lux49
1 files changed, 49 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/compiler/version.lux b/stdlib/source/library/lux/meta/compiler/version.lux
new file mode 100644
index 000000000..fa67df166
--- /dev/null
+++ b/stdlib/source/library/lux/meta/compiler/version.lux
@@ -0,0 +1,49 @@
+(.require
+ [library
+ [lux (.except)
+ [data
+ [text
+ ["%" \\format]]]
+ [math
+ [number
+ ["n" nat]]]]])
+
+(type .public Version
+ Nat)
+
+(def range
+ 100)
+
+(def level
+ (n.% ..range))
+
+(def next
+ (n./ ..range))
+
+(def .public patch
+ (-> Version Nat)
+ (|>> ..level))
+
+(def .public minor
+ (-> Version Nat)
+ (|>> ..next ..level))
+
+(def .public major
+ (-> Version Nat)
+ (|>> ..next ..next ..level))
+
+(def separator ".")
+
+(def (padded value)
+ (-> Nat Text)
+ (if (n.< 10 value)
+ (%.format "0" (%.nat value))
+ (%.nat value)))
+
+(def .public (format version)
+ (%.Format Version)
+ (%.format (%.nat (..major version))
+ ..separator
+ (..padded (..minor version))
+ ..separator
+ (..padded (..patch version))))