Re: How do i compile asm files with vcc compiler?

2018-10-11 Thread rokups
You mean masm? That is the Microsoft assembler that comes with VCC. Or does Nim 
use external assemler now?


Re: Read gzip-compressed file line by line

2018-10-11 Thread pqflx3
Since you mention DNA seqs, you might want to take a look at 
[nim-hts](https://github.com/brentp/hts-nim/). It's easy on unix systems to get 
htslib, and not too difficult on windows using msys2

You could probably write an iterator around his BGZ type.


Re: migrate oldwinapi to winim

2018-10-11 Thread geezer9
Well . . . it's Microsoft vs the world. I'm inclined to side with Microsoft 
when it is their library, but then try to hide the irritating proc names in my 
own module.

That has the benefit(?) of clearly marking what is Microsoft stuff as opposed 
to my own code - when I look back at the code months later.


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread timothee
i had made a PR recently, unfortunately it was closed: 
[https://github.com/nim-lang/Nim/pull/8528](https://github.com/nim-lang/Nim/pull/8528)


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread jyapayne
I didn't know you could do this, but apparently this works as well (tried on 
both 0.18.0 and 0.19.0).


type
  MyType = distinct int

template Cast[T](value: typed): T =
  cast[T](value)

let a = Cast[int](3.MyType)
echo a
# prints 3


Run


Re: How do i compile asm files with vcc compiler?

2018-10-11 Thread Araq
Looks like a regression. We need to change how `yasm` is called, I think.


Re: migrate oldwinapi to winim

2018-10-11 Thread Araq
> Mostly it was changing identifiers back to their originals as published by 
> msdn.

I've said it before but `winim` should really have used `lowerCase` for the 
procs like our style guide recommends. Many Nim programmers read UpperCase as 
type names nowadays.


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread juancarlospaco
With choosenim is 1 command to switch versions, super friendly.


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread miran
> I want to install 0.19 but i am afraid that whether my current code will work 
> or not.

0.19 brings lots of improvements and bugfixes, my recommendation would be to 
use it.

And if you want to have multiple versions installed, and you want to easily 
switch between them: [choosenim](https://github.com/dom96/choosenim/) is your 
friend.


migrate oldwinapi to winim

2018-10-11 Thread geezer9
I just had great success migrating some of my code from using oldwinapi to 
using the newer winm module. **Much applause for the author of winim** ! ! ! ! 
! ! ! !

Mostly it was changing identifiers back to their originals as published by msdn.

Also since my project does not use unicode (nor utf8) in any way, I needed to 
compile using the nim option:

> -d:winascii|   
> ---|---  
  
To get the result to link edit when cross compiling from Linux to MS binary, I 
changed a line (about #11) in the ---/.nimble/pkgs/winim-2.5.1/winim/inc winim 
package (after you install it) from:

> const winimPrivateDir = parentDir(currentSourcePath()) & "/../lib/"

to:

> const winimPrivateDir = parentDir(currentSourcePath()) & r"..lib"

Below is a list of the changes I had to make (to **MY** sources) during the 
migration. This no doubt needs to be extended by other programmer's 
experiences. Please feel free to do so.


oldwinapi   winim   module  comment
-   -   --- -
LPITEMIDLISTLPCITEMIDLIST   inc/objbase.nim

HINST   HINSTANCE   inc/windef.nim

WINUINT UINTinc/windef.nim

TopLeft.x   leftinc/windef.nim  IN RECT

TopLeft.y   top inc/windef.nim  IN RECT

BottomRight.x   right   inc/windef.nim  IN RECT

BottomRight.y   bottom  inc/windef.nim  IN RECT

TOPENFILENAME   OPENFILENAME   inc/commdlg.nim

flags   Flags   inc/commdlg.nim in OPENFILENAME

TLOGFONTLOGFONT inc/wingdi.nim

lfItaliclfItalicinc/wingdi.nim  cast to BYTE

TCHOOSEFONTTCHOOSEFONT  inc/commdlg.nim NOTE the T prefix is 
kept.


Had used UncheckedArray[RGBQUAD] instead of array[0..0,RGBQUAD] in my code 
to solve a problem
better solved by {.boundChecks: off.}

make sure 4th parameter of CreateDIBSection is of type: ptr pointer and 
just just pointer

When using SendMessage, it may be necessary to coerce the 3rd param into 
WPARAM whenever
that param is an int (e.g. any kind of HANDLE). This is because HANDLE is 
int whereas
WPARAM is uint32 (when winimCpu32)

See above, but for 4th SendMessage param LPARAM

In SendMessage(---,WM_CTLCOLOREDIT,---,---) return value had to coerce 
HBRUSH into LRESULT, because
HBRUSH was HANDLE is int but LRESULT is LONG_PTR is int32 (when winimCpu32)



Run


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread kcvinu
I want to install 0.19 but i am afraid that whether my current code will work 
or not. 


Re: Trying to learn templates, but its hard to understand.

2018-10-11 Thread Hlaaftana
This is your safest bet:


template Cast(T: typedesc, value: untyped): untyped =
  cast[T](value)

echo Cast(int, 3)


Run

To explain the template parameter types, `typedesc` (or just `type` is enough 
if you're on 0.19) matches type descriptors, so things like `int`, `Exception`, 
`seq`, `Slice[int]` and whatnot. `untyped` matches any AST expression and no 
type checking is performed on it, so you can do things like:


template foo(ex: untyped) =
  var a {.inject.} = 3 # {.inject.} passes the variable `a` to `ex`
  echo ex

foo(a * 4) # 12


Run

On the other hand, templates can also have generics, so you can do:


template Cast[T](_: typedesc[T], value: untyped): T =
  cast[T](value)

echo Cast(int, 3)


Run

Like before, if you're on 0.19, you can replace `typedesc[T]` with `type T`.


Trying to learn templates, but its hard to understand.

2018-10-11 Thread kcvinu
Hi all, I am trying to learn templates but i coudnt get the idea of templates 
easily. My aim is to mimic the cast function. Please look this -- 


template Cast(tp : typed, value : typed) = cast[tp](value)   # Failed
template Cast[T](tp : T, value : typed) = cast[tp](value)  # Failed
template Cast(tp : [T], value : typed) = cast[tp](value)# Failed


Run

All i want to tell the compiler is - 


template Cast( tp : is_a_generic_type, value : any_typed_value) = cast[ 
_generic_type](typed_value)


Run

How to do it ? Any help ?


How do i compile asm files with vcc compiler?

2018-10-11 Thread rokups
Hey, I am trying following:

assembly.asm: 


.code

asm_test PROC
mov rax, 1


Run

assembly.nim: 


{.compile: "assembly.asm".}
proc asm_test(): int {.cdecl, importc.}

echo asm_test()


Run

Compilation fails:


C:\nim-coro>nim-0.19.0\bin\nim.exe c --cc:vcc -r assembly.nim
Hint: used config file 'C:\nim-coro\nim-0.19.0\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: assembly [Processing]
Hint:  [Link]
"C:\Windows\system32\cmd.exe" /C ""C:\Program Files (x86)\Microsoft Visual 
Studio 14.0\VC\vcvarsall" amd64 && SET"
cl.exe /nologo /DEBUG /Zi /F33554432 /FeC:\nim-coro\assembly.exe 
C:\Users\Administrator\nimcache\assembly_d\assembly.asm.obj 
C:\Users\Administrator\nimcache\assembly_d\assembly.c.obj 
C:\Users\Administrator\nimcache\assembly_d\stdlib_system.c.obj
LINK : fatal error LNK1181: cannot open input file 
'C:\Users\Administrator\nimcache\assembly_d\assembly.asm.obj'
Error: execution of an external program failed: 'vccexe.exe
--platform:amd64 /nologo /DEBUG /Zi /F33554432  /FeC:\nim-coro\assembly.exe  
C:\Users\Administrator\nimcache\assembly_d\assembly.asm.obj 
C:\Users\Administrator\nimcache\assembly_d\assembly.c.obj 
C:\Users\Administrator\nimcache\assembly_d\stdlib_system.c.obj '

assembly.asm.obj appears to be never compiled. Am i missing something or is 
this a bug?


Re: Opposite of astGenRepr

2018-10-11 Thread iffycan
I should explain exactly what I'm trying to do:

I'm trying to make macros. In my macros, I'd like to start with a base AST, 
then modify it according to passed-in arguments. I'm having trouble making that 
base AST.

There's `dumpAstGen` which makes it easy to print out the AST-generating code. 
For example:


dumpAstGen:
  echo something

# produces:
# nnkStmtList.newTree(
#   nnkCommand.newTree(
# newIdentNode("echo"),
# newIdentNode("something")
#   )
# )


Run

I've had success copying and pasting that output back into my source. But it's 
cumbersome to copy and paste a bunch of trees.

So I tried using `quote`. But `quote` produces `newSymNode` in places where 
`dumpAstGen` produces `newIdentNode`:


macro usingQuote(): untyped =
  var x = quote do:
echo something
  echo x.astGenRepr()
usingQuote

# produces:
# nnkCommand.newTree(
#   newSymNode("echo"),
#   newIdentNode("something")
# )


Run

Unfortunately, `newSymNode` breaks where `newIdentNode` didn't. (I haven't yet 
been able to make a small, reproducible example for this breakage).

And that's why I tried making my own kind of `quote` substitute in that first 
post. But I can't figure out how to evaluate a string as produced by 
`astGenRepr`


Re: Read gzip-compressed file line by line

2018-10-11 Thread enormandeau
Storing the whole file will not work very well for the application, where the 
input file could be 10 or 100 Gb :/

I need an iterator function (that I will create) that reads the file line by 
line inside the gzip archive and yields each meaningfull chunk (DNA sequences 
and their associated names and quality) on the fly.


Re: how to increase velocity for merging PRs?

2018-10-11 Thread Araq
I created this document, but IMO it would be much better if most `.nim` files 
would get a "Code-owner: Name here" comment instead, who wants to keep these 
tables up-to-date...

[https://raw.githubusercontent.com/nim-lang/Nim/devel/doc/codeowners.rst](https://raw.githubusercontent.com/nim-lang/Nim/devel/doc/codeowners.rst)


Re: `import foo {.private.}` to allows access to private fields (eg: package-level visibility)

2018-10-11 Thread kobi
Hi The Haxe language has that feature, you can see how they did it here: 
[https://haxe.org/manual/lf-access-control.html](https://haxe.org/manual/lf-access-control.html)

you know, learn from their lessons about intended usage. In general, I think 
it's a mis-feature, since it can break my design. I only found it useful for 
unit testing, when the tester is in a different module, and you wish to test 
all the private functions as well. for what it's worth, C# has a related 
feature, which is the an access modifier called "internal", which means it's 
public for everything inside the dll (the same assembly) even if it contains 
numerous namespaces (modules). I think this is a better way, design-wise, 
though not as flexible as your suggestion.


Re: `import foo {.private.}` to allows access to private fields (eg: package-level visibility)

2018-10-11 Thread Trustable
I like the idea and would call it `{.exposePrivate.}`, because that is what is 
does in my understanding.