@@ -51,7 +51,8 @@ import {
5151import {
5252 Type ,
5353 Signature ,
54- typesToString
54+ typesToString ,
55+ TypeKind
5556} from "./types" ;
5657
5758import {
@@ -154,30 +155,29 @@ export class Resolver extends DiagnosticEmitter {
154155 }
155156
156157 // resolve parameters
157- {
158- let typeArgumentNodes = typeNode . typeArguments ;
159- if ( typeArgumentNodes ) {
160- let numTypeArguments = typeArgumentNodes . length ;
161- let paramTypes = new Array < Type > ( numTypeArguments ) ;
162- for ( let i = 0 ; i < numTypeArguments ; ++ i ) {
163- let paramType = this . resolveType ( // reports
164- typeArgumentNodes [ i ] ,
165- contextualTypeArguments ,
166- reportMode
167- ) ;
168- if ( ! paramType ) return null ;
169- paramTypes [ i ] = paramType ;
170- }
171- if ( numTypeArguments ) { // can't be a placeholder if it has parameters
172- let instanceKey = typesToString ( paramTypes ) ;
173- if ( instanceKey . length ) {
174- localName += "<" + instanceKey + ">" ;
175- globalName += "<" + instanceKey + ">" ;
176- }
177- } else if ( contextualTypeArguments ) {
178- let placeholderType = contextualTypeArguments . get ( globalName ) ;
179- if ( placeholderType ) return placeholderType ;
158+ var typeArgumentNodes = typeNode . typeArguments ;
159+ var typeArguments : Type [ ] | null = null ;
160+ if ( typeArgumentNodes ) {
161+ let numTypeArguments = typeArgumentNodes . length ;
162+ typeArguments = new Array < Type > ( numTypeArguments ) ;
163+ for ( let i = 0 ; i < numTypeArguments ; ++ i ) {
164+ let paramType = this . resolveType ( // reports
165+ typeArgumentNodes [ i ] ,
166+ contextualTypeArguments ,
167+ reportMode
168+ ) ;
169+ if ( ! paramType ) return null ;
170+ typeArguments [ i ] = paramType ;
171+ }
172+ if ( numTypeArguments ) { // can't be a placeholder if it has parameters
173+ let instanceKey = typesToString ( typeArguments ) ;
174+ if ( instanceKey . length ) {
175+ localName += "<" + instanceKey + ">" ;
176+ globalName += "<" + instanceKey + ">" ;
180177 }
178+ } else if ( contextualTypeArguments ) {
179+ let placeholderType = contextualTypeArguments . get ( globalName ) ;
180+ if ( placeholderType ) return placeholderType ;
181181 }
182182 }
183183
@@ -193,6 +193,36 @@ export class Resolver extends DiagnosticEmitter {
193193 }
194194 }
195195
196+ // check built-in macro types
197+ if ( simpleName == "NATIVE" ) {
198+ if ( ! ( typeArguments && typeArguments . length == 1 ) ) {
199+ if ( reportMode == ReportMode . REPORT ) {
200+ this . error (
201+ DiagnosticCode . Expected_0_type_arguments_but_got_1 ,
202+ typeNode . range , "1" , ( typeArgumentNodes ? typeArgumentNodes . length : 1 ) . toString ( 10 )
203+ ) ;
204+ }
205+ return null ;
206+ }
207+ switch ( typeArguments [ 0 ] . kind ) {
208+ case TypeKind . I8 :
209+ case TypeKind . I16 :
210+ case TypeKind . I32 : return Type . i32 ;
211+ case TypeKind . ISIZE : if ( ! this . program . options . isWasm64 ) return Type . i32 ;
212+ case TypeKind . I64 : return Type . i64 ;
213+ case TypeKind . U8 :
214+ case TypeKind . U16 :
215+ case TypeKind . U32 :
216+ case TypeKind . BOOL : return Type . u32 ;
217+ case TypeKind . USIZE : if ( ! this . program . options . isWasm64 ) return Type . u32 ;
218+ case TypeKind . U64 : return Type . u64 ;
219+ case TypeKind . F32 : return Type . f32 ;
220+ case TypeKind . F64 : return Type . f64 ;
221+ case TypeKind . VOID : return Type . void ;
222+ default : assert ( false ) ;
223+ }
224+ }
225+
196226 if ( reportMode == ReportMode . REPORT ) {
197227 this . error (
198228 DiagnosticCode . Cannot_find_name_0 ,
0 commit comments