{"id":3102,"date":"2018-12-16T19:43:30","date_gmt":"2018-12-16T10:43:30","guid":{"rendered":"http:\/\/oohito.com\/nqthm\/?p=3102"},"modified":"2018-12-16T19:43:30","modified_gmt":"2018-12-16T10:43:30","slug":"pharo%e3%81%8b%e3%82%89c%e3%81%a7%e6%9b%b8%e3%81%84%e3%81%9f%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0%e3%82%92%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%99%ef%bc%88%e3%81%9d%e3%81%ae2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/oohito.com\/nqthm\/archives\/3102","title":{"rendered":"Pharo\u304b\u3089C\u3067\u66f8\u3044\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u547c\u3073\u51fa\u3059\uff08\u305d\u306e2\uff09"},"content":{"rendered":"\n<p>\u3053\u308c\u306f<a href=\"https:\/\/qiita.com\/advent-calendar\/2018\/smalltalk\">Smalltalk Advent Calendar 2018<\/a>\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\n\n\n<p>\u524d\u56de\u306e\u8a18\u4e8b\u3067Pharo\u304b\u3089C\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u4eca\u56de\u3082\u305d\u306e\u7d9a\u304d\u3067\u3001UFFI\u3068\u3044\u3046\u30e1\u30ab\u30cb\u30ba\u30e0\u3092\u4f7f\u3063\u305f\u5916\u90e8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<br \/><\/p>\n\n\n<p>\u3055\u3066\u3001\u6570\u5024\u306e\u3088\u3046\u306a\u5358\u7d14\u306a\u30c7\u30fc\u30bf\u3092\u6e21\u3059\u306e\u306f\u7c21\u5358\u3067\u3059\u304c\u3001\u914d\u5217\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u6e21\u3059\u306b\u306f\u5c11\u3057\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u4f8b\u3048\u3070\u6b21\u306e\u3088\u3046\u306aC\u95a2\u6570\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">double fsum(double *list, int n)<br \/>{<br \/>  double result = 0;<br \/>  for (int i = 0; i &lt; n; i ++) {<br \/>    result += list[i];<br \/>  }<br \/>  return result;<br \/>}<\/pre>\n\n\n<p>double\u578b\u306e\u8981\u7d20\u3092n\u500b\u6301\u3064\u914d\u5217\u3092\u5f15\u6570\u3067\u5f97\u3066\u3001\u305d\u306e\u548c\u3092\u6c42\u3081\u308b\u3088\u3046\u306a\u5834\u5408\u3001Pharo \u5074\u3067\u306f\u5c11\u3057\u5de5\u592b\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n<p>\u307e\u305a\u3001C\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">fsum: anArray size: anInteger<br \/>    ^ self ffiCall: #(double fsum #(FFIExternalArray anArray , int anInteger)) module: UFFITestLibrary<\/pre>\n\n\n<p>\u914d\u5217\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3059\u308b\u90e8\u5206\u4ee5\u5916\u306f\u524d\u56de\u306e\u8a18\u4e8b\u3068\u5909\u308f\u308a\u3042\u308a\u307e\u305b\u3093\u3002double\u578b\u306e\u8981\u7d20\u3092\u6301\u3064\u914d\u5217\u3092\u53d7\u3051\u6e21\u3059\u5834\u5408\u306b\u306f\u3001FFIExternalArray \u3068\u3044\u3046\u578b\u3092\u660e\u793a\u7684\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u4f7f\u308f\u308c\u308b\u6642\u306b\u306f\u3001anArray \u306b FFIExternalArray \u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u6307\u5b9a\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/><\/p>\n\n\n<pre class=\"wp-block-preformatted\">fsum: anArray<br \/>    | size arr |<br \/>    size := anArray size.<br \/>    ^ [ arr := FFIExternalArray externalNewType: 'double' size: size.<br \/>        1 to: size do: [ :i | arr at: i put: (anArray at: i) ].<br \/>        self fsum: arr size: size ]<br \/>      ensure: [ arr free ]<\/pre>\n\n\n<p>#externalNewType:size: \u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f7f\u3063\u3066 FFIExternalArray \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u53d7\u3051\u6e21\u3057\u305f\u3044\u8981\u7d20\u3092\u4e00\u3064\u305a\u3064\u8a2d\u5b9a\u3057\u3066\u304b\u3089\u3001\u5148\u7a0b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002\u4f7f\u3044\u7d42\u308f\u3063\u305f\u3068\u3053\u308d\u3067\u3001\u4f5c\u6210\u3057\u305f FFIExternalArray \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u958b\u653e\u3057\u307e\u3059\u3002<br \/><\/p>\n\n\n<p>C\u306e\u95a2\u6570\u306e\u4e2d\u3067\u914d\u5217\u306e\u8981\u7d20\u306b\u5909\u66f4\u3092\u52a0\u3048\u308b\u3088\u3046\u306a\u5834\u5408\u3082\u4f3c\u305f\u3088\u3046\u306a\u5f62\u3068\u306a\u308a\u307e\u3059\u3002\u914d\u5217\u306e\u5404\u8981\u7d20\u3092\u5b9a\u6570\u500d\u3059\u308b\u95a2\u6570\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">void fmultiplyBy(double *list, int n, double x)<br \/>{<br \/>  for (int i = 0; i &lt; n; i ++) {<br \/>    list[i] *= x;<br \/>  }<br \/>}<\/pre>\n\n\n<p>\u3053\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059 Pharo \u306e\u30e1\u30bd\u30c3\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">fmultiply: anArray size: anInteger by: x<br \/>    ^ self ffiCall: #(double fmultiplyBy #(FFIExternalArray anArray , int anInteger , double x)) module: UFFITestLibrary<br \/><\/pre>\n\n\n<p>\u4e0a\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u305f\u3081\u306b FFIExternalArray \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u3063\u3066\u6e21\u3059\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u610f\u3057\u307e\u3059\u3002<br \/><\/p>\n\n\n<pre class=\"wp-block-preformatted\">fmultiply: anArray by: x<br \/>    | size arr |<br \/>    size := anArray size.<br \/>    [ arr := FFIExternalArray externalNewType: 'double' size: size.<br \/>      1 to: size do: [ :i | arr at: i put: (anArray at: i) ].<br \/>      self fmultiply: arr size: size by: x.<br \/>      1 to: size do: [ :i | anArray at: i put: (arr at: i) ] ]<br \/>    ensure: [ arr free ]<\/pre>\n\n\n<p>\u8981\u3059\u308b\u306b FFIExternalArray \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u8981\u7d20\u3092\u4e00\u3064\u305a\u3064\u53d6\u308a\u51fa\u3057\u3066\u5143\u306e\u914d\u5217\u3092\u5909\u66f4\u3059\u308b\u308f\u3051\u3067\u3059\u3002<br \/><\/p>\n\n\n<p>\u4ee5\u4e0a\u304c\u914d\u5217\u306a\u3069\u306e\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u6e21\u3059\u5834\u5408\u306e\u65b9\u6cd5\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<p>\u6b8b\u5ff5\u306a\u304c\u3089\u5927\u304d\u306a\u914d\u5217\u306e\u3084\u308a\u53d6\u308a\u306e\u5834\u5408\u3060\u3068\u3001\u8981\u7d20\u306e\u51fa\u3057\u5165\u308c\u306b\u4f59\u8a08\u306a\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b\u3076\u3093\u52b9\u7387\u306f\u826f\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u7279\u306b\u4eca\u56de\u306e\u3088\u3046\u306a\u4f8b\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306e\u65b9\u304c\u305a\u3063\u3068\u65e9\u3044\u3067\u3059\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">a := #(1 2 3 4) asFloatArray.<br \/>a *= 2.<br \/>a.<\/pre>\n\n\n<p>\u3053\u3061\u3089\u306f FloatArrayPlugin \u3068\u3044\u3046 VM \u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u7528\u3044\u3066\u304a\u308a\u3001C\u8a00\u8a9e\u306e\u95a2\u6570\u5074\u3067\u914d\u5217\u306e\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u308c\u306fSmalltalk Advent Calendar 2018\u306e\u8a18\u4e8b\u3067\u3059\u3002 \u524d\u56de\u306e\u8a18\u4e8b\u3067Pharo\u304b\u3089C\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u4eca\u56de\u3082\u305d\u306e\u7d9a\u304d\u3067\u3001UFFI\u3068\u3044\u3046\u30e1\u30ab\u30cb\u30ba\u30e0\u3092\u4f7f\u3063\u305f\u5916\u90e8\u30a4\u30f3\u30bf\u30fc\u30d5&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,19],"tags":[],"class_list":["post-3102","post","type-post","status-publish","format-standard","hentry","category-pharo","category-tutorials"],"_links":{"self":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/comments?post=3102"}],"version-history":[{"count":0,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3102\/revisions"}],"wp:attachment":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/media?parent=3102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/categories?post=3102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/tags?post=3102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}