@@ -5,6 +5,7 @@ import {CPPMangler} from "./cpp.mangler";
55import { Context } from "./context" ;
66import { NativeTypeResolver } from "./native-type-resolver" ;
77import UnsupportedError from "../error/unsupported.error" ;
8+ import { NativeType } from "./native-type" ;
89
910export function passReturnStatement ( parent : ts . ReturnStatement , ctx : Context , builder : llvm . IRBuilder ) {
1011 if ( ! parent . expression ) {
@@ -74,13 +75,19 @@ function buildFromNumericLiteral(
7475 value : ts . NumericLiteral ,
7576 ctx : Context ,
7677 builder : llvm . IRBuilder ,
77- lType ?: llvm . Type
78+ nativeType ?: NativeType
7879) : llvm . Value {
79- if ( ! lType || lType . isDoubleTy ( ) ) {
80+ if ( ! nativeType || nativeType . getType ( ) . isDoubleTy ( ) ) {
8081 return llvm . ConstantFP . get ( ctx . llvmContext , parseFloat ( value . text ) ) ;
8182 }
8283
83- return llvm . ConstantInt . get ( ctx . llvmContext , parseInt ( value . text ) , ( < llvm . IntegerType > lType ) . getBitWidth ( ) ) ;
84+ const type = nativeType . getType ( ) ;
85+ return llvm . ConstantInt . get (
86+ ctx . llvmContext ,
87+ parseInt ( value . text ) ,
88+ ( < llvm . IntegerType > type ) . getBitWidth ( ) ,
89+ nativeType . isSigned ( )
90+ ) ;
8491}
8592
8693function buildFromBinaryExpression (
@@ -195,12 +202,12 @@ function buildFromIdentifier(identifier: ts.Identifier, ctx: Context, builder: l
195202}
196203
197204
198- function buildFromExpression ( block : ts . Expression , ctx : Context , builder : llvm . IRBuilder , lType ?: llvm . Type ) : llvm . Value {
205+ function buildFromExpression ( block : ts . Expression , ctx : Context , builder : llvm . IRBuilder , nativeType ?: NativeType ) : llvm . Value {
199206 switch ( block . kind ) {
200207 case ts . SyntaxKind . Identifier :
201208 return buildFromIdentifier ( < any > block , ctx , builder ) ;
202209 case ts . SyntaxKind . NumericLiteral :
203- return buildFromNumericLiteral ( < any > block , ctx , builder , lType ) ;
210+ return buildFromNumericLiteral ( < any > block , ctx , builder , nativeType ) ;
204211 case ts . SyntaxKind . StringLiteral :
205212 return buildFromStringValue ( < any > block , ctx , builder ) ;
206213 case ts . SyntaxKind . BinaryExpression :
@@ -224,16 +231,16 @@ export function passVariableDeclaration(block: ts.VariableDeclaration, ctx: Cont
224231 if ( block . initializer ) {
225232 const type = ctx . typeChecker . getTypeAtLocation ( block ) ;
226233
227- const llvmType = NativeTypeResolver . getType (
234+ const nativeType = NativeTypeResolver . getType (
228235 type ,
229236 ctx
230237 ) ;
231238
232- const defaultValue = buildFromExpression ( block . initializer , ctx , builder , llvmType ) ;
239+ const defaultValue = buildFromExpression ( block . initializer , ctx , builder , nativeType ) ;
233240
234241 if ( block . name . kind == ts . SyntaxKind . Identifier ) {
235242 const allocate = builder . createAlloca (
236- llvmType ,
243+ nativeType . getType ( ) ,
237244 undefined ,
238245 < string > block . name . escapedText
239246 ) ;
0 commit comments