standard filter supports multiple line expressions; better amd64 detection for mac os X

This commit is contained in:
Araq 2010-09-17 01:17:51 +02:00
commit c065694598
3 changed files with 56 additions and 16 deletions

View file

@ -720,7 +720,7 @@ const
proc compileOption*(option: string): bool {. proc compileOption*(option: string): bool {.
magic: "CompileOption", noSideEffect.} magic: "CompileOption", noSideEffect.}
## can be used to determine a on|off compile-time option. Example: ## can be used to determine an on|off compile-time option. Example:
## ##
## .. code-block:: nimrod ## .. code-block:: nimrod
## when compileOption("floatchecks"): ## when compileOption("floatchecks"):
@ -735,6 +735,8 @@ proc compileOption*(option, arg: string): bool {.
## echo "compiled with optimization for size and uses Boehm's GC" ## echo "compiled with optimization for size and uses Boehm's GC"
include "system/inclrtl" include "system/inclrtl"
when not defined(ecmascript):
include "system/cgprocs" include "system/cgprocs"
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}

View file

@ -1,7 +1,7 @@
# #
# #
# The Nimrod Compiler # The Nimrod Compiler
# (c) Copyright 2009 Andreas Rumpf # (c) Copyright 2010 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
@ -21,23 +21,52 @@ type
TParseState = enum TParseState = enum
psDirective, psTempl psDirective, psTempl
TTmplParser{.final.} = object TTmplParser{.final.} = object
inp*: PLLStream inp: PLLStream
state*: TParseState state: TParseState
info*: TLineInfo info: TLineInfo
indent*, par*: int indent, emitPar: int
x*: string # the current input line x: string # the current input line
outp*: PLLStream # the ouput will be parsed by pnimsyn outp: PLLStream # the ouput will be parsed by pnimsyn
subsChar*, NimDirective*: Char subsChar, NimDirective: Char
emit*, conc*, toStr*: string emit, conc, toStr: string
curly, bracket, par: int
pendingExprLine: bool
const const
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '.', '_'} PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '.', '_'}
proc newLine(p: var TTmplParser) = proc newLine(p: var TTmplParser) =
LLStreamWrite(p.outp, repeatChar(p.par, ')')) LLStreamWrite(p.outp, repeatChar(p.emitPar, ')'))
p.par = 0 p.emitPar = 0
if p.info.line > int16(1): LLStreamWrite(p.outp, "\n") if p.info.line > int16(1): LLStreamWrite(p.outp, "\n")
if p.pendingExprLine:
LLStreamWrite(p.outp, repeatChar(2))
p.pendingExprLine = false
proc scanPar(p: var TTmplParser, d: int) =
var i = d
while true:
case p.x[i]
of '\0': break
of '(': inc(p.par)
of ')': dec(p.par)
of '[': inc(p.bracket)
of ']': dec(p.bracket)
of '{': inc(p.curly)
of '}': dec(p.curly)
else: nil
inc(i)
proc endsWithOpr(p: TTmplParser): bool =
var i = p.x.len-1
while i >= 0 and p.x[i] == ' ': dec(i)
if i >= 0 and p.x[i] in {'+', '-', '*', '/', '\\', '<', '>', '!', '?', '^',
'|', '%', '&', '$', '@', '~', ','}:
result = true
proc withInExpr(p: TTmplParser): bool {.inline.} =
result = p.par > 0 or p.bracket > 0 or p.curly > 0
proc parseLine(p: var TTmplParser) = proc parseLine(p: var TTmplParser) =
var var
@ -56,6 +85,9 @@ proc parseLine(p: var TTmplParser) =
while p.x[j] in PatternChars: while p.x[j] in PatternChars:
add(keyw, p.x[j]) add(keyw, p.x[j])
inc(j) inc(j)
scanPar(p, j)
p.pendingExprLine = withInExpr(p) or endsWithOpr(p)
case whichKeyword(keyw) case whichKeyword(keyw)
of wEnd: of wEnd:
if p.indent >= 2: if p.indent >= 2:
@ -79,6 +111,10 @@ proc parseLine(p: var TTmplParser) =
p.state = psDirective p.state = psDirective
else: else:
# data line # data line
# reset counters
p.par = 0
p.curly = 0
p.bracket = 0
j = 0 j = 0
case p.state case p.state
of psTempl: of psTempl:
@ -92,7 +128,7 @@ proc parseLine(p: var TTmplParser) =
LLStreamWrite(p.outp, repeatChar(p.indent)) LLStreamWrite(p.outp, repeatChar(p.indent))
LLStreamWrite(p.outp, p.emit) LLStreamWrite(p.outp, p.emit)
LLStreamWrite(p.outp, "(\"") LLStreamWrite(p.outp, "(\"")
inc(p.par) inc(p.emitPar)
p.state = psTempl p.state = psTempl
while true: while true:
case p.x[j] case p.x[j]

View file

@ -1,6 +1,8 @@
#! stdtmpl(subsChar='?') | standard #! stdtmpl(subsChar='?') | standard
#proc GenerateBuildShellScript(c: TConfigData): string = #proc GenerateBuildShellScript(c: TConfigData): string =
# result = "#! /bin/sh\n# Generated by niminst\n" # result = "#! /bin/sh\n# Generated from niminst\n" &
# "# Template is in tools/buildsh.tmpl\n" &
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
CC="gcc" CC="gcc"
LINKER="gcc" LINKER="gcc"
COMP_FLAGS="-w -O3 -fno-strict-aliasing" COMP_FLAGS="-w -O3 -fno-strict-aliasing"
@ -33,7 +35,7 @@ case $uos in
*darwin* ) *darwin* )
myos="macosx" myos="macosx"
LINK_FLAGS="$LINK_FLAGS -ldl -lm" LINK_FLAGS="$LINK_FLAGS -ldl -lm"
if [ "`sysctl hw |grep 64bit`" = "hw.cpu64bit_capable: 1" ] ; then if [ "$HOSTTYPE" = "x86_64" ] ; then
ucpu="amd64" ucpu="amd64"
fi fi
;; ;;