From a401a8e5536ead1bfe949df306985c694b60f03d Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 10 Feb 2020 14:38:40 -0700 Subject: [PATCH 1/2] WIP --- build_all.sh | 2 +- compiler/evalffi.nim | 37 ++++++++++++++++++++++++++++++-- compiler/renderer.nim | 2 +- compiler/sizealignoffsetimpl.nim | 2 ++ compiler/vm.nim | 2 ++ lib/system/io.nim | 23 ++++++++------------ 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/build_all.sh b/build_all.sh index 2ed2233e9..84230c018 100644 --- a/build_all.sh +++ b/build_all.sh @@ -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. diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index 58c505a5b..3c47251c1 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -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..".} = cint From ccf052fe6ff39c2b7a4e19d05488e9d2c3d1cfcb Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Wed, 12 Feb 2020 08:30:35 -0700 Subject: [PATCH 2/2] WIP2 --- compiler/evalffi.nim | 5 ----- compiler/sizealignoffsetimpl.nim | 4 ++-- compiler/vm.nim | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index 3c47251c1..856410eda 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -130,7 +130,6 @@ 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}: @@ -145,13 +144,9 @@ proc packSize(conf: ConfigRef, v: PNode, typ: PType): int = if v.kind in {nkNilLit, nkPtrLit}: result = sizeof(pointer) 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) diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 92cfcb0c3..455bbd3a2 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -196,8 +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 + # echo "In size align!!" + # echo typ.kind let hasSize = typ.size != szUncomputedSize let hasAlign = typ.align != szUncomputedSize diff --git a/compiler/vm.nim b/compiler/vm.nim index df646f509..9d4ef298c 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -592,7 +592,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of 1: # PtrLikeKinds case regs[rb].kind 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: regs[ra].intVal = cast[int](regs[rb].nodeAddr) else: @@ -609,8 +619,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 + # 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