next up previous contents
Next: ���h�L�������g����� ... Up: �v���O�������Cmm version4.0 Previous: 15.7 �R�����g

  
16. ����sCmm�R�[�h

Cmm����n�������s����Cmm�R�[�h��A��L���������B������ ���`���N���X�A����������s����B

���ACmm���Object�N���X���`����B���N���X���A�X�[�p�[ �N���X��������B���N���X��f�t�H���g��A���Object�N���X ��X�[�p�[�N���X�����B

������A���Object�N���X������n���`�����A���X�[�p�[ �N���X�����������A�������������������B


class Object {

method IsInstanceOf ;
method IsArray () void ;
method IsInteger () void ;
method IsReal () void ;
method IsNumber () void ;
method IsString () void ;
method IsVoid () void ;
method IsInstance() void ;
method IsClass () void ;
}

���A���\�b�h�AIsInstanceOf��A�g�������\�b�h����ACmm����n��� ���R�[�h��������B

����O���`���L������B


var __loadedModules = [] ;


// Class �N���X - �C���X�^���X������N���X����[�g
class Class : Object {
method IsClass () is_class(this) ;
method IsInstance () is_instance(this) ;
}

// ��O�N���X
class Exception : Class {
public message ;
method New (mes) {
if ($# == 1)
message = "Exception" ;
else
message = mes ;
}
}

// SystemException �N���X - ����n�������O����N���X
class SystemException : Exception {
public pos ;
method New (mes) : (mes) ;
}

// �z��A�N�Z�X�G���[�����������
class ArrayOutOfBoundsException : SystemException {
method New (mes) : (mes) ;
}

// 0���Z���������
class DivisionByZeroException : SystemException {
method New (mes) : (mes) ;
}

// �f�[�^�^����������������
class TypeMismatchException : SystemException {
method New (mes) : (mes) ;
}

// ����������������������
class ArgNumberException : SystemException {
method New (mes) : (mes) ;
}

// �o�C�i���p�b�P�[�W����[�h���s������������
class PackageLoadException : SystemException {
method New (mes) : (mes) ;
}

// �t�@�C������[�h���s������������
class FileLoadException : SystemException {
method New (mes) : (mes) ;
}

// �J�v�Z���N���X���`
// Void �N���X
class Void : Object {
method IsVoid () 1 ;
}

// String �N���X - ������J�v�Z���N���X
class String : Object {
method Length () length(this);
method Concat (s) { this + s ; };
method Format (wid, align) {
var len = ->Length() ;
if (len >= wid || $# == 2)
return this ;
var s = this ;
var i ;
var rest = wid - len ;
if (align == `left) {
return s + " " * rest ;
}else if (align == `right) {
return " " * rest + s ;
}else if (align == `center) {
var lrest = rest/2 ;
var rrest = rest - lrest ;
return " " * lrest + s + " " * rrest ;
}
return s ;
} ;
method SubStr (from, len)
{
var s ;
if ($# == 2)
var len = this->Length () - from ;
s = substr (this, from, len) ;
if (!s)
return "" ;
s ;
}
method ToInteger () to_int (this) ;
method ToReal () to_real (this) ;
method IsString () 1 ;
}

// Array�N���X - �z��
class Array : Object {
method Length () length(this) ;
method Index (n) this[n] ;
//�z������\�b�h
method Create (n1, n2) {
if ($# == 1) {
mkarray(0) ;
} else if ($# == 2) {
if (n1 < 0) return mkarray(0) ;
return mkarray(n1) ;
} else {
if (n1 < 0) n1 = 0 ;
if (n2 < n1) n2 = n1 ;
return mkarray(n1, n2) ;
}
}
method IsArray () 1 ;
}

// Integer�N���X
class Integer : Object {
method IsInteger () 1 ;
method IsNumber () 1 ;
method Format (width, align, base)
{
if ($# == 2) {{
var align = `right ;
var base = 10 ;
}} else if ($# == 3) {{
var base = 10 ;
}} else if (base->IsString()) {
base = if (base == `binary) 2
else if (base == `octal) 8
else if (base == `decimal) 10
else if (base == `hexadecimal) 16
else 10 ;
}
if (base == 10) {
ToString()->Format (width, align) ;
} else if (base == 16) {
var xnum = "0123456789ABCDEF" ;
var n = this ;
var s = "" ;
for ( ; n > 0; n /= base)
s = xnum->SubStr (n % base, 1) + s ;
s->Format (width, align) ;
} else if (1 < base < 10) {
var s = "" ;
var n = this ;
for ( ; n > 0 ; n /= base) {
s = (n % base)->ToString() + s ;
}
s->Format (width, align) ;
}
}
method ToString () to_string (this) ;
method ToReal () to_real (this) ;
}

// Real�N���X - タ��
class Real : Object {
method IsReal () 1 ;
method IsNumber () 1 ;
method Format (width, prec, align)
{
var intpart, realpart ;
if ($# == 3)
var align = `right ;
intpart = ->ToInteger() ;
if (prec == 0)
return intpart->ToString()->Format (width, align) ;
realpart = ((this - intpart)->ToString() + "0" * width)->SubStr(0, prec + 2) ;
realpart = realpart->SubStr (2) ;
(intpart->ToString() + "." + realpart)->Format (width, align) ;
}
method ToString () to_string(this);
method ToInteger() to_int(this);
}

// ��`����O�C���X�^���X
var arrayOutOfBoundsException
= ArrayOutOfBoundsException->New ("Array index out of bounds") ;
var divisionByZeroException
= DivisionByZeroException->New ("Division by 0") ;
var typeMismatchException
= TypeMismatchException->New ("Type mismatch") ;
var argNumberException
= ArgNumberException->New('Invalit Number of Arguments');
var fileLoadException
= FileLoadException->New ('cannot load file') ;
var packageLoadException
= PackageLoadException->New ('cannot load package') ;


next up previous contents
Next: ���h�L�������g����� ... Up: �v���O�������Cmm version4.0 Previous: 15.7 �R�����g
Tetsuo Ono
1998-11-05