all repos — min @ b12d6698fb941ca8be8719221e5a5032c47847ae

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
 66
import 
  strutils, 
  os,
  times
import 
  ../core/parser, 
  ../core/value, 
  ../core/interpreter, 
  ../core/utils,
  ../core/fileutils

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

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

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

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

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

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

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

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

  def.finalize("fs")