tcnstseq works again

This commit is contained in:
Araq 2013-12-23 08:28:32 +01:00
commit 4447c1b7e3
3 changed files with 17 additions and 6 deletions

View file

@ -43,7 +43,7 @@ proc activate(c: PContext, n: PNode)
proc semQuoteAst(c: PContext, n: PNode): PNode proc semQuoteAst(c: PContext, n: PNode): PNode
proc finishMethod(c: PContext, s: PSym) proc finishMethod(c: PContext, s: PSym)
proc IndexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode
proc typeMismatch(n: PNode, formal, actual: PType) = proc typeMismatch(n: PNode, formal, actual: PType) =
if formal.kind != tyError and actual.kind != tyError: if formal.kind != tyError and actual.kind != tyError:
@ -63,7 +63,7 @@ proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
if result == nil: if result == nil:
typeMismatch(arg, formal, arg.typ) typeMismatch(arg, formal, arg.typ)
# error correction: # error correction:
result = copyNode(arg) result = copyTree(arg)
result.typ = formal result.typ = formal
var CommonTypeBegin = PType(kind: tyExpr) var CommonTypeBegin = PType(kind: tyExpr)
@ -211,7 +211,15 @@ proc semConstExpr(c: PContext, n: PNode): PNode =
# recompute the types as 'eval' isn't guaranteed to construct types nor # recompute the types as 'eval' isn't guaranteed to construct types nor
# that the types are sound: # that the types are sound:
result = semExprWithType(c, result) result = semExprWithType(c, result)
result = fitNode(c, e.typ, result) #result = fitNode(c, e.typ, result) inlined with special case:
let arg = result
result = indexTypesMatch(c, e.typ, arg.typ, arg)
if result == nil:
result = arg
# for 'tcnstseq' we support [] to become 'seq'
if e.typ.skipTypes(abstractInst).kind == tySequence and
arg.typ.skipTypes(abstractInst).kind == tyArrayConstr:
arg.typ = e.typ
include hlo, seminst, semcall include hlo, seminst, semcall

View file

@ -632,10 +632,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
# we pass 'tos.slots' instead of 'regs' so that the compiler can keep # we pass 'tos.slots' instead of 'regs' so that the compiler can keep
# 'regs' in a register: # 'regs' in a register:
when hasFFI: when hasFFI:
if c.globals.sons[prc.position-1].kind == nkEmpty: let prcValue = c.globals.sons[prc.position-1]
if prcValue.kind == nkEmpty:
globalError(c.debug[pc], errGenerated, "canot run " & prc.name.s) globalError(c.debug[pc], errGenerated, "canot run " & prc.name.s)
let newValue = callForeignFunction(c.globals.sons[prc.position-1], let newValue = callForeignFunction(prcValue, prc.typ, tos.slots,
prc.typ, tos.slots,
rb+1, rc-1, c.debug[pc]) rb+1, rc-1, c.debug[pc])
if newValue.kind != nkEmpty: if newValue.kind != nkEmpty:
assert instr.opcode == opcIndCallAsgn assert instr.opcode == opcIndCallAsgn

View file

@ -10,6 +10,9 @@
## Nimrod support for C/C++'s `wide strings`:idx:. This is part of the system ## Nimrod support for C/C++'s `wide strings`:idx:. This is part of the system
## module! Do not import it directly! ## module! Do not import it directly!
when not defined(NimString):
{.error: "You must not import this module explicitly".}
type type
TUtf16Char* = distinct int16 TUtf16Char* = distinct int16
WideCString* = ref array[0.. 1_000_000, TUtf16Char] WideCString* = ref array[0.. 1_000_000, TUtf16Char]