Merge branch 'araq-compress2' into araq-compress3

This commit is contained in:
araq
2025-11-11 16:36:00 +01:00
9 changed files with 2 additions and 341 deletions

View File

@@ -128,7 +128,7 @@ proc createInterpreter*(scriptName: string;
if conf.libpath.isEmpty: conf.libpath = AbsoluteDir p
var m = graph.makeModule(scriptName)
incl(m.flags, sfMainModule)
incl(m, sfMainModule)
var idgen = idGeneratorFromModule(m)
var vm = newCtx(m, cache, graph, idgen)
vm.mode = emRepl
@@ -168,7 +168,7 @@ proc runRepl*(r: TLLRepl;
if supportNimscript: defineSymbol(conf.symbols, "nimconfig")
when hasFFI: defineSymbol(graph.config.symbols, "nimffi")
var m = graph.makeStdinModule()
incl(m.flags, sfMainModule)
incl(m, sfMainModule)
var idgen = idGeneratorFromModule(m)
if supportNimscript: graph.vm = setupVM(m, cache, "stdin", graph, idgen)

View File

@@ -1,2 +0,0 @@
var x* = 123
var y = x

View File

@@ -1,79 +0,0 @@
type
FooEnum = enum
X,
Y,
Z
var enumTest = X
enumTest = Y
assert enumTest == Y
var enumSet = {X, Y}
enumSet.incl Z
var intArray = [1, 1 + 1, 1 * 2, 0]
intArray[3] = intArray[1] + intArray[0] * intArray[2]
var strArray = ["foo", "ba" & "r", ""]
strArray[2] = $(intArray[2])
var floatArray = [intArray[0].float, 1.0, 0.0]
floatArray[2] = floatArray[0] + floatArray[1]
var intSeq = @[3, 2]
intSeq.add 1
var tup1 = (foo: "Foo", bar: 123)
tup1.foo = "Bar"
tup1.bar = 321
tup1[0] = "Baz"
assert tup1 is (string, int)
let (tup1foo, tup1bar) = tup1
let (_, tup1bar2) = tup1
let (tup1foo2, _) = tup1
var testAddr: int
var testPtr = addr testAddr
testPtr[] = 123
var testAddr2: array[2, int]
var testPtr2: ptr int
testPtr2 = addr testAddr2[0]
var testPointer: pointer = testPtr2
testPtr2 = cast[ptr int](testPointer)
var stmtListExpr = (echo "foo"; "stmtListExpr")
var cond1 = true
var testIfExpr = if cond1: 1 else: -1
const TestWhenExpr = when sizeof(int) == 8: 1 else: -1
var cond2: FooEnum = X
var testCaseExpr = case cond2
of X:
1
of Y:
2
else:
3
var testBlockExpr = block:
var a = "test"
a
var testTryExpr = try:
if cond1:
222
else:
raise newException(CatchableError, "test")
except CatchableError:
-123
var testTryExpr2 = try:
if cond1:
333
else:
raise newException(CatchableError, "test")
except CatchableError as e:
echo e.msg
-1234
finally:
echo "finally"
proc getNum(a: int): int = a
echo static(getNum(123))

View File

@@ -1,43 +0,0 @@
type
GenericsType[T] = object
GenericsType2[T] = object
x: T
GenericsType3[T, U] = object
x: T
y: U
GenericsType4[T: int or bool] = distinct int
GenericsType5[N: static[int]; T] = object
x: array[N, T]
GenericsType6[T: SomeNumber] = object
x: T
var genericsType: GenericsType[int]
var genericsType2: GenericsType2[int]
var genericsType3: GenericsType3[float, string]
var genericsType4: GenericsType4[bool]
var genericsType5: GenericsType5[3, float]
var genericsType6: GenericsType6[int8]
proc genericsProc[T]() = discard
genericsProc[int]()
proc genericsProc2[T](x: T) = discard x
genericsProc2(123)
proc genericsProc3[T, U](x: T; y: U) = discard x
genericsProc3("foo", true)
proc genericsProc4[T: int or float](x: T): T = x
discard genericsProc4(1.23)
proc genericsProc5(x: static[int]) = discard x
genericsProc5(123)
proc genericsProc6[T: SomeNumber](x: T) = discard x
genericsProc6(321)
proc genericsProc7[T: SomeNumber](x: T): T = x
discard genericsProc7(321)
proc genericsProc8[N: static[int]; T](x: array[N, T]): T = x[0]
discard genericsProc8([1, 2, 3])

View File

@@ -1,36 +0,0 @@
var strlit = "test string"
var rstrlit = r"test\t raw"
var triplestrlit = """Triple
string
literal
"""
var charlit = 'a'
var intlit1 = 123456
var intlit2 = -123456
var int8litH = 127'i8
var int8litL = -128'i8
var int16litH = 32767'i16
var int16litL = -32768'i16
var int32litH = 2147483647'i32
var int32litL = -2147483648'i32
var int64litH = 9223372036854775807'i64
var int64litL = -9223372036854775808'i64
var uintlitH = 18446744073709551615'u
var uint8litH = 255'u8
var uint16litH = 65535'u16
var uint32litH = 4294967295'u32
var uint64litH = 18446744073709551615'u64
var floatlit = 1.25
var floatlit2 = -1.25
var float32lit = 1.25'f32
var float64lit = 1.25'f64
var floatZero = 0.0
# Needs newer Nimony to save `-0.0` to NIF correclty
#var floatNegZero = -0.0
var floatInf = Inf
var floatNaN = NaN
var floatNegInf = NegInf
var nillit: ptr int = nil

View File

@@ -1,48 +0,0 @@
var exportcTest {.exportc.}: int
var importcTest {.importc.}: int
var y* {.importc, header: "test.h".}: int
var EACCES {.importc, nodecl.}: cint
var volatileTest {.volatile.}: int
const FooBar {.intdefine.}: int = 5
echo FooBar
{.passc: "-Wall -Werror".}
{.link: "myfile.o".}
type
TestImportC {.importc.} = object
x: int
TestImportC2 {.importc: "TestImportC2Name".} = object
x {.importc.}: int
y {.importc: "yyy".}: int
TestBitfield = object
flag {.bitsize:1.}: cuint
TestEnumWithSize* {.size: sizeof(uint32).} = enum
X,
Y,
Z
sseType = object
sseData {.align(16).}: array[4, float32]
TestUnionObj {.union.} = object
x: cint
y: cfloat
const irr = "<irrlicht/irrlicht.h>"
type
IrrlichtDeviceObj {.header: irr,
importcpp: "irr::IrrlichtDevice".} = object
proc importCProc() {.importc.}
proc importCProc2(x: cint) {.importc: "import_c_proc_2".}
proc headerProc(): cint {.importc, header: "foo.h".}
proc exportCProc() {.exportc.}
{.pragma: pragmaPragmaTest, importc, header: "foo.h".}
proc pragmaPragmaTestProc() {.pragmaPragmaTest.}

View File

@@ -1,48 +0,0 @@
proc foo() = discard
foo()
proc bar(x: int): int = x
discard bar(1)
proc baz(x, y: int): int =
bar(x)
proc baz(a: bool; b: string; c: int): float = 0.0
proc forwardDecl()
proc forwardDecl() =
foo()
forwardDecl()
proc forwardDecl2*(): int
proc forwardDecl2*(): int = bar(1)
discard forwardDecl2()
proc forwardDecl3(x, y: int): int
proc forwardDecl3(x, y: int): int = x
discard forwardDecl3(3, 2)
func func1(): int = 123
discard func1()
func func2(x: int): int = x
func func3*(x, y: bool): bool = x
proc withDefaultValue(x = 1) = discard
withDefaultValue()
withDefaultValue(2)
withDefaultValue(x = 3)
proc withDefaultValue2(x = "foo"; y = true) = discard
withDefaultValue2()
withDefaultValue2("bar")
withDefaultValue2(x = "baz", y = false)
proc varParam(x: var int) = x = 10
var x = 0
varParam(x)
proc varRet(x: var int): var int = x
varRet(x) = 100

View File

@@ -1,44 +0,0 @@
var stmtListExpr = (echo "foo"; 111)
if false:
discard
elif false:
discard
else:
discard
var caseExpr = true
case caseExpr
of true:
discard
else:
discard
when sizeof(int) == 2:
echo "running on a 16 bit system!"
elif sizeof(int) == 4:
echo "running on a 32 bit system!"
elif sizeof(int) == 8:
echo "running on a 64 bit system!"
else:
echo "cannot happen!"
while true:
break
var x = 2
while x != 0:
if x == 2:
x = 0
continue
else:
break
block testblock:
while true:
if x > -1:
break testblock
for i in 0 .. 3:
discard i

View File

@@ -1,39 +0,0 @@
type
TestInt = int
TestEnum = enum
X
Y
TestDistinct = distinct int
TestObject = object
x*: int
y: int
TestObject2* = object
x: TestObject
TestRefInt = ref int
TestPtrInt = ptr int
TestRefObj = ref object
x: int
TestPtrObj = ptr object
x: int
TestEmptyObj = object
var x: TestInt
var testEnum: TestEnum
var testEnum1 = X
var testDistinct: TestDistinct
var testObject: TestObject
var testObject2*: TestObject2
var testRefInt: TestRefInt = nil
var testRefInt2: ref int = nil
var testPtrInt: TestPtrInt = nil
var testPtrInt2: ptr int = nil
var testRefObj: TestRefObj = nil
var testPtrObj: TestPtrObj = nil
var testEmptyObj: TestEmptyObj