Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccf052fe6f | ||
|
|
a401a8e553 |
6 changed files with 56 additions and 19 deletions
|
|
@ -47,5 +47,5 @@ build_nim_csources(){
|
||||||
# Note: if fails, may need to `cd csources && git pull`
|
# Note: if fails, may need to `cd csources && git pull`
|
||||||
echo_run bin/nim c --skipUserCfg --skipParentCfg koch
|
echo_run bin/nim c --skipUserCfg --skipParentCfg koch
|
||||||
|
|
||||||
echo_run ./koch boot -d:release
|
echo_run ./koch boot -d:release -d:nimHasLibFFI
|
||||||
echo_run ./koch tools # Compile Nimble and other tools.
|
echo_run ./koch tools # Compile Nimble and other tools.
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,21 @@ proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.Type =
|
||||||
result = addr libffi.type_pointer
|
result = addr libffi.type_pointer
|
||||||
of tyDistinct, tyAlias, tySink:
|
of tyDistinct, tyAlias, tySink:
|
||||||
result = mapType(conf, t[0])
|
result = mapType(conf, t[0])
|
||||||
|
of tyObject:
|
||||||
|
var els = newSeq[ptr libffi.Type](t.n.sons.len + 1)
|
||||||
|
var ty: ptr libffi.Type = cast[ptr libffi.Type](alloc(sizeof(libffi.Type)))
|
||||||
|
|
||||||
|
ty.size = 0
|
||||||
|
ty.alignment = 0
|
||||||
|
ty.typ = tkSTRUCT
|
||||||
|
ty.elements = addr els[0]
|
||||||
|
|
||||||
|
els[els.len-1] = nil
|
||||||
|
for i in 0..<t.n.sons.len:
|
||||||
|
let son = t.n.sons[i]
|
||||||
|
els[i] = mapType(conf, son.typ)
|
||||||
|
|
||||||
|
result = ty
|
||||||
else:
|
else:
|
||||||
result = nil
|
result = nil
|
||||||
# too risky:
|
# too risky:
|
||||||
|
|
@ -128,8 +143,21 @@ proc packSize(conf: ConfigRef, v: PNode, typ: PType): int =
|
||||||
# we use the real length here instead
|
# we use the real length here instead
|
||||||
if v.kind in {nkNilLit, nkPtrLit}:
|
if v.kind in {nkNilLit, nkPtrLit}:
|
||||||
result = sizeof(pointer)
|
result = sizeof(pointer)
|
||||||
elif v.len != 0:
|
elif typ.sons.len != 0:
|
||||||
result = v.len * packSize(conf, v[0], typ[1])
|
let trange = typ.sons[0].n
|
||||||
|
let ttypenode = typ.sons[1]
|
||||||
|
let anode = trange.sons[1]
|
||||||
|
result += (anode.intVal.int + 1) * packSize(conf, ttypenode.n, ttypenode)
|
||||||
|
# for ts in trange.sons:
|
||||||
|
# result += ts.intVal * packSize(conf, typ.sons[1], typ.sons[1].typ)
|
||||||
|
# for ts in typ.sons:
|
||||||
|
# echo ts.kind
|
||||||
|
# echo ts.n.kind
|
||||||
|
elif v.sons.len != 0:
|
||||||
|
result = v.sons.len * packSize(conf, v[0], typ[1])
|
||||||
|
of tyObject:
|
||||||
|
for son in typ.n.sons:
|
||||||
|
result += packSize(conf, son, son.typ)
|
||||||
else:
|
else:
|
||||||
result = getSize(conf, typ).int
|
result = getSize(conf, typ).int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1605,4 +1605,4 @@ proc genFieldError*(field: PSym, disc: PSym): string =
|
||||||
## import ast
|
## import ast
|
||||||
result = field.name.s.quoteExpr & " is not accessible using discriminant " &
|
result = field.name.s.quoteExpr & " is not accessible using discriminant " &
|
||||||
disc.name.s.quoteExpr & " of type " &
|
disc.name.s.quoteExpr & " of type " &
|
||||||
disc.owner.name.s.quoteExpr
|
$disc.owner.ast.kind
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,8 @@ proc computeUnionObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; accum: var
|
||||||
proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||||
## computes and sets ``size`` and ``align`` members of ``typ``
|
## computes and sets ``size`` and ``align`` members of ``typ``
|
||||||
assert typ != nil
|
assert typ != nil
|
||||||
|
# echo "In size align!!"
|
||||||
|
# echo typ.kind
|
||||||
let hasSize = typ.size != szUncomputedSize
|
let hasSize = typ.size != szUncomputedSize
|
||||||
let hasAlign = typ.align != szUncomputedSize
|
let hasAlign = typ.align != szUncomputedSize
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of 1: # PtrLikeKinds
|
of 1: # PtrLikeKinds
|
||||||
case regs[rb].kind
|
case regs[rb].kind
|
||||||
of rkNode:
|
of rkNode:
|
||||||
regs[ra].intVal = cast[int](regs[rb].node.intVal)
|
case regs[rb].node.kind
|
||||||
|
of nkCharLit..nkUInt64Lit:
|
||||||
|
regs[ra].intVal = regs[rb].node.intVal
|
||||||
|
of nkFloatLit..nkFloat128Lit:
|
||||||
|
regs[ra].intVal = int64(regs[rb].floatVal)
|
||||||
|
else:
|
||||||
|
# echo regs[rb].node.kind
|
||||||
|
# echo regs[rb].node.typ.kind
|
||||||
|
# for son in regs[rb].node.sons:
|
||||||
|
# echo son.kind
|
||||||
|
regs[ra].intVal = cast[int](regs[rb].node.addr)
|
||||||
of rkNodeAddr:
|
of rkNodeAddr:
|
||||||
regs[ra].intVal = cast[int](regs[rb].nodeAddr)
|
regs[ra].intVal = cast[int](regs[rb].nodeAddr)
|
||||||
else:
|
else:
|
||||||
|
|
@ -609,6 +619,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of rkNode:
|
of rkNode:
|
||||||
if regs[rb].node.typ.kind notin PtrLikeKinds:
|
if regs[rb].node.typ.kind notin PtrLikeKinds:
|
||||||
stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].node.typ: " & $regs[rb].node.typ.kind)
|
stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].node.typ: " & $regs[rb].node.typ.kind)
|
||||||
|
# echo node2.kind
|
||||||
|
# echo regs[rb].node.kind
|
||||||
node2.intVal = regs[rb].node.intVal
|
node2.intVal = regs[rb].node.intVal
|
||||||
else: stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].kind: " & $regs[rb].kind)
|
else: stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].kind: " & $regs[rb].kind)
|
||||||
regs[ra].node = node2
|
regs[ra].node = node2
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,6 @@ proc write*(f: File, s: string) {.tags: [WriteIOEffect], benign.} =
|
||||||
raiseEIO("cannot write string to file")
|
raiseEIO("cannot write string to file")
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
when NoFakeVars:
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
|
|
@ -254,10 +253,6 @@ when NoFakeVars:
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
IONBF = cint(2)
|
IONBF = cint(2)
|
||||||
else:
|
|
||||||
var
|
|
||||||
IOFBF {.importc: "_IOFBF", nodecl.}: cint
|
|
||||||
IONBF {.importc: "_IONBF", nodecl.}: cint
|
|
||||||
|
|
||||||
const
|
const
|
||||||
BufSize = 4000
|
BufSize = 4000
|
||||||
|
|
@ -507,7 +502,7 @@ const
|
||||||
# should not be translated.
|
# should not be translated.
|
||||||
|
|
||||||
when defined(posix) and not defined(nimscript):
|
when defined(posix) and not defined(nimscript):
|
||||||
when defined(linux) and defined(amd64):
|
when (defined(linux) or defined(macosx)) and defined(amd64):
|
||||||
type
|
type
|
||||||
Mode {.importc: "mode_t", header: "<sys/types.h>".} = cint
|
Mode {.importc: "mode_t", header: "<sys/types.h>".} = cint
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue