Browse Source

added :: operator (OpList)

Nicolas Cannasse 7 years ago
parent
commit
b6a7b24fa3

+ 1 - 1
src/codegen/gencommon/dynamicOperators.ml

@@ -119,7 +119,7 @@ let init com handle_strings (should_change:texpr->bool) (equals_handler:texpr->t
 				{ e with eexpr = TBinop (op, mk_cast com.basic.tbool (run e1), mk_cast com.basic.tbool (run e2)) }
 			| OpAnd | OpOr | OpXor | OpShl | OpShr | OpUShr ->
 				{ e with eexpr = TBinop (op, mk_cast com.basic.tint (run e1), mk_cast com.basic.tint (run e2)) }
-			| OpAssign | OpAssignOp _ | OpInterval | OpArrow | OpIn ->
+			| OpAssign | OpAssignOp _ | OpInterval | OpArrow | OpIn | OpList ->
 				assert false)
 
 		| TUnop (Increment as op, flag, e1)

+ 2 - 0
src/core/ast.ml

@@ -89,6 +89,7 @@ type binop =
 	| OpInterval
 	| OpArrow
 	| OpIn
+	| OpList
 
 type unop =
 	| Increment
@@ -441,6 +442,7 @@ let rec s_binop = function
 	| OpInterval -> "..."
 	| OpArrow -> "=>"
 	| OpIn -> " in "
+	| OpList -> "::"
 
 let s_unop = function
 	| Increment -> "++"

+ 3 - 0
src/generators/gencpp.ml

@@ -4093,6 +4093,7 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args function_
       | OpInterval -> "..."
       | OpArrow -> "->"
       | OpIn -> " in "
+	  | OpList -> assert false
       | OpAssign | OpAssignOp _ -> abort "Unprocessed OpAssign" pos
    and string_of_path path =
       "::" ^ (join_class_path_remap path "::") ^ "_obj"
@@ -7038,6 +7039,7 @@ let cppia_op_info = function
 	| IaBinOp OpInterval -> ("...", 121)
 	| IaBinOp OpArrow -> ("=>", 122)
 	| IaBinOp OpIn -> (" in ", 123)
+	| IaBinOp OpList -> assert false
 	| IaBinOp OpAssignOp OpAdd -> ("+=", 201)
 	| IaBinOp OpAssignOp OpMult -> ("*=", 202)
 	| IaBinOp OpAssignOp OpDiv -> ("/=", 203)
@@ -7055,6 +7057,7 @@ let cppia_op_info = function
 	| IaBinOp OpAssignOp OpMod -> ("%=", 220)
 
 	| IaBinOp OpAssignOp OpIn
+	| IaBinOp OpAssignOp OpList
 	| IaBinOp OpAssignOp OpInterval
 	| IaBinOp OpAssignOp OpAssign
 	| IaBinOp OpAssignOp OpEq

+ 1 - 1
src/generators/genhl.ml

@@ -2352,7 +2352,7 @@ and eval_expr ctx e =
 					free ctx r;
 					binop r r b;
 					r))
-		| OpInterval | OpArrow | OpIn ->
+		| OpInterval | OpArrow | OpIn | OpList ->
 			assert false)
 	| TUnop (Not,_,v) ->
 		let tmp = alloc_tmp ctx HBool in

+ 1 - 1
src/generators/genpy.ml

@@ -1053,7 +1053,7 @@ module Printer = struct
 		| OpShr -> ">>"
 		| OpUShr -> ">>"
 		| OpMod -> "%"
-		| OpInterval | OpArrow | OpIn | OpAssignOp _ -> assert false
+		| OpInterval | OpArrow | OpIn | OpAssignOp _ | OpList -> assert false
 
 	let print_string s =
 		Printf.sprintf "\"%s\"" (Ast.s_escape s)

+ 1 - 1
src/generators/genswf9.ml

@@ -1691,7 +1691,7 @@ and gen_binop ctx retval op e1 e2 t p =
 		gen_op A3OLt
 	| OpLte ->
 		gen_op A3OLte
-	| OpInterval | OpArrow | OpIn ->
+	| OpInterval | OpArrow | OpIn | OpList ->
 		assert false
 
 and gen_expr ctx retval e =

+ 1 - 1
src/macro/eval/evalJit.ml

@@ -64,7 +64,7 @@ let get_binop_fun op p = match op with
 	| OpShr -> op_shr p
 	| OpUShr -> op_ushr p
 	| OpMod -> op_mod p
-	| OpAssign | OpBoolAnd | OpBoolOr | OpAssignOp _ | OpInterval | OpArrow | OpIn -> assert false
+	| OpAssign | OpBoolAnd | OpBoolOr | OpAssignOp _ | OpInterval | OpArrow | OpIn | OpList -> assert false
 
 open EvalJitContext
 

+ 2 - 0
src/macro/macroApi.ml

@@ -342,6 +342,7 @@ let rec encode_binop op =
 	| OpInterval -> 21, []
 	| OpArrow -> 22, []
 	| OpIn -> 23, []
+	| OpList -> 24, []
 	in
 	encode_enum IBinop tag pl
 
@@ -619,6 +620,7 @@ let rec decode_op op =
 	| 21, [] -> OpInterval
 	| 22,[] -> OpArrow
 	| 23,[] -> OpIn
+	| 24,[] -> OpList
 	| _ -> raise Invalid_expr
 
 let decode_unop op =

+ 1 - 0
src/optimization/analyzerTexpr.ml

@@ -606,6 +606,7 @@ module Fusion = struct
 		| OpShl
 		| OpShr
 		| OpUShr
+		| OpList
 		| OpMod ->
 			true
 		| OpAssign

+ 1 - 1
src/optimization/analyzerTexprTransformer.ml

@@ -727,7 +727,7 @@ and func ctx i =
 			let e2 = loop e2 in
 			let e3 = loop e3 in
 			let is_valid_assign_op = function
-				| OpAdd | OpMult | OpDiv | OpSub | OpAnd
+				| OpAdd | OpMult | OpDiv | OpSub | OpAnd | OpList
 				| OpOr | OpXor | OpShl | OpShr | OpUShr | OpMod ->
 					true
 				| OpAssignOp _ | OpInterval | OpArrow | OpIn | OpAssign | OpEq

+ 1 - 1
src/optimization/optimizer.ml

@@ -917,7 +917,7 @@ let standard_precedence op =
 	match op with
 	| OpIn -> 4, right
 	| OpMult | OpDiv | OpMod -> 5, left
-	| OpAdd | OpSub -> 6, left
+	| OpAdd | OpSub | OpList -> 6, left
 	| OpShl | OpShr | OpUShr -> 7, left
 	| OpLt | OpLte | OpGt | OpGte -> 8, left
 	| OpEq | OpNotEq -> 9, left

+ 1 - 0
src/syntax/lexer.ml

@@ -325,6 +325,7 @@ let rec token lexbuf =
 	| ">" -> mk lexbuf (Binop OpGt)
 	| ";" -> mk lexbuf Semicolon
 	| ":" -> mk lexbuf DblDot
+	| "::" -> mk lexbuf (Binop OpList)
 	| "," -> mk lexbuf Comma
 	| "." -> mk lexbuf Dot
 	| "%" -> mk lexbuf (Binop OpMod)

+ 1 - 1
src/syntax/parser.ml

@@ -136,7 +136,7 @@ let precedence op =
 	| OpIn -> 0, right
 	| OpMod -> 1, left
 	| OpMult | OpDiv -> 2, left
-	| OpAdd | OpSub -> 3, left
+	| OpAdd | OpSub | OpList -> 3, left
 	| OpShl | OpShr | OpUShr -> 4, left
 	| OpOr | OpAnd | OpXor -> 5, left
 	| OpEq | OpNotEq | OpGt | OpLt | OpGte | OpLte -> 6, left

+ 1 - 0
src/syntax/reification.ml

@@ -65,6 +65,7 @@ let reify in_macro =
 		| OpInterval -> op "OpInterval"
 		| OpArrow -> op "OpArrow"
 		| OpIn -> op "OpIn"
+		| OpList -> op "OpList"
 	in
 	let to_string s p =
 		let len = String.length s in

+ 2 - 0
src/typing/typer.ml

@@ -2055,6 +2055,8 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 		error "Unexpected =>" p
 	| OpIn ->
 		error "Unexpected in" p
+	| OpList ->
+		error "Unexpected ::" p
 	| OpAssign
 	| OpAssignOp _ ->
 		assert false

+ 5 - 0
std/haxe/macro/Expr.hx

@@ -217,6 +217,11 @@ enum Binop {
 		`in`
 	**/
 	OpIn;
+	
+	/**
+		`::`
+	**/
+	OpList;
 }
 
 /**