synthemesc-codex 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/Makefile.server +47 -0
- data/README.markdown +3 -0
- data/Rakefile +71 -0
- data/VERSION +1 -0
- data/build.h +11 -0
- data/codex.c +470 -0
- data/codex.gemspec +49 -0
- data/codex.h +58 -0
- data/codex_rb_ext.c +208 -0
- data/extconf.rb +2 -0
- data/format.h +126 -0
- data/lib/codex.rb +39 -0
- data/ptrn2mask +23 -0
- data/tpl.c +2449 -0
- data/tpl.h +119 -0
- data/vm.c +57 -0
- data/vm.h +35 -0
- metadata +71 -0
data/codex.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{codex}
|
5
|
+
s.version = "0.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Joshua Eckstein"]
|
9
|
+
s.date = %q{2009-08-09}
|
10
|
+
s.email = %q{josh@eksdyne.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"README.markdown"
|
13
|
+
]
|
14
|
+
s.files = [
|
15
|
+
".gitignore",
|
16
|
+
"Makefile.server",
|
17
|
+
"README.markdown",
|
18
|
+
"Rakefile",
|
19
|
+
"VERSION",
|
20
|
+
"build.h",
|
21
|
+
"codex.c",
|
22
|
+
"codex.gemspec",
|
23
|
+
"codex.h",
|
24
|
+
"codex_rb_ext.c",
|
25
|
+
"extconf.rb",
|
26
|
+
"format.h",
|
27
|
+
"lib/codex.rb",
|
28
|
+
"ptrn2mask",
|
29
|
+
"tpl.c",
|
30
|
+
"tpl.h",
|
31
|
+
"vm.c",
|
32
|
+
"vm.h"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/synthemesc/codex}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.4}
|
38
|
+
s.summary = %q{Codex network machine}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
data/codex.h
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2
|
+
|
3
|
+
#ifndef _CODEX_H
|
4
|
+
#define _CODEX_H
|
5
|
+
|
6
|
+
#include "vm.h"
|
7
|
+
|
8
|
+
/*
|
9
|
+
* On some Linux systems, this is missing and causes libevent to fail.
|
10
|
+
* There shouldn't be a problem with redefining it, as long as the
|
11
|
+
* definition is consistent.
|
12
|
+
*/
|
13
|
+
typedef unsigned char u_char;
|
14
|
+
|
15
|
+
/*
|
16
|
+
* GCC will complain if you use uint64_t for the %llu convention in printf,
|
17
|
+
* even though they're exactly the same.
|
18
|
+
*/
|
19
|
+
#define LLU (unsigned long long)
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Default values and enumerations for codex server.
|
23
|
+
*/
|
24
|
+
#define PORT 32700
|
25
|
+
#define VERBOSE 1
|
26
|
+
#define SILENT 0
|
27
|
+
#define DAEMONIZE 1
|
28
|
+
#define FOREGROUND 0
|
29
|
+
#define DEFAULT_SIZE 0x00FFFFFF
|
30
|
+
#define DEFAULT_START 0x00000000
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Pipeline sizes.
|
34
|
+
*/
|
35
|
+
#define PIPELINE_DEPTH (128) /* In pages */
|
36
|
+
#define PIPELINE_SIZE (sizeof(struct instruction_word)*PIPELINE_DEPTH) /* In bytes */
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Default verbosity in development.
|
40
|
+
*/
|
41
|
+
#ifdef DEVELOPMENT
|
42
|
+
#define VERBOSITY VERBOSE
|
43
|
+
#else
|
44
|
+
#define VERBOSITY SILENT
|
45
|
+
#endif
|
46
|
+
|
47
|
+
/*
|
48
|
+
* GCC branch prediction.
|
49
|
+
*/
|
50
|
+
#ifndef LIKELY
|
51
|
+
#define LIKELY(cond) __builtin_expect((cond),1)
|
52
|
+
#endif
|
53
|
+
|
54
|
+
#ifndef UNLIKELY
|
55
|
+
#define UNLIKELY(cond) __builtin_expect((cond),0)
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#endif
|
data/codex_rb_ext.c
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
/* -*- Mode: C (Ruby); tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2
|
+
|
3
|
+
#include <ruby.h>
|
4
|
+
|
5
|
+
#include "build.h"
|
6
|
+
#include "tpl.h"
|
7
|
+
#include "codex.h"
|
8
|
+
#include "format.h"
|
9
|
+
#include "vm.h"
|
10
|
+
|
11
|
+
VALUE rb_mCodex;
|
12
|
+
VALUE rb_cCodexPage;
|
13
|
+
VALUE rb_cCodexFile;
|
14
|
+
|
15
|
+
ID id_serialized;
|
16
|
+
ID id_unserialized;
|
17
|
+
|
18
|
+
static void
|
19
|
+
tpl_rb_mark(tpl_node *tpl)
|
20
|
+
{
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
static void
|
25
|
+
tpl_rb_free(tpl_node *tpl)
|
26
|
+
{
|
27
|
+
tpl_free(tpl);
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
tpl_rb_alloc(VALUE self)
|
33
|
+
{
|
34
|
+
tpl_node *tpl = NULL;
|
35
|
+
return Data_Wrap_Struct(self, tpl_rb_mark, tpl_rb_free, tpl);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
t_page_init(self, ary)
|
40
|
+
VALUE self;
|
41
|
+
VALUE ary;
|
42
|
+
{
|
43
|
+
char* buffer;
|
44
|
+
int buffer_size;
|
45
|
+
struct instruction_word op;
|
46
|
+
int i=0;
|
47
|
+
|
48
|
+
Check_Type(ary, T_ARRAY);
|
49
|
+
if (RARRAY(ary)->len % 4 != 0)
|
50
|
+
{
|
51
|
+
rb_raise(rb_eArgError, "Array must be multiples of 4.");
|
52
|
+
return (Qnil);
|
53
|
+
}
|
54
|
+
|
55
|
+
op.reserved = 0;
|
56
|
+
DATA_PTR(self) = tpl_map(TPL_INSTRUCTION_FORMAT, &op);
|
57
|
+
|
58
|
+
while(i<RARRAY(ary)->len)
|
59
|
+
{
|
60
|
+
op.opcode = rb_num2ulong(RARRAY(ary)->ptr[i++]);
|
61
|
+
op.src = rb_num2ull(RARRAY(ary)->ptr[i++]);
|
62
|
+
op.arg = rb_num2ull(RARRAY(ary)->ptr[i++]);
|
63
|
+
op.dst = rb_num2ull(RARRAY(ary)->ptr[i++]);
|
64
|
+
tpl_pack(DATA_PTR(self), 1);
|
65
|
+
}
|
66
|
+
|
67
|
+
tpl_dump(DATA_PTR(self), TPL_MEM, &buffer, &buffer_size);
|
68
|
+
rb_ivar_set(self, id_serialized, rb_str_new(buffer, buffer_size));
|
69
|
+
free(buffer);
|
70
|
+
|
71
|
+
return(self);
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
t_page_serialized(VALUE self)
|
76
|
+
{
|
77
|
+
return(rb_ivar_get(self, id_serialized));
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
t_file_init(self, str)
|
82
|
+
VALUE self;
|
83
|
+
VALUE str;
|
84
|
+
{
|
85
|
+
/* Make sure we get a string */
|
86
|
+
Check_Type(str, T_STRING);
|
87
|
+
|
88
|
+
/* The register file */
|
89
|
+
uint64_t native_registers[REGISTER_COUNT];
|
90
|
+
VALUE bignum_registers = rb_ivar_set(self, id_unserialized, rb_ary_new());
|
91
|
+
|
92
|
+
DATA_PTR(self) = tpl_map(TPL_REGISTER_FORMAT, native_registers, REGISTER_COUNT);
|
93
|
+
if (tpl_load(DATA_PTR(self), TPL_MEM, RSTRING(str)->ptr, RSTRING(str)->len) == -1)
|
94
|
+
{
|
95
|
+
rb_raise(rb_eArgError, "String is not a valid serialized register file.");
|
96
|
+
return(Qnil);
|
97
|
+
}
|
98
|
+
|
99
|
+
tpl_unpack(DATA_PTR(self), 0); /* unpack all REGISTER_COUNT elements at once */
|
100
|
+
|
101
|
+
int i; for(i=0; i<REGISTER_COUNT; i++)
|
102
|
+
rb_ary_push(bignum_registers, rb_ull2inum(native_registers[i]));
|
103
|
+
|
104
|
+
return(self);
|
105
|
+
}
|
106
|
+
|
107
|
+
static VALUE
|
108
|
+
t_file_unserialized(VALUE self)
|
109
|
+
{
|
110
|
+
return(rb_ivar_get(self, id_unserialized));
|
111
|
+
}
|
112
|
+
|
113
|
+
void Init_codex_rb_ext()
|
114
|
+
{
|
115
|
+
rb_mCodex = rb_define_module("Codex");
|
116
|
+
|
117
|
+
rb_define_const(rb_mCodex, "VERSION_MAJOR", INT2FIX(VERSION_MAJOR));
|
118
|
+
rb_define_const(rb_mCodex, "VERSION_MINOR", INT2FIX(VERSION_MINOR));
|
119
|
+
rb_define_const(rb_mCodex, "VERSION_PATCH", INT2FIX(VERSION_PATCH));
|
120
|
+
rb_define_const(rb_mCodex, "BUILD", INT2FIX(CODEX_BUILD));
|
121
|
+
|
122
|
+
#define TO_STR(x) #x
|
123
|
+
#define CODEX_OP(op) rb_define_const(rb_mCodex,TO_STR(op),rb_uint2inum(OP_##op))
|
124
|
+
|
125
|
+
CODEX_OP(CLR);
|
126
|
+
CODEX_OP(MOV);
|
127
|
+
CODEX_OP(SORT);
|
128
|
+
CODEX_OP(AVG);
|
129
|
+
CODEX_OP(BE);
|
130
|
+
CODEX_OP(BNE);
|
131
|
+
CODEX_OP(BEZ);
|
132
|
+
CODEX_OP(BNEZ);
|
133
|
+
CODEX_OP(BLTEZ);
|
134
|
+
CODEX_OP(BGTEZ);
|
135
|
+
CODEX_OP(JMP);
|
136
|
+
CODEX_OP(SKP);
|
137
|
+
CODEX_OP(MIN);
|
138
|
+
CODEX_OP(MAX);
|
139
|
+
CODEX_OP(BLT);
|
140
|
+
CODEX_OP(BGT);
|
141
|
+
CODEX_OP(BLTZ);
|
142
|
+
CODEX_OP(BGTZ);
|
143
|
+
CODEX_OP(BLTE);
|
144
|
+
CODEX_OP(BGTE);
|
145
|
+
CODEX_OP(PUSH);
|
146
|
+
CODEX_OP(POP);
|
147
|
+
CODEX_OP(OR);
|
148
|
+
CODEX_OP(NOR);
|
149
|
+
CODEX_OP(ADD);
|
150
|
+
CODEX_OP(SUB);
|
151
|
+
CODEX_OP(INC);
|
152
|
+
CODEX_OP(DEC);
|
153
|
+
CODEX_OP(GRY);
|
154
|
+
CODEX_OP(HUE);
|
155
|
+
CODEX_OP(CALL);
|
156
|
+
CODEX_OP(RET);
|
157
|
+
CODEX_OP(AND);
|
158
|
+
CODEX_OP(NAND);
|
159
|
+
CODEX_OP(MUL);
|
160
|
+
CODEX_OP(DIV);
|
161
|
+
CODEX_OP(SHL);
|
162
|
+
CODEX_OP(SHR);
|
163
|
+
CODEX_OP(ROTL);
|
164
|
+
CODEX_OP(ROTR);
|
165
|
+
CODEX_OP(LOCK);
|
166
|
+
CODEX_OP(ULOCK);
|
167
|
+
CODEX_OP(XOR);
|
168
|
+
CODEX_OP(NOT);
|
169
|
+
CODEX_OP(POW);
|
170
|
+
CODEX_OP(ROOT);
|
171
|
+
CODEX_OP(SQR);
|
172
|
+
CODEX_OP(SQRT);
|
173
|
+
CODEX_OP(EXP);
|
174
|
+
CODEX_OP(LN);
|
175
|
+
CODEX_OP(TXN);
|
176
|
+
CODEX_OP(CMT);
|
177
|
+
CODEX_OP(RSV0);
|
178
|
+
CODEX_OP(RSV1);
|
179
|
+
CODEX_OP(SIN);
|
180
|
+
CODEX_OP(ASIN);
|
181
|
+
CODEX_OP(COS);
|
182
|
+
CODEX_OP(ACOS);
|
183
|
+
CODEX_OP(TAN);
|
184
|
+
CODEX_OP(ATAN);
|
185
|
+
CODEX_OP(RND);
|
186
|
+
CODEX_OP(SEND);
|
187
|
+
CODEX_OP(RSV2);
|
188
|
+
CODEX_OP(RSV3);
|
189
|
+
CODEX_OP(CSC);
|
190
|
+
CODEX_OP(ACSC);
|
191
|
+
CODEX_OP(SEC);
|
192
|
+
CODEX_OP(ASEC);
|
193
|
+
CODEX_OP(COT);
|
194
|
+
CODEX_OP(ACOT);
|
195
|
+
|
196
|
+
rb_cCodexPage = rb_define_class_under(rb_mCodex, "Page", rb_cObject);
|
197
|
+
rb_cCodexFile = rb_define_class_under(rb_mCodex, "File", rb_cObject);
|
198
|
+
|
199
|
+
rb_define_alloc_func(rb_cCodexPage, tpl_rb_alloc);
|
200
|
+
rb_define_method(rb_cCodexPage, "initialize", t_page_init, 1);
|
201
|
+
rb_define_method(rb_cCodexPage, "to_s", t_page_serialized, 0);
|
202
|
+
|
203
|
+
rb_define_alloc_func(rb_cCodexFile, tpl_rb_alloc);
|
204
|
+
rb_define_method(rb_cCodexFile, "initialize", t_file_init, 1);
|
205
|
+
rb_define_method(rb_cCodexFile, "to_a", t_file_unserialized, 0);
|
206
|
+
|
207
|
+
return;
|
208
|
+
}
|
data/extconf.rb
ADDED
data/format.h
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
#ifndef _FORMAT_H
|
2
|
+
#define _FORMAT_H
|
3
|
+
|
4
|
+
#define TPL_INSTRUCTION_FORMAT "A(S(uuUUU))"
|
5
|
+
#define TPL_REGISTER_FORMAT "U#"
|
6
|
+
|
7
|
+
/****** Source masks ******/
|
8
|
+
#define SRC_TYPE 0x00000001 /* ...... ........ ...... .... .... 0001 */
|
9
|
+
#define SRC_MODE 0x00000006 /* ...... ........ ...... .... .... 0110 */
|
10
|
+
#define SRC_RSVD 0x00000008 /* ...... ........ ...... .... .... 1000 */
|
11
|
+
|
12
|
+
#define SRC_TYPE_VAL 0x00000000 /* ...... ........ ...... .... .... ...0 */
|
13
|
+
#define SRC_TYPE_REF 0x00000001 /* ...... ........ ...... .... .... ...1 */
|
14
|
+
|
15
|
+
#define SRC_MODE_IMM 0x00000000 /* ...... ........ ...... .... .... .00. */
|
16
|
+
#define SRC_MODE_CONST 0x00000002 /* ...... ........ ...... .... .... .01. */
|
17
|
+
#define SRC_MODE_ADDR 0x00000006 /* ...... ........ ...... .... .... .11. */
|
18
|
+
#define SRC_MODE_REG 0x00000004 /* ...... ........ ...... .... .... .10. */
|
19
|
+
|
20
|
+
/****** Argument masks ******/
|
21
|
+
#define ARG_TYPE 0x00000010 /* ...... ........ ...... .... 0001 .... */
|
22
|
+
#define ARG_MODE 0x00000060 /* ...... ........ ...... .... 0110 .... */
|
23
|
+
#define ARG_RSVD 0x00000080 /* ...... ........ ...... .... 1000 .... */
|
24
|
+
|
25
|
+
#define ARG_TYPE_VAL 0x00000000 /* ...... ........ ...... .... ...0 .... */
|
26
|
+
#define ARG_TYPE_REF 0x00000010 /* ...... ........ ...... .... ...1 .... */
|
27
|
+
|
28
|
+
#define ARG_MODE_IMM 0x00000000 /* ...... ........ ...... .... .00. .... */
|
29
|
+
#define ARG_MODE_CONST 0x00000020 /* ...... ........ ...... .... .01. .... */
|
30
|
+
#define ARG_MODE_ADDR 0x00000060 /* ...... ........ ...... .... .11. .... */
|
31
|
+
#define ARG_MODE_REG 0x00000040 /* ...... ........ ...... .... .10. .... */
|
32
|
+
|
33
|
+
/****** Destination masks ******/
|
34
|
+
#define DST_TYPE 0x00000600 /* ...... ........ ...... 0110 .... .... */
|
35
|
+
#define DST_RSVD 0x00000900 /* ...... ........ ...... 1001 .... .... */
|
36
|
+
|
37
|
+
#define DST_MODE_ADDR 0x00000600 /* ...... ........ ...... .11. .... .... */
|
38
|
+
#define DST_MODE_REG 0x00000400 /* ...... ........ ...... .10. .... .... */
|
39
|
+
|
40
|
+
#define OP 0x03FC0000 /* ...... 11111111 ...... .... .... .... */
|
41
|
+
#define OP_RSVD 0x00000000 /* ...... 00000000 ...... .... .... .... */
|
42
|
+
|
43
|
+
#define IF 0x00007000 /* ...... ........ 000001 .... .... .... */
|
44
|
+
#define IF_RSVD 0x00038000 /* ...... ........ 111110 .... .... .... */
|
45
|
+
|
46
|
+
/* OP_FULL is a combined opcode and interface mask. */
|
47
|
+
#define OP_FULL (IF|OP) /* ...... 11111111 000001 .... .... .... */
|
48
|
+
|
49
|
+
#define IF_CORE 0x00000000 /* ...... ........ .....0 .... .... .... */
|
50
|
+
|
51
|
+
#define OP_CLR 0x00000000 /* ...... 00000000 .....0 .... .... .... */
|
52
|
+
#define OP_MOV 0x03FC0000 /* ...... 11111111 .....0 .... .... .... */
|
53
|
+
#define OP_SORT 0x00040000 /* ...... 00000001 .....0 .... .... .... */
|
54
|
+
#define OP_AVG 0x03F80000 /* ...... 11111110 .....0 .... .... .... */
|
55
|
+
#define OP_BE 0x000C0000 /* ...... 00000011 .....0 .... .... .... */
|
56
|
+
#define OP_BNE 0x03F00000 /* ...... 11111100 .....0 .... .... .... */
|
57
|
+
#define OP_BEZ 0x00080000 /* ...... 00000010 .....0 .... .... .... */
|
58
|
+
#define OP_BNEZ 0x03F40000 /* ...... 11111101 .....0 .... .... .... */
|
59
|
+
#define OP_BLTEZ 0x00180000 /* ...... 00000110 .....0 .... .... .... */
|
60
|
+
#define OP_BGTEZ 0x03E40000 /* ...... 11111001 .....0 .... .... .... */
|
61
|
+
#define OP_JMP 0x001C0000 /* ...... 00000111 .....0 .... .... .... */
|
62
|
+
#define OP_SKP 0x03E00000 /* ...... 11111000 .....0 .... .... .... */
|
63
|
+
#define OP_MIN 0x00140000 /* ...... 00000101 .....0 .... .... .... */
|
64
|
+
#define OP_MAX 0x03E80000 /* ...... 11111010 .....0 .... .... .... */
|
65
|
+
#define OP_BLT 0x00100000 /* ...... 00000100 .....0 .... .... .... */
|
66
|
+
#define OP_BGT 0x03EC0000 /* ...... 11111011 .....0 .... .... .... */
|
67
|
+
#define OP_BLTZ 0x00300000 /* ...... 00001100 .....0 .... .... .... */
|
68
|
+
#define OP_BGTZ 0x03CC0000 /* ...... 11110011 .....0 .... .... .... */
|
69
|
+
#define OP_BLTE 0x00340000 /* ...... 00001101 .....0 .... .... .... */
|
70
|
+
#define OP_BGTE 0x03C80000 /* ...... 11110010 .....0 .... .... .... */
|
71
|
+
#define OP_PUSH 0x003C0000 /* ...... 00001111 .....0 .... .... .... */
|
72
|
+
#define OP_POP 0x03C00000 /* ...... 11110000 .....0 .... .... .... */
|
73
|
+
#define OP_OR 0x00380000 /* ...... 00001110 .....0 .... .... .... */
|
74
|
+
#define OP_NOR 0x03C40000 /* ...... 11110001 .....0 .... .... .... */
|
75
|
+
#define OP_ADD 0x00280000 /* ...... 00001010 .....0 .... .... .... */
|
76
|
+
#define OP_SUB 0x03D40000 /* ...... 11110101 .....0 .... .... .... */
|
77
|
+
#define OP_INC 0x002C0000 /* ...... 00001011 .....0 .... .... .... */
|
78
|
+
#define OP_DEC 0x03D00000 /* ...... 11110100 .....0 .... .... .... */
|
79
|
+
#define OP_GRY 0x00240000 /* ...... 00001001 .....0 .... .... .... */
|
80
|
+
#define OP_HUE 0x03D80000 /* ...... 11110110 .....0 .... .... .... */
|
81
|
+
#define OP_CALL 0x00200000 /* ...... 00001000 .....0 .... .... .... */
|
82
|
+
#define OP_RET 0x03DC0000 /* ...... 11110111 .....0 .... .... .... */
|
83
|
+
#define OP_AND 0x00600000 /* ...... 00011000 .....0 .... .... .... */
|
84
|
+
#define OP_NAND 0x039C0000 /* ...... 11100111 .....0 .... .... .... */
|
85
|
+
#define OP_MUL 0x00640000 /* ...... 00011001 .....0 .... .... .... */
|
86
|
+
#define OP_DIV 0x03980000 /* ...... 11100110 .....0 .... .... .... */
|
87
|
+
#define OP_SHL 0x006C0000 /* ...... 00011011 .....0 .... .... .... */
|
88
|
+
#define OP_SHR 0x03900000 /* ...... 11100100 .....0 .... .... .... */
|
89
|
+
#define OP_ROTL 0x00680000 /* ...... 00011010 .....0 .... .... .... */
|
90
|
+
#define OP_ROTR 0x03940000 /* ...... 11100101 .....0 .... .... .... */
|
91
|
+
#define OP_LOCK 0x00780000 /* ...... 00011110 .....0 .... .... .... */
|
92
|
+
#define OP_ULOCK 0x03840000 /* ...... 11100001 .....0 .... .... .... */
|
93
|
+
#define OP_XOR 0x007C0000 /* ...... 00011111 .....0 .... .... .... */
|
94
|
+
#define OP_NOT 0x03800000 /* ...... 11100000 .....0 .... .... .... */
|
95
|
+
#define OP_POW 0x00740000 /* ...... 00011101 .....0 .... .... .... */
|
96
|
+
#define OP_ROOT 0x03880000 /* ...... 11100010 .....0 .... .... .... */
|
97
|
+
#define OP_SQR 0x00700000 /* ...... 00011100 .....0 .... .... .... */
|
98
|
+
#define OP_SQRT 0x038C0000 /* ...... 11100011 .....0 .... .... .... */
|
99
|
+
#define OP_EXP 0x00500000 /* ...... 00010100 .....0 .... .... .... */
|
100
|
+
#define OP_LN 0x03AC0000 /* ...... 11101011 .....0 .... .... .... */
|
101
|
+
#define OP_TXN 0x00540000 /* ...... 00010101 .....0 .... .... .... */
|
102
|
+
#define OP_CMT 0x03A80000 /* ...... 11101010 .....0 .... .... .... */
|
103
|
+
#define OP_RSV0 0x005C0000 /* ...... 00010111 .....0 .... .... .... */
|
104
|
+
#define OP_RSV1 0x03A00000 /* ...... 11101000 .....0 .... .... .... */
|
105
|
+
#define OP_SIN 0x00580000 /* ...... 00010110 .....0 .... .... .... */
|
106
|
+
#define OP_ASIN 0x03A40000 /* ...... 11101001 .....0 .... .... .... */
|
107
|
+
#define OP_COS 0x00480000 /* ...... 00010010 .....0 .... .... .... */
|
108
|
+
#define OP_ACOS 0x03B40000 /* ...... 11101101 .....0 .... .... .... */
|
109
|
+
#define OP_TAN 0x004C0000 /* ...... 00010011 .....0 .... .... .... */
|
110
|
+
#define OP_ATAN 0x03B00000 /* ...... 11101100 .....0 .... .... .... */
|
111
|
+
#define OP_RND 0x00440000 /* ...... 00010001 .....0 .... .... .... */
|
112
|
+
#define OP_SEND 0x03B80000 /* ...... 11101110 .....0 .... .... .... */
|
113
|
+
#define OP_RSV2 0x00400000 /* ...... 00010000 .....0 .... .... .... */
|
114
|
+
#define OP_RSV3 0x03BC0000 /* ...... 11101111 .....0 .... .... .... */
|
115
|
+
#define OP_CSC 0x00C00000 /* ...... 00110000 .....0 .... .... .... */
|
116
|
+
#define OP_ACSC 0x033C0000 /* ...... 11001111 .....0 .... .... .... */
|
117
|
+
#define OP_SEC 0x00C40000 /* ...... 00110001 .....0 .... .... .... */
|
118
|
+
#define OP_ASEC 0x03380000 /* ...... 11001110 .....0 .... .... .... */
|
119
|
+
#define OP_COT 0x00CC0000 /* ...... 00110011 .....0 .... .... .... */
|
120
|
+
#define OP_ACOT 0x03300000 /* ...... 11001100 .....0 .... .... .... */
|
121
|
+
|
122
|
+
#define FLAGS_RSVD 0xFC000000 /* 111111 ........ ...... .... .... .... */
|
123
|
+
|
124
|
+
#define VALID_INSTRUCTION (~(SRC_RSVD|ARG_RSVD|DST_RSVD|OP_RSVD|IF_RSVD|FLAGS_RSVD))
|
125
|
+
|
126
|
+
#endif
|
data/lib/codex.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "codex_rb_ext")
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module Codex
|
5
|
+
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}".freeze
|
6
|
+
|
7
|
+
class Page
|
8
|
+
end
|
9
|
+
|
10
|
+
class File
|
11
|
+
end
|
12
|
+
|
13
|
+
class Connection
|
14
|
+
def initialize(host='cloudburst.net', port=32700)
|
15
|
+
@host = host
|
16
|
+
@port = port
|
17
|
+
@sock = UDPSocket.open
|
18
|
+
@ops = []
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def push(op, src, arg, dst)
|
23
|
+
@ops += [op, src, arg, dst]
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def compile
|
28
|
+
@page = Codex::Page.new(@ops)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
@sock.send(@page.to_s, 0, @host, @port)
|
34
|
+
if select([@sock], nil, nil, 1)
|
35
|
+
Codex::File.new(@sock.recvfrom(0xFFFF).shift).to_a
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|