예제 #1
0
파일: core.c 프로젝트: whatot/ma_c
local var return_true(var self)
{
	return type_class_method(self, ReturnTrue, return_true, self);
}

local var IntParent_ReturnTrue(var self)
{
	return True;
}

instance(IntParent, ReturnTrue) = {
IntParent_ReturnTrue};

var IntParent = type_data {
	type_begin(IntParent),
	type_entry(IntParent, ReturnTrue),
	type_end(IntParent),
};

PT_FUNC(test_type)
{
	PT_ASSERT(type_of($(Int, 1)) is Int);
	PT_ASSERT(type_of($(Real, 1.0)) is Real);
	PT_ASSERT(type_of(True) is Bool);
	PT_ASSERT(type_of(False) is Bool);
	PT_ASSERT(type_of(Int) is Type);
	PT_ASSERT(type_of(Real) is Type);
	PT_ASSERT(type_of(Type) is Type);
}
예제 #2
0
파일: xq.cpp 프로젝트: DoBuiThao/hoxchess
 bool XQ::set_fen(string const &fen)
 {
     clear();
     uint idx = 0UL, len = (uint)fen.size();
     uint y = 9UL, x = 0UL;
     while (idx < len)
     {
         sint32 c = fen[idx++];
         uint32 type = char_type(c);
         if (type != InvaildPiece)
         {
             if (y >= 10UL || x >= 9UL)
             {
                 //error
                 clear();
                 return false;
             }
             uint32 begin = type_begin(type);
             uint32 end = type_end(type);
             while (end >= begin)
             {
                 if (piece(begin) == InvaildCoordinate)
                 {
                     break;
                 }
                 ++begin;
             }
             if (begin > end)
             {
                 //error
                 clear();
                 return false;
             }
             uint32 sq = xy_coordinate(x++, y);
             m_coordinates[sq] = static_cast<uint8>(begin);
             m_pieces[begin] = static_cast<uint8>(sq);
         }
         else if (c == ' ')
         {
             if (y || x != 9UL || (idx == len))
             {
                 //error
                 clear();
                 return false;
             }
             c = fen[idx];
             m_player = ((c == 'b') ? Black : Red);
             for (int i = 0; i < 32; i++)
             {
                 uint32 sq = piece(i);
                 if (sq != InvaildCoordinate)
                 {
                     if (!(coordinate_flag(sq) & piece_flag(i)))
                     {
                         //error
                         clear();
                         return false;
                     }
                     m_bitmap.setbit(sq);
                 }
             }
             //ok
             return true;
         }
         else if (c == '/')
         {
             if (!y || x != 9UL)
             {
                 //error
                 clear();
                 return false;
             }
             --y;
             x = 0UL;
         }
         else if (c >= '1' && c <= '9')
         {
             x += c - '0';
         }
         else
         {
             //error
             clear();
             return false;
         }
     }
     //error
     clear();
     return false;
 }
예제 #3
0
파일: File.c 프로젝트: 0x73/libCello
#include "Cello/File.h"

#include "Cello/Exception.h"
#include "Cello/Number.h"
#include "Cello/String.h"

var File = type_data {
  type_begin(File),
  type_entry(File, New),
  type_entry(File, With),
  type_entry(File, Stream),
  type_entry(File, Dict),
  type_entry(File, Format),
  type_end(File),
};

var File_New(var self, var_list vl) {
  FileData* fd = cast(self, File);
  const char* filename = as_str(var_list_get(vl));
  const char* access = as_str(var_list_get(vl));
  stream_open(self, filename, access);
  return self;
}

var File_Delete(var self) {
  FileData* fd = cast(self, File);
  if (fd->f != NULL) { stream_close(self); }
  return self;
}

size_t File_Size(void) {
예제 #4
0
파일: Map.c 프로젝트: 0x73/libCello
struct MapNode {
  var leaf_key;
  var leaf_val;
  struct MapNode* left;
  struct MapNode* right;
};

data {
  var type;
  var keys;
  struct MapNode* root;
} MapData;

var Map = type_data {
  type_begin(Map),
  type_entry(Map, New),
  type_entry(Map, Assign),
  type_entry(Map, Copy),
  type_entry(Map, Eq),
  type_entry(Map, Collection),
  type_entry(Map, Dict),
  type_entry(Map, Iter),
  type_entry(Map, Show),
  type_end(Map),
};

var Map_New(var self, var_list vl) {
  MapData* md = cast(self, Map);
  md->keys = new(List);
  md->root = NULL;
예제 #5
0
파일: Vec2.c 프로젝트: rcmaniac25/libCello
#include "Vec2.h"

#include <math.h>

float dot(var self, var obj) {
    return type_class_method(type_of(self), Vector, dot, self, obj);
}

float length(var self) {
    return type_class_method(type_of(self), Vector, length, self);
}

var Vec2 = type_data {
    type_begin(Vec2),
    type_entry(Vec2, New),
    type_entry(Vec2, Assign),
    type_entry(Vec2, Copy),
    type_entry(Vec2, Eq),
    type_entry(Vec2, Show),
    type_entry(Vec2, Vector),
    type_end(Vec2)
};

var Vec2_New(var self, var_list vl) {
    Vec2Data* v = cast(self, Vec2);
    v->x = as_double(var_list_get(vl));
    v->y = as_double(var_list_get(vl));
    return self;
}

var Vec2_Delete(var self) {
예제 #6
0
#include "Cello/None.h"
#include "Cello/Exception.h"

#include <stdlib.h>
#include <string.h>

data {
  var type;
  int size;
  var keys;
  var* key_buckets;
  var* val_buckets;
} DictionaryData;

var Dictionary = type_data {
  type_begin(Dictionary),
  type_entry(Dictionary, New),
  type_entry(Dictionary, Assign),
  type_entry(Dictionary, Copy),
  type_entry(Dictionary, Eq),
  type_entry(Dictionary, Collection),
  type_entry(Dictionary, Dict),
  type_entry(Dictionary, Iter),
  type_entry(Dictionary, Show),
  type_end(Dictionary)
};

var Dictionary_New(var self, var_list vl) {
  DictionaryData* dict = cast(self, Dictionary);
  dict->size = 1024;
  dict->keys = new(List);
예제 #7
0
파일: Table.c 프로젝트: kazupon/libCello
#include <stdlib.h>
#include <string.h>

data {
    var type;
    var key_type;
    var val_type;
    int size;
    var keys;
    var* key_buckets;
    var* val_buckets;
} TableData;

var Table = type_data {
    type_begin(Table),
    type_entry(Table, New),
    type_entry(Table, Assign),
    type_entry(Table, Copy),
    type_entry(Table, Eq),
    type_entry(Table, Collection),
    type_entry(Table, Dict),
    type_entry(Table, Iter),
    type_entry(Table, Show),
    type_end(Table)
};

var Table_New(var self, var_list vl) {
    TableData* tab = cast(self, Table);

    tab->key_type = cast(var_list_get(vl), Type);
예제 #8
0
파일: Reference.c 프로젝트: whatot/ma_c
#include "Cello/Reference.h"

#include "Cello/Bool.h"
#include "Cello/Type.h"
#include "Cello/Exception.h"

#include <string.h>

var Reference = type_data {
	type_begin(Reference),
	type_entry(Reference, New),
	type_entry(Reference, Assign),
	type_entry(Reference, Copy),
	type_entry(Reference, Eq),
	type_entry(Reference, Hash),
	type_entry(Reference, At),
	type_entry(Reference, With),
	type_entry(Reference, Show),
	type_end(Reference)
};

var Reference_New(var self, var_list vl)
{
	ReferenceData *rd = cast(self, Reference);
	rd->ref = var_list_get(vl);
	return rd;
}

var Reference_Delete(var self)
{
	return self;