Closed Sinfolke closed 1 month ago
I will improve it for "any" type.
try this code:
let arr: any[] = [1, 2, 3, 4];
function main() {
let a: any = "Hello, World!";
print(a);
for (let i: int = 0; i < arr.length; i++) {
print(<string>arr[i]);
}
}
I would recommend to write something like the following:
const arr : TypeOf<1>[] = [1, 2, 3, 4];
function main() {
let a = "Hello, World!";
print(a);
for (const i of arr) {
print(i);
}
}
- Caused the compiler waite also for around 3-5 seconds and just quit with no messages. It occurs just if insert that line even without main function.
let arr: Array<number> = "";
this one is working in my latest git version
IDK
C:\programming\tsc>tsc --version
TypeScript Native Compiler (https://github.com/ASDAlexander77/TypeScriptCompiler):
TSNC version v0.0-pre-alpha46
LLVM (http://llvm.org/):
LLVM version 17.0.2
Optimized build.
Default target: x86_64-pc-windows-msvc
Host CPU: alderlake
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
thumb - Thumb
thumbeb - Thumb (big endian)
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
C:\programming\tsc>tsc --emit=jit
let arr: Array
C:\programming\tsc>
i used the prebuild release. Possibly you're using own build release and therefore missmatches. And possibly you've already accidentally fixed it. Also you could run on linux while i do on windows.
C:\programming\tsc>tsc --emit=jit let arr: Array = ""; ^Z
C:\programming\tsc>
here is missing
function main() {}
it should show the error:
tsc: error: JIT invocation failed, error: Symbols not found: [ _mlir_main ]
Program aborted due to an unhandled Error: ...
idk when i add to the release i installed it always aborts without depend what's more is there
and even no matter what type is within Array<>
in other words you can cast "any" type into any
but you can't cast from any
into other type that type was stored. for example
const v1: number = 1;
const any1: any = v1; // it is OK
const v2: number = any1; // it is still OK
const s1: string = any1; // it is ***NOT OK***;
const s2: string = <string>any1; // it is OK
here is example of unboxing from any:
function __as<T>(a: any) : T
{
if (typeof a == 'number') return <T>a;
if (typeof a == 'string') return <T>a;
if (typeof a == 'i32') return <T>a;
if (typeof a == 'class') if (a instanceof T) return <T>a;
return <T>null;
}
so u can use it as
const s3: string = __as(any1);
improved code in the latest commit, it will be included in the next release
in the next release unboxing any type from any
will be OK.
let a = 1;
let any1: any = a;
let s: string = any1;
print(s);
I have tested it recently and found out some issues with types. They seem to be simple so maybe you just didn't went up to fix them
0 0x00007ff9cfa4a6e0 (C:\WINDOWS\System32\ucrtbase.dll+0x5a6e0)
1 0x00007ff9cfa4a762 (C:\WINDOWS\System32\ucrtbase.dll+0x5a762)
2 0x0000029e8d94015b