SqueakByExample:3.7

From 흡혈양파의 번역工房
Revision as of 08:06, 13 August 2012 by Onionmixer (talk | contribs) (SBE 프리미티브와프라그마 페이지 추가)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

프리미티브와 프라그마(Primitives and pragmas)

스몰토크에서는 모든 것이 오브젝트이며, 모든 것은 메시지를 보내어 작동합니다. 그럼에도 불구하고, 우리는 특정 지점에서, 한계를 보게 됩니다. 특정 오브젝트는 오직 가상 머신 프리미티브(virtual machine primitive)를 불러옴으로서 활용할 수 있습니다.

예를 들면, 다음 오브젝트들은 모두 프리미티브로서 실행됩니다: 메모리 할당(new,new:), 비트 조작 (bitAnd:,bitOr:.bitShift:) 포인터와 정수 연산 (+, --, <, >, *, / , =, ==...) 그리고 배열 접근 (at:, at:put:)

프리미티브는 구문 <primitive: aNumber>와 함께 불러집니다. 이러한 프리미티브를 불러오는 메소드는 오직 그 프리미티브가 오류가 나는 경우에 평가될 스몰토크코드 또한 포함할 수 있습니다.

여기에 우리는 SmallInteger»+를 위한 코드를 볼 수 있습니다. 만약 프리미티브가 오류가 나면 표현식 super+aNumber가 평가되고 리턴됩니다.


메소드 3.2: 프리미티브 메소드

+ aNumber
"Primitive. Add the receiver to the argument and answer with the result
if it is a SmallInteger. Fail if the argument or the result is not a
SmallInteger Essential No Lookup. See Object documentation whatIsAPrimitive."

<primitive: 1>
 super + aNumber

. 스퀵 3.9 이후로, 꺽쇠괄호구문(the angle bracket syntax)은 프라그마(pragmas)라고 불리는 메소드 어노테이션(method annotation)에 사용되었습니다.

Notes