all repos — min @ f5c37b9b51e9a4784537995f0a9ac1ccbb73d02a

A small but practical concatenative programming language.

minpkg/core/stdlib.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
import
  std/[
    logging,
    os,
    strutils
  ]

import
  env,
  parser,
  interpreter

import
  ../lib/[min_global,
  min_stack,
  min_dict,
  min_time,
  min_sys,
  min_io,
  min_dstore,
  min_fs,
  min_xml,
  min_http,
  min_net,
  min_crypto,
  min_math]

const PRELUDE* = "../../prelude.min".slurp.strip
var customPrelude* {.threadvar.}: string
customPrelude = ""

proc stdLib*(i: In) =
  if not MINSYMBOLS.fileExists:
    MINSYMBOLS.writeFile("{}")
  if not MINHISTORY.fileExists:
    MINHISTORY.writeFile("")
  if not MINRC.fileExists:
    MINRC.writeFile("")
  i.global_module
  i.stack_module
  i.dict_module
  i.time_module
  i.sys_module
  i.fs_module
  i.dstore_module
  i.io_module
  i.crypto_module
  i.net_module
  i.math_module
  i.http_module
  i.xml_module
  if customPrelude == "":
    i.eval PRELUDE, "<prelude>"
  else:
    try:
      i.eval customPrelude.readFile, customPrelude
    except CatchableError:
      logging.warn("Unable to process custom prelude code in $1" % customPrelude)
  try:
    i.eval MINRC.readFile()
  except CatchableError:
    error "An error occurred evaluating the .minrc file."