Skip to content

Commit

Permalink
Merge pull request #5 from jangko/nim_v1_compat
Browse files Browse the repository at this point in the history
Nim v1 compat
  • Loading branch information
jangko authored Jan 4, 2020
2 parents b787689 + 495d73a commit 6e56212
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 38 deletions.
36 changes: 36 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@echo off

if [%1]==[] goto usage

if "%1"=="all" goto nppnim32
if "%1"=="x86" goto nppnim32
if "%1"=="x64" goto nppnim64

:nppnim32
@echo building 32 bit version
SET BASE=release\nppnim32
SET TMPPATH=%PATH%
SET PATH=e:\mingw32\mingw32\bin;f:\projects\new_nim\bin;%PATH%
windres -i resource\resource.rc -F pe-i386 -o resource\resource32.o
nim c -d:release --cpu:i386 -o:%BASE%\nppnim.dll nppnim
strip %BASE%\nppnim.dll
7z a -tzip %BASE%\nppnim32.zip %BASE%\nppnim.dll %BASE%\nppnim.xml
SET PATH=%TMPPATH%
if "%1"=="all" goto nppnim64
goto :eof

:nppnim64
@echo building 64 bit version
SET BASE=release\nppnim64
windres -i resource\resource.rc -o resource\resource64.o
nim c -d:release -o:%BASE%\nppnim.dll nppnim
strip %BASE%\nppnim.dll
7z a -tzip %BASE%\nppnim64.zip %BASE%\nppnim.dll %BASE%\nppnim.xml
goto :eof

:usage
@echo Usage: %0 options
@echo x86: buils 32 bit version
@echo x64: build 64 bit version
@echo all: build both 32 bit and 64 bit version
exit /B 1
11 changes: 6 additions & 5 deletions leximpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ proc GetWordType(L: ptr LexAccessor, start, stop: int): WordType =
kw.setLen(0)
for i in start..<stop:
kw.add L[][i]
if support.NimKeywords.contains(kw): return WT_KEYWORD
if support.NimTypes.contains(kw): return WT_TYPE
if support.NimCTypes.contains(kw): return WT_CTYPE
if support.NimMagic.contains(kw): return WT_MAGIC
let word = normalize(kw)
if support.NimKeywords.contains(word): return WT_KEYWORD
if support.NimTypes.contains(word): return WT_TYPE
if support.NimCTypes.contains(word): return WT_CTYPE
if support.NimMagic.contains(word): return WT_MAGIC
result = WT_IDENT

# this is Nim legacy
Expand Down Expand Up @@ -177,7 +178,7 @@ proc getString(sc: var StyleContext, rawMode: bool) =
sc.forward()
discard sc.popState()

template DEFAULT_STATE_BODY: typed =
template DEFAULT_STATE_BODY =
case sc.ch
of SymStartChars - {'r', 'R', 'l'}:
sc.getSymbol()
Expand Down
19 changes: 10 additions & 9 deletions nppnim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#
#-----------------------------------------
import
winapi, scintilla, nppmsg, menucmdid, support,
lexaccessor, stylecontext, sets, utils, strutils
winapi, scintilla, support, strutils,
lexaccessor, stylecontext, sets, utils

when defined(cpu64):
{.link: "resource/resource64.o".}
Expand Down Expand Up @@ -38,13 +38,14 @@ proc pluginInit(hModule: HMODULE) = discard
# Here you can do the clean up, save the parameters (if any) for the next session
proc pluginCleanUp() = discard

proc getSciHandle(): SciHandle =
# Get the current scintilla
var which = -1
sendMessage(nppData.nppHandle, NPPM_GETCURRENTSCINTILLA, 0, cast[LPARAM](which.addr))
if which == -1: return
let curScintilla = if which == 0: nppData.sciMainHandle else: nppData.sciSecondHandle
result = initSciHandle(curScintilla)
when false:
proc getSciHandle(): SciHandle =
# Get the current scintilla
var which = -1
sendMessage(nppData.nppHandle, NPPM_GETCURRENTSCINTILLA, 0, cast[LPARAM](which.addr))
if which == -1: return
let curScintilla = if which == 0: nppData.sciMainHandle else: nppData.sciSecondHandle
result = initSciHandle(curScintilla)

#proc hello() {.cdecl.} =
#Open a new document
Expand Down
4 changes: 2 additions & 2 deletions resource/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <windows.h>

#define VERSION_STRING "1.0.1"
#define VERSION_WORDS 1, 0, 1, 0
#define VERSION_STRING "1.2.4"
#define VERSION_WORDS 1, 2, 4, 0

VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_WORDS
Expand Down
Binary file modified resource/resource32.o
Binary file not shown.
Binary file modified resource/resource64.o
Binary file not shown.
2 changes: 1 addition & 1 deletion stylecontext.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (See accompanying file LICENSE.txt)
#
#-----------------------------------------
import lexaccessor, scintilla
import lexaccessor

const maxState = 10

Expand Down
20 changes: 11 additions & 9 deletions support.nim
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,18 @@ let
"tuple",
"type",
"using",
"unsafeAddr",
"unsafeaddr",
"unowned",
"var",
"when",
"while",
"with",
"without",
"xor",
"yield"].toSet()
"yield"].toHashSet()

NimTypes* = [
"byte",
"bool",
"int",
"uint",
Expand Down Expand Up @@ -146,10 +148,10 @@ let
"untyped",
"range",
"array",
"openArray",
"openarray",
"set",
"varargs"
].toSet()
].toHashSet()

NimCTypes* = [
"csize",
Expand All @@ -167,18 +169,18 @@ let
"cint",
"cuint",
"cstring",
"cstringArray"
].toSet()
"cstringarray"
].toHashSet()

NimMagic* = [
"defined",
"declared",
"declaredInScope",
"definedInScope",
"declaredinscope",
"definedinscope",
"new",
"high",
"low"
].toSet()
].toHashSet()

type
WordType* = enum
Expand Down
24 changes: 12 additions & 12 deletions winapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ const
WS_MINIMIZEBOX* = 0x00020000
WS_OVERLAPPED* = 0
WS_OVERLAPPEDWINDOW* = 0x00CF0000
WS_POPUP* = LONG(0x80000000)
WS_POPUPWINDOW* = LONG(0x80880000)
WS_POPUP* = cast[LONG](0x80000000)
WS_POPUPWINDOW* = cast[LONG](0x80880000)
WS_SIZEBOX* = 0x00040000
WS_SYSMENU* = 0x00080000
WS_TABSTOP* = 0x00010000
Expand Down Expand Up @@ -839,10 +839,10 @@ const
IDYES* = 6

proc RGB*(r, g, b: int): COLORREF =
result = toU32(r) or (toU32(g) shl 8) or (toU32(b) shl 16)
result = cast[int32](r) or (cast[int32](g) shl 8) or (cast[int32](b) shl 16)

proc RGB*(r, g, b: range[0 .. 255]): COLORREF =
result = toU32(r) or (toU32(g) shl 8) or (toU32(b) shl 16)
result = cast[int32](r) or (cast[int32](g) shl 8) or (cast[int32](b) shl 16)

proc PALETTERGB*(r, g, b: range[0..255]): COLORREF =
result = 0x02000000 or RGB(r, g, b)
Expand All @@ -851,31 +851,31 @@ proc PALETTEINDEX*(i: DWORD): COLORREF =
result = COLORREF(0x01000000'i32 or i and 0xffff'i32)

proc GetRValue*(rgb: COLORREF): int8 =
result = toU8(rgb)
result = int8(rgb)

proc GetGValue*(rgb: COLORREF): int8 =
result = toU8(rgb shr 8)
result = int8(rgb shr 8)

proc GetBValue*(rgb: COLORREF): int8 =
result = toU8(rgb shr 16)
result = int8(rgb shr 16)

proc HIBYTE*(w: int32): int8 =
result = toU8(w shr 8'i32 and 0x000000FF'i32)
result = cast[int8](w shr 8'i32 and 0x000000FF'i32)

proc HIWORD*(L: int32): int16 =
result = toU16(L shr 16'i32 and 0x0000FFFF'i32)
result = cast[int16](L shr 16'i32 and 0x0000FFFF'i32)

proc LOBYTE*(w: int32): int8 =
result = toU8(w)
result = cast[int8](w)

proc LOWORD*(L: int32): int16 =
result = toU16(L)
result = cast[int16](L)

proc MAKELONG*(a, b: int32): LONG =
result = a and 0x0000ffff'i32 or b shl 16'i32

proc MAKEWORD*(a, b: int32): int16 =
result = toU16(a and 0xff'i32) or toU16(b shl 8'i32)
result = cast[int16](a and 0xff'i32) or cast[int16](b shl 8'i32)

when defined(winUniCode):
proc WC*(s: string): LPCWSTR =
Expand Down

0 comments on commit 6e56212

Please sign in to comment.