├── .gitignore ├── LICENSE ├── NimBorg.babel ├── README.md ├── TODO.txt ├── changelog.txt ├── contributors.txt └── nimborg ├── lua ├── high_level.nim ├── low_level │ ├── lauxlib.nim │ ├── lua.nim │ └── lualib.nim ├── test │ ├── Makefile │ └── test_lua.nim └── usage.txt └── py ├── high_level.nim ├── low_level.nim ├── test ├── Makefile ├── test_linalg.nim ├── test_py.nim ├── test_py_eval.nim └── test_pylab.nim └── usage.txt /.gitignore: -------------------------------------------------------------------------------- 1 | nimcache 2 | *~ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 by the contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /NimBorg.babel: -------------------------------------------------------------------------------- 1 | [Package] 2 | name: "NimBorg" 3 | version: "0.0.2" 4 | author: "Andreas Rumpf & Micky Latowicki" 5 | description: "Both low-level and high-level wrappers to interface with foreign languages" 6 | license: "MIT" 7 | 8 | [Deps] 9 | requires: "nimrod > 0.9.2" 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NimBorg 2 | ======= 3 | 4 | The goal of NimBorg is to assimilate multiple programming languages into the 5 | Nimrod ecosystem. In other words, I aspire to develop here high-level interfaces 6 | between Nimrod and other languages. Currently we have very basic support for 7 | python and lua. 8 | 9 | The current state of the bindings can be observed by looking at the 'test' directory 10 | for each of the languages. There's also a "usage.txt" file under nimborg/py and under 11 | nimborg/lua, but it might occasionally get out-of-date, so the tests are more reliable. 12 | 13 | This project is unmaintained 14 | ============================ 15 | 16 | This repo is no longer maintained. If there is any volunteer willing 17 | to maintain it, please open an issue asking to receive maintainership. 18 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | most urgently needed: 2 | * internals docs 3 | * pass nimrod functions to the foreign runtime? (might lead to memory leaks due to uncollectable cycles) 4 | 5 | lower priority 6 | * change the python API to work more like the lua API. The PyRefs and the PyContexts 7 | should hold a reference to the Interpreter so that it isn't collected before they are. 8 | * switch to nake (?) 9 | * read through the Julia discussion here and pick some ideas 10 | https://groups.google.com/forum/#!msg/julia-dev/YftOOEfcwrk/7q3cm2y3Xs4J 11 | 12 | blue sky 13 | * perl, java, R (follow rpy2), ... 14 | * parrot supports pluggable GC, so it might be feasible to run a parrot instance inside 15 | a nimrod process with references pointing in both directions, and still no memory leaks. 16 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 2014-02-18 2 | * eliminate the ~ macro, using Zahary's `.` overloads instead 3 | * add exec(stmt) to lua 4 | 5 | -------------------------------------------------------------------------------- /contributors.txt: -------------------------------------------------------------------------------- 1 | This package contains the work of the following authors: 2 | 3 | Andreas Rumpf 4 | Dr. Dietmar Budelsky 5 | TeCGraf 6 | Lavergne Thomas 7 | Bram Kuijvenhoven 8 | Micky Latowicki 9 | -------------------------------------------------------------------------------- /nimborg/lua/high_level.nim: -------------------------------------------------------------------------------- 1 | from low_level/lua import REGISTRYINDEX, Integer, Number 2 | from low_level/lualib import nil 3 | from low_level/lauxlib import NOREF, unref, reference 4 | import macros 5 | from strutils import format, `%` 6 | 7 | # TODO: 8 | # 9 | # * call nimrod functions from lua 10 | # * more error handling 11 | # * each proc should check that its args belong to the same lua state, 12 | # subject perhaps to a compilation flag 13 | 14 | type 15 | # wrap a LuaState in an object, to facilitate future use of destructors: 16 | LuaState = object {.byref.} 17 | L: lua.PState 18 | PLuaState* = ref LuaState 19 | 20 | # A non-borrowed (counted) reference. Avoid copying these around! Nimrod 21 | # doesn't have the equivalent of an assignment constructor (yet?), so any 22 | # copy of a LuaRef must be counted (use dup for that). 23 | LuaRef = object {.byref.} 24 | state: PLuaState # prevents the lua state from being GC'd while this ref is alive 25 | r: cint 26 | PLuaRef* = ref LuaRef 27 | 28 | ELua* = object of Exception 29 | ELuaTypeError* = object of ELua 30 | ELuaSyntax* = object of ELua 31 | #ELuaGCMM* = object of ELua # only defined in lua 5.2, the bindings are for 5.1 32 | 33 | # forward declarations: 34 | proc toLua*[T](state: PLuaState, x:T) : PLuaRef 35 | proc callWithLuaRefs*(f: PLuaRef, args: varargs[PLuaRef]): PLuaRef 36 | 37 | #------------------------------------------------------------ 38 | # lifetime management 39 | 40 | proc finalizeLuaRef(o: PLuaRef) = 41 | unref(o.state.L, REGISTRYINDEX, o.r) 42 | o.r = NOREF 43 | 44 | proc popRef*(state: PLuaState): PLuaRef {.inline.} = 45 | new(result, finalizeLuaRef) 46 | result.state = state 47 | #echo "gettop=", lua.gettop(state.L) 48 | assert(lua.gettop(state.L)>0) 49 | result.r = reference(state.L, REGISTRYINDEX) 50 | 51 | #------------------------------------------------------------ 52 | # pushing stuff into the stack 53 | 54 | {.push inline.} 55 | 56 | proc luaPush*(s: PLuaState, x:int) = lua.pushinteger(s.L, Integer(x)) 57 | proc luaPush*(s: PLuaState, x:string) = lua.pushstring(s.L, x) 58 | proc luaPush*(s: PLuaState, x:cstring) = lua.pushstring(s.L, x) 59 | proc luaPush*(s: PLuaState, x:float) = lua.pushnumber(s.L, x) 60 | proc luaPush*(s: PLuaState, x:bool) = lua.pushboolean(s.L, ord(x)) 61 | 62 | proc luaPush*(x: PLuaRef): void = 63 | assert(x!=nil) 64 | #echo "calling rawgeti(L, REGISTRYINDEX, $1)" % $x.r 65 | lua.rawgeti(x.state.L, REGISTRYINDEX, x.r) 66 | #echo "lua type of returned value is ", lua.luatype(x.state.L, -1) 67 | 68 | proc len*(x: PLuaRef): cint = lua.objlen(x.state.L, x.r) 69 | 70 | {.pop.} 71 | 72 | proc toLua*(state: PLuaState, x:PLuaRef): PLuaRef = x 73 | 74 | proc toLua*[T](state: PLuaState, x:T) : PLuaRef = 75 | state.luaPush(x) 76 | result = popRef(state) 77 | 78 | proc openLibs*(s: PLuaState) : void = lualib.openlibs(s.L) 79 | 80 | proc finalizeLuaState(s: PLuaState) = 81 | if s.L!=nil: 82 | lua.close(s.L) 83 | s.L = nil 84 | 85 | proc newLuaState*(open_std_libs=true) : PLuaState = 86 | let L = lauxlib.newstate() 87 | if L==nil: 88 | raise newException(OutOfMemError, "failure in lua_newstate()") 89 | new(result, finalizeLuaState) 90 | result.L = L 91 | if open_std_libs: result.openLibs() 92 | 93 | proc luaTable*(s: PLuaState): PLuaRef = 94 | lua.newtable(s.L) 95 | result = s.popRef 96 | 97 | proc luaError(err_code: int, context = "lua FFI"): void = 98 | case err_code: 99 | of lua.OK: 100 | discard 101 | of lua.ERRSYNTAX: 102 | raise newException(ELuaSyntax, context) 103 | of lua.ERRMEM: 104 | raise newException(OutOfMemError, context) 105 | else: 106 | let msg = format("lua thread state=$1, in $2", 107 | err_code, context) 108 | raise newException(ELua, msg) 109 | 110 | proc nullaryFunc*(s: PLuaState, body: string): PLuaRef = 111 | let err_code = lauxlib.loadstring(s.L, body) 112 | if err_code == lua.OK: 113 | return popRef(s) 114 | lua.pop(s.L, 1) 115 | if err_code == lua.ERRSYNTAX: 116 | raise newException(ELuaSyntax, "syntax error in: " & body) 117 | else: 118 | luaError(err_code, body) 119 | 120 | proc exec*(s: PLuaState, luaStmt: string): PLuaRef {.discardable.} = 121 | callWithLuaRefs(s.nullaryFunc(luaStmt)) 122 | 123 | proc eval*(s: PLuaState, luaExpr: string): PLuaRef {.discardable.} = 124 | exec(s, "return " & luaExpr) 125 | 126 | #------------------------------ 127 | 128 | proc toInt*(x: PLuaRef): Integer = 129 | luaPush(x) 130 | result = lua.tointeger(x.state.L, -1) 131 | lua.pop(x.state.L, 1) 132 | 133 | proc toFloat*(x: PLuaRef): Number = 134 | luaPush(x) 135 | result = lua.tonumber(x.state.L, -1) 136 | lua.pop(x.state.L, 1) 137 | 138 | proc toString(x: PLuaRef): string = 139 | luaPush(x) 140 | try: 141 | if lua.isstring(x.state.L, -1) != 0: 142 | result = $lua.tostring(x.state.L, -1) 143 | else: 144 | raise newException(ELuaTypeError, "This lua object is not immediately convertible to string") 145 | finally: 146 | lua.pop(x.state.L, 1) 147 | 148 | #------------------------------------------------------------------------------- 149 | # operators 150 | 151 | proc `[]=`*[K,V](table: PLuaRef, key: K, val: V): void = 152 | luaPush(table) 153 | luaPush(table.state, key) 154 | luaPush(table.state, val) 155 | lua.settable(table.state.L, -3) 156 | lua.pop(table.state.L, 1) 157 | 158 | proc lookupKey[K](table: PLuaRef, key: K): PLuaRef = 159 | let s = table.state 160 | luaPush(table) 161 | luaPush(s, key) 162 | lua.gettable(s.L, -2) 163 | result = popRef(s) 164 | lua.pop(table.state.L, 1) 165 | 166 | proc `[]`*[K](table: PLuaRef, key:K): PLuaRef = lookupKey[K](table, key) 167 | 168 | proc `$`*(x: PLuaRef): string {.inline.} = toString(x) 169 | 170 | proc peek*(s: PLuaState): string = 171 | if lua.gettop(s.L)==0: 172 | return "NA" 173 | let t = lua.luatype(s.L, -1) 174 | if lua.isstring(s.L, -1) != 0: 175 | return format("$1{$2}", $lua.tostring(s.L, -1), t) 176 | return "non-stringable{$1}" % $t 177 | 178 | proc callWithLuaRefs(f: PLuaRef, args: varargs[PLuaRef]): PLuaRef = 179 | let s = f.state 180 | luaPush(f) 181 | for i in 0..args.len-1: 182 | luaPush(args[i]) 183 | let err_code = lua.pcall(s.L, cint(args.len), 1, 0) 184 | if err_code == lua.OK: 185 | #echo "call result is: ", peek(s) 186 | result = popRef(s) 187 | else: 188 | #echo "call failed ($1)" % $err_code 189 | let err_text = popRef(s) 190 | luaError(err_code, toString(err_text)) 191 | assert(result!=nil) 192 | 193 | proc newLuaCall(func: PNimrodNode, args: openarray[PNimrodNode]): PNimrodNode {.compileTime.} = 194 | template let_f(f: expr, func: PLuaRef, body: expr): expr {.immediate.} = 195 | # a workaround to nimrod issue #904 196 | (proc(f: PLuaref): PLuaRef = body)(func) 197 | let f = gensym(nskParam, "f") 198 | let body = newCall(bindSym"callWithLuaRefs", f) 199 | for i in 0..args.len-1: 200 | let state = newDotExpr(f, newIdentNode("state")) 201 | body.add(newCall(bindSym"toLua", state, args[i])) 202 | result = getAst(let_f(f, func, body)) 203 | 204 | proc argsFromCS(cs: PNimrodNode, nDropped: int): seq[PNimrodNode] {.compileTime.} = 205 | result = @[] 206 | for i in nDropped..len(cs)-1: result.add(cs[i]) 207 | 208 | macro `()`*(func: PLuaRef, args: varargs[expr]): PLuaRef = 209 | # work around the problems with varargs by pulling arguments 210 | # out of callsite(): 211 | let cs = callsite() 212 | assert($toStrLit(cs[1]) == $toStrLit(func)) 213 | result = newLuaCall(func, argsFromCS(cs, 2)) 214 | 215 | #------------------------------------------------------------------------------- 216 | # the new mechanism for overloading the dot 217 | 218 | proc `.`*(obj: PLuaRef, field: string): PLuaRef {.inline.} = 219 | lookupKey[string](obj, field) 220 | 221 | proc `.=`*[T](obj: PLuaRef, field: string, value: T) {.inline.} = 222 | obj[field] = toLua(value) 223 | 224 | macro `.()`*(obj: PLuaRef, field: string, args: varargs[expr]): expr = 225 | let cs = callsite() 226 | assert($cs[2] == $field) 227 | let func = newCall(bindSym"lookupKey", obj, field) 228 | result = newLuaCall(func, argsFromCS(cs, 3)) 229 | -------------------------------------------------------------------------------- /nimborg/lua/low_level/lauxlib.nim: -------------------------------------------------------------------------------- 1 | #***************************************************************************** 2 | # * * 3 | # * File: lauxlib.pas * 4 | # * Authors: TeCGraf (C headers + actual Lua libraries) * 5 | # * Lavergne Thomas (original translation to Pascal) * 6 | # * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) * 7 | # * Description: Lua auxiliary library * 8 | # * * 9 | # ***************************************************************************** 10 | # 11 | #** $Id: lauxlib.h,v 1.59 2003/03/18 12:25:32 roberto Exp $ 12 | #** Auxiliary functions for building Lua libraries 13 | #** See Copyright Notice in lua.h 14 | # 15 | # 16 | #** Translated to pascal by Lavergne Thomas 17 | #** Notes : 18 | #** - Pointers type was prefixed with 'P' 19 | #** Bug reports : 20 | #** - thomas.lavergne@laposte.net 21 | #** In french or in english 22 | # 23 | 24 | import 25 | lua 26 | 27 | proc pushstring*(L: PState, s: string) 28 | # compatibilty macros 29 | proc getn*(L: PState, n: cint): cint 30 | # calls lua_objlen 31 | proc setn*(L: PState, t, n: cint) 32 | # does nothing! 33 | type 34 | Treg*{.final.} = object 35 | name*: cstring 36 | func*: CFunction 37 | 38 | Preg* = ptr Treg 39 | 40 | 41 | {.push callConv: cdecl, dynlib: lua.LIB_NAME.} 42 | {.push importc: "luaL_$1".} 43 | 44 | proc openlib*(L: PState, libname: cstring, lr: Preg, nup: cint) 45 | proc register*(L: PState, libname: cstring, lr: Preg) 46 | 47 | proc getmetafield*(L: PState, obj: cint, e: cstring): cint 48 | proc callmeta*(L: PState, obj: cint, e: cstring): cint 49 | proc typerror*(L: PState, narg: cint, tname: cstring): cint 50 | proc argerror*(L: PState, numarg: cint, extramsg: cstring): cint 51 | proc checklstring*(L: PState, numArg: cint, len: ptr int): cstring 52 | proc optlstring*(L: PState, numArg: cint, def: cstring, len: ptr cint): cstring 53 | proc checknumber*(L: PState, numArg: cint): Number 54 | proc optnumber*(L: PState, nArg: cint, def: Number): Number 55 | proc checkinteger*(L: PState, numArg: cint): Integer 56 | proc optinteger*(L: PState, nArg: cint, def: Integer): Integer 57 | proc checkstack*(L: PState, sz: cint, msg: cstring) 58 | proc checktype*(L: PState, narg, t: cint) 59 | 60 | proc checkany*(L: PState, narg: cint) 61 | proc newmetatable*(L: PState, tname: cstring): cint 62 | 63 | proc checkudata*(L: PState, ud: cint, tname: cstring): pointer 64 | proc where*(L: PState, lvl: cint) 65 | proc error*(L: PState, fmt: cstring): cint{.varargs.} 66 | proc checkoption*(L: PState, narg: cint, def: cstring, lst: cstringArray): cint 67 | 68 | proc unref*(L: PState, t, theref: cint) 69 | proc loadfile*(L: PState, filename: cstring): cint 70 | proc loadbuffer*(L: PState, buff: cstring, size: cint, name: cstring): cint 71 | proc loadstring*(L: PState, s: cstring): cint 72 | proc newstate*(): PState 73 | 74 | {.pop.} 75 | proc reference*(L: PState, t: cint): cint{.importc: "luaL_ref".} 76 | 77 | {.pop.} 78 | 79 | proc open*(): PState 80 | # compatibility; moved from unit lua to lauxlib because it needs luaL_newstate 81 | # 82 | #** =============================================================== 83 | #** some useful macros 84 | #** =============================================================== 85 | # 86 | proc argcheck*(L: PState, cond: bool, numarg: cint, extramsg: cstring) 87 | proc checkstring*(L: PState, n: cint): cstring 88 | proc optstring*(L: PState, n: cint, d: cstring): cstring 89 | proc checkint*(L: PState, n: cint): cint 90 | proc checklong*(L: PState, n: cint): clong 91 | proc optint*(L: PState, n: cint, d: float64): cint 92 | proc optlong*(L: PState, n: cint, d: float64): clong 93 | proc dofile*(L: PState, filename: cstring): cint 94 | proc dostring*(L: PState, str: cstring): cint 95 | proc getmetatable*(L: PState, tname: cstring) 96 | # not translated: 97 | # #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 98 | # 99 | #** ======================================================= 100 | #** Generic Buffer manipulation 101 | #** ======================================================= 102 | # 103 | const # note: this is just arbitrary, as it related to the BUFSIZ defined in stdio.h ... 104 | BUFFERSIZE* = 4096 105 | 106 | type 107 | Buffer*{.final.} = object 108 | p*: cstring # current position in buffer 109 | lvl*: cint # number of strings in the stack (level) 110 | L*: PState 111 | buffer*: array[0..BUFFERSIZE - 1, char] # warning: see note above about LUAL_BUFFERSIZE 112 | 113 | PBuffer* = ptr Buffer 114 | 115 | proc addchar*(B: PBuffer, c: char) 116 | # warning: see note above about LUAL_BUFFERSIZE 117 | # compatibility only (alias for luaL_addchar) 118 | proc putchar*(B: PBuffer, c: char) 119 | # warning: see note above about LUAL_BUFFERSIZE 120 | proc addsize*(B: PBuffer, n: cint) 121 | 122 | {.push callConv: cdecl, dynlib: lua.LIB_NAME, importc: "luaL_$1".} 123 | proc buffinit*(L: PState, B: PBuffer) 124 | proc prepbuffer*(B: PBuffer): cstring 125 | proc addlstring*(B: PBuffer, s: cstring, L: cint) 126 | proc addstring*(B: PBuffer, s: cstring) 127 | proc addvalue*(B: PBuffer) 128 | proc pushresult*(B: PBuffer) 129 | proc gsub*(L: PState, s, p, r: cstring): cstring 130 | proc findtable*(L: PState, idx: cint, fname: cstring, szhint: cint): cstring 131 | # compatibility with ref system 132 | # pre-defined references 133 | {.pop.} 134 | 135 | const 136 | NOREF* = - 2 137 | REFNIL* = - 1 138 | 139 | proc unref*(L: PState, theref: cint) 140 | proc getref*(L: PState, theref: cint) 141 | # 142 | #** Compatibility macros and functions 143 | # 144 | # implementation 145 | 146 | proc pushstring(L: PState, s: string) = 147 | pushlstring(L, cstring(s), s.len.cint) 148 | 149 | proc getn(L: PState, n: cint): cint = 150 | result = objlen(L, n) 151 | 152 | proc setn(L: PState, t, n: cint) = 153 | # does nothing as this operation is deprecated 154 | raise newException(Exception, "This operation is deprecated. Now shoo!") 155 | 156 | proc open(): PState = 157 | result = newstate() 158 | 159 | proc dofile(L: PState, filename: cstring): cint = 160 | result = loadfile(L, filename) 161 | if result == 0: result = pcall(L, 0, MULTRET, 0) 162 | 163 | proc dostring(L: PState, str: cstring): cint = 164 | result = loadstring(L, str) 165 | if result == 0: result = pcall(L, 0, MULTRET, 0) 166 | 167 | proc getmetatable(L: PState, tname: cstring) = 168 | getfield(L, REGISTRYINDEX, tname) 169 | 170 | proc argcheck(L: PState, cond: bool, numarg: cint, extramsg: cstring) = 171 | if not cond: 172 | discard argerror(L, numarg, extramsg) 173 | 174 | proc checkstring(L: PState, n: cint): cstring = 175 | result = checklstring(L, n, nil) 176 | 177 | proc optstring(L: PState, n: cint, d: cstring): cstring = 178 | result = optlstring(L, n, d, nil) 179 | 180 | proc checkint(L: PState, n: cint): cint = 181 | result = cint(checknumber(L, n)) 182 | 183 | proc checklong(L: PState, n: cint): clong = 184 | result = int32(toInt(checknumber(L, n))) 185 | 186 | proc optint(L: PState, n: cint, d: float64): cint = 187 | result = optnumber(L, n, d).cint 188 | 189 | proc optlong(L: PState, n: cint, d: float64): clong = 190 | result = int32(toInt(optnumber(L, n, d))) 191 | 192 | proc addchar(B: PBuffer, c: char) = 193 | if cast[int](addr((B.p))) < (cast[int](addr((B.buffer[0]))) + BUFFERSIZE): 194 | discard prepbuffer(B) 195 | B.p[1] = c 196 | B.p = cast[cstring](cast[int](B.p) + 1) 197 | 198 | proc putchar(B: PBuffer, c: char) = 199 | addchar(B, c) 200 | 201 | proc addsize(B: PBuffer, n: cint) = 202 | B.p = cast[cstring](cast[int](B.p) + n) 203 | 204 | proc unref(L: PState, theref: cint) = 205 | unref(L, REGISTRYINDEX, theref) 206 | 207 | proc getref(L: PState, theref: cint) = 208 | rawgeti(L, REGISTRYINDEX, theref) 209 | -------------------------------------------------------------------------------- /nimborg/lua/low_level/lua.nim: -------------------------------------------------------------------------------- 1 | #***************************************************************************** 2 | # * * 3 | # * File: lua.pas * 4 | # * Authors: TeCGraf (C headers + actual Lua libraries) * 5 | # * Lavergne Thomas (original translation to Pascal) * 6 | # * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) * 7 | # * Description: Basic Lua library * 8 | # * * 9 | # ***************************************************************************** 10 | # 11 | #** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $ 12 | #** Lua - An Extensible Extension Language 13 | #** TeCGraf: Computer Graphics Technology Group, PUC-Rio, Brazil 14 | #** http://www.lua.org mailto:info@lua.org 15 | #** See Copyright Notice at the end of this file 16 | # 17 | # 18 | #** Updated to Lua 5.1.1 by Bram Kuijvenhoven (bram at kuijvenhoven dot net), 19 | #** Hexis BV (http://www.hexis.nl), the Netherlands 20 | #** Notes: 21 | #** - Only tested with FPC (FreePascal Compiler) 22 | #** - Using LuaBinaries styled DLL/SO names, which include version names 23 | #** - LUA_YIELD was suffixed by '_' for avoiding name collision 24 | # 25 | # 26 | #** Translated to pascal by Lavergne Thomas 27 | #** Notes : 28 | #** - Pointers type was prefixed with 'P' 29 | #** - lua_upvalueindex constant was transformed to function 30 | #** - Some compatibility function was isolated because with it you must have 31 | #** lualib. 32 | #** - LUA_VERSION was suffixed by '_' for avoiding name collision. 33 | #** Bug reports : 34 | #** - thomas.lavergne@laposte.net 35 | #** In french or in english 36 | # 37 | 38 | when defined(useLuajit): 39 | when defined(MACOSX): 40 | const 41 | NAME* = "libluajit.dylib" 42 | LIB_NAME* = "libluajit.dylib" 43 | elif defined(UNIX): 44 | const 45 | NAME* = "libluajit.so(|.0)" 46 | LIB_NAME* = "libluajit.so(|.0)" 47 | else: 48 | const 49 | NAME* = "luajit.dll" 50 | LIB_NAME* = "luajit.dll" 51 | else: 52 | when defined(MACOSX): 53 | const 54 | NAME* = "liblua(|5.1|5.0).dylib" 55 | LIB_NAME* = "liblua(|5.1|5.0).dylib" 56 | elif defined(UNIX): 57 | const 58 | NAME* = "liblua(|5.1|5.0).so(|.0)" 59 | LIB_NAME* = "liblua(|5.1|5.0).so(|.0)" 60 | else: 61 | const 62 | NAME* = "lua(|5.1|5.0).dll" 63 | LIB_NAME* = "lua(|5.1|5.0).dll" 64 | 65 | const 66 | VERSION* = "Lua 5.1" 67 | RELEASE* = "Lua 5.1.1" 68 | VERSION_NUM* = 501 69 | COPYRIGHT* = "Copyright (C) 1994-2006 Lua.org, PUC-Rio" 70 | AUTHORS* = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 71 | # option for multiple returns in `lua_pcall' and `lua_call' 72 | MULTRET* = - 1 # 73 | #** pseudo-indices 74 | # 75 | REGISTRYINDEX* = - 10000 76 | ENVIRONINDEX* = - 10001 77 | GLOBALSINDEX* = - 10002 78 | 79 | proc upvalueindex*(I: cint): cint 80 | const # thread status; 0 is OK 81 | OK* = 0 82 | constYIELD* = 1 83 | ERRRUN* = 2 84 | ERRSYNTAX* = 3 85 | ERRMEM* = 4 86 | ERRERR* = 5 87 | 88 | type 89 | PState* = pointer 90 | CFunction* = proc (L: PState): cint{.cdecl.} 91 | 92 | # 93 | #** functions that read/write blocks when loading/dumping Lua chunks 94 | # 95 | 96 | type 97 | Reader* = proc (L: PState, ud: pointer, sz: ptr cint): cstring{.cdecl.} 98 | Writer* = proc (L: PState, p: pointer, sz: cint, ud: pointer): cint{.cdecl.} 99 | Alloc* = proc (ud, theptr: pointer, osize, nsize: cint){.cdecl.} 100 | 101 | const 102 | TNONE* = - 1 103 | TNIL* = 0 104 | TBOOLEAN* = 1 105 | TLIGHTUSERDATA* = 2 106 | TNUMBER* = 3 107 | TSTRING* = 4 108 | TTABLE* = 5 109 | TFUNCTION* = 6 110 | TUSERDATA* = 7 111 | TTHREAD* = 8 # minimum Lua stack available to a C function 112 | MINSTACK* = 20 113 | 114 | type # Type of Numbers in Lua 115 | Number* = float 116 | Integer* = cint 117 | 118 | {.pragma: ilua, importc: "lua_$1".} 119 | 120 | {.push callConv: cdecl, dynlib: LIB_NAME.} 121 | #{.push importc: "lua_$1".} 122 | 123 | proc newstate*(f: Alloc, ud: pointer): PState {.ilua.} 124 | 125 | proc close*(L: PState){.ilua.} 126 | proc newthread*(L: PState): PState{.ilua.} 127 | proc atpanic*(L: PState, panicf: CFunction): CFunction{.ilua.} 128 | 129 | proc gettop*(L: PState): cint{.ilua.} 130 | proc settop*(L: PState, idx: cint){.ilua.} 131 | proc pushvalue*(L: PState, Idx: cint){.ilua.} 132 | proc remove*(L: PState, idx: cint){.ilua.} 133 | proc insert*(L: PState, idx: cint){.ilua.} 134 | proc replace*(L: PState, idx: cint){.ilua.} 135 | proc checkstack*(L: PState, sz: cint): cint{.ilua.} 136 | proc xmove*(`from`, `to`: PState, n: cint){.ilua.} 137 | proc isnumber*(L: PState, idx: cint): cint{.ilua.} 138 | proc isstring*(L: PState, idx: cint): cint{.ilua.} 139 | proc iscfunction*(L: PState, idx: cint): cint{.ilua.} 140 | proc isuserdata*(L: PState, idx: cint): cint{.ilua.} 141 | proc luatype*(L: PState, idx: cint): cint{.importc: "lua_type".} 142 | proc typename*(L: PState, tp: cint): cstring{.ilua.} 143 | proc equal*(L: PState, idx1, idx2: cint): cint{.ilua.} 144 | proc rawequal*(L: PState, idx1, idx2: cint): cint{.ilua.} 145 | proc lessthan*(L: PState, idx1, idx2: cint): cint{.ilua.} 146 | proc tonumber*(L: PState, idx: cint): Number{.ilua.} 147 | proc tointeger*(L: PState, idx: cint): Integer{.ilua.} 148 | proc toboolean*(L: PState, idx: cint): cint{.ilua.} 149 | proc tolstring*(L: PState, idx: cint, length: ptr cint): cstring{.ilua.} 150 | proc objlen*(L: PState, idx: cint): cint{.ilua.} 151 | proc tocfunction*(L: PState, idx: cint): CFunction{.ilua.} 152 | proc touserdata*(L: PState, idx: cint): pointer{.ilua.} 153 | proc tothread*(L: PState, idx: cint): PState{.ilua.} 154 | proc topointer*(L: PState, idx: cint): pointer{.ilua.} 155 | proc pushnil*(L: PState){.ilua.} 156 | proc pushnumber*(L: PState, n: Number){.ilua.} 157 | proc pushinteger*(L: PState, n: Integer){.ilua.} 158 | proc pushlstring*(L: PState, s: cstring, len: cint){.ilua.} 159 | proc pushstring*(L: PState, s: cstring){.ilua.} 160 | proc pushvfstring*(L: PState, fmt: cstring, argp: pointer): cstring{.ilua.} 161 | proc pushfstring*(L: PState, fmt: cstring): cstring{.varargs,ilua.} 162 | proc pushcclosure*(L: PState, fn: CFunction, n: cint){.ilua.} 163 | proc pushboolean*(L: PState, b: cint){.ilua.} 164 | proc pushlightuserdata*(L: PState, p: pointer){.ilua.} 165 | proc pushthread*(L: PState){.ilua.} 166 | proc gettable*(L: PState, idx: cint){.ilua.} 167 | proc getfield*(L: PState, idx: cint, k: cstring){.ilua.} 168 | proc rawget*(L: PState, idx: cint){.ilua.} 169 | proc rawgeti*(L: PState, idx, n: cint){.ilua.} 170 | proc createtable*(L: PState, narr, nrec: cint){.ilua.} 171 | proc newuserdata*(L: PState, sz: cint): pointer{.ilua.} 172 | proc getmetatable*(L: PState, objindex: cint): cint{.ilua.} 173 | proc getfenv*(L: PState, idx: cint){.ilua.} 174 | proc settable*(L: PState, idx: cint){.ilua.} 175 | proc setfield*(L: PState, idx: cint, k: cstring){.ilua.} 176 | proc rawset*(L: PState, idx: cint){.ilua.} 177 | proc rawseti*(L: PState, idx, n: cint){.ilua.} 178 | proc setmetatable*(L: PState, objindex: cint): cint{.ilua.} 179 | proc setfenv*(L: PState, idx: cint): cint{.ilua.} 180 | proc call*(L: PState, nargs, nresults: cint){.ilua.} 181 | proc pcall*(L: PState, nargs, nresults, errf: cint): cint{.ilua.} 182 | proc cpcall*(L: PState, func: CFunction, ud: pointer): cint{.ilua.} 183 | proc load*(L: PState, reader: Reader, dt: pointer, chunkname: cstring): cint{.ilua.} 184 | proc dump*(L: PState, writer: Writer, data: pointer): cint{.ilua.} 185 | proc luayield*(L: PState, nresults: cint): cint{.importc: "lua_yield".} 186 | proc resume*(L: PState, narg: cint): cint{.ilua.} 187 | proc status*(L: PState): cint{.ilua.} 188 | proc gc*(L: PState, what, data: cint): cint{.ilua.} 189 | proc error*(L: PState): cint{.ilua.} 190 | proc next*(L: PState, idx: cint): cint{.ilua.} 191 | proc concat*(L: PState, n: cint){.ilua.} 192 | proc getallocf*(L: PState, ud: ptr pointer): Alloc{.ilua.} 193 | proc setallocf*(L: PState, f: Alloc, ud: pointer){.ilua.} 194 | {.pop.} 195 | 196 | # 197 | #** Garbage-collection functions and options 198 | # 199 | 200 | const 201 | GCSTOP* = 0 202 | GCRESTART* = 1 203 | GCCOLLECT* = 2 204 | GCCOUNT* = 3 205 | GCCOUNTB* = 4 206 | GCSTEP* = 5 207 | GCSETPAUSE* = 6 208 | GCSETSTEPMUL* = 7 209 | 210 | # 211 | #** =============================================================== 212 | #** some useful macros 213 | #** =============================================================== 214 | # 215 | 216 | proc pop*(L: PState, n: cint) 217 | proc newtable*(L: PState) 218 | proc register*(L: PState, n: cstring, f: CFunction) 219 | proc pushcfunction*(L: PState, f: CFunction) 220 | proc strlen*(L: PState, i: cint): cint 221 | proc isfunction*(L: PState, n: cint): bool 222 | proc istable*(L: PState, n: cint): bool 223 | proc islightuserdata*(L: PState, n: cint): bool 224 | proc isnil*(L: PState, n: cint): bool 225 | proc isboolean*(L: PState, n: cint): bool 226 | proc isthread*(L: PState, n: cint): bool 227 | proc isnone*(L: PState, n: cint): bool 228 | proc isnoneornil*(L: PState, n: cint): bool 229 | proc pushliteral*(L: PState, s: cstring) 230 | proc setglobal*(L: PState, s: cstring) 231 | proc getglobal*(L: PState, s: cstring) 232 | proc tostring*(L: PState, i: cint): cstring 233 | # 234 | #** compatibility macros and functions 235 | # 236 | 237 | proc getregistry*(L: PState) 238 | proc getgccount*(L: PState): cint 239 | type 240 | Chunkreader* = Reader 241 | Chunkwriter* = Writer 242 | 243 | # 244 | #** ====================================================================== 245 | #** Debug API 246 | #** ====================================================================== 247 | # 248 | 249 | const 250 | HOOKCALL* = 0 251 | HOOKRET* = 1 252 | HOOKLINE* = 2 253 | HOOKCOUNT* = 3 254 | HOOKTAILRET* = 4 255 | 256 | const 257 | MASKCALL* = 1 shl ord(HOOKCALL) 258 | MASKRET* = 1 shl ord(HOOKRET) 259 | MASKLINE* = 1 shl ord(HOOKLINE) 260 | MASKCOUNT* = 1 shl ord(HOOKCOUNT) 261 | 262 | const 263 | IDSIZE* = 60 264 | 265 | type 266 | TDebug*{.final.} = object # activation record 267 | event*: cint 268 | name*: cstring # (n) 269 | namewhat*: cstring # (n) `global', `local', `field', `method' 270 | what*: cstring # (S) `Lua', `C', `main', `tail' 271 | source*: cstring # (S) 272 | currentline*: cint # (l) 273 | nups*: cint # (u) number of upvalues 274 | linedefined*: cint # (S) 275 | lastlinedefined*: cint # (S) 276 | short_src*: array[0.. = $*" % [$i, $sizeof(T), $lim]) 229 | 230 | proc `[]=`*[T](arr: PTypedPyBuffer1D[T], i: int, v: T) {.inline.} = 231 | let p : ptr T = addr(arr[i]) 232 | p[] = v 233 | 234 | proc finalizeTypedPyBuffer1D[T](tb: ref TypedPyBuffer1D[T]) = 235 | if tb.pyBuf.obj!=nil: PyBuffer_Release(addr(tb.pyBuf)) 236 | 237 | let default_buffer_flags: cint = PyBUF_WRITABLE or PyBUF_FORMAT 238 | 239 | template defPyBufferConverter(convName: expr, T: typeDesc, fmt: string): stmt {.immediate.} = 240 | proc convName*(obj: PPyRef, flags = default_buffer_flags): PTypedPyBuffer1D[T] = 241 | new(result, finalizeTypedPyBuffer1D[T]) 242 | result.pyBuf.obj = nil # flag to skip PyBuffer_Release, unless GetBuffer succeeds 243 | let err = PyObject_GetBuffer(obj, addr(result.pyBuf), flags) 244 | if err == -1: 245 | raise newException(EPyNotSupported, 246 | "buffer interface not supported with flags " & $flags) 247 | if ((flags and PyBUF_FORMAT)!=0) and (fmt != $result.pyBuf.format): 248 | let msg = "expected buffer format $1 but got $2" % [fmt, $result.pyBuf.format] 249 | raise newException(EPyTypeError, msg) 250 | result.nElements = result.pyBuf.length div result.pyBuf.itemsize 251 | 252 | defPyBufferConverter(float64Buffer, float64, "d") 253 | defPyBufferConverter(float32Buffer, float32, "f") 254 | defPyBufferConverter(uint8Buffer, uint8, "B") 255 | 256 | #------------------------------------------------------------------------------- 257 | # importation and evaluation 258 | 259 | proc eval*(c: PContext, src: cstring): PPyRef = 260 | wrapNew(PyRun_String(src, eval_input, c.globals.p, c.locals.p)) 261 | 262 | proc builtins*(): PPyRef = wrapNew(PyEval_GetBuiltins()) 263 | 264 | proc pyImport*(name: cstring): PPyRef = 265 | wrapNew(PyImport_ImportModule(name)) 266 | 267 | proc initContext*(): PContext = 268 | new result 269 | result.locals = pyDict() 270 | result.globals = pyDict() 271 | let b = builtins() 272 | result.globals["__builtins__"] = b 273 | result.locals["__builtins__"] = b 274 | 275 | const 276 | GC_the_python_interpreter = false 277 | 278 | when GC_the_python_interpreter: 279 | type 280 | Interpreter = object {.bycopy.} 281 | PInterpreter* = ref Interpreter 282 | 283 | proc finalizeInterpreter(interpreter: PInterpreter) = 284 | finalizePython() 285 | 286 | # init_python is not useful yet. Before I let users call this, 287 | # I must add and maintain a reference to the interpreter 288 | # in each PyRef, as is done with lua states. 289 | # The reason is that the python references are unsafe if 290 | # the interpreter is finalized, so they semantically depend 291 | # upon the interpreter, even though the interpreter is not 292 | # passed to the python/C API routines. 293 | proc initPy(): PInterpreter = 294 | new(result, finalizeInterpreter) 295 | initPython() 296 | else: 297 | # temporary kludge, until I adopt the lua convention 298 | initPython() 299 | -------------------------------------------------------------------------------- /nimborg/py/low_level.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Light-weight binding for the Python interpreter 3 | # (c) 2010 Andreas Rumpf 4 | # Based on 'PythonEngine' module by Dr. Dietmar Budelsky 5 | # 6 | # 7 | #************************************************************************ 8 | # 9 | # Module: Unit 'PythonEngine' Copyright (c) 1997 10 | # 11 | # Version: 3.0 Dr. Dietmar Budelsky 12 | # Sub-Version: 0.25 dbudelsky@web.de 13 | # Germany 14 | # 15 | # Morgan Martinet 16 | # 4721 rue Brebeuf 17 | # H2J 3L2 MONTREAL (QC) 18 | # CANADA 19 | # e-mail: mmm@free.fr 20 | # 21 | # look our page at: http://www.multimania.com/marat 22 | #************************************************************************ 23 | # Functionality: Delphi Components that provide an interface to the 24 | # Python language (see python.txt for more infos on 25 | # Python itself). 26 | # 27 | #************************************************************************ 28 | # Contributors: 29 | # Grzegorz Makarewicz (mak@mikroplan.com.pl) 30 | # Andrew Robinson (andy@hps1.demon.co.uk) 31 | # Mark Watts(mark_watts@hotmail.com) 32 | # Olivier Deckmyn (olivier.deckmyn@mail.dotcom.fr) 33 | # Sigve Tjora (public@tjora.no) 34 | # Mark Derricutt (mark@talios.com) 35 | # Igor E. Poteryaev (jah@mail.ru) 36 | # Yuri Filimonov (fil65@mail.ru) 37 | # Stefan Hoffmeister (Stefan.Hoffmeister@Econos.de) 38 | #************************************************************************ 39 | # This source code is distributed with no WARRANTY, for no reason or use. 40 | # Everyone is allowed to use and change this code free for his own tasks 41 | # and projects, as long as this header and its copyright text is intact. 42 | # For changed versions of this code, which are public distributed the 43 | # following additional conditions have to be fullfilled: 44 | # 1) The header has to contain a comment on the change and the author of 45 | # it. 46 | # 2) A copy of the changed source has to be sent to the above E-Mail 47 | # address or my then valid address, if this is possible to the 48 | # author. 49 | # The second condition has the target to maintain an up to date central 50 | # version of the component. If this condition is not acceptable for 51 | # confidential or legal reasons, everyone is free to derive a component 52 | # or to generate a diff file to my or other original sources. 53 | # Dr. Dietmar Budelsky, 1997-11-17 54 | #************************************************************************ 55 | # 56 | # 14/2/2014 Micky Latowicki: place initialization and finalization code 57 | # in functions that are not called unconditionally 58 | # 14/2/2014 Micky Latowicki: add definitions of the new buffer interface 59 | 60 | {.deadCodeElim: on.} 61 | 62 | import 63 | dynlib 64 | 65 | 66 | when defined(windows): 67 | # the new buffer protocol only exists since python 2.6 68 | const dllname = "python(27|26).dll" 69 | elif defined(macosx): 70 | const dllname = "libpython(2.7|2.6).dylib" 71 | else: 72 | const dllver = ".1" 73 | const dllname = "libpython(2.7|2.6).so" & dllver 74 | 75 | 76 | const 77 | PYT_METHOD_BUFFER_INCREASE* = 10 78 | PYT_MEMBER_BUFFER_INCREASE* = 10 79 | PYT_GETSET_BUFFER_INCREASE* = 10 80 | METH_VARARGS* = 0x0001 81 | METH_KEYWORDS* = 0x0002 # Masks for the co_flags field of PyCodeObject 82 | CO_OPTIMIZED* = 0x0001 83 | CO_NEWLOCALS* = 0x0002 84 | CO_VARARGS* = 0x0004 85 | CO_VARKEYWORDS* = 0x0008 86 | 87 | type # Rich comparison opcodes introduced in version 2.1 88 | TRichComparisonOpcode* = enum 89 | Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE 90 | 91 | const 92 | Py_TPFLAGS_HAVE_GETCHARBUFFER* = (1 shl 0) # PySequenceMethods contains sq_contains 93 | Py_TPFLAGS_HAVE_SEQUENCE_IN* = (1 shl 1) # Objects which participate in garbage collection (see objimp.h) 94 | Py_TPFLAGS_GC* = (1 shl 2) # PySequenceMethods and PyNumberMethods contain in-place operators 95 | Py_TPFLAGS_HAVE_INPLACEOPS* = (1 shl 3) # PyNumberMethods do their own coercion */ 96 | Py_TPFLAGS_CHECKTYPES* = (1 shl 4) 97 | Py_TPFLAGS_HAVE_RICHCOMPARE* = (1 shl 5) # Objects which are weakly referencable if their tp_weaklistoffset is >0 98 | # XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE? 99 | # These both indicate a feature that appeared in the same alpha release. 100 | Py_TPFLAGS_HAVE_WEAKREFS* = (1 shl 6) # tp_iter is defined 101 | Py_TPFLAGS_HAVE_ITER* = (1 shl 7) # New members introduced by Python 2.2 exist 102 | Py_TPFLAGS_HAVE_CLASS* = (1 shl 8) # Set if the type object is dynamically allocated 103 | Py_TPFLAGS_HEAPTYPE* = (1 shl 9) # Set if the type allows subclassing 104 | Py_TPFLAGS_BASETYPE* = (1 shl 10) # Set if the type is 'ready' -- fully initialized 105 | Py_TPFLAGS_READY* = (1 shl 12) # Set while the type is being 'readied', to prevent recursive ready calls 106 | Py_TPFLAGS_READYING* = (1 shl 13) # Objects support garbage collection (see objimp.h) 107 | Py_TPFLAGS_HAVE_GC* = (1 shl 14) 108 | Py_TPFLAGS_HAVE_INDEX* = (1 shl 17) # Objects support nb_index in PyNumberMethods 109 | Py_TPFLAGS_HAVE_NEWBUFFER* = (1 shl 21) 110 | 111 | Py_TPFLAGS_HAVE_STACKLESS_EXTENSION = 0 112 | Py_TPFLAGS_DEFAULT* = Py_TPFLAGS_HAVE_GETCHARBUFFER or 113 | Py_TPFLAGS_HAVE_SEQUENCE_IN or Py_TPFLAGS_HAVE_INPLACEOPS or 114 | Py_TPFLAGS_HAVE_RICHCOMPARE or Py_TPFLAGS_HAVE_WEAKREFS or 115 | Py_TPFLAGS_HAVE_ITER or Py_TPFLAGS_HAVE_CLASS or 116 | Py_TPFLAGS_HAVE_STACKLESS_EXTENSION or Py_TPFLAGS_HAVE_INDEX 117 | 118 | type 119 | TPFlag* = enum 120 | tpfHaveGetCharBuffer, tpfHaveSequenceIn, tpfGC, tpfHaveInplaceOps, 121 | tpfCheckTypes, tpfHaveRichCompare, tpfHaveWeakRefs, tpfHaveIter, 122 | tpfHaveClass, tpfHeapType, tpfBaseType, tpfReady, tpfReadying, tpfHaveGC 123 | TPFlags* = set[TPFlag] 124 | 125 | const 126 | TPFLAGS_DEFAULT* = {tpfHaveGetCharBuffer, tpfHaveSequenceIn, 127 | tpfHaveInplaceOps, tpfHaveRichCompare, tpfHaveWeakRefs, tpfHaveIter, 128 | tpfHaveClass} 129 | 130 | const # Python opcodes 131 | single_input* = 256 132 | file_input* = 257 133 | eval_input* = 258 134 | funcdef* = 259 135 | parameters* = 260 136 | varargslist* = 261 137 | fpdef* = 262 138 | fplist* = 263 139 | stmt* = 264 140 | simple_stmt* = 265 141 | small_stmt* = 266 142 | expr_stmt* = 267 143 | augassign* = 268 144 | print_stmt* = 269 145 | del_stmt* = 270 146 | pass_stmt* = 271 147 | flow_stmt* = 272 148 | break_stmt* = 273 149 | continue_stmt* = 274 150 | return_stmt* = 275 151 | raise_stmt* = 276 152 | import_stmt* = 277 153 | import_as_name* = 278 154 | dotted_as_name* = 279 155 | dotted_name* = 280 156 | global_stmt* = 281 157 | exec_stmt* = 282 158 | assert_stmt* = 283 159 | compound_stmt* = 284 160 | if_stmt* = 285 161 | while_stmt* = 286 162 | for_stmt* = 287 163 | try_stmt* = 288 164 | except_clause* = 289 165 | suite* = 290 166 | test* = 291 167 | and_test* = 291 168 | not_test* = 293 169 | comparison* = 294 170 | comp_op* = 295 171 | expr* = 296 172 | xor_expr* = 297 173 | and_expr* = 298 174 | shift_expr* = 299 175 | arith_expr* = 300 176 | term* = 301 177 | factor* = 302 178 | power* = 303 179 | atom* = 304 180 | listmaker* = 305 181 | lambdef* = 306 182 | trailer* = 307 183 | subscriptlist* = 308 184 | subscript* = 309 185 | sliceop* = 310 186 | exprlist* = 311 187 | testlist* = 312 188 | dictmaker* = 313 189 | classdef* = 314 190 | arglist* = 315 191 | argument* = 316 192 | list_iter* = 317 193 | list_for* = 318 194 | list_if* = 319 195 | 196 | const 197 | T_SHORT* = 0 198 | T_INT* = 1 199 | T_LONG* = 2 200 | T_FLOAT* = 3 201 | T_DOUBLE* = 4 202 | T_STRING* = 5 203 | T_OBJECT* = 6 204 | T_CHAR* = 7 # 1-character string 205 | T_BYTE* = 8 # 8-bit signed int 206 | T_UBYTE* = 9 207 | T_USHORT* = 10 208 | T_UINT* = 11 209 | T_ULONG* = 12 210 | T_STRING_INPLACE* = 13 211 | T_OBJECT_EX* = 16 212 | READONLY* = 1 213 | RO* = READONLY # Shorthand 214 | READ_RESTRICTED* = 2 215 | WRITE_RESTRICTED* = 4 216 | RESTRICTED* = (READ_RESTRICTED or WRITE_RESTRICTED) 217 | 218 | type 219 | TPyMemberType* = enum 220 | mtShort, mtInt, mtLong, mtFloat, mtDouble, mtString, mtObject, mtChar, 221 | mtByte, mtUByte, mtUShort, mtUInt, mtULong, mtStringInplace, mtObjectEx 222 | TPyMemberFlag* = enum 223 | mfDefault, mfReadOnly, mfReadRestricted, mfWriteRestricted, mfRestricted 224 | 225 | type 226 | PInt* = ptr int 227 | 228 | # PLong* = ptr int32 229 | # PFloat* = ptr float32 230 | # PShort* = ptr int8 231 | 232 | type 233 | PP_frozen* = ptr Pfrozen 234 | P_frozen* = ptr Tfrozen 235 | PPyObject* = ptr TPyObject 236 | PPPyObject* = ptr PPyObject 237 | PPPPyObject* = ptr PPPyObject 238 | PPyIntObject* = ptr TPyIntObject 239 | PPyTypeObject* = ptr TPyTypeObject 240 | PPySliceObject* = ptr TPySliceObject 241 | TPyCFunction* = proc (self, args: PPyObject): PPyObject{.cdecl.} 242 | Py_ssize_t = cint # PEP353: Py_ssize_t is signed and has the same size as size_t 243 | PPy_buffer = ptr TPy_buffer 244 | Tunaryfunc* = proc (ob1: PPyObject): PPyObject{.cdecl.} 245 | Tbinaryfunc* = proc (ob1, ob2: PPyObject): PPyObject{.cdecl.} 246 | Tternaryfunc* = proc (ob1, ob2, ob3: PPyObject): PPyObject{.cdecl.} 247 | Tinquiry* = proc (ob1: PPyObject): int{.cdecl.} 248 | Tcoercion* = proc (ob1, ob2: PPPyObject): int{.cdecl.} 249 | Tintargfunc* = proc (ob1: PPyObject, i: int): PPyObject{.cdecl.} 250 | Tintintargfunc* = proc (ob1: PPyObject, i1, i2: int): PPyObject{.cdecl.} 251 | Tintobjargproc* = proc (ob1: PPyObject, i: int, ob2: PPyObject): int{.cdecl.} 252 | Tintintobjargproc* = proc (ob1: PPyObject, i1, i2: int, ob2: PPyObject): int{. 253 | cdecl.} 254 | Tobjobjargproc* = proc (ob1, ob2, ob3: PPyObject): int{.cdecl.} 255 | Tpydestructor* = proc (ob: PPyObject){.cdecl.} 256 | Tprintfunc* = proc (ob: PPyObject, f: File, i: int): int{.cdecl.} 257 | Tgetattrfunc* = proc (ob1: PPyObject, name: cstring): PPyObject{.cdecl.} 258 | Tsetattrfunc* = proc (ob1: PPyObject, name: cstring, ob2: PPyObject): int{. 259 | cdecl.} 260 | Tcmpfunc* = proc (ob1, ob2: PPyObject): int{.cdecl.} 261 | Treprfunc* = proc (ob: PPyObject): PPyObject{.cdecl.} 262 | Thashfunc* = proc (ob: PPyObject): int32{.cdecl.} 263 | Tgetattrofunc* = proc (ob1, ob2: PPyObject): PPyObject{.cdecl.} 264 | Tsetattrofunc* = proc (ob1, ob2, ob3: PPyObject): int{.cdecl.} 265 | Tgetreadbufferproc* = proc (ob1: PPyObject, i: int, p: pointer): int{.cdecl.} 266 | Tgetwritebufferproc* = proc (ob1: PPyObject, i: int, p: pointer): int{.cdecl.} 267 | Tgetsegcountproc* = proc (ob1: PPyObject, i: int): int{.cdecl.} 268 | Tgetcharbufferproc* = proc (ob1: PPyObject, i: int, pstr: cstring): int{.cdecl.} 269 | Tgetbufferproc* = proc (a:PPyObject, buf:PPy_buffer, c:int): int {.cdecl.} 270 | Treleasebufferproc* = proc(a:PPyObject, buf:PPy_buffer): void {.cdecl.} 271 | 272 | 273 | Tobjobjproc* = proc (ob1, ob2: PPyObject): int{.cdecl.} 274 | Tvisitproc* = proc (ob1: PPyObject, p: pointer): int{.cdecl.} 275 | Ttraverseproc* = proc (ob1: PPyObject, prc: TVisitproc, p: pointer): int{. 276 | cdecl.} 277 | Trichcmpfunc* = proc (ob1, ob2: PPyObject, i: int): PPyObject{.cdecl.} 278 | Tgetiterfunc* = proc (ob1: PPyObject): PPyObject{.cdecl.} 279 | Titernextfunc* = proc (ob1: PPyObject): PPyObject{.cdecl.} 280 | Tdescrgetfunc* = proc (ob1, ob2, ob3: PPyObject): PPyObject{.cdecl.} 281 | Tdescrsetfunc* = proc (ob1, ob2, ob3: PPyObject): int{.cdecl.} 282 | Tinitproc* = proc (self, args, kwds: PPyObject): int{.cdecl.} 283 | Tnewfunc* = proc (subtype: PPyTypeObject, args, kwds: PPyObject): PPyObject{. 284 | cdecl.} 285 | Tallocfunc* = proc (self: PPyTypeObject, nitems: int): PPyObject{.cdecl.} 286 | TPyNumberMethods*{.final.} = object 287 | nb_add*: Tbinaryfunc 288 | nb_substract*: Tbinaryfunc 289 | nb_multiply*: Tbinaryfunc 290 | nb_divide*: Tbinaryfunc 291 | nb_remainder*: Tbinaryfunc 292 | nb_divmod*: Tbinaryfunc 293 | nb_power*: Tternaryfunc 294 | nb_negative*: Tunaryfunc 295 | nb_positive*: Tunaryfunc 296 | nb_absolute*: Tunaryfunc 297 | nb_nonzero*: Tinquiry 298 | nb_invert*: Tunaryfunc 299 | nb_lshift*: Tbinaryfunc 300 | nb_rshift*: Tbinaryfunc 301 | nb_and*: Tbinaryfunc 302 | nb_xor*: Tbinaryfunc 303 | nb_or*: Tbinaryfunc 304 | nb_coerce*: Tcoercion 305 | nb_int*: Tunaryfunc 306 | nb_long*: Tunaryfunc 307 | nb_float*: Tunaryfunc 308 | nb_oct*: Tunaryfunc 309 | nb_hex*: Tunaryfunc #/ jah 29-sep-2000: updated for python 2.0 310 | #/ added from .h 311 | nb_inplace_add*: Tbinaryfunc 312 | nb_inplace_subtract*: Tbinaryfunc 313 | nb_inplace_multiply*: Tbinaryfunc 314 | nb_inplace_divide*: Tbinaryfunc 315 | nb_inplace_remainder*: Tbinaryfunc 316 | nb_inplace_power*: Tternaryfunc 317 | nb_inplace_lshift*: Tbinaryfunc 318 | nb_inplace_rshift*: Tbinaryfunc 319 | nb_inplace_and*: Tbinaryfunc 320 | nb_inplace_xor*: Tbinaryfunc 321 | nb_inplace_or*: Tbinaryfunc # Added in release 2.2 322 | # The following require the Py_TPFLAGS_HAVE_CLASS flag 323 | nb_floor_divide*: Tbinaryfunc 324 | nb_true_divide*: Tbinaryfunc 325 | nb_inplace_floor_divide*: Tbinaryfunc 326 | nb_inplace_true_divide*: Tbinaryfunc 327 | 328 | PPyNumberMethods* = ptr TPyNumberMethods 329 | TPySequenceMethods*{.final.} = object 330 | sq_length*: Tinquiry 331 | sq_concat*: Tbinaryfunc 332 | sq_repeat*: Tintargfunc 333 | sq_item*: Tintargfunc 334 | sq_slice*: Tintintargfunc 335 | sq_ass_item*: Tintobjargproc 336 | sq_ass_slice*: Tintintobjargproc 337 | sq_contains*: Tobjobjproc 338 | sq_inplace_concat*: Tbinaryfunc 339 | sq_inplace_repeat*: Tintargfunc 340 | 341 | PPySequenceMethods* = ptr TPySequenceMethods 342 | TPyMappingMethods*{.final.} = object 343 | mp_length*: Tinquiry 344 | mp_subscript*: Tbinaryfunc 345 | mp_ass_subscript*: Tobjobjargproc 346 | 347 | PPyMappingMethods* = ptr TPyMappingMethods 348 | TPyBufferProcs*{.final.} = object 349 | bf_getreadbuffer*: Tgetreadbufferproc 350 | bf_getwritebuffer*: Tgetwritebufferproc 351 | bf_getsegcount*: Tgetsegcountproc 352 | bf_getcharbuffer*: Tgetcharbufferproc 353 | bf_getbuffer*: Tgetbufferproc 354 | bf_releasebuffer*: Treleasebufferproc 355 | 356 | PPyBufferProcs* = ptr TPyBufferProcs 357 | TPy_complex*{.final.} = object 358 | float*: float64 359 | imag*: float64 360 | 361 | TPyObject*{.pure, inheritable.} = object 362 | ob_refcnt*: int 363 | ob_type*: PPyTypeObject 364 | 365 | TPyIntObject* = object of TPyObject 366 | ob_ival*: int32 367 | 368 | PByte* = ptr int8 369 | Tfrozen*{.final.} = object 370 | name*: cstring 371 | code*: PByte 372 | size*: int 373 | 374 | TPySliceObject* = object of TPyObject 375 | start*, stop*, step*: PPyObject 376 | 377 | PPyMethodDef* = ptr TPyMethodDef 378 | TPyMethodDef*{.final.} = object # structmember.h 379 | ml_name*: cstring 380 | ml_meth*: TPyCFunction 381 | ml_flags*: int 382 | ml_doc*: cstring 383 | 384 | PPyMemberDef* = ptr TPyMemberDef 385 | TPyMemberDef*{.final.} = object # descrobject.h 386 | # Descriptors 387 | name*: cstring 388 | theType*: int 389 | offset*: int 390 | flags*: int 391 | doc*: cstring 392 | 393 | Tgetter* = proc (obj: PPyObject, context: pointer): PPyObject{.cdecl.} 394 | Tsetter* = proc (obj, value: PPyObject, context: pointer): int{.cdecl.} 395 | PPyGetSetDef* = ptr TPyGetSetDef 396 | TPyGetSetDef*{.final.} = object 397 | name*: cstring 398 | get*: Tgetter 399 | setter*: Tsetter 400 | doc*: cstring 401 | closure*: pointer 402 | 403 | Twrapperfunc* = proc (self, args: PPyObject, wrapped: pointer): PPyObject{. 404 | cdecl.} 405 | pwrapperbase* = ptr Twrapperbase 406 | # Various kinds of descriptor objects 407 | ##define PyDescr_COMMON \ 408 | # PyObject_HEAD \ 409 | # PyTypeObject *d_type; \ 410 | # PyObject *d_name 411 | # 412 | Twrapperbase*{.final.} = object 413 | name*: cstring 414 | wrapper*: Twrapperfunc 415 | doc*: cstring 416 | 417 | PPyDescrObject* = ptr TPyDescrObject 418 | TPyDescrObject* = object of TPyObject 419 | d_type*: PPyTypeObject 420 | d_name*: PPyObject 421 | 422 | PPyMethodDescrObject* = ptr TPyMethodDescrObject 423 | TPyMethodDescrObject* = object of TPyDescrObject 424 | d_method*: PPyMethodDef 425 | 426 | PPyMemberDescrObject* = ptr TPyMemberDescrObject 427 | TPyMemberDescrObject* = object of TPyDescrObject 428 | d_member*: PPyMemberDef 429 | 430 | PPyGetSetDescrObject* = ptr TPyGetSetDescrObject 431 | TPyGetSetDescrObject* = object of TPyDescrObject 432 | d_getset*: PPyGetSetDef 433 | 434 | PPyWrapperDescrObject* = ptr TPyWrapperDescrObject 435 | TPyWrapperDescrObject* = object of TPyDescrObject # object.h 436 | d_base*: pwrapperbase 437 | d_wrapped*: pointer # This can be any function pointer 438 | 439 | TPyTypeObject* = object of TPyObject 440 | ob_size*: int # Number of items in variable part 441 | tp_name*: cstring # For printing 442 | tp_basicsize*, tp_itemsize*: int # For allocation 443 | # Methods to implement standard operations 444 | tp_dealloc*: Tpydestructor 445 | tp_print*: Tprintfunc 446 | tp_getattr*: Tgetattrfunc 447 | tp_setattr*: Tsetattrfunc 448 | tp_compare*: Tcmpfunc 449 | tp_repr*: Treprfunc # Method suites for standard classes 450 | tp_as_number*: PPyNumberMethods 451 | tp_as_sequence*: PPySequenceMethods 452 | tp_as_mapping*: PPyMappingMethods # More standard operations (here for binary compatibility) 453 | tp_hash*: Thashfunc 454 | tp_call*: Tternaryfunc 455 | tp_str*: Treprfunc 456 | tp_getattro*: Tgetattrofunc 457 | tp_setattro*: Tsetattrofunc #/ jah 29-sep-2000: updated for python 2.0 458 | # Functions to access object as input/output buffer 459 | tp_as_buffer*: PPyBufferProcs # Flags to define presence of optional/expanded features 460 | tp_flags*: int32 461 | tp_doc*: cstring # Documentation string 462 | # call function for all accessible objects 463 | tp_traverse*: Ttraverseproc # delete references to contained objects 464 | tp_clear*: Tinquiry # rich comparisons 465 | tp_richcompare*: Trichcmpfunc # weak reference enabler 466 | tp_weaklistoffset*: int32 # Iterators 467 | tp_iter*: Tgetiterfunc 468 | tp_iternext*: Titernextfunc # Attribute descriptor and subclassing stuff 469 | tp_methods*: PPyMethodDef 470 | tp_members*: PPyMemberDef 471 | tp_getset*: PPyGetSetDef 472 | tp_base*: PPyTypeObject 473 | tp_dict*: PPyObject 474 | tp_descr_get*: Tdescrgetfunc 475 | tp_descr_set*: Tdescrsetfunc 476 | tp_dictoffset*: int32 477 | tp_init*: Tinitproc 478 | tp_alloc*: Tallocfunc 479 | tp_new*: Tnewfunc 480 | tp_free*: Tpydestructor # Low-level free-memory routine 481 | tp_is_gc*: Tinquiry # For PyObject_IS_GC 482 | tp_bases*: PPyObject 483 | tp_mro*: PPyObject # method resolution order 484 | tp_cache*: PPyObject 485 | tp_subclasses*: PPyObject 486 | tp_weaklist*: PPyObject #More spares 487 | tp_xxx7*: pointer # tp_del, for internal use only 488 | tp_xxx8*: pointer # tp_version_tag, for internal use only 489 | 490 | PPyMethodChain* = ptr TPyMethodChain 491 | TPyMethodChain*{.final.} = object 492 | methods*: PPyMethodDef 493 | link*: PPyMethodChain 494 | 495 | PPyClassObject* = ptr TPyClassObject 496 | TPyClassObject* = object of TPyObject 497 | cl_bases*: PPyObject # A tuple of class objects 498 | cl_dict*: PPyObject # A dictionary 499 | cl_name*: PPyObject # A string 500 | # The following three are functions or NULL 501 | cl_getattr*: PPyObject 502 | cl_setattr*: PPyObject 503 | cl_delattr*: PPyObject 504 | 505 | PPyInstanceObject* = ptr TPyInstanceObject 506 | TPyInstanceObject* = object of TPyObject 507 | in_class*: PPyClassObject # The class object 508 | in_dict*: PPyObject # A dictionary 509 | 510 | PPyMethodObject* = ptr TPyMethodObject 511 | TPyMethodObject* = object of TPyObject # Bytecode object, compile.h 512 | im_func*: PPyObject # The function implementing the method 513 | im_self*: PPyObject # The instance it is bound to, or NULL 514 | im_class*: PPyObject # The class that defined the method 515 | 516 | PPyCodeObject* = ptr TPyCodeObject 517 | TPyCodeObject* = object of TPyObject # from pystate.h 518 | co_argcount*: int # #arguments, except *args 519 | co_nlocals*: int # #local variables 520 | co_stacksize*: int # #entries needed for evaluation stack 521 | co_flags*: int # CO_..., see below 522 | co_code*: PPyObject # instruction opcodes (it hides a PyStringObject) 523 | co_consts*: PPyObject # list (constants used) 524 | co_names*: PPyObject # list of strings (names used) 525 | co_varnames*: PPyObject # tuple of strings (local variable names) 526 | co_freevars*: PPyObject # tuple of strings (free variable names) 527 | co_cellvars*: PPyObject # tuple of strings (cell variable names) 528 | # The rest doesn't count for hash/cmp 529 | co_filename*: PPyObject # string (where it was loaded from) 530 | co_name*: PPyObject # string (name, for reference) 531 | co_firstlineno*: int # first source line number 532 | co_lnotab*: PPyObject # string (encoding addr<->lineno mapping) 533 | 534 | TPy_buffer* {.pure, final.} = object 535 | buf*: pointer 536 | obj*: PPyObject # owned reference 537 | length*: Py_ssize_t # number of bytes in this buffer (called 'len' in the .h, sorry about that) 538 | itemsize*: Py_ssize_t # This is Py_ssize_t so it can be 539 | # pointed to by strides in simple case. 540 | readonly*: cint 541 | ndim*: cint 542 | format*: cstring 543 | shape*: ptr Py_ssize_t 544 | strides*: ptr Py_ssize_t 545 | suboffsets*: ptr Py_ssize_t 546 | smalltable*: array[0..1, Py_ssize_t] # static store for shape and 547 | # strides of mono-dimensional 548 | # buffers. 549 | internal*: pointer 550 | 551 | PPyInterpreterState* = ptr TPyInterpreterState 552 | PPyThreadState* = ptr TPyThreadState 553 | PPyFrameObject* = ptr TPyFrameObject # Interpreter environments 554 | TPyInterpreterState*{.final.} = object # Thread specific information 555 | next*: PPyInterpreterState 556 | tstate_head*: PPyThreadState 557 | modules*: PPyObject 558 | sysdict*: PPyObject 559 | builtins*: PPyObject 560 | checkinterval*: int 561 | 562 | TPyThreadState*{.final.} = object # from frameobject.h 563 | next*: PPyThreadState 564 | interp*: PPyInterpreterState 565 | frame*: PPyFrameObject 566 | recursion_depth*: int 567 | ticker*: int 568 | tracing*: int 569 | sys_profilefunc*: PPyObject 570 | sys_tracefunc*: PPyObject 571 | curexc_type*: PPyObject 572 | curexc_value*: PPyObject 573 | curexc_traceback*: PPyObject 574 | exc_type*: PPyObject 575 | exc_value*: PPyObject 576 | exc_traceback*: PPyObject 577 | dict*: PPyObject 578 | 579 | PPyTryBlock* = ptr TPyTryBlock 580 | TPyTryBlock*{.final.} = object 581 | b_type*: int # what kind of block this is 582 | b_handler*: int # where to jump to find handler 583 | b_level*: int # value stack level to pop to 584 | 585 | CO_MAXBLOCKS* = range[0..19] 586 | TPyFrameObject* = object of TPyObject # start of the VAR_HEAD of an object 587 | # From traceback.c 588 | ob_size*: int # Number of items in variable part 589 | # End of the Head of an object 590 | f_back*: PPyFrameObject # previous frame, or NULL 591 | f_code*: PPyCodeObject # code segment 592 | f_builtins*: PPyObject # builtin symbol table (PyDictObject) 593 | f_globals*: PPyObject # global symbol table (PyDictObject) 594 | f_locals*: PPyObject # local symbol table (PyDictObject) 595 | f_valuestack*: PPPyObject # points after the last local 596 | # Next free slot in f_valuestack. Frame creation sets to f_valuestack. 597 | # Frame evaluation usually NULLs it, but a frame that yields sets it 598 | # to the current stack top. 599 | f_stacktop*: PPPyObject 600 | f_trace*: PPyObject # Trace function 601 | f_exc_type*, f_exc_value*, f_exc_traceback*: PPyObject 602 | f_tstate*: PPyThreadState 603 | f_lasti*: int # Last instruction if called 604 | f_lineno*: int # Current line number 605 | f_restricted*: int # Flag set if restricted operations 606 | # in this scope 607 | f_iblock*: int # index in f_blockstack 608 | f_blockstack*: array[CO_MAXBLOCKS, TPyTryBlock] # for try and loop blocks 609 | f_nlocals*: int # number of locals 610 | f_ncells*: int 611 | f_nfreevars*: int 612 | f_stacksize*: int # size of value stack 613 | f_localsplus*: array[0..0, PPyObject] # locals+stack, dynamically sized 614 | 615 | PPyTraceBackObject* = ptr TPyTraceBackObject 616 | TPyTraceBackObject* = object of TPyObject # Parse tree node interface 617 | tb_next*: PPyTraceBackObject 618 | tb_frame*: PPyFrameObject 619 | tb_lasti*: int 620 | tb_lineno*: int 621 | 622 | PNode* = ptr Tnode 623 | Tnode*{.final.} = object # From weakrefobject.h 624 | n_type*: int16 625 | n_str*: cstring 626 | n_lineno*: int16 627 | n_nchildren*: int16 628 | n_child*: PNode 629 | 630 | PPyWeakReference* = ptr TPyWeakReference 631 | TPyWeakReference* = object of TPyObject 632 | wr_object*: PPyObject 633 | wr_callback*: PPyObject 634 | hash*: int32 635 | wr_prev*: PPyWeakReference 636 | wr_next*: PPyWeakReference 637 | 638 | const 639 | PyBUF_SIMPLE* = 0 640 | PyBUF_WRITABLE* = 0x00000001 641 | PyBUF_WRITEABLE* = PyBUF_WRITABLE 642 | PyBUF_FORMAT* = 0x00000004 643 | PyBUF_ND* = 0x00000008 644 | PyBUF_STRIDES* = (0x00000010 or PyBUF_ND) 645 | PyBUF_C_CONTIGUOUS* = (0x00000020 or PyBUF_STRIDES) 646 | PyBUF_F_CONTIGUOUS* = (0x00000040 or PyBUF_STRIDES) 647 | PyBUF_ANY_CONTIGUOUS* = (0x00000080 or PyBUF_STRIDES) 648 | PyBUF_INDIRECT* = (0x00000100 or PyBUF_STRIDES) 649 | PyBUF_CONTIG* = (PyBUF_ND or PyBUF_WRITABLE) 650 | PyBUF_CONTIG_RO* = (PyBUF_ND) 651 | PyBUF_STRIDED* = (PyBUF_STRIDES or PyBUF_WRITABLE) 652 | PyBUF_STRIDED_RO* = (PyBUF_STRIDES) 653 | PyBUF_RECORDS* = (PyBUF_STRIDES or PyBUF_WRITABLE or PyBUF_FORMAT) 654 | PyBUF_RECORDS_RO* = (PyBUF_STRIDES or PyBUF_FORMAT) 655 | PyBUF_FULL* = (PyBUF_INDIRECT or PyBUF_WRITABLE or PyBUF_FORMAT) 656 | PyBUF_FULL_RO* = (PyBUF_INDIRECT or PyBUF_FORMAT) 657 | PyBUF_READ* = 0x00000100 658 | PyBUF_WRITE* = 0x00000200 659 | PyBUF_SHADOW* = 0x00000400 660 | 661 | const 662 | PyDateTime_DATE_DATASIZE* = 4 # # of bytes for year, month, and day 663 | PyDateTime_TIME_DATASIZE* = 6 # # of bytes for hour, minute, second, and usecond 664 | PyDateTime_DATETIME_DATASIZE* = 10 # # of bytes for year, month, 665 | # day, hour, minute, second, and usecond. 666 | 667 | type 668 | TPyDateTime_Delta* = object of TPyObject 669 | hashcode*: int # -1 when unknown 670 | days*: int # -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS 671 | seconds*: int # 0 <= seconds < 24*3600 is invariant 672 | microseconds*: int # 0 <= microseconds < 1000000 is invariant 673 | 674 | PPyDateTime_Delta* = ptr TPyDateTime_Delta 675 | TPyDateTime_TZInfo* = object of TPyObject # a pure abstract base clase 676 | PPyDateTime_TZInfo* = ptr TPyDateTime_TZInfo 677 | TPyDateTime_BaseTZInfo* = object of TPyObject 678 | hashcode*: int 679 | hastzinfo*: bool # boolean flag 680 | 681 | PPyDateTime_BaseTZInfo* = ptr TPyDateTime_BaseTZInfo 682 | TPyDateTime_BaseTime* = object of TPyDateTime_BaseTZInfo 683 | data*: array[0..pred(PyDateTime_TIME_DATASIZE), int8] 684 | 685 | PPyDateTime_BaseTime* = ptr TPyDateTime_BaseTime 686 | TPyDateTime_Time* = object of TPyDateTime_BaseTime # hastzinfo true 687 | tzinfo*: PPyObject 688 | 689 | PPyDateTime_Time* = ptr TPyDateTime_Time 690 | TPyDateTime_Date* = object of TPyDateTime_BaseTZInfo 691 | data*: array[0..pred(PyDateTime_DATE_DATASIZE), int8] 692 | 693 | PPyDateTime_Date* = ptr TPyDateTime_Date 694 | TPyDateTime_BaseDateTime* = object of TPyDateTime_BaseTZInfo 695 | data*: array[0..pred(PyDateTime_DATETIME_DATASIZE), int8] 696 | 697 | PPyDateTime_BaseDateTime* = ptr TPyDateTime_BaseDateTime 698 | TPyDateTime_DateTime* = object of TPyDateTime_BaseTZInfo 699 | data*: array[0..pred(PyDateTime_DATETIME_DATASIZE), int8] 700 | tzinfo*: PPyObject 701 | 702 | PPyDateTime_DateTime* = ptr TPyDateTime_DateTime 703 | 704 | #----------------------------------------------------# 705 | # # 706 | # New exception classes # 707 | # # 708 | #----------------------------------------------------# 709 | 710 | # 711 | # // Python's exceptions 712 | # EPythonError = object(Exception) 713 | # EName: String; 714 | # EValue: String; 715 | # end; 716 | # EPyExecError = object(EPythonError) 717 | # end; 718 | # 719 | # // Standard exception classes of Python 720 | # 721 | #/// jah 29-sep-2000: updated for python 2.0 722 | #/// base classes updated according python documentation 723 | # 724 | #{ Hierarchy of Python exceptions, Python 2.3, copied from \Python\exceptions.c 725 | # 726 | #Exception\n\ 727 | # |\n\ 728 | # +-- SystemExit\n\ 729 | # +-- StopIteration\n\ 730 | # +-- StandardError\n\ 731 | # | |\n\ 732 | # | +-- KeyboardInterrupt\n\ 733 | # | +-- ImportError\n\ 734 | # | +-- EnvironmentError\n\ 735 | # | | |\n\ 736 | # | | +-- IOError\n\ 737 | # | | +-- OSError\n\ 738 | # | | |\n\ 739 | # | | +-- WindowsError\n\ 740 | # | | +-- VMSError\n\ 741 | # | |\n\ 742 | # | +-- EOFError\n\ 743 | # | +-- RuntimeError\n\ 744 | # | | |\n\ 745 | # | | +-- NotImplementedError\n\ 746 | # | |\n\ 747 | # | +-- NameError\n\ 748 | # | | |\n\ 749 | # | | +-- UnboundLocalError\n\ 750 | # | |\n\ 751 | # | +-- AttributeError\n\ 752 | # | +-- SyntaxError\n\ 753 | # | | |\n\ 754 | # | | +-- IndentationError\n\ 755 | # | | |\n\ 756 | # | | +-- TabError\n\ 757 | # | |\n\ 758 | # | +-- TypeError\n\ 759 | # | +-- AssertionError\n\ 760 | # | +-- LookupError\n\ 761 | # | | |\n\ 762 | # | | +-- IndexError\n\ 763 | # | | +-- KeyError\n\ 764 | # | |\n\ 765 | # | +-- ArithmeticError\n\ 766 | # | | |\n\ 767 | # | | +-- OverflowError\n\ 768 | # | | +-- ZeroDivisionError\n\ 769 | # | | +-- FloatingPointError\n\ 770 | # | |\n\ 771 | # | +-- ValueError\n\ 772 | # | | |\n\ 773 | # | | +-- UnicodeError\n\ 774 | # | | |\n\ 775 | # | | +-- UnicodeEncodeError\n\ 776 | # | | +-- UnicodeDecodeError\n\ 777 | # | | +-- UnicodeTranslateError\n\ 778 | # | |\n\ 779 | # | +-- ReferenceError\n\ 780 | # | +-- SystemError\n\ 781 | # | +-- MemoryError\n\ 782 | # |\n\ 783 | # +---Warning\n\ 784 | # |\n\ 785 | # +-- UserWarning\n\ 786 | # +-- DeprecationWarning\n\ 787 | # +-- PendingDeprecationWarning\n\ 788 | # +-- SyntaxWarning\n\ 789 | # +-- OverflowWarning\n\ 790 | # +-- RuntimeWarning\n\ 791 | # +-- FutureWarning" 792 | #} 793 | # EPyException = class (EPythonError); 794 | # EPyStandardError = class (EPyException); 795 | # EPyArithmeticError = class (EPyStandardError); 796 | # EPyLookupError = class (EPyStandardError); 797 | # EPyAssertionError = class (EPyStandardError); 798 | # EPyAttributeError = class (EPyStandardError); 799 | # EPyEOFError = class (EPyStandardError); 800 | # EPyFloatingPointError = class (EPyArithmeticError); 801 | # EPyEnvironmentError = class (EPyStandardError); 802 | # EPyIOError = class (EPyEnvironmentError); 803 | # EPyOSError = class (EPyEnvironmentError); 804 | # EPyImportError = class (EPyStandardError); 805 | # EPyIndexError = class (EPyLookupError); 806 | # EPyKeyError = class (EPyLookupError); 807 | # EPyKeyboardInterrupt = class (EPyStandardError); 808 | # EPyMemoryError = class (EPyStandardError); 809 | # EPyNameError = class (EPyStandardError); 810 | # EPyOverflowError = class (EPyArithmeticError); 811 | # EPyRuntimeError = class (EPyStandardError); 812 | # EPyNotImplementedError = class (EPyRuntimeError); 813 | # EPySyntaxError = class (EPyStandardError) 814 | # public 815 | # EFileName: string; 816 | # ELineStr: string; 817 | # ELineNumber: Integer; 818 | # EOffset: Integer; 819 | # end; 820 | # EPyIndentationError = class (EPySyntaxError); 821 | # EPyTabError = class (EPyIndentationError); 822 | # EPySystemError = class (EPyStandardError); 823 | # EPySystemExit = class (EPyException); 824 | # EPyTypeError = class (EPyStandardError); 825 | # EPyUnboundLocalError = class (EPyNameError); 826 | # EPyValueError = class (EPyStandardError); 827 | # EPyUnicodeError = class (EPyValueError); 828 | # UnicodeEncodeError = class (EPyUnicodeError); 829 | # UnicodeDecodeError = class (EPyUnicodeError); 830 | # UnicodeTranslateError = class (EPyUnicodeError); 831 | # EPyZeroDivisionError = class (EPyArithmeticError); 832 | # EPyStopIteration = class(EPyException); 833 | # EPyWarning = class (EPyException); 834 | # EPyUserWarning = class (EPyWarning); 835 | # EPyDeprecationWarning = class (EPyWarning); 836 | # PendingDeprecationWarning = class (EPyWarning); 837 | # FutureWarning = class (EPyWarning); 838 | # EPySyntaxWarning = class (EPyWarning); 839 | # EPyOverflowWarning = class (EPyWarning); 840 | # EPyRuntimeWarning = class (EPyWarning); 841 | # EPyReferenceError = class (EPyStandardError); 842 | # 843 | 844 | var 845 | PyArg_Parse*: proc (args: PPyObject, format: cstring): int{.cdecl, varargs.} 846 | PyArg_ParseTuple*: proc (args: PPyObject, format: cstring, x1: pointer = nil, 847 | x2: pointer = nil, x3: pointer = nil): int{.cdecl, varargs.} 848 | Py_BuildValue*: proc (format: cstring): PPyObject{.cdecl, varargs.} 849 | PyCode_Addr2Line*: proc (co: PPyCodeObject, addrq: int): int{.cdecl.} 850 | DLL_Py_GetBuildInfo*: proc (): cstring{.cdecl.} 851 | 852 | var 853 | Py_DebugFlag*: PInt 854 | Py_VerboseFlag*: PInt 855 | Py_InteractiveFlag*: PInt 856 | Py_OptimizeFlag*: PInt 857 | Py_NoSiteFlag*: PInt 858 | Py_UseClassExceptionsFlag*: PInt 859 | Py_FrozenFlag*: PInt 860 | Py_TabcheckFlag*: PInt 861 | Py_UnicodeFlag*: PInt 862 | Py_IgnoreEnvironmentFlag*: PInt 863 | Py_DivisionWarningFlag*: PInt 864 | #_PySys_TraceFunc: PPPyObject; 865 | #_PySys_ProfileFunc: PPPPyObject; 866 | PyImport_FrozenModules*: PP_frozen 867 | Py_None*: PPyObject 868 | Py_Ellipsis*: PPyObject 869 | Py_False*: PPyIntObject 870 | Py_True*: PPyIntObject 871 | Py_NotImplemented*: PPyObject 872 | PyExc_AttributeError*: PPPyObject 873 | PyExc_EOFError*: PPPyObject 874 | PyExc_IOError*: PPPyObject 875 | PyExc_ImportError*: PPPyObject 876 | PyExc_IndexError*: PPPyObject 877 | PyExc_KeyError*: PPPyObject 878 | PyExc_KeyboardInterrupt*: PPPyObject 879 | PyExc_MemoryError*: PPPyObject 880 | PyExc_NameError*: PPPyObject 881 | PyExc_OverflowError*: PPPyObject 882 | PyExc_RuntimeError*: PPPyObject 883 | PyExc_SyntaxError*: PPPyObject 884 | PyExc_SystemError*: PPPyObject 885 | PyExc_SystemExit*: PPPyObject 886 | PyExc_TypeError*: PPPyObject 887 | PyExc_ValueError*: PPPyObject 888 | PyExc_ZeroDivisionError*: PPPyObject 889 | PyExc_ArithmeticError*: PPPyObject 890 | PyExc_Exception*: PPPyObject 891 | PyExc_FloatingPointError*: PPPyObject 892 | PyExc_LookupError*: PPPyObject 893 | PyExc_StandardError*: PPPyObject 894 | PyExc_AssertionError*: PPPyObject 895 | PyExc_EnvironmentError*: PPPyObject 896 | PyExc_IndentationError*: PPPyObject 897 | PyExc_MemoryErrorInst*: PPPyObject 898 | PyExc_NotImplementedError*: PPPyObject 899 | PyExc_OSError*: PPPyObject 900 | PyExc_TabError*: PPPyObject 901 | PyExc_UnboundLocalError*: PPPyObject 902 | PyExc_UnicodeError*: PPPyObject 903 | PyExc_Warning*: PPPyObject 904 | PyExc_DeprecationWarning*: PPPyObject 905 | PyExc_RuntimeWarning*: PPPyObject 906 | PyExc_SyntaxWarning*: PPPyObject 907 | PyExc_UserWarning*: PPPyObject 908 | PyExc_OverflowWarning*: PPPyObject 909 | PyExc_ReferenceError*: PPPyObject 910 | PyExc_StopIteration*: PPPyObject 911 | PyExc_FutureWarning*: PPPyObject 912 | PyExc_PendingDeprecationWarning*: PPPyObject 913 | PyExc_UnicodeDecodeError*: PPPyObject 914 | PyExc_UnicodeEncodeError*: PPPyObject 915 | PyExc_UnicodeTranslateError*: PPPyObject 916 | PyType_Type*: PPyTypeObject 917 | PyCFunction_Type*: PPyTypeObject 918 | PyCObject_Type*: PPyTypeObject 919 | PyClass_Type*: PPyTypeObject 920 | PyCode_Type*: PPyTypeObject 921 | PyComplex_Type*: PPyTypeObject 922 | PyDict_Type*: PPyTypeObject 923 | PyFile_Type*: PPyTypeObject 924 | PyFloat_Type*: PPyTypeObject 925 | PyFrame_Type*: PPyTypeObject 926 | PyFunction_Type*: PPyTypeObject 927 | PyInstance_Type*: PPyTypeObject 928 | PyInt_Type*: PPyTypeObject 929 | PyList_Type*: PPyTypeObject 930 | PyLong_Type*: PPyTypeObject 931 | PyMethod_Type*: PPyTypeObject 932 | PyModule_Type*: PPyTypeObject 933 | PyObject_Type*: PPyTypeObject 934 | PyRange_Type*: PPyTypeObject 935 | PySlice_Type*: PPyTypeObject 936 | PyString_Type*: PPyTypeObject 937 | PyTuple_Type*: PPyTypeObject 938 | PyBaseObject_Type*: PPyTypeObject 939 | PyBuffer_Type*: PPyTypeObject 940 | PyCallIter_Type*: PPyTypeObject 941 | PyCell_Type*: PPyTypeObject 942 | PyClassMethod_Type*: PPyTypeObject 943 | PyProperty_Type*: PPyTypeObject 944 | PySeqIter_Type*: PPyTypeObject 945 | PyStaticMethod_Type*: PPyTypeObject 946 | PySuper_Type*: PPyTypeObject 947 | PySymtableEntry_Type*: PPyTypeObject 948 | PyTraceBack_Type*: PPyTypeObject 949 | PyUnicode_Type*: PPyTypeObject 950 | PyWrapperDescr_Type*: PPyTypeObject 951 | PyBaseString_Type*: PPyTypeObject 952 | PyBool_Type*: PPyTypeObject 953 | PyEnum_Type*: PPyTypeObject 954 | 955 | #PyArg_GetObject: proc(args: PPyObject; nargs, i: integer; p_a: PPPyObject): integer; cdecl; 956 | #PyArg_GetLong: proc(args: PPyObject; nargs, i: integer; p_a: PLong): integer; cdecl; 957 | #PyArg_GetShort: proc(args: PPyObject; nargs, i: integer; p_a: PShort): integer; cdecl; 958 | #PyArg_GetFloat: proc(args: PPyObject; nargs, i: integer; p_a: PFloat): integer; cdecl; 959 | #PyArg_GetString: proc(args: PPyObject; nargs, i: integer; p_a: PString): integer; cdecl; 960 | #PyArgs_VaParse: proc (args: PPyObject; format: PChar; 961 | # va_list: array of const): integer; cdecl; 962 | # Does not work! 963 | # Py_VaBuildValue: proc (format: PChar; va_list: array of const): PPyObject; cdecl; 964 | #PyBuiltin_Init: proc; cdecl; 965 | proc PyComplex_FromCComplex*(c: TPy_complex): PPyObject{.cdecl, importc, dynlib: dllname.} 966 | proc PyComplex_FromDoubles*(realv, imag: float64): PPyObject{.cdecl, importc, dynlib: dllname.} 967 | proc PyComplex_RealAsDouble*(op: PPyObject): float64{.cdecl, importc, dynlib: dllname.} 968 | proc PyComplex_ImagAsDouble*(op: PPyObject): float64{.cdecl, importc, dynlib: dllname.} 969 | proc PyComplex_AsCComplex*(op: PPyObject): TPy_complex{.cdecl, importc, dynlib: dllname.} 970 | proc PyCFunction_GetFunction*(ob: PPyObject): pointer{.cdecl, importc, dynlib: dllname.} 971 | proc PyCFunction_GetSelf*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 972 | proc PyCallable_Check*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} 973 | proc PyCObject_FromVoidPtr*(cobj, destruct: pointer): PPyObject{.cdecl, importc, dynlib: dllname.} 974 | proc PyCObject_AsVoidPtr*(ob: PPyObject): pointer{.cdecl, importc, dynlib: dllname.} 975 | proc PyClass_New*(ob1, ob2, ob3: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 976 | proc PyClass_IsSubclass*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} 977 | proc Py_InitModule4*(name: cstring, methods: PPyMethodDef, doc: cstring, 978 | passthrough: PPyObject, Api_Version: int): PPyObject{. 979 | cdecl, importc, dynlib: dllname.} 980 | proc PyErr_BadArgument*(): int{.cdecl, importc, dynlib: dllname.} 981 | proc PyErr_BadInternalCall*(){.cdecl, importc, dynlib: dllname.} 982 | proc PyErr_CheckSignals*(): int{.cdecl, importc, dynlib: dllname.} 983 | proc PyErr_Clear*(){.cdecl, importc, dynlib: dllname.} 984 | proc PyErr_Fetch*(errtype, errvalue, errtraceback: PPPyObject){.cdecl, importc, dynlib: dllname.} 985 | proc PyErr_NoMemory*(): PPyObject{.cdecl, importc, dynlib: dllname.} 986 | proc PyErr_Occurred*(): PPyObject{.cdecl, importc, dynlib: dllname.} 987 | proc PyErr_Print*(){.cdecl, importc, dynlib: dllname.} 988 | proc PyErr_Restore*(errtype, errvalue, errtraceback: PPyObject){.cdecl, importc, dynlib: dllname.} 989 | proc PyErr_SetFromErrno*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 990 | proc PyErr_SetNone*(value: PPyObject){.cdecl, importc, dynlib: dllname.} 991 | proc PyErr_SetObject*(ob1, ob2: PPyObject){.cdecl, importc, dynlib: dllname.} 992 | proc PyErr_SetString*(ErrorObject: PPyObject, text: cstring){.cdecl, importc, dynlib: dllname.} 993 | proc PyImport_GetModuleDict*(): PPyObject{.cdecl, importc, dynlib: dllname.} 994 | proc PyInt_FromLong*(x: int32): PPyObject{.cdecl, importc, dynlib: dllname.} 995 | proc Py_Initialize*(){.cdecl, importc, dynlib: dllname.} 996 | proc Py_Exit*(RetVal: int){.cdecl, importc, dynlib: dllname.} 997 | proc PyEval_GetBuiltins*(): PPyObject{.cdecl, importc, dynlib: dllname.} 998 | proc PyDict_GetItem*(mp, key: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 999 | proc PyDict_SetItem*(mp, key, item: PPyObject): int{.cdecl, importc, dynlib: dllname.} 1000 | proc PyDict_DelItem*(mp, key: PPyObject): int{.cdecl, importc, dynlib: dllname.} 1001 | proc PyDict_Clear*(mp: PPyObject){.cdecl, importc, dynlib: dllname.} 1002 | proc PyDict_Next*(mp: PPyObject, pos: PInt, key, value: PPPyObject): int{. 1003 | cdecl, importc, dynlib: dllname.} 1004 | proc PyDict_Keys*(mp: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1005 | proc PyDict_Values*(mp: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1006 | proc PyDict_Items*(mp: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1007 | proc PyDict_Size*(mp: PPyObject): int{.cdecl, importc, dynlib: dllname.} 1008 | proc PyDict_DelItemString*(dp: PPyObject, key: cstring): int{.cdecl, importc, dynlib: dllname.} 1009 | proc PyDict_New*(): PPyObject{.cdecl, importc, dynlib: dllname.} 1010 | proc PyDict_GetItemString*(dp: PPyObject, key: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} 1011 | proc PyDict_SetItemString*(dp: PPyObject, key: cstring, item: PPyObject): int{. 1012 | cdecl, importc, dynlib: dllname.} 1013 | proc PyDictProxy_New*(obj: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1014 | proc PyModule_GetDict*(module: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1015 | proc PyObject_Str*(v: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1016 | proc PyRun_String*(str: cstring, start: int, globals: PPyObject, 1017 | locals: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1018 | proc PyRun_SimpleString*(str: cstring): int{.cdecl, importc, dynlib: dllname.} 1019 | proc PyString_AsString*(ob: PPyObject): cstring{.cdecl, importc, dynlib: dllname.} 1020 | proc PyString_FromString*(str: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} 1021 | proc PySys_SetArgv*(argc: int, argv: cstringArray){.cdecl, importc, dynlib: dllname.} 1022 | #+ means, Grzegorz or me has tested his non object version of this function 1023 | #+ 1024 | proc PyCFunction_New*(md: PPyMethodDef, ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1025 | proc PyEval_CallObject*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1026 | proc PyEval_CallObjectWithKeywords*(ob1, ob2, ob3: PPyObject): PPyObject{. 1027 | cdecl, importc, dynlib: dllname.} #- 1028 | proc PyEval_GetFrame*(): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1029 | proc PyEval_GetGlobals*(): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1030 | proc PyEval_GetLocals*(): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1031 | proc PyEval_GetOwner*(): PPyObject {.cdecl, importc, dynlib: dllname.} 1032 | proc PyEval_GetRestricted*(): int{.cdecl, importc, dynlib: dllname.} #- 1033 | proc PyEval_InitThreads*(){.cdecl, importc, dynlib: dllname.} #- 1034 | proc PyEval_RestoreThread*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} #- 1035 | proc PyEval_SaveThread*(): PPyThreadState{.cdecl, importc, dynlib: dllname.} #- 1036 | proc PyFile_FromString*(pc1, pc2: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1037 | proc PyFile_GetLine*(ob: PPyObject, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1038 | proc PyFile_Name*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1039 | proc PyFile_SetBufSize*(ob: PPyObject, i: int){.cdecl, importc, dynlib: dllname.} #- 1040 | proc PyFile_SoftSpace*(ob: PPyObject, i: int): int{.cdecl, importc, dynlib: dllname.} #- 1041 | proc PyFile_WriteObject*(ob1, ob2: PPyObject, i: int): int{.cdecl, importc, dynlib: dllname.} #- 1042 | proc PyFile_WriteString*(s: cstring, ob: PPyObject){.cdecl, importc, dynlib: dllname.} #+ 1043 | proc PyFloat_AsDouble*(ob: PPyObject): float64{.cdecl, importc, dynlib: dllname.} #+ 1044 | proc PyFloat_FromDouble*(db: float64): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1045 | proc PyFunction_GetCode*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1046 | proc PyFunction_GetGlobals*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1047 | proc PyFunction_New*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1048 | proc PyImport_AddModule*(name: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1049 | proc PyImport_Cleanup*(){.cdecl, importc, dynlib: dllname.} #- 1050 | proc PyImport_GetMagicNumber*(): int32{.cdecl, importc, dynlib: dllname.} #+ 1051 | proc PyImport_ImportFrozenModule*(key: cstring): int{.cdecl, importc, dynlib: dllname.} #+ 1052 | proc PyImport_ImportModule*(name: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1053 | proc PyImport_Import*(name: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1054 | 1055 | proc PyImport_Init*() {.cdecl, importc, dynlib: dllname.} 1056 | proc PyImport_ReloadModule*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1057 | proc PyInstance_New*(obClass, obArg, obKW: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1058 | proc PyInt_AsLong*(ob: PPyObject): int32{.cdecl, importc, dynlib: dllname.} #- 1059 | proc PyList_Append*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1060 | proc PyList_AsTuple*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1061 | proc PyList_GetItem*(ob: PPyObject, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1062 | proc PyList_GetSlice*(ob: PPyObject, i1, i2: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1063 | proc PyList_Insert*(dp: PPyObject, idx: int, item: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1064 | proc PyList_New*(size: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1065 | proc PyList_Reverse*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1066 | proc PyList_SetItem*(dp: PPyObject, idx: int, item: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1067 | proc PyList_SetSlice*(ob: PPyObject, i1, i2: int, ob2: PPyObject): int{. 1068 | cdecl, importc, dynlib: dllname.} #+ 1069 | proc PyList_Size*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1070 | proc PyList_Sort*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1071 | proc PyLong_AsDouble*(ob: PPyObject): float64{.cdecl, importc, dynlib: dllname.} #+ 1072 | proc PyLong_AsLong*(ob: PPyObject): int32{.cdecl, importc, dynlib: dllname.} #+ 1073 | proc PyLong_FromDouble*(db: float64): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1074 | proc PyLong_FromLong*(L: int32): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1075 | proc PyLong_FromString*(pc: cstring, ppc: var cstring, i: int): PPyObject{. 1076 | cdecl, importc, dynlib: dllname.} #- 1077 | proc PyLong_FromUnsignedLong*(val: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1078 | proc PyLong_AsUnsignedLong*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1079 | proc PyLong_FromUnicode*(ob: PPyObject, a, b: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1080 | proc PyLong_FromLongLong*(val: int64): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1081 | proc PyLong_AsLongLong*(ob: PPyObject): int64{.cdecl, importc, dynlib: dllname.} #- 1082 | proc PyMapping_Check*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1083 | proc PyMapping_GetItemString*(ob: PPyObject, key: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1084 | proc PyMapping_HasKey*(ob, key: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1085 | proc PyMapping_HasKeyString*(ob: PPyObject, key: cstring): int{.cdecl, importc, dynlib: dllname.} #- 1086 | proc PyMapping_Length*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1087 | proc PyMapping_SetItemString*(ob: PPyObject, key: cstring, value: PPyObject): int{. 1088 | cdecl, importc, dynlib: dllname.} #- 1089 | proc PyMethod_Class*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1090 | proc PyMethod_Function*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1091 | proc PyMethod_New*(ob1, ob2, ob3: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1092 | proc PyMethod_Self*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1093 | proc PyModule_GetName*(ob: PPyObject): cstring{.cdecl, importc, dynlib: dllname.} #- 1094 | proc PyModule_New*(key: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1095 | proc PyNumber_Absolute*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1096 | proc PyNumber_Add*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1097 | proc PyNumber_And*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1098 | proc PyNumber_Check*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1099 | proc PyNumber_Coerce*(ob1, ob2: var PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1100 | proc PyNumber_Divide*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1101 | proc PyNumber_FloorDivide*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1102 | proc PyNumber_TrueDivide*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1103 | proc PyNumber_Divmod*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1104 | proc PyNumber_Float*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1105 | proc PyNumber_Int*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1106 | proc PyNumber_Invert*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1107 | proc PyNumber_Long*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1108 | proc PyNumber_Lshift*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1109 | proc PyNumber_Multiply*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1110 | proc PyNumber_Negative*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1111 | proc PyNumber_Or*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1112 | proc PyNumber_Positive*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1113 | proc PyNumber_Power*(ob1, ob2, ob3: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1114 | proc PyNumber_Remainder*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1115 | proc PyNumber_Rshift*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1116 | proc PyNumber_Subtract*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1117 | proc PyNumber_Xor*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1118 | proc PyOS_InitInterrupts*(){.cdecl, importc, dynlib: dllname.} #- 1119 | proc PyOS_InterruptOccurred*(): int{.cdecl, importc, dynlib: dllname.} #- 1120 | proc PyObject_CallObject*(ob, args: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1121 | proc PyObject_Compare*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1122 | proc PyObject_GetAttr*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1123 | proc PyObject_GetAttrString*(ob: PPyObject, c: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1124 | proc PyObject_GetItem*(ob, key: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1125 | proc PyObject_DelItem*(ob, key: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1126 | proc PyObject_HasAttrString*(ob: PPyObject, key: cstring): int{.cdecl, importc, dynlib: dllname.} #- 1127 | proc PyObject_Hash*(ob: PPyObject): int32{.cdecl, importc, dynlib: dllname.} #- 1128 | proc PyObject_IsTrue*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1129 | proc PyObject_Length*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1130 | proc PyObject_Repr*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1131 | proc PyObject_SetAttr*(ob1, ob2, ob3: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1132 | proc PyObject_SetAttrString*(ob: PPyObject, key: cstring, value: PPyObject): int{. 1133 | cdecl, importc, dynlib: dllname.} #- 1134 | proc PyObject_SetItem*(ob1, ob2, ob3: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1135 | proc PyObject_Init*(ob: PPyObject, t: PPyTypeObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1136 | proc PyObject_InitVar*(ob: PPyObject, t: PPyTypeObject, size: int): PPyObject{. 1137 | cdecl, importc, dynlib: dllname.} #- 1138 | proc PyObject_New*(t: PPyTypeObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1139 | proc PyObject_NewVar*(t: PPyTypeObject, size: int): PPyObject{.cdecl, importc, dynlib: dllname.} 1140 | proc PyObject_Free*(ob: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1141 | proc PyObject_IsInstance*(inst, cls: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1142 | proc PyObject_IsSubclass*(derived, cls: PPyObject): int{.cdecl, importc, dynlib: dllname.} 1143 | proc PyObject_GenericGetAttr*(obj, name: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1144 | proc PyObject_GenericSetAttr*(obj, name, value: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1145 | proc PyObject_RichCompare*(o1, o2: PPyObject, opid: TRichComparisonOpcode): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1146 | 1147 | proc PyObject_GetBuffer*(obj: PPyObject, view: PPy_buffer, flags: cint): cint{.cdecl, importc, dynlib: dllname.} 1148 | proc PyBuffer_Release*(view: PPy_buffer) {.cdecl, importc, dynlib: dllname.} #- 1149 | 1150 | proc PyObject_GC_Malloc*(size: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1151 | proc PyObject_GC_New*(t: PPyTypeObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1152 | proc PyObject_GC_NewVar*(t: PPyTypeObject, size: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1153 | proc PyObject_GC_Resize*(t: PPyObject, newsize: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1154 | proc PyObject_GC_Del*(ob: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1155 | proc PyObject_GC_Track*(ob: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1156 | proc PyObject_GC_UnTrack*(ob: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1157 | proc PyRange_New*(l1, l2, l3: int32, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1158 | proc PySequence_Check*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1159 | proc PySequence_Concat*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1160 | proc PySequence_Count*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1161 | proc PySequence_GetItem*(ob: PPyObject, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1162 | proc PySequence_GetSlice*(ob: PPyObject, i1, i2: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1163 | proc PySequence_In*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1164 | proc PySequence_Index*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1165 | proc PySequence_Length*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1166 | proc PySequence_Repeat*(ob: PPyObject, count: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1167 | proc PySequence_SetItem*(ob: PPyObject, i: int, value: PPyObject): int{. 1168 | cdecl, importc, dynlib: dllname.} #- 1169 | proc PySequence_SetSlice*(ob: PPyObject, i1, i2: int, value: PPyObject): int{. 1170 | cdecl, importc, dynlib: dllname.} #- 1171 | proc PySequence_DelSlice*(ob: PPyObject, i1, i2: int): int{.cdecl, importc, dynlib: dllname.} #- 1172 | proc PySequence_Tuple*(ob: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1173 | proc PySequence_Contains*(ob, value: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1174 | proc PySlice_GetIndices*(ob: PPySliceObject, len: int, 1175 | start, stop, step: var int): int{.cdecl, importc, dynlib: dllname.} #- 1176 | proc PySlice_GetIndicesEx*(ob: PPySliceObject, len: int, 1177 | start, stop, step, slicelength: var int): int{. 1178 | cdecl, importc, dynlib: dllname.} #- 1179 | proc PySlice_New*(start, stop, step: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1180 | proc PyString_Concat*(ob1: var PPyObject, ob2: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1181 | proc PyString_ConcatAndDel*(ob1: var PPyObject, ob2: PPyObject){.cdecl, importc, dynlib: dllname.} #- 1182 | proc PyString_Format*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1183 | proc PyString_FromStringAndSize*(s: cstring, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1184 | proc PyString_Size*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1185 | proc PyString_DecodeEscape*(s: cstring, length: int, errors: cstring, 1186 | unicode: int, recode_encoding: cstring): PPyObject{. 1187 | cdecl, importc, dynlib: dllname.} #- 1188 | proc PyString_Repr*(ob: PPyObject, smartquotes: int): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1189 | proc PySys_GetObject*(s: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} 1190 | #- 1191 | #PySys_Init:procedure; cdecl, importc, dynlib: dllname; 1192 | #- 1193 | proc PySys_SetObject*(s: cstring, ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1194 | proc PySys_SetPath*(path: cstring){.cdecl, importc, dynlib: dllname.} #- 1195 | #PyTraceBack_Fetch:function:PPyObject; cdecl, importc, dynlib: dllname; 1196 | #- 1197 | proc PyTraceBack_Here*(p: pointer): int{.cdecl, importc, dynlib: dllname.} #- 1198 | proc PyTraceBack_Print*(ob1, ob2: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1199 | #PyTraceBack_Store:function (ob:PPyObject):integer; cdecl, importc, dynlib: dllname; 1200 | #+ 1201 | proc PyTuple_GetItem*(ob: PPyObject, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1202 | proc PyTuple_GetSlice*(ob: PPyObject, i1, i2: int): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1203 | proc PyTuple_New*(size: int): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1204 | proc PyTuple_SetItem*(ob: PPyObject, key: int, value: PPyObject): int{.cdecl, importc, dynlib: dllname.} #+ 1205 | proc PyTuple_Size*(ob: PPyObject): int{.cdecl, importc, dynlib: dllname.} #+ 1206 | proc PyType_IsSubtype*(a, b: PPyTypeObject): int{.cdecl, importc, dynlib: dllname.} 1207 | proc PyType_GenericAlloc*(atype: PPyTypeObject, nitems: int): PPyObject{. 1208 | cdecl, importc, dynlib: dllname.} 1209 | proc PyType_GenericNew*(atype: PPyTypeObject, args, kwds: PPyObject): PPyObject{. 1210 | cdecl, importc, dynlib: dllname.} 1211 | proc PyType_Ready*(atype: PPyTypeObject): int{.cdecl, importc, dynlib: dllname.} #+ 1212 | proc PyUnicode_FromWideChar*(w: pointer, size: int): PPyObject{.cdecl, importc, dynlib: dllname.} #+ 1213 | proc PyUnicode_AsWideChar*(unicode: PPyObject, w: pointer, size: int): int{. 1214 | cdecl, importc, dynlib: dllname.} #- 1215 | proc PyUnicode_FromOrdinal*(ordinal: int): PPyObject{.cdecl, importc, dynlib: dllname.} 1216 | proc PyWeakref_GetObject*(theRef: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1217 | proc PyWeakref_NewProxy*(ob, callback: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1218 | proc PyWeakref_NewRef*(ob, callback: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1219 | proc PyWrapper_New*(ob1, ob2: PPyObject): PPyObject{.cdecl, importc, dynlib: dllname.} 1220 | proc PyBool_FromLong*(ok: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1221 | proc Py_AtExit*(prc: proc () {.cdecl.}): int{.cdecl, importc, dynlib: dllname.} #- 1222 | #Py_Cleanup:procedure; cdecl, importc, dynlib: dllname; 1223 | #- 1224 | proc Py_CompileString*(s1, s2: cstring, i: int): PPyObject{.cdecl, importc, dynlib: dllname.} #- 1225 | proc Py_FatalError*(s: cstring){.cdecl, importc, dynlib: dllname.} #- 1226 | proc Py_FindMethod*(md: PPyMethodDef, ob: PPyObject, key: cstring): PPyObject{. 1227 | cdecl, importc, dynlib: dllname.} #- 1228 | proc Py_FindMethodInChain*(mc: PPyMethodChain, ob: PPyObject, key: cstring): PPyObject{. 1229 | cdecl, importc, dynlib: dllname.} #- 1230 | proc Py_FlushLine*(){.cdecl, importc, dynlib: dllname.} #+ 1231 | proc Py_Finalize*(){.cdecl, importc, dynlib: dllname.} #- 1232 | proc PyErr_ExceptionMatches*(exc: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1233 | proc PyErr_GivenExceptionMatches*(raised_exc, exc: PPyObject): int{.cdecl, importc, dynlib: dllname.} #- 1234 | proc PyEval_EvalCode*(co: PPyCodeObject, globals, locals: PPyObject): PPyObject{. 1235 | cdecl, importc, dynlib: dllname.} #+ 1236 | proc Py_GetVersion*(): cstring{.cdecl, importc, dynlib: dllname.} #+ 1237 | proc Py_GetCopyright*(): cstring{.cdecl, importc, dynlib: dllname.} #+ 1238 | proc Py_GetExecPrefix*(): cstring{.cdecl, importc, dynlib: dllname.} #+ 1239 | proc Py_GetPath*(): cstring{.cdecl, importc, dynlib: dllname.} #+ 1240 | proc Py_GetPrefix*(): cstring{.cdecl, importc, dynlib: dllname.} #+ 1241 | proc Py_GetProgramName*(): cstring{.cdecl, importc, dynlib: dllname.} #- 1242 | proc PyParser_SimpleParseString*(str: cstring, start: int): PNode{.cdecl, importc, dynlib: dllname.} #- 1243 | proc PyNode_Free*(n: PNode){.cdecl, importc, dynlib: dllname.} #- 1244 | proc PyErr_NewException*(name: cstring, base, dict: PPyObject): PPyObject{. 1245 | cdecl, importc, dynlib: dllname.} #- 1246 | proc Py_Malloc*(size: int): pointer {.cdecl, importc, dynlib: dllname.} 1247 | proc PyMem_Malloc*(size: int): pointer {.cdecl, importc, dynlib: dllname.} 1248 | proc PyObject_CallMethod*(obj: PPyObject, theMethod, 1249 | format: cstring): PPyObject{.cdecl, importc, dynlib: dllname.} 1250 | proc Py_SetProgramName*(name: cstring){.cdecl, importc, dynlib: dllname.} 1251 | proc Py_IsInitialized*(): int{.cdecl, importc, dynlib: dllname.} 1252 | proc Py_GetProgramFullPath*(): cstring{.cdecl, importc, dynlib: dllname.} 1253 | proc Py_NewInterpreter*(): PPyThreadState{.cdecl, importc, dynlib: dllname.} 1254 | proc Py_EndInterpreter*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} 1255 | proc PyEval_AcquireLock*(){.cdecl, importc, dynlib: dllname.} 1256 | proc PyEval_ReleaseLock*(){.cdecl, importc, dynlib: dllname.} 1257 | proc PyEval_AcquireThread*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} 1258 | proc PyEval_ReleaseThread*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} 1259 | proc PyInterpreterState_New*(): PPyInterpreterState{.cdecl, importc, dynlib: dllname.} 1260 | proc PyInterpreterState_Clear*(interp: PPyInterpreterState){.cdecl, importc, dynlib: dllname.} 1261 | proc PyInterpreterState_Delete*(interp: PPyInterpreterState){.cdecl, importc, dynlib: dllname.} 1262 | proc PyThreadState_New*(interp: PPyInterpreterState): PPyThreadState{.cdecl, importc, dynlib: dllname.} 1263 | proc PyThreadState_Clear*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} 1264 | proc PyThreadState_Delete*(tstate: PPyThreadState){.cdecl, importc, dynlib: dllname.} 1265 | proc PyThreadState_Get*(): PPyThreadState{.cdecl, importc, dynlib: dllname.} 1266 | proc PyThreadState_Swap*(tstate: PPyThreadState): PPyThreadState{.cdecl, importc, dynlib: dllname.} 1267 | 1268 | #Further exported Objects, may be implemented later 1269 | # 1270 | # PyCode_New: pointer; 1271 | # PyErr_SetInterrupt: pointer; 1272 | # PyFile_AsFile: pointer; 1273 | # PyFile_FromFile: pointer; 1274 | # PyFloat_AsString: pointer; 1275 | # PyFrame_BlockPop: pointer; 1276 | # PyFrame_BlockSetup: pointer; 1277 | # PyFrame_ExtendStack: pointer; 1278 | # PyFrame_FastToLocals: pointer; 1279 | # PyFrame_LocalsToFast: pointer; 1280 | # PyFrame_New: pointer; 1281 | # PyGrammar_AddAccelerators: pointer; 1282 | # PyGrammar_FindDFA: pointer; 1283 | # PyGrammar_LabelRepr: pointer; 1284 | # PyInstance_DoBinOp: pointer; 1285 | # PyInt_GetMax: pointer; 1286 | # PyMarshal_Init: pointer; 1287 | # PyMarshal_ReadLongFromFile: pointer; 1288 | # PyMarshal_ReadObjectFromFile: pointer; 1289 | # PyMarshal_ReadObjectFromString: pointer; 1290 | # PyMarshal_WriteLongToFile: pointer; 1291 | # PyMarshal_WriteObjectToFile: pointer; 1292 | # PyMember_Get: pointer; 1293 | # PyMember_Set: pointer; 1294 | # PyNode_AddChild: pointer; 1295 | # PyNode_Compile: pointer; 1296 | # PyNode_New: pointer; 1297 | # PyOS_GetLastModificationTime: pointer; 1298 | # PyOS_Readline: pointer; 1299 | # PyOS_strtol: pointer; 1300 | # PyOS_strtoul: pointer; 1301 | # PyObject_CallFunction: pointer; 1302 | # PyObject_CallMethod: pointer; 1303 | # PyObject_Print: pointer; 1304 | # PyParser_AddToken: pointer; 1305 | # PyParser_Delete: pointer; 1306 | # PyParser_New: pointer; 1307 | # PyParser_ParseFile: pointer; 1308 | # PyParser_ParseString: pointer; 1309 | # PyParser_SimpleParseFile: pointer; 1310 | # PyRun_AnyFile: pointer; 1311 | # PyRun_File: pointer; 1312 | # PyRun_InteractiveLoop: pointer; 1313 | # PyRun_InteractiveOne: pointer; 1314 | # PyRun_SimpleFile: pointer; 1315 | # PySys_GetFile: pointer; 1316 | # PyToken_OneChar: pointer; 1317 | # PyToken_TwoChars: pointer; 1318 | # PyTokenizer_Free: pointer; 1319 | # PyTokenizer_FromFile: pointer; 1320 | # PyTokenizer_FromString: pointer; 1321 | # PyTokenizer_Get: pointer; 1322 | # Py_Main: pointer; 1323 | # _PyObject_NewVar: pointer; 1324 | # _PyParser_Grammar: pointer; 1325 | # _PyParser_TokenNames: pointer; 1326 | # _PyThread_Started: pointer; 1327 | # _Py_c_diff: pointer; 1328 | # _Py_c_neg: pointer; 1329 | # _Py_c_pow: pointer; 1330 | # _Py_c_prod: pointer; 1331 | # _Py_c_quot: pointer; 1332 | # _Py_c_sum: pointer; 1333 | # 1334 | 1335 | # This function handles all cardinals, pointer types (with no adjustment of pointers!) 1336 | # (Extended) floats, which are handled as Python doubles and currencies, handled 1337 | # as (normalized) Python doubles. 1338 | proc PyImport_ExecCodeModule*(name: string, codeobject: PPyObject): PPyObject 1339 | proc PyString_Check*(obj: PPyObject): bool 1340 | proc PyString_CheckExact*(obj: PPyObject): bool 1341 | proc PyFloat_Check*(obj: PPyObject): bool 1342 | proc PyFloat_CheckExact*(obj: PPyObject): bool 1343 | proc PyInt_Check*(obj: PPyObject): bool 1344 | proc PyInt_CheckExact*(obj: PPyObject): bool 1345 | proc PyLong_Check*(obj: PPyObject): bool 1346 | proc PyLong_CheckExact*(obj: PPyObject): bool 1347 | proc PyTuple_Check*(obj: PPyObject): bool 1348 | proc PyTuple_CheckExact*(obj: PPyObject): bool 1349 | proc PyInstance_Check*(obj: PPyObject): bool 1350 | proc PyClass_Check*(obj: PPyObject): bool 1351 | proc PyMethod_Check*(obj: PPyObject): bool 1352 | proc PyList_Check*(obj: PPyObject): bool 1353 | proc PyList_CheckExact*(obj: PPyObject): bool 1354 | proc PyDict_Check*(obj: PPyObject): bool 1355 | proc PyDict_CheckExact*(obj: PPyObject): bool 1356 | proc PyModule_Check*(obj: PPyObject): bool 1357 | proc PyModule_CheckExact*(obj: PPyObject): bool 1358 | proc PySlice_Check*(obj: PPyObject): bool 1359 | proc PyFunction_Check*(obj: PPyObject): bool 1360 | proc PyUnicode_Check*(obj: PPyObject): bool 1361 | proc PyUnicode_CheckExact*(obj: PPyObject): bool 1362 | proc PyType_IS_GC*(t: PPyTypeObject): bool 1363 | proc PyObject_IS_GC*(obj: PPyObject): bool 1364 | proc PyBool_Check*(obj: PPyObject): bool 1365 | proc PyBaseString_Check*(obj: PPyObject): bool 1366 | proc PyEnum_Check*(obj: PPyObject): bool 1367 | proc PyObject_TypeCheck*(obj: PPyObject, t: PPyTypeObject): bool 1368 | proc Py_InitModule*(name: cstring, md: PPyMethodDef): PPyObject 1369 | proc PyType_HasFeature*(AType: PPyTypeObject, AFlag: int): bool 1370 | # implementation 1371 | 1372 | proc Py_INCREF*(op: PPyObject) {.inline.} = 1373 | inc(op.ob_refcnt) 1374 | 1375 | proc Py_DECREF*(op: PPyObject) {.inline.} = 1376 | dec(op.ob_refcnt) 1377 | if op.ob_refcnt == 0: 1378 | op.ob_type.tp_dealloc(op) 1379 | 1380 | proc Py_XINCREF*(op: PPyObject) {.inline.} = 1381 | if op != nil: Py_INCREF(op) 1382 | 1383 | proc Py_XDECREF*(op: PPyObject) {.inline.} = 1384 | if op != nil: Py_DECREF(op) 1385 | 1386 | proc PyImport_ExecCodeModule(name: string, codeobject: PPyObject): PPyObject = 1387 | var m, d, v, modules: PPyObject 1388 | m = PyImport_AddModule(cstring(name)) 1389 | if m == nil: 1390 | return nil 1391 | d = PyModule_GetDict(m) 1392 | if PyDict_GetItemString(d, "__builtins__") == nil: 1393 | if PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins()) != 0: 1394 | return nil 1395 | if PyDict_SetItemString(d, "__file__", 1396 | PPyCodeObject(codeobject).co_filename) != 0: 1397 | PyErr_Clear() # Not important enough to report 1398 | v = PyEval_EvalCode(PPyCodeObject(codeobject), d, d) # XXX owner ? 1399 | if v == nil: 1400 | return nil 1401 | Py_XDECREF(v) 1402 | modules = PyImport_GetModuleDict() 1403 | if PyDict_GetItemString(modules, cstring(name)) == nil: 1404 | PyErr_SetString(PyExc_ImportError[] , cstring( 1405 | "Loaded module " & name & "not found in sys.modules")) 1406 | return nil 1407 | Py_XINCREF(m) 1408 | result = m 1409 | 1410 | proc PyString_Check(obj: PPyObject): bool = 1411 | result = PyObject_TypeCheck(obj, PyString_Type) 1412 | 1413 | proc PyString_CheckExact(obj: PPyObject): bool = 1414 | result = (obj != nil) and (obj.ob_type == PyString_Type) 1415 | 1416 | proc PyFloat_Check(obj: PPyObject): bool = 1417 | result = PyObject_TypeCheck(obj, PyFloat_Type) 1418 | 1419 | proc PyFloat_CheckExact(obj: PPyObject): bool = 1420 | result = (obj != nil) and (obj.ob_type == PyFloat_Type) 1421 | 1422 | proc PyInt_Check(obj: PPyObject): bool = 1423 | result = PyObject_TypeCheck(obj, PyInt_Type) 1424 | 1425 | proc PyInt_CheckExact(obj: PPyObject): bool = 1426 | result = (obj != nil) and (obj.ob_type == PyInt_Type) 1427 | 1428 | proc PyLong_Check(obj: PPyObject): bool = 1429 | result = PyObject_TypeCheck(obj, PyLong_Type) 1430 | 1431 | proc PyLong_CheckExact(obj: PPyObject): bool = 1432 | result = (obj != nil) and (obj.ob_type == PyLong_Type) 1433 | 1434 | proc PyTuple_Check(obj: PPyObject): bool = 1435 | result = PyObject_TypeCheck(obj, PyTuple_Type) 1436 | 1437 | proc PyTuple_CheckExact(obj: PPyObject): bool = 1438 | result = (obj != nil) and (obj[].ob_type == PyTuple_Type) 1439 | 1440 | proc PyInstance_Check(obj: PPyObject): bool = 1441 | result = (obj != nil) and (obj[].ob_type == PyInstance_Type) 1442 | 1443 | proc PyClass_Check(obj: PPyObject): bool = 1444 | result = (obj != nil) and (obj[].ob_type == PyClass_Type) 1445 | 1446 | proc PyMethod_Check(obj: PPyObject): bool = 1447 | result = (obj != nil) and (obj[].ob_type == PyMethod_Type) 1448 | 1449 | proc PyList_Check(obj: PPyObject): bool = 1450 | result = PyObject_TypeCheck(obj, PyList_Type) 1451 | 1452 | proc PyList_CheckExact(obj: PPyObject): bool = 1453 | result = (obj != nil) and (obj[].ob_type == PyList_Type) 1454 | 1455 | proc PyDict_Check(obj: PPyObject): bool = 1456 | result = PyObject_TypeCheck(obj, PyDict_Type) 1457 | 1458 | proc PyDict_CheckExact(obj: PPyObject): bool = 1459 | result = (obj != nil) and (obj[].ob_type == PyDict_Type) 1460 | 1461 | proc PyModule_Check(obj: PPyObject): bool = 1462 | result = PyObject_TypeCheck(obj, PyModule_Type) 1463 | 1464 | proc PyModule_CheckExact(obj: PPyObject): bool = 1465 | result = (obj != nil) and (obj[].ob_type == PyModule_Type) 1466 | 1467 | proc PySlice_Check(obj: PPyObject): bool = 1468 | result = (obj != nil) and (obj[].ob_type == PySlice_Type) 1469 | 1470 | proc PyFunction_Check(obj: PPyObject): bool = 1471 | result = (obj != nil) and 1472 | ((obj.ob_type == PyCFunction_Type) or 1473 | (obj.ob_type == PyFunction_Type)) 1474 | 1475 | proc PyUnicode_Check(obj: PPyObject): bool = 1476 | result = PyObject_TypeCheck(obj, PyUnicode_Type) 1477 | 1478 | proc PyUnicode_CheckExact(obj: PPyObject): bool = 1479 | result = (obj != nil) and (obj.ob_type == PyUnicode_Type) 1480 | 1481 | proc PyType_IS_GC(t: PPyTypeObject): bool = 1482 | result = PyType_HasFeature(t, Py_TPFLAGS_HAVE_GC) 1483 | 1484 | proc PyObject_IS_GC(obj: PPyObject): bool = 1485 | result = PyType_IS_GC(obj.ob_type) and 1486 | ((obj.ob_type.tp_is_gc == nil) or (obj.ob_type.tp_is_gc(obj) == 1)) 1487 | 1488 | proc PyBool_Check(obj: PPyObject): bool = 1489 | result = (obj != nil) and (obj.ob_type == PyBool_Type) 1490 | 1491 | proc PyBaseString_Check(obj: PPyObject): bool = 1492 | result = PyObject_TypeCheck(obj, PyBaseString_Type) 1493 | 1494 | proc PyEnum_Check(obj: PPyObject): bool = 1495 | result = (obj != nil) and (obj.ob_type == PyEnum_Type) 1496 | 1497 | proc PyObject_TypeCheck(obj: PPyObject, t: PPyTypeObject): bool = 1498 | result = (obj != nil) and (obj.ob_type == t) 1499 | if not result and (obj != nil) and (t != nil): 1500 | result = PyType_IsSubtype(obj.ob_type, t) == 1 1501 | 1502 | proc Py_InitModule(name: cstring, md: PPyMethodDef): PPyObject = 1503 | result = Py_InitModule4(name, md, nil, nil, 1012) 1504 | 1505 | proc PyType_HasFeature(AType: PPyTypeObject, AFlag: int): bool = 1506 | #(((t)->tp_flags & (f)) != 0) 1507 | result = (AType.tp_flags and AFlag) != 0 1508 | 1509 | proc PyObject_CheckBuffer*(obj: PPyObject): bool {.inline.} = 1510 | ((obj.ob_type.tp_as_buffer != nil) and 1511 | PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_NEWBUFFER) and 1512 | (obj.ob_type.tp_as_buffer.bf_getbuffer != nil)) 1513 | 1514 | proc initLibVars(lib: LibHandle) = 1515 | Py_DebugFlag = cast[PInt](symAddr(lib, "Py_DebugFlag")) 1516 | Py_VerboseFlag = cast[PInt](symAddr(lib, "Py_VerboseFlag")) 1517 | Py_InteractiveFlag = cast[PInt](symAddr(lib, "Py_InteractiveFlag")) 1518 | Py_OptimizeFlag = cast[PInt](symAddr(lib, "Py_OptimizeFlag")) 1519 | Py_NoSiteFlag = cast[PInt](symAddr(lib, "Py_NoSiteFlag")) 1520 | Py_UseClassExceptionsFlag = cast[PInt](symAddr(lib, "Py_UseClassExceptionsFlag")) 1521 | Py_FrozenFlag = cast[PInt](symAddr(lib, "Py_FrozenFlag")) 1522 | Py_TabcheckFlag = cast[PInt](symAddr(lib, "Py_TabcheckFlag")) 1523 | Py_UnicodeFlag = cast[PInt](symAddr(lib, "Py_UnicodeFlag")) 1524 | Py_IgnoreEnvironmentFlag = cast[PInt](symAddr(lib, "Py_IgnoreEnvironmentFlag")) 1525 | Py_DivisionWarningFlag = cast[PInt](symAddr(lib, "Py_DivisionWarningFlag")) 1526 | Py_None = cast[PPyObject](symAddr(lib, "_Py_NoneStruct")) 1527 | Py_Ellipsis = cast[PPyObject](symAddr(lib, "_Py_EllipsisObject")) 1528 | Py_False = cast[PPyIntObject](symAddr(lib, "_Py_ZeroStruct")) 1529 | Py_True = cast[PPyIntObject](symAddr(lib, "_Py_TrueStruct")) 1530 | Py_NotImplemented = cast[PPyObject](symAddr(lib, "_Py_NotImplementedStruct")) 1531 | PyImport_FrozenModules = cast[PP_frozen](symAddr(lib, "PyImport_FrozenModules")) 1532 | PyExc_AttributeError = cast[PPPyObject](symAddr(lib, "PyExc_AttributeError")) 1533 | PyExc_EOFError = cast[PPPyObject](symAddr(lib, "PyExc_EOFError")) 1534 | PyExc_IOError = cast[PPPyObject](symAddr(lib, "PyExc_IOError")) 1535 | PyExc_ImportError = cast[PPPyObject](symAddr(lib, "PyExc_ImportError")) 1536 | PyExc_IndexError = cast[PPPyObject](symAddr(lib, "PyExc_IndexError")) 1537 | PyExc_KeyError = cast[PPPyObject](symAddr(lib, "PyExc_KeyError")) 1538 | PyExc_KeyboardInterrupt = cast[PPPyObject](symAddr(lib, "PyExc_KeyboardInterrupt")) 1539 | PyExc_MemoryError = cast[PPPyObject](symAddr(lib, "PyExc_MemoryError")) 1540 | PyExc_NameError = cast[PPPyObject](symAddr(lib, "PyExc_NameError")) 1541 | PyExc_OverflowError = cast[PPPyObject](symAddr(lib, "PyExc_OverflowError")) 1542 | PyExc_RuntimeError = cast[PPPyObject](symAddr(lib, "PyExc_RuntimeError")) 1543 | PyExc_SyntaxError = cast[PPPyObject](symAddr(lib, "PyExc_SyntaxError")) 1544 | PyExc_SystemError = cast[PPPyObject](symAddr(lib, "PyExc_SystemError")) 1545 | PyExc_SystemExit = cast[PPPyObject](symAddr(lib, "PyExc_SystemExit")) 1546 | PyExc_TypeError = cast[PPPyObject](symAddr(lib, "PyExc_TypeError")) 1547 | PyExc_ValueError = cast[PPPyObject](symAddr(lib, "PyExc_ValueError")) 1548 | PyExc_ZeroDivisionError = cast[PPPyObject](symAddr(lib, "PyExc_ZeroDivisionError")) 1549 | PyExc_ArithmeticError = cast[PPPyObject](symAddr(lib, "PyExc_ArithmeticError")) 1550 | PyExc_Exception = cast[PPPyObject](symAddr(lib, "PyExc_Exception")) 1551 | PyExc_FloatingPointError = cast[PPPyObject](symAddr(lib, "PyExc_FloatingPointError")) 1552 | PyExc_LookupError = cast[PPPyObject](symAddr(lib, "PyExc_LookupError")) 1553 | PyExc_StandardError = cast[PPPyObject](symAddr(lib, "PyExc_StandardError")) 1554 | PyExc_AssertionError = cast[PPPyObject](symAddr(lib, "PyExc_AssertionError")) 1555 | PyExc_EnvironmentError = cast[PPPyObject](symAddr(lib, "PyExc_EnvironmentError")) 1556 | PyExc_IndentationError = cast[PPPyObject](symAddr(lib, "PyExc_IndentationError")) 1557 | PyExc_MemoryErrorInst = cast[PPPyObject](symAddr(lib, "PyExc_MemoryErrorInst")) 1558 | PyExc_NotImplementedError = cast[PPPyObject](symAddr(lib, "PyExc_NotImplementedError")) 1559 | PyExc_OSError = cast[PPPyObject](symAddr(lib, "PyExc_OSError")) 1560 | PyExc_TabError = cast[PPPyObject](symAddr(lib, "PyExc_TabError")) 1561 | PyExc_UnboundLocalError = cast[PPPyObject](symAddr(lib, "PyExc_UnboundLocalError")) 1562 | PyExc_UnicodeError = cast[PPPyObject](symAddr(lib, "PyExc_UnicodeError")) 1563 | PyExc_Warning = cast[PPPyObject](symAddr(lib, "PyExc_Warning")) 1564 | PyExc_DeprecationWarning = cast[PPPyObject](symAddr(lib, "PyExc_DeprecationWarning")) 1565 | PyExc_RuntimeWarning = cast[PPPyObject](symAddr(lib, "PyExc_RuntimeWarning")) 1566 | PyExc_SyntaxWarning = cast[PPPyObject](symAddr(lib, "PyExc_SyntaxWarning")) 1567 | PyExc_UserWarning = cast[PPPyObject](symAddr(lib, "PyExc_UserWarning")) 1568 | PyExc_OverflowWarning = cast[PPPyObject](symAddr(lib, "PyExc_OverflowWarning")) 1569 | PyExc_ReferenceError = cast[PPPyObject](symAddr(lib, "PyExc_ReferenceError")) 1570 | PyExc_StopIteration = cast[PPPyObject](symAddr(lib, "PyExc_StopIteration")) 1571 | PyExc_FutureWarning = cast[PPPyObject](symAddr(lib, "PyExc_FutureWarning")) 1572 | PyExc_PendingDeprecationWarning = cast[PPPyObject](symAddr(lib, 1573 | "PyExc_PendingDeprecationWarning")) 1574 | PyExc_UnicodeDecodeError = cast[PPPyObject](symAddr(lib, "PyExc_UnicodeDecodeError")) 1575 | PyExc_UnicodeEncodeError = cast[PPPyObject](symAddr(lib, "PyExc_UnicodeEncodeError")) 1576 | PyExc_UnicodeTranslateError = cast[PPPyObject](symAddr(lib, "PyExc_UnicodeTranslateError")) 1577 | PyType_Type = cast[PPyTypeObject](symAddr(lib, "PyType_Type")) 1578 | PyCFunction_Type = cast[PPyTypeObject](symAddr(lib, "PyCFunction_Type")) 1579 | PyCObject_Type = cast[PPyTypeObject](symAddr(lib, "PyCObject_Type")) 1580 | PyClass_Type = cast[PPyTypeObject](symAddr(lib, "PyClass_Type")) 1581 | PyCode_Type = cast[PPyTypeObject](symAddr(lib, "PyCode_Type")) 1582 | PyComplex_Type = cast[PPyTypeObject](symAddr(lib, "PyComplex_Type")) 1583 | PyDict_Type = cast[PPyTypeObject](symAddr(lib, "PyDict_Type")) 1584 | PyFile_Type = cast[PPyTypeObject](symAddr(lib, "PyFile_Type")) 1585 | PyFloat_Type = cast[PPyTypeObject](symAddr(lib, "PyFloat_Type")) 1586 | PyFrame_Type = cast[PPyTypeObject](symAddr(lib, "PyFrame_Type")) 1587 | PyFunction_Type = cast[PPyTypeObject](symAddr(lib, "PyFunction_Type")) 1588 | PyInstance_Type = cast[PPyTypeObject](symAddr(lib, "PyInstance_Type")) 1589 | PyInt_Type = cast[PPyTypeObject](symAddr(lib, "PyInt_Type")) 1590 | PyList_Type = cast[PPyTypeObject](symAddr(lib, "PyList_Type")) 1591 | PyLong_Type = cast[PPyTypeObject](symAddr(lib, "PyLong_Type")) 1592 | PyMethod_Type = cast[PPyTypeObject](symAddr(lib, "PyMethod_Type")) 1593 | PyModule_Type = cast[PPyTypeObject](symAddr(lib, "PyModule_Type")) 1594 | PyObject_Type = cast[PPyTypeObject](symAddr(lib, "PyObject_Type")) 1595 | PyRange_Type = cast[PPyTypeObject](symAddr(lib, "PyRange_Type")) 1596 | PySlice_Type = cast[PPyTypeObject](symAddr(lib, "PySlice_Type")) 1597 | PyString_Type = cast[PPyTypeObject](symAddr(lib, "PyString_Type")) 1598 | PyTuple_Type = cast[PPyTypeObject](symAddr(lib, "PyTuple_Type")) 1599 | PyUnicode_Type = cast[PPyTypeObject](symAddr(lib, "PyUnicode_Type")) 1600 | PyBaseObject_Type = cast[PPyTypeObject](symAddr(lib, "PyBaseObject_Type")) 1601 | PyBuffer_Type = cast[PPyTypeObject](symAddr(lib, "PyBuffer_Type")) 1602 | PyCallIter_Type = cast[PPyTypeObject](symAddr(lib, "PyCallIter_Type")) 1603 | PyCell_Type = cast[PPyTypeObject](symAddr(lib, "PyCell_Type")) 1604 | PyClassMethod_Type = cast[PPyTypeObject](symAddr(lib, "PyClassMethod_Type")) 1605 | PyProperty_Type = cast[PPyTypeObject](symAddr(lib, "PyProperty_Type")) 1606 | PySeqIter_Type = cast[PPyTypeObject](symAddr(lib, "PySeqIter_Type")) 1607 | PyStaticMethod_Type = cast[PPyTypeObject](symAddr(lib, "PyStaticMethod_Type")) 1608 | PySuper_Type = cast[PPyTypeObject](symAddr(lib, "PySuper_Type")) 1609 | PySymtableEntry_Type = cast[PPyTypeObject](symAddr(lib, "PySymtableEntry_Type")) 1610 | PyTraceBack_Type = cast[PPyTypeObject](symAddr(lib, "PyTraceBack_Type")) 1611 | PyWrapperDescr_Type = cast[PPyTypeObject](symAddr(lib, "PyWrapperDescr_Type")) 1612 | PyBaseString_Type = cast[PPyTypeObject](symAddr(lib, "PyBaseString_Type")) 1613 | PyBool_Type = cast[PPyTypeObject](symAddr(lib, "PyBool_Type")) 1614 | PyEnum_Type = cast[PPyTypeObject](symAddr(lib, "PyEnum_Type")) 1615 | 1616 | # Unfortunately we have to duplicate the loading mechanism here, because Nimrod 1617 | # used to not support variables from dynamic libraries. Well designed API's 1618 | # don't require this anyway. Python is an exception. 1619 | 1620 | var 1621 | lib: LibHandle 1622 | 1623 | when defined(windows): 1624 | const 1625 | LibNames = ["python27.dll", "python26.dll", "python25.dll", 1626 | "python24.dll", "python23.dll", "python22.dll", "python21.dll", 1627 | "python20.dll", "python16.dll", "python15.dll"] 1628 | elif defined(macosx): 1629 | const 1630 | LibNames = ["libpython2.7.dylib", "libpython2.6.dylib", 1631 | "libpython2.5.dylib", "libpython2.4.dylib", "libpython2.3.dylib", 1632 | "libpython2.2.dylib", "libpython2.1.dylib", "libpython2.0.dylib", 1633 | "libpython1.6.dylib", "libpython1.5.dylib"] 1634 | else: 1635 | const 1636 | LibNames = [ 1637 | "libpython2.7.so" & dllver, 1638 | "libpython2.6.so" & dllver, 1639 | "libpython2.5.so" & dllver, 1640 | "libpython2.4.so" & dllver, 1641 | "libpython2.3.so" & dllver, 1642 | "libpython2.2.so" & dllver, 1643 | "libpython2.1.so" & dllver, 1644 | "libpython2.0.so" & dllver, 1645 | "libpython1.6.so" & dllver, 1646 | "libpython1.5.so" & dllver] 1647 | 1648 | proc initPython*() = 1649 | for libName in items(LibNames): 1650 | lib = loadLib(libName, global_symbols=true) 1651 | if lib != nil: break 1652 | 1653 | if lib == nil: 1654 | raise newException(LibraryError, 1655 | "no suitable version of the python dll was found") 1656 | initLibVars(lib) 1657 | Py_Initialize() 1658 | 1659 | proc finalizePython*() = 1660 | if lib != nil: 1661 | Py_Finalize() 1662 | unloadLib(lib) 1663 | finally: lib = nil 1664 | -------------------------------------------------------------------------------- /nimborg/py/test/Makefile: -------------------------------------------------------------------------------- 1 | tests: test_py test_py_eval test_pylab test_linalg 2 | ./test_py 3 | ./test_py_eval 4 | ./test_pylab 5 | ./test_linalg 6 | 7 | COMPILE = nimrod -p=../../.. c 8 | DEPS = ../high_level.nim ../low_level.nim 9 | 10 | test_linalg: test_linalg.nim $(DEPS) 11 | $(COMPILE) $< 12 | 13 | test_minimize: test_minimize.nim $(DEPS) 14 | $(COMPILE) $< 15 | 16 | test_py: test_py.nim $(DEPS) 17 | $(COMPILE) $< 18 | 19 | test_pylab: test_pylab.nim $(DEPS) 20 | $(COMPILE) $< 21 | 22 | test_py_eval: test_py_eval.nim $(DEPS) 23 | $(COMPILE) $< 24 | -------------------------------------------------------------------------------- /nimborg/py/test/test_linalg.nim: -------------------------------------------------------------------------------- 1 | # solve a random linear system of equations using scipy 2 | 3 | import "../high_level" 4 | import "../low_level" 5 | import strutils 6 | from math import sin 7 | 8 | # values of x1..xk 9 | let truth = [13, -2, 4, 19] 10 | let np = pyImport("numpy") 11 | let random = pyImport("numpy.random") 12 | let linalg = pyImport("scipy.linalg") 13 | # plenty of equations ensure a good condition number 14 | let A = random.randn(30,4) 15 | let pyTruth = np.array(truth).reshape(mkTuple(truth.len, 1)) 16 | let b = np.dot(A, pyTruth) 17 | 18 | # solve for x: Ax = b 19 | let estimate = linalg.lstsq(A, b)[0] 20 | let epsilon = 0.0001 21 | for i in 0..len(truth)-1: 22 | assert(abs(estimate[i]-truth[i])