all repos — min @ 4f157a8e003dd068d99a9cf1c95ccea268a2496d

A small but practical concatenative programming language.

lib/min_fs.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
import 
  strutils, 
  os,
  times
import 
  ../core/types,
  ../core/parser, 
  ../core/interpreter, 
  ../core/utils

proc fs_module*(i: In) =
  i.define("fs")
    .symbol("mtime") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getLastModificationTime.toSeconds.newVal

    .symbol("atime") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getLastAccessTime.toSeconds.newVal

    .symbol("ctime") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getCreationTime.toSeconds.newVal

    .symbol("hidden?") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.isHidden.newVal

    .symbol("fsize") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getFileSize.newVal

    .symbol("fstats") do (i: In):
      var s: MinValue
      i.reqStringLike s
      let fi = s.getString.getFileInfo
      var info = newSeq[MinValue](0).newVal
      info.qVal.add @["name".newSym, s].newVal
      info.qVal.add @["device".newSym, fi.id.device.newVal].newVal
      info.qVal.add @["file".newSym, fi.id.file.newVal].newVal
      info.qVal.add @["type".newSym, fi.kind.filetype.newVal].newVal
      info.qVal.add @["size".newSym, fi.size.newVal].newVal
      info.qVal.add @["permissions".newSym, fi.permissions.unixPermissions.newVal].newVal
      info.qVal.add @["nlinks".newSym, fi.linkCount.newVal].newVal
      info.qVal.add @["ctime".newSym, fi.creationTime.toSeconds.newVal].newVal
      info.qVal.add @["atime".newSym, fi.lastAccessTime.toSeconds.newVal].newVal
      info.qVal.add @["mtime".newSym, fi.lastWriteTime.toSeconds.newVal].newVal
      i.push info

    .symbol("ftype") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getFileInfo.kind.filetype.newVal

    .symbol("fperms") do (i: In):
      var s: MinValue
      i.reqStringLike s
      i.push s.getString.getFilePermissions.unixPermissions.newVal

    .finalize()