summary refs log tree commit diff stats
path: root/lib/system/reprjs.nim
blob: 57237cfffae8dcbb2d4af685c5c2a877b572fc62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#
#            Nim's Runtime Library
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

proc reprInt(x: int64): string {.compilerproc.} = return $x

proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
  if ntfEnumHole notin typ.flags:
    if e <% typ.node.len:
      return $typ.node.sons[e].name
  else:
    # ugh we need a slow linear search:
    var n = typ.node
    var s = n.sons
    for i in 0 .. n.len-1:
      if s[i].offset == e: return $s[i].name
  result = $e & " (invalid data!)"
highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
type ConnectErrorCode* = enum
  ERROR_FAILED_TO_REDIRECT = (-17, "failed to redirect request body")
  ERROR_URL_NOT_IN_CACHE = (-16, "URL was not found in the cache")
  ERROR_FILE_NOT_IN_CACHE = (-15, "file was not found in the cache")
  ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT = (-14, "failed to execute CGI script")
  ERROR_CGI_NO_DATA = (-13, "CGI script returned no data")
  ERROR_CGI_MALFORMED_HEADER = (-12, "CGI script returned a malformed header")
  ERROR_CGI_INVALID_CHA_CONTROL = (-11, "CGI got invalid Cha-Control header")
  ERROR_TOO_MANY_REWRITES = (-10, "too many URI method map rewrites")
  ERROR_INVALID_URI_METHOD_ENTRY = (-9, "invalid URI method entry")
  ERROR_CGI_FILE_NOT_FOUND = (-8, "CGI file not found")
  ERROR_INVALID_CGI_PATH = (-7, "invalid CGI path")
  ERROR_FAIL_SETUP_CGI = (-6, "failed to set up CGI script")
  ERROR_NO_CGI_DIR = (-5, "no local-CGI directory configured")
  ERROR_SOURCE_NOT_FOUND = (-4, "clone source could not be found")
  ERROR_LOADER_KILLED = (-3, "loader killed during transfer")
  ERROR_DISALLOWED_URL = (-2, "url not allowed by filter")
  ERROR_UNKNOWN_SCHEME = (-1, "unknown scheme")
  CONNECTION_SUCCESS = (0, "connection successful")
  ERROR_INTERNAL = (1, "internal error")
  ERROR_INVALID_METHOD = (2, "invalid method")
  ERROR_INVALID_URL = (3, "invalid URL")
  ERROR_FILE_NOT_FOUND = (4, "file not found")
  ERROR_CONNECTION_REFUSED = (5, "connection refused")
  ERROR_PROXY_REFUSED_TO_CONNECT = (6, "proxy refused to connect")
  ERROR_FAILED_TO_RESOLVE_HOST = (7, "failed to resolve host")
  ERROR_FAILED_TO_RESOLVE_PROXY = (8, "failed to resolve proxy")

converter toInt*(code: ConnectErrorCode): int =
  return int(code)

func getLoaderErrorMessage*(code: int): string =
  if code in int(ConnectErrorCode.low)..int(ConnectErrorCode.high):
    return $ConnectErrorCode(code)
  return "unexpected error code " & $code