summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-26 17:21:52 +0200
committerAraq <rumpf_a@web.de>2011-06-26 17:21:52 +0200
commit990dc2d7152f09c413d8fd96d66484d79aec97c7 (patch)
treea267c16996c61292c78019ab56d1116d811fd0dc /compiler
parentdb0a4a9f86d167faccbd50f3f12f9de470e516b8 (diff)
downloadNim-990dc2d7152f09c413d8fd96d66484d79aec97c7.tar.gz
code gen bugfixes; marshal.nim implemented
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ccgtypes.nim39
-rwxr-xr-xcompiler/cgen.nim5
-rwxr-xr-xcompiler/pragmas.nim2
3 files changed, 32 insertions, 14 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 6d9533dd1..c44516304 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -61,18 +61,20 @@ proc getTypeName(typ: PType): PRope =
     result = typ.loc.r
   if result == nil: InternalError("getTypeName: " & $typ.kind)
   
+proc mapSetType(typ: PType): TCTypeKind =
+  case int(getSize(typ))
+  of 1: result = ctInt8
+  of 2: result = ctInt16
+  of 4: result = ctInt32
+  of 8: result = ctInt64
+  else: result = ctArray
+
 proc mapType(typ: PType): TCTypeKind = 
   case typ.kind
   of tyNone: result = ctVoid
   of tyBool: result = ctBool
   of tyChar: result = ctChar
-  of tySet: 
-    case int(getSize(typ))
-    of 1: result = ctInt8
-    of 2: result = ctInt16
-    of 4: result = ctInt32
-    of 8: result = ctInt64
-    else: result = ctArray
+  of tySet: result = mapSetType(typ)
   of tyOpenArray, tyArrayConstr, tyArray: result = ctArray
   of tyObject, tyTuple: result = ctStruct
   of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal: 
@@ -89,8 +91,12 @@ proc mapType(typ: PType): TCTypeKind =
       else: internalError("mapType")
   of tyRange: result = mapType(typ.sons[0])
   of tyPtr, tyVar, tyRef: 
-    case typ.sons[0].kind
+    var base = skipTypes(typ.sons[0], abstractInst)
+    case base.kind
     of tyOpenArray, tyArrayConstr, tyArray: result = ctArray
+    of tySet:
+      result = mapSetType(base)
+      if result != ctArray: result = ctPtr
     else: result = ctPtr
   of tyPointer: result = ctPtr
   of tySequence: result = ctNimSeq
@@ -172,6 +178,14 @@ proc fillResult(param: PSym) =
     incl(param.loc.flags, lfIndirect)
     param.loc.s = OnUnknown
 
+proc getParamTypeDesc(m: BModule, t: PType, check: var TIntSet): PRope =
+  if t.Kind in {tyRef, tyPtr, tyVar}:
+    var b = skipTypes(t.sons[0], abstractInst)
+    if b.kind == tySet and mapSetType(b) == ctArray:
+      return toRope("NU8*") 
+      # getTypeDescAux(m, b, check)
+  result = getTypeDescAux(m, t, check)
+
 proc genProcParams(m: BModule, t: PType, rettype, params: var PRope, 
                    check: var TIntSet) = 
   params = nil
@@ -183,19 +197,20 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
     if t.n.sons[i].kind != nkSym: InternalError(t.n.info, "genProcParams")
     var param = t.n.sons[i].sym
     fillLoc(param.loc, locParam, param.typ, mangleName(param), OnStack)
-    app(params, getTypeDescAux(m, param.typ, check))
+    app(params, getParamTypeDesc(m, param.typ, check))
     if ccgIntroducedPtr(param): 
       app(params, "*")
       incl(param.loc.flags, lfIndirect)
       param.loc.s = OnUnknown
     app(params, " ")
-    app(params, param.loc.r)  # declare the len field for open arrays:
+    app(params, param.loc.r)
+    # declare the len field for open arrays:
     var arr = param.typ
     if arr.kind == tyVar: arr = arr.sons[0]
     var j = 0
     while arr.Kind == tyOpenArray: 
       # need to pass hidden parameter:
-      appff(params, ", NI $1Len$2", ", @NI $1Len$2", [param.loc.r, toRope(j)])
+      appff(params, ", NI $1Len$2", ", @NI $1Len$2", [param.loc.r, j.toRope])
       inc(j)
       arr = arr.sons[0]
     if i < sonsLen(t.n) - 1: app(params, ", ")
@@ -396,6 +411,8 @@ proc getTypeDescAux(m: BModule, typ: PType, check: var TIntSet): PRope =
   of tyRef, tyPtr, tyVar: 
     et = getUniqueType(t.sons[0])
     if et.kind in {tyArrayConstr, tyArray, tyOpenArray}: 
+      # this is correct! sets have no proper base type, so we treat
+      # ``var set[char]`` in `getParamTypeDesc`
       et = getUniqueType(elemType(et))
     case et.Kind
     of tyObject, tyTuple: 
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 1ecadbec4..60c052d5d 100755
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -253,7 +253,8 @@ proc rdLoc(a: TLoc): PRope =
 
 proc addrLoc(a: TLoc): PRope =
   result = a.r
-  if lfIndirect notin a.flags: result = con("&", result)
+  if lfIndirect notin a.flags and mapType(a.t) != ctArray: 
+    result = con("&", result)
 
 proc rdCharLoc(a: TLoc): PRope =
   # read a location that may need a char-cast:
@@ -333,7 +334,7 @@ proc initVariable(p: BProc, v: PSym) =
     zeroVar(p, v.loc, b)
     
 proc initTemp(p: BProc, tmp: var TLoc) = 
-  if containsGarbageCollectedRef(tmp.t):
+  if containsGarbageCollectedRef(tmp.t) or isInvalidReturnType(tmp.t):
     zeroTemp(p, tmp)
 
 proc getTemp(p: BProc, t: PType, result: var TLoc) = 
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index a450db3a4..7ca980dcc 100755
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -119,7 +119,7 @@ proc processMagic(c: PContext, n: PNode, s: PSym) =
       s.magic = m
       break
   if s.magic == mNone: Message(n.info, warnUnknownMagic, v)
-  elif s.magic != mCreateThread: 
+  if s.magic != mCreateThread: 
     # magics don't need an implementation, so we
     # treat them as imported, instead of modifing a lot of working code:
     incl(s.flags, sfImportc)