Comments (5)
- Also, I see that 100 is handled as a floating-point number (double).
Although Typescript considers all number as thenumber
type, is there a way
to know the intention whether it is an integer or a floating point number?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
At the abstract level, nodejs v8 engine is smart enough to interpret values of the Number type into double-precision numbers between -(2^53 − 1) and 2^53 − 1. MORE THAN THIS RANGE, the value of the Number type is to be represented as special symbols: -Infinity, Infinity, or NaN.
from tsll.
Thanks @lung21!
-
Can you test with more generics of primitive types and print intput/output?
let v1 = new AnotherClass<bool>(true); let v2 = new AnotherClass<string>("foo"); ...
-
Also, I see that 100 is handled as a floating-point number (double).
Although Typescript considers all number as the
number
type, is there a way
to know the intention whether it is an integer or a floating point number?
from tsll.
@taquangtrung Thank you...
To follow up, for the first question, we could successfully test generics of primitives and more nested generics as follows.
Input in Typescript
class AnotherClass<T> {
private testPrivateMember: T;
constructor(intro: T) {
this.testPrivateMember = intro;
}
public testPrivateInPublic(): T {
return this.testPrivateMember;
}
}
class GenericClass<T> {
private testPrivateMember: T;
constructor(intro: T) {
this.testPrivateMember = intro;
}
public testPrivateInPublic(): T {
return this.testPrivateMember;
}
}
let typicalGeneric = new GenericClass<number>(100);
let boolGeneric = new AnotherClass<string>('errc');
let nestedGeneric = new AnotherClass<AnotherClass<string>>(boolGeneric);
Output in LLVM IR
; ModuleID = 'genericType.ts'
source_filename = "genericType.ts"
%GenericClass_double = type { double }
%"AnotherClass_i8*" = type { i8* }
%"AnotherClass_%\22AnotherClass_i8*\22*" = type { %"AnotherClass_i8*"* }
@0 = private unnamed_addr constant [5 x i8] c"errc\00", align 1
define void @main(...) {
%typicalGeneric = alloca %GenericClass_double, align 8
call void (%GenericClass_double*, double, ...) @GenericClass_double_Constructor(%GenericClass_double* %typicalGeneric, double 1.000000e+02)
%boolGeneric = alloca %"AnotherClass_i8*", align 8
call void (%"AnotherClass_i8*"*, i8*, ...) @"AnotherClass_i8*_Constructor"(%"AnotherClass_i8*"* %boolGeneric, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0))
%nestedGeneric = alloca %"AnotherClass_%\22AnotherClass_i8*\22*", align 8
call void (%"AnotherClass_%\22AnotherClass_i8*\22*"*, %"AnotherClass_i8*"*, ...) @"AnotherClass_%\22AnotherClass_i8*\22*_Constructor"(%"AnotherClass_%\22AnotherClass_i8*\22*"* %nestedGeneric, %"AnotherClass_i8*"* %boolGeneric)
ret void
}
define void @GenericClass_double_Constructor(%GenericClass_double* %this, double %intro, ...) {
%1 = alloca double, align 8
store double %intro, double* %1, align 8
%2 = getelementptr inbounds %GenericClass_double, %GenericClass_double* %this, i32 0, i32 0
%3 = load double, double* %1, align 8
store double %3, double* %2, align 8
ret void
}
define double @GenericClass_double_testPrivateInPublic(%GenericClass_double* %this, ...) {
%1 = getelementptr inbounds %GenericClass_double, %GenericClass_double* %this, i32 0, i32 0
%2 = load double, double* %1, align 8
ret double %2
}
define void @"AnotherClass_i8*_Constructor"(%"AnotherClass_i8*"* %this, i8* %intro, ...) {
%1 = getelementptr inbounds %"AnotherClass_i8*", %"AnotherClass_i8*"* %this, i32 0, i32 0
store i8* %intro, i8** %1, align 8
ret void
}
define i8** @"AnotherClass_i8*_testPrivateInPublic"(%"AnotherClass_i8*"* %this, ...) {
%1 = getelementptr inbounds %"AnotherClass_i8*", %"AnotherClass_i8*"* %this, i32 0, i32 0
ret i8** %1
}
define void @"AnotherClass_%\22AnotherClass_i8*\22*_Constructor"(%"AnotherClass_%\22AnotherClass_i8*\22*"* %this, %"AnotherClass_i8*"* %intro, ...) {
%1 = getelementptr inbounds %"AnotherClass_%\22AnotherClass_i8*\22*", %"AnotherClass_%\22AnotherClass_i8*\22*"* %this, i32 0, i32 0
store %"AnotherClass_i8*"* %intro, %"AnotherClass_i8*"** %1, align 8
ret void
}
define %"AnotherClass_i8*"** @"AnotherClass_%\22AnotherClass_i8*\22*_testPrivateInPublic"(%"AnotherClass_%\22AnotherClass_i8*\22*"* %this, ...) {
%1 = getelementptr inbounds %"AnotherClass_%\22AnotherClass_i8*\22*", %"AnotherClass_%\22AnotherClass_i8*\22*"* %this, i32 0, i32 0
ret %"AnotherClass_i8*"** %1
}
For the second question, although we have realized that Nodejs v8 engine may store number
type in double or int32, we should investigate further and modify our typescriptllvm to allocate proper sizes for the number
type in LLVM IR.
from tsll.
Thanks Lung! The generated code seems correct.
I notice that the parameters still keep names like %intro, %this
. Maybe you want to rename it to LLVM SSA format similar to Clang to avoid potential naming conflict in the future?
from tsll.
Implemented, under test
from tsll.
Related Issues (12)
- Node installation issue HOT 5
- Translation of TypeAliasDeclaration from Typescript into LLVM IR HOT 1
- Translation of IndexedAccessType from Typescript into LLVM IR HOT 1
- Translation of UnionType from Typescript into LLVM IR HOT 1
- Translation of IntersectionType from Typescript into LLVM IR HOT 1
- Translation of Typescript anyType to LLVM IR HOT 3
- Failed to install typescriptllvm globally HOT 1
- Compilation of library imports into LLVM IR/Bitcode HOT 5
- Attach debugging information to instructions in LLVM IR HOT 4
- Translation of enum into LLVM IR HOT 1
- Translation of extends/implements into LLVM IR HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsll.