浏览代码

Correctly initialise global variable. Fixes #65.

woollybah 10 年之前
父节点
当前提交
d8a62dc283
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 9 1
      ctranslator.bmx
  2. 1 1
      options.bmx

+ 9 - 1
ctranslator.bmx

@@ -525,7 +525,7 @@ t:+"NULLNULLNULL"
 
 		glob :+ munged+"="
 
-		If TNewObjectExpr(init) And Not (attrs & DECL_INITONLY) Then
+		If (TNewObjectExpr(init) Or TNewArrayExpr(init)) And Not (attrs & DECL_INITONLY) Then
 			glob :+ "0;~n"
 			glob :+ indent + "if (" + munged + "==0) {~n"
 			glob :+ indent + "~t" + munged + "=" + init.Trans() + ";~n"
@@ -547,6 +547,14 @@ t:+"NULLNULLNULL"
 					Else
 						glob :+ init.Trans()
 					End If
+				Else If Not TConstExpr(init) And Not (attrs & DECL_INITONLY) Then
+					' for non const, we need to add an initialiser
+					glob :+ TransValue(ty, "") + ";~n"
+					glob :+ indent +"static int _" + munged + "_inited = 0;~n"
+					glob :+ indent + "if (!_" + munged + "_inited) {~n"
+					glob :+ indent + "~t_" + munged + "_inited = 1;~n"
+					glob :+ indent + "~t" + munged + " = " + init.Trans() + ";~n"
+					glob :+ indent + "}"
 				Else
 					glob :+ init.Trans()
 				End If

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.34"
+Const version:String = "0.35"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1