bugfix: complex.nim compiles
This commit is contained in:
parent
f530bbd631
commit
b2ad7b30dc
7 changed files with 55 additions and 79 deletions
|
|
@ -22,7 +22,9 @@ __TINYC__
|
||||||
#ifndef NIMBASE_H
|
#ifndef NIMBASE_H
|
||||||
#define NIMBASE_H
|
#define NIMBASE_H
|
||||||
|
|
||||||
#include <math.h>
|
#if !defined(__TINYC__)
|
||||||
|
# include <math.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* calling convention mess ----------------------------------------------- */
|
/* calling convention mess ----------------------------------------------- */
|
||||||
#if defined(__GNUC__) || defined(__LCC__) || defined(__POCC__) \
|
#if defined(__GNUC__) || defined(__LCC__) || defined(__POCC__) \
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2006 Andreas Rumpf
|
# (c) Copyright 2010 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -101,6 +101,6 @@ proc sqrt*(z: TComplex): TComplex =
|
||||||
else:
|
else:
|
||||||
if z.im >= 0.0: result.im = w
|
if z.im >= 0.0: result.im = w
|
||||||
else: result.im = -w
|
else: result.im = -w
|
||||||
result.re = z.im / (c.im + c.im)
|
result.re = z.im / (result.im + result.im)
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
0
lib/wrappers/tinyc.nim
Normal file → Executable file
0
lib/wrappers/tinyc.nim
Normal file → Executable file
|
|
@ -375,7 +375,7 @@ proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
|
||||||
compilePattern = cc[c].compilerExe
|
compilePattern = cc[c].compilerExe
|
||||||
if targetOS == platform.hostOS: cfile = cfilename
|
if targetOS == platform.hostOS: cfile = cfilename
|
||||||
else: cfile = extractFileName(cfilename)
|
else: cfile = extractFileName(cfilename)
|
||||||
if not isExternal or (targetOS != platform.hostOS): objfile = toObjFile(cfile)
|
if not isExternal or targetOS != platform.hostOS: objfile = toObjFile(cfile)
|
||||||
else: objfile = completeCFilePath(toObjFile(cfile))
|
else: objfile = completeCFilePath(toObjFile(cfile))
|
||||||
cfile = quoteIfContainsWhite(AddFileExt(cfile, cExt))
|
cfile = quoteIfContainsWhite(AddFileExt(cfile, cExt))
|
||||||
objfile = quoteIfContainsWhite(objfile)
|
objfile = quoteIfContainsWhite(objfile)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
This directory contains the Nimrod version of Nimrod's source code. MODIFY THIS
|
This directory contains the Nimrod compiler written in Nimrod. Note that this
|
||||||
VERSION, NOT THE PASCAL VERSION!
|
code has been translated from a bootstrapping version written in Pascal, so
|
||||||
|
the code is **not** a poster child of good Nimrod code.
|
||||||
|
|
||||||
|
|
|
||||||
114
rod/sigmatch.nim
114
rod/sigmatch.nim
|
|
@ -6,6 +6,7 @@
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
# This module implements the signature matching for resolving
|
# This module implements the signature matching for resolving
|
||||||
# the call to overloaded procs, generic procs and operators.
|
# the call to overloaded procs, generic procs and operators.
|
||||||
|
|
||||||
|
|
@ -150,18 +151,16 @@ proc tupleRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
result = isEqual
|
result = isEqual
|
||||||
for i in countup(0, sonsLen(f) - 1):
|
for i in countup(0, sonsLen(f) - 1):
|
||||||
var m = typeRel(mapping, f.sons[i], a.sons[i])
|
var m = typeRel(mapping, f.sons[i], a.sons[i])
|
||||||
if m < isSubtype:
|
if m < isSubtype: return isNone
|
||||||
return isNone
|
|
||||||
result = minRel(result, m)
|
result = minRel(result, m)
|
||||||
if (f.n != nil) and (a.n != nil):
|
if f.n != nil and a.n != nil:
|
||||||
for i in countup(0, sonsLen(f.n) - 1):
|
for i in countup(0, sonsLen(f.n) - 1):
|
||||||
# check field names:
|
# check field names:
|
||||||
if f.n.sons[i].kind != nkSym: InternalError(f.n.info, "tupleRel")
|
if f.n.sons[i].kind != nkSym: InternalError(f.n.info, "tupleRel")
|
||||||
if a.n.sons[i].kind != nkSym: InternalError(a.n.info, "tupleRel")
|
if a.n.sons[i].kind != nkSym: InternalError(a.n.info, "tupleRel")
|
||||||
var x = f.n.sons[i].sym
|
var x = f.n.sons[i].sym
|
||||||
var y = a.n.sons[i].sym
|
var y = a.n.sons[i].sym
|
||||||
if x.name.id != y.name.id:
|
if x.name.id != y.name.id: return isNone
|
||||||
return isNone
|
|
||||||
|
|
||||||
proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
var
|
var
|
||||||
|
|
@ -171,42 +170,33 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
result = isNone
|
result = isNone
|
||||||
assert(f != nil)
|
assert(f != nil)
|
||||||
assert(a != nil)
|
assert(a != nil)
|
||||||
if (a.kind == tyGenericInst) and
|
if a.kind == tyGenericInst and
|
||||||
not (skipTypes(f, {tyVar}).kind in {tyGenericBody, tyGenericInvokation}):
|
skipTypes(f, {tyVar}).kind notin {tyGenericBody, tyGenericInvokation}:
|
||||||
return typeRel(mapping, f, lastSon(a))
|
return typeRel(mapping, f, lastSon(a))
|
||||||
if (a.kind == tyVar) and (f.kind != tyVar):
|
if a.kind == tyVar and f.kind != tyVar:
|
||||||
return typeRel(mapping, f, a.sons[0])
|
return typeRel(mapping, f, a.sons[0])
|
||||||
case f.kind
|
case f.kind
|
||||||
of tyEnum:
|
of tyEnum:
|
||||||
if (a.kind == f.kind) and (a.id == f.id): result = isEqual
|
if a.kind == f.kind and a.id == f.id: result = isEqual
|
||||||
elif (skipTypes(a, {tyRange}).id == f.id): result = isSubtype
|
elif skipTypes(a, {tyRange}).id == f.id: result = isSubtype
|
||||||
of tyBool, tyChar:
|
of tyBool, tyChar:
|
||||||
if (a.kind == f.kind): result = isEqual
|
if a.kind == f.kind: result = isEqual
|
||||||
elif skipTypes(a, {tyRange}).kind == f.kind: result = isSubtype
|
elif skipTypes(a, {tyRange}).kind == f.kind: result = isSubtype
|
||||||
of tyRange:
|
of tyRange:
|
||||||
if (a.kind == f.kind):
|
if a.kind == f.kind:
|
||||||
result = typeRel(mapping, base(a), base(f))
|
result = typeRel(mapping, base(a), base(f))
|
||||||
if result < isGeneric: result = isNone
|
if result < isGeneric: result = isNone
|
||||||
elif skipTypes(f, {tyRange}).kind == a.kind:
|
elif skipTypes(f, {tyRange}).kind == a.kind:
|
||||||
result = isConvertible # a convertible to f
|
result = isConvertible # a convertible to f
|
||||||
of tyInt:
|
of tyInt: result = handleRange(f, a, tyInt8, tyInt32)
|
||||||
result = handleRange(f, a, tyInt8, tyInt32)
|
of tyInt8: result = handleRange(f, a, tyInt8, tyInt8)
|
||||||
of tyInt8:
|
of tyInt16: result = handleRange(f, a, tyInt8, tyInt16)
|
||||||
result = handleRange(f, a, tyInt8, tyInt8)
|
of tyInt32: result = handleRange(f, a, tyInt, tyInt32)
|
||||||
of tyInt16:
|
of tyInt64: result = handleRange(f, a, tyInt, tyInt64)
|
||||||
result = handleRange(f, a, tyInt8, tyInt16)
|
of tyFloat: result = handleFloatRange(f, a)
|
||||||
of tyInt32:
|
of tyFloat32: result = handleFloatRange(f, a)
|
||||||
result = handleRange(f, a, tyInt, tyInt32)
|
of tyFloat64: result = handleFloatRange(f, a)
|
||||||
of tyInt64:
|
of tyFloat128: result = handleFloatRange(f, a)
|
||||||
result = handleRange(f, a, tyInt, tyInt64)
|
|
||||||
of tyFloat:
|
|
||||||
result = handleFloatRange(f, a)
|
|
||||||
of tyFloat32:
|
|
||||||
result = handleFloatRange(f, a)
|
|
||||||
of tyFloat64:
|
|
||||||
result = handleFloatRange(f, a)
|
|
||||||
of tyFloat128:
|
|
||||||
result = handleFloatRange(f, a)
|
|
||||||
of tyVar:
|
of tyVar:
|
||||||
if (a.kind == f.kind): result = typeRel(mapping, base(f), base(a))
|
if (a.kind == f.kind): result = typeRel(mapping, base(f), base(a))
|
||||||
else: result = typeRel(mapping, base(f), a)
|
else: result = typeRel(mapping, base(f), a)
|
||||||
|
|
@ -227,8 +217,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
result = isNone
|
result = isNone
|
||||||
elif f.sons[0].kind in GenericTypes:
|
elif f.sons[0].kind in GenericTypes:
|
||||||
result = minRel(result, typeRel(mapping, f.sons[0], a.sons[0]))
|
result = minRel(result, typeRel(mapping, f.sons[0], a.sons[0]))
|
||||||
else:
|
else: nil
|
||||||
nil
|
|
||||||
of tyOpenArray:
|
of tyOpenArray:
|
||||||
case a.Kind
|
case a.Kind
|
||||||
of tyOpenArray:
|
of tyOpenArray:
|
||||||
|
|
@ -249,8 +238,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
result = isConvertible
|
result = isConvertible
|
||||||
elif typeRel(mapping, base(f), a.sons[0]) >= isGeneric:
|
elif typeRel(mapping, base(f), a.sons[0]) >= isGeneric:
|
||||||
result = isConvertible
|
result = isConvertible
|
||||||
else:
|
else: nil
|
||||||
nil
|
|
||||||
of tySequence:
|
of tySequence:
|
||||||
case a.Kind
|
case a.Kind
|
||||||
of tyNil:
|
of tyNil:
|
||||||
|
|
@ -261,16 +249,14 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
else:
|
else:
|
||||||
result = typeRel(mapping, f.sons[0], a.sons[0])
|
result = typeRel(mapping, f.sons[0], a.sons[0])
|
||||||
if result < isGeneric: result = isNone
|
if result < isGeneric: result = isNone
|
||||||
else:
|
else: nil
|
||||||
nil
|
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
if isOrdinalType(a):
|
if isOrdinalType(a):
|
||||||
if a.kind == tyOrdinal: x = a.sons[0]
|
if a.kind == tyOrdinal: x = a.sons[0]
|
||||||
else: x = a
|
else: x = a
|
||||||
result = typeRel(mapping, f.sons[0], x)
|
result = typeRel(mapping, f.sons[0], x)
|
||||||
if result < isGeneric: result = isNone
|
if result < isGeneric: result = isNone
|
||||||
of tyForward:
|
of tyForward: InternalError("forward type in typeRel()")
|
||||||
InternalError("forward type in typeRel()")
|
|
||||||
of tyNil:
|
of tyNil:
|
||||||
if a.kind == f.kind: result = isEqual
|
if a.kind == f.kind: result = isEqual
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
|
|
@ -294,23 +280,18 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
of tyPtr:
|
of tyPtr:
|
||||||
result = typeRel(mapping, base(f), base(a))
|
result = typeRel(mapping, base(f), base(a))
|
||||||
if result <= isConvertible: result = isNone
|
if result <= isConvertible: result = isNone
|
||||||
of tyNil:
|
of tyNil: result = isSubtype
|
||||||
result = isSubtype
|
else: nil
|
||||||
else:
|
|
||||||
nil
|
|
||||||
of tyRef:
|
of tyRef:
|
||||||
case a.kind
|
case a.kind
|
||||||
of tyRef:
|
of tyRef:
|
||||||
result = typeRel(mapping, base(f), base(a))
|
result = typeRel(mapping, base(f), base(a))
|
||||||
if result <= isConvertible: result = isNone
|
if result <= isConvertible: result = isNone
|
||||||
of tyNil:
|
of tyNil: result = isSubtype
|
||||||
result = isSubtype
|
else: nil
|
||||||
else:
|
|
||||||
nil
|
|
||||||
of tyProc:
|
of tyProc:
|
||||||
case a.kind
|
case a.kind
|
||||||
of tyNil:
|
of tyNil: result = isSubtype
|
||||||
result = isSubtype
|
|
||||||
of tyProc:
|
of tyProc:
|
||||||
if (sonsLen(f) == sonsLen(a)) and (f.callconv == a.callconv):
|
if (sonsLen(f) == sonsLen(a)) and (f.callconv == a.callconv):
|
||||||
# Note: We have to do unification for the parameters before the
|
# Note: We have to do unification for the parameters before the
|
||||||
|
|
@ -340,8 +321,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
result = isNone
|
result = isNone
|
||||||
if (tfNoSideEffect in f.flags) and not (tfNoSideEffect in a.flags):
|
if (tfNoSideEffect in f.flags) and not (tfNoSideEffect in a.flags):
|
||||||
result = isNone
|
result = isNone
|
||||||
else:
|
else: nil
|
||||||
nil
|
|
||||||
of tyPointer:
|
of tyPointer:
|
||||||
case a.kind
|
case a.kind
|
||||||
of tyPointer: result = isEqual
|
of tyPointer: result = isEqual
|
||||||
|
|
@ -356,12 +336,9 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
of tyCString:
|
of tyCString:
|
||||||
# conversion from string to cstring is automatic:
|
# conversion from string to cstring is automatic:
|
||||||
case a.Kind
|
case a.Kind
|
||||||
of tyCString:
|
of tyCString: result = isEqual
|
||||||
result = isEqual
|
of tyNil: result = isSubtype
|
||||||
of tyNil:
|
of tyString: result = isConvertible
|
||||||
result = isSubtype
|
|
||||||
of tyString:
|
|
||||||
result = isConvertible
|
|
||||||
of tyPtr:
|
of tyPtr:
|
||||||
if a.sons[0].kind == tyChar: result = isConvertible
|
if a.sons[0].kind == tyChar: result = isConvertible
|
||||||
of tyArray:
|
of tyArray:
|
||||||
|
|
@ -369,8 +346,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
|
||||||
(skipTypes(a.sons[0], {tyRange}).kind in {tyInt..tyInt64}) and
|
(skipTypes(a.sons[0], {tyRange}).kind in {tyInt..tyInt64}) and
|
||||||
(a.sons[1].kind == tyChar):
|
(a.sons[1].kind == tyChar):
|
||||||
result = isConvertible
|
result = isConvertible
|
||||||
else:
|
else: nil
|
||||||
nil
|
|
||||||
of tyEmpty:
|
of tyEmpty:
|
||||||
if a.kind == tyEmpty: result = isEqual
|
if a.kind == tyEmpty: result = isEqual
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
|
|
@ -682,10 +658,10 @@ proc matches(c: PContext, n: PNode, m: var TCandidate) =
|
||||||
|
|
||||||
proc sameMethodDispatcher(a, b: PSym): bool =
|
proc sameMethodDispatcher(a, b: PSym): bool =
|
||||||
result = false
|
result = false
|
||||||
if (a.kind == skMethod) and (b.kind == skMethod):
|
if a.kind == skMethod and b.kind == skMethod:
|
||||||
var aa = lastSon(a.ast)
|
var aa = lastSon(a.ast)
|
||||||
var bb = lastSon(b.ast)
|
var bb = lastSon(b.ast)
|
||||||
if (aa.kind == nkSym) and (bb.kind == nkSym) and (aa.sym == bb.sym):
|
if aa.kind == nkSym and bb.kind == nkSym and aa.sym == bb.sym:
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc semDirectCall(c: PContext, n: PNode, filter: TSymKinds): PNode =
|
proc semDirectCall(c: PContext, n: PNode, filter: TSymKinds): PNode =
|
||||||
|
|
@ -707,29 +683,25 @@ proc semDirectCall(c: PContext, n: PNode, filter: TSymKinds): PNode =
|
||||||
matches(c, n, z)
|
matches(c, n, z)
|
||||||
if z.state == csMatch:
|
if z.state == csMatch:
|
||||||
case x.state
|
case x.state
|
||||||
of csEmpty, csNoMatch:
|
of csEmpty, csNoMatch: x = z
|
||||||
x = z
|
|
||||||
of csMatch:
|
of csMatch:
|
||||||
var cmp = cmpCandidates(x, z)
|
var cmp = cmpCandidates(x, z)
|
||||||
if cmp < 0:
|
if cmp < 0: x = z # z is better than x
|
||||||
x = z # z is better than x
|
elif cmp == 0: y = z # z is as good as x
|
||||||
elif cmp == 0:
|
else: nil
|
||||||
y = z # z is as good as x
|
|
||||||
else:
|
|
||||||
nil
|
|
||||||
sym = nextOverloadIter(o, c, n.sons[0])
|
sym = nextOverloadIter(o, c, n.sons[0])
|
||||||
if x.state == csEmpty:
|
if x.state == csEmpty:
|
||||||
# no overloaded proc found
|
# no overloaded proc found
|
||||||
# do not generate an error yet; the semantic checking will check for
|
# do not generate an error yet; the semantic checking will check for
|
||||||
# an overloaded () operator
|
# an overloaded () operator
|
||||||
elif (y.state == csMatch) and (cmpCandidates(x, y) == 0) and
|
elif y.state == csMatch and cmpCandidates(x, y) == 0 and
|
||||||
not sameMethodDispatcher(x.calleeSym, y.calleeSym):
|
not sameMethodDispatcher(x.calleeSym, y.calleeSym):
|
||||||
if x.state != csMatch:
|
if x.state != csMatch:
|
||||||
InternalError(n.info, "x.state is not csMatch") #writeMatches(x);
|
InternalError(n.info, "x.state is not csMatch") #writeMatches(x);
|
||||||
#writeMatches(y);
|
#writeMatches(y);
|
||||||
liMessage(n.Info, errGenerated, `%`(msgKindToString(errAmbiguousCallXYZ), [
|
liMessage(n.Info, errGenerated, msgKindToString(errAmbiguousCallXYZ) % [
|
||||||
getProcHeader(x.calleeSym), getProcHeader(y.calleeSym),
|
getProcHeader(x.calleeSym), getProcHeader(y.calleeSym),
|
||||||
x.calleeSym.Name.s]))
|
x.calleeSym.Name.s])
|
||||||
else:
|
else:
|
||||||
# only one valid interpretation found:
|
# only one valid interpretation found:
|
||||||
markUsed(n, x.calleeSym)
|
markUsed(n, x.calleeSym)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ proc execCode(code: string): string =
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
raise newException(EIO, "Unable to open file")
|
raise newException(EIO, "Unable to open file")
|
||||||
result = osproc.execProcess("nimrod run --verbosity:0 temp.nim")
|
result = osproc.execProcess(
|
||||||
|
"nimrod run --verbosity:0 --hint[Conf]:off temp.nim")
|
||||||
|
|
||||||
var shiftPressed = False
|
var shiftPressed = False
|
||||||
var w: gtk2.PWindow
|
var w: gtk2.PWindow
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue