summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim13
-rw-r--r--compiler/cgen.nim16
-rw-r--r--compiler/jsgen.nim52
-rw-r--r--compiler/platform.nim7
-rw-r--r--compiler/semcall.nim1
-rw-r--r--compiler/semtypinst.nim2
-rw-r--r--compiler/sigmatch.nim2
7 files changed, 77 insertions, 16 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 6e10379e6..b03f7c5aa 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -944,7 +944,6 @@ proc genEcho(p: BProc, n: PNode) =
   # this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
   # is threadsafe.
   internalAssert n.kind == nkBracket
-  p.module.includeHeader("<stdio.h>")
   var args: Rope = nil
   var a: TLoc
   for i in countup(0, n.len-1):
@@ -953,9 +952,15 @@ proc genEcho(p: BProc, n: PNode) =
     else:
       initLocExpr(p, n.sons[i], a)
       addf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
-  linefmt(p, cpsStmts, "printf($1$2);$n",
-          makeCString(repeat("%s", n.len) & tnl), args)
-  linefmt(p, cpsStmts, "fflush(stdout);$n")
+  if platform.targetOS == osGenode:
+    # bypass libc and print directly to the Genode LOG session
+    p.module.includeHeader("<base/log.h>")
+    linefmt(p, cpsStmts, """Genode::log(""$1);$n""", args)
+  else:
+    p.module.includeHeader("<stdio.h>")
+    linefmt(p, cpsStmts, "printf($1$2);$n",
+            makeCString(repeat("%s", n.len) & tnl), args)
+    linefmt(p, cpsStmts, "fflush(stdout);$n")
 
 proc gcUsage(n: PNode) =
   if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index ebdbffa5a..fd15d0793 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -966,6 +966,19 @@ proc genMainProc(m: BModule) =
         MainProcs &
       "}$N$N"
 
+    GenodeNimMain =
+      "Libc::Env *genodeEnv;$N" &
+      NimMainBody
+
+    ComponentConstruct =
+      "void Libc::Component::construct(Libc::Env &env) {$N" &
+      "\tgenodeEnv = &env;$N" &
+      "\tLibc::with_libc([&] () {$n\t" &
+      MainProcs &
+      "\t});$N" &
+      "\tenv.parent().exit(0);$N" &
+      "}$N$N"
+
   var nimMain, otherMain: FormatStr
   if platform.targetOS == osWindows and
       gGlobalOptions * {optGenGuiApp, optGenDynLib} != {}:
@@ -976,6 +989,9 @@ proc genMainProc(m: BModule) =
       nimMain = WinNimDllMain
       otherMain = WinCDllMain
     m.includeHeader("<windows.h>")
+  elif platform.targetOS == osGenode:
+    nimMain = GenodeNimMain
+    otherMain = ComponentConstruct
   elif optGenDynLib in gGlobalOptions:
     nimMain = PosixNimDllMain
     otherMain = PosixCDllMain
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index d64e4f7dd..0016a8492 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1626,22 +1626,56 @@ proc genToArray(p: PProc; n: PNode; r: var TCompRes) =
     localError(x.info, "'toArray' needs an array literal")
   r.res.add(")")
 
+proc genReprAux(p: PProc, n: PNode, r: var TCompRes, magic: string, typ: Rope = nil) =
+  useMagic(p, magic)
+  add(r.res, magic & "(")
+  var a: TCompRes
+
+  gen(p, n.sons[1], a)
+  if magic == "reprAny":
+    # the pointer argument in reprAny is expandend to 
+    # (pointedto, pointer), so we need to fill it
+    if a.address.isNil:
+      add(r.res, a.res)
+      add(r.res, ", null") 
+    else:
+      add(r.res, "$1, $2" % [a.address, a.res])
+  else:
+    add(r.res, a.res)
+
+  if not typ.isNil:
+    add(r.res, ", ")
+    add(r.res, typ)
+  add(r.res, ")")
+
 proc genRepr(p: PProc, n: PNode, r: var TCompRes) =
   if p.target == targetPHP:
     localError(n.info, "'repr' not available for PHP backend")
     return
   let t = skipTypes(n.sons[1].typ, abstractVarRange)
-  case t.kind
-  of tyInt..tyUInt64:
-    unaryExpr(p, n, r, "", "(\"\"+ ($1))")
+  case t.kind:
+  of tyInt..tyInt64, tyUInt..tyUInt64:
+    genReprAux(p, n, r, "reprInt")
+  of tyChar:
+    genReprAux(p, n, r, "reprChar")
+  of tyBool:
+    genReprAux(p, n, r, "reprBool")
+  of tyFloat..tyFloat128:
+    genReprAux(p, n, r, "reprFloat")
+  of tyString:
+    genReprAux(p, n, r, "reprStr")
   of tyEnum, tyOrdinal:
-    gen(p, n.sons[1], r)
-    useMagic(p, "cstrToNimstr")
-    r.kind = resExpr
-    r.res = "cstrToNimstr($1.node.sons[$2].name)" % [genTypeInfo(p, t), r.res]
+    genReprAux(p, n, r, "reprEnum", genTypeInfo(p, t))
+  of tySet:
+    genReprAux(p, n, r, "reprSet", genTypeInfo(p, t))
+  of tyEmpty, tyVoid:
+    localError(n.info, "'repr' doesn't support 'void' type")
+  of tyPointer: 
+    genReprAux(p, n, r, "reprPointer")
+  of tyOpenArray, tyVarargs:
+    genReprAux(p, n, r, "reprJSONStringify")
   else:
-    # XXX:
-    internalError(n.info, "genRepr: Not implemented")
+    genReprAux(p, n, r, "reprAny", genTypeInfo(p, t))
 
 proc genOf(p: PProc, n: PNode, r: var TCompRes) =
   var x: TCompRes
diff --git a/compiler/platform.nim b/compiler/platform.nim
index 19d0d5853..eb0aca186 100644
--- a/compiler/platform.nim
+++ b/compiler/platform.nim
@@ -21,7 +21,7 @@ type
                     # conditionals to condsyms (end of module).
     osNone, osDos, osWindows, osOs2, osLinux, osMorphos, osSkyos, osSolaris,
     osIrix, osNetbsd, osFreebsd, osOpenbsd, osDragonfly, osAix, osPalmos, osQnx,
-    osAmiga, osAtari, osNetware, osMacos, osMacosx, osHaiku, osVxworks,
+    osAmiga, osAtari, osNetware, osMacos, osMacosx, osHaiku, osVxworks, osGenode
     osJS, osNimrodVM, osStandalone
 
 type
@@ -147,6 +147,11 @@ const
       objExt: ".o", newLine: "\x0A", pathSep: ";", dirSep: "\\",
       scriptExt: ".sh", curDir: ".", exeExt: ".vxe", extSep: ".",
       props: {ospNeedsPIC, ospPosix, ospLacksThreadVars}),
+     (name: "Genode", pardir: "..", dllFrmt: "$1.lib.so", altDirSep: "/",
+      objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
+      scriptExt: "", curDir: "/", exeExt: "", extSep: ".",
+      props: {ospNeedsPIC, ospLacksThreadVars}),
+
      (name: "JS", parDir: "..",
       dllFrmt: "lib$1.so", altDirSep: "/",
       objExt: ".o", newLine: "\x0A",
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index d6852859b..2dd115b1b 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -256,6 +256,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
         f.ident.s[0..f.ident.s.len-2]).withInfo(n.info)
       let callOp = newIdentNode(getIdent".=", n.info)
       n.sons[0..1] = [callOp, n[1], calleeName]
+      excl(n.flags, nfDotSetter)
       orig.sons[0..1] = [callOp, orig[1], calleeName]
       pickBest(callOp)
 
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index fddcc7a24..9ff0b7e78 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -472,7 +472,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
           var r = replaceTypeVarsT(cl, result.sons[i])
           if result.kind == tyObject:
             # carefully coded to not skip the precious tyGenericInst:
-            let r2 = r.skipTypes({tyGenericInst, tyAlias})
+            let r2 = r.skipTypes({tyAlias})
             if r2.kind in {tyPtr, tyRef}:
               r = skipTypes(r2, {tyPtr, tyRef})
           result.sons[i] = r
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index ff7b0ae72..4661abda0 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1268,7 +1268,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
         # crossing path with metatypes/aliases, so we need to separate them
         # by checking sym.id
         let genericSubtype = isGenericSubType(c, x, f, depth, f)
-        if not (genericSubtype and aobj.sym.id != fobj.sym.id):
+        if not (genericSubtype and aobj.sym.id != fobj.sym.id) and aOrig.kind != tyGenericBody:
           depth = -1
 
       if depth >= 0: