new VM: some progress for the FFI support
This commit is contained in:
parent
e2a4d591e5
commit
9145bcfbb6
8 changed files with 80 additions and 60 deletions
|
|
@ -10,7 +10,7 @@
|
|||
import os, strutils
|
||||
|
||||
const
|
||||
cc = "gcc -o $1 $1.c"
|
||||
cc = "gcc -o $# $#.c"
|
||||
|
||||
cfile = """
|
||||
/* Generated by detect.nim */
|
||||
|
|
@ -37,6 +37,7 @@ var
|
|||
tl = ""
|
||||
|
||||
proc myExec(cmd: string): bool =
|
||||
echo "CMD ", cmd
|
||||
return execShellCmd(cmd) == 0
|
||||
|
||||
proc header(s: string): bool =
|
||||
|
|
@ -46,7 +47,7 @@ proc header(s: string): bool =
|
|||
f.write("#include $1\n" % s)
|
||||
f.write("int main() { return 0; }\n")
|
||||
close(f)
|
||||
result = myExec(cc % testh)
|
||||
result = myExec(cc % [testh.addFileExt(ExeExt), testh])
|
||||
removeFile(addFileExt(testh, "c"))
|
||||
if result:
|
||||
addf(hd, "#include $1\n", s)
|
||||
|
|
@ -60,13 +61,16 @@ proc main =
|
|||
if open(f, addFileExt(gen, "c"), fmWrite):
|
||||
f.write(cfile % [hd, tl, system.hostOS, system.hostCPU])
|
||||
close(f)
|
||||
if not myExec(cc % gen): quit(1)
|
||||
if not myExec("./" & gen): quit(1)
|
||||
if not myExec(cc % [gen.addFileExt(ExeExt), gen]): quit(1)
|
||||
when defined(windows):
|
||||
if not myExec(gen.addFileExt(ExeExt)): quit(1)
|
||||
else:
|
||||
if not myExec("./" & gen): quit(1)
|
||||
removeFile(addFileExt(gen, "c"))
|
||||
echo("Success")
|
||||
|
||||
proc v(name: string, typ: TTypeKind=cint) =
|
||||
var n = if name[0] == '_': copy(name, 1) else: name
|
||||
var n = if name[0] == '_': substr(name, 1) else: name
|
||||
var t = $typ
|
||||
case typ
|
||||
of pointer:
|
||||
|
|
@ -369,7 +373,7 @@ if header("<pthread.h>"):
|
|||
#v("PTHREAD_MUTEX_INITIALIZER")
|
||||
v("PTHREAD_MUTEX_NORMAL")
|
||||
v("PTHREAD_MUTEX_RECURSIVE") #{.importc, header: "<pthread.h>".}: cint
|
||||
v("PTHREAD_ONCE_INIT") #{.importc, header: "<pthread.h>".}: cint
|
||||
#v("PTHREAD_ONCE_INIT") #{.importc, header: "<pthread.h>".}: cint
|
||||
v("PTHREAD_PRIO_INHERIT") #{.importc, header: "<pthread.h>".}: cint
|
||||
v("PTHREAD_PRIO_NONE") #{.importc, header: "<pthread.h>".}: cint
|
||||
v("PTHREAD_PRIO_PROTECT") #{.importc, header: "<pthread.h>".}: cint
|
||||
|
|
@ -820,5 +824,8 @@ if header("<spawn.h>"):
|
|||
v("POSIX_SPAWN_SETSIGDEF")
|
||||
v("POSIX_SPAWN_SETSIGMASK")
|
||||
|
||||
main()
|
||||
if header("<stdio.h>"):
|
||||
v "_IOFBF"
|
||||
v "_IONBF"
|
||||
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue