Oh threadpool, my threadpool

2024-06-17 Thread slangmgh
I have an program with 50k lines source code, it is cpu extensive, and it run fine with refc. The program can compile with arc/orc without one line code modify, but run very slowly.

Oh threadpool, my threadpool

2024-06-17 Thread slangmgh
Sorry, Is malebolgia support refc or arc/orc only?

It is annoying that the template doesn't resolve the symbol at template caller.

2024-06-15 Thread slangmgh
.inject still works. import strformat import macros macro t1(): untyped = return quote do: var i {.inject.} = 10# add {.inject.} here echo fmt"i is {i}" # now works proc p1() = t1() when isMainModule: p1()

It is annoying that the template doesn't resolve the symbol at template caller.

2024-06-15 Thread slangmgh
No, {.dirty.} deos't change anything, it is still resolved at p1 context.

It is annoying that the template doesn't resolve the symbol at template caller.

2024-06-15 Thread slangmgh
When the reference variable is parameter, pragma {.dirty.} cannot helpful. template t1() {.dirty.} = echo i template t2(i: int) {.dirty.} = t1() proc p1() = t2(x) when isMainModule: p1() Run Compile output:

It is annoying that the template doesn't resolve the symbol at template caller.

2024-06-15 Thread slangmgh
In fact, it is useless when only make t1 {.dirty.}, make t1 and t2 {.dirty.} will fix the problem.

It is annoying that the template doesn't resolve the symbol at template caller.

2024-06-14 Thread slangmgh
For example, the following code doesn't compile: template t2() = template t1() = res.add "hello" var res = "" t1() echo res proc p1() = t2() when isMainModule: p1() Run The compiler out: :

GC refc or MarkAndSweep bug with msvc compiler optimizer.

2024-05-19 Thread slangmgh
There is bug with refc or MarkAndSweep gc combine msvc compiler. And it is reported as . Here is the code: import strformat, strutils let SIZE = 10_000_000 let COUNT = 99 proc printf*(formatstr: cstring) {.header: "

May bug with ``ptr ref`` combine closure?

2023-05-26 Thread slangmgh
So this is the reason why share an ref object between threads is dangerous even if the ref object is read only. But with atomicRef should be fine with read only ref object.

May bug with ``ptr ref`` combine closure?

2023-05-26 Thread slangmgh
You are very correct. I change the incRef/decRef to atomicInc/atomicDec in gc.nim, then the program work fine. :) Thank you.

May bug with ``ptr ref`` combine closure?

2023-05-26 Thread slangmgh
Good point!

May bug with ``ptr ref`` combine closure?

2023-05-26 Thread slangmgh
As the example above show, the ref count only increased, rather than decreased, so it is will not be freeed because of ref count is zero. But as I said, add GC_Ref(BigObj) sure prevent the BigObj from be freeed.

May bug with ``ptr ref`` combine closure?

2023-05-25 Thread slangmgh
Thank you, that make sence. :) I have a real world bug related this, it is troubled me for long time, please give me some hints if possible. The real world program like this: I have an big ref object named as BigObj, which I pass to several children thread with pointer, because I don't want it

May bug with ``ptr ref`` combine closure?

2023-05-25 Thread slangmgh
Look at the following code: ## nim c --mm:refc a.nim type Foo = ref object a: int proc unsafe_ref_count(x: ref): int = let p = cast[ptr UncheckedArray[int]](x) p[-2] shr 3 proc main(px: ptr Foo) = let x = px[] proc p1(

Is it bug of pragma nodecl?

2023-05-07 Thread slangmgh
Great! using pragma `global` works. The assembler code is same for both make_nim_char_array and make_c_char_array with msvc compiler flag `/O2`.

Is it bug of pragma nodecl?

2023-05-07 Thread slangmgh
The code `var x: array[6, char] = ['h', 'e', 'l', 'l', 'o', '\0']` doesn't work either. Here is the generated c code: static NIM_CONST tyArray__9bPFPkkEEeeNM9bKgiV8Q49cg TM__7Wo7NjlPCKzJJsFsMhIJow_2 = {104, 101, 108, 108, 111, 0} ; .. N_LIB_PRIVATE N_NIMCALL(void, main__

Is it bug of pragma nodecl?

2023-05-06 Thread slangmgh
I want to define a var in c with "char x[] = {'h', 'e', 'l', 'l', 'o', 0};" to make the varaible allocate on stack, and doesnt refrence any global variable. (The code will be remote execute with CreateRemoteThread). So I wrote a macro and using importc to import the varaible, the code is:

try-catch misbehavior

2022-12-27 Thread slangmgh
I don't like the exception model of Nim, when I want to write an server program, which process data every cycle, there is possible sometime the program don't do good because of we don't know what will the input data be, so I need to catch all exception, regardless of Defect or Error or SystemErr

TinyRE - Tiny Regex Engine for Nim

2022-12-13 Thread slangmgh
I like it, thank you.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Your are right! The assembler code generate by c compiler with simple object wrapper is almost same with the plain int.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
It is `distinct int` and `float`, not with `int`.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Use `distinct` for performance, disable `Price(3.6)` for safety.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
I hope I can find way to prevent the code like this: proc Price(x: float) {.error.} Run But this doesn't compile.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
But this code compiles fine. type Price = distinct int var f = 3.6 var p = Price(f) echo p # 3, rather than 4 Run This is what I want to avoid.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Look at the following code. type Price = distinct int converter float_to_price(x: float): Price = x.toInt.Price let x = 3.6 let y = Price(x) # y = 3, I want to disable it let z: Price = x # z = 4, correct Run

Nim v2: what would you change?

2022-04-30 Thread slangmgh
If the v2 will make the --mm:arc --mm:orc --threads:on default, then make them works well all, include task, channle, isolate, threadpool, locks, async, etc.

Confusion about `swap`

2021-08-18 Thread slangmgh
`(a, b) = (b, a) ` Run

Is it possible to pass a list/array of types to a function?

2021-08-03 Thread slangmgh
https://github.com/yglukhov/typelists

How can I run a procedure with specified time interval

2021-07-17 Thread slangmgh
There should be event loop outside like runForever(.)

Use break statement inside of called proc

2021-06-22 Thread slangmgh
Use template.

An simple nrpl for nim

2021-06-15 Thread slangmgh
It is fast.

An simple nrpl for nim

2021-06-12 Thread slangmgh
You need libffi if you compile with -d:nimHasLibFFI, input followin command to install libffi: nimble install libffi Run You can disable libffi to compile without option "-d:nimHasLibFFI".

An simple nrpl for nim

2021-06-11 Thread slangmgh
:quit or :exit with prefix ':'

An simple nrpl for nim

2021-06-11 Thread slangmgh
The findNimStdLib code is simple, the directory should be: nimdir |-bin\nim |-lib\ |-system.nim Run Just like the nim repository on github.

An simple nrpl for nim

2021-06-11 Thread slangmgh
findNimStdLib is proc from compiler/nimeval.nim, I think it should work with linux.

An simple nrpl for nim

2021-06-11 Thread slangmgh
Now the code is refactored, should be easy to understood.

An simple nrpl for nim

2021-06-11 Thread slangmgh
Maybe you should download most recent nim compiler code.

An simple nrpl for nim

2021-06-09 Thread slangmgh
function with vm_native macro easily. I have build an version for windows, you can just download and try. :) <https://github.com/slangmgh/nims>

Asynchronous processing of http requests vs spawn tasks!

2021-06-01 Thread slangmgh
Async suitable for IO intensive task, multi-thread model suitable for cpu intensive task.

There is any simple to convert a Time to DateTime?

2020-12-05 Thread slangmgh
Find proc inZone(time, zone): DateTime

There is any simple to convert a Time to DateTime?

2020-12-05 Thread slangmgh
I save the time as unix timestamp, and now I want to convert it to DateTime, but I can only find method DateTime.toTime.