Re: How do I revert a my fork back to nim devel?

2020-05-31 Thread slangmgh
` git checkout devel # your version of devel git reset --hard nim-lang/devel # reset to nim-lang/devel git push --force # push to github ` Run

Re: Run nimble install with error, need help.

2020-05-09 Thread slangmgh
There is some problem with my nim.cfg, I replace the nim.cfg to the original one, it is fine now. I will check my nim.cfg to see what is the culprit.

Run nimble install with error, need help.

2020-05-09 Thread slangmgh
When I run `nimble install jester`, it gives following error message: Downloading https://github.com/dom96/jester using git Tip: 3 messages have been suppressed, use --verbose to show them. Error: Could not read package info file in D:\Tmp\Temp\nimble_\githubc

Re: Runtime generated function with generated constant value

2020-05-08 Thread slangmgh
for i in 0..5: closureScope: let x = i test.add( proc () = echo x ) test[3]()

Re: Runtime generated function with generated constant value

2020-05-08 Thread slangmgh
`import sugar var test: seq[proc ()] for i in 0..5: capture i: test.add( proc () = echo i ) test[3]() ` Run

Re: Anyway to make the following code work?

2020-05-03 Thread slangmgh
Thank you, I will try.

Anyway to make the following code work?

2020-05-03 Thread slangmgh
import "../../compiler" / [ast, vmdef, vm, nimeval, llstream] import std / [os] when isMainModule: const moduleName = "script.nim" let std = findNimStdLibCompileTime() let intr = createInterpreter(moduleName, [std, std / "pure", std / "core"]) proc

Re: Bug or feature?

2019-12-02 Thread slangmgh
Good to hear the news. @Araq

Re: Bug or feature?

2019-12-01 Thread slangmgh
Global variable always deepCopy, local variable `let` assign using shallowCopy for value type, it is by design, not bug, not feature.

Re: Immutability -- more ideas

2019-03-14 Thread slangmgh
Add `mut` will pass the pointer of pointer. proc p2(x: mut Node) = x.left = nil # invalid x = Node()# valid proc p3(x: var mut Node) = x.left = nil # valid x = Node()# valid Run

Re: Immutability -- more ideas

2019-03-14 Thread slangmgh
I try use the `var` `let` and `mut` to test some scenario. First, we define the meaning of these terms(all for ref T type). 1\. `let` means fixed readonly variable binding, parameter without `var` means `let` binding proc p1() = let x = Node() x.left = nil # i

Re: Immutability -- more ideas

2019-03-13 Thread slangmgh
I think the `mut` proposal is more concise, look at the following code: proc copy(n1: Node, n2: Node) {.write [n1.left, n1.right].} = n1.left = n2.left n1.right = n2.right Run Using the write effect has the following disadvantage: 1. It is verbose

Re: Immutability -- more ideas

2019-03-12 Thread slangmgh
Totally agreed, constructors must be treated differently from other proc to construct immutable object.

Re: Help with template!

2019-03-11 Thread slangmgh
Try add the following code: template routes(body: untyped): untyped {.dirty.}= block routes: body Run

Re: Immutability -- more ideas

2019-03-10 Thread slangmgh
Now let's talk about what the `let`, `var`, `=` means semantically for ref type, when it is clear, then the programmer know what he is doing exactly, and the compiler know what the programmer doing wrong. (We talk about the parameter and return value later) For value object type, they are clear

Re: Immutability -- more ideas

2019-03-09 Thread slangmgh
About `mut` or `var` syntax. 1\. For `T` is value type, `var x: T` or `x: var T`, here `x=y` or `x.p=y` means change the `value` of `x`, so variable `x` is same as the `value`. 2\. For `T` is ref type, `var x: T` or `x: var T`, here `x` is the pointer to the `value`, `x=y` means change the poin

Re: Immutability -- more ideas

2019-03-09 Thread slangmgh
`Immutability` just like `static type`, `noSideEffect`, it is very useful feature to write reliable correct code, and we have no other way to make the ref type immutable.

Re: Immutability -- more ideas

2019-03-09 Thread slangmgh
We can discuss the design first, and the plan according the implementation cost. `T` is ref type. 1\. For any parameter `m` is not `mut T` > 1. `let x = m` is fine > 2. `var x = m` is disallowed > 3. `var y; y.x = m` is disallowed > 2\. For proc return result > 1. If `proc f(...): va

Re: Immutability -- more ideas

2019-03-08 Thread slangmgh
Deep immutability is great feature! `var T` is seems more consistent, but `mut T` is fine.

Re: The portable way to find nimbase.h or system.nim location

2019-02-12 Thread slangmgh
Good. :)

Re: The portable way to find nimbase.h or system.nim location

2019-02-11 Thread slangmgh
[https://scripter.co/notes/nim](https://scripter.co/notes/nim)/ It's great, is it possible add link to the official tutorial?

Re: How to "install" a newly built Nim on a directory?

2019-02-10 Thread slangmgh
Copy the config directory too.

Re: inline asm err?

2019-02-06 Thread slangmgh
But I think maybe we can specify calling convention, so the following code may correct: asm """ mov eax, `a` """ Run Otherwise, we cannot refer the parameter in the assembler code. But it still make sense, because the vcc compiler treat the __declspec(naked

Re: inline asm err?

2019-02-06 Thread slangmgh
If the `asmNoStackFrame` disable any call convention pragma, a warning is required when it is combined with call convention pragma or the code refer the parameter name.

Re: inline asm err?

2019-02-06 Thread slangmgh
Add the pragma `.cdecl.` or `.stdcall.` to addInt doesn't change the type nim compiler treat the parameter of addInt, maybe this is the bug.

Re: inline asm err?

2019-02-06 Thread slangmgh
Look at the assembler code: @addInt_WYbpHhMOLfd0wzp13vORMw@8 PROC NEAR mov eax, dword ptr [ebp-4H] ; 0020 _ 8B. 45, FC add eax, dword ptr [ebp-8H] ; 0023 _ 03. 45, F8 ret

Re: import object from another file

2019-02-04 Thread slangmgh
` type object3d*=object ` Run

Re: A bug of vcc compiler

2019-02-01 Thread slangmgh
No, the `=` function code is generated as __fastcall, and `&` function call `=` as __fastcall. If the `&` is not inlined in function `main` with compiler option `/Ob1` or `/Ob0`, then all is fine. But when the function `&` is inlined in function `main`, the code is generated as __stdcall to cal

Re: A bug of vcc compiler

2019-01-31 Thread slangmgh
I don't think so. 1. With x64, the call convention is all same. 2. The __fastcall is fast than __cdecl indeed. 3. The lastest compiler from vs 2013 has fixed this bug. 4. This is only happened with vcc. 5. It happened rarely.

A bug of vcc compiler

2019-01-31 Thread slangmgh
Yesterday, I am testing nim destructor thing, and find a strange bug. Look at the code modified from tests/destrcutor/tcustomstrings.nim type mystring = object len, cap: int data: ptr UncheckedArray[char] var allocCount, deallocCount: int

Re: Module typeinfo, can't access field by name. Bug or not?

2019-01-18 Thread slangmgh
You can use fieldPairs to get field value by name. type Foo = object field: int proc `[]`(x: Foo, s: string, T: type): T = for n, v in x.fieldPairs: if n == s: result = v break var foo = Foo(field: 123) ec

Re: How to get the address of an proc with same name and different parameter type

2019-01-18 Thread slangmgh
I had tried this way, but failed. I can try again.

Re: How to get the address of an proc with same name and different parameter type

2019-01-18 Thread slangmgh
Yes, it can!! I had tried this way: cast[proc (x: string) {.nimcall.}](p2) Run It doesn't work.

Re: Module typeinfo, can't access field by name. Bug or not?

2019-01-18 Thread slangmgh
The following code works: import typeinfo type Foo = object field: int var foo = Foo(field: 123) echo foo.field let x = foo.toAny echo x["field"].getInt Run

Re: Modified version of Kru02's interfaced

2019-01-17 Thread slangmgh
The following post have detailed explanation of Go interface. [https://forum.nim-lang.org/t/2422](https://forum.nim-lang.org/t/2422)

Re: Modified version of Kru02's interfaced

2019-01-17 Thread slangmgh
Current implementation doesn't support generic, because the vtable must be build at compile time when impl is called, but with generic, this is not possible, maybe we need the compiler to do it. :)

Re: Modified version of Kru02's interfaced

2019-01-17 Thread slangmgh
Here is the source: [https://github.com/slangmgh/interfaced](https://github.com/slangmgh/interfaced)

Modified version of Kru02's interfaced

2019-01-17 Thread slangmgh
I have created a modified version of Kru02's interfaced. The original post is here: [https://forum.nim-lang.org/t/2422](https://forum.nim-lang.org/t/2422) This version include more feature: 1. interface can inherited from other interfaces 2. interface to base interface can be converted impli

Re: How to get the address of an proc with same name and different parameter type

2019-01-16 Thread slangmgh
Find a way, the following code seems fine. proc p2(x: int) = echo x proc p2(x: string) = echo x let t1: proc(x: int) {.nimcall.} = p2 let t2: proc(x: string) {.nimcall.} = p2 t1(10) t2("string") echo toHex(cast[int](t1)) e

How to get the address of an proc with same name and different parameter type

2019-01-16 Thread slangmgh
When two proc have the same name, how can I get the proc address? proc p2(x: int) = echo x proc p2(x: string) = echo x let t1 = p2 # Run

Re: Is it possible get the export flag of a type symbol

2019-01-16 Thread slangmgh
I need a typed symbol. Thank you. :)

Re: Is it possible get the export flag of a type symbol

2019-01-15 Thread slangmgh
The macro will executed in scope which define the type symbol, so the when compiles will be always true.

Is it possible get the export flag of a type symbol

2019-01-15 Thread slangmgh
I am writing a macro which need to know if a type symbol is exported or not. But the getImpl doesn't contain export flag. The following code: import macros type T1* = object macro m1(t: typed): untyped = echo t.getImpl.treeRepr m1(T1)

Re: Cannot build the compiler v0.20 devel in windows.

2018-12-25 Thread slangmgh
Seems break with the config/nim.cfg, when I replace the nim.cfg with the new devel version, the nim.exe execute fine.

Cannot build the compiler v0.20 devel in windows.

2018-12-25 Thread slangmgh
I cannot compile the latest devel v0.20 successfully, never happened before. I use vc2013 in window7. Here is the output of command koch boot -d:release: D:\Tool\Nim>koch boot -d:release iteration: 1 compiler\nim0.exe c -d:release --nimcache:nimcache/r_windows_i386 compile

Re: Arraymancer - v0.4.0 (May 2018)

2018-12-23 Thread slangmgh
Great!!!

Re: Unicode display

2018-05-22 Thread slangmgh
To make the text display correctly, you need to set the encoding of the string(byte array) and the terminal codepage correctly. If you encoding of the string(Depending you source file or the source of the string) is unicode or utf8(\u5f9e is unicode), you need to set the terminal codepage to 65

Re: How to get the address of string

2018-05-15 Thread slangmgh
Here is the code from asyncpg package in apg_core.nim, it works before and doesn't now: # cast[](addr [0]) proc castPointer0(n: NimNode, v: string): NimNode {.compileTime.} = result = newNimNode(nnkCast).add( newIdentNode(v), newNimNode(nnkCommand).add(

Re: How to get the address of string

2018-05-11 Thread slangmgh
It just parameter, useless after call.

Re: How to get the address of string ""

2018-05-09 Thread slangmgh
I need to get the pointer, then set the pointer to a struct. So I cannot just use FFI.

Re: How to get the address of string ""

2018-05-08 Thread slangmgh
@c0ntribut0r Thank you, this is the method I use now. Because I need to call c function, so I need the address of the string.

How to get the address of string ""

2018-05-08 Thread slangmgh
The code following is fine in the prevous version, but it failed with the current devel branch because access the terminator zero is disabled. var a = "" let b = addr a[0] Now, there is any way I can get the address of the empty string?

Re: Statistics for standard library usage

2018-05-02 Thread slangmgh
>From the previous threads, I think there is two important thing to do: * Maintain the `nim compiler and core library` and keep them progress, which make the nim appeal to people who like a wonderful program language. * The `big standard package` which make most of user can develop with nim

Re: Is there any problem with the code in atomic.nim for tcc?

2018-05-02 Thread slangmgh
Yes, I know that async is single thread. But the tinyc do work with thread.

Re: Is there any problem with the code in atomic.nim for tcc?

2018-05-01 Thread slangmgh
Yes, it works for thread, async.

Re: Is there any problem with the code in atomic.nim for tcc?

2018-05-01 Thread slangmgh
TinyC on Windows works well. The TinyC compile speed and code optimization is not as good as vc, but it is so small, the total size of tcc compiler and header/lib file is no more than 2M. It can compile the nim compiler successfully!

Is there any problem with the code in atomic.nim for tcc?

2018-05-01 Thread slangmgh
The _cas code in `atomic.nim` for `tcc` of windows is disabled. elif defined(tcc) and not defined(windows): when defined(amd64): {.emit:""" static int __tcc_cas(int *ptr, int oldVal, int newVal) { unsigned char ret; __asm__ __volatile__ (

Re: Installing on Windows issues

2018-05-01 Thread slangmgh
Just grab the zip and extract them to some directory. [https://nim-lang.org/download/nim-0.18.0_x64.zip](https://nim-lang.org/download/nim-0.18.0_x64.zip)

Re: init DateTime is very annoying because we always need to initialize the DateTime object

2018-04-30 Thread slangmgh
@GULPF I need to define the variable first, then initialize the object later according to different condition. And when other object reference this object with `DateTime`, they need to be initialized when variable define if we don't want to see the warning. In nim, variable can be defiend as:

init DateTime is very annoying because we always need to initialize the DateTime object

2018-04-30 Thread slangmgh
When I include the `DateTime` into the object, I cannot use the object freely because the compiler always complain that the `DateTime` field is not initialized. type User = object name: string age: int birthday: DateTime var u = User(nam

Re: Perfecting Nim

2018-04-29 Thread slangmgh
I like the idea to make `seq` and `string` default `@[]` and `""`, we can use `{.noinit.}` to make them `nil` if care about performance.

Re: What is the typedesc inside the compiler?

2018-04-24 Thread slangmgh
@Araq Yes, I think static[T] should be nnkLitXXX, and typedesc should be nnkLitType maybe. Every should be NimNode in the macro, but it affect compatibility.

Re: What is the typedesc inside the compiler?

2018-04-24 Thread slangmgh
typedesc seems different from other type in the macro. macro m1(T: typed): untyped = echo treeRepr T macro m2(T: typedesc): untyped = #echo treeRepr T # compile error echo repr T.getType m1(int) # Sym "int" m2(int) # typeDesc[int]

Re: What is the typedesc inside the compiler?

2018-04-23 Thread slangmgh
Change the code: template create(x: int, T: typedesc): untyped = T(age: x) to: template create(x: int, T: untyped): untyped = T(age: x) All the code of above works!

Re: What is the typedesc inside the compiler?

2018-04-23 Thread slangmgh
Now here is problem how to pass typedesc to template: template create(x: int, T: typedesc): untyped = T(age: x) macro m2(T: typedesc): untyped = let nT = quote do: `T` #Sym "User" let t1 = T.getType()[1] #Sym "User" let t2 = bindSym"Us

Re: What is the typedesc inside the compiler?

2018-04-23 Thread slangmgh
The following code is ok: result = newCall("stepTwo", ident("User")) # OK! result = newCall("stepTwo", T.getType) # OK! Now, I know how to pass User as typedesc, but still it is a little confusion about typedesc to me.

What is the typedesc inside the compiler?

2018-04-23 Thread slangmgh
When a proc call a macro with typedesc parameter, we can just user the type name, but when we call another macro in the macro and pass the typedesc parameter to it, something is strange, look at the code: type User = object id: int name: string a

Re: Is there any way to create template with await?

2018-04-01 Thread slangmgh
@dom96 is right, it can be done like this: macro withTran(db, body: untyped): untyped = quote do: block: proc action(`db`: apgPoolConnection) {.async.} = `body` let fut = doTransaction(action) yield fut

Re: Bug (?) with templates

2018-03-30 Thread slangmgh
I think maybe this is template bug. These code doesn't compile from @zielmicha. template bar() {.dirty.} = echo a template foo() = let a = 5 bar() foo() But when we turn foo into proc, the code works. template bar() {.dirt

Re: Is there any way to create template with await?

2018-03-29 Thread slangmgh
The following code is extracted from asyncpg. template withConnection*(pool: apgPool, conn, body: untyped) = ## Retrieves first available connection from pool, assign it ## to variable with name `conn`. You can use this connection ## inside withConnection code block

Re: Is there any way to create template with await?

2018-03-29 Thread slangmgh
The document is about exception raised by async proc, my problem is about the exception raised by called proc between async code using resource, they are something different. Maybe I can wrapper the body with a proc which turn exception into return value.

Re: Is there any way to create template with await?

2018-03-28 Thread slangmgh
@dom96 Thanks. The code seems works, but it doesn't. db.close() seems executed before the code 'block', this is the error message: asyncdispatch.nim(1492) waitFor asyncdispatch.nim(1496) poll asyncdispatch.nim(292) runOnce Error: unhandled exception: No handles or tim

Is there any way to create template with await?

2018-03-21 Thread slangmgh
We can create template with like this: template withFile(name: string, body: untyped) = let fh = open(name, ...) defer: close(fh) block: body But when template contain await, the compiler will complain the 'await' is undeclared identifier. The co

Re: How to turn thread spawn call into an async call

2018-03-19 Thread slangmgh
It works finally. To make the {.async.} works in quoted code, the 'await' and Future variable must be ident!! type Result* = ref object of RootObj body*: string proc waitEvent(evt: AsyncEvent): Future[void] = var fut = newFuture[void]("callAsync")

Re: How to turn thread spawn call into an async call

2018-03-18 Thread slangmgh
It's seems not perfect, but works, thank you.

Re: How to turn thread spawn call into an async call

2018-03-17 Thread slangmgh
I think what I really need is a new spawn which return a Future[T] rather than FlowVar[T].

Re: How to turn thread spawn call into an async call

2018-03-17 Thread slangmgh
Now there is another problem. I hope I can write the code like this: proc ff1(p1: int): Result = # my db acess code here .. proc ff2(p1, p2: int): Result = # my db acess code here .. proc main() {.async.} = # async call ff1

Re: How to turn thread spawn call into an async call

2018-03-17 Thread slangmgh
@adrianv Thank you

Re: How to turn thread spawn call into an async call

2018-03-15 Thread slangmgh
@2vg asyncpg is good, thank you!

Re: How to turn thread spawn call into an async call

2018-03-15 Thread slangmgh
Find a way to solve the problem. Here is the code: proc doWork(evt: AsyncEvent) {.gcsafe.} = sleep(3000) evt.trigger() echo "work over" proc waitEvent(ev: AsyncEvent): Future[void] = var fut = newFuture[void]("waitEvent") proc cb(fd: AsyncF

How to turn thread spawn call into an async call

2018-03-15 Thread slangmgh
I encounter a problem, and hope someone would help me. Here is the problem: 1. I use Jester to deal with socket reques/response, which is single threaded(main thread). 2. I use postgresql to store/acess data, which is block function. 3. I think I can use postgresql in threadpool, then retur

Re: Compile error when wrapper type(...) with template

2017-05-12 Thread slangmgh
@LeuGim One little question. When I import the macros, the getType of this file is used, not the macros's getType, this is strange. That's mean import macros affect the template in this file can be used or not.

Re: Compile error when wrapper type(...) with template

2017-05-12 Thread slangmgh
I found a way to deal with the problem finally. We cannot define an template which return an 'type' (sometime it will fail to compile), but if I return a variable of the type, it is ok, then I can get the type of the variable. template get_val_from_item(seq1: untyped): untyped =

Re: Compile error when wrapper type(...) with template

2017-05-10 Thread slangmgh
@mashingan Yes, I can convert the iterator to seq and all works. But it not the way I want. I hope the iterator is same as seq, like following code: print collectz(1..5, @[toSeq(1..it)]) print collectz(@[1,2,3], @[toSeq(1..it)]) print collectz(countup(1,4), @[toSeq(1..it)])

Re: Compile error when wrapper type(...) with template

2017-05-10 Thread slangmgh
@cdome That doesn't work, because iterator is treated as untyped, and untyped parameter cannot be overloaded. The following code cannot compile. proc f1(t: seq[int]) = discard template f1(t: untyped) = discard f1(@[1]) f1(countup(1,3))

Re: Compile error when wrapper type(...) with template

2017-05-09 Thread slangmgh
@cdome Thank you. I am writing function like map, it will take the type array, slice, seq, iterator, etc as parameter, because the iterator cannot be treated as typed, so I cannot use typed(If the paramter type is typed, the function in the code can compile successfully). The code like this wo

Compile error when wrapper type(...) with template

2017-05-09 Thread slangmgh
I need get the type of container item(seq, array, iterator etc), so I write an template to get the item type, but when work with the generic, sometime it will fail to compile using the wrapper. Here is the code import macros template getTypeOfItem(t: untyped): auto =

Re: Compile error when wrapper type(...) with template

2017-05-09 Thread slangmgh
The compiler show the following message: ttype.nim(29, 4) template/generic instantiation from here ttype.nim(16, 24) Error: type expected

Anyone tried the "nim secret"?

2017-04-26 Thread slangmgh
When I browse the compiler source today, I find that the REPL is already here and is PERFECT for me.

Re: Problem with the generic of sequence.

2017-03-27 Thread slangmgh
Thank you for clarification.

Re: Problem with the generic of sequence.

2017-03-26 Thread slangmgh
There is simple version to show the problem. import typetraits type Foo[T] = ref object x: T proc `@@`*[T](a: T): Foo[T] = new(result); result.x = a proc `$`*[T](f: Foo[T]): string = "Foo[" & $f.x & "]" type Bar[T] = Foo[Foo[T]] # OOPS

Problem with the generic of sequence.

2017-03-25 Thread slangmgh
A compiler problem when I using generic. the code: import sequtils, typetraits type Point = object x,y: int rseq[T] = ref object inq: ref seq[T] Vector[T] = rseq[T] proc P(x, y: int): Point = Point(x: x, y: y) proc `+`(p1

Re: concat(seqs: varargs[seq[T]]) doesn't compile when T is seq[int]

2017-03-20 Thread slangmgh
Test more, find this code works: echo concat([@[@[1,2]], @[@[3,4]]]) Turn the arguments into array, then the varargs parameter works.

concat(seqs: varargs[seq[T]]) doesn't compile when T is seq[int]

2017-03-20 Thread slangmgh
This code is ok: echo concat(@[1,2], @[3,4]) But this code doesn't compile: echo concat(@[@[1,2]], @[@[3,4]])