diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index eb7b9b274..06ac804d0 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -9008,6 +9008,8 @@ namespace PascalABCCompiler.NETGenerator case basic_function_type.booltoui: il.Emit(OpCodes.Conv_U4); break; case basic_function_type.booltol: il.Emit(OpCodes.Conv_I8); break; case basic_function_type.booltoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.ltop: il.Emit(OpCodes.Conv_I); break; + case basic_function_type.ptol: il.Emit(OpCodes.Conv_I8); break; case basic_function_type.objtoobj: { diff --git a/SemanticTree/SemanticTree.cs b/SemanticTree/SemanticTree.cs index ae9819024..674bb4dc5 100644 --- a/SemanticTree/SemanticTree.cs +++ b/SemanticTree/SemanticTree.cs @@ -63,7 +63,8 @@ namespace PascalABCCompiler.SemanticTree objassign,objeq,objnoteq, //присваивание и эквивалентность объектов по ссылке. //write,writei,writed,writec,writeb,read,readi,readd,readc,readb,expd,absd,absi //temporary functions (Нужны только на начальном этапе отладки. Потом обязательно удалить.) objtoobj, boolinc, booldec, boolsinc, boolsdec, booltoi, enumgr, enumgreq, enumsm, enumsmeq, - booltob, booltosb, booltos, booltous, booltoui, booltol, booltoul + booltob, booltosb, booltos, booltous, booltoui, booltol, booltoul, + ltop, ptol }; public enum runtime_statement_type { invoke_delegate, ctor_delegate, begin_invoke_delegate, end_invoke_delegate }; diff --git a/TestSuite/pointers10.pas b/TestSuite/pointers10.pas new file mode 100644 index 000000000..e1c243595 --- /dev/null +++ b/TestSuite/pointers10.pas @@ -0,0 +1,15 @@ +begin + var i: int64 := $FF22FF3322; + var p := pointer(i); + i := int64(p); + if System.Environment.Is64BitProcess then + begin + assert(i = $FF22FF3322); + assert(PointerToString(p) = '$FF22FF3322'); + end; + i := $FF22FF; + p := pointer(i); + i := int64(p); + assert(i = $FF22FF); + assert(PointerToString(p) = '$FF22FF'); +end. \ No newline at end of file diff --git a/TreeConverter/SystemLib/StaticSystemLib.cs b/TreeConverter/SystemLib/StaticSystemLib.cs index 0d139d1ce..75b4aba4b 100644 --- a/TreeConverter/SystemLib/StaticSystemLib.cs +++ b/TreeConverter/SystemLib/StaticSystemLib.cs @@ -493,6 +493,9 @@ namespace PascalABCCompiler.SystemLibrary private static basic_function_node _obj_to_obj; + private static basic_function_node _int64_to_pointer; + private static basic_function_node _pointer_to_int64; + private static compiled_function_node _resize_func; private static System.StringComparer _string_comparer = StringComparer.Ordinal; @@ -2057,6 +2060,8 @@ namespace PascalABCCompiler.SystemLibrary _exception_base_type = compiled_type_node.get_type_node(typeof(System.Exception), symtab); _exception_base_type.SetName(compiler_string_consts.base_exception_class_name); + _int64_to_pointer = make_type_conversion(_int64_type, _pointer_type, type_compare.greater_type, SemanticTree.basic_function_type.ltop, false); + _pointer_to_int64 = make_type_conversion(_pointer_type, _int64_type, type_compare.less_type, SemanticTree.basic_function_type.ptol, false); } private static List wait_add_ref_list = new List(); @@ -5156,6 +5161,22 @@ namespace PascalABCCompiler.SystemLibrary } } + public static basic_function_node int64_to_pointer + { + get + { + return _int64_to_pointer; + } + } + + public static basic_function_node pointer_to_int64 + { + get + { + return _pointer_to_int64; + } + } + public static compiled_type_node icloneable_interface { get diff --git a/TreeConverter/TreeRealization/types.cs b/TreeConverter/TreeRealization/types.cs index 31fad12cd..c860367b1 100644 --- a/TreeConverter/TreeRealization/types.cs +++ b/TreeConverter/TreeRealization/types.cs @@ -3714,13 +3714,29 @@ namespace PascalABCCompiler.TreeRealization if (_explicit_convertions_from.TryGetValue(ctn, out fn)) return fn; if (SemanticRules.PoinerRealization == PoinerRealization.VoidStar) + { if ((this == SystemLibrary.SystemLibrary.integer_type && ctn == SystemLibrary.SystemLibrary.pointer_type) || - (this == SystemLibrary.SystemLibrary.pointer_type && ctn == SystemLibrary.SystemLibrary.integer_type)) + (this == SystemLibrary.SystemLibrary.pointer_type && ctn == SystemLibrary.SystemLibrary.integer_type) + ) { fn = TreeConverter.convertion_data_and_alghoritms.get_empty_conversion(ctn, this, false); _explicit_convertions_from.Add(ctn, fn); return fn; } + /*else if ((this == SystemLibrary.SystemLibrary.pointer_type && ctn == SystemLibrary.SystemLibrary.int64_type)) + { + fn = SystemLibrary.SystemLibrary.int64_to_pointer; + _explicit_convertions_from.Add(ctn, fn); + return fn; + } + else if ((this == SystemLibrary.SystemLibrary.int64_type && ctn == SystemLibrary.SystemLibrary.pointer_type)) + { + fn = SystemLibrary.SystemLibrary.pointer_to_int64; + _explicit_convertions_from.Add(ctn, fn); + return fn; + }*/ + } + //enum->int32, int32->enum //TODO переделать это. Наверно это делается както нетак. Enum Conversion diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 8b584ae3f..d5048cfca 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -6877,7 +6877,10 @@ begin //result:= Convert.ToString(integer(p), 16); if p = nil then result := 'nil' - else result := '$' + integer(p).ToString('X'); + else if Environment.Is64BitProcess then + result := '$' + int64(p).ToString('X') + else + result := '$' + integer(p).ToString('X') end; procedure Exec(filename: string);