Re: Wrong copy of sequences?

2018-03-20 Thread lscrd
Yes, I understand. Indeed, it seemed to me it was an issue quite difficult to 
solve. But, it is something very unlikely to happen in real programs and, so 
far, nobody has encountered these problems. I have built these examples when I 
have suspected that something may be wrong in some cases and this is not actual 
code in some program I have written.


Re: cpuTime not in JS backend?

2018-03-20 Thread treeform
Also DOM package does not include performance.now which requires and {.emit.} 
to get working.


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread mashingan
Hmm, I'm not sure, all I can say is the cross compiler cannot find the sysroot

This the exact command line I did and it success


\nimcache>arm-linux-androideabi-gcc -I d:/installer/nim/lib hello_android.c 
stdlib_system.c -o hello 
--sysroot=e:/installer/android/ndk/platforms/android-19/arch-arm


Before I did failed like what you had but because I wrote the sysroot wrong, 
before I wrote it `--sysroot=e:/installer/ndk/platforms/android-19/arch-arm` , 
but after recompiled with correct path, it compiled successfully.

My Nim version is still 0.17.2, 64 bit (haven't had a chance to try 0.18.0)

My arm-linux-androideabi-gcc version and its path dependency


arm-linux-androideabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-androideabi-gcc

COLLECT_LTO_WRAPPER=e:/installer/android/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper.exe
Target: arm-linux-androideabi
Configured with: 
/usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure
 --prefix=/tmp/54f254f8bb7b48dd787052921220a87d --target=arm-linux-androideabi 
--host=x86_64-pc-mingw32msvc --build=x86_64-linux-gnu --with-gnu-as 
--with-gnu-ld --enable-languages=c,c++ 
--with-gmp=/buildbot/tmp/build/toolchain/temp-install 
--with-mpfr=/buildbot/tmp/build/toolchain/temp-install 
--with-mpc=/buildbot/tmp/build/toolchain/temp-install 
--with-cloog=/buildbot/tmp/build/toolchain/temp-install 
--with-isl=/buildbot/tmp/build/toolchain/temp-install 
--with-ppl=/buildbot/tmp/build/toolchain/temp-install 
--disable-ppl-version-check --disable-cloog-version-check 
--disable-isl-version-check --enable-cloog-backend=isl 
--with-host-libstdcxx='-static-libgcc -static-libstdc++ -lstdc++ -lm -static' 
--disable-libssp --enable-threads --disable-nls --disable-libmudflap 
--disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions 
--disable-shared --disable-tls --disable-libitm --with-float=soft 
--with-fpu=vfp --with-arch=armv5te --enable-target-optspace 
--enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array 
--disable-nls --prefix=/tmp/54f254f8bb7b48dd787052921220a87d 
--with-sysroot=/tmp/54f254f8bb7b48dd787052921220a87d/sysroot 
--with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 
--with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none 
--with-gxx-include-dir=/tmp/54f254f8bb7b48dd787052921220a87d/include/c++/4.9.x 
--with-bugurl=http://source.android.com/source/report-bugs.html 
--enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp 
--enable-gnu-indirect-function --disable-libsanitizer --enable-gold 
--enable-eh-frame-hdr-for-static --enable-graphite=yes 
--with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te 
--program-transform-name='s&^&' --enable-gold=default
Thread model: posix
gcc version 4.9.x 20150123 (prerelease) (GCC)


My system is Windows 10 64 bit


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad
Hi mashingan,

I tried cross-compile the same hello.nim from linux and **got the same errors 
exactly like in windows**.

what I did:

  1. Cloned nim-lang branch master from github and compled it.
  2. Downloaded android ndk
  3. Defined all needed paths in PATH
  4. Compile hello.nim: nim c --cpu:arm --os:android --compileOnly hello.nim
  5. Compile with arm-linux-androideabi-gcc.exe




Re: how to get value of object's field from second thread?

2018-03-20 Thread r3d9u11
Thanks!


Re: how to get value of object's field from second thread?

2018-03-20 Thread mashingan
You forgot `initLock`.

Also since you just only toggle the boolean value, you may consider to use 
[cas](https://nim-lang.org/docs/system.html#cas,ptr.T,T,T)


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad

> cd C:\Users\uname\Documents\nimapps\jnijava\
> set 
PATH=%PATH%;C:\Users\uname\Documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin
> nim c --cpu:arm --os:android --compileOnly hello.nim
> cd nimcache
> arm-linux-androideabi-gcc.exe -I "C:/Nim/lib" hello.c stdlib_system.c -o 
hello 
--sysroot="C:/Users/uname/Documents/apps/android-ndk-r16b/platforms/android-19/arch-arm"


Re: how to get value of object's field from second thread?

2018-03-20 Thread r3d9u11
well, "\--threadAnalysis:off"+globalvar+lock looks nice: 


import os, threadpool, locks

type
  MyObj = ref object
flag: bool

var olock: Lock
var obj {.guard: olock.}: MyObj

proc someThread() {.gcsafe.} =
  {.locks: [olock].}:
if obj != nil:
  echo obj.flag
  obj.flag = false

obj.new()
obj.flag = true
spawn someThread()
sleep 500
echo obj.flag



Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread mashingan
Could you give the command-line you typed?

For example, what I did was like this


arm-linux-androideabi-gcc.exe -I "C:/Nim/lib" hello.c stdlib_system.c -o 
hello 
--sysroot="C:/Users/uname/Documents/apps/android-ndk-r16b/platforms/android-19/arch-arm"



Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad
Hi mashingan,

thank you for suggestion and I tried all this /," and // possibilities but 
errors are the same.

any other suggestions? maybe I have not prepared some things... 


Re: Nim syntax Quiz

2018-03-20 Thread Araq
"Error: Not all cases are covered" when you have one ')' too much? "Invalid 
indentation" when you have one ')' too much?

Your "quiz" has quite some potential still. 


Re: how to get value of object's field from second thread?

2018-03-20 Thread r3d9u11
Thanks, I saw your examples in previous posts with similar theme (I've post 
link before). Well, I did "simple" application, who demonstrate exchanging 
process of object between two threads. This model looks it is logical, but code 
looks really mad and inflexible  (for 21th), sorry: 


import os, threadpool

type
  SharedChannel[T] = ptr Channel[T]

proc newSharedChannel[T](): SharedChannel[T] =
  result = cast[SharedChannel[T]](allocShared0(sizeof(Channel[T])))
  open(result[])

proc close[T](ch: var SharedChannel[T]) =
  close(ch[])
  deallocShared(ch)
  ch = nil

proc send[T](ch: SharedChannel[T], content: T) =
  ch[].send(content)

proc recv[T](ch: SharedChannel[T]): T =
  result = ch[].recv

type
  MyObj = ref object
flag: bool

proc someThread(ch: SharedChannel[MyObj]) {.thread.} =
  var obj = ch.recv
  if obj != nil:
echo obj.flag
obj.flag = false
  ch.send(obj)

var
  ch = newSharedChannel[MyObj]()
spawn someThread(ch)
var obj: MyObj
obj.new()
obj.flag = true
ch.send(obj)
sleep 500
obj = ch.recv
echo obj.flag
close(ch)


Now I'll figure out how best to integrate this model into the application. 
Thanks for all for your help and discussion!


Re: Emscripten/WebAssembly GC considerations?

2018-03-20 Thread Lando
To complete the picture: the generated HTML file should be run with emrun 
main-wasm.html.

To learn about GC behaviour in WASM, probably any Nim code for testing the GC 
(like the one from [here](https://forum.nim-lang.org/t/2646)) could be run in 
the browser. If someone already had some in-process code/method for e.g. 
detecting memory leaks for a 32-bit target, I would be interested.


Re: Nim syntax Quiz

2018-03-20 Thread Allin
On behalf of future Nim beginners I say that is a great reply to my rants. 
Correct and helpful feedback from compiler is even more important than correct 
and helpful feedback from community. When next version comes out, I'll check if 
there's room left for another syntax (error) "quiz".


Re: Emscripten/WebAssembly GC considerations?

2018-03-20 Thread rpowers
@yglukhov Thanks, that makes sense, I can just call GC_step at the start of 
each emscripten_set_main_loop callback. By the way, thanks for writing jsbind, 
it has been very helpful! 

@mashingan I copied most of the nim.cfg from here: 
[https://forum.nim-lang.org/t/2991](https://forum.nim-lang.org/t/2991). Then 
follow the Emscripten installation instructions: 
[https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html)
 (be sure to source ./emsdk_env.sh in the console before using the Nim 
compiler).

To compile, run something like nim c -d:emscripten -d:wasm -d:release 
-o:main-wasm.html main.nim and it will just.. work. If I have time, I'll put 
together a simple example repo.

FYI, I could only get it to work on Linux (or Windows Linux), the Windows 
command prompt had some issues.


Re: Introducing loopfusion: loop over any number of sequences of any single type.

2018-03-20 Thread mratsim
Done


import loopfusion

let a = @[1, 2, 3]
let b = @[11, 12, 13]
let c = @[10, 10, 10]

forEach x in a, y in b, z in c:
  echo (x + y) * z

# 120
# 140
# 160

# i is the iteration index [0, 1, 2]
forEach i, x in a, y in b, z in c:
  d.add (x + y) * z * i

# index: 0, 120
# index: 1, 140
# index: 2, 160


The tricky thing was the difference between typed and untyped macro. I can't do 
all in the same one.

I have removed the ForEachIndexed and added it to forEach. It was a workaround 
because somehow I use overloading previously.