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/tpl.h ADDED
@@ -0,0 +1,119 @@
1
+ /*
2
+ Copyright (c) 2005-2009, Troy D. Hanson http://tpl.sourceforge.net
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
12
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
13
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
15
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ #ifndef TPL_H
25
+ #define TPL_H
26
+
27
+ #include <stddef.h> /* size_t */
28
+
29
+ #ifdef _MSC_VER
30
+ typedef unsigned int uint32_t;
31
+ #else
32
+ #include <inttypes.h> /* uint32_t */
33
+ #endif
34
+
35
+ #if defined __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ #define TPL_API
40
+
41
+ /* bit flags (external) */
42
+ #define TPL_FILE (1 << 0)
43
+ #define TPL_MEM (1 << 1)
44
+ #define TPL_PREALLOCD (1 << 2)
45
+ #define TPL_EXCESS_OK (1 << 3)
46
+ #define TPL_FD (1 << 4)
47
+ #define TPL_UFREE (1 << 5)
48
+ #define TPL_DATAPEEK (1 << 6)
49
+ #define TPL_FXLENS (1 << 7)
50
+ #define TPL_GETSIZE (1 << 8)
51
+ /* do not add flags here without renumbering the internal flags! */
52
+
53
+ /* flags for tpl_gather mode */
54
+ #define TPL_GATHER_BLOCKING 1
55
+ #define TPL_GATHER_NONBLOCKING 2
56
+ #define TPL_GATHER_MEM 3
57
+
58
+ /* Hooks for error logging, memory allocation functions and fatal */
59
+ typedef int (tpl_print_fcn)(const char *fmt, ...);
60
+ typedef void *(tpl_malloc_fcn)(size_t sz);
61
+ typedef void *(tpl_realloc_fcn)(void *ptr, size_t sz);
62
+ typedef void (tpl_free_fcn)(void *ptr);
63
+ typedef void (tpl_fatal_fcn)(char *fmt, ...);
64
+
65
+ typedef struct tpl_hook_t {
66
+ tpl_print_fcn *oops;
67
+ tpl_malloc_fcn *malloc;
68
+ tpl_realloc_fcn *realloc;
69
+ tpl_free_fcn *free;
70
+ tpl_fatal_fcn *fatal;
71
+ size_t gather_max;
72
+ } tpl_hook_t;
73
+
74
+ typedef struct tpl_node {
75
+ int type;
76
+ void *addr;
77
+ void *data; /* r:tpl_root_data*. A:tpl_atyp*. ow:szof type */
78
+ int num; /* length of type if its a C array */
79
+ size_t ser_osz; /* serialization output size for subtree */
80
+ struct tpl_node *children; /* my children; linked-list */
81
+ struct tpl_node *next,*prev; /* my siblings (next child of my parent) */
82
+ struct tpl_node *parent; /* my parent */
83
+ } tpl_node;
84
+
85
+ /* used when un/packing 'B' type (binary buffers) */
86
+ typedef struct tpl_bin {
87
+ void *addr;
88
+ uint32_t sz;
89
+ } tpl_bin;
90
+
91
+ /* for async/piecemeal reading of tpl images */
92
+ typedef struct tpl_gather_t {
93
+ char *img;
94
+ int len;
95
+ } tpl_gather_t;
96
+
97
+ /* Callback used when tpl_gather has read a full tpl image */
98
+ typedef int (tpl_gather_cb)(void *img, size_t sz, void *data);
99
+
100
+ /* Prototypes */
101
+ TPL_API tpl_node *tpl_map(char *fmt,...); /* define tpl using format */
102
+ TPL_API void tpl_free(tpl_node *r); /* free a tpl map */
103
+ TPL_API int tpl_pack(tpl_node *r, int i); /* pack the n'th packable */
104
+ TPL_API int tpl_unpack(tpl_node *r, int i); /* unpack the n'th packable */
105
+ TPL_API int tpl_dump(tpl_node *r, int mode, ...); /* serialize to mem/file */
106
+ TPL_API int tpl_load(tpl_node *r, int mode, ...); /* set mem/file to unpack */
107
+ TPL_API int tpl_Alen(tpl_node *r, int i); /* array len of packable i */
108
+ TPL_API char* tpl_peek(int mode, ...); /* sneak peek at format string */
109
+ TPL_API int tpl_gather( int mode, ...); /* non-blocking image gather */
110
+ TPL_API int tpl_jot(int mode, ...); /* quick write a simple tpl */
111
+
112
+ char *calc_field_addr(tpl_node *r, int t, char *addr, int o);
113
+
114
+ #if defined __cplusplus
115
+ }
116
+ #endif
117
+
118
+ #endif /* TPL_H */
119
+
data/vm.c ADDED
@@ -0,0 +1,57 @@
1
+ #include <assert.h>
2
+ #include <fcntl.h>
3
+ #include <stdio.h>
4
+ #include <string.h>
5
+ #include <sys/mman.h>
6
+ #include <sys/stat.h>
7
+ #include <sys/types.h>
8
+ #include <unistd.h>
9
+
10
+ #include "codex.h"
11
+
12
+ void codex_init(struct codex* sys)
13
+ {
14
+ /* Make sure map size is sane */
15
+ assert(sys->size > 0);
16
+ assert(sys->size > (uint64_t)getpagesize());
17
+ assert(sys->size < UINT64_MAX);
18
+
19
+ assert(sys->offset >= 0);
20
+ assert((sys->offset + sys->size) < UINT64_MAX);
21
+
22
+ sys->filename[sizeof(sys->filename)-1] = '\0';
23
+
24
+ assert(sys->filename != NULL);
25
+ assert(strlen(sys->filename) > 0);
26
+ assert(strlen(sys->filename) < 256);
27
+
28
+ fprintf(stderr, "Minimum size is %llu bytes, responding to 0x%llx.\n", LLU sys->size, LLU sys->offset);
29
+ fprintf(stderr, "Page size is %llu bytes.\n", LLU getpagesize());
30
+
31
+ fprintf(stderr, "Opening %s.. ", sys->filename);
32
+ assert((sys->descriptor = open(sys->filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) > 0);
33
+ fprintf(stderr, "done.\n");
34
+
35
+ /* Set permissions to something a little less arbitrary */
36
+ fprintf(stderr, "Setting 0600.. ");
37
+ assert(fchmod(sys->descriptor, S_IRUSR | S_IWUSR) == 0);
38
+ fprintf(stderr, "done.\n");
39
+
40
+ /* Stretch if possible by seeking to the position we want and writing a single byte. */
41
+ fprintf(stderr, "Stretching file to %llu bytes.. ", LLU sys->size);
42
+ assert(lseek(sys->descriptor, sys->size-1, SEEK_SET) == (sys->size-1)); /* Seek */
43
+ assert(write(sys->descriptor, "", 1) == 1); /* Write a single byte */
44
+ assert(lseek(sys->descriptor, 0, SEEK_SET) == 0); /* Rewind */
45
+ fprintf(stderr, "done.\n");
46
+
47
+ /* Grab the file status from our descriptor */
48
+ assert(fstat(sys->descriptor, &sys->status) == 0);
49
+
50
+ fprintf(stderr, "Mapping %llu bytes.. ", LLU sys->size);
51
+ sys->memory = mmap(NULL, sys->size, PROT_READ | PROT_WRITE, MAP_SHARED, sys->descriptor, 0);
52
+ assert(sys->memory != NULL);
53
+ assert(sys->memory != MAP_FAILED);
54
+ fprintf(stderr, "done.\n");
55
+
56
+ return;
57
+ }
data/vm.h ADDED
@@ -0,0 +1,35 @@
1
+ /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
+
3
+ #ifndef _VM_H
4
+ #define _VM_H
5
+
6
+ #include <stdint.h>
7
+ #include <sys/stat.h>
8
+
9
+ struct instruction_word {
10
+ uint32_t reserved;
11
+ uint32_t opcode;
12
+ uint64_t src;
13
+ uint64_t arg;
14
+ uint64_t dst;
15
+ };
16
+
17
+ #define CONSTANT_COUNT 1
18
+
19
+ #define REGISTER_COUNT 16
20
+ #define VALID_REGISTER 15
21
+
22
+ struct codex {
23
+ int descriptor;
24
+ char filename[256];
25
+ struct stat status;
26
+ uint64_t *memory;
27
+ uint64_t *limit;
28
+ uint64_t size;
29
+ uint64_t offset;
30
+ uint64_t registers[REGISTER_COUNT];
31
+ };
32
+
33
+ void codex_init(struct codex* sys);
34
+
35
+ #endif
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synthemesc-codex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Eckstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: josh@eksdyne.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - .gitignore
26
+ - Makefile.server
27
+ - README.markdown
28
+ - Rakefile
29
+ - VERSION
30
+ - build.h
31
+ - codex.c
32
+ - codex.gemspec
33
+ - codex.h
34
+ - codex_rb_ext.c
35
+ - extconf.rb
36
+ - format.h
37
+ - lib/codex.rb
38
+ - ptrn2mask
39
+ - tpl.c
40
+ - tpl.h
41
+ - vm.c
42
+ - vm.h
43
+ has_rdoc: false
44
+ homepage: http://github.com/synthemesc/codex
45
+ licenses:
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Codex network machine
70
+ test_files: []
71
+