7d46d4b5cb
Prototype for `dart:ffi` on Linux/MacOS x64 in JIT mode. `dart:ffi` is experimental and its API is likely to change in the future. Progress and design decisions are tracked in https://github.com/dart-lang/sdk/projects/13 issue: https://github.com/dart-lang/sdk/issues/34452 Change-Id: Ifa4566388e42c8757f154741d11e303465ef305d Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try, vm-kernel-precomp-win-release-x64-try, vm-kernel-mac-debug-x64-try, vm-kernel-asan-linux-release-x64 Reviewed-on: https://dart-review.googlesource.com/c/80124 Reviewed-by: Samir Jindel <sjindel@google.com> Auto-Submit: Daco Harkes <dacoharkes@google.com>
64 lines
1.5 KiB
Dart
64 lines
1.5 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:ffi' as ffi;
|
|
|
|
import 'coordinate.dart';
|
|
|
|
main(List<String> arguments) {
|
|
print('start main');
|
|
|
|
{
|
|
// allocates each coordinate separately in c memory
|
|
Coordinate c1 = Coordinate(10.0, 10.0, null);
|
|
Coordinate c2 = Coordinate(20.0, 20.0, c1);
|
|
Coordinate c3 = Coordinate(30.0, 30.0, c2);
|
|
c1.next = c3;
|
|
|
|
Coordinate currentCoordinate = c1;
|
|
for (var i in [0, 1, 2, 3, 4]) {
|
|
currentCoordinate = currentCoordinate.next;
|
|
print("${currentCoordinate.x}; ${currentCoordinate.y}");
|
|
}
|
|
|
|
c1.free();
|
|
c2.free();
|
|
c3.free();
|
|
}
|
|
|
|
{
|
|
// allocates coordinates consecutively in c memory
|
|
Coordinate c1 = Coordinate.allocate(count: 3);
|
|
Coordinate c2 = c1.elementAt(1);
|
|
Coordinate c3 = c1.elementAt(2);
|
|
c1.x = 10.0;
|
|
c1.y = 10.0;
|
|
c1.next = c3;
|
|
c2.x = 20.0;
|
|
c2.y = 20.0;
|
|
c2.next = c1;
|
|
c3.x = 30.0;
|
|
c3.y = 30.0;
|
|
c3.next = c2;
|
|
|
|
Coordinate currentCoordinate = c1;
|
|
for (var i in [0, 1, 2, 3, 4]) {
|
|
currentCoordinate = currentCoordinate.next;
|
|
print("${currentCoordinate.x}; ${currentCoordinate.y}");
|
|
}
|
|
|
|
c1.free();
|
|
}
|
|
|
|
{
|
|
Coordinate c = Coordinate(10, 10, null);
|
|
print(c is Coordinate);
|
|
print(c is ffi.Pointer<ffi.Void>);
|
|
print(c is ffi.Pointer);
|
|
c.free();
|
|
}
|
|
|
|
print("end main");
|
|
}
|