|
@@ -438,53 +438,11 @@ let no_value ctx retval =
|
|
|
(* -------------------------------------------------------------- *)
|
|
|
(* Generation *)
|
|
|
|
|
|
-let unescape_chars s p =
|
|
|
- let b = Buffer.create 0 in
|
|
|
- let rec loop esc i =
|
|
|
- if i = String.length s then
|
|
|
- ()
|
|
|
- else
|
|
|
- let c = s.[i] in
|
|
|
- if esc then begin
|
|
|
- let inext = ref (i + 1) in
|
|
|
- (match c with
|
|
|
- | 'n' -> Buffer.add_char b '\n'
|
|
|
- | 'r' -> Buffer.add_char b '\r'
|
|
|
- | 't' -> Buffer.add_char b '\t'
|
|
|
- | '"' | '\'' | '\\' -> Buffer.add_char b c
|
|
|
- | '0'..'3' ->
|
|
|
- let c = (try
|
|
|
- char_of_int (int_of_string ("0o" ^ String.sub s i 3))
|
|
|
- with _ ->
|
|
|
- raise (Lexer.Error (Lexer.Invalid_character c,p))
|
|
|
- ) in
|
|
|
- Buffer.add_char b c;
|
|
|
- inext := !inext + 2;
|
|
|
- | 'x' ->
|
|
|
- let c = (try
|
|
|
- char_of_int (int_of_string ("0x" ^ String.sub s (i+1) 2))
|
|
|
- with _ ->
|
|
|
- raise (Lexer.Error (Lexer.Invalid_character c,p))
|
|
|
- ) in
|
|
|
- Buffer.add_char b c;
|
|
|
- inext := !inext + 2;
|
|
|
- | _ -> raise (Lexer.Error (Lexer.Invalid_character c,p)));
|
|
|
- loop false !inext;
|
|
|
- end else
|
|
|
- match c with
|
|
|
- | '\\' -> loop true (i + 1)
|
|
|
- | c ->
|
|
|
- Buffer.add_char b c;
|
|
|
- loop false (i + 1)
|
|
|
- in
|
|
|
- loop false 0;
|
|
|
- Buffer.contents b
|
|
|
-
|
|
|
let rec gen_constant ctx c p =
|
|
|
match c with
|
|
|
| TInt s -> (try push ctx [VInt32 (Int32.of_string s)] with _ -> gen_constant ctx (TFloat s) p)
|
|
|
| TFloat s -> push ctx [VFloat (try float_of_string s with _ -> error p)]
|
|
|
- | TString s -> push ctx [VStr (unescape_chars s p)]
|
|
|
+ | TString s -> push ctx [VStr s]
|
|
|
| TBool b -> write ctx (APush [PBool b])
|
|
|
| TNull -> push ctx [VNull]
|
|
|
| TThis
|