Skip to content

Commit

Permalink
Switch implementation of OS.Path depending on the platform
Browse files Browse the repository at this point in the history
  • Loading branch information
minoki committed Dec 9, 2023
1 parent fb18661 commit 3fccd3f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 96 deletions.
2 changes: 0 additions & 2 deletions doc/BasisLibrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,6 @@ end

## structure OS.Path - complete

Currently, only Unix-style paths are supported.

```sml
signature OS_PATH = sig
exception Path
Expand Down
21 changes: 18 additions & 3 deletions lib/lunarml/ml/basis/lua/os.sml
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,24 @@ val remove : string -> unit = fn filename => Lua.call0 Lua.Lib.os.remove #[Lua.f
val rename : { old : string, new : string } -> unit = fn { old, new } => Lua.call0 Lua.Lib.os.rename #[Lua.fromString old, Lua.fromString new]
end (* structure FileSys *)
structure IO = struct end
structure Path = UnixPath (exception Path
exception InvalidArc
)
structure Path = struct
exception Path
exception InvalidArc
structure UnixPath = UnixPath (exception Path = Path
exception InvalidArc = InvalidArc
)
structure WindowsPath = WindowsPath (exception Path = Path
exception InvalidArc = InvalidArc
)
val parentArc = ".."
val currentArc = "."
val isWindows = LunarML.assumeDiscardable (fn () => String.sub (Lua.unsafeToString (Lua.field (Lua.Lib.package, "config")), 0) = #"\\") ()
val { fromString, toString, validVolume, getVolume, getParent, splitDirFile, joinDirFile, dir, file, splitBaseExt, joinBaseExt, base, ext, mkCanonical, isCanonical, mkAbsolute, mkRelative, isAbsolute, isRelative, isRoot, concat, fromUnixPath, toUnixPath }
= if isWindows then
{ fromString = WindowsPath.fromString, toString = WindowsPath.toString, validVolume = WindowsPath.validVolume, getVolume = WindowsPath.getVolume, getParent = WindowsPath.getParent, splitDirFile = WindowsPath.splitDirFile, joinDirFile = WindowsPath.joinDirFile, dir = WindowsPath.dir, file = WindowsPath.file, splitBaseExt = WindowsPath.splitBaseExt, joinBaseExt = WindowsPath.joinBaseExt, base = WindowsPath.base, ext = WindowsPath.ext, mkCanonical = WindowsPath.mkCanonical, isCanonical = WindowsPath.isCanonical, mkAbsolute = WindowsPath.mkAbsolute, mkRelative = WindowsPath.mkRelative, isAbsolute = WindowsPath.isAbsolute, isRelative = WindowsPath.isRelative, isRoot = WindowsPath.isRoot, concat = WindowsPath.concat, fromUnixPath = WindowsPath.fromUnixPath, toUnixPath = WindowsPath.toUnixPath }
else
{ fromString = UnixPath.fromString, toString = UnixPath.toString, validVolume = UnixPath.validVolume, getVolume = UnixPath.getVolume, getParent = UnixPath.getParent, splitDirFile = UnixPath.splitDirFile, joinDirFile = UnixPath.joinDirFile, dir = UnixPath.dir, file = UnixPath.file, splitBaseExt = UnixPath.splitBaseExt, joinBaseExt = UnixPath.joinBaseExt, base = UnixPath.base, ext = UnixPath.ext, mkCanonical = UnixPath.mkCanonical, isCanonical = UnixPath.isCanonical, mkAbsolute = UnixPath.mkAbsolute, mkRelative = UnixPath.mkRelative, isAbsolute = UnixPath.isAbsolute, isRelative = UnixPath.isRelative, isRoot = UnixPath.isRoot, concat = UnixPath.concat, fromUnixPath = UnixPath.fromUnixPath, toUnixPath = UnixPath.toUnixPath }
end
structure Process = struct
type status = int
val success : status = 0
Expand Down
23 changes: 19 additions & 4 deletions lib/lunarml/ml/basis/nodejs/os-async.sml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local
_esImport [pure] { mkdirSync, rmdirSync, statSync, lstatSync, readlinkSync, rmSync, renameSync, utimesSync } from "node:fs";
end
structure process = struct
_esImport [pure] { chdir, cwd, exit, env } from "node:process";
_esImport [pure] { chdir, cwd, exit, env, platform } from "node:process";
end
structure child_process = struct
_esImport [pure] { execSync } from "node:child_process";
Expand Down Expand Up @@ -99,9 +99,24 @@ fun rename { old : string, new : string } = ( JavaScript.call fs.renameSync #[Ja
)
end (* structure FileSys *)
structure IO = struct end
structure Path = UnixPath (exception Path
exception InvalidArc
)
structure Path = struct
exception Path
exception InvalidArc
structure UnixPath = UnixPath (exception Path = Path
exception InvalidArc = InvalidArc
)
structure WindowsPath = WindowsPath (exception Path = Path
exception InvalidArc = InvalidArc
)
val parentArc = ".."
val currentArc = "."
val isWindows = LunarML.assumeDiscardable (fn () => (JavaScript.unsafeFromValue process.platform : WideString.string) = "win32") ()
val { fromString, toString, validVolume, getVolume, getParent, splitDirFile, joinDirFile, dir, file, splitBaseExt, joinBaseExt, base, ext, mkCanonical, isCanonical, mkAbsolute, mkRelative, isAbsolute, isRelative, isRoot, concat, fromUnixPath, toUnixPath }
= if isWindows then
{ fromString = WindowsPath.fromString, toString = WindowsPath.toString, validVolume = WindowsPath.validVolume, getVolume = WindowsPath.getVolume, getParent = WindowsPath.getParent, splitDirFile = WindowsPath.splitDirFile, joinDirFile = WindowsPath.joinDirFile, dir = WindowsPath.dir, file = WindowsPath.file, splitBaseExt = WindowsPath.splitBaseExt, joinBaseExt = WindowsPath.joinBaseExt, base = WindowsPath.base, ext = WindowsPath.ext, mkCanonical = WindowsPath.mkCanonical, isCanonical = WindowsPath.isCanonical, mkAbsolute = WindowsPath.mkAbsolute, mkRelative = WindowsPath.mkRelative, isAbsolute = WindowsPath.isAbsolute, isRelative = WindowsPath.isRelative, isRoot = WindowsPath.isRoot, concat = WindowsPath.concat, fromUnixPath = WindowsPath.fromUnixPath, toUnixPath = WindowsPath.toUnixPath }
else
{ fromString = UnixPath.fromString, toString = UnixPath.toString, validVolume = UnixPath.validVolume, getVolume = UnixPath.getVolume, getParent = UnixPath.getParent, splitDirFile = UnixPath.splitDirFile, joinDirFile = UnixPath.joinDirFile, dir = UnixPath.dir, file = UnixPath.file, splitBaseExt = UnixPath.splitBaseExt, joinBaseExt = UnixPath.joinBaseExt, base = UnixPath.base, ext = UnixPath.ext, mkCanonical = UnixPath.mkCanonical, isCanonical = UnixPath.isCanonical, mkAbsolute = UnixPath.mkAbsolute, mkRelative = UnixPath.mkRelative, isAbsolute = UnixPath.isAbsolute, isRelative = UnixPath.isRelative, isRoot = UnixPath.isRoot, concat = UnixPath.concat, fromUnixPath = UnixPath.fromUnixPath, toUnixPath = UnixPath.toUnixPath }
end
structure Process = struct
type status = int
val success : status = 0
Expand Down
23 changes: 19 additions & 4 deletions lib/lunarml/ml/basis/nodejs/os.sml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local
_esImport [pure] { mkdirSync, rmdirSync, statSync, lstatSync, readlinkSync, rmSync, renameSync } from "node:fs";
end
structure process = struct
_esImport [pure] { chdir, cwd, exit, env } from "node:process";
_esImport [pure] { chdir, cwd, exit, env, platform } from "node:process";
end
structure child_process = struct
_esImport [pure] { execSync } from "node:child_process";
Expand Down Expand Up @@ -84,9 +84,24 @@ fun rename { old : string, new : string } = ( JavaScript.call fs.renameSync #[Ja
)
end (* structure FileSys *)
structure IO = struct end
structure Path = UnixPath (exception Path
exception InvalidArc
)
structure Path = struct
exception Path
exception InvalidArc
structure UnixPath = UnixPath (exception Path = Path
exception InvalidArc = InvalidArc
)
structure WindowsPath = WindowsPath (exception Path = Path
exception InvalidArc = InvalidArc
)
val parentArc = ".."
val currentArc = "."
val isWindows = LunarML.assumeDiscardable (fn () => (JavaScript.unsafeFromValue process.platform : WideString.string) = "win32") ()
val { fromString, toString, validVolume, getVolume, getParent, splitDirFile, joinDirFile, dir, file, splitBaseExt, joinBaseExt, base, ext, mkCanonical, isCanonical, mkAbsolute, mkRelative, isAbsolute, isRelative, isRoot, concat, fromUnixPath, toUnixPath }
= if isWindows then
{ fromString = WindowsPath.fromString, toString = WindowsPath.toString, validVolume = WindowsPath.validVolume, getVolume = WindowsPath.getVolume, getParent = WindowsPath.getParent, splitDirFile = WindowsPath.splitDirFile, joinDirFile = WindowsPath.joinDirFile, dir = WindowsPath.dir, file = WindowsPath.file, splitBaseExt = WindowsPath.splitBaseExt, joinBaseExt = WindowsPath.joinBaseExt, base = WindowsPath.base, ext = WindowsPath.ext, mkCanonical = WindowsPath.mkCanonical, isCanonical = WindowsPath.isCanonical, mkAbsolute = WindowsPath.mkAbsolute, mkRelative = WindowsPath.mkRelative, isAbsolute = WindowsPath.isAbsolute, isRelative = WindowsPath.isRelative, isRoot = WindowsPath.isRoot, concat = WindowsPath.concat, fromUnixPath = WindowsPath.fromUnixPath, toUnixPath = WindowsPath.toUnixPath }
else
{ fromString = UnixPath.fromString, toString = UnixPath.toString, validVolume = UnixPath.validVolume, getVolume = UnixPath.getVolume, getParent = UnixPath.getParent, splitDirFile = UnixPath.splitDirFile, joinDirFile = UnixPath.joinDirFile, dir = UnixPath.dir, file = UnixPath.file, splitBaseExt = UnixPath.splitBaseExt, joinBaseExt = UnixPath.joinBaseExt, base = UnixPath.base, ext = UnixPath.ext, mkCanonical = UnixPath.mkCanonical, isCanonical = UnixPath.isCanonical, mkAbsolute = UnixPath.mkAbsolute, mkRelative = UnixPath.mkRelative, isAbsolute = UnixPath.isAbsolute, isRelative = UnixPath.isRelative, isRoot = UnixPath.isRoot, concat = UnixPath.concat, fromUnixPath = UnixPath.fromUnixPath, toUnixPath = UnixPath.toUnixPath }
end
structure Process = struct
type status = int
val success : status = 0
Expand Down
6 changes: 3 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ should_run += $(addprefix mlbasis/should_run/,\
)
# int-inf-factorial.sml
ifeq ($(VARIANT), lua)
should_run += mlbasis/should_run/os-path.sml mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
should_run += mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
else ifeq ($(VARIANT), lua-continuations)
should_run += mlbasis/should_run/os-path.sml mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
should_run += mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
else ifeq ($(VARIANT), luajit)
should_run += mlbasis/should_run/os-path.sml mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
should_run += mlbasis/should_run/scan-real.sml lua/should_run/nil_in_vector.mlb
endif
should_compile += $(addprefix interface/should_compile/,\
INTEGER.sml \
Expand Down
43 changes: 0 additions & 43 deletions test/mlbasis/should_run/os-path.sml

This file was deleted.

37 changes: 0 additions & 37 deletions test/mlbasis/should_run/os-path.stdout

This file was deleted.

0 comments on commit 3fccd3f

Please sign in to comment.