Przeglądaj źródła

Added WString extern type.

Mark Sibly 7 lat temu
rodzic
commit
fbeb595c0f

+ 8 - 0
modules/monkey/types.monkey2

@@ -399,6 +399,14 @@ This type should only be used when declaring parameters for extern functions.
 Struct @CString="bbCString"
 End
 
+#rem monkeydoc String wrapper type for native 'wchar_t *' strings.
+
+This type should only be used when declaring parameters for extern functions.
+
+#end
+Struct @WString="bbWString"
+End
+
 #rem monkeydoc Variant type.
 
 The 'Variant' type is a primitive type that can be used to 'box' values of any type.

+ 4 - 1
src/mx2cc/builder.monkey2

@@ -574,6 +574,7 @@ Class BuilderInstance
 		Type.ThrowableClass=TCast<ClassType>( types.nodes["@throwable"] )
 
 		Type.CStringClass=TCast<ClassType>( types.nodes["@cstring"] )
+		Type.WStringClass=TCast<ClassType>( types.nodes["@wstring"] )
 		Type.TypeInfoClass=TCast<ClassType>( types.nodes["@typeinfo"] )
 
 		rootNamespace.Insert( "void",Type.VoidType )
@@ -595,6 +596,7 @@ Class BuilderInstance
 		rootNamespace.Insert( "throwable",Type.ThrowableClass )
 
 		rootNamespace.Insert( "cstring",Type.CStringClass )
+		rootNamespace.Insert( "wstring",Type.WStringClass )
 		rootNamespace.Insert( "typeinfo",Type.TypeInfoClass )
 		
 		Type.BoolType.Semant()
@@ -614,6 +616,7 @@ Class BuilderInstance
 		Type.ObjectClass.Semant()
 		Type.ThrowableClass.Semant()
 		Type.CStringClass.Semant()
+		Type.WStringClass?.Semant()
 		Type.TypeInfoClass.Semant()
 	End
 	
@@ -661,7 +664,7 @@ Class BuilderInstance
 		Case ".lib"
 			
 			If opts.toolchain="msvc"
-				product.LIB_FILES.Push( name )
+				product.LIB_FILES.Push( StripDir( path ) )'name )
 			Else
 				product.LIB_FILES.Push( "-l"+name )
 			Endif

+ 1 - 1
src/mx2cc/parser.monkey2

@@ -1257,7 +1257,7 @@ Class Parser
 	
 	Method IsTypeIdent:Bool( ident:String )
 		Select ident
-		Case "void","bool","byte","ubyte","short","ushort","int","uint","long","ulong","float","double","string","object","throwable","variant","cstring","typeinfo"
+		Case "void","bool","byte","ubyte","short","ushort","int","uint","long","ulong","float","double","string","object","throwable","variant","cstring","wstring","typeinfo"
 			Return True
 		End
 		Return False

+ 1 - 1
src/mx2cc/toker.monkey2

@@ -36,7 +36,7 @@ Function InitToker:Void()
 	keyWords+="Repeat;Until;Forever;"
 	keyWords+="For;To;Step;Next;"
 	keyWords+="Select;Case;Default;"
-	keyWords+="Try;Catch;Throw;Throwable;Variant;CString;TypeInfo;Typeof;"
+	keyWords+="Try;Catch;Throw;Throwable;Variant;CString;WString;TypeInfo;Typeof;"
 	keyWords+="Return;Print;Static;Cast;"
 	keyWords+="Extension;Protocol;Finalize;Delete"
 

+ 4 - 2
src/mx2cc/type.monkey2

@@ -29,6 +29,8 @@ Class Type Extends SNode
 	Global ThrowableClass:ClassType
 	
 	Global CStringClass:ClassType
+	Global WStringClass:ClassType
+	
 	Global TypeInfoClass:ClassType
 	
 	Field flags:Int
@@ -269,7 +271,7 @@ Class PrimType Extends Type
 			'numeric->string
 			If IsNumeric Or Self=BoolType Return MAX_DISTANCE
 
-		Case CStringClass
+		Case CStringClass,WStringClass
 		
 			'numeric,string->cstring.
 			If Self=StringType Or IsNumeric Return MAX_DISTANCE
@@ -576,7 +578,7 @@ Class FuncType Extends Type
 		Local r:Value=New InvokeValue( value,args )
 		
 		'Autocast CString to String
-		If r.type.Equals( Type.CStringClass )
+		If r.type.Equals( Type.CStringClass ) Or r.type.Equals( Type.WStringClass )
 			r=New UpCastValue( Type.StringType,r )
 		Endif