Browse Source

Lua : Misc and noteworthy!

None of these fixes are particularly interesting, some of the injected
code had the wrong syntax, etc.

One noteworthy thing has now happened:  The entire unit test suite no
longer generates any lua interpreter errors.  Of course, it fails
immediately because of the complex haxe reflection utility code, but
regardless this is a big first step towards running the full unit test
suite.
Justin Donaldson 10 years ago
parent
commit
a5b2cadc29
5 changed files with 43 additions and 26 deletions
  1. 30 15
      genlua.ml
  2. 2 0
      std/StringTools.hx
  3. 1 1
      std/lua/StringTools.hx
  4. 1 1
      std/lua/_std/Math.hx
  5. 9 9
      std/lua/_std/Std.hx

+ 30 - 15
genlua.ml

@@ -337,9 +337,9 @@ let rec gen_call ctx e el in_value =
 		spr ctx "{";
 		spr ctx "{";
 		concat ctx "," (fun (name,data) ->
 		concat ctx "," (fun (name,data) ->
 			spr ctx "{ ";
 			spr ctx "{ ";
-			spr ctx "name : ";
+			spr ctx "name = ";
 			gen_constant ctx e.epos (TString name);
 			gen_constant ctx e.epos (TString name);
-			spr ctx ", data : ";
+			spr ctx ", data = ";
 			gen_constant ctx e.epos (TString (Codegen.bytes_serialize data));
 			gen_constant ctx e.epos (TString (Codegen.bytes_serialize data));
 			spr ctx "}"
 			spr ctx "}"
 		) (Hashtbl.fold (fun name data acc -> (name,data) :: acc) ctx.com.resources []);
 		) (Hashtbl.fold (fun name data acc -> (name,data) :: acc) ctx.com.resources []);
@@ -601,17 +601,29 @@ and gen_expr ctx e =
 		(* TODO: generate this label conditionally *)
 		(* TODO: generate this label conditionally *)
 		print ctx "::_hx_continue_%i::" id;
 		print ctx "::_hx_continue_%i::" id;
 		newline ctx;
 		newline ctx;
-		spr ctx "end ";
+		spr ctx " end ";
 	| TWhile (cond,e,Ast.DoWhile) ->
 	| TWhile (cond,e,Ast.DoWhile) ->
 		let handle_break = handle_break ctx e in
 		let handle_break = handle_break ctx e in
+		ctx.continue_counter <- ctx.continue_counter + 1;
+		let id = ctx.continue_counter in
 		spr ctx "while true do ";
 		spr ctx "while true do ";
 		gen_expr ctx e;
 		gen_expr ctx e;
-		spr ctx "break end while ";
+		spr ctx "break end";
+		newline ctx;
+		print ctx "::_hx_continue_%i::" id;
+		newline ctx;
+		ctx.continue_counter <- ctx.continue_counter + 1;
+		let id2 = ctx.continue_counter in
+		spr ctx " while ";
 		gen_cond ctx cond;
 		gen_cond ctx cond;
 		spr ctx " do ";
 		spr ctx " do ";
 		gen_expr ctx e;
 		gen_expr ctx e;
 		handle_break();
 		handle_break();
-		spr ctx "end ";
+		newline ctx;
+		(* TODO: generate this label conditionally *)
+		print ctx "::_hx_continue_%i::" id2;
+		newline ctx;
+		spr ctx " end ";
 	| TObjectDecl fields ->
 	| TObjectDecl fields ->
 		spr ctx "{ ";
 		spr ctx "{ ";
 		concat ctx ", " (fun (f,e) -> print ctx "%s = " (anon_field f); gen_value ctx e) fields;
 		concat ctx ", " (fun (f,e) -> print ctx "%s = " (anon_field f); gen_value ctx e) fields;
@@ -677,7 +689,7 @@ and gen_expr ctx e =
 			match t with
 			match t with
 			| None ->
 			| None ->
 				last := true;
 				last := true;
-				if !else_block then print ctx "{";
+				if !else_block then print ctx "";
 				if vname <> v.v_name then begin
 				if vname <> v.v_name then begin
 					newline ctx;
 					newline ctx;
 					print ctx "local %s = %s" v.v_name vname;
 					print ctx "local %s = %s" v.v_name vname;
@@ -685,7 +697,7 @@ and gen_expr ctx e =
 				gen_block_element ctx e;
 				gen_block_element ctx e;
 				if !else_block then begin
 				if !else_block then begin
 					newline ctx;
 					newline ctx;
-					print ctx "}";
+					print ctx " end ";
 				end
 				end
 			| Some t ->
 			| Some t ->
 				if not !else_block then newline ctx;
 				if not !else_block then newline ctx;
@@ -700,7 +712,7 @@ and gen_expr ctx e =
 				gen_block_element ctx e;
 				gen_block_element ctx e;
 				bend();
 				bend();
 				newline ctx;
 				newline ctx;
-				spr ctx " else ";
+				spr ctx " else";
 				else_block := true
 				else_block := true
 		) catchs;
 		) catchs;
 		if not !last then begin
 		if not !last then begin
@@ -750,8 +762,8 @@ and gen_expr ctx e =
 
 
 
 
 and gen_block_element ?(after=false) ctx e =
 and gen_block_element ?(after=false) ctx e =
-	match e.eexpr with
-	| TCast _ -> ();
+    begin match e.eexpr with
+	| TTypeExpr _ | TCast _ -> ();
 	| TBinop (op,e1,e2) when op <> Ast.OpAssign ->
 	| TBinop (op,e1,e2) when op <> Ast.OpAssign ->
 		let f () = gen_tbinop ctx op e1 e2 in
 		let f () = gen_tbinop ctx op e1 e2 in
 		gen_iife_assign ctx f;
 		gen_iife_assign ctx f;
@@ -774,9 +786,11 @@ and gen_block_element ?(after=false) ctx e =
 		List.iter (fun (_,e) -> gen_block_element ~after ctx e) fl
 		List.iter (fun (_,e) -> gen_block_element ~after ctx e) fl
 	| _ ->
 	| _ ->
 		if not after then newline ctx;
 		if not after then newline ctx;
+		spr ctx (debug_expression e);
 		gen_expr ctx e;
 		gen_expr ctx e;
 		semicolon ctx;
 		semicolon ctx;
 		if after then newline ctx;
 		if after then newline ctx;
+    end;
 
 
 and gen_value ctx e =
 and gen_value ctx e =
 	let assign e =
 	let assign e =
@@ -1408,15 +1422,16 @@ let generate com =
 		newline ctx;
 		newline ctx;
 	end;
 	end;
 	if has_feature ctx "use._bind" then begin
 	if has_feature ctx "use._bind" then begin
-		print ctx "var $_, $fid = 0";
+		(* TODO:  figure out bind *)
+		(* print ctx "var _, _fid = 0"; *)
 		newline ctx;
 		newline ctx;
-		print ctx "function _bind(o,m) { if( m == nil ) return nil; if( m.__id__ == nil ) m.__id__ = $fid++; var f; if( o.hx__closures__ == nil ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == nil ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; }";
+		(* print ctx "function _bind(o,m) { if( m == nil ) return nil; if( m.__id__ == nil ) m.__id__ = _fid +1; var f; if( o.hx__closures__ == nil ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == nil ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; }"; *)
 		newline ctx;
 		newline ctx;
 	end;
 	end;
 	if has_feature ctx "use._arrayPushClosure" then begin
 	if has_feature ctx "use._arrayPushClosure" then begin
-		print ctx "function _arrayPushClosure(a) {";
-		print ctx " return function(x) { a.push(x); }; ";
-		print ctx "}";
+		print ctx "function _arrayPushClosure(a) ";
+		print ctx " return function(x) a.push(x); end; ";
+		print ctx "end";
 		newline ctx
 		newline ctx
 	end;
 	end;
 	List.iter (gen_block_element ~after:true ctx) (List.rev ctx.inits);
 	List.iter (gen_block_element ~after:true ctx) (List.rev ctx.inits);

+ 2 - 0
std/StringTools.hx

@@ -406,6 +406,8 @@ class StringTools {
 		return if (index >= s.length) -1 else python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
 		return if (index >= s.length) -1 else python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
 		#elseif hl
 		#elseif hl
 		return @:privateAccess s.bytes.getUI16(index << 1);
 		return @:privateAccess s.bytes.getUI16(index << 1);
+		#elseif lua
+		return lua.StringTools.byte(s,index+1);
 		#else
 		#else
 		return untyped s.cca(index);
 		return untyped s.cca(index);
 		#end
 		#end

+ 1 - 1
std/lua/StringTools.hx

@@ -3,7 +3,7 @@ package lua;
   These are all externs for the base Lua "string" class.  Note that all
   These are all externs for the base Lua "string" class.  Note that all
   relevant indexes are "1" based.
   relevant indexes are "1" based.
  **/
  **/
-@:native("_G.string") 
+@:native("_G.string")
 extern class StringTools {
 extern class StringTools {
 	public static function len(str : String): Int;
 	public static function len(str : String): Int;
 	public static function sub(str : String, start : Int, end : Int): String;
 	public static function sub(str : String, start : Int, end : Int): String;

+ 1 - 1
std/lua/_std/Math.hx

@@ -89,6 +89,6 @@ extern class Math
 	}
 	}
 
 
 	static function __init__() : Void {
 	static function __init__() : Void {
-		untyped __feature__("Type.resolveClass", $hxClasses["Math"] = Math);
+		untyped __feature__("Type.resolveClass", _hxClasses["Math"] = Math);
 	}
 	}
 }
 }

+ 9 - 9
std/lua/_std/Std.hx

@@ -59,36 +59,36 @@ import lua.Boot;
 	}
 	}
 
 
 	static function __init__() : Void untyped {
 	static function __init__() : Void untyped {
-		__feature__("js.Boot.getClass",String.prototype.__class__ = __feature__("Type.resolveClass",$hxClasses["String"] = String,String));
+		__feature__("js.Boot.getClass",String.prototype.__class__ = __feature__("Type.resolveClass",_hxClasses["String"] = String,String));
 		__feature__("js.Boot.isClass",String.__name__ = __feature__("Type.getClassName",["String"],true));
 		__feature__("js.Boot.isClass",String.__name__ = __feature__("Type.getClassName",["String"],true));
-		__feature__("Type.resolveClass",$hxClasses["Array"] = Array);
+		__feature__("Type.resolveClass",_hxClasses["Array"] = Array);
 		__feature__("js.Boot.isClass",Array.__name__ = __feature__("Type.getClassName",["Array"],true));
 		__feature__("js.Boot.isClass",Array.__name__ = __feature__("Type.getClassName",["Array"],true));
 		__feature__("Date.*", {
 		__feature__("Date.*", {
-			__feature__("js.Boot.getClass",__js__('Date').prototype.__class__ = __feature__("Type.resolveClass",$hxClasses["Date"] = __js__('Date'),__js__('Date')));
+			__feature__("js.Boot.getClass",__js__('Date').prototype.__class__ = __feature__("Type.resolveClass",_hxClasses["Date"] = __js__('Date'),__js__('Date')));
 			__feature__("js.Boot.isClass",__js__('Date').__name__ = ["Date"]);
 			__feature__("js.Boot.isClass",__js__('Date').__name__ = ["Date"]);
 		});
 		});
 		__feature__("Int.*",{
 		__feature__("Int.*",{
-			var Int = __feature__("Type.resolveClass", $hxClasses["Int"] = { __name__ : ["Int"] }, { __name__ : ["Int"] });
+			var Int = __feature__("Type.resolveClass", _hxClasses["Int"] = { __name__ : ["Int"] }, { __name__ : ["Int"] });
 		});
 		});
 		__feature__("Dynamic.*",{
 		__feature__("Dynamic.*",{
-			var Dynamic = __feature__("Type.resolveClass", $hxClasses["Dynamic"] = { __name__ : ["Dynamic"] }, { __name__ : ["Dynamic"] });
+			var Dynamic = __feature__("Type.resolveClass", _hxClasses["Dynamic"] = { __name__ : ["Dynamic"] }, { __name__ : ["Dynamic"] });
 		});
 		});
 		__feature__("Float.*",{
 		__feature__("Float.*",{
-			var Float = __feature__("Type.resolveClass", $hxClasses["Float"] = __js__("Number"), __js__("Number"));
+			var Float = __feature__("Type.resolveClass", _hxClasses["Float"] = __js__("Number"), __js__("Number"));
 			Float.__name__ = ["Float"];
 			Float.__name__ = ["Float"];
 		});
 		});
 		__feature__("Bool.*",{
 		__feature__("Bool.*",{
-			var Bool = __feature__("Type.resolveEnum",$hxClasses["Bool"] = __js__("Boolean"), __js__("Boolean"));
+			var Bool = __feature__("Type.resolveEnum",_hxClasses["Bool"] = __js__("Boolean"), __js__("Boolean"));
 			Bool.__ename__ = ["Bool"];
 			Bool.__ename__ = ["Bool"];
 		});
 		});
 		__feature__("Class.*",{
 		__feature__("Class.*",{
-			var Class = __feature__("Type.resolveClass", $hxClasses["Class"] = { __name__ : ["Class"] }, { __name__ : ["Class"] });
+			var Class = __feature__("Type.resolveClass", _hxClasses["Class"] = { __name__ : ["Class"] }, { __name__ : ["Class"] });
 		});
 		});
 		__feature__("Enum.*",{
 		__feature__("Enum.*",{
 			var Enum = {};
 			var Enum = {};
 		});
 		});
 		__feature__("Void.*",{
 		__feature__("Void.*",{
-			var Void = __feature__("Type.resolveEnum", $hxClasses["Void"] = { __ename__ : ["Void"] }, { __ename__ : ["Void"] });
+			var Void = __feature__("Type.resolveEnum", _hxClasses["Void"] = { __ename__ : ["Void"] }, { __ename__ : ["Void"] });
 		});
 		});
 
 
 	}
 	}