WIP
This commit is contained in:
parent
1e303100f8
commit
a401a8e553
6 changed files with 50 additions and 18 deletions
|
|
@ -47,5 +47,5 @@ build_nim_csources(){
|
|||
# Note: if fails, may need to `cd csources && git pull`
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -95,6 +95,21 @@ proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.Type =
|
|||
result = addr libffi.type_pointer
|
||||
of tyDistinct, tyAlias, tySink:
|
||||
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:
|
||||
result = nil
|
||||
# too risky:
|
||||
|
|
@ -115,6 +130,7 @@ template `+!`(x, y: untyped): untyped =
|
|||
|
||||
proc packSize(conf: ConfigRef, v: PNode, typ: PType): int =
|
||||
## computes the size of the blob
|
||||
echo typ.kind
|
||||
case typ.kind
|
||||
of tyPtr, tyRef, tyVar, tyLent:
|
||||
if v.kind in {nkNilLit, nkPtrLit}:
|
||||
|
|
@ -128,8 +144,25 @@ proc packSize(conf: ConfigRef, v: PNode, typ: PType): int =
|
|||
# we use the real length here instead
|
||||
if v.kind in {nkNilLit, nkPtrLit}:
|
||||
result = sizeof(pointer)
|
||||
elif v.len != 0:
|
||||
result = v.len * packSize(conf, v[0], typ[1])
|
||||
elif typ.sons.len != 0:
|
||||
echo v.kind
|
||||
let trange = typ.sons[0].n
|
||||
let ttypenode = typ.sons[1]
|
||||
let anode = trange.sons[1]
|
||||
echo anode.intVal
|
||||
echo "adfadf"
|
||||
echo typ.kind
|
||||
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:
|
||||
result = getSize(conf, typ).int
|
||||
|
||||
|
|
|
|||
|
|
@ -1605,4 +1605,4 @@ proc genFieldError*(field: PSym, disc: PSym): string =
|
|||
## import ast
|
||||
result = field.name.s.quoteExpr & " is not accessible using discriminant " &
|
||||
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) =
|
||||
## computes and sets ``size`` and ``align`` members of ``typ``
|
||||
assert typ != nil
|
||||
echo "In size align!!"
|
||||
echo typ.kind
|
||||
let hasSize = typ.size != szUncomputedSize
|
||||
let hasAlign = typ.align != szUncomputedSize
|
||||
|
||||
|
|
|
|||
|
|
@ -609,6 +609,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
|||
of rkNode:
|
||||
if regs[rb].node.typ.kind notin PtrLikeKinds:
|
||||
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
|
||||
else: stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].kind: " & $regs[rb].kind)
|
||||
regs[ra].node = node2
|
||||
|
|
|
|||
|
|
@ -244,20 +244,15 @@ proc write*(f: File, s: string) {.tags: [WriteIOEffect], benign.} =
|
|||
raiseEIO("cannot write string to file")
|
||||
{.pop.}
|
||||
|
||||
when NoFakeVars:
|
||||
when defined(windows):
|
||||
const
|
||||
IOFBF = cint(0)
|
||||
IONBF = cint(4)
|
||||
else:
|
||||
# On all systems I could find, including Linux, Mac OS X, and the BSDs
|
||||
const
|
||||
IOFBF = cint(0)
|
||||
IONBF = cint(2)
|
||||
when defined(windows):
|
||||
const
|
||||
IOFBF = cint(0)
|
||||
IONBF = cint(4)
|
||||
else:
|
||||
var
|
||||
IOFBF {.importc: "_IOFBF", nodecl.}: cint
|
||||
IONBF {.importc: "_IONBF", nodecl.}: cint
|
||||
# On all systems I could find, including Linux, Mac OS X, and the BSDs
|
||||
const
|
||||
IOFBF = cint(0)
|
||||
IONBF = cint(2)
|
||||
|
||||
const
|
||||
BufSize = 4000
|
||||
|
|
@ -507,7 +502,7 @@ const
|
|||
# should not be translated.
|
||||
|
||||
when defined(posix) and not defined(nimscript):
|
||||
when defined(linux) and defined(amd64):
|
||||
when (defined(linux) or defined(macosx)) and defined(amd64):
|
||||
type
|
||||
Mode {.importc: "mode_t", header: "<sys/types.h>".} = cint
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue