mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 22:13:29 +00:00
Merge branch 'new_spawn' into devel
Conflicts: todo.txt web/news.txt web/nimrod.ini
This commit is contained in:
@@ -1 +1 @@
|
||||
This file keeps several tools from deleting this subdirectory.
|
||||
This file keeps several tools from deleting this subdirectory.
|
||||
|
||||
@@ -417,6 +417,7 @@ type
|
||||
# efficiency
|
||||
nfTransf, # node has been transformed
|
||||
nfSem # node has been checked for semantics
|
||||
nfLL # node has gone through lambda lifting
|
||||
nfDotField # the call can use a dot operator
|
||||
nfDotSetter # the call can use a setter dot operarator
|
||||
nfExplicitCall # x.y() was used instead of x.y
|
||||
@@ -1505,7 +1506,7 @@ proc isGenericRoutine*(s: PSym): bool =
|
||||
proc skipGenericOwner*(s: PSym): PSym =
|
||||
internalAssert s.kind in skProcKinds
|
||||
## Generic instantiations are owned by their originating generic
|
||||
## symbol. This proc skips such owners and goes straigh to the owner
|
||||
## symbol. This proc skips such owners and goes straight to the owner
|
||||
## of the generic itself (the module or the enclosing proc).
|
||||
result = if sfFromGeneric in s.flags: s.owner.owner
|
||||
else: s.owner
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
#
|
||||
#
|
||||
# c2nim - C to Nimrod source converter
|
||||
# (c) Copyright 2013 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
import
|
||||
strutils, os, times, parseopt, llstream, ast, renderer, options, msgs,
|
||||
clex, cparse
|
||||
|
||||
const
|
||||
Version = NimrodVersion
|
||||
Usage = """
|
||||
c2nim - C to Nimrod source converter
|
||||
(c) 2013 Andreas Rumpf
|
||||
Usage: c2nim [options] inputfile [options]
|
||||
Options:
|
||||
-o, --out:FILE set output filename
|
||||
--cpp process C++ input file
|
||||
--dynlib:SYMBOL import from dynlib: SYMBOL will be used for the import
|
||||
--header:HEADER_FILE import from a HEADER_FILE (discouraged!)
|
||||
--cdecl annotate procs with ``{.cdecl.}``
|
||||
--stdcall annotate procs with ``{.stdcall.}``
|
||||
--ref convert typ* to ref typ (default: ptr typ)
|
||||
--prefix:PREFIX strip prefix for the generated Nimrod identifiers
|
||||
(multiple --prefix options are supported)
|
||||
--suffix:SUFFIX strip suffix for the generated Nimrod identifiers
|
||||
(multiple --suffix options are supported)
|
||||
--skipinclude do not convert ``#include`` to ``import``
|
||||
--typeprefixes generate ``T`` and ``P`` type prefixes
|
||||
--skipcomments do not copy comments
|
||||
--ignoreRValueRefs translate C++'s ``T&&`` to ``T`` instead ``of var T``
|
||||
--keepBodies keep C++'s method bodies
|
||||
--spliceHeader parse and emit header before source file
|
||||
-v, --version write c2nim's version
|
||||
-h, --help show this help
|
||||
"""
|
||||
|
||||
proc parse(infile: string, options: PParserOptions): PNode =
|
||||
var stream = llStreamOpen(infile, fmRead)
|
||||
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
||||
var p: TParser
|
||||
openParser(p, infile, stream, options)
|
||||
result = parseUnit(p)
|
||||
closeParser(p)
|
||||
|
||||
proc main(infile, outfile: string, options: PParserOptions, spliceHeader: bool) =
|
||||
var start = getTime()
|
||||
if spliceHeader and infile.splitFile.ext == ".c" and existsFile(infile.changeFileExt(".h")):
|
||||
var header_module = parse(infile.changeFileExt(".h"), options)
|
||||
var source_module = parse(infile, options)
|
||||
for n in source_module:
|
||||
addson(header_module, n)
|
||||
renderModule(header_module, outfile)
|
||||
else:
|
||||
renderModule(parse(infile, options), outfile)
|
||||
rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start),
|
||||
formatSize(getTotalMem())])
|
||||
|
||||
var
|
||||
infile = ""
|
||||
outfile = ""
|
||||
spliceHeader = false
|
||||
parserOptions = newParserOptions()
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
of cmdArgument: infile = key
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key.toLower
|
||||
of "help", "h":
|
||||
stdout.write(Usage)
|
||||
quit(0)
|
||||
of "version", "v":
|
||||
stdout.write(Version & "\n")
|
||||
quit(0)
|
||||
of "o", "out": outfile = val
|
||||
of "spliceheader": spliceHeader = true
|
||||
else:
|
||||
if not parserOptions.setOption(key, val):
|
||||
stdout.writeln("[Error] unknown option: " & key)
|
||||
of cmdEnd: assert(false)
|
||||
if infile.len == 0:
|
||||
# no filename has been given, so we show the help:
|
||||
stdout.write(Usage)
|
||||
else:
|
||||
if outfile.len == 0:
|
||||
outfile = changeFileExt(infile, "nim")
|
||||
infile = addFileExt(infile, "h")
|
||||
main(infile, outfile, parserOptions, spliceHeader)
|
||||
@@ -1,787 +0,0 @@
|
||||
#
|
||||
#
|
||||
# c2nim - C to Nimrod source converter
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# This module implements an Ansi C scanner. This is an adaption from
|
||||
# the scanner module. Keywords are not handled here, but in the parser to make
|
||||
# it more flexible.
|
||||
|
||||
|
||||
import
|
||||
options, msgs, strutils, platform, nimlexbase, llstream
|
||||
|
||||
const
|
||||
MaxLineLength* = 80 # lines longer than this lead to a warning
|
||||
numChars*: TCharSet = {'0'..'9', 'a'..'z', 'A'..'Z'}
|
||||
SymChars*: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
|
||||
SymStartChars*: TCharSet = {'a'..'z', 'A'..'Z', '_', '\x80'..'\xFF'}
|
||||
|
||||
type
|
||||
TTokKind* = enum
|
||||
pxInvalid, pxEof,
|
||||
pxMacroParam, # fake token: macro parameter (with its index)
|
||||
pxStarComment, # /* */ comment
|
||||
pxLineComment, # // comment
|
||||
pxDirective, # #define, etc.
|
||||
pxDirectiveParLe, # #define m( with parle (yes, C is that ugly!)
|
||||
pxDirConc, # ##
|
||||
pxNewLine, # newline: end of directive
|
||||
pxAmp, # &
|
||||
pxAmpAmp, # &&
|
||||
pxAmpAsgn, # &=
|
||||
pxAmpAmpAsgn, # &&=
|
||||
pxBar, # |
|
||||
pxBarBar, # ||
|
||||
pxBarAsgn, # |=
|
||||
pxBarBarAsgn, # ||=
|
||||
pxNot, # !
|
||||
pxPlusPlus, # ++
|
||||
pxMinusMinus, # --
|
||||
pxPlus, # +
|
||||
pxPlusAsgn, # +=
|
||||
pxMinus, # -
|
||||
pxMinusAsgn, # -=
|
||||
pxMod, # %
|
||||
pxModAsgn, # %=
|
||||
pxSlash, # /
|
||||
pxSlashAsgn, # /=
|
||||
pxStar, # *
|
||||
pxStarAsgn, # *=
|
||||
pxHat, # ^
|
||||
pxHatAsgn, # ^=
|
||||
pxAsgn, # =
|
||||
pxEquals, # ==
|
||||
pxDot, # .
|
||||
pxDotDotDot, # ...
|
||||
pxLe, # <=
|
||||
pxLt, # <
|
||||
pxGe, # >=
|
||||
pxGt, # >
|
||||
pxNeq, # !=
|
||||
pxConditional, # ?
|
||||
pxShl, # <<
|
||||
pxShlAsgn, # <<=
|
||||
pxShr, # >>
|
||||
pxShrAsgn, # >>=
|
||||
pxTilde, # ~
|
||||
pxTildeAsgn, # ~=
|
||||
pxArrow, # ->
|
||||
pxScope, # ::
|
||||
|
||||
pxStrLit,
|
||||
pxCharLit,
|
||||
pxSymbol, # a symbol
|
||||
pxIntLit,
|
||||
pxInt64Lit, # long constant like 0x70fffffff or out of int range
|
||||
pxFloatLit,
|
||||
pxParLe, pxBracketLe, pxCurlyLe, # this order is important
|
||||
pxParRi, pxBracketRi, pxCurlyRi, # for macro argument parsing!
|
||||
pxComma, pxSemiColon, pxColon,
|
||||
pxAngleRi # '>' but determined to be the end of a
|
||||
# template's angle bracket
|
||||
TTokKinds* = set[TTokKind]
|
||||
|
||||
type
|
||||
TNumericalBase* = enum base10, base2, base8, base16
|
||||
TToken* = object
|
||||
xkind*: TTokKind # the type of the token
|
||||
s*: string # parsed symbol, char or string literal
|
||||
iNumber*: BiggestInt # the parsed integer literal;
|
||||
# if xkind == pxMacroParam: parameter's position
|
||||
fNumber*: BiggestFloat # the parsed floating point literal
|
||||
base*: TNumericalBase # the numerical base; only valid for int
|
||||
# or float literals
|
||||
next*: ref TToken # for C we need arbitrary look-ahead :-(
|
||||
|
||||
TLexer* = object of TBaseLexer
|
||||
fileIdx*: int32
|
||||
inDirective: bool
|
||||
|
||||
proc getTok*(L: var TLexer, tok: var TToken)
|
||||
proc printTok*(tok: TToken)
|
||||
proc `$`*(tok: TToken): string
|
||||
# implementation
|
||||
|
||||
var
|
||||
gLinesCompiled*: int
|
||||
|
||||
proc fillToken(L: var TToken) =
|
||||
L.xkind = pxInvalid
|
||||
L.iNumber = 0
|
||||
L.s = ""
|
||||
L.fNumber = 0.0
|
||||
L.base = base10
|
||||
|
||||
proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream) =
|
||||
openBaseLexer(lex, inputstream)
|
||||
lex.fileIdx = filename.fileInfoIdx
|
||||
|
||||
proc closeLexer*(lex: var TLexer) =
|
||||
inc(gLinesCompiled, lex.LineNumber)
|
||||
closeBaseLexer(lex)
|
||||
|
||||
proc getColumn*(L: TLexer): int =
|
||||
result = getColNumber(L, L.bufPos)
|
||||
|
||||
proc getLineInfo*(L: TLexer): TLineInfo =
|
||||
result = newLineInfo(L.fileIdx, L.linenumber, getColNumber(L, L.bufpos))
|
||||
|
||||
proc lexMessage*(L: TLexer, msg: TMsgKind, arg = "") =
|
||||
msgs.GlobalError(getLineInfo(L), msg, arg)
|
||||
|
||||
proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||
var info = newLineInfo(L.fileIdx, L.linenumber, pos - L.lineStart)
|
||||
msgs.GlobalError(info, msg, arg)
|
||||
|
||||
proc tokKindToStr*(k: TTokKind): string =
|
||||
case k
|
||||
of pxEof: result = "[EOF]"
|
||||
of pxInvalid: result = "[invalid]"
|
||||
of pxMacroParam: result = "[macro param]"
|
||||
of pxStarComment, pxLineComment: result = "[comment]"
|
||||
of pxStrLit: result = "[string literal]"
|
||||
of pxCharLit: result = "[char literal]"
|
||||
|
||||
of pxDirective, pxDirectiveParLe: result = "#" # #define, etc.
|
||||
of pxDirConc: result = "##"
|
||||
of pxNewLine: result = "[NewLine]"
|
||||
of pxAmp: result = "&" # &
|
||||
of pxAmpAmp: result = "&&" # &&
|
||||
of pxAmpAsgn: result = "&=" # &=
|
||||
of pxAmpAmpAsgn: result = "&&=" # &&=
|
||||
of pxBar: result = "|" # |
|
||||
of pxBarBar: result = "||" # ||
|
||||
of pxBarAsgn: result = "|=" # |=
|
||||
of pxBarBarAsgn: result = "||=" # ||=
|
||||
of pxNot: result = "!" # !
|
||||
of pxPlusPlus: result = "++" # ++
|
||||
of pxMinusMinus: result = "--" # --
|
||||
of pxPlus: result = "+" # +
|
||||
of pxPlusAsgn: result = "+=" # +=
|
||||
of pxMinus: result = "-" # -
|
||||
of pxMinusAsgn: result = "-=" # -=
|
||||
of pxMod: result = "%" # %
|
||||
of pxModAsgn: result = "%=" # %=
|
||||
of pxSlash: result = "/" # /
|
||||
of pxSlashAsgn: result = "/=" # /=
|
||||
of pxStar: result = "*" # *
|
||||
of pxStarAsgn: result = "*=" # *=
|
||||
of pxHat: result = "^" # ^
|
||||
of pxHatAsgn: result = "^=" # ^=
|
||||
of pxAsgn: result = "=" # =
|
||||
of pxEquals: result = "==" # ==
|
||||
of pxDot: result = "." # .
|
||||
of pxDotDotDot: result = "..." # ...
|
||||
of pxLe: result = "<=" # <=
|
||||
of pxLt: result = "<" # <
|
||||
of pxGe: result = ">=" # >=
|
||||
of pxGt: result = ">" # >
|
||||
of pxNeq: result = "!=" # !=
|
||||
of pxConditional: result = "?"
|
||||
of pxShl: result = "<<"
|
||||
of pxShlAsgn: result = "<<="
|
||||
of pxShr: result = ">>"
|
||||
of pxShrAsgn: result = ">>="
|
||||
of pxTilde: result = "~"
|
||||
of pxTildeAsgn: result = "~="
|
||||
of pxArrow: result = "->"
|
||||
of pxScope: result = "::"
|
||||
|
||||
of pxSymbol: result = "[identifier]"
|
||||
of pxIntLit, pxInt64Lit: result = "[integer literal]"
|
||||
of pxFloatLit: result = "[floating point literal]"
|
||||
of pxParLe: result = "("
|
||||
of pxParRi: result = ")"
|
||||
of pxBracketLe: result = "["
|
||||
of pxBracketRi: result = "]"
|
||||
of pxComma: result = ","
|
||||
of pxSemiColon: result = ";"
|
||||
of pxColon: result = ":"
|
||||
of pxCurlyLe: result = "{"
|
||||
of pxCurlyRi: result = "}"
|
||||
of pxAngleRi: result = "> [end of template]"
|
||||
|
||||
proc `$`(tok: TToken): string =
|
||||
case tok.xkind
|
||||
of pxSymbol, pxInvalid, pxStarComment, pxLineComment, pxStrLit: result = tok.s
|
||||
of pxIntLit, pxInt64Lit: result = $tok.iNumber
|
||||
of pxFloatLit: result = $tok.fNumber
|
||||
else: result = tokKindToStr(tok.xkind)
|
||||
|
||||
proc printTok(tok: TToken) =
|
||||
writeln(stdout, $tok)
|
||||
|
||||
proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: TCharSet) =
|
||||
# matches ([chars]_)*
|
||||
var pos = L.bufpos # use registers for pos, buf
|
||||
var buf = L.buf
|
||||
while true:
|
||||
if buf[pos] in chars:
|
||||
add(tok.s, buf[pos])
|
||||
inc(pos)
|
||||
else:
|
||||
break
|
||||
if buf[pos] == '_':
|
||||
add(tok.s, '_')
|
||||
inc(pos)
|
||||
L.bufPos = pos
|
||||
|
||||
proc isFloatLiteral(s: string): bool =
|
||||
for i in countup(0, len(s)-1):
|
||||
if s[i] in {'.', 'e', 'E'}:
|
||||
return true
|
||||
|
||||
proc getNumber2(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 2 # skip 0b
|
||||
tok.base = base2
|
||||
var xi: BiggestInt = 0
|
||||
var bits = 0
|
||||
while true:
|
||||
case L.buf[pos]
|
||||
of 'A'..'Z', 'a'..'z':
|
||||
# ignore type suffix:
|
||||
inc(pos)
|
||||
of '2'..'9', '.':
|
||||
lexMessage(L, errInvalidNumber)
|
||||
inc(pos)
|
||||
of '_':
|
||||
inc(pos)
|
||||
of '0', '1':
|
||||
xi = `shl`(xi, 1) or (ord(L.buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
inc(bits)
|
||||
else: break
|
||||
tok.iNumber = xi
|
||||
if (bits > 32): tok.xkind = pxInt64Lit
|
||||
else: tok.xkind = pxIntLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getNumber8(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 1 # skip 0
|
||||
tok.base = base8
|
||||
var xi: BiggestInt = 0
|
||||
var bits = 0
|
||||
while true:
|
||||
case L.buf[pos]
|
||||
of 'A'..'Z', 'a'..'z':
|
||||
# ignore type suffix:
|
||||
inc(pos)
|
||||
of '8'..'9', '.':
|
||||
lexMessage(L, errInvalidNumber)
|
||||
inc(pos)
|
||||
of '_':
|
||||
inc(pos)
|
||||
of '0'..'7':
|
||||
xi = `shl`(xi, 3) or (ord(L.buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
inc(bits)
|
||||
else: break
|
||||
tok.iNumber = xi
|
||||
if (bits > 12): tok.xkind = pxInt64Lit
|
||||
else: tok.xkind = pxIntLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getNumber16(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 2 # skip 0x
|
||||
tok.base = base16
|
||||
var xi: BiggestInt = 0
|
||||
var bits = 0
|
||||
while true:
|
||||
case L.buf[pos]
|
||||
of 'G'..'Z', 'g'..'z':
|
||||
# ignore type suffix:
|
||||
inc(pos)
|
||||
of '_': inc(pos)
|
||||
of '0'..'9':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
of 'a'..'f':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('a') + 10)
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
of 'A'..'F':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('A') + 10)
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
else: break
|
||||
tok.iNumber = xi
|
||||
if bits > 32: tok.xkind = pxInt64Lit
|
||||
else: tok.xkind = pxIntLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getFloating(L: var TLexer, tok: var TToken) =
|
||||
matchUnderscoreChars(L, tok, {'0'..'9'})
|
||||
if L.buf[L.bufpos] in {'e', 'E'}:
|
||||
add(tok.s, L.buf[L.bufpos])
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] in {'+', '-'}:
|
||||
add(tok.s, L.buf[L.bufpos])
|
||||
inc(L.bufpos)
|
||||
matchUnderscoreChars(L, tok, {'0'..'9'})
|
||||
|
||||
proc getNumber(L: var TLexer, tok: var TToken) =
|
||||
tok.base = base10
|
||||
if L.buf[L.bufpos] == '.':
|
||||
add(tok.s, "0.")
|
||||
inc(L.bufpos)
|
||||
getFloating(L, tok)
|
||||
else:
|
||||
matchUnderscoreChars(L, tok, {'0'..'9'})
|
||||
if L.buf[L.bufpos] == '.':
|
||||
add(tok.s, '.')
|
||||
inc(L.bufpos)
|
||||
getFloating(L, tok)
|
||||
try:
|
||||
if isFloatLiteral(tok.s):
|
||||
tok.fnumber = parseFloat(tok.s)
|
||||
tok.xkind = pxFloatLit
|
||||
else:
|
||||
tok.iNumber = parseInt(tok.s)
|
||||
if (tok.iNumber < low(int32)) or (tok.iNumber > high(int32)):
|
||||
tok.xkind = pxInt64Lit
|
||||
else:
|
||||
tok.xkind = pxIntLit
|
||||
except EInvalidValue:
|
||||
lexMessage(L, errInvalidNumber, tok.s)
|
||||
except EOverflow:
|
||||
lexMessage(L, errNumberOutOfRange, tok.s)
|
||||
# ignore type suffix:
|
||||
while L.buf[L.bufpos] in {'A'..'Z', 'a'..'z'}: inc(L.bufpos)
|
||||
|
||||
proc handleCRLF(L: var TLexer, pos: int): int =
|
||||
case L.buf[pos]
|
||||
of CR: result = nimlexbase.handleCR(L, pos)
|
||||
of LF: result = nimlexbase.handleLF(L, pos)
|
||||
else: result = pos
|
||||
|
||||
proc escape(L: var TLexer, tok: var TToken, allowEmpty=false) =
|
||||
inc(L.bufpos) # skip \
|
||||
case L.buf[L.bufpos]
|
||||
of 'b', 'B':
|
||||
add(tok.s, '\b')
|
||||
inc(L.bufpos)
|
||||
of 't', 'T':
|
||||
add(tok.s, '\t')
|
||||
inc(L.bufpos)
|
||||
of 'n', 'N':
|
||||
add(tok.s, '\L')
|
||||
inc(L.bufpos)
|
||||
of 'f', 'F':
|
||||
add(tok.s, '\f')
|
||||
inc(L.bufpos)
|
||||
of 'r', 'R':
|
||||
add(tok.s, '\r')
|
||||
inc(L.bufpos)
|
||||
of '\'':
|
||||
add(tok.s, '\'')
|
||||
inc(L.bufpos)
|
||||
of '"':
|
||||
add(tok.s, '"')
|
||||
inc(L.bufpos)
|
||||
of '\\':
|
||||
add(tok.s, '\b')
|
||||
inc(L.bufpos)
|
||||
of '0'..'7':
|
||||
var xi = ord(L.buf[L.bufpos]) - ord('0')
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] in {'0'..'7'}:
|
||||
xi = (xi shl 3) or (ord(L.buf[L.bufpos]) - ord('0'))
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] in {'0'..'7'}:
|
||||
xi = (xi shl 3) or (ord(L.buf[L.bufpos]) - ord('0'))
|
||||
inc(L.bufpos)
|
||||
add(tok.s, chr(xi))
|
||||
of 'x':
|
||||
var xi = 0
|
||||
inc(L.bufpos)
|
||||
while true:
|
||||
case L.buf[L.bufpos]
|
||||
of '0'..'9':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[L.bufpos]) - ord('0'))
|
||||
inc(L.bufpos)
|
||||
of 'a'..'f':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[L.bufpos]) - ord('a') + 10)
|
||||
inc(L.bufpos)
|
||||
of 'A'..'F':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[L.bufpos]) - ord('A') + 10)
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
break
|
||||
add(tok.s, chr(xi))
|
||||
elif not allowEmpty:
|
||||
lexMessage(L, errInvalidCharacterConstant)
|
||||
|
||||
proc getCharLit(L: var TLexer, tok: var TToken) =
|
||||
inc(L.bufpos) # skip '
|
||||
if L.buf[L.bufpos] == '\\':
|
||||
escape(L, tok)
|
||||
else:
|
||||
add(tok.s, L.buf[L.bufpos])
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '\'':
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
lexMessage(L, errMissingFinalQuote)
|
||||
tok.xkind = pxCharLit
|
||||
|
||||
proc getString(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufPos + 1 # skip "
|
||||
var buf = L.buf # put `buf` in a register
|
||||
var line = L.linenumber # save linenumber for better error message
|
||||
while true:
|
||||
case buf[pos]
|
||||
of '\"':
|
||||
inc(pos)
|
||||
break
|
||||
of CR:
|
||||
pos = nimlexbase.HandleCR(L, pos)
|
||||
buf = L.buf
|
||||
of LF:
|
||||
pos = nimlexbase.HandleLF(L, pos)
|
||||
buf = L.buf
|
||||
of nimlexbase.EndOfFile:
|
||||
var line2 = L.linenumber
|
||||
L.LineNumber = line
|
||||
lexMessagePos(L, errClosingQuoteExpected, L.lineStart)
|
||||
L.LineNumber = line2
|
||||
break
|
||||
of '\\':
|
||||
# we allow an empty \ for line concatenation, but we don't require it
|
||||
# for line concatenation
|
||||
L.bufpos = pos
|
||||
escape(L, tok, allowEmpty=true)
|
||||
pos = L.bufpos
|
||||
else:
|
||||
add(tok.s, buf[pos])
|
||||
inc(pos)
|
||||
L.bufpos = pos
|
||||
tok.xkind = pxStrLit
|
||||
|
||||
proc getSymbol(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
while true:
|
||||
var c = buf[pos]
|
||||
if c notin SymChars: break
|
||||
add(tok.s, c)
|
||||
inc(pos)
|
||||
L.bufpos = pos
|
||||
tok.xkind = pxSymbol
|
||||
|
||||
proc scanLineComment(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
# a comment ends if the next line does not start with the // on the same
|
||||
# column after only whitespace
|
||||
tok.xkind = pxLineComment
|
||||
var col = getColNumber(L, pos)
|
||||
while true:
|
||||
inc(pos, 2) # skip //
|
||||
add(tok.s, '#')
|
||||
while not (buf[pos] in {CR, LF, nimlexbase.EndOfFile}):
|
||||
add(tok.s, buf[pos])
|
||||
inc(pos)
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
var indent = 0
|
||||
while buf[pos] == ' ':
|
||||
inc(pos)
|
||||
inc(indent)
|
||||
if (col == indent) and (buf[pos] == '/') and (buf[pos + 1] == '/'):
|
||||
add(tok.s, "\n")
|
||||
else:
|
||||
break
|
||||
L.bufpos = pos
|
||||
|
||||
proc scanStarComment(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
tok.s = "#"
|
||||
tok.xkind = pxStarComment
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR, LF:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
add(tok.s, "\n#")
|
||||
# skip annoying stars as line prefix: (eg.
|
||||
# /*
|
||||
# * ugly comment <-- this star
|
||||
# */
|
||||
while buf[pos] in {' ', '\t'}:
|
||||
add(tok.s, ' ')
|
||||
inc(pos)
|
||||
if buf[pos] == '*' and buf[pos+1] != '/': inc(pos)
|
||||
of '*':
|
||||
inc(pos)
|
||||
if buf[pos] == '/':
|
||||
inc(pos)
|
||||
break
|
||||
else:
|
||||
add(tok.s, '*')
|
||||
of nimlexbase.EndOfFile:
|
||||
lexMessage(L, errTokenExpected, "*/")
|
||||
else:
|
||||
add(tok.s, buf[pos])
|
||||
inc(pos)
|
||||
L.bufpos = pos
|
||||
|
||||
proc skip(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
while true:
|
||||
case buf[pos]
|
||||
of '\\':
|
||||
# Ignore \ line continuation characters when not inDirective
|
||||
inc(pos)
|
||||
if L.inDirective:
|
||||
while buf[pos] in {' ', '\t'}: inc(pos)
|
||||
if buf[pos] in {CR, LF}:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
of ' ', Tabulator:
|
||||
inc(pos) # newline is special:
|
||||
of CR, LF:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
if L.inDirective:
|
||||
tok.xkind = pxNewLine
|
||||
L.inDirective = false
|
||||
else:
|
||||
break # EndOfFile also leaves the loop
|
||||
L.bufpos = pos
|
||||
|
||||
proc getDirective(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 1
|
||||
var buf = L.buf
|
||||
while buf[pos] in {' ', '\t'}: inc(pos)
|
||||
while buf[pos] in SymChars:
|
||||
add(tok.s, buf[pos])
|
||||
inc(pos)
|
||||
# a HACK: we need to distinguish
|
||||
# #define x (...)
|
||||
# from:
|
||||
# #define x(...)
|
||||
#
|
||||
L.bufpos = pos
|
||||
# look ahead:
|
||||
while buf[pos] in {' ', '\t'}: inc(pos)
|
||||
while buf[pos] in SymChars: inc(pos)
|
||||
if buf[pos] == '(': tok.xkind = pxDirectiveParLe
|
||||
else: tok.xkind = pxDirective
|
||||
L.inDirective = true
|
||||
|
||||
proc getTok(L: var TLexer, tok: var TToken) =
|
||||
tok.xkind = pxInvalid
|
||||
fillToken(tok)
|
||||
skip(L, tok)
|
||||
if tok.xkind == pxNewLine: return
|
||||
var c = L.buf[L.bufpos]
|
||||
if c in SymStartChars:
|
||||
getSymbol(L, tok)
|
||||
elif c == '0':
|
||||
case L.buf[L.bufpos+1]
|
||||
of 'x', 'X': getNumber16(L, tok)
|
||||
of 'b', 'B': getNumber2(L, tok)
|
||||
of '1'..'7': getNumber8(L, tok)
|
||||
else: getNumber(L, tok)
|
||||
elif c in {'1'..'9'} or (c == '.' and L.buf[L.bufpos+1] in {'0'..'9'}):
|
||||
getNumber(L, tok)
|
||||
else:
|
||||
case c
|
||||
of ';':
|
||||
tok.xkind = pxSemicolon
|
||||
inc(L.bufpos)
|
||||
of '/':
|
||||
if L.buf[L.bufpos + 1] == '/':
|
||||
scanLineComment(L, tok)
|
||||
elif L.buf[L.bufpos+1] == '*':
|
||||
inc(L.bufpos, 2)
|
||||
scanStarComment(L, tok)
|
||||
elif L.buf[L.bufpos+1] == '=':
|
||||
inc(L.bufpos, 2)
|
||||
tok.xkind = pxSlashAsgn
|
||||
else:
|
||||
tok.xkind = pxSlash
|
||||
inc(L.bufpos)
|
||||
of ',':
|
||||
tok.xkind = pxComma
|
||||
inc(L.bufpos)
|
||||
of '(':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxParLe
|
||||
of '*':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxStarAsgn
|
||||
else:
|
||||
tok.xkind = pxStar
|
||||
of ')':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxParRi
|
||||
of '[':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxBracketLe
|
||||
of ']':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxBracketRi
|
||||
of '.':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '.' and L.buf[L.bufpos+1] == '.':
|
||||
tok.xkind = pxDotDotDot
|
||||
inc(L.bufpos, 2)
|
||||
else:
|
||||
tok.xkind = pxDot
|
||||
of '{':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxCurlyLe
|
||||
of '}':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxCurlyRi
|
||||
of '+':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxPlusAsgn
|
||||
inc(L.bufpos)
|
||||
elif L.buf[L.bufpos] == '+':
|
||||
tok.xkind = pxPlusPlus
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxPlus
|
||||
of '-':
|
||||
inc(L.bufpos)
|
||||
case L.buf[L.bufpos]
|
||||
of '>':
|
||||
tok.xkind = pxArrow
|
||||
inc(L.bufpos)
|
||||
of '=':
|
||||
tok.xkind = pxMinusAsgn
|
||||
inc(L.bufpos)
|
||||
of '-':
|
||||
tok.xkind = pxMinusMinus
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxMinus
|
||||
of '?':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxConditional
|
||||
of ':':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == ':':
|
||||
tok.xkind = pxScope
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxColon
|
||||
of '!':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxNeq
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxNot
|
||||
of '<':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxLe
|
||||
elif L.buf[L.bufpos] == '<':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxShlAsgn
|
||||
else:
|
||||
tok.xkind = pxShl
|
||||
else:
|
||||
tok.xkind = pxLt
|
||||
of '>':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxGe
|
||||
elif L.buf[L.bufpos] == '>':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxShrAsgn
|
||||
else:
|
||||
tok.xkind = pxShr
|
||||
else:
|
||||
tok.xkind = pxGt
|
||||
of '=':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxEquals
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxAsgn
|
||||
of '&':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxAmpAsgn
|
||||
inc(L.bufpos)
|
||||
elif L.buf[L.bufpos] == '&':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxAmpAmpAsgn
|
||||
else:
|
||||
tok.xkind = pxAmpAmp
|
||||
else:
|
||||
tok.xkind = pxAmp
|
||||
of '|':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxBarAsgn
|
||||
inc(L.bufpos)
|
||||
elif L.buf[L.bufpos] == '|':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxBarBarAsgn
|
||||
else:
|
||||
tok.xkind = pxBarBar
|
||||
else:
|
||||
tok.xkind = pxBar
|
||||
of '^':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxHatAsgn
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxHat
|
||||
of '%':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxModAsgn
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxMod
|
||||
of '~':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
tok.xkind = pxTildeAsgn
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxTilde
|
||||
of '#':
|
||||
if L.buf[L.bufpos+1] == '#':
|
||||
inc(L.bufpos, 2)
|
||||
tok.xkind = pxDirConc
|
||||
else:
|
||||
getDirective(L, tok)
|
||||
of '"': getString(L, tok)
|
||||
of '\'': getCharLit(L, tok)
|
||||
of nimlexbase.EndOfFile:
|
||||
tok.xkind = pxEof
|
||||
else:
|
||||
tok.s = $c
|
||||
tok.xkind = pxInvalid
|
||||
lexMessage(L, errInvalidToken, c & " (\\" & $(ord(c)) & ')')
|
||||
inc(L.bufpos)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,347 +0,0 @@
|
||||
#
|
||||
#
|
||||
# c2nim - C to Nimrod source converter
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# Preprocessor support
|
||||
|
||||
const
|
||||
c2nimSymbol = "C2NIM"
|
||||
|
||||
proc eatNewLine(p: var TParser, n: PNode) =
|
||||
if p.tok.xkind == pxLineComment:
|
||||
skipCom(p, n)
|
||||
if p.tok.xkind == pxNewLine: getTok(p)
|
||||
elif p.tok.xkind == pxNewLine:
|
||||
eat(p, pxNewLine)
|
||||
|
||||
proc skipLine(p: var TParser) =
|
||||
while p.tok.xkind notin {pxEof, pxNewLine, pxLineComment}: getTok(p)
|
||||
eatNewLine(p, nil)
|
||||
|
||||
proc parseDefineBody(p: var TParser, tmplDef: PNode): string =
|
||||
if p.tok.xkind == pxCurlyLe or
|
||||
(p.tok.xkind == pxSymbol and (
|
||||
declKeyword(p, p.tok.s) or stmtKeyword(p.tok.s))):
|
||||
addSon(tmplDef, statement(p))
|
||||
result = "stmt"
|
||||
elif p.tok.xkind in {pxLineComment, pxNewLine}:
|
||||
addSon(tmplDef, buildStmtList(newNodeP(nkNilLit, p)))
|
||||
result = "stmt"
|
||||
else:
|
||||
addSon(tmplDef, buildStmtList(expression(p)))
|
||||
result = "expr"
|
||||
|
||||
proc parseDefine(p: var TParser): PNode =
|
||||
if p.tok.xkind == pxDirectiveParLe:
|
||||
# a macro with parameters:
|
||||
result = newNodeP(nkTemplateDef, p)
|
||||
getTok(p)
|
||||
addSon(result, skipIdentExport(p))
|
||||
addSon(result, ast.emptyNode)
|
||||
eat(p, pxParLe)
|
||||
var params = newNodeP(nkFormalParams, p)
|
||||
# return type; not known yet:
|
||||
addSon(params, ast.emptyNode)
|
||||
if p.tok.xkind != pxParRi:
|
||||
var identDefs = newNodeP(nkIdentDefs, p)
|
||||
while p.tok.xkind != pxParRi:
|
||||
addSon(identDefs, skipIdent(p))
|
||||
skipStarCom(p, nil)
|
||||
if p.tok.xkind != pxComma: break
|
||||
getTok(p)
|
||||
addSon(identDefs, newIdentNodeP("expr", p))
|
||||
addSon(identDefs, ast.emptyNode)
|
||||
addSon(params, identDefs)
|
||||
eat(p, pxParRi)
|
||||
|
||||
addSon(result, ast.emptyNode) # no generic parameters
|
||||
addSon(result, params)
|
||||
addSon(result, ast.emptyNode) # no pragmas
|
||||
addSon(result, ast.emptyNode)
|
||||
var kind = parseDefineBody(p, result)
|
||||
params.sons[0] = newIdentNodeP(kind, p)
|
||||
eatNewLine(p, result)
|
||||
else:
|
||||
# a macro without parameters:
|
||||
result = newNodeP(nkConstSection, p)
|
||||
while p.tok.xkind == pxDirective and p.tok.s == "define":
|
||||
getTok(p) # skip #define
|
||||
var c = newNodeP(nkConstDef, p)
|
||||
addSon(c, skipIdentExport(p))
|
||||
addSon(c, ast.emptyNode)
|
||||
skipStarCom(p, c)
|
||||
if p.tok.xkind in {pxLineComment, pxNewLine, pxEof}:
|
||||
addSon(c, newIdentNodeP("true", p))
|
||||
else:
|
||||
addSon(c, expression(p))
|
||||
addSon(result, c)
|
||||
eatNewLine(p, c)
|
||||
assert result != nil
|
||||
|
||||
proc parseDefBody(p: var TParser, m: var TMacro, params: seq[string]) =
|
||||
m.body = @[]
|
||||
# A little hack: We safe the context, so that every following token will be
|
||||
# put into a newly allocated TToken object. Thus we can just save a
|
||||
# reference to the token in the macro's body.
|
||||
saveContext(p)
|
||||
while p.tok.xkind notin {pxEof, pxNewLine, pxLineComment}:
|
||||
case p.tok.xkind
|
||||
of pxSymbol:
|
||||
# is it a parameter reference?
|
||||
var tok = p.tok
|
||||
for i in 0..high(params):
|
||||
if params[i] == p.tok.s:
|
||||
new(tok)
|
||||
tok.xkind = pxMacroParam
|
||||
tok.iNumber = i
|
||||
break
|
||||
m.body.add(tok)
|
||||
of pxDirConc:
|
||||
# just ignore this token: this implements token merging correctly
|
||||
discard
|
||||
else:
|
||||
m.body.add(p.tok)
|
||||
# we do not want macro expansion here:
|
||||
rawGetTok(p)
|
||||
eatNewLine(p, nil)
|
||||
closeContext(p)
|
||||
# newline token might be overwritten, but this is not
|
||||
# part of the macro body, so it is safe.
|
||||
|
||||
proc parseDef(p: var TParser, m: var TMacro) =
|
||||
var hasParams = p.tok.xkind == pxDirectiveParLe
|
||||
getTok(p)
|
||||
expectIdent(p)
|
||||
m.name = p.tok.s
|
||||
getTok(p)
|
||||
var params: seq[string] = @[]
|
||||
# parse parameters:
|
||||
if hasParams:
|
||||
eat(p, pxParLe)
|
||||
while p.tok.xkind != pxParRi:
|
||||
expectIdent(p)
|
||||
params.add(p.tok.s)
|
||||
getTok(p)
|
||||
skipStarCom(p, nil)
|
||||
if p.tok.xkind != pxComma: break
|
||||
getTok(p)
|
||||
eat(p, pxParRi)
|
||||
m.params = params.len
|
||||
parseDefBody(p, m, params)
|
||||
|
||||
proc isDir(p: TParser, dir: string): bool =
|
||||
result = p.tok.xkind in {pxDirectiveParLe, pxDirective} and p.tok.s == dir
|
||||
|
||||
proc parseInclude(p: var TParser): PNode =
|
||||
result = newNodeP(nkImportStmt, p)
|
||||
while isDir(p, "include"):
|
||||
getTok(p) # skip "include"
|
||||
if p.tok.xkind == pxStrLit and pfSkipInclude notin p.options.flags:
|
||||
var file = newStrNodeP(nkStrLit, changeFileExt(p.tok.s, ""), p)
|
||||
addSon(result, file)
|
||||
getTok(p)
|
||||
skipStarCom(p, file)
|
||||
eatNewLine(p, nil)
|
||||
else:
|
||||
skipLine(p)
|
||||
if sonsLen(result) == 0:
|
||||
# we only parsed includes that we chose to ignore:
|
||||
result = ast.emptyNode
|
||||
|
||||
proc definedExprAux(p: var TParser): PNode =
|
||||
result = newNodeP(nkCall, p)
|
||||
addSon(result, newIdentNodeP("defined", p))
|
||||
addSon(result, skipIdent(p))
|
||||
|
||||
proc parseStmtList(p: var TParser): PNode =
|
||||
result = newNodeP(nkStmtList, p)
|
||||
while true:
|
||||
case p.tok.xkind
|
||||
of pxEof: break
|
||||
of pxDirectiveParLe, pxDirective:
|
||||
case p.tok.s
|
||||
of "else", "endif", "elif": break
|
||||
else: discard
|
||||
addSon(result, statement(p))
|
||||
|
||||
proc eatEndif(p: var TParser) =
|
||||
if isDir(p, "endif"):
|
||||
skipLine(p)
|
||||
else:
|
||||
parMessage(p, errXExpected, "#endif")
|
||||
|
||||
proc parseIfDirAux(p: var TParser, result: PNode) =
|
||||
addSon(result.sons[0], parseStmtList(p))
|
||||
while isDir(p, "elif"):
|
||||
var b = newNodeP(nkElifBranch, p)
|
||||
getTok(p)
|
||||
addSon(b, expression(p))
|
||||
eatNewLine(p, nil)
|
||||
addSon(b, parseStmtList(p))
|
||||
addSon(result, b)
|
||||
if isDir(p, "else"):
|
||||
var s = newNodeP(nkElse, p)
|
||||
skipLine(p)
|
||||
addSon(s, parseStmtList(p))
|
||||
addSon(result, s)
|
||||
eatEndif(p)
|
||||
|
||||
proc skipUntilEndif(p: var TParser) =
|
||||
var nested = 1
|
||||
while p.tok.xkind != pxEof:
|
||||
if isDir(p, "ifdef") or isDir(p, "ifndef") or isDir(p, "if"):
|
||||
inc(nested)
|
||||
elif isDir(p, "endif"):
|
||||
dec(nested)
|
||||
if nested <= 0:
|
||||
skipLine(p)
|
||||
return
|
||||
getTok(p)
|
||||
parMessage(p, errXExpected, "#endif")
|
||||
|
||||
type
|
||||
TEndifMarker = enum
|
||||
emElif, emElse, emEndif
|
||||
|
||||
proc skipUntilElifElseEndif(p: var TParser): TEndifMarker =
|
||||
var nested = 1
|
||||
while p.tok.xkind != pxEof:
|
||||
if isDir(p, "ifdef") or isDir(p, "ifndef") or isDir(p, "if"):
|
||||
inc(nested)
|
||||
elif isDir(p, "elif") and nested <= 1:
|
||||
return emElif
|
||||
elif isDir(p, "else") and nested <= 1:
|
||||
return emElse
|
||||
elif isDir(p, "endif"):
|
||||
dec(nested)
|
||||
if nested <= 0:
|
||||
return emEndif
|
||||
getTok(p)
|
||||
parMessage(p, errXExpected, "#endif")
|
||||
|
||||
proc parseIfdef(p: var TParser): PNode =
|
||||
getTok(p) # skip #ifdef
|
||||
expectIdent(p)
|
||||
case p.tok.s
|
||||
of "__cplusplus":
|
||||
skipUntilEndif(p)
|
||||
result = ast.emptyNode
|
||||
of c2nimSymbol:
|
||||
skipLine(p)
|
||||
result = parseStmtList(p)
|
||||
skipUntilEndif(p)
|
||||
else:
|
||||
result = newNodeP(nkWhenStmt, p)
|
||||
addSon(result, newNodeP(nkElifBranch, p))
|
||||
addSon(result.sons[0], definedExprAux(p))
|
||||
eatNewLine(p, nil)
|
||||
parseIfDirAux(p, result)
|
||||
|
||||
proc parseIfndef(p: var TParser): PNode =
|
||||
result = ast.emptyNode
|
||||
getTok(p) # skip #ifndef
|
||||
expectIdent(p)
|
||||
if p.tok.s == c2nimSymbol:
|
||||
skipLine(p)
|
||||
case skipUntilElifElseEndif(p)
|
||||
of emElif:
|
||||
result = newNodeP(nkWhenStmt, p)
|
||||
addSon(result, newNodeP(nkElifBranch, p))
|
||||
getTok(p)
|
||||
addSon(result.sons[0], expression(p))
|
||||
eatNewLine(p, nil)
|
||||
parseIfDirAux(p, result)
|
||||
of emElse:
|
||||
skipLine(p)
|
||||
result = parseStmtList(p)
|
||||
eatEndif(p)
|
||||
of emEndif: skipLine(p)
|
||||
else:
|
||||
result = newNodeP(nkWhenStmt, p)
|
||||
addSon(result, newNodeP(nkElifBranch, p))
|
||||
var e = newNodeP(nkCall, p)
|
||||
addSon(e, newIdentNodeP("not", p))
|
||||
addSon(e, definedExprAux(p))
|
||||
eatNewLine(p, nil)
|
||||
addSon(result.sons[0], e)
|
||||
parseIfDirAux(p, result)
|
||||
|
||||
proc parseIfDir(p: var TParser): PNode =
|
||||
result = newNodeP(nkWhenStmt, p)
|
||||
addSon(result, newNodeP(nkElifBranch, p))
|
||||
getTok(p)
|
||||
addSon(result.sons[0], expression(p))
|
||||
eatNewLine(p, nil)
|
||||
parseIfDirAux(p, result)
|
||||
|
||||
proc parsePegLit(p: var TParser): TPeg =
|
||||
var col = getColumn(p.lex) + 2
|
||||
getTok(p)
|
||||
if p.tok.xkind != pxStrLit: expectIdent(p)
|
||||
try:
|
||||
result = parsePeg(
|
||||
pattern = if p.tok.xkind == pxStrLit: p.tok.s else: escapePeg(p.tok.s),
|
||||
filename = p.lex.fileIdx.toFilename,
|
||||
line = p.lex.linenumber,
|
||||
col = col)
|
||||
getTok(p)
|
||||
except EInvalidPeg:
|
||||
parMessage(p, errUser, getCurrentExceptionMsg())
|
||||
|
||||
proc parseMangleDir(p: var TParser) =
|
||||
var pattern = parsePegLit(p)
|
||||
if p.tok.xkind != pxStrLit: expectIdent(p)
|
||||
p.options.mangleRules.add((pattern, p.tok.s))
|
||||
getTok(p)
|
||||
eatNewLine(p, nil)
|
||||
|
||||
proc modulePragmas(p: var TParser): PNode =
|
||||
if p.options.dynlibSym.len > 0 and not p.hasDeadCodeElimPragma:
|
||||
p.hasDeadCodeElimPragma = true
|
||||
result = newNodeP(nkPragma, p)
|
||||
var e = newNodeP(nkExprColonExpr, p)
|
||||
addSon(e, newIdentNodeP("deadCodeElim", p), newIdentNodeP("on", p))
|
||||
addSon(result, e)
|
||||
else:
|
||||
result = ast.emptyNode
|
||||
|
||||
proc parseDir(p: var TParser): PNode =
|
||||
result = ast.emptyNode
|
||||
assert(p.tok.xkind in {pxDirective, pxDirectiveParLe})
|
||||
case p.tok.s
|
||||
of "define": result = parseDefine(p)
|
||||
of "include": result = parseInclude(p)
|
||||
of "ifdef": result = parseIfdef(p)
|
||||
of "ifndef": result = parseIfndef(p)
|
||||
of "if": result = parseIfDir(p)
|
||||
of "cdecl", "stdcall", "ref", "skipinclude", "typeprefixes", "skipcomments":
|
||||
discard setOption(p.options, p.tok.s)
|
||||
getTok(p)
|
||||
eatNewLine(p, nil)
|
||||
of "dynlib", "header", "prefix", "suffix", "class":
|
||||
var key = p.tok.s
|
||||
getTok(p)
|
||||
if p.tok.xkind != pxStrLit: expectIdent(p)
|
||||
discard setOption(p.options, key, p.tok.s)
|
||||
getTok(p)
|
||||
eatNewLine(p, nil)
|
||||
result = modulePragmas(p)
|
||||
of "mangle":
|
||||
parseMangleDir(p)
|
||||
of "def":
|
||||
var L = p.options.macros.len
|
||||
setLen(p.options.macros, L+1)
|
||||
parseDef(p, p.options.macros[L])
|
||||
of "private":
|
||||
var pattern = parsePegLit(p)
|
||||
p.options.privateRules.add(pattern)
|
||||
eatNewLine(p, nil)
|
||||
else:
|
||||
# ignore unimportant/unknown directive ("undef", "pragma", "error")
|
||||
skipLine(p)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
# Use the modules of the compiler
|
||||
|
||||
path: "$nimrod/compiler"
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
|
||||
enum vehicles
|
||||
{
|
||||
car = 0x10,
|
||||
truck,
|
||||
boat = 0x01,
|
||||
ship = 1,
|
||||
speedboat = 1,
|
||||
bicycle = 4,
|
||||
bobycar
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
red = 4,
|
||||
green = 2,
|
||||
blue
|
||||
};
|
||||
|
||||
typedef enum food
|
||||
{
|
||||
bread = 4,
|
||||
toast = 4,
|
||||
bun = 0x04,
|
||||
cucumber = 2,
|
||||
chocolate = 6
|
||||
};
|
||||
|
||||
typedef enum numbers
|
||||
{
|
||||
one = 1,
|
||||
two,
|
||||
nten = - 10,
|
||||
nnine,
|
||||
four = 4,
|
||||
three = + 3,
|
||||
positivenine = + 9,
|
||||
nfour = - 4,
|
||||
negativeten = -10
|
||||
};
|
||||
@@ -1,240 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/matrix.h
|
||||
// Purpose: wxTransformMatrix class. NOT YET USED
|
||||
// Author: Chris Breeze, Julian Smart
|
||||
// Modified by: Klaas Holwerda
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart, Chris Breeze
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_MATRIXH__
|
||||
#define _WX_MATRIXH__
|
||||
|
||||
//! headerfiles="matrix.h wx/object.h"
|
||||
#include "wx/object.h"
|
||||
#include "wx/math.h"
|
||||
|
||||
//! codefiles="matrix.cpp"
|
||||
|
||||
// A simple 3x3 matrix. This may be replaced by a more general matrix
|
||||
// class some day.
|
||||
//
|
||||
// Note: this is intended to be used in wxDC at some point to replace
|
||||
// the current system of scaling/translation. It is not yet used.
|
||||
|
||||
#def WXDLLIMPEXP_CORE
|
||||
#header "wxmatrix.h"
|
||||
|
||||
//:definition
|
||||
// A 3x3 matrix to do 2D transformations.
|
||||
// It can be used to map data to window coordinates,
|
||||
// and also for manipulating your own data.
|
||||
// For example drawing a picture (composed of several primitives)
|
||||
// at a certain coordinate and angle within another parent picture.
|
||||
// At all times m_isIdentity is set if the matrix itself is an Identity matrix.
|
||||
// It is used where possible to optimize calculations.
|
||||
class WXDLLIMPEXP_CORE wxTransformMatrix: public wxObject<string, string<ubyte>>
|
||||
{
|
||||
public:
|
||||
wxTransformMatrix(void);
|
||||
wxTransformMatrix(const wxTransformMatrix& mat);
|
||||
|
||||
~wxTransformMatrix(void);
|
||||
|
||||
//get the value in the matrix at col,row
|
||||
//rows are horizontal (second index of m_matrix member)
|
||||
//columns are vertical (first index of m_matrix member)
|
||||
double GetValue(int col, int row) const;
|
||||
|
||||
//set the value in the matrix at col,row
|
||||
//rows are horizontal (second index of m_matrix member)
|
||||
//columns are vertical (first index of m_matrix member)
|
||||
void SetValue(int col, int row, double value);
|
||||
|
||||
void operator = (const wxTransformMatrix& mat);
|
||||
bool operator == (const wxTransformMatrix& mat) const;
|
||||
bool operator != (const module::gah::wxTransformMatrix& mat) const;
|
||||
|
||||
//multiply every element by t
|
||||
wxTransformMatrix& operator*=(const double& t);
|
||||
//divide every element by t
|
||||
wxTransformMatrix& operator/=(const double& t);
|
||||
//add matrix m to this t
|
||||
wxTransformMatrix& operator+=(const wxTransformMatrix& m);
|
||||
//subtract matrix m from this
|
||||
wxTransformMatrix& operator-=(const wxTransformMatrix& m);
|
||||
//multiply matrix m with this
|
||||
wxTransformMatrix& operator*=(const wxTransformMatrix& m);
|
||||
|
||||
// constant operators
|
||||
|
||||
//multiply every element by t and return result
|
||||
wxTransformMatrix operator*(const double& t) const;
|
||||
//divide this matrix by t and return result
|
||||
wxTransformMatrix operator/(const double& t) const;
|
||||
//add matrix m to this and return result
|
||||
wxTransformMatrix operator+(const wxTransformMatrix& m) const;
|
||||
//subtract matrix m from this and return result
|
||||
wxTransformMatrix operator-(const wxTransformMatrix& m) const;
|
||||
//multiply this by matrix m and return result
|
||||
wxTransformMatrix operator*(const wxTransformMatrix& m) const;
|
||||
wxTransformMatrix operator-() const;
|
||||
|
||||
//rows are horizontal (second index of m_matrix member)
|
||||
//columns are vertical (first index of m_matrix member)
|
||||
double& operator()(int col, int row);
|
||||
|
||||
//rows are horizontal (second index of m_matrix member)
|
||||
//columns are vertical (first index of m_matrix member)
|
||||
double operator()(int col, int row) const;
|
||||
|
||||
// Invert matrix
|
||||
bool Invert(void);
|
||||
|
||||
// Make into identity matrix
|
||||
bool Identity(void);
|
||||
|
||||
// Is the matrix the identity matrix?
|
||||
// Only returns a flag, which is set whenever an operation
|
||||
// is done.
|
||||
inline bool IsIdentity(void) const { return m_isIdentity; }
|
||||
|
||||
// This does an actual check.
|
||||
inline bool IsIdentity1(void) const ;
|
||||
|
||||
//Scale by scale (isotropic scaling i.e. the same in x and y):
|
||||
//!ex:
|
||||
//!code: | scale 0 0 |
|
||||
//!code: matrix' = | 0 scale 0 | x matrix
|
||||
//!code: | 0 0 scale |
|
||||
bool Scale(double scale);
|
||||
|
||||
//Scale with center point and x/y scale
|
||||
//
|
||||
//!ex:
|
||||
//!code: | xs 0 xc(1-xs) |
|
||||
//!code: matrix' = | 0 ys yc(1-ys) | x matrix
|
||||
//!code: | 0 0 1 |
|
||||
wxTransformMatrix& Scale(const double &xs, const double &ys,const double &xc, const double &yc);
|
||||
|
||||
// mirror a matrix in x, y
|
||||
//!ex:
|
||||
//!code: | -1 0 0 |
|
||||
//!code: matrix' = | 0 -1 0 | x matrix
|
||||
//!code: | 0 0 1 |
|
||||
wxTransformMatrix<float>& Mirror(bool x=true, bool y=false);
|
||||
// Translate by dx, dy:
|
||||
//!ex:
|
||||
//!code: | 1 0 dx |
|
||||
//!code: matrix' = | 0 1 dy | x matrix
|
||||
//!code: | 0 0 1 |
|
||||
bool Translate(double x, double y);
|
||||
|
||||
// Rotate clockwise by the given number of degrees:
|
||||
//!ex:
|
||||
//!code: | cos sin 0 |
|
||||
//!code: matrix' = | -sin cos 0 | x matrix
|
||||
//!code: | 0 0 1 |
|
||||
bool Rotate(double angle);
|
||||
|
||||
//Rotate counter clockwise with point of rotation
|
||||
//
|
||||
//!ex:
|
||||
//!code: | cos(r) -sin(r) x(1-cos(r))+y(sin(r)|
|
||||
//!code: matrix' = | sin(r) cos(r) y(1-cos(r))-x(sin(r)| x matrix
|
||||
//!code: | 0 0 1 |
|
||||
wxTransformMatrix& Rotate(const double &r, const double &x, const double &y);
|
||||
|
||||
// Transform X value from logical to device
|
||||
inline double TransformX(double x) const;
|
||||
|
||||
// Transform Y value from logical to device
|
||||
inline double TransformY(double y) const;
|
||||
|
||||
// Transform a point from logical to device coordinates
|
||||
bool TransformPoint(double x, double y, double& tx, double& ty) const;
|
||||
|
||||
// Transform a point from device to logical coordinates.
|
||||
// Example of use:
|
||||
// wxTransformMatrix mat = dc.GetTransformation();
|
||||
// mat.Invert();
|
||||
// mat.InverseTransformPoint(x, y, x1, y1);
|
||||
// OR (shorthand:)
|
||||
// dc.LogicalToDevice(x, y, x1, y1);
|
||||
// The latter is slightly less efficient if we're doing several
|
||||
// conversions, since the matrix is inverted several times.
|
||||
// N.B. 'this' matrix is the inverse at this point
|
||||
bool InverseTransformPoint(double x, double y, double& tx, double& ty) const;
|
||||
|
||||
double Get_scaleX();
|
||||
double Get_scaleY();
|
||||
double GetRotation();
|
||||
void SetRotation(double rotation);
|
||||
|
||||
|
||||
public:
|
||||
double m_matrix[3][3];
|
||||
bool m_isIdentity;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Chris Breeze reported, that
|
||||
some functions of wxTransformMatrix cannot work because it is not
|
||||
known if he matrix has been inverted. Be careful when using it.
|
||||
*/
|
||||
|
||||
// Transform X value from logical to device
|
||||
// warning: this function can only be used for this purpose
|
||||
// because no rotation is involved when mapping logical to device coordinates
|
||||
// mirror and scaling for x and y will be part of the matrix
|
||||
// if you have a matrix that is rotated, eg a shape containing a matrix to place
|
||||
// it in the logical coordinate system, use TransformPoint
|
||||
inline double wxTransformMatrix::TransformX(double x) const
|
||||
{
|
||||
//normally like this, but since no rotation is involved (only mirror and scale)
|
||||
//we can do without Y -> m_matrix[1]{0] is -sin(rotation angle) and therefore zero
|
||||
//(x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0]))
|
||||
return (m_isIdentity ? x : (x * m_matrix[0][0] + m_matrix[2][0]));
|
||||
}
|
||||
|
||||
// Transform Y value from logical to device
|
||||
// warning: this function can only be used for this purpose
|
||||
// because no rotation is involved when mapping logical to device coordinates
|
||||
// mirror and scaling for x and y will be part of the matrix
|
||||
// if you have a matrix that is rotated, eg a shape containing a matrix to place
|
||||
// it in the logical coordinate system, use TransformPoint
|
||||
inline double wxTransformMatrix::TransformY(double y) const
|
||||
{
|
||||
//normally like this, but since no rotation is involved (only mirror and scale)
|
||||
//we can do without X -> m_matrix[0]{1] is sin(rotation angle) and therefore zero
|
||||
//(x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1]))
|
||||
return (m_isIdentity ? y : (y * m_matrix[1][1] + m_matrix[2][1]));
|
||||
}
|
||||
|
||||
|
||||
// Is the matrix the identity matrix?
|
||||
// Each operation checks whether the result is still the identity matrix and sets a flag.
|
||||
inline bool wxTransformMatrix::IsIdentity1(void) const
|
||||
{
|
||||
return
|
||||
( wxIsSameDouble(m_matrix[0][0], 1.0) &&
|
||||
wxIsSameDouble(m_matrix[1][1], 1.0) &&
|
||||
wxIsSameDouble(m_matrix[2][2], 1.0) &&
|
||||
wxIsSameDouble(m_matrix[1][0], 0.0) &&
|
||||
wxIsSameDouble(m_matrix[2][0], 0.0) &&
|
||||
wxIsSameDouble(m_matrix[0][1], 0.0) &&
|
||||
wxIsSameDouble(m_matrix[2][1], 0.0) &&
|
||||
wxIsSameDouble(m_matrix[0][2], 0.0) &&
|
||||
wxIsSameDouble(m_matrix[1][2], 0.0) );
|
||||
}
|
||||
|
||||
// Calculates the determinant of a 2 x 2 matrix
|
||||
inline double wxCalculateDet(double a11, double a21, double a12, double a22)
|
||||
{
|
||||
return a11 * a22 - a12 * a21;
|
||||
}
|
||||
|
||||
#endif // _WX_MATRIXH__
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
struct normal{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
typedef struct outerStruct {
|
||||
struct normal a_nomal_one;
|
||||
|
||||
int a;
|
||||
|
||||
struct {
|
||||
union {
|
||||
int b;
|
||||
} a_union_in_the_struct;
|
||||
|
||||
int c;
|
||||
};
|
||||
|
||||
union {
|
||||
int d;
|
||||
|
||||
struct {
|
||||
int e;
|
||||
} a_struct_in_the_union;
|
||||
} a_union;
|
||||
};
|
||||
@@ -1,622 +0,0 @@
|
||||
/* This file has been written by Blablub.
|
||||
*
|
||||
* Another comment line.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __SOME_OTHER_CRAP
|
||||
extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define interrupts() sei()
|
||||
|
||||
enum
|
||||
{
|
||||
/* 8bit, color or not */
|
||||
CV_LOAD_IMAGE_UNCHANGED =-1,
|
||||
/* 8bit, gray */
|
||||
CV_LOAD_IMAGE_GRAYSCALE =0,
|
||||
/* ?, color */
|
||||
CV_LOAD_IMAGE_COLOR =1,
|
||||
/* any depth, ? */
|
||||
CV_LOAD_IMAGE_ANYDEPTH =2,
|
||||
/* ?, any color */
|
||||
CV_LOAD_IMAGE_ANYCOLOR =4
|
||||
};
|
||||
|
||||
typedef void (*callback_t) (int rc);
|
||||
typedef const char* (*callback2)(int rc, long L, const char* buffer);
|
||||
|
||||
int aw_callback_set (AW_CALLBACK c, callback_t callback );
|
||||
int aw_instance_callback_set (AW_CALLBACK c, callback_t callback);
|
||||
|
||||
unsigned long int wawa;
|
||||
|
||||
#define MAX(x, y) ((x) < (y)? (y) : (x))
|
||||
|
||||
#define AW_BUILD 85 // AW 5.0
|
||||
// Limits
|
||||
#define AW_MAX_AVCHANGE_PER_SECOND 10
|
||||
|
||||
#private expatDll
|
||||
|
||||
#if !defined(expatDll)
|
||||
# if defined(windows)
|
||||
# define expatDll "expat.dll"
|
||||
# elif defined(macosx)
|
||||
# define expatDll "libexpat.dynlib"
|
||||
# else
|
||||
# define expatDll "libexpat.so(.1|)"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#mangle "'XML_'{.*}" "$1"
|
||||
#private "'XML_ParserStruct'"
|
||||
|
||||
#mangle cuint cint
|
||||
|
||||
unsigned int uiVar;
|
||||
|
||||
#private "@('_'!.)"
|
||||
unsigned int myPrivateVar__;
|
||||
|
||||
|
||||
struct XML_ParserStruct;
|
||||
|
||||
#def XMLCALL __cdecl
|
||||
|
||||
typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
|
||||
const XML_Char *name,
|
||||
XML_Content *model);
|
||||
|
||||
|
||||
void* x;
|
||||
void* fn(void);
|
||||
void (*fn)(void);
|
||||
void* (*fn)(void);
|
||||
void* (*fn)(void*);
|
||||
|
||||
/*
|
||||
* Very ugly real world code ahead:
|
||||
*/
|
||||
|
||||
#def JMETHOD(rettype, name, params) rettype (*name) params
|
||||
|
||||
typedef struct cjpeg_source_struct * cjpeg_source_ptr;
|
||||
|
||||
struct cjpeg_source_struct {
|
||||
JMETHOD(void, start_input, (j_compress_ptr cinfo,
|
||||
cjpeg_source_ptr sinfo));
|
||||
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
|
||||
cjpeg_source_ptr sinfo));
|
||||
JMETHOD(void, finish_input, (j_compress_ptr cinfo,
|
||||
cjpeg_source_ptr sinfo));
|
||||
|
||||
FILE *input_file;
|
||||
|
||||
JSAMPARRAY buffer;
|
||||
JDIMENSION buffer_height;
|
||||
};
|
||||
|
||||
// Test standalone structs:
|
||||
|
||||
union myunion {
|
||||
char x, y, *z;
|
||||
myint a, b;
|
||||
} u;
|
||||
|
||||
struct mystruct {
|
||||
char x, y, *z;
|
||||
myint a, b;
|
||||
};
|
||||
|
||||
struct mystruct fn(i32 x, i64 y);
|
||||
|
||||
struct mystruct {
|
||||
char x, y, *z;
|
||||
myint a, b;
|
||||
} *myvar = NULL, **myvar2 = NULL;
|
||||
|
||||
// anonymous struct:
|
||||
|
||||
struct {
|
||||
char x, y, *z;
|
||||
myint a, b;
|
||||
} varX, **varY;
|
||||
|
||||
// empty anonymous struct:
|
||||
|
||||
struct {
|
||||
|
||||
} varX, **varY;
|
||||
|
||||
// Test C2NIM skipping:
|
||||
|
||||
#define MASK(x) ((x) & 0xff)
|
||||
#define CAST1(x) ((int) &x)
|
||||
#define CAST2(x) (typ*) &x
|
||||
#define CAST3(x) ((const unsigned char**) &x)
|
||||
|
||||
#ifndef C2NIM
|
||||
#if someNestedCond
|
||||
This is an invalid text that should generate a parser error, if not
|
||||
#endif
|
||||
skipped correctly.
|
||||
#endif
|
||||
|
||||
#ifndef C2NIM
|
||||
#if someNestedCond
|
||||
This is an invalid text that should generate a parser error, if not
|
||||
#endif
|
||||
skipped correctly.
|
||||
#else
|
||||
typedef char gchar;
|
||||
typedef unsigned int gunsignedint;
|
||||
typedef unsigned char guchar;
|
||||
#endif
|
||||
|
||||
#ifdef C2NIM
|
||||
# mangle "'those'" "these"
|
||||
int those;
|
||||
#elif abc
|
||||
#if someNestedCond
|
||||
This is an invalid text that should generate a parser error, if not
|
||||
#else
|
||||
skipped correctly.
|
||||
#endif
|
||||
#else
|
||||
Another crappy input line.
|
||||
#endif
|
||||
|
||||
point* newPoint(void) {
|
||||
for (int i = 0; i < 89; ++i) echo("test" " string " "concatenation");
|
||||
for (; j < 54; j++) {}
|
||||
for (;; j--) ;
|
||||
for (;;) {}
|
||||
mytype * x = y * z;
|
||||
|
||||
if (**p == ' ') {
|
||||
--p;
|
||||
} else if (**p == '\t') {
|
||||
p += 3;
|
||||
} else {
|
||||
p = 45 + (mytype*)45;
|
||||
p = 45 + ((mytype*)45);
|
||||
p = 45 + ((mytype)45);
|
||||
// BUG: This does not parse:
|
||||
// p = 45 + (mytype)45;
|
||||
}
|
||||
|
||||
while (x >= 6 && x <= 20)
|
||||
--x;
|
||||
|
||||
switch (*p) {
|
||||
case 'A'...'Z':
|
||||
case 'a'...'z':
|
||||
++p;
|
||||
break;
|
||||
case '0':
|
||||
++p;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
a1, a2 = 4, a3
|
||||
};
|
||||
|
||||
typedef enum crazyTAG {
|
||||
x1, x2, x3 = 8, x4, x5
|
||||
} myEnum, *pMyEnum;
|
||||
|
||||
typedef enum {
|
||||
x1, x2, x3 = 8, x4, x5
|
||||
} myEnum, *pMyEnum;
|
||||
|
||||
// Test multi-line macro:
|
||||
|
||||
#define MUILTILINE "abc" \
|
||||
"xyz" \
|
||||
"def"
|
||||
|
||||
#define MULTILINE(x, y) do { \
|
||||
++y; ++x; \
|
||||
} while (0)
|
||||
|
||||
#ifdef C2NIM
|
||||
# dynlib iupdll
|
||||
# cdecl
|
||||
# mangle "'GTK_'{.*}" "TGtk$1"
|
||||
# mangle "'PGTK_'{.*}" "PGtk$1"
|
||||
# if defined(windows)
|
||||
# define iupdll "iup.dll"
|
||||
# elif defined(macosx)
|
||||
# define iupdll "libiup.dynlib"
|
||||
# else
|
||||
# define iupdll "libiup.so"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef struct stupidTAG {
|
||||
mytype a, b;
|
||||
} GTK_MyStruct, *PGTK_MyStruct;
|
||||
|
||||
typedef struct {
|
||||
mytype a, b;
|
||||
} GTK_MyStruct, *PGTK_MyStruct;
|
||||
|
||||
int IupConvertXYToPos(PIhandle ih, int x, int y);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define OUT(x) printf("%s\n", x)
|
||||
#else
|
||||
# define OUT(x)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef C2NIM
|
||||
# def EXTERN(x) static x
|
||||
# def TWO_ARGS(x, y) x* y
|
||||
#endif
|
||||
// parses now!
|
||||
EXTERN(int) f(void);
|
||||
EXTERN(int) g(void);
|
||||
|
||||
|
||||
#def EXPORT
|
||||
// does parse now!
|
||||
EXPORT int f(void);
|
||||
EXPORT int g(void);
|
||||
|
||||
static TWO_ARGS(int, x) = TWO_ARGS(56, 45);
|
||||
|
||||
|
||||
# define abc 34
|
||||
# define xyz 42
|
||||
|
||||
# define wuseldusel "my string\nconstant"
|
||||
|
||||
#undef ignoreThis
|
||||
|
||||
char* x;
|
||||
|
||||
typedef struct {
|
||||
char x, y, *z;
|
||||
} point;
|
||||
|
||||
char* __stdcall printf(char* frmt, const char* const** ptrToStrArray,
|
||||
const int* const dummy, ...);
|
||||
|
||||
inline char* myinlineProc(char* frmt, const char* const* strArray,
|
||||
const int* const dummy, ...);
|
||||
|
||||
// Test void parameter list:
|
||||
void myVoidProc(void);
|
||||
|
||||
void emptyReturn(void) { return; }
|
||||
|
||||
// POSIX stuff:
|
||||
|
||||
#ifdef C2NIM
|
||||
#prefix posix_
|
||||
int c2nimBranch;
|
||||
#elif defined(MACOSX)
|
||||
int* x, y, z;
|
||||
#else
|
||||
int dummy;
|
||||
#endif
|
||||
|
||||
#ifndef C2NIM
|
||||
int dontTranslateThis;
|
||||
#elif defined(Windows)
|
||||
int WindowsTrue = true;
|
||||
#endif
|
||||
|
||||
int posix_spawn(pid_t *restrict, const char *restrict,
|
||||
const posix_spawn_file_actions_t *,
|
||||
const posix_spawnattr_t *restrict, char *const [restrict],
|
||||
char *const [restrict]);
|
||||
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
|
||||
int);
|
||||
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *,
|
||||
int, int);
|
||||
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict,
|
||||
int, const char *restrict, int, mode_t);
|
||||
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
|
||||
int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
|
||||
int posix_spawnattr_destroy(posix_spawnattr_t *);
|
||||
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict,
|
||||
sigset_t *restrict);
|
||||
int posix_spawnattr_getflags(const posix_spawnattr_t *restrict,
|
||||
short *restrict);
|
||||
int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict,
|
||||
pid_t *restrict);
|
||||
int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict,
|
||||
struct sched_param *restrict);
|
||||
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict,
|
||||
int *restrict);
|
||||
int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict,
|
||||
sigset_t *restrict);
|
||||
int posix_spawnattr_init(posix_spawnattr_t *);
|
||||
int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict,
|
||||
const sigset_t *restrict);
|
||||
int posix_spawnattr_setflags(posix_spawnattr_t *, short);
|
||||
int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);
|
||||
|
||||
|
||||
int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict,
|
||||
const struct sched_param *restrict);
|
||||
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
|
||||
int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict,
|
||||
const sigset_t *restrict);
|
||||
int posix_spawnp(pid_t *restrict, const char *restrict,
|
||||
const posix_spawn_file_actions_t *,
|
||||
const posix_spawnattr_t *restrict,
|
||||
char *const [restrict], char *const [restrict]);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float R, G, B;
|
||||
}
|
||||
RGBType;
|
||||
typedef struct
|
||||
{
|
||||
float H, W, B;
|
||||
}
|
||||
HWBType;
|
||||
|
||||
static HWBType *
|
||||
RGB_to_HWB (RGBType RGB, HWBType * HWB)
|
||||
{
|
||||
HWBType* myArray[20];
|
||||
/*
|
||||
* RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
|
||||
* returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
|
||||
*/
|
||||
|
||||
float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
|
||||
int i;
|
||||
|
||||
w = MIN3 (R, G, B);
|
||||
v = MAX3 (R, G, B);
|
||||
b &= 1 - v;
|
||||
if (v == w)
|
||||
RETURN_HWB (HWB_UNDEFINED, w, b);
|
||||
f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
|
||||
i = (R == w) ? 3 : ((G == w) ? 5 : 1);
|
||||
RETURN_HWB (i - f / (v - w), w, b);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
clip_1d (int *x0, int *y0, int *x1, int *y1, int mindim, int maxdim)
|
||||
{
|
||||
double m; // gradient of line
|
||||
if (*x0 < mindim)
|
||||
{ // start of line is left of window
|
||||
if (*x1 < mindim) // as is the end, so the line never cuts the window
|
||||
return 0;
|
||||
m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line
|
||||
// adjust x0 to be on the left boundary (ie to be zero), and y0 to match
|
||||
*y0 -= m * (*x0 - mindim);
|
||||
*x0 = mindim;
|
||||
// now, perhaps, adjust the far end of the line as well
|
||||
if (*x1 > maxdim)
|
||||
{
|
||||
*y1 += m * (maxdim - *x1);
|
||||
*x1 = maxdim;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (*x0 > maxdim)
|
||||
{ // start of line is right of window - complement of above
|
||||
if (*x1 > maxdim) // as is the end, so the line misses the window
|
||||
return 0;
|
||||
m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line
|
||||
*y0 += m * (maxdim - *x0); // adjust so point is on the right
|
||||
// boundary
|
||||
*x0 = maxdim;
|
||||
// now, perhaps, adjust the end of the line
|
||||
if (*x1 < mindim)
|
||||
{
|
||||
*y1 -= m * (*x1 - mindim);
|
||||
*x1 = mindim;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
// the final case - the start of the line is inside the window
|
||||
if (*x1 > maxdim)
|
||||
{ // other end is outside to the right
|
||||
m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line
|
||||
*y1 += m * (maxdim - *x1);
|
||||
*x1 = maxdim;
|
||||
return 1;
|
||||
}
|
||||
if (*x1 < mindim)
|
||||
{ // other end is outside to the left
|
||||
m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of line
|
||||
*y1 -= m * (*x1 - mindim);
|
||||
*x1 = mindim;
|
||||
return 1;
|
||||
}
|
||||
// only get here if both points are inside the window
|
||||
return 1;
|
||||
}
|
||||
|
||||
// end of line clipping code
|
||||
|
||||
static void
|
||||
gdImageBrushApply (gdImagePtr im, int x, int y)
|
||||
{
|
||||
int lx, ly;
|
||||
int hy;
|
||||
int hx;
|
||||
int x1, y1, x2, y2;
|
||||
int srcx, srcy;
|
||||
if (!im->brush)
|
||||
{
|
||||
return;
|
||||
}
|
||||
hy = gdImageSY (im->brush) / 2;
|
||||
y1 = y - hy;
|
||||
y2 = y1 + gdImageSY (im->brush);
|
||||
hx = gdImageSX (im->brush) / 2;
|
||||
x1 = x - hx;
|
||||
x2 = x1 + gdImageSX (im->brush);
|
||||
srcy = 0;
|
||||
if (im->trueColor)
|
||||
{
|
||||
if (im->brush->trueColor)
|
||||
{
|
||||
for (ly = y1; (ly < y2); ly++)
|
||||
{
|
||||
srcx = 0;
|
||||
for (lx = x1; (lx < x2); lx++)
|
||||
{
|
||||
int p;
|
||||
p = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
|
||||
// 2.0.9, Thomas Winzig: apply simple full transparency
|
||||
if (p != gdImageGetTransparent (im->brush))
|
||||
{
|
||||
gdImageSetPixel (im, lx, ly, p);
|
||||
}
|
||||
srcx++;
|
||||
}
|
||||
srcy++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2.0.12: Brush palette, image truecolor (thanks to Thorben Kundinger
|
||||
// for pointing out the issue)
|
||||
for (ly = y1; (ly < y2); ly++)
|
||||
{
|
||||
srcx = 0;
|
||||
for (lx = x1; (lx < x2); lx++)
|
||||
{
|
||||
int p, tc;
|
||||
p = gdImageGetPixel (im->brush, srcx, srcy);
|
||||
tc = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
|
||||
// 2.0.9, Thomas Winzig: apply simple full transparency
|
||||
if (p != gdImageGetTransparent (im->brush))
|
||||
{
|
||||
gdImageSetPixel (im, lx, ly, tc);
|
||||
}
|
||||
srcx++;
|
||||
}
|
||||
srcy++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ly = y1; (ly < y2); ly++)
|
||||
{
|
||||
srcx = 0;
|
||||
for (lx = x1; (lx < x2); lx++)
|
||||
{
|
||||
int p;
|
||||
p = gdImageGetPixel (im->brush, srcx, srcy);
|
||||
// Allow for non-square brushes!
|
||||
if (p != gdImageGetTransparent (im->brush))
|
||||
{
|
||||
// Truecolor brush. Very slow
|
||||
// on a palette destination.
|
||||
if (im->brush->trueColor)
|
||||
{
|
||||
gdImageSetPixel (im, lx, ly,
|
||||
gdImageColorResolveAlpha(im,
|
||||
gdTrueColorGetRed(p),
|
||||
gdTrueColorGetGreen(p),
|
||||
gdTrueColorGetBlue(p),
|
||||
gdTrueColorGetAlpha(p)));
|
||||
}
|
||||
else
|
||||
{
|
||||
gdImageSetPixel (im, lx, ly, im->brushColorMap[p]);
|
||||
}
|
||||
}
|
||||
srcx++;
|
||||
}
|
||||
srcy++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gdImageSetPixel (gdImagePtr im, int x, int y, int color)
|
||||
{
|
||||
int p;
|
||||
switch (color)
|
||||
{
|
||||
case gdStyled:
|
||||
if (!im->style)
|
||||
{
|
||||
// Refuse to draw if no style is set.
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = im->style[im->stylePos++];
|
||||
}
|
||||
if (p != (gdTransparent))
|
||||
{
|
||||
gdImageSetPixel (im, x, y, p);
|
||||
}
|
||||
im->stylePos = im->stylePos % im->styleLength;
|
||||
break;
|
||||
case gdStyledBrushed:
|
||||
if (!im->style)
|
||||
{
|
||||
// Refuse to draw if no style is set.
|
||||
return;
|
||||
}
|
||||
p = im->style[im->stylePos++];
|
||||
if ((p != gdTransparent) && (p != 0))
|
||||
{
|
||||
gdImageSetPixel (im, x, y, gdBrushed);
|
||||
}
|
||||
im->stylePos = im->stylePos % im->styleLength;
|
||||
break;
|
||||
case gdBrushed:
|
||||
gdImageBrushApply (im, x, y);
|
||||
break;
|
||||
case gdTiled:
|
||||
gdImageTileApply (im, x, y);
|
||||
break;
|
||||
case gdAntiAliased:
|
||||
// This shouldn't happen (2.0.26) because we just call
|
||||
// gdImageAALine now, but do something sane.
|
||||
gdImageSetPixel(im, x, y, im->AA_color);
|
||||
break;
|
||||
default:
|
||||
if (gdImageBoundsSafeMacro (im, x, y))
|
||||
{
|
||||
if (im->trueColor)
|
||||
{
|
||||
if (im->alphaBlendingFlag)
|
||||
{
|
||||
im->tpixels[y][x] = gdAlphaBlend (im->tpixels[y][x], color);
|
||||
}
|
||||
else
|
||||
{
|
||||
im->tpixels[y][x] = color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
im->pixels[y][x] = color;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifdef C2NIM
|
||||
# header "iup.h"
|
||||
# cdecl
|
||||
# mangle "'GTK_'{.*}" "TGtk$1"
|
||||
# mangle "'PGTK_'{.*}" "PGtk$1"
|
||||
#endif
|
||||
|
||||
typedef struct stupidTAG {
|
||||
mytype a, b;
|
||||
} GTK_MyStruct, *PGTK_MyStruct;
|
||||
|
||||
typedef struct {
|
||||
mytype a, b;
|
||||
} GTK_MyStruct, *PGTK_MyStruct;
|
||||
|
||||
int IupConvertXYToPos(PIhandle ih, int x, int y);
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int rand(void);
|
||||
|
||||
int id2(void) {
|
||||
return (int *)1;
|
||||
}
|
||||
|
||||
int id(void (*f)(void)) {
|
||||
f();
|
||||
((void (*)(int))f)(10);
|
||||
return 10;
|
||||
return (20+1);
|
||||
return (int *)id;
|
||||
}
|
||||
|
||||
int main() {
|
||||
float f = .2,
|
||||
g = 2.,
|
||||
h = 1.0+rand(),
|
||||
i = 1.0e+3;
|
||||
int j, a;
|
||||
for(j = 0, a = 10; j < 0; j++, a++) ;
|
||||
do {
|
||||
printf("howdy");
|
||||
} while(--i, 0);
|
||||
if(1)
|
||||
printf("1"); // error from this comment
|
||||
else
|
||||
printf("2");
|
||||
return '\x00';
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
struct foo {
|
||||
int x,y,z;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,22 @@ proc createObj*(owner: PSym, info: TLineInfo): PType =
|
||||
incl result.flags, tfFinal
|
||||
result.n = newNodeI(nkRecList, info)
|
||||
|
||||
proc rawAddField*(obj: PType; field: PSym) =
|
||||
assert field.kind == skField
|
||||
field.position = sonsLen(obj.n)
|
||||
addSon(obj.n, newSymNode(field))
|
||||
|
||||
proc rawIndirectAccess*(a: PNode; field: PSym; info: TLineInfo): PNode =
|
||||
# returns a[].field as a node
|
||||
assert field.kind == skField
|
||||
var deref = newNodeI(nkHiddenDeref, info)
|
||||
deref.typ = a.typ.skipTypes(abstractInst).sons[0]
|
||||
addSon(deref, a)
|
||||
result = newNodeI(nkDotExpr, info)
|
||||
addSon(result, deref)
|
||||
addSon(result, newSymNode(field))
|
||||
result.typ = field.typ
|
||||
|
||||
proc addField*(obj: PType; s: PSym) =
|
||||
# because of 'gensym' support, we have to mangle the name with its ID.
|
||||
# This is hacky but the clean solution is much more complex than it looks.
|
||||
@@ -74,6 +90,16 @@ proc addField*(obj: PType; s: PSym) =
|
||||
field.position = sonsLen(obj.n)
|
||||
addSon(obj.n, newSymNode(field))
|
||||
|
||||
proc addUniqueField*(obj: PType; s: PSym) =
|
||||
let fieldName = getIdent(s.name.s & $s.id)
|
||||
if lookupInRecord(obj.n, fieldName) == nil:
|
||||
var field = newSym(skField, fieldName, s.owner, s.info)
|
||||
let t = skipIntLit(s.typ)
|
||||
field.typ = t
|
||||
assert t.kind != tyStmt
|
||||
field.position = sonsLen(obj.n)
|
||||
addSon(obj.n, newSymNode(field))
|
||||
|
||||
proc newDotExpr(obj, b: PSym): PNode =
|
||||
result = newNodeI(nkDotExpr, obj.info)
|
||||
let field = getSymFromList(obj.typ.n, getIdent(b.name.s & $b.id))
|
||||
@@ -95,13 +121,28 @@ proc indirectAccess*(a: PNode, b: string, info: TLineInfo): PNode =
|
||||
t = t.sons[0]
|
||||
if t == nil: break
|
||||
t = t.skipTypes(abstractInst)
|
||||
assert field != nil, b
|
||||
#if field == nil:
|
||||
# debug deref.typ
|
||||
# echo deref.typ.id
|
||||
internalAssert field != nil
|
||||
addSon(deref, a)
|
||||
result = newNodeI(nkDotExpr, info)
|
||||
addSon(result, deref)
|
||||
addSon(result, newSymNode(field))
|
||||
result.typ = field.typ
|
||||
|
||||
proc getFieldFromObj*(t: PType; v: PSym): PSym =
|
||||
assert v.kind != skField
|
||||
let fieldName = getIdent(v.name.s & $v.id)
|
||||
var t = t
|
||||
while true:
|
||||
assert t.kind == tyObject
|
||||
result = getSymFromList(t.n, fieldName)
|
||||
if result != nil: break
|
||||
t = t.sons[0]
|
||||
if t == nil: break
|
||||
t = t.skipTypes(abstractInst)
|
||||
|
||||
proc indirectAccess*(a: PNode, b: PSym, info: TLineInfo): PNode =
|
||||
# returns a[].b as a node
|
||||
result = indirectAccess(a, b.name.s & $b.id, info)
|
||||
|
||||
@@ -27,6 +27,8 @@ var
|
||||
gSysTypes: array[TTypeKind, PType]
|
||||
compilerprocs: TStrTable
|
||||
|
||||
proc nilOrSysInt*: PType = gSysTypes[tyInt]
|
||||
|
||||
proc registerSysType(t: PType) =
|
||||
if gSysTypes[t.kind] == nil: gSysTypes[t.kind] = t
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
# Use the modules of the compiler
|
||||
|
||||
path: "$nimrod/compiler"
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Pas2nim - Pascal to Nimrod source converter
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
import
|
||||
strutils, os, parseopt, llstream, ast, renderer, options, msgs,
|
||||
paslex, pasparse
|
||||
|
||||
const
|
||||
Version = "0.8"
|
||||
Usage = """
|
||||
pas2nim - Pascal to Nimrod source converter
|
||||
(c) 2012 Andreas Rumpf
|
||||
Usage: pas2nim [options] inputfile [options]
|
||||
Options:
|
||||
-o, --out:FILE set output filename
|
||||
--ref convert ^typ to ref typ (default: ptr typ)
|
||||
--boot use special translation rules for the Nimrod compiler
|
||||
-v, --version write pas2nim's version
|
||||
-h, --help show this help
|
||||
"""
|
||||
|
||||
proc main(infile, outfile: string, flags: set[TParserFlag]) =
|
||||
var stream = llStreamOpen(infile, fmRead)
|
||||
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
||||
var p: TParser
|
||||
openParser(p, infile, stream, flags)
|
||||
var module = parseUnit(p)
|
||||
closeParser(p)
|
||||
renderModule(module, outfile)
|
||||
|
||||
var
|
||||
infile = ""
|
||||
outfile = ""
|
||||
flags: set[TParserFlag] = {}
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
of cmdArgument: infile = key
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key
|
||||
of "help", "h":
|
||||
stdout.write(Usage)
|
||||
quit(0)
|
||||
of "version", "v":
|
||||
stdout.write(Version & "\n")
|
||||
quit(0)
|
||||
of "o", "out": outfile = val
|
||||
of "ref": incl(flags, pfRefs)
|
||||
of "boot": flags = flags + {pfRefs, pfMoreReplacements, pfImportBlackList}
|
||||
else: stdout.writeln("[Error] unknown option: " & key)
|
||||
of cmdEnd: assert(false)
|
||||
if infile.len == 0:
|
||||
# no filename has been given, so we show the help:
|
||||
stdout.write(Usage)
|
||||
else:
|
||||
if outfile.len == 0:
|
||||
outfile = changeFileExt(infile, "nim")
|
||||
infile = addFileExt(infile, "pas")
|
||||
main(infile, outfile, flags)
|
||||
@@ -1,570 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Pas2nim - Pascal to Nimrod source converter
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# This module implements a FreePascal scanner. This is an adaption from
|
||||
# the scanner module.
|
||||
|
||||
import
|
||||
hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream
|
||||
|
||||
const
|
||||
MaxLineLength* = 80 # lines longer than this lead to a warning
|
||||
numChars*: TCharSet = {'0'..'9', 'a'..'z', 'A'..'Z'}
|
||||
SymChars*: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF'}
|
||||
SymStartChars*: TCharSet = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'}
|
||||
OpChars*: TCharSet = {'+', '-', '*', '/', '<', '>', '!', '?', '^', '.', '|',
|
||||
'=', ':', '%', '&', '$', '@', '~', '\x80'..'\xFF'}
|
||||
|
||||
# keywords are sorted!
|
||||
|
||||
type
|
||||
TTokKind* = enum
|
||||
pxInvalid, pxEof,
|
||||
pxAnd, pxArray, pxAs, pxAsm, pxBegin, pxCase, pxClass, pxConst,
|
||||
pxConstructor, pxDestructor, pxDiv, pxDo, pxDownto, pxElse, pxEnd, pxExcept,
|
||||
pxExports, pxFinalization, pxFinally, pxFor, pxFunction, pxGoto, pxIf,
|
||||
pxImplementation, pxIn, pxInherited, pxInitialization, pxInline,
|
||||
pxInterface, pxIs, pxLabel, pxLibrary, pxMod, pxNil, pxNot, pxObject, pxOf,
|
||||
pxOr, pxOut, pxPacked, pxProcedure, pxProgram, pxProperty, pxRaise,
|
||||
pxRecord, pxRepeat, pxResourcestring, pxSet, pxShl, pxShr, pxThen,
|
||||
pxThreadvar, pxTo, pxTry, pxType, pxUnit, pxUntil, pxUses, pxVar, pxWhile,
|
||||
pxWith, pxXor,
|
||||
pxComment, # ordinary comment
|
||||
pxCommand, # {@}
|
||||
pxAmp, # {&}
|
||||
pxPer, # {%}
|
||||
pxStrLit, pxSymbol, # a symbol
|
||||
pxIntLit, pxInt64Lit, # long constant like 0x70fffffff or out of int range
|
||||
pxFloatLit, pxParLe, pxParRi, pxBracketLe, pxBracketRi, pxComma,
|
||||
pxSemiColon, pxColon, # operators
|
||||
pxAsgn, pxEquals, pxDot, pxDotDot, pxHat, pxPlus, pxMinus, pxStar, pxSlash,
|
||||
pxLe, pxLt, pxGe, pxGt, pxNeq, pxAt, pxStarDirLe, pxStarDirRi, pxCurlyDirLe,
|
||||
pxCurlyDirRi
|
||||
TTokKinds* = set[TTokKind]
|
||||
|
||||
const
|
||||
Keywords = ["and", "array", "as", "asm", "begin", "case", "class", "const",
|
||||
"constructor", "destructor", "div", "do", "downto", "else", "end", "except",
|
||||
"exports", "finalization", "finally", "for", "function", "goto", "if",
|
||||
"implementation", "in", "inherited", "initialization", "inline",
|
||||
"interface", "is", "label", "library", "mod", "nil", "not", "object", "of",
|
||||
"or", "out", "packed", "procedure", "program", "property", "raise",
|
||||
"record", "repeat", "resourcestring", "set", "shl", "shr", "then",
|
||||
"threadvar", "to", "try", "type", "unit", "until", "uses", "var", "while",
|
||||
"with", "xor"]
|
||||
|
||||
firstKeyword = pxAnd
|
||||
lastKeyword = pxXor
|
||||
|
||||
type
|
||||
TNumericalBase* = enum base10, base2, base8, base16
|
||||
TToken* = object
|
||||
xkind*: TTokKind # the type of the token
|
||||
ident*: PIdent # the parsed identifier
|
||||
iNumber*: BiggestInt # the parsed integer literal
|
||||
fNumber*: BiggestFloat # the parsed floating point literal
|
||||
base*: TNumericalBase # the numerical base; only valid for int
|
||||
# or float literals
|
||||
literal*: string # the parsed (string) literal
|
||||
|
||||
TLexer* = object of TBaseLexer
|
||||
filename*: string
|
||||
|
||||
|
||||
proc getTok*(L: var TLexer, tok: var TToken)
|
||||
proc printTok*(tok: TToken)
|
||||
proc `$`*(tok: TToken): string
|
||||
# implementation
|
||||
|
||||
var
|
||||
dummyIdent: PIdent
|
||||
gLinesCompiled: int
|
||||
|
||||
proc fillToken(L: var TToken) =
|
||||
L.xkind = pxInvalid
|
||||
L.iNumber = 0
|
||||
L.literal = ""
|
||||
L.fNumber = 0.0
|
||||
L.base = base10
|
||||
L.ident = dummyIdent # this prevents many bugs!
|
||||
|
||||
proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream) =
|
||||
openBaseLexer(lex, inputstream)
|
||||
lex.filename = filename
|
||||
|
||||
proc closeLexer*(lex: var TLexer) =
|
||||
inc(gLinesCompiled, lex.LineNumber)
|
||||
closeBaseLexer(lex)
|
||||
|
||||
proc getColumn(L: TLexer): int =
|
||||
result = getColNumber(L, L.bufPos)
|
||||
|
||||
proc getLineInfo*(L: TLexer): TLineInfo =
|
||||
result = newLineInfo(L.filename, L.linenumber, getColNumber(L, L.bufpos))
|
||||
|
||||
proc lexMessage*(L: TLexer, msg: TMsgKind, arg = "") =
|
||||
msgs.globalError(getLineInfo(L), msg, arg)
|
||||
|
||||
proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||
var info = newLineInfo(L.filename, L.linenumber, pos - L.lineStart)
|
||||
msgs.globalError(info, msg, arg)
|
||||
|
||||
proc tokKindToStr*(k: TTokKind): string =
|
||||
case k
|
||||
of pxEof: result = "[EOF]"
|
||||
of firstKeyword..lastKeyword:
|
||||
result = Keywords[ord(k)-ord(firstKeyword)]
|
||||
of pxInvalid, pxComment, pxStrLit: result = "string literal"
|
||||
of pxCommand: result = "{@"
|
||||
of pxAmp: result = "{&"
|
||||
of pxPer: result = "{%"
|
||||
of pxSymbol: result = "identifier"
|
||||
of pxIntLit, pxInt64Lit: result = "integer literal"
|
||||
of pxFloatLit: result = "floating point literal"
|
||||
of pxParLe: result = "("
|
||||
of pxParRi: result = ")"
|
||||
of pxBracketLe: result = "["
|
||||
of pxBracketRi: result = "]"
|
||||
of pxComma: result = ","
|
||||
of pxSemiColon: result = ";"
|
||||
of pxColon: result = ":"
|
||||
of pxAsgn: result = ":="
|
||||
of pxEquals: result = "="
|
||||
of pxDot: result = "."
|
||||
of pxDotDot: result = ".."
|
||||
of pxHat: result = "^"
|
||||
of pxPlus: result = "+"
|
||||
of pxMinus: result = "-"
|
||||
of pxStar: result = "*"
|
||||
of pxSlash: result = "/"
|
||||
of pxLe: result = "<="
|
||||
of pxLt: result = "<"
|
||||
of pxGe: result = ">="
|
||||
of pxGt: result = ">"
|
||||
of pxNeq: result = "<>"
|
||||
of pxAt: result = "@"
|
||||
of pxStarDirLe: result = "(*$"
|
||||
of pxStarDirRi: result = "*)"
|
||||
of pxCurlyDirLe: result = "{$"
|
||||
of pxCurlyDirRi: result = "}"
|
||||
|
||||
proc `$`(tok: TToken): string =
|
||||
case tok.xkind
|
||||
of pxInvalid, pxComment, pxStrLit: result = tok.literal
|
||||
of pxSymbol: result = tok.ident.s
|
||||
of pxIntLit, pxInt64Lit: result = $tok.iNumber
|
||||
of pxFloatLit: result = $tok.fNumber
|
||||
else: result = tokKindToStr(tok.xkind)
|
||||
|
||||
proc printTok(tok: TToken) =
|
||||
writeln(stdout, $tok)
|
||||
|
||||
proc setKeyword(L: var TLexer, tok: var TToken) =
|
||||
var x = binaryStrSearch(keywords, toLower(tok.ident.s))
|
||||
if x < 0: tok.xkind = pxSymbol
|
||||
else: tok.xKind = TTokKind(x + ord(firstKeyword))
|
||||
|
||||
proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: TCharSet) =
|
||||
# matches ([chars]_)*
|
||||
var pos = L.bufpos # use registers for pos, buf
|
||||
var buf = L.buf
|
||||
while true:
|
||||
if buf[pos] in chars:
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
else:
|
||||
break
|
||||
if buf[pos] == '_':
|
||||
add(tok.literal, '_')
|
||||
inc(pos)
|
||||
L.bufPos = pos
|
||||
|
||||
proc isFloatLiteral(s: string): bool =
|
||||
for i in countup(0, len(s)-1):
|
||||
if s[i] in {'.', 'e', 'E'}:
|
||||
return true
|
||||
|
||||
proc getNumber2(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 1 # skip %
|
||||
if not (L.buf[pos] in {'0'..'1'}):
|
||||
# BUGFIX for %date%
|
||||
tok.xkind = pxInvalid
|
||||
add(tok.literal, '%')
|
||||
inc(L.bufpos)
|
||||
return
|
||||
tok.base = base2
|
||||
var xi: BiggestInt = 0
|
||||
var bits = 0
|
||||
while true:
|
||||
case L.buf[pos]
|
||||
of 'A'..'Z', 'a'..'z', '2'..'9', '.':
|
||||
lexMessage(L, errInvalidNumber)
|
||||
inc(pos)
|
||||
of '_':
|
||||
inc(pos)
|
||||
of '0', '1':
|
||||
xi = `shl`(xi, 1) or (ord(L.buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
inc(bits)
|
||||
else: break
|
||||
tok.iNumber = xi
|
||||
if (bits > 32): tok.xkind = pxInt64Lit
|
||||
else: tok.xkind = pxIntLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getNumber16(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos + 1 # skip $
|
||||
tok.base = base16
|
||||
var xi: BiggestInt = 0
|
||||
var bits = 0
|
||||
while true:
|
||||
case L.buf[pos]
|
||||
of 'G'..'Z', 'g'..'z', '.':
|
||||
lexMessage(L, errInvalidNumber)
|
||||
inc(pos)
|
||||
of '_': inc(pos)
|
||||
of '0'..'9':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
of 'a'..'f':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('a') + 10)
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
of 'A'..'F':
|
||||
xi = `shl`(xi, 4) or (ord(L.buf[pos]) - ord('A') + 10)
|
||||
inc(pos)
|
||||
inc(bits, 4)
|
||||
else: break
|
||||
tok.iNumber = xi
|
||||
if (bits > 32):
|
||||
tok.xkind = pxInt64Lit
|
||||
else:
|
||||
tok.xkind = pxIntLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getNumber10(L: var TLexer, tok: var TToken) =
|
||||
tok.base = base10
|
||||
matchUnderscoreChars(L, tok, {'0'..'9'})
|
||||
if (L.buf[L.bufpos] == '.') and (L.buf[L.bufpos + 1] in {'0'..'9'}):
|
||||
add(tok.literal, '.')
|
||||
inc(L.bufpos)
|
||||
matchUnderscoreChars(L, tok, {'e', 'E', '+', '-', '0'..'9'})
|
||||
try:
|
||||
if isFloatLiteral(tok.literal):
|
||||
tok.fnumber = parseFloat(tok.literal)
|
||||
tok.xkind = pxFloatLit
|
||||
else:
|
||||
tok.iNumber = parseInt(tok.literal)
|
||||
if (tok.iNumber < low(int32)) or (tok.iNumber > high(int32)):
|
||||
tok.xkind = pxInt64Lit
|
||||
else:
|
||||
tok.xkind = pxIntLit
|
||||
except EInvalidValue:
|
||||
lexMessage(L, errInvalidNumber, tok.literal)
|
||||
except EOverflow:
|
||||
lexMessage(L, errNumberOutOfRange, tok.literal)
|
||||
|
||||
proc handleCRLF(L: var TLexer, pos: int): int =
|
||||
case L.buf[pos]
|
||||
of CR: result = nimlexbase.handleCR(L, pos)
|
||||
of LF: result = nimlexbase.handleLF(L, pos)
|
||||
else: result = pos
|
||||
|
||||
proc getString(L: var TLexer, tok: var TToken) =
|
||||
var xi: int
|
||||
var pos = L.bufPos
|
||||
var buf = L.buf
|
||||
while true:
|
||||
if buf[pos] == '\'':
|
||||
inc(pos)
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR, LF, nimlexbase.EndOfFile:
|
||||
lexMessage(L, errClosingQuoteExpected)
|
||||
break
|
||||
of '\'':
|
||||
inc(pos)
|
||||
if buf[pos] == '\'':
|
||||
inc(pos)
|
||||
add(tok.literal, '\'')
|
||||
else:
|
||||
break
|
||||
else:
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
elif buf[pos] == '#':
|
||||
inc(pos)
|
||||
xi = 0
|
||||
case buf[pos]
|
||||
of '$':
|
||||
inc(pos)
|
||||
xi = 0
|
||||
while true:
|
||||
case buf[pos]
|
||||
of '0'..'9': xi = (xi shl 4) or (ord(buf[pos]) - ord('0'))
|
||||
of 'a'..'f': xi = (xi shl 4) or (ord(buf[pos]) - ord('a') + 10)
|
||||
of 'A'..'F': xi = (xi shl 4) or (ord(buf[pos]) - ord('A') + 10)
|
||||
else: break
|
||||
inc(pos)
|
||||
of '0'..'9':
|
||||
xi = 0
|
||||
while buf[pos] in {'0'..'9'}:
|
||||
xi = (xi * 10) + (ord(buf[pos]) - ord('0'))
|
||||
inc(pos)
|
||||
else: lexMessage(L, errInvalidCharacterConstant)
|
||||
if (xi <= 255): add(tok.literal, chr(xi))
|
||||
else: lexMessage(L, errInvalidCharacterConstant)
|
||||
else:
|
||||
break
|
||||
tok.xkind = pxStrLit
|
||||
L.bufpos = pos
|
||||
|
||||
proc getSymbol(L: var TLexer, tok: var TToken) =
|
||||
var h: THash = 0
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
while true:
|
||||
var c = buf[pos]
|
||||
case c
|
||||
of 'a'..'z', '0'..'9', '\x80'..'\xFF':
|
||||
h = h +% ord(c)
|
||||
h = h +% h shl 10
|
||||
h = h xor (h shr 6)
|
||||
of 'A'..'Z':
|
||||
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
||||
h = h +% ord(c)
|
||||
h = h +% h shl 10
|
||||
h = h xor (h shr 6)
|
||||
of '_': discard
|
||||
else: break
|
||||
inc(pos)
|
||||
h = h +% h shl 3
|
||||
h = h xor (h shr 11)
|
||||
h = h +% h shl 15
|
||||
tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h)
|
||||
L.bufpos = pos
|
||||
setKeyword(L, tok)
|
||||
|
||||
proc scanLineComment(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
# a comment ends if the next line does not start with the // on the same
|
||||
# column after only whitespace
|
||||
tok.xkind = pxComment
|
||||
var col = getColNumber(L, pos)
|
||||
while true:
|
||||
inc(pos, 2) # skip //
|
||||
add(tok.literal, '#')
|
||||
while not (buf[pos] in {CR, LF, nimlexbase.EndOfFile}):
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
var indent = 0
|
||||
while buf[pos] == ' ':
|
||||
inc(pos)
|
||||
inc(indent)
|
||||
if (col == indent) and (buf[pos] == '/') and (buf[pos + 1] == '/'):
|
||||
tok.literal = tok.literal & "\n"
|
||||
else:
|
||||
break
|
||||
L.bufpos = pos
|
||||
|
||||
proc scanCurlyComment(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
tok.literal = "#"
|
||||
tok.xkind = pxComment
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR, LF:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
add(tok.literal, "\n#")
|
||||
of '}':
|
||||
inc(pos)
|
||||
break
|
||||
of nimlexbase.EndOfFile: lexMessage(L, errTokenExpected, "}")
|
||||
else:
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
L.bufpos = pos
|
||||
|
||||
proc scanStarComment(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
tok.literal = "#"
|
||||
tok.xkind = pxComment
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR, LF:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
add(tok.literal, "\n#")
|
||||
of '*':
|
||||
inc(pos)
|
||||
if buf[pos] == ')':
|
||||
inc(pos)
|
||||
break
|
||||
else:
|
||||
add(tok.literal, '*')
|
||||
of nimlexbase.EndOfFile:
|
||||
lexMessage(L, errTokenExpected, "*)")
|
||||
else:
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
L.bufpos = pos
|
||||
|
||||
proc skip(L: var TLexer, tok: var TToken) =
|
||||
var pos = L.bufpos
|
||||
var buf = L.buf
|
||||
while true:
|
||||
case buf[pos]
|
||||
of ' ', Tabulator:
|
||||
inc(pos) # newline is special:
|
||||
of CR, LF:
|
||||
pos = handleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
else:
|
||||
break # EndOfFile also leaves the loop
|
||||
L.bufpos = pos
|
||||
|
||||
proc getTok(L: var TLexer, tok: var TToken) =
|
||||
tok.xkind = pxInvalid
|
||||
fillToken(tok)
|
||||
skip(L, tok)
|
||||
var c = L.buf[L.bufpos]
|
||||
if c in SymStartChars:
|
||||
getSymbol(L, tok)
|
||||
elif c in {'0'..'9'}:
|
||||
getNumber10(L, tok)
|
||||
else:
|
||||
case c
|
||||
of ';':
|
||||
tok.xkind = pxSemicolon
|
||||
inc(L.bufpos)
|
||||
of '/':
|
||||
if L.buf[L.bufpos + 1] == '/':
|
||||
scanLineComment(L, tok)
|
||||
else:
|
||||
tok.xkind = pxSlash
|
||||
inc(L.bufpos)
|
||||
of ',':
|
||||
tok.xkind = pxComma
|
||||
inc(L.bufpos)
|
||||
of '(':
|
||||
inc(L.bufpos)
|
||||
if (L.buf[L.bufPos] == '*'):
|
||||
if (L.buf[L.bufPos + 1] == '$'):
|
||||
inc(L.bufpos, 2)
|
||||
skip(L, tok)
|
||||
getSymbol(L, tok)
|
||||
tok.xkind = pxStarDirLe
|
||||
else:
|
||||
inc(L.bufpos)
|
||||
scanStarComment(L, tok)
|
||||
else:
|
||||
tok.xkind = pxParLe
|
||||
of '*':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == ')':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxStarDirRi
|
||||
else:
|
||||
tok.xkind = pxStar
|
||||
of ')':
|
||||
tok.xkind = pxParRi
|
||||
inc(L.bufpos)
|
||||
of '[':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxBracketLe
|
||||
of ']':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxBracketRi
|
||||
of '.':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '.':
|
||||
tok.xkind = pxDotDot
|
||||
inc(L.bufpos)
|
||||
else:
|
||||
tok.xkind = pxDot
|
||||
of '{':
|
||||
inc(L.bufpos)
|
||||
case L.buf[L.bufpos]
|
||||
of '$':
|
||||
inc(L.bufpos)
|
||||
skip(L, tok)
|
||||
getSymbol(L, tok)
|
||||
tok.xkind = pxCurlyDirLe
|
||||
of '&':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxAmp
|
||||
of '%':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxPer
|
||||
of '@':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxCommand
|
||||
else: scanCurlyComment(L, tok)
|
||||
of '+':
|
||||
tok.xkind = pxPlus
|
||||
inc(L.bufpos)
|
||||
of '-':
|
||||
tok.xkind = pxMinus
|
||||
inc(L.bufpos)
|
||||
of ':':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxAsgn
|
||||
else:
|
||||
tok.xkind = pxColon
|
||||
of '<':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '>':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxNeq
|
||||
elif L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxLe
|
||||
else:
|
||||
tok.xkind = pxLt
|
||||
of '>':
|
||||
inc(L.bufpos)
|
||||
if L.buf[L.bufpos] == '=':
|
||||
inc(L.bufpos)
|
||||
tok.xkind = pxGe
|
||||
else:
|
||||
tok.xkind = pxGt
|
||||
of '=':
|
||||
tok.xkind = pxEquals
|
||||
inc(L.bufpos)
|
||||
of '@':
|
||||
tok.xkind = pxAt
|
||||
inc(L.bufpos)
|
||||
of '^':
|
||||
tok.xkind = pxHat
|
||||
inc(L.bufpos)
|
||||
of '}':
|
||||
tok.xkind = pxCurlyDirRi
|
||||
inc(L.bufpos)
|
||||
of '\'', '#':
|
||||
getString(L, tok)
|
||||
of '$':
|
||||
getNumber16(L, tok)
|
||||
of '%':
|
||||
getNumber2(L, tok)
|
||||
of nimlexbase.EndOfFile:
|
||||
tok.xkind = pxEof
|
||||
else:
|
||||
tok.literal = c & ""
|
||||
tok.xkind = pxInvalid
|
||||
lexMessage(L, errInvalidToken, c & " (\\" & $(ord(c)) & ')')
|
||||
inc(L.bufpos)
|
||||
File diff suppressed because it is too large
Load Diff
295
doc/c2nim.txt
295
doc/c2nim.txt
@@ -1,295 +0,0 @@
|
||||
=======================
|
||||
c2nim User's manual
|
||||
=======================
|
||||
|
||||
:Author: Andreas Rumpf
|
||||
:Version: |nimrodversion|
|
||||
|
||||
.. contents::
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
"We all make choices. But in the end our choices make us."
|
||||
|
||||
|
||||
c2nim is a tool to translate Ansi C code to Nimrod. The output is
|
||||
human-readable Nimrod code that is meant to be tweaked by hand after the
|
||||
translation process. c2nim is no real compiler!
|
||||
|
||||
c2nim is preliminary meant to translate C header files. Because of this, the
|
||||
preprocessor is part of the parser. For example:
|
||||
|
||||
.. code-block:: C
|
||||
#define abc 123
|
||||
#define xyz 789
|
||||
|
||||
Is translated into:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
const
|
||||
abc* = 123
|
||||
xyz* = 789
|
||||
|
||||
|
||||
c2nim is meant to translate fragments of C code and thus does not follow
|
||||
include files. c2nim cannot parse all of Ansi C and many constructs cannot
|
||||
be represented in Nimrod: for example `duff's device`:idx: cannot be translated
|
||||
to Nimrod.
|
||||
|
||||
|
||||
Preprocessor support
|
||||
====================
|
||||
|
||||
Even though the translation process is not perfect, it is often the case that
|
||||
the translated Nimrod code does not need any tweaking by hand. In other cases
|
||||
it may be preferable to modify the input file instead of the generated Nimrod
|
||||
code so that c2nim can parse it properly. c2nim's preprocessor defines the
|
||||
symbol ``C2NIM`` that can be used to mark code sections:
|
||||
|
||||
.. code-block:: C
|
||||
#ifndef C2NIM
|
||||
// C2NIM should ignore this prototype:
|
||||
int fprintf(FILE* f, const char* frmt, ...);
|
||||
#endif
|
||||
|
||||
The ``C2NIM`` symbol is only recognized in ``#ifdef`` and ``#ifndef``
|
||||
constructs! ``#if defined(C2NIM)`` does **not** work.
|
||||
|
||||
c2nim *processes* ``#ifdef C2NIM`` and ``#ifndef C2NIM`` directives, but other
|
||||
``#if[def]`` directives are *translated* into Nimrod's ``when`` construct:
|
||||
|
||||
.. code-block:: C
|
||||
#ifdef DEBUG
|
||||
# define OUT(x) printf("%s\n", x)
|
||||
#else
|
||||
# define OUT(x)
|
||||
#endif
|
||||
|
||||
Is translated into:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
when defined(debug):
|
||||
template OUT*(x: expr): expr =
|
||||
printf("%s\x0A", x)
|
||||
else:
|
||||
template OUT*(x: expr): stmt =
|
||||
discard
|
||||
|
||||
As can been seen from the example, C's macros with parameters are mapped
|
||||
to Nimrod's templates. This mapping is the best one can do, but it is of course
|
||||
not accurate: Nimrod's templates operate on syntax trees whereas C's
|
||||
macros work on the token level. c2nim cannot translate any macro that contains
|
||||
the ``##`` token concatenation operator.
|
||||
|
||||
c2nim's preprocessor supports special directives that affect how the output
|
||||
is generated. They should be put into a ``#ifdef C2NIM`` section so that
|
||||
ordinary C compilers ignore them.
|
||||
|
||||
|
||||
``#skipinclude`` directive
|
||||
--------------------------
|
||||
**Note**: There is also a ``--skipinclude`` command line option that can be
|
||||
used for the same purpose.
|
||||
|
||||
By default, c2nim translates an ``#include`` that is not followed by ``<``
|
||||
(like in ``#include <stdlib>``) to a Nimrod ``import`` statement. This
|
||||
directive tells c2nim to just skip any ``#include``.
|
||||
|
||||
|
||||
``#stdcall`` and ``#cdecl`` directives
|
||||
--------------------------------------
|
||||
**Note**: There are also ``--stdcall`` and ``--cdecl`` command line options
|
||||
that can be used for the same purpose.
|
||||
|
||||
These directives tell c2nim that it should annotate every proc (or proc type)
|
||||
with the ``stdcall`` / ``cdecl`` calling convention.
|
||||
|
||||
|
||||
``#dynlib`` directive
|
||||
---------------------
|
||||
**Note**: There is also a ``--dynlib`` command line option that can be used for
|
||||
the same purpose.
|
||||
|
||||
This directive tells c2nim that it should annotate every proc that resulted
|
||||
from a C function prototype with the ``dynlib`` pragma:
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#ifdef C2NIM
|
||||
# dynlib iupdll
|
||||
# cdecl
|
||||
# if defined(windows)
|
||||
# define iupdll "iup.dll"
|
||||
# elif defined(macosx)
|
||||
# define iupdll "libiup.dylib"
|
||||
# else
|
||||
# define iupdll "libiup.so"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int IupConvertXYToPos(PIhandle ih, int x, int y);
|
||||
|
||||
Is translated to:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
when defined(windows):
|
||||
const iupdll* = "iup.dll"
|
||||
elif defined(macosx):
|
||||
const iupdll* = "libiup.dylib"
|
||||
else:
|
||||
const iupdll* = "libiup.so"
|
||||
|
||||
proc IupConvertXYToPos*(ih: PIhandle, x: cint, y: cint): cint {.
|
||||
importc: "IupConvertXYToPos", cdecl, dynlib: iupdll.}
|
||||
|
||||
Note how the example contains extra C code to declare the ``iupdll`` symbol
|
||||
in the generated Nimrod code.
|
||||
|
||||
|
||||
``#header`` directive
|
||||
---------------------
|
||||
**Note**: There is also a ``--header`` command line option that can be used for
|
||||
the same purpose.
|
||||
|
||||
The ``#header`` directive tells c2nim that it should annotate every proc that
|
||||
resulted from a C function prototype and every exported variable and type with
|
||||
the ``header`` pragma:
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#ifdef C2NIM
|
||||
# header "iup.h"
|
||||
#endif
|
||||
|
||||
int IupConvertXYToPos(PIhandle ih, int x, int y);
|
||||
|
||||
Is translated to:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
proc IupConvertXYToPos*(ih: PIhandle, x: cint, y: cint): cint {.
|
||||
importc: "IupConvertXYToPos", header: "iup.h".}
|
||||
|
||||
The ``#header`` and the ``#dynlib`` directives are mutually exclusive.
|
||||
A binding that uses ``dynlib`` is much more preferable over one that uses
|
||||
``header``! The Nimrod compiler might drop support for the ``header`` pragma
|
||||
in the future as it cannot work for backends that do not generate C code.
|
||||
|
||||
|
||||
``#prefix`` and ``#suffix`` directives
|
||||
--------------------------------------
|
||||
|
||||
**Note**: There are also ``--prefix`` and ``--suffix`` command line options
|
||||
that can be used for the same purpose.
|
||||
|
||||
c2nim does not do any name mangling by default. However the
|
||||
``#prefix`` and ``#suffix`` directives can be used to strip prefixes and
|
||||
suffixes from the identifiers in the C code:
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#ifdef C2NIM
|
||||
# prefix Iup
|
||||
# dynlib dllname
|
||||
# cdecl
|
||||
#endif
|
||||
|
||||
int IupConvertXYToPos(PIhandle ih, int x, int y);
|
||||
|
||||
Is translated to:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
|
||||
proc ConvertXYToPos*(ih: PIhandle, x: cint, y: cint): cint {.
|
||||
importc: "IupConvertXYToPos", cdecl, dynlib: dllname.}
|
||||
|
||||
|
||||
``#mangle`` directive
|
||||
---------------------
|
||||
|
||||
Even more sophisticated name mangling can be achieved by the ``#mangle``
|
||||
directive: It takes a PEG pattern and format string that specify how the
|
||||
identifier should be converted:
|
||||
|
||||
.. code-block:: C
|
||||
#mangle "'GTK_'{.*}" "TGtk$1"
|
||||
|
||||
For convenience the PEG pattern and the replacement can be single identifiers
|
||||
too, there is no need to quote them:
|
||||
|
||||
.. code-block:: C
|
||||
#mangle ssize_t int
|
||||
// is short for:
|
||||
#mangle "'ssize_t'" "int"
|
||||
|
||||
|
||||
``#private`` directive
|
||||
----------------------
|
||||
|
||||
By default c2nim marks every top level identifier (proc name, variable, etc.)
|
||||
as exported (the export marker is ``*`` in Nimrod). With the ``#private``
|
||||
directive identifiers can be marked as private so that the resulting Nimrod
|
||||
module does not export them. The ``#private`` directive takes a PEG pattern:
|
||||
|
||||
.. code-block:: C
|
||||
#private "@('_'!.)" // all identifiers ending in '_' are private
|
||||
|
||||
Note: The pattern refers to the original C identifiers, not to the resulting
|
||||
identifiers after mangling!
|
||||
|
||||
|
||||
``#skipcomments`` directive
|
||||
---------------------------
|
||||
**Note**: There is also a ``--skipcomments`` command line option that can be
|
||||
used for the same purpose.
|
||||
|
||||
The ``#skipcomments`` directive can be put into the C code to make c2nim
|
||||
ignore comments and not copy them into the generated Nimrod file.
|
||||
|
||||
|
||||
``#typeprefixes`` directive
|
||||
---------------------------
|
||||
**Note**: There is also a ``--typeprefixes`` command line option that can be
|
||||
used for the same purpose.
|
||||
|
||||
The ``#typeprefixes`` directive can be put into the C code to make c2nim
|
||||
generate the ``T`` or ``P`` prefix for every defined type.
|
||||
|
||||
|
||||
``#def`` directive
|
||||
------------------
|
||||
|
||||
Often C code contains special macros that affect the declaration of a function
|
||||
prototype but confuse c2nim's parser:
|
||||
|
||||
.. code-block:: C
|
||||
// does not parse!
|
||||
EXTERN(int) f(void);
|
||||
EXTERN(int) g(void);
|
||||
|
||||
Instead of removing ``EXTERN()`` from the input source file (which cannot be
|
||||
done reliably even with a regular expression!), one can tell c2nim
|
||||
that ``EXPORT`` is a macro that should be expanded by c2nim too:
|
||||
|
||||
.. code-block:: C
|
||||
#ifdef C2NIM
|
||||
# def EXTERN(x) static x
|
||||
#endif
|
||||
// parses now!
|
||||
EXTERN(int) f(void);
|
||||
EXTERN(int) g(void);
|
||||
|
||||
``#def`` is very similar to C's ``#define``, so in general the macro definition
|
||||
can be copied and pasted into a ``#def`` directive.
|
||||
|
||||
|
||||
Limitations
|
||||
===========
|
||||
|
||||
* C's ``,`` operator (comma operator) is not supported.
|
||||
* C's ``union`` are translated to Nimrod's objects and only the first field
|
||||
is included in the object type. This way there is a high chance that it is
|
||||
binary compatible to the union.
|
||||
* The condition in a ``do while(condition)`` statement must be ``0``.
|
||||
* Lots of other small issues...
|
||||
|
||||
3
koch.nim
3
koch.nim
@@ -93,10 +93,9 @@ proc buildTool(toolname, args: string) =
|
||||
copyFile(dest="bin"/ splitFile(toolname).name.exe, source=toolname.exe)
|
||||
|
||||
proc inno(args: string) =
|
||||
# make sure we have generated the c2nim and niminst executables:
|
||||
# make sure we have generated the niminst executables:
|
||||
buildTool("tools/niminst/niminst", args)
|
||||
buildTool("tools/nimgrep", args)
|
||||
buildTool("compiler/c2nim/c2nim", args)
|
||||
exec("tools" / "niminst" / "niminst --var:version=$# inno compiler/nimrod" %
|
||||
NimrodVersion)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ when defined(windows):
|
||||
|
||||
const
|
||||
winEncodings = [
|
||||
(1, "OEMCP"), # current OEM codepage
|
||||
(037, "IBM037"), # IBM EBCDIC US-Canada
|
||||
(437, "IBM437"), # OEM United States
|
||||
(500, "IBM500"), # IBM EBCDIC International
|
||||
|
||||
@@ -2990,9 +2990,10 @@ proc locals*(): TObject {.magic: "Locals", noSideEffect.} =
|
||||
## # -> B is 1
|
||||
discard
|
||||
|
||||
proc deepCopy*[T](x: T): T {.magic: "DeepCopy", noSideEffect.} = discard
|
||||
proc deepCopy*[T](x: T): T {.magic: "DeepCopy", noSideEffect.} =
|
||||
## performs a deep copy of `x`. This is also used by the code generator
|
||||
## for the implementation of ``spawn``.
|
||||
discard
|
||||
|
||||
{.pop.} #{.push warning[GcMem]: off.}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
discard """
|
||||
file: "tclosure.nim"
|
||||
output: "2 4 6 8 10"
|
||||
disabled: true
|
||||
output: "1 3 6 11 20"
|
||||
"""
|
||||
# Test the closure implementation
|
||||
|
||||
@@ -30,7 +29,8 @@ proc testA() =
|
||||
testA()
|
||||
|
||||
myData.each do (x: int):
|
||||
write(stout, x)
|
||||
write(stdout, x)
|
||||
write(stdout, " ")
|
||||
|
||||
#OUT 2 4 6 8 10
|
||||
|
||||
@@ -42,6 +42,6 @@ type
|
||||
proc getInterf(): ITest =
|
||||
var shared: int
|
||||
|
||||
return (setter: proc (x) = shared = x,
|
||||
return (setter: proc (x: int) = shared = x,
|
||||
getter: proc (): int = return shared)
|
||||
|
||||
|
||||
32
tests/closure/tjester.nim
Normal file
32
tests/closure/tjester.nim
Normal file
@@ -0,0 +1,32 @@
|
||||
discard """
|
||||
output: '''baro0'''
|
||||
"""
|
||||
|
||||
type
|
||||
Future[T] = ref object
|
||||
data: T
|
||||
callback: proc () {.closure.}
|
||||
|
||||
proc cbOuter(response: string) {.closure, discardable.} =
|
||||
iterator cbIter(): Future[int] {.closure.} =
|
||||
for i in 0..7:
|
||||
proc foo(): int =
|
||||
iterator fooIter(): Future[int] {.closure.} =
|
||||
echo response, i
|
||||
yield Future[int](data: 17)
|
||||
var iterVar = fooIter
|
||||
iterVar().data
|
||||
yield Future[int](data: foo())
|
||||
|
||||
var iterVar2 = cbIter
|
||||
proc cb2() {.closure.} =
|
||||
try:
|
||||
if not finished(iterVar2):
|
||||
let next = iterVar2()
|
||||
if next != nil:
|
||||
next.callback = cb2
|
||||
except:
|
||||
echo "WTF"
|
||||
cb2()
|
||||
|
||||
cbOuter "baro"
|
||||
51
tests/closure/tnestedclosure.nim
Normal file
51
tests/closure/tnestedclosure.nim
Normal file
@@ -0,0 +1,51 @@
|
||||
discard """
|
||||
output: '''foo88
|
||||
23 24foo 88
|
||||
foo88
|
||||
23 24foo 88
|
||||
hohoho'''
|
||||
"""
|
||||
|
||||
# test nested closure
|
||||
proc main(param: int) =
|
||||
var foo = 23
|
||||
proc outer(outerParam: string) =
|
||||
var outerVar = 88
|
||||
echo outerParam, outerVar
|
||||
proc inner() =
|
||||
block Test:
|
||||
echo foo, " ", param, outerParam, " ", outerVar
|
||||
inner()
|
||||
outer("foo")
|
||||
|
||||
# test simple closure within dummy 'main':
|
||||
proc dummy =
|
||||
proc main2(param: int) =
|
||||
var foo = 23
|
||||
proc outer(outerParam: string) =
|
||||
var outerVar = 88
|
||||
echo outerParam, outerVar
|
||||
proc inner() =
|
||||
block Test:
|
||||
echo foo, " ", param, outerParam, " ", outerVar
|
||||
inner()
|
||||
outer("foo")
|
||||
main2(24)
|
||||
|
||||
dummy()
|
||||
|
||||
main(24)
|
||||
|
||||
# Jester + async triggered this bug:
|
||||
proc cbOuter() =
|
||||
var response = "hohoho"
|
||||
block:
|
||||
proc cbIter() =
|
||||
block:
|
||||
proc fooIter() =
|
||||
echo response
|
||||
fooIter()
|
||||
|
||||
cbIter()
|
||||
|
||||
cbOuter()
|
||||
1536
tests/manyloc/keineschweine/lib/gl.nim
Normal file
1536
tests/manyloc/keineschweine/lib/gl.nim
Normal file
File diff suppressed because it is too large
Load Diff
4673
tests/manyloc/keineschweine/lib/glext.nim
Normal file
4673
tests/manyloc/keineschweine/lib/glext.nim
Normal file
File diff suppressed because it is too large
Load Diff
335
tests/manyloc/keineschweine/lib/glu.nim
Normal file
335
tests/manyloc/keineschweine/lib/glu.nim
Normal file
@@ -0,0 +1,335 @@
|
||||
#
|
||||
#
|
||||
# Adaption of the delphi3d.net OpenGL units to FreePascal
|
||||
# Sebastian Guenther (sg@freepascal.org) in 2002
|
||||
# These units are free to use
|
||||
#******************************************************************************
|
||||
# Converted to Delphi by Tom Nuydens (tom@delphi3d.net)
|
||||
# For the latest updates, visit Delphi3D: http://www.delphi3d.net
|
||||
#******************************************************************************
|
||||
|
||||
import
|
||||
GL
|
||||
|
||||
when defined(windows):
|
||||
{.push, callconv: stdcall.}
|
||||
else:
|
||||
{.push, callconv: cdecl.}
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
dllname = "glu32.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
dllname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"
|
||||
else:
|
||||
const
|
||||
dllname = "libGLU.so.1"
|
||||
type
|
||||
TViewPortArray* = array[0..3, TGLint]
|
||||
T16dArray* = array[0..15, TGLdouble]
|
||||
TCallBack* = proc ()
|
||||
T3dArray* = array[0..2, TGLdouble]
|
||||
T4pArray* = array[0..3, Pointer]
|
||||
T4fArray* = array[0..3, TGLfloat]
|
||||
PPointer* = ptr Pointer
|
||||
|
||||
type
|
||||
GLUnurbs*{.final.} = object
|
||||
PGLUnurbs* = ptr GLUnurbs
|
||||
GLUquadric*{.final.} = object
|
||||
PGLUquadric* = ptr GLUquadric
|
||||
GLUtesselator*{.final.} = object
|
||||
PGLUtesselator* = ptr GLUtesselator # backwards compatibility:
|
||||
GLUnurbsObj* = GLUnurbs
|
||||
PGLUnurbsObj* = PGLUnurbs
|
||||
GLUquadricObj* = GLUquadric
|
||||
PGLUquadricObj* = PGLUquadric
|
||||
GLUtesselatorObj* = GLUtesselator
|
||||
PGLUtesselatorObj* = PGLUtesselator
|
||||
GLUtriangulatorObj* = GLUtesselator
|
||||
PGLUtriangulatorObj* = PGLUtesselator
|
||||
TGLUnurbs* = GLUnurbs
|
||||
TGLUquadric* = GLUquadric
|
||||
TGLUtesselator* = GLUtesselator
|
||||
TGLUnurbsObj* = GLUnurbsObj
|
||||
TGLUquadricObj* = GLUquadricObj
|
||||
TGLUtesselatorObj* = GLUtesselatorObj
|
||||
TGLUtriangulatorObj* = GLUtriangulatorObj
|
||||
|
||||
proc gluErrorString*(errCode: TGLenum): cstring{.dynlib: dllname,
|
||||
importc: "gluErrorString".}
|
||||
proc gluErrorUnicodeStringEXT*(errCode: TGLenum): ptr int16{.dynlib: dllname,
|
||||
importc: "gluErrorUnicodeStringEXT".}
|
||||
proc gluGetString*(name: TGLenum): cstring{.dynlib: dllname,
|
||||
importc: "gluGetString".}
|
||||
proc gluOrtho2D*(left, right, bottom, top: TGLdouble){.dynlib: dllname,
|
||||
importc: "gluOrtho2D".}
|
||||
proc gluPerspective*(fovy, aspect, zNear, zFar: TGLdouble){.dynlib: dllname,
|
||||
importc: "gluPerspective".}
|
||||
proc gluPickMatrix*(x, y, width, height: TGLdouble, viewport: var TViewPortArray){.
|
||||
dynlib: dllname, importc: "gluPickMatrix".}
|
||||
proc gluLookAt*(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz: TGLdouble){.
|
||||
dynlib: dllname, importc: "gluLookAt".}
|
||||
proc gluProject*(objx, objy, objz: TGLdouble,
|
||||
modelMatrix, projMatrix: var T16dArray,
|
||||
viewport: var TViewPortArray, winx, winy, winz: PGLdouble): int{.
|
||||
dynlib: dllname, importc: "gluProject".}
|
||||
proc gluUnProject*(winx, winy, winz: TGLdouble,
|
||||
modelMatrix, projMatrix: var T16dArray,
|
||||
viewport: var TViewPortArray, objx, objy, objz: PGLdouble): int{.
|
||||
dynlib: dllname, importc: "gluUnProject".}
|
||||
proc gluScaleImage*(format: TGLenum, widthin, heightin: TGLint, typein: TGLenum,
|
||||
datain: Pointer, widthout, heightout: TGLint,
|
||||
typeout: TGLenum, dataout: Pointer): int{.dynlib: dllname,
|
||||
importc: "gluScaleImage".}
|
||||
proc gluBuild1DMipmaps*(target: TGLenum, components, width: TGLint,
|
||||
format, atype: TGLenum, data: Pointer): int{.
|
||||
dynlib: dllname, importc: "gluBuild1DMipmaps".}
|
||||
proc gluBuild2DMipmaps*(target: TGLenum, components, width, height: TGLint,
|
||||
format, atype: TGLenum, data: Pointer): int{.
|
||||
dynlib: dllname, importc: "gluBuild2DMipmaps".}
|
||||
proc gluNewQuadric*(): PGLUquadric{.dynlib: dllname, importc: "gluNewQuadric".}
|
||||
proc gluDeleteQuadric*(state: PGLUquadric){.dynlib: dllname,
|
||||
importc: "gluDeleteQuadric".}
|
||||
proc gluQuadricNormals*(quadObject: PGLUquadric, normals: TGLenum){.
|
||||
dynlib: dllname, importc: "gluQuadricNormals".}
|
||||
proc gluQuadricTexture*(quadObject: PGLUquadric, textureCoords: TGLboolean){.
|
||||
dynlib: dllname, importc: "gluQuadricTexture".}
|
||||
proc gluQuadricOrientation*(quadObject: PGLUquadric, orientation: TGLenum){.
|
||||
dynlib: dllname, importc: "gluQuadricOrientation".}
|
||||
proc gluQuadricDrawStyle*(quadObject: PGLUquadric, drawStyle: TGLenum){.
|
||||
dynlib: dllname, importc: "gluQuadricDrawStyle".}
|
||||
proc gluCylinder*(qobj: PGLUquadric, baseRadius, topRadius, height: TGLdouble,
|
||||
slices, stacks: TGLint){.dynlib: dllname,
|
||||
importc: "gluCylinder".}
|
||||
proc gluDisk*(qobj: PGLUquadric, innerRadius, outerRadius: TGLdouble,
|
||||
slices, loops: TGLint){.dynlib: dllname, importc: "gluDisk".}
|
||||
proc gluPartialDisk*(qobj: PGLUquadric, innerRadius, outerRadius: TGLdouble,
|
||||
slices, loops: TGLint, startAngle, sweepAngle: TGLdouble){.
|
||||
dynlib: dllname, importc: "gluPartialDisk".}
|
||||
proc gluSphere*(qobj: PGLuquadric, radius: TGLdouble, slices, stacks: TGLint){.
|
||||
dynlib: dllname, importc: "gluSphere".}
|
||||
proc gluQuadricCallback*(qobj: PGLUquadric, which: TGLenum, fn: TCallBack){.
|
||||
dynlib: dllname, importc: "gluQuadricCallback".}
|
||||
proc gluNewTess*(): PGLUtesselator{.dynlib: dllname, importc: "gluNewTess".}
|
||||
proc gluDeleteTess*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluDeleteTess".}
|
||||
proc gluTessBeginPolygon*(tess: PGLUtesselator, polygon_data: Pointer){.
|
||||
dynlib: dllname, importc: "gluTessBeginPolygon".}
|
||||
proc gluTessBeginContour*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluTessBeginContour".}
|
||||
proc gluTessVertex*(tess: PGLUtesselator, coords: var T3dArray, data: Pointer){.
|
||||
dynlib: dllname, importc: "gluTessVertex".}
|
||||
proc gluTessEndContour*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluTessEndContour".}
|
||||
proc gluTessEndPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluTessEndPolygon".}
|
||||
proc gluTessProperty*(tess: PGLUtesselator, which: TGLenum, value: TGLdouble){.
|
||||
dynlib: dllname, importc: "gluTessProperty".}
|
||||
proc gluTessNormal*(tess: PGLUtesselator, x, y, z: TGLdouble){.dynlib: dllname,
|
||||
importc: "gluTessNormal".}
|
||||
proc gluTessCallback*(tess: PGLUtesselator, which: TGLenum, fn: TCallBack){.
|
||||
dynlib: dllname, importc: "gluTessCallback".}
|
||||
proc gluGetTessProperty*(tess: PGLUtesselator, which: TGLenum, value: PGLdouble){.
|
||||
dynlib: dllname, importc: "gluGetTessProperty".}
|
||||
proc gluNewNurbsRenderer*(): PGLUnurbs{.dynlib: dllname,
|
||||
importc: "gluNewNurbsRenderer".}
|
||||
proc gluDeleteNurbsRenderer*(nobj: PGLUnurbs){.dynlib: dllname,
|
||||
importc: "gluDeleteNurbsRenderer".}
|
||||
proc gluBeginSurface*(nobj: PGLUnurbs){.dynlib: dllname,
|
||||
importc: "gluBeginSurface".}
|
||||
proc gluBeginCurve*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluBeginCurve".}
|
||||
proc gluEndCurve*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndCurve".}
|
||||
proc gluEndSurface*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndSurface".}
|
||||
proc gluBeginTrim*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluBeginTrim".}
|
||||
proc gluEndTrim*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndTrim".}
|
||||
proc gluPwlCurve*(nobj: PGLUnurbs, count: TGLint, aarray: PGLfloat,
|
||||
stride: TGLint, atype: TGLenum){.dynlib: dllname,
|
||||
importc: "gluPwlCurve".}
|
||||
proc gluNurbsCurve*(nobj: PGLUnurbs, nknots: TGLint, knot: PGLfloat,
|
||||
stride: TGLint, ctlarray: PGLfloat, order: TGLint,
|
||||
atype: TGLenum){.dynlib: dllname, importc: "gluNurbsCurve".}
|
||||
proc gluNurbsSurface*(nobj: PGLUnurbs, sknot_count: TGLint, sknot: PGLfloat,
|
||||
tknot_count: TGLint, tknot: PGLfloat,
|
||||
s_stride, t_stride: TGLint, ctlarray: PGLfloat,
|
||||
sorder, torder: TGLint, atype: TGLenum){.dynlib: dllname,
|
||||
importc: "gluNurbsSurface".}
|
||||
proc gluLoadSamplingMatrices*(nobj: PGLUnurbs,
|
||||
modelMatrix, projMatrix: var T16dArray,
|
||||
viewport: var TViewPortArray){.dynlib: dllname,
|
||||
importc: "gluLoadSamplingMatrices".}
|
||||
proc gluNurbsProperty*(nobj: PGLUnurbs, aproperty: TGLenum, value: TGLfloat){.
|
||||
dynlib: dllname, importc: "gluNurbsProperty".}
|
||||
proc gluGetNurbsProperty*(nobj: PGLUnurbs, aproperty: TGLenum, value: PGLfloat){.
|
||||
dynlib: dllname, importc: "gluGetNurbsProperty".}
|
||||
proc gluNurbsCallback*(nobj: PGLUnurbs, which: TGLenum, fn: TCallBack){.
|
||||
dynlib: dllname, importc: "gluNurbsCallback".}
|
||||
#*** Callback function prototypes ***
|
||||
type # gluQuadricCallback
|
||||
GLUquadricErrorProc* = proc (p: TGLenum) # gluTessCallback
|
||||
GLUtessBeginProc* = proc (p: TGLenum)
|
||||
GLUtessEdgeFlagProc* = proc (p: TGLboolean)
|
||||
GLUtessVertexProc* = proc (p: Pointer)
|
||||
GLUtessEndProc* = proc ()
|
||||
GLUtessErrorProc* = proc (p: TGLenum)
|
||||
GLUtessCombineProc* = proc (p1: var T3dArray, p2: T4pArray, p3: T4fArray,
|
||||
p4: PPointer)
|
||||
GLUtessBeginDataProc* = proc (p1: TGLenum, p2: Pointer)
|
||||
GLUtessEdgeFlagDataProc* = proc (p1: TGLboolean, p2: Pointer)
|
||||
GLUtessVertexDataProc* = proc (p1, p2: Pointer)
|
||||
GLUtessEndDataProc* = proc (p: Pointer)
|
||||
GLUtessErrorDataProc* = proc (p1: TGLenum, p2: Pointer)
|
||||
GLUtessCombineDataProc* = proc (p1: var T3dArray, p2: var T4pArray,
|
||||
p3: var T4fArray, p4: PPointer, p5: Pointer) #
|
||||
#
|
||||
# gluNurbsCallback
|
||||
GLUnurbsErrorProc* = proc (p: TGLenum) #*** Generic constants ****/
|
||||
|
||||
const # Version
|
||||
GLU_VERSION_1_1* = 1
|
||||
GLU_VERSION_1_2* = 1 # Errors: (return value 0 = no error)
|
||||
GLU_INVALID_ENUM* = 100900
|
||||
GLU_INVALID_VALUE* = 100901
|
||||
GLU_OUT_OF_MEMORY* = 100902
|
||||
GLU_INCOMPATIBLE_GL_VERSION* = 100903 # StringName
|
||||
GLU_VERSION* = 100800
|
||||
GLU_EXTENSIONS* = 100801 # Boolean
|
||||
GLU_TRUE* = GL_TRUE
|
||||
GLU_FALSE* = GL_FALSE #*** Quadric constants ****/
|
||||
# QuadricNormal
|
||||
GLU_SMOOTH* = 100000
|
||||
GLU_FLAT* = 100001
|
||||
GLU_NONE* = 100002 # QuadricDrawStyle
|
||||
GLU_POINT* = 100010
|
||||
GLU_LINE* = 100011
|
||||
GLU_FILL* = 100012
|
||||
GLU_SILHOUETTE* = 100013 # QuadricOrientation
|
||||
GLU_OUTSIDE* = 100020
|
||||
GLU_INSIDE* = 100021 # Callback types:
|
||||
# GLU_ERROR = 100103;
|
||||
#*** Tesselation constants ****/
|
||||
GLU_TESS_MAX_COORD* = 1.00000e+150 # TessProperty
|
||||
GLU_TESS_WINDING_RULE* = 100140
|
||||
GLU_TESS_BOUNDARY_ONLY* = 100141
|
||||
GLU_TESS_TOLERANCE* = 100142 # TessWinding
|
||||
GLU_TESS_WINDING_ODD* = 100130
|
||||
GLU_TESS_WINDING_NONZERO* = 100131
|
||||
GLU_TESS_WINDING_POSITIVE* = 100132
|
||||
GLU_TESS_WINDING_NEGATIVE* = 100133
|
||||
GLU_TESS_WINDING_ABS_GEQ_TWO* = 100134 # TessCallback
|
||||
GLU_TESS_BEGIN* = 100100 # void (CALLBACK*)(TGLenum type)
|
||||
constGLU_TESS_VERTEX* = 100101 # void (CALLBACK*)(void *data)
|
||||
GLU_TESS_END* = 100102 # void (CALLBACK*)(void)
|
||||
GLU_TESS_ERROR* = 100103 # void (CALLBACK*)(TGLenum errno)
|
||||
GLU_TESS_EDGE_FLAG* = 100104 # void (CALLBACK*)(TGLboolean boundaryEdge)
|
||||
GLU_TESS_COMBINE* = 100105 # void (CALLBACK*)(TGLdouble coords[3],
|
||||
# void *data[4],
|
||||
# TGLfloat weight[4],
|
||||
# void **dataOut)
|
||||
GLU_TESS_BEGIN_DATA* = 100106 # void (CALLBACK*)(TGLenum type,
|
||||
# void *polygon_data)
|
||||
GLU_TESS_VERTEX_DATA* = 100107 # void (CALLBACK*)(void *data,
|
||||
# void *polygon_data)
|
||||
GLU_TESS_END_DATA* = 100108 # void (CALLBACK*)(void *polygon_data)
|
||||
GLU_TESS_ERROR_DATA* = 100109 # void (CALLBACK*)(TGLenum errno,
|
||||
# void *polygon_data)
|
||||
GLU_TESS_EDGE_FLAG_DATA* = 100110 # void (CALLBACK*)(TGLboolean boundaryEdge,
|
||||
# void *polygon_data)
|
||||
GLU_TESS_COMBINE_DATA* = 100111 # void (CALLBACK*)(TGLdouble coords[3],
|
||||
# void *data[4],
|
||||
# TGLfloat weight[4],
|
||||
# void **dataOut,
|
||||
# void *polygon_data)
|
||||
# TessError
|
||||
GLU_TESS_ERROR1* = 100151
|
||||
GLU_TESS_ERROR2* = 100152
|
||||
GLU_TESS_ERROR3* = 100153
|
||||
GLU_TESS_ERROR4* = 100154
|
||||
GLU_TESS_ERROR5* = 100155
|
||||
GLU_TESS_ERROR6* = 100156
|
||||
GLU_TESS_ERROR7* = 100157
|
||||
GLU_TESS_ERROR8* = 100158
|
||||
GLU_TESS_MISSING_BEGIN_POLYGON* = GLU_TESS_ERROR1
|
||||
GLU_TESS_MISSING_BEGIN_CONTOUR* = GLU_TESS_ERROR2
|
||||
GLU_TESS_MISSING_END_POLYGON* = GLU_TESS_ERROR3
|
||||
GLU_TESS_MISSING_END_CONTOUR* = GLU_TESS_ERROR4
|
||||
GLU_TESS_COORD_TOO_LARGE* = GLU_TESS_ERROR5
|
||||
GLU_TESS_NEED_COMBINE_CALLBACK* = GLU_TESS_ERROR6 #*** NURBS constants ****/
|
||||
# NurbsProperty
|
||||
GLU_AUTO_LOAD_MATRIX* = 100200
|
||||
GLU_CULLING* = 100201
|
||||
GLU_SAMPLING_TOLERANCE* = 100203
|
||||
GLU_DISPLAY_MODE* = 100204
|
||||
GLU_PARAMETRIC_TOLERANCE* = 100202
|
||||
GLU_SAMPLING_METHOD* = 100205
|
||||
GLU_U_STEP* = 100206
|
||||
GLU_V_STEP* = 100207 # NurbsSampling
|
||||
GLU_PATH_LENGTH* = 100215
|
||||
GLU_PARAMETRIC_ERROR* = 100216
|
||||
GLU_DOMAIN_DISTANCE* = 100217 # NurbsTrim
|
||||
GLU_MAP1_TRIM_2* = 100210
|
||||
GLU_MAP1_TRIM_3* = 100211 # NurbsDisplay
|
||||
# GLU_FILL = 100012;
|
||||
GLU_OUTLINE_POLYGON* = 100240
|
||||
GLU_OUTLINE_PATCH* = 100241 # NurbsCallback
|
||||
# GLU_ERROR = 100103;
|
||||
# NurbsErrors
|
||||
GLU_NURBS_ERROR1* = 100251
|
||||
GLU_NURBS_ERROR2* = 100252
|
||||
GLU_NURBS_ERROR3* = 100253
|
||||
GLU_NURBS_ERROR4* = 100254
|
||||
GLU_NURBS_ERROR5* = 100255
|
||||
GLU_NURBS_ERROR6* = 100256
|
||||
GLU_NURBS_ERROR7* = 100257
|
||||
GLU_NURBS_ERROR8* = 100258
|
||||
GLU_NURBS_ERROR9* = 100259
|
||||
GLU_NURBS_ERROR10* = 100260
|
||||
GLU_NURBS_ERROR11* = 100261
|
||||
GLU_NURBS_ERROR12* = 100262
|
||||
GLU_NURBS_ERROR13* = 100263
|
||||
GLU_NURBS_ERROR14* = 100264
|
||||
GLU_NURBS_ERROR15* = 100265
|
||||
GLU_NURBS_ERROR16* = 100266
|
||||
GLU_NURBS_ERROR17* = 100267
|
||||
GLU_NURBS_ERROR18* = 100268
|
||||
GLU_NURBS_ERROR19* = 100269
|
||||
GLU_NURBS_ERROR20* = 100270
|
||||
GLU_NURBS_ERROR21* = 100271
|
||||
GLU_NURBS_ERROR22* = 100272
|
||||
GLU_NURBS_ERROR23* = 100273
|
||||
GLU_NURBS_ERROR24* = 100274
|
||||
GLU_NURBS_ERROR25* = 100275
|
||||
GLU_NURBS_ERROR26* = 100276
|
||||
GLU_NURBS_ERROR27* = 100277
|
||||
GLU_NURBS_ERROR28* = 100278
|
||||
GLU_NURBS_ERROR29* = 100279
|
||||
GLU_NURBS_ERROR30* = 100280
|
||||
GLU_NURBS_ERROR31* = 100281
|
||||
GLU_NURBS_ERROR32* = 100282
|
||||
GLU_NURBS_ERROR33* = 100283
|
||||
GLU_NURBS_ERROR34* = 100284
|
||||
GLU_NURBS_ERROR35* = 100285
|
||||
GLU_NURBS_ERROR36* = 100286
|
||||
GLU_NURBS_ERROR37* = 100287 #*** Backwards compatibility for old tesselator ****/
|
||||
|
||||
proc gluBeginPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluBeginPolygon".}
|
||||
proc gluNextContour*(tess: PGLUtesselator, atype: TGLenum){.dynlib: dllname,
|
||||
importc: "gluNextContour".}
|
||||
proc gluEndPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
||||
importc: "gluEndPolygon".}
|
||||
const # Contours types -- obsolete!
|
||||
GLU_CW* = 100120
|
||||
GLU_CCW* = 100121
|
||||
GLU_INTERIOR* = 100122
|
||||
GLU_EXTERIOR* = 100123
|
||||
GLU_UNKNOWN* = 100124 # Names without "TESS_" prefix
|
||||
GLU_BEGIN* = GLU_TESS_BEGIN
|
||||
GLU_VERTEX* = constGLU_TESS_VERTEX
|
||||
GLU_END* = GLU_TESS_END
|
||||
GLU_ERROR* = GLU_TESS_ERROR
|
||||
GLU_EDGE_FLAG* = GLU_TESS_EDGE_FLAG
|
||||
|
||||
{.pop.}
|
||||
# implementation
|
||||
438
tests/manyloc/keineschweine/lib/glut.nim
Normal file
438
tests/manyloc/keineschweine/lib/glut.nim
Normal file
@@ -0,0 +1,438 @@
|
||||
#
|
||||
#
|
||||
# Adaption of the delphi3d.net OpenGL units to FreePascal
|
||||
# Sebastian Guenther (sg@freepascal.org) in 2002
|
||||
# These units are free to use
|
||||
#
|
||||
|
||||
# Copyright (c) Mark J. Kilgard, 1994, 1995, 1996.
|
||||
# This program is freely distributable without licensing fees and is
|
||||
# provided without guarantee or warrantee expressed or implied. This
|
||||
# program is -not- in the public domain.
|
||||
#******************************************************************************
|
||||
# Converted to Delphi by Tom Nuydens (tom@delphi3d.net)
|
||||
# Contributions by Igor Karpov (glygrik@hotbox.ru)
|
||||
# For the latest updates, visit Delphi3D: http://www.delphi3d.net
|
||||
#******************************************************************************
|
||||
|
||||
import
|
||||
GL
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
dllname = "glut32.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
dllname = "/System/Library/Frameworks/GLUT.framework/GLUT"
|
||||
else:
|
||||
const
|
||||
dllname = "libglut.so.3"
|
||||
type
|
||||
TGlutVoidCallback* = proc (){.cdecl.}
|
||||
TGlut1IntCallback* = proc (value: cint){.cdecl.}
|
||||
TGlut2IntCallback* = proc (v1, v2: cint){.cdecl.}
|
||||
TGlut3IntCallback* = proc (v1, v2, v3: cint){.cdecl.}
|
||||
TGlut4IntCallback* = proc (v1, v2, v3, v4: cint){.cdecl.}
|
||||
TGlut1Char2IntCallback* = proc (c: int8, v1, v2: cint){.cdecl.}
|
||||
TGlut1UInt3IntCallback* = proc (u, v1, v2, v3: cint){.cdecl.}
|
||||
|
||||
const
|
||||
GLUT_API_VERSION* = 3
|
||||
GLUT_XLIB_IMPLEMENTATION* = 12 # Display mode bit masks.
|
||||
GLUT_RGB* = 0
|
||||
GLUT_RGBA* = GLUT_RGB
|
||||
GLUT_INDEX* = 1
|
||||
GLUT_SINGLE* = 0
|
||||
GLUT_DOUBLE* = 2
|
||||
GLUT_ACCUM* = 4
|
||||
GLUT_ALPHA* = 8
|
||||
GLUT_DEPTH* = 16
|
||||
GLUT_STENCIL* = 32
|
||||
GLUT_MULTISAMPLE* = 128
|
||||
GLUT_STEREO* = 256
|
||||
GLUT_LUMINANCE* = 512 # Mouse buttons.
|
||||
GLUT_LEFT_BUTTON* = 0
|
||||
GLUT_MIDDLE_BUTTON* = 1
|
||||
GLUT_RIGHT_BUTTON* = 2 # Mouse button state.
|
||||
GLUT_DOWN* = 0
|
||||
GLUT_UP* = 1 # function keys
|
||||
GLUT_KEY_F1* = 1
|
||||
GLUT_KEY_F2* = 2
|
||||
GLUT_KEY_F3* = 3
|
||||
GLUT_KEY_F4* = 4
|
||||
GLUT_KEY_F5* = 5
|
||||
GLUT_KEY_F6* = 6
|
||||
GLUT_KEY_F7* = 7
|
||||
GLUT_KEY_F8* = 8
|
||||
GLUT_KEY_F9* = 9
|
||||
GLUT_KEY_F10* = 10
|
||||
GLUT_KEY_F11* = 11
|
||||
GLUT_KEY_F12* = 12 # directional keys
|
||||
GLUT_KEY_LEFT* = 100
|
||||
GLUT_KEY_UP* = 101
|
||||
GLUT_KEY_RIGHT* = 102
|
||||
GLUT_KEY_DOWN* = 103
|
||||
GLUT_KEY_PAGE_UP* = 104
|
||||
GLUT_KEY_PAGE_DOWN* = 105
|
||||
GLUT_KEY_HOME* = 106
|
||||
GLUT_KEY_END* = 107
|
||||
GLUT_KEY_INSERT* = 108 # Entry/exit state.
|
||||
GLUT_LEFT* = 0
|
||||
GLUT_ENTERED* = 1 # Menu usage state.
|
||||
GLUT_MENU_NOT_IN_USE* = 0
|
||||
GLUT_MENU_IN_USE* = 1 # Visibility state.
|
||||
GLUT_NOT_VISIBLE* = 0
|
||||
GLUT_VISIBLE* = 1 # Window status state.
|
||||
GLUT_HIDDEN* = 0
|
||||
GLUT_FULLY_RETAINED* = 1
|
||||
GLUT_PARTIALLY_RETAINED* = 2
|
||||
GLUT_FULLY_COVERED* = 3 # Color index component selection values.
|
||||
GLUT_RED* = 0
|
||||
GLUT_GREEN* = 1
|
||||
GLUT_BLUE* = 2 # Layers for use.
|
||||
GLUT_NORMAL* = 0
|
||||
GLUT_OVERLAY* = 1
|
||||
|
||||
when defined(Windows):
|
||||
const # Stroke font constants (use these in GLUT program).
|
||||
GLUT_STROKE_ROMAN* = cast[Pointer](0)
|
||||
GLUT_STROKE_MONO_ROMAN* = cast[Pointer](1) # Bitmap font constants (use these in GLUT program).
|
||||
GLUT_BITMAP_9_BY_15* = cast[Pointer](2)
|
||||
GLUT_BITMAP_8_BY_13* = cast[Pointer](3)
|
||||
GLUT_BITMAP_TIMES_ROMAN_10* = cast[Pointer](4)
|
||||
GLUT_BITMAP_TIMES_ROMAN_24* = cast[Pointer](5)
|
||||
GLUT_BITMAP_HELVETICA_10* = cast[Pointer](6)
|
||||
GLUT_BITMAP_HELVETICA_12* = cast[Pointer](7)
|
||||
GLUT_BITMAP_HELVETICA_18* = cast[Pointer](8)
|
||||
else:
|
||||
var # Stroke font constants (use these in GLUT program).
|
||||
GLUT_STROKE_ROMAN*: Pointer
|
||||
GLUT_STROKE_MONO_ROMAN*: Pointer # Bitmap font constants (use these in GLUT program).
|
||||
GLUT_BITMAP_9_BY_15*: Pointer
|
||||
GLUT_BITMAP_8_BY_13*: Pointer
|
||||
GLUT_BITMAP_TIMES_ROMAN_10*: Pointer
|
||||
GLUT_BITMAP_TIMES_ROMAN_24*: Pointer
|
||||
GLUT_BITMAP_HELVETICA_10*: Pointer
|
||||
GLUT_BITMAP_HELVETICA_12*: Pointer
|
||||
GLUT_BITMAP_HELVETICA_18*: Pointer
|
||||
const # glutGet parameters.
|
||||
GLUT_WINDOW_X* = 100
|
||||
GLUT_WINDOW_Y* = 101
|
||||
GLUT_WINDOW_WIDTH* = 102
|
||||
GLUT_WINDOW_HEIGHT* = 103
|
||||
GLUT_WINDOW_BUFFER_SIZE* = 104
|
||||
GLUT_WINDOW_STENCIL_SIZE* = 105
|
||||
GLUT_WINDOW_DEPTH_SIZE* = 106
|
||||
GLUT_WINDOW_RED_SIZE* = 107
|
||||
GLUT_WINDOW_GREEN_SIZE* = 108
|
||||
GLUT_WINDOW_BLUE_SIZE* = 109
|
||||
GLUT_WINDOW_ALPHA_SIZE* = 110
|
||||
GLUT_WINDOW_ACCUM_RED_SIZE* = 111
|
||||
GLUT_WINDOW_ACCUM_GREEN_SIZE* = 112
|
||||
GLUT_WINDOW_ACCUM_BLUE_SIZE* = 113
|
||||
GLUT_WINDOW_ACCUM_ALPHA_SIZE* = 114
|
||||
GLUT_WINDOW_DOUBLEBUFFER* = 115
|
||||
GLUT_WINDOW_RGBA* = 116
|
||||
GLUT_WINDOW_PARENT* = 117
|
||||
GLUT_WINDOW_NUM_CHILDREN* = 118
|
||||
GLUT_WINDOW_COLORMAP_SIZE* = 119
|
||||
GLUT_WINDOW_NUM_SAMPLES* = 120
|
||||
GLUT_WINDOW_STEREO* = 121
|
||||
GLUT_WINDOW_CURSOR* = 122
|
||||
GLUT_SCREEN_WIDTH* = 200
|
||||
GLUT_SCREEN_HEIGHT* = 201
|
||||
GLUT_SCREEN_WIDTH_MM* = 202
|
||||
GLUT_SCREEN_HEIGHT_MM* = 203
|
||||
GLUT_MENU_NUM_ITEMS* = 300
|
||||
GLUT_DISPLAY_MODE_POSSIBLE* = 400
|
||||
GLUT_INIT_WINDOW_X* = 500
|
||||
GLUT_INIT_WINDOW_Y* = 501
|
||||
GLUT_INIT_WINDOW_WIDTH* = 502
|
||||
GLUT_INIT_WINDOW_HEIGHT* = 503
|
||||
constGLUT_INIT_DISPLAY_MODE* = 504
|
||||
GLUT_ELAPSED_TIME* = 700
|
||||
GLUT_WINDOW_FORMAT_ID* = 123 # glutDeviceGet parameters.
|
||||
GLUT_HAS_KEYBOARD* = 600
|
||||
GLUT_HAS_MOUSE* = 601
|
||||
GLUT_HAS_SPACEBALL* = 602
|
||||
GLUT_HAS_DIAL_AND_BUTTON_BOX* = 603
|
||||
GLUT_HAS_TABLET* = 604
|
||||
GLUT_NUM_MOUSE_BUTTONS* = 605
|
||||
GLUT_NUM_SPACEBALL_BUTTONS* = 606
|
||||
GLUT_NUM_BUTTON_BOX_BUTTONS* = 607
|
||||
GLUT_NUM_DIALS* = 608
|
||||
GLUT_NUM_TABLET_BUTTONS* = 609
|
||||
GLUT_DEVICE_IGNORE_KEY_REPEAT* = 610
|
||||
GLUT_DEVICE_KEY_REPEAT* = 611
|
||||
GLUT_HAS_JOYSTICK* = 612
|
||||
GLUT_OWNS_JOYSTICK* = 613
|
||||
GLUT_JOYSTICK_BUTTONS* = 614
|
||||
GLUT_JOYSTICK_AXES* = 615
|
||||
GLUT_JOYSTICK_POLL_RATE* = 616 # glutLayerGet parameters.
|
||||
GLUT_OVERLAY_POSSIBLE* = 800
|
||||
GLUT_LAYER_IN_USE* = 801
|
||||
GLUT_HAS_OVERLAY* = 802
|
||||
GLUT_TRANSPARENT_INDEX* = 803
|
||||
GLUT_NORMAL_DAMAGED* = 804
|
||||
GLUT_OVERLAY_DAMAGED* = 805 # glutVideoResizeGet parameters.
|
||||
GLUT_VIDEO_RESIZE_POSSIBLE* = 900
|
||||
GLUT_VIDEO_RESIZE_IN_USE* = 901
|
||||
GLUT_VIDEO_RESIZE_X_DELTA* = 902
|
||||
GLUT_VIDEO_RESIZE_Y_DELTA* = 903
|
||||
GLUT_VIDEO_RESIZE_WIDTH_DELTA* = 904
|
||||
GLUT_VIDEO_RESIZE_HEIGHT_DELTA* = 905
|
||||
GLUT_VIDEO_RESIZE_X* = 906
|
||||
GLUT_VIDEO_RESIZE_Y* = 907
|
||||
GLUT_VIDEO_RESIZE_WIDTH* = 908
|
||||
GLUT_VIDEO_RESIZE_HEIGHT* = 909 # glutGetModifiers return mask.
|
||||
GLUT_ACTIVE_SHIFT* = 1
|
||||
GLUT_ACTIVE_CTRL* = 2
|
||||
GLUT_ACTIVE_ALT* = 4 # glutSetCursor parameters.
|
||||
# Basic arrows.
|
||||
GLUT_CURSOR_RIGHT_ARROW* = 0
|
||||
GLUT_CURSOR_LEFT_ARROW* = 1 # Symbolic cursor shapes.
|
||||
GLUT_CURSOR_INFO* = 2
|
||||
GLUT_CURSOR_DESTROY* = 3
|
||||
GLUT_CURSOR_HELP* = 4
|
||||
GLUT_CURSOR_CYCLE* = 5
|
||||
GLUT_CURSOR_SPRAY* = 6
|
||||
GLUT_CURSOR_WAIT* = 7
|
||||
GLUT_CURSOR_TEXT* = 8
|
||||
GLUT_CURSOR_CROSSHAIR* = 9 # Directional cursors.
|
||||
GLUT_CURSOR_UP_DOWN* = 10
|
||||
GLUT_CURSOR_LEFT_RIGHT* = 11 # Sizing cursors.
|
||||
GLUT_CURSOR_TOP_SIDE* = 12
|
||||
GLUT_CURSOR_BOTTOM_SIDE* = 13
|
||||
GLUT_CURSOR_LEFT_SIDE* = 14
|
||||
GLUT_CURSOR_RIGHT_SIDE* = 15
|
||||
GLUT_CURSOR_TOP_LEFT_CORNER* = 16
|
||||
GLUT_CURSOR_TOP_RIGHT_CORNER* = 17
|
||||
GLUT_CURSOR_BOTTOM_RIGHT_CORNER* = 18
|
||||
GLUT_CURSOR_BOTTOM_LEFT_CORNER* = 19 # Inherit from parent window.
|
||||
GLUT_CURSOR_INHERIT* = 100 # Blank cursor.
|
||||
GLUT_CURSOR_NONE* = 101 # Fullscreen crosshair (if available).
|
||||
GLUT_CURSOR_FULL_CROSSHAIR* = 102 # GLUT device control sub-API.
|
||||
# glutSetKeyRepeat modes.
|
||||
GLUT_KEY_REPEAT_OFF* = 0
|
||||
GLUT_KEY_REPEAT_ON* = 1
|
||||
GLUT_KEY_REPEAT_DEFAULT* = 2 # Joystick button masks.
|
||||
GLUT_JOYSTICK_BUTTON_A* = 1
|
||||
GLUT_JOYSTICK_BUTTON_B* = 2
|
||||
GLUT_JOYSTICK_BUTTON_C* = 4
|
||||
GLUT_JOYSTICK_BUTTON_D* = 8 # GLUT game mode sub-API.
|
||||
# glutGameModeGet.
|
||||
GLUT_GAME_MODE_ACTIVE* = 0
|
||||
GLUT_GAME_MODE_POSSIBLE* = 1
|
||||
GLUT_GAME_MODE_WIDTH* = 2
|
||||
GLUT_GAME_MODE_HEIGHT* = 3
|
||||
GLUT_GAME_MODE_PIXEL_DEPTH* = 4
|
||||
GLUT_GAME_MODE_REFRESH_RATE* = 5
|
||||
GLUT_GAME_MODE_DISPLAY_CHANGED* = 6 # GLUT initialization sub-API.
|
||||
|
||||
proc glutInit*(argcp: ptr cint, argv: pointer){.dynlib: dllname,
|
||||
importc: "glutInit".}
|
||||
|
||||
proc glutInit*() =
|
||||
## version that passes `argc` and `argc` implicitely.
|
||||
var
|
||||
cmdLine {.importc: "cmdLine".}: array[0..255, cstring]
|
||||
cmdCount {.importc: "cmdCount".}: cint
|
||||
glutInit(addr(cmdCount), addr(cmdLine))
|
||||
|
||||
proc glutInitDisplayMode*(mode: int16){.dynlib: dllname,
|
||||
importc: "glutInitDisplayMode".}
|
||||
proc glutInitDisplayString*(str: cstring){.dynlib: dllname,
|
||||
importc: "glutInitDisplayString".}
|
||||
proc glutInitWindowPosition*(x, y: int){.dynlib: dllname,
|
||||
importc: "glutInitWindowPosition".}
|
||||
proc glutInitWindowSize*(width, height: int){.dynlib: dllname,
|
||||
importc: "glutInitWindowSize".}
|
||||
proc glutMainLoop*(){.dynlib: dllname, importc: "glutMainLoop".}
|
||||
# GLUT window sub-API.
|
||||
proc glutCreateWindow*(title: cstring): int{.dynlib: dllname,
|
||||
importc: "glutCreateWindow".}
|
||||
proc glutCreateSubWindow*(win, x, y, width, height: int): int{.dynlib: dllname,
|
||||
importc: "glutCreateSubWindow".}
|
||||
proc glutDestroyWindow*(win: int){.dynlib: dllname, importc: "glutDestroyWindow".}
|
||||
proc glutPostRedisplay*(){.dynlib: dllname, importc: "glutPostRedisplay".}
|
||||
proc glutPostWindowRedisplay*(win: int){.dynlib: dllname,
|
||||
importc: "glutPostWindowRedisplay".}
|
||||
proc glutSwapBuffers*(){.dynlib: dllname, importc: "glutSwapBuffers".}
|
||||
proc glutGetWindow*(): int{.dynlib: dllname, importc: "glutGetWindow".}
|
||||
proc glutSetWindow*(win: int){.dynlib: dllname, importc: "glutSetWindow".}
|
||||
proc glutSetWindowTitle*(title: cstring){.dynlib: dllname,
|
||||
importc: "glutSetWindowTitle".}
|
||||
proc glutSetIconTitle*(title: cstring){.dynlib: dllname,
|
||||
importc: "glutSetIconTitle".}
|
||||
proc glutPositionWindow*(x, y: int){.dynlib: dllname,
|
||||
importc: "glutPositionWindow".}
|
||||
proc glutReshapeWindow*(width, height: int){.dynlib: dllname,
|
||||
importc: "glutReshapeWindow".}
|
||||
proc glutPopWindow*(){.dynlib: dllname, importc: "glutPopWindow".}
|
||||
proc glutPushWindow*(){.dynlib: dllname, importc: "glutPushWindow".}
|
||||
proc glutIconifyWindow*(){.dynlib: dllname, importc: "glutIconifyWindow".}
|
||||
proc glutShowWindow*(){.dynlib: dllname, importc: "glutShowWindow".}
|
||||
proc glutHideWindow*(){.dynlib: dllname, importc: "glutHideWindow".}
|
||||
proc glutFullScreen*(){.dynlib: dllname, importc: "glutFullScreen".}
|
||||
proc glutSetCursor*(cursor: int){.dynlib: dllname, importc: "glutSetCursor".}
|
||||
proc glutWarpPointer*(x, y: int){.dynlib: dllname, importc: "glutWarpPointer".}
|
||||
# GLUT overlay sub-API.
|
||||
proc glutEstablishOverlay*(){.dynlib: dllname, importc: "glutEstablishOverlay".}
|
||||
proc glutRemoveOverlay*(){.dynlib: dllname, importc: "glutRemoveOverlay".}
|
||||
proc glutUseLayer*(layer: TGLenum){.dynlib: dllname, importc: "glutUseLayer".}
|
||||
proc glutPostOverlayRedisplay*(){.dynlib: dllname,
|
||||
importc: "glutPostOverlayRedisplay".}
|
||||
proc glutPostWindowOverlayRedisplay*(win: int){.dynlib: dllname,
|
||||
importc: "glutPostWindowOverlayRedisplay".}
|
||||
proc glutShowOverlay*(){.dynlib: dllname, importc: "glutShowOverlay".}
|
||||
proc glutHideOverlay*(){.dynlib: dllname, importc: "glutHideOverlay".}
|
||||
# GLUT menu sub-API.
|
||||
proc glutCreateMenu*(callback: TGlut1IntCallback): int{.dynlib: dllname,
|
||||
importc: "glutCreateMenu".}
|
||||
proc glutDestroyMenu*(menu: int){.dynlib: dllname, importc: "glutDestroyMenu".}
|
||||
proc glutGetMenu*(): int{.dynlib: dllname, importc: "glutGetMenu".}
|
||||
proc glutSetMenu*(menu: int){.dynlib: dllname, importc: "glutSetMenu".}
|
||||
proc glutAddMenuEntry*(caption: cstring, value: int){.dynlib: dllname,
|
||||
importc: "glutAddMenuEntry".}
|
||||
proc glutAddSubMenu*(caption: cstring, submenu: int){.dynlib: dllname,
|
||||
importc: "glutAddSubMenu".}
|
||||
proc glutChangeToMenuEntry*(item: int, caption: cstring, value: int){.
|
||||
dynlib: dllname, importc: "glutChangeToMenuEntry".}
|
||||
proc glutChangeToSubMenu*(item: int, caption: cstring, submenu: int){.
|
||||
dynlib: dllname, importc: "glutChangeToSubMenu".}
|
||||
proc glutRemoveMenuItem*(item: int){.dynlib: dllname,
|
||||
importc: "glutRemoveMenuItem".}
|
||||
proc glutAttachMenu*(button: int){.dynlib: dllname, importc: "glutAttachMenu".}
|
||||
proc glutDetachMenu*(button: int){.dynlib: dllname, importc: "glutDetachMenu".}
|
||||
# GLUT window callback sub-API.
|
||||
proc glutDisplayFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
||||
importc: "glutDisplayFunc".}
|
||||
proc glutReshapeFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutReshapeFunc".}
|
||||
proc glutKeyboardFunc*(f: TGlut1Char2IntCallback){.dynlib: dllname,
|
||||
importc: "glutKeyboardFunc".}
|
||||
proc glutMouseFunc*(f: TGlut4IntCallback){.dynlib: dllname,
|
||||
importc: "glutMouseFunc".}
|
||||
proc glutMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutMotionFunc".}
|
||||
proc glutPassiveMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutPassiveMotionFunc".}
|
||||
proc glutEntryFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
||||
importc: "glutEntryFunc".}
|
||||
proc glutVisibilityFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
||||
importc: "glutVisibilityFunc".}
|
||||
proc glutIdleFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
||||
importc: "glutIdleFunc".}
|
||||
proc glutTimerFunc*(millis: int16, f: TGlut1IntCallback, value: int){.
|
||||
dynlib: dllname, importc: "glutTimerFunc".}
|
||||
proc glutMenuStateFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
||||
importc: "glutMenuStateFunc".}
|
||||
proc glutSpecialFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
||||
importc: "glutSpecialFunc".}
|
||||
proc glutSpaceballMotionFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
||||
importc: "glutSpaceballMotionFunc".}
|
||||
proc glutSpaceballRotateFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
||||
importc: "glutSpaceballRotateFunc".}
|
||||
proc glutSpaceballButtonFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutSpaceballButtonFunc".}
|
||||
proc glutButtonBoxFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutButtonBoxFunc".}
|
||||
proc glutDialsFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutDialsFunc".}
|
||||
proc glutTabletMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
||||
importc: "glutTabletMotionFunc".}
|
||||
proc glutTabletButtonFunc*(f: TGlut4IntCallback){.dynlib: dllname,
|
||||
importc: "glutTabletButtonFunc".}
|
||||
proc glutMenuStatusFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
||||
importc: "glutMenuStatusFunc".}
|
||||
proc glutOverlayDisplayFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
||||
importc: "glutOverlayDisplayFunc".}
|
||||
proc glutWindowStatusFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
||||
importc: "glutWindowStatusFunc".}
|
||||
proc glutKeyboardUpFunc*(f: TGlut1Char2IntCallback){.dynlib: dllname,
|
||||
importc: "glutKeyboardUpFunc".}
|
||||
proc glutSpecialUpFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
||||
importc: "glutSpecialUpFunc".}
|
||||
proc glutJoystickFunc*(f: TGlut1UInt3IntCallback, pollInterval: int){.
|
||||
dynlib: dllname, importc: "glutJoystickFunc".}
|
||||
# GLUT color index sub-API.
|
||||
proc glutSetColor*(cell: int, red, green, blue: TGLfloat){.dynlib: dllname,
|
||||
importc: "glutSetColor".}
|
||||
proc glutGetColor*(ndx, component: int): TGLfloat{.dynlib: dllname,
|
||||
importc: "glutGetColor".}
|
||||
proc glutCopyColormap*(win: int){.dynlib: dllname, importc: "glutCopyColormap".}
|
||||
# GLUT state retrieval sub-API.
|
||||
proc glutGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutGet".}
|
||||
proc glutDeviceGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutDeviceGet".}
|
||||
# GLUT extension support sub-API
|
||||
proc glutExtensionSupported*(name: cstring): int{.dynlib: dllname,
|
||||
importc: "glutExtensionSupported".}
|
||||
proc glutGetModifiers*(): int{.dynlib: dllname, importc: "glutGetModifiers".}
|
||||
proc glutLayerGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutLayerGet".}
|
||||
# GLUT font sub-API
|
||||
proc glutBitmapCharacter*(font: pointer, character: int){.dynlib: dllname,
|
||||
importc: "glutBitmapCharacter".}
|
||||
proc glutBitmapWidth*(font: pointer, character: int): int{.dynlib: dllname,
|
||||
importc: "glutBitmapWidth".}
|
||||
proc glutStrokeCharacter*(font: pointer, character: int){.dynlib: dllname,
|
||||
importc: "glutStrokeCharacter".}
|
||||
proc glutStrokeWidth*(font: pointer, character: int): int{.dynlib: dllname,
|
||||
importc: "glutStrokeWidth".}
|
||||
proc glutBitmapLength*(font: pointer, str: cstring): int{.dynlib: dllname,
|
||||
importc: "glutBitmapLength".}
|
||||
proc glutStrokeLength*(font: pointer, str: cstring): int{.dynlib: dllname,
|
||||
importc: "glutStrokeLength".}
|
||||
# GLUT pre-built models sub-API
|
||||
proc glutWireSphere*(radius: TGLdouble, slices, stacks: TGLint){.
|
||||
dynlib: dllname, importc: "glutWireSphere".}
|
||||
proc glutSolidSphere*(radius: TGLdouble, slices, stacks: TGLint){.
|
||||
dynlib: dllname, importc: "glutSolidSphere".}
|
||||
proc glutWireCone*(base, height: TGLdouble, slices, stacks: TGLint){.
|
||||
dynlib: dllname, importc: "glutWireCone".}
|
||||
proc glutSolidCone*(base, height: TGLdouble, slices, stacks: TGLint){.
|
||||
dynlib: dllname, importc: "glutSolidCone".}
|
||||
proc glutWireCube*(size: TGLdouble){.dynlib: dllname, importc: "glutWireCube".}
|
||||
proc glutSolidCube*(size: TGLdouble){.dynlib: dllname, importc: "glutSolidCube".}
|
||||
proc glutWireTorus*(innerRadius, outerRadius: TGLdouble, sides, rings: TGLint){.
|
||||
dynlib: dllname, importc: "glutWireTorus".}
|
||||
proc glutSolidTorus*(innerRadius, outerRadius: TGLdouble, sides, rings: TGLint){.
|
||||
dynlib: dllname, importc: "glutSolidTorus".}
|
||||
proc glutWireDodecahedron*(){.dynlib: dllname, importc: "glutWireDodecahedron".}
|
||||
proc glutSolidDodecahedron*(){.dynlib: dllname, importc: "glutSolidDodecahedron".}
|
||||
proc glutWireTeapot*(size: TGLdouble){.dynlib: dllname,
|
||||
importc: "glutWireTeapot".}
|
||||
proc glutSolidTeapot*(size: TGLdouble){.dynlib: dllname,
|
||||
importc: "glutSolidTeapot".}
|
||||
proc glutWireOctahedron*(){.dynlib: dllname, importc: "glutWireOctahedron".}
|
||||
proc glutSolidOctahedron*(){.dynlib: dllname, importc: "glutSolidOctahedron".}
|
||||
proc glutWireTetrahedron*(){.dynlib: dllname, importc: "glutWireTetrahedron".}
|
||||
proc glutSolidTetrahedron*(){.dynlib: dllname, importc: "glutSolidTetrahedron".}
|
||||
proc glutWireIcosahedron*(){.dynlib: dllname, importc: "glutWireIcosahedron".}
|
||||
proc glutSolidIcosahedron*(){.dynlib: dllname, importc: "glutSolidIcosahedron".}
|
||||
# GLUT video resize sub-API.
|
||||
proc glutVideoResizeGet*(param: TGLenum): int{.dynlib: dllname,
|
||||
importc: "glutVideoResizeGet".}
|
||||
proc glutSetupVideoResizing*(){.dynlib: dllname,
|
||||
importc: "glutSetupVideoResizing".}
|
||||
proc glutStopVideoResizing*(){.dynlib: dllname, importc: "glutStopVideoResizing".}
|
||||
proc glutVideoResize*(x, y, width, height: int){.dynlib: dllname,
|
||||
importc: "glutVideoResize".}
|
||||
proc glutVideoPan*(x, y, width, height: int){.dynlib: dllname,
|
||||
importc: "glutVideoPan".}
|
||||
# GLUT debugging sub-API.
|
||||
proc glutReportErrors*(){.dynlib: dllname, importc: "glutReportErrors".}
|
||||
# GLUT device control sub-API.
|
||||
proc glutIgnoreKeyRepeat*(ignore: int){.dynlib: dllname,
|
||||
importc: "glutIgnoreKeyRepeat".}
|
||||
proc glutSetKeyRepeat*(repeatMode: int){.dynlib: dllname,
|
||||
importc: "glutSetKeyRepeat".}
|
||||
proc glutForceJoystickFunc*(){.dynlib: dllname, importc: "glutForceJoystickFunc".}
|
||||
# GLUT game mode sub-API.
|
||||
#example glutGameModeString('1280x1024:32@75');
|
||||
proc glutGameModeString*(AString: cstring){.dynlib: dllname,
|
||||
importc: "glutGameModeString".}
|
||||
proc glutEnterGameMode*(): int{.dynlib: dllname, importc: "glutEnterGameMode".}
|
||||
proc glutLeaveGameMode*(){.dynlib: dllname, importc: "glutLeaveGameMode".}
|
||||
proc glutGameModeGet*(mode: TGLenum): int{.dynlib: dllname,
|
||||
importc: "glutGameModeGet".}
|
||||
# implementation
|
||||
153
tests/manyloc/keineschweine/lib/glx.nim
Normal file
153
tests/manyloc/keineschweine/lib/glx.nim
Normal file
@@ -0,0 +1,153 @@
|
||||
#
|
||||
#
|
||||
# Translation of the Mesa GLX headers for FreePascal
|
||||
# Copyright (C) 1999 Sebastian Guenther
|
||||
#
|
||||
#
|
||||
# Mesa 3-D graphics library
|
||||
# Version: 3.0
|
||||
# Copyright (C) 1995-1998 Brian Paul
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
|
||||
import
|
||||
X, XLib, XUtil, gl
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
dllname = "GL.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
dllname = "/usr/X11R6/lib/libGL.dylib"
|
||||
else:
|
||||
const
|
||||
dllname = "libGL.so"
|
||||
const
|
||||
GLX_USE_GL* = 1
|
||||
GLX_BUFFER_SIZE* = 2
|
||||
GLX_LEVEL* = 3
|
||||
GLX_RGBA* = 4
|
||||
GLX_DOUBLEBUFFER* = 5
|
||||
GLX_STEREO* = 6
|
||||
GLX_AUX_BUFFERS* = 7
|
||||
GLX_RED_SIZE* = 8
|
||||
GLX_GREEN_SIZE* = 9
|
||||
GLX_BLUE_SIZE* = 10
|
||||
GLX_ALPHA_SIZE* = 11
|
||||
GLX_DEPTH_SIZE* = 12
|
||||
GLX_STENCIL_SIZE* = 13
|
||||
GLX_ACCUM_RED_SIZE* = 14
|
||||
GLX_ACCUM_GREEN_SIZE* = 15
|
||||
GLX_ACCUM_BLUE_SIZE* = 16
|
||||
GLX_ACCUM_ALPHA_SIZE* = 17 # GLX_EXT_visual_info extension
|
||||
GLX_X_VISUAL_TYPE_EXT* = 0x00000022
|
||||
GLX_TRANSPARENT_TYPE_EXT* = 0x00000023
|
||||
GLX_TRANSPARENT_INDEX_VALUE_EXT* = 0x00000024
|
||||
GLX_TRANSPARENT_RED_VALUE_EXT* = 0x00000025
|
||||
GLX_TRANSPARENT_GREEN_VALUE_EXT* = 0x00000026
|
||||
GLX_TRANSPARENT_BLUE_VALUE_EXT* = 0x00000027
|
||||
GLX_TRANSPARENT_ALPHA_VALUE_EXT* = 0x00000028 # Error codes returned by glXGetConfig:
|
||||
GLX_BAD_SCREEN* = 1
|
||||
GLX_BAD_ATTRIBUTE* = 2
|
||||
GLX_NO_EXTENSION* = 3
|
||||
GLX_BAD_VISUAL* = 4
|
||||
GLX_BAD_CONTEXT* = 5
|
||||
GLX_BAD_VALUE* = 6
|
||||
GLX_BAD_ENUM* = 7 # GLX 1.1 and later:
|
||||
GLX_VENDOR* = 1
|
||||
GLX_VERSION* = 2
|
||||
GLX_EXTENSIONS* = 3 # GLX_visual_info extension
|
||||
GLX_TRUE_COLOR_EXT* = 0x00008002
|
||||
GLX_DIRECT_COLOR_EXT* = 0x00008003
|
||||
GLX_PSEUDO_COLOR_EXT* = 0x00008004
|
||||
GLX_STATIC_COLOR_EXT* = 0x00008005
|
||||
GLX_GRAY_SCALE_EXT* = 0x00008006
|
||||
GLX_STATIC_GRAY_EXT* = 0x00008007
|
||||
GLX_NONE_EXT* = 0x00008000
|
||||
GLX_TRANSPARENT_RGB_EXT* = 0x00008008
|
||||
GLX_TRANSPARENT_INDEX_EXT* = 0x00008009
|
||||
|
||||
type # From XLib:
|
||||
XPixmap* = TXID
|
||||
XFont* = TXID
|
||||
XColormap* = TXID
|
||||
GLXContext* = Pointer
|
||||
GLXPixmap* = TXID
|
||||
GLXDrawable* = TXID
|
||||
GLXContextID* = TXID
|
||||
TXPixmap* = XPixmap
|
||||
TXFont* = XFont
|
||||
TXColormap* = XColormap
|
||||
TGLXContext* = GLXContext
|
||||
TGLXPixmap* = GLXPixmap
|
||||
TGLXDrawable* = GLXDrawable
|
||||
TGLXContextID* = GLXContextID
|
||||
|
||||
proc glXChooseVisual*(dpy: PDisplay, screen: int, attribList: ptr int32): PXVisualInfo{.
|
||||
cdecl, dynlib: dllname, importc: "glXChooseVisual".}
|
||||
proc glXCreateContext*(dpy: PDisplay, vis: PXVisualInfo, shareList: GLXContext,
|
||||
direct: bool): GLXContext{.cdecl, dynlib: dllname,
|
||||
importc: "glXCreateContext".}
|
||||
proc glXDestroyContext*(dpy: PDisplay, ctx: GLXContext){.cdecl, dynlib: dllname,
|
||||
importc: "glXDestroyContext".}
|
||||
proc glXMakeCurrent*(dpy: PDisplay, drawable: GLXDrawable, ctx: GLXContext): bool{.
|
||||
cdecl, dynlib: dllname, importc: "glXMakeCurrent".}
|
||||
proc glXCopyContext*(dpy: PDisplay, src, dst: GLXContext, mask: int32){.cdecl,
|
||||
dynlib: dllname, importc: "glXCopyContext".}
|
||||
proc glXSwapBuffers*(dpy: PDisplay, drawable: GLXDrawable){.cdecl,
|
||||
dynlib: dllname, importc: "glXSwapBuffers".}
|
||||
proc glXCreateGLXPixmap*(dpy: PDisplay, visual: PXVisualInfo, pixmap: XPixmap): GLXPixmap{.
|
||||
cdecl, dynlib: dllname, importc: "glXCreateGLXPixmap".}
|
||||
proc glXDestroyGLXPixmap*(dpy: PDisplay, pixmap: GLXPixmap){.cdecl,
|
||||
dynlib: dllname, importc: "glXDestroyGLXPixmap".}
|
||||
proc glXQueryExtension*(dpy: PDisplay, errorb, event: var int): bool{.cdecl,
|
||||
dynlib: dllname, importc: "glXQueryExtension".}
|
||||
proc glXQueryVersion*(dpy: PDisplay, maj, min: var int): bool{.cdecl,
|
||||
dynlib: dllname, importc: "glXQueryVersion".}
|
||||
proc glXIsDirect*(dpy: PDisplay, ctx: GLXContext): bool{.cdecl, dynlib: dllname,
|
||||
importc: "glXIsDirect".}
|
||||
proc glXGetConfig*(dpy: PDisplay, visual: PXVisualInfo, attrib: int,
|
||||
value: var int): int{.cdecl, dynlib: dllname,
|
||||
importc: "glXGetConfig".}
|
||||
proc glXGetCurrentContext*(): GLXContext{.cdecl, dynlib: dllname,
|
||||
importc: "glXGetCurrentContext".}
|
||||
proc glXGetCurrentDrawable*(): GLXDrawable{.cdecl, dynlib: dllname,
|
||||
importc: "glXGetCurrentDrawable".}
|
||||
proc glXWaitGL*(){.cdecl, dynlib: dllname, importc: "glXWaitGL".}
|
||||
proc glXWaitX*(){.cdecl, dynlib: dllname, importc: "glXWaitX".}
|
||||
proc glXUseXFont*(font: XFont, first, count, list: int){.cdecl, dynlib: dllname,
|
||||
importc: "glXUseXFont".}
|
||||
# GLX 1.1 and later
|
||||
proc glXQueryExtensionsString*(dpy: PDisplay, screen: int): cstring{.cdecl,
|
||||
dynlib: dllname, importc: "glXQueryExtensionsString".}
|
||||
proc glXQueryServerString*(dpy: PDisplay, screen, name: int): cstring{.cdecl,
|
||||
dynlib: dllname, importc: "glXQueryServerString".}
|
||||
proc glXGetClientString*(dpy: PDisplay, name: int): cstring{.cdecl,
|
||||
dynlib: dllname, importc: "glXGetClientString".}
|
||||
# Mesa GLX Extensions
|
||||
proc glXCreateGLXPixmapMESA*(dpy: PDisplay, visual: PXVisualInfo,
|
||||
pixmap: XPixmap, cmap: XColormap): GLXPixmap{.
|
||||
cdecl, dynlib: dllname, importc: "glXCreateGLXPixmapMESA".}
|
||||
proc glXReleaseBufferMESA*(dpy: PDisplay, d: GLXDrawable): bool{.cdecl,
|
||||
dynlib: dllname, importc: "glXReleaseBufferMESA".}
|
||||
proc glXCopySubBufferMESA*(dpy: PDisplay, drawbale: GLXDrawable,
|
||||
x, y, width, height: int){.cdecl, dynlib: dllname,
|
||||
importc: "glXCopySubBufferMESA".}
|
||||
proc glXGetVideoSyncSGI*(counter: var int32): int{.cdecl, dynlib: dllname,
|
||||
importc: "glXGetVideoSyncSGI".}
|
||||
proc glXWaitVideoSyncSGI*(divisor, remainder: int, count: var int32): int{.
|
||||
cdecl, dynlib: dllname, importc: "glXWaitVideoSyncSGI".}
|
||||
# implementation
|
||||
368
tests/manyloc/keineschweine/lib/wingl.nim
Normal file
368
tests/manyloc/keineschweine/lib/wingl.nim
Normal file
@@ -0,0 +1,368 @@
|
||||
import
|
||||
gl, windows
|
||||
|
||||
proc wglGetExtensionsStringARB*(hdc: HDC): cstring{.dynlib: dllname,
|
||||
importc: "wglGetExtensionsStringARB".}
|
||||
const
|
||||
WGL_FRONT_COLOR_BUFFER_BIT_ARB* = 0x00000001
|
||||
WGL_BACK_COLOR_BUFFER_BIT_ARB* = 0x00000002
|
||||
WGL_DEPTH_BUFFER_BIT_ARB* = 0x00000004
|
||||
WGL_STENCIL_BUFFER_BIT_ARB* = 0x00000008
|
||||
|
||||
proc WinChoosePixelFormat*(DC: HDC, p2: PPixelFormatDescriptor): int{.
|
||||
dynlib: "gdi32", importc: "ChoosePixelFormat".}
|
||||
proc wglCreateBufferRegionARB*(hDC: HDC, iLayerPlane: TGLint, uType: TGLuint): THandle{.
|
||||
dynlib: dllname, importc: "wglCreateBufferRegionARB".}
|
||||
proc wglDeleteBufferRegionARB*(hRegion: THandle){.dynlib: dllname,
|
||||
importc: "wglDeleteBufferRegionARB".}
|
||||
proc wglSaveBufferRegionARB*(hRegion: THandle, x: TGLint, y: TGLint,
|
||||
width: TGLint, height: TGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglSaveBufferRegionARB".}
|
||||
proc wglRestoreBufferRegionARB*(hRegion: THandle, x: TGLint, y: TGLint,
|
||||
width: TGLint, height: TGLint, xSrc: TGLint,
|
||||
ySrc: TGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglRestoreBufferRegionARB".}
|
||||
proc wglAllocateMemoryNV*(size: TGLsizei, readFrequency: TGLfloat,
|
||||
writeFrequency: TGLfloat, priority: TGLfloat): PGLvoid{.
|
||||
dynlib: dllname, importc: "wglAllocateMemoryNV".}
|
||||
proc wglFreeMemoryNV*(pointer: PGLvoid){.dynlib: dllname,
|
||||
importc: "wglFreeMemoryNV".}
|
||||
const
|
||||
WGL_IMAGE_BUFFER_MIN_ACCESS_I3D* = 0x00000001
|
||||
WGL_IMAGE_BUFFER_LOCK_I3D* = 0x00000002
|
||||
|
||||
proc wglCreateImageBufferI3D*(hDC: HDC, dwSize: DWORD, uFlags: UINT): PGLvoid{.
|
||||
dynlib: dllname, importc: "wglCreateImageBufferI3D".}
|
||||
proc wglDestroyImageBufferI3D*(hDC: HDC, pAddress: PGLvoid): BOOL{.
|
||||
dynlib: dllname, importc: "wglDestroyImageBufferI3D".}
|
||||
proc wglAssociateImageBufferEventsI3D*(hdc: HDC, pEvent: PHandle,
|
||||
pAddress: PGLvoid, pSize: PDWORD,
|
||||
count: UINT): BOOL{.dynlib: dllname,
|
||||
importc: "wglAssociateImageBufferEventsI3D".}
|
||||
proc wglReleaseImageBufferEventsI3D*(hdc: HDC, pAddress: PGLvoid, count: UINT): BOOL{.
|
||||
dynlib: dllname, importc: "wglReleaseImageBufferEventsI3D".}
|
||||
proc wglEnableFrameLockI3D*(): BOOL{.dynlib: dllname,
|
||||
importc: "wglEnableFrameLockI3D".}
|
||||
proc wglDisableFrameLockI3D*(): BOOL{.dynlib: dllname,
|
||||
importc: "wglDisableFrameLockI3D".}
|
||||
proc wglIsEnabledFrameLockI3D*(pFlag: PBOOL): BOOL{.dynlib: dllname,
|
||||
importc: "wglIsEnabledFrameLockI3D".}
|
||||
proc wglQueryFrameLockMasterI3D*(pFlag: PBOOL): BOOL{.dynlib: dllname,
|
||||
importc: "wglQueryFrameLockMasterI3D".}
|
||||
proc wglGetFrameUsageI3D*(pUsage: PGLfloat): BOOL{.dynlib: dllname,
|
||||
importc: "wglGetFrameUsageI3D".}
|
||||
proc wglBeginFrameTrackingI3D*(): BOOL{.dynlib: dllname,
|
||||
importc: "wglBeginFrameTrackingI3D".}
|
||||
proc wglEndFrameTrackingI3D*(): BOOL{.dynlib: dllname,
|
||||
importc: "wglEndFrameTrackingI3D".}
|
||||
proc wglQueryFrameTrackingI3D*(pFrameCount: PDWORD, pMissedFrames: PDWORD,
|
||||
pLastMissedUsage: PGLfloat): BOOL{.
|
||||
dynlib: dllname, importc: "wglQueryFrameTrackingI3D".}
|
||||
const
|
||||
WGL_NUMBER_PIXEL_FORMATS_ARB* = 0x00002000
|
||||
WGL_DRAW_TO_WINDOW_ARB* = 0x00002001
|
||||
WGL_DRAW_TO_BITMAP_ARB* = 0x00002002
|
||||
WGL_ACCELERATION_ARB* = 0x00002003
|
||||
WGL_NEED_PALETTE_ARB* = 0x00002004
|
||||
WGL_NEED_SYSTEM_PALETTE_ARB* = 0x00002005
|
||||
WGL_SWAP_LAYER_BUFFERS_ARB* = 0x00002006
|
||||
WGL_SWAP_METHOD_ARB* = 0x00002007
|
||||
WGL_NUMBER_OVERLAYS_ARB* = 0x00002008
|
||||
WGL_NUMBER_UNDERLAYS_ARB* = 0x00002009
|
||||
WGL_TRANSPARENT_ARB* = 0x0000200A
|
||||
WGL_TRANSPARENT_RED_VALUE_ARB* = 0x00002037
|
||||
WGL_TRANSPARENT_GREEN_VALUE_ARB* = 0x00002038
|
||||
WGL_TRANSPARENT_BLUE_VALUE_ARB* = 0x00002039
|
||||
WGL_TRANSPARENT_ALPHA_VALUE_ARB* = 0x0000203A
|
||||
WGL_TRANSPARENT_INDEX_VALUE_ARB* = 0x0000203B
|
||||
WGL_SHARE_DEPTH_ARB* = 0x0000200C
|
||||
WGL_SHARE_STENCIL_ARB* = 0x0000200D
|
||||
WGL_SHARE_ACCUM_ARB* = 0x0000200E
|
||||
WGL_SUPPORT_GDI_ARB* = 0x0000200F
|
||||
WGL_SUPPORT_OPENGL_ARB* = 0x00002010
|
||||
WGL_DOUBLE_BUFFER_ARB* = 0x00002011
|
||||
WGL_STEREO_ARB* = 0x00002012
|
||||
WGL_PIXEL_TYPE_ARB* = 0x00002013
|
||||
WGL_COLOR_BITS_ARB* = 0x00002014
|
||||
WGL_RED_BITS_ARB* = 0x00002015
|
||||
WGL_RED_SHIFT_ARB* = 0x00002016
|
||||
WGL_GREEN_BITS_ARB* = 0x00002017
|
||||
WGL_GREEN_SHIFT_ARB* = 0x00002018
|
||||
WGL_BLUE_BITS_ARB* = 0x00002019
|
||||
WGL_BLUE_SHIFT_ARB* = 0x0000201A
|
||||
WGL_ALPHA_BITS_ARB* = 0x0000201B
|
||||
WGL_ALPHA_SHIFT_ARB* = 0x0000201C
|
||||
WGL_ACCUM_BITS_ARB* = 0x0000201D
|
||||
WGL_ACCUM_RED_BITS_ARB* = 0x0000201E
|
||||
WGL_ACCUM_GREEN_BITS_ARB* = 0x0000201F
|
||||
WGL_ACCUM_BLUE_BITS_ARB* = 0x00002020
|
||||
WGL_ACCUM_ALPHA_BITS_ARB* = 0x00002021
|
||||
WGL_DEPTH_BITS_ARB* = 0x00002022
|
||||
WGL_STENCIL_BITS_ARB* = 0x00002023
|
||||
WGL_AUX_BUFFERS_ARB* = 0x00002024
|
||||
WGL_NO_ACCELERATION_ARB* = 0x00002025
|
||||
WGL_GENERIC_ACCELERATION_ARB* = 0x00002026
|
||||
WGL_FULL_ACCELERATION_ARB* = 0x00002027
|
||||
WGL_SWAP_EXCHANGE_ARB* = 0x00002028
|
||||
WGL_SWAP_COPY_ARB* = 0x00002029
|
||||
WGL_SWAP_UNDEFINED_ARB* = 0x0000202A
|
||||
WGL_TYPE_RGBA_ARB* = 0x0000202B
|
||||
WGL_TYPE_COLORINDEX_ARB* = 0x0000202C
|
||||
|
||||
proc wglGetPixelFormatAttribivARB*(hdc: HDC, iPixelFormat: TGLint,
|
||||
iLayerPlane: TGLint, nAttributes: TGLuint,
|
||||
piAttributes: PGLint, piValues: PGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetPixelFormatAttribivARB".}
|
||||
proc wglGetPixelFormatAttribfvARB*(hdc: HDC, iPixelFormat: TGLint,
|
||||
iLayerPlane: TGLint, nAttributes: TGLuint,
|
||||
piAttributes: PGLint, pfValues: PGLfloat): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetPixelFormatAttribfvARB".}
|
||||
proc wglChoosePixelFormatARB*(hdc: HDC, piAttribIList: PGLint,
|
||||
pfAttribFList: PGLfloat, nMaxFormats: TGLuint,
|
||||
piFormats: PGLint, nNumFormats: PGLuint): BOOL{.
|
||||
dynlib: dllname, importc: "wglChoosePixelFormatARB".}
|
||||
const
|
||||
WGL_ERROR_INVALID_PIXEL_TYPE_ARB* = 0x00002043
|
||||
WGL_ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB* = 0x00002054
|
||||
|
||||
proc wglMakeContextCurrentARB*(hDrawDC: HDC, hReadDC: HDC, hglrc: HGLRC): BOOL{.
|
||||
dynlib: dllname, importc: "wglMakeContextCurrentARB".}
|
||||
proc wglGetCurrentReadDCARB*(): HDC{.dynlib: dllname,
|
||||
importc: "wglGetCurrentReadDCARB".}
|
||||
const
|
||||
WGL_DRAW_TO_PBUFFER_ARB* = 0x0000202D # WGL_DRAW_TO_PBUFFER_ARB { already defined }
|
||||
WGL_MAX_PBUFFER_PIXELS_ARB* = 0x0000202E
|
||||
WGL_MAX_PBUFFER_WIDTH_ARB* = 0x0000202F
|
||||
WGL_MAX_PBUFFER_HEIGHT_ARB* = 0x00002030
|
||||
WGL_PBUFFER_LARGEST_ARB* = 0x00002033
|
||||
WGL_PBUFFER_WIDTH_ARB* = 0x00002034
|
||||
WGL_PBUFFER_HEIGHT_ARB* = 0x00002035
|
||||
WGL_PBUFFER_LOST_ARB* = 0x00002036
|
||||
|
||||
proc wglCreatePbufferARB*(hDC: HDC, iPixelFormat: TGLint, iWidth: TGLint,
|
||||
iHeight: TGLint, piAttribList: PGLint): THandle{.
|
||||
dynlib: dllname, importc: "wglCreatePbufferARB".}
|
||||
proc wglGetPbufferDCARB*(hPbuffer: THandle): HDC{.dynlib: dllname,
|
||||
importc: "wglGetPbufferDCARB".}
|
||||
proc wglReleasePbufferDCARB*(hPbuffer: THandle, hDC: HDC): TGLint{.
|
||||
dynlib: dllname, importc: "wglReleasePbufferDCARB".}
|
||||
proc wglDestroyPbufferARB*(hPbuffer: THandle): BOOL{.dynlib: dllname,
|
||||
importc: "wglDestroyPbufferARB".}
|
||||
proc wglQueryPbufferARB*(hPbuffer: THandle, iAttribute: TGLint, piValue: PGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglQueryPbufferARB".}
|
||||
proc wglSwapIntervalEXT*(interval: TGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglSwapIntervalEXT".}
|
||||
proc wglGetSwapIntervalEXT*(): TGLint{.dynlib: dllname,
|
||||
importc: "wglGetSwapIntervalEXT".}
|
||||
const
|
||||
WGL_BIND_TO_TEXTURE_RGB_ARB* = 0x00002070
|
||||
WGL_BIND_TO_TEXTURE_RGBA_ARB* = 0x00002071
|
||||
WGL_TEXTURE_FORMAT_ARB* = 0x00002072
|
||||
WGL_TEXTURE_TARGET_ARB* = 0x00002073
|
||||
WGL_MIPMAP_TEXTURE_ARB* = 0x00002074
|
||||
WGL_TEXTURE_RGB_ARB* = 0x00002075
|
||||
WGL_TEXTURE_RGBA_ARB* = 0x00002076
|
||||
WGL_NO_TEXTURE_ARB* = 0x00002077
|
||||
WGL_TEXTURE_CUBE_MAP_ARB* = 0x00002078
|
||||
WGL_TEXTURE_1D_ARB* = 0x00002079
|
||||
WGL_TEXTURE_2D_ARB* = 0x0000207A # WGL_NO_TEXTURE_ARB { already defined }
|
||||
WGL_MIPMAP_LEVEL_ARB* = 0x0000207B
|
||||
WGL_CUBE_MAP_FACE_ARB* = 0x0000207C
|
||||
WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB* = 0x0000207D
|
||||
WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB* = 0x0000207E
|
||||
WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB* = 0x0000207F
|
||||
WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB* = 0x00002080
|
||||
WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB* = 0x00002081
|
||||
WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB* = 0x00002082
|
||||
WGL_FRONT_LEFT_ARB* = 0x00002083
|
||||
WGL_FRONT_RIGHT_ARB* = 0x00002084
|
||||
WGL_BACK_LEFT_ARB* = 0x00002085
|
||||
WGL_BACK_RIGHT_ARB* = 0x00002086
|
||||
WGL_AUX0_ARB* = 0x00002087
|
||||
WGL_AUX1_ARB* = 0x00002088
|
||||
WGL_AUX2_ARB* = 0x00002089
|
||||
WGL_AUX3_ARB* = 0x0000208A
|
||||
WGL_AUX4_ARB* = 0x0000208B
|
||||
WGL_AUX5_ARB* = 0x0000208C
|
||||
WGL_AUX6_ARB* = 0x0000208D
|
||||
WGL_AUX7_ARB* = 0x0000208E
|
||||
WGL_AUX8_ARB* = 0x0000208F
|
||||
WGL_AUX9_ARB* = 0x00002090
|
||||
|
||||
proc wglBindTexImageARB*(hPbuffer: THandle, iBuffer: TGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglBindTexImageARB".}
|
||||
proc wglReleaseTexImageARB*(hPbuffer: THandle, iBuffer: TGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglReleaseTexImageARB".}
|
||||
proc wglSetPbufferAttribARB*(hPbuffer: THandle, piAttribList: PGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglSetPbufferAttribARB".}
|
||||
proc wglGetExtensionsStringEXT*(): cstring{.dynlib: dllname,
|
||||
importc: "wglGetExtensionsStringEXT".}
|
||||
proc wglMakeContextCurrentEXT*(hDrawDC: HDC, hReadDC: HDC, hglrc: HGLRC): BOOL{.
|
||||
dynlib: dllname, importc: "wglMakeContextCurrentEXT".}
|
||||
proc wglGetCurrentReadDCEXT*(): HDC{.dynlib: dllname,
|
||||
importc: "wglGetCurrentReadDCEXT".}
|
||||
const
|
||||
WGL_DRAW_TO_PBUFFER_EXT* = 0x0000202D
|
||||
WGL_MAX_PBUFFER_PIXELS_EXT* = 0x0000202E
|
||||
WGL_MAX_PBUFFER_WIDTH_EXT* = 0x0000202F
|
||||
WGL_MAX_PBUFFER_HEIGHT_EXT* = 0x00002030
|
||||
WGL_OPTIMAL_PBUFFER_WIDTH_EXT* = 0x00002031
|
||||
WGL_OPTIMAL_PBUFFER_HEIGHT_EXT* = 0x00002032
|
||||
WGL_PBUFFER_LARGEST_EXT* = 0x00002033
|
||||
WGL_PBUFFER_WIDTH_EXT* = 0x00002034
|
||||
WGL_PBUFFER_HEIGHT_EXT* = 0x00002035
|
||||
|
||||
proc wglCreatePbufferEXT*(hDC: HDC, iPixelFormat: TGLint, iWidth: TGLint,
|
||||
iHeight: TGLint, piAttribList: PGLint): THandle{.
|
||||
dynlib: dllname, importc: "wglCreatePbufferEXT".}
|
||||
proc wglGetPbufferDCEXT*(hPbuffer: THandle): HDC{.dynlib: dllname,
|
||||
importc: "wglGetPbufferDCEXT".}
|
||||
proc wglReleasePbufferDCEXT*(hPbuffer: THandle, hDC: HDC): TGLint{.
|
||||
dynlib: dllname, importc: "wglReleasePbufferDCEXT".}
|
||||
proc wglDestroyPbufferEXT*(hPbuffer: THandle): BOOL{.dynlib: dllname,
|
||||
importc: "wglDestroyPbufferEXT".}
|
||||
proc wglQueryPbufferEXT*(hPbuffer: THandle, iAttribute: TGLint, piValue: PGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglQueryPbufferEXT".}
|
||||
const
|
||||
WGL_NUMBER_PIXEL_FORMATS_EXT* = 0x00002000
|
||||
WGL_DRAW_TO_WINDOW_EXT* = 0x00002001
|
||||
WGL_DRAW_TO_BITMAP_EXT* = 0x00002002
|
||||
WGL_ACCELERATION_EXT* = 0x00002003
|
||||
WGL_NEED_PALETTE_EXT* = 0x00002004
|
||||
WGL_NEED_SYSTEM_PALETTE_EXT* = 0x00002005
|
||||
WGL_SWAP_LAYER_BUFFERS_EXT* = 0x00002006
|
||||
WGL_SWAP_METHOD_EXT* = 0x00002007
|
||||
WGL_NUMBER_OVERLAYS_EXT* = 0x00002008
|
||||
WGL_NUMBER_UNDERLAYS_EXT* = 0x00002009
|
||||
WGL_TRANSPARENT_EXT* = 0x0000200A
|
||||
WGL_TRANSPARENT_VALUE_EXT* = 0x0000200B
|
||||
WGL_SHARE_DEPTH_EXT* = 0x0000200C
|
||||
WGL_SHARE_STENCIL_EXT* = 0x0000200D
|
||||
WGL_SHARE_ACCUM_EXT* = 0x0000200E
|
||||
WGL_SUPPORT_GDI_EXT* = 0x0000200F
|
||||
WGL_SUPPORT_OPENGL_EXT* = 0x00002010
|
||||
WGL_DOUBLE_BUFFER_EXT* = 0x00002011
|
||||
WGL_STEREO_EXT* = 0x00002012
|
||||
WGL_PIXEL_TYPE_EXT* = 0x00002013
|
||||
WGL_COLOR_BITS_EXT* = 0x00002014
|
||||
WGL_RED_BITS_EXT* = 0x00002015
|
||||
WGL_RED_SHIFT_EXT* = 0x00002016
|
||||
WGL_GREEN_BITS_EXT* = 0x00002017
|
||||
WGL_GREEN_SHIFT_EXT* = 0x00002018
|
||||
WGL_BLUE_BITS_EXT* = 0x00002019
|
||||
WGL_BLUE_SHIFT_EXT* = 0x0000201A
|
||||
WGL_ALPHA_BITS_EXT* = 0x0000201B
|
||||
WGL_ALPHA_SHIFT_EXT* = 0x0000201C
|
||||
WGL_ACCUM_BITS_EXT* = 0x0000201D
|
||||
WGL_ACCUM_RED_BITS_EXT* = 0x0000201E
|
||||
WGL_ACCUM_GREEN_BITS_EXT* = 0x0000201F
|
||||
WGL_ACCUM_BLUE_BITS_EXT* = 0x00002020
|
||||
WGL_ACCUM_ALPHA_BITS_EXT* = 0x00002021
|
||||
WGL_DEPTH_BITS_EXT* = 0x00002022
|
||||
WGL_STENCIL_BITS_EXT* = 0x00002023
|
||||
WGL_AUX_BUFFERS_EXT* = 0x00002024
|
||||
WGL_NO_ACCELERATION_EXT* = 0x00002025
|
||||
WGL_GENERIC_ACCELERATION_EXT* = 0x00002026
|
||||
WGL_FULL_ACCELERATION_EXT* = 0x00002027
|
||||
WGL_SWAP_EXCHANGE_EXT* = 0x00002028
|
||||
WGL_SWAP_COPY_EXT* = 0x00002029
|
||||
WGL_SWAP_UNDEFINED_EXT* = 0x0000202A
|
||||
WGL_TYPE_RGBA_EXT* = 0x0000202B
|
||||
WGL_TYPE_COLORINDEX_EXT* = 0x0000202C
|
||||
|
||||
proc wglGetPixelFormatAttribivEXT*(hdc: HDC, iPixelFormat: TGLint,
|
||||
iLayerPlane: TGLint, nAttributes: TGLuint,
|
||||
piAttributes: PGLint, piValues: PGLint): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetPixelFormatAttribivEXT".}
|
||||
proc wglGetPixelFormatAttribfvEXT*(hdc: HDC, iPixelFormat: TGLint,
|
||||
iLayerPlane: TGLint, nAttributes: TGLuint,
|
||||
piAttributes: PGLint, pfValues: PGLfloat): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetPixelFormatAttribfvEXT".}
|
||||
proc wglChoosePixelFormatEXT*(hdc: HDC, piAttribIList: PGLint,
|
||||
pfAttribFList: PGLfloat, nMaxFormats: TGLuint,
|
||||
piFormats: PGLint, nNumFormats: PGLuint): BOOL{.
|
||||
dynlib: dllname, importc: "wglChoosePixelFormatEXT".}
|
||||
const
|
||||
WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D* = 0x00002050
|
||||
WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D* = 0x00002051
|
||||
WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D* = 0x00002052
|
||||
WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D* = 0x00002053
|
||||
|
||||
proc wglGetDigitalVideoParametersI3D*(hDC: HDC, iAttribute: TGLint,
|
||||
piValue: PGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglGetDigitalVideoParametersI3D".}
|
||||
proc wglSetDigitalVideoParametersI3D*(hDC: HDC, iAttribute: TGLint,
|
||||
piValue: PGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglSetDigitalVideoParametersI3D".}
|
||||
const
|
||||
WGL_GAMMA_TABLE_SIZE_I3D* = 0x0000204E
|
||||
WGL_GAMMA_EXCLUDE_DESKTOP_I3D* = 0x0000204F
|
||||
|
||||
proc wglGetGammaTableParametersI3D*(hDC: HDC, iAttribute: TGLint,
|
||||
piValue: PGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglGetGammaTableParametersI3D".}
|
||||
proc wglSetGammaTableParametersI3D*(hDC: HDC, iAttribute: TGLint,
|
||||
piValue: PGLint): BOOL{.dynlib: dllname,
|
||||
importc: "wglSetGammaTableParametersI3D".}
|
||||
proc wglGetGammaTableI3D*(hDC: HDC, iEntries: TGLint, puRed: PGLUSHORT,
|
||||
puGreen: PGLUSHORT, puBlue: PGLUSHORT): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetGammaTableI3D".}
|
||||
proc wglSetGammaTableI3D*(hDC: HDC, iEntries: TGLint, puRed: PGLUSHORT,
|
||||
puGreen: PGLUSHORT, puBlue: PGLUSHORT): BOOL{.
|
||||
dynlib: dllname, importc: "wglSetGammaTableI3D".}
|
||||
const
|
||||
WGL_GENLOCK_SOURCE_MULTIVIEW_I3D* = 0x00002044
|
||||
WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D* = 0x00002045
|
||||
WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D* = 0x00002046
|
||||
WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D* = 0x00002047
|
||||
WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D* = 0x00002048
|
||||
WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D* = 0x00002049
|
||||
WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D* = 0x0000204A
|
||||
WGL_GENLOCK_SOURCE_EDGE_RISING_I3D* = 0x0000204B
|
||||
WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D* = 0x0000204C
|
||||
WGL_FLOAT_COMPONENTS_NV* = 0x000020B0
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV* = 0x000020B1
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV* = 0x000020B2
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV* = 0x000020B3
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV* = 0x000020B4
|
||||
WGL_TEXTURE_FLOAT_R_NV* = 0x000020B5
|
||||
WGL_TEXTURE_FLOAT_RG_NV* = 0x000020B6
|
||||
WGL_TEXTURE_FLOAT_RGB_NV* = 0x000020B7
|
||||
WGL_TEXTURE_FLOAT_RGBA_NV* = 0x000020B8
|
||||
|
||||
proc wglEnableGenlockI3D*(hDC: HDC): BOOL{.dynlib: dllname,
|
||||
importc: "wglEnableGenlockI3D".}
|
||||
proc wglDisableGenlockI3D*(hDC: HDC): BOOL{.dynlib: dllname,
|
||||
importc: "wglDisableGenlockI3D".}
|
||||
proc wglIsEnabledGenlockI3D*(hDC: HDC, pFlag: PBOOL): BOOL{.dynlib: dllname,
|
||||
importc: "wglIsEnabledGenlockI3D".}
|
||||
proc wglGenlockSourceI3D*(hDC: HDC, uSource: TGLuint): BOOL{.dynlib: dllname,
|
||||
importc: "wglGenlockSourceI3D".}
|
||||
proc wglGetGenlockSourceI3D*(hDC: HDC, uSource: PGLUINT): BOOL{.dynlib: dllname,
|
||||
importc: "wglGetGenlockSourceI3D".}
|
||||
proc wglGenlockSourceEdgeI3D*(hDC: HDC, uEdge: TGLuint): BOOL{.dynlib: dllname,
|
||||
importc: "wglGenlockSourceEdgeI3D".}
|
||||
proc wglGetGenlockSourceEdgeI3D*(hDC: HDC, uEdge: PGLUINT): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetGenlockSourceEdgeI3D".}
|
||||
proc wglGenlockSampleRateI3D*(hDC: HDC, uRate: TGLuint): BOOL{.dynlib: dllname,
|
||||
importc: "wglGenlockSampleRateI3D".}
|
||||
proc wglGetGenlockSampleRateI3D*(hDC: HDC, uRate: PGLUINT): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetGenlockSampleRateI3D".}
|
||||
proc wglGenlockSourceDelayI3D*(hDC: HDC, uDelay: TGLuint): BOOL{.
|
||||
dynlib: dllname, importc: "wglGenlockSourceDelayI3D".}
|
||||
proc wglGetGenlockSourceDelayI3D*(hDC: HDC, uDelay: PGLUINT): BOOL{.
|
||||
dynlib: dllname, importc: "wglGetGenlockSourceDelayI3D".}
|
||||
proc wglQueryGenlockMaxSourceDelayI3D*(hDC: HDC, uMaxLineDelay: PGLUINT,
|
||||
uMaxPixelDelay: PGLUINT): BOOL{.
|
||||
dynlib: dllname, importc: "wglQueryGenlockMaxSourceDelayI3D".}
|
||||
const
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV* = 0x000020A0
|
||||
WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV* = 0x000020A1
|
||||
WGL_TEXTURE_RECTANGLE_NV* = 0x000020A2
|
||||
|
||||
const
|
||||
WGL_RGBA_FLOAT_MODE_ATI* = 0x00008820
|
||||
WGL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI* = 0x00008835
|
||||
WGL_TYPE_RGBA_FLOAT_ATI* = 0x000021A0
|
||||
|
||||
# implementation
|
||||
0
tests/manyloc/packages/package1/p1.babel
Normal file
0
tests/manyloc/packages/package1/p1.babel
Normal file
0
tests/manyloc/packages/package2/p2.babel
Normal file
0
tests/manyloc/packages/package2/p2.babel
Normal file
1
todo.txt
1
todo.txt
@@ -4,6 +4,7 @@ version 0.9.6
|
||||
- scopes are still broken for generic instantiation!
|
||||
- integrate the new LL into the devel branch
|
||||
- start experimental branch
|
||||
- overloading of '='; general lift mechanism
|
||||
|
||||
Concurrency
|
||||
-----------
|
||||
|
||||
@@ -14,6 +14,8 @@ News
|
||||
``threadpool``.
|
||||
- The symbol binding rules in generics changed: ``bar`` in ``foo.bar`` is
|
||||
now considered for implicit early binding.
|
||||
- ``c2nim`` moved into its own repository and is now a Babel package.
|
||||
- ``pas2nim`` moved into its own repository and is now a Babel package.
|
||||
|
||||
|
||||
Library Additions
|
||||
|
||||
@@ -38,7 +38,7 @@ UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson."""
|
||||
[Documentation]
|
||||
doc: "endb;intern;apis;lib;manual;tut1;tut2;nimrodc;overview;filters"
|
||||
doc: "tools;c2nim;niminst;nimgrep;gc;estp;idetools;docgen;koch;backends.txt"
|
||||
pdf: "manual;lib;tut1;tut2;nimrodc;c2nim;niminst;gc"
|
||||
pdf: "manual;lib;tut1;tut2;nimrodc;niminst;gc"
|
||||
srcdoc2: "system.nim;impure/graphics;wrappers/sdl"
|
||||
srcdoc2: "core/macros;pure/marshal;core/typeinfo;core/unsigned"
|
||||
srcdoc2: "impure/re;pure/sockets"
|
||||
|
||||
Reference in New Issue
Block a user