mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
* defaults to Orc * bootstrap using refc * use gc * init orc defines * unregister orc * fix gc * fix commands * add prepareMutation for orc * enable deepcopy for orc * prepareMutation * more fixes * some cases * bug #20081 * partial fixes * partial fixes * fixes command line * more fixes * build Nim with refc * use gc * more fixes * rstore * orc doesn't support threadpool * more shallowCopy * more fixes * fixes unsafeNew * workarounds * small * more fixes * fixes some megatest * tcodegenbugs1 refc * fxies megatest * build nimble with refc * workaround tensordsl tests * replace shallowCopy with move * fixes action * workaround * add todo * fixes important packages * unpublic unregisterArcOrc * fixes cpp * enable windows Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
100 lines
2.0 KiB
Nim
100 lines
2.0 KiB
Nim
discard """
|
|
matrix: "--mm:refc"
|
|
output: '''
|
|
Future is no longer empty, 42
|
|
'''
|
|
"""
|
|
|
|
import threadpool
|
|
proc foo: string = "Dog"
|
|
var x: FlowVar[string] = spawn foo()
|
|
doAssert(^x == "Dog")
|
|
|
|
block:
|
|
type
|
|
Box = object
|
|
case empty: bool
|
|
of false:
|
|
contents: string
|
|
else:
|
|
discard
|
|
|
|
var obj = Box(empty: false, contents: "Hello")
|
|
doAssert obj.contents == "Hello"
|
|
|
|
var obj2 = Box(empty: true)
|
|
doAssertRaises(FieldDefect):
|
|
echo(obj2.contents)
|
|
|
|
import json
|
|
doAssert parseJson("null").kind == JNull
|
|
doAssert parseJson("true").kind == JBool
|
|
doAssert parseJson("42").kind == JInt
|
|
doAssert parseJson("3.14").kind == JFloat
|
|
doAssert parseJson("\"Hi\"").kind == JString
|
|
doAssert parseJson("""{ "key": "value" }""").kind == JObject
|
|
doAssert parseJson("[1, 2, 3, 4]").kind == JArray
|
|
|
|
import json
|
|
let data = """
|
|
{"username": "Dominik"}
|
|
"""
|
|
|
|
let obj = parseJson(data)
|
|
doAssert obj.kind == JObject
|
|
doAssert obj["username"].kind == JString
|
|
doAssert obj["username"].str == "Dominik"
|
|
|
|
block:
|
|
proc count10(): int =
|
|
for i in 0 ..< 10:
|
|
result.inc
|
|
doAssert count10() == 10
|
|
|
|
type
|
|
Point = tuple[x, y: int]
|
|
|
|
var point = (5, 10)
|
|
var point2 = (x: 5, y: 10)
|
|
|
|
type
|
|
Human = object
|
|
name: string
|
|
age: int
|
|
|
|
var jeff = Human(name: "Jeff", age: 23)
|
|
var amy = Human(name: "Amy", age: 20)
|
|
|
|
import asyncdispatch
|
|
|
|
var future = newFuture[int]()
|
|
doAssert(not future.finished)
|
|
|
|
future.callback =
|
|
proc (future: Future[int]) =
|
|
echo("Future is no longer empty, ", future.read)
|
|
|
|
future.complete(42)
|
|
|
|
import asyncdispatch, asyncfile
|
|
|
|
when false:
|
|
var file = openAsync("")
|
|
let dataFut = file.readAll()
|
|
dataFut.callback =
|
|
proc (future: Future[string]) =
|
|
echo(future.read())
|
|
|
|
asyncdispatch.runForever()
|
|
|
|
import asyncdispatch, asyncfile, os
|
|
|
|
proc readFiles() {.async.} =
|
|
# --- Changed to getTempDir here.
|
|
var file = openAsync(getTempDir() / "test.txt", fmReadWrite)
|
|
let data = await file.readAll()
|
|
echo(data)
|
|
await file.write("Hello!\n")
|
|
|
|
waitFor readFiles()
|