synthemesc-impulse 0.0.1 → 0.0.3
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/.document +5 -0
- data/VERSION +1 -1
- data/ext/.gitignore +1 -0
- data/ext/extconf.rb +12 -0
- data/ext/impulse_ext.c +21 -0
- data/ext/impulse_ext.h +25 -0
- data/ext/stream.c +69 -0
- data/impulse.gemspec +53 -0
- data/lib/app.rb +77 -0
- data/lib/impulse.rb +2 -1
- data/lib/ruby_to_impulse.rb +31 -0
- data/lib/stream.rb +60 -0
- metadata +12 -2
data/.document
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/ext/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mkmf.log
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
ImpulseC = ENV["IMPULSEC_HOME"] || File.join(%w(usr Impulse CoDeveloper3))
|
4
|
+
|
5
|
+
lib_path = File.join(ImpulseC, "Libraries")
|
6
|
+
inc_path = File.join(ImpulseC, "Include")
|
7
|
+
|
8
|
+
((have_header("co.h") || find_header("co.h", inc_path)) &&
|
9
|
+
have_header("cosim_log.h") || find_header("cosim_log.h", inc_path) &&
|
10
|
+
have_library("ImpulseC") || find_library("ImpulseC", nil, lib_path)) || exit
|
11
|
+
|
12
|
+
create_makefile("impulse_ext")
|
data/ext/impulse_ext.c
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "impulse_ext.h"
|
3
|
+
|
4
|
+
void Init_impulse_ext()
|
5
|
+
{
|
6
|
+
/* Impulse module */
|
7
|
+
mImpulse = rb_define_module("Impulse");
|
8
|
+
|
9
|
+
/* Base classes, probably placeholders for now */
|
10
|
+
cArch = rb_define_class_under(mImpulse, "Architecture", rb_cObject);
|
11
|
+
cLog = rb_define_class_under(mImpulse, "Log", rb_cObject);
|
12
|
+
cMemory = rb_define_class_under(mImpulse, "Memory", rb_cObject);
|
13
|
+
cProcess = rb_define_class_under(mImpulse, "Process", rb_cObject);
|
14
|
+
cRegister = rb_define_class_under(mImpulse, "Register", rb_cObject);
|
15
|
+
cSignal = rb_define_class_under(mImpulse, "Signal", rb_cObject);
|
16
|
+
|
17
|
+
/* Impulse::Stream */
|
18
|
+
Init_stream();
|
19
|
+
|
20
|
+
return;
|
21
|
+
}
|
data/ext/impulse_ext.h
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#ifndef IMPULSE_EXT_H
|
2
|
+
#define IMPULSE_EXT_H
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
|
6
|
+
#include "co.h"
|
7
|
+
#include "cosim_log.h"
|
8
|
+
|
9
|
+
/* Modules */
|
10
|
+
VALUE mImpulse;
|
11
|
+
|
12
|
+
/* Classes */
|
13
|
+
VALUE cArch;
|
14
|
+
VALUE cLog;
|
15
|
+
VALUE cMemory;
|
16
|
+
VALUE cProcess;
|
17
|
+
VALUE cRegister;
|
18
|
+
VALUE cSignal;
|
19
|
+
VALUE cStream;
|
20
|
+
|
21
|
+
/* Init prototypes */
|
22
|
+
void Init_impulse_ext();
|
23
|
+
void Init_stream();
|
24
|
+
|
25
|
+
#endif
|
data/ext/stream.c
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
#include "impulse_ext.h"
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Marks a co_stream object for the Ruby garbage collector.
|
8
|
+
* Currently a no-op.
|
9
|
+
*/
|
10
|
+
static void
|
11
|
+
co_stream_rb_mark(stream)
|
12
|
+
co_stream stream;
|
13
|
+
{
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
|
17
|
+
/* Frees the actual co_stream object by closing it. */
|
18
|
+
static void
|
19
|
+
co_stream_rb_free(stream)
|
20
|
+
co_stream stream;
|
21
|
+
{
|
22
|
+
if (stream) co_stream_close(stream);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE
|
27
|
+
co_stream_rb_alloc(self)
|
28
|
+
VALUE self;
|
29
|
+
{
|
30
|
+
co_stream stream;
|
31
|
+
return Data_Wrap_Struct(self, co_stream_rb_mark, co_stream_rb_free, stream);
|
32
|
+
}
|
33
|
+
|
34
|
+
static VALUE
|
35
|
+
t_stream_init(self, name, mode, width, depth)
|
36
|
+
VALUE self; /* the object */
|
37
|
+
VALUE name; /* unique name */
|
38
|
+
VALUE mode; /* 'r' || 'w' || error */
|
39
|
+
VALUE width; /* stream width */
|
40
|
+
VALUE depth; /* stream depth */
|
41
|
+
{
|
42
|
+
DATA_PTR(self) = co_stream_create(RSTRING(name)->ptr,
|
43
|
+
INT_TYPE(FIX2INT(width)), /* co_int32, e.g. */
|
44
|
+
FIX2INT(depth)); /* stream FIFO depth */
|
45
|
+
|
46
|
+
/* 'r' is read only mode */
|
47
|
+
if (!strncmp(RSTRING(mode)->ptr, "r", 1)) {
|
48
|
+
co_stream_open(DATA_PTR(self), O_RDONLY, INT_TYPE(FIX2INT(width)));
|
49
|
+
|
50
|
+
/* 'w' is write only mode */
|
51
|
+
} else if (!strncmp(RSTRING(mode)->ptr, "w", 1)) {
|
52
|
+
co_stream_open(DATA_PTR(self), O_WRONLY, INT_TYPE(FIX2INT(width)));
|
53
|
+
|
54
|
+
/* there is no other mode these can have. */
|
55
|
+
} else {
|
56
|
+
rb_raise(rb_eRuntimeError, "Reading and writing on streams is mutually exclusive.");
|
57
|
+
return Qnil;
|
58
|
+
}
|
59
|
+
|
60
|
+
return (self);
|
61
|
+
}
|
62
|
+
|
63
|
+
void Init_stream()
|
64
|
+
{
|
65
|
+
cStream = rb_define_class_under(mImpulse, "Stream", rb_cObject);
|
66
|
+
|
67
|
+
rb_define_alloc_func(cStream, co_stream_rb_alloc);
|
68
|
+
rb_define_method(cStream, "initialize", t_stream_init, 4);
|
69
|
+
}
|
data/impulse.gemspec
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{impulse}
|
5
|
+
s.version = "0.0.3"
|
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-06-23}
|
10
|
+
s.email = %q{josh@agentcomputer.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"ext/.gitignore",
|
23
|
+
"ext/extconf.rb",
|
24
|
+
"ext/impulse_ext.c",
|
25
|
+
"ext/impulse_ext.h",
|
26
|
+
"ext/stream.c",
|
27
|
+
"impulse.gemspec",
|
28
|
+
"lib/app.rb",
|
29
|
+
"lib/impulse.rb",
|
30
|
+
"lib/project.rb",
|
31
|
+
"lib/ruby_to_impulse.rb",
|
32
|
+
"lib/stream.rb",
|
33
|
+
"lib/template.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/synthemesc/impulse}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubyforge_project = %q{impulse}
|
39
|
+
s.rubygems_version = %q{1.3.4}
|
40
|
+
s.summary = %q{Ruby tools for the Impulse platform}
|
41
|
+
|
42
|
+
s.add_dependency "facets"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
else
|
50
|
+
end
|
51
|
+
else
|
52
|
+
end
|
53
|
+
end
|
data/lib/app.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "facets"
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
module AppMacros
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def has_stream( *syms )
|
12
|
+
syms.flatten.each do |sym|
|
13
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
14
|
+
def #{sym}
|
15
|
+
@streams ||= Hash.new { |hash, key| hash[key] = Impulse::Stream.new(key) }
|
16
|
+
@streams[:#{sym}]
|
17
|
+
end
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
return syms
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_process( *syms )
|
24
|
+
syms.flatten.each do |sym|
|
25
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
26
|
+
def #{sym}
|
27
|
+
@processes ||= Hash.new { |hash, key| hash[key] = Impulse::Process.new(key) }
|
28
|
+
@processes[:#{sym}]
|
29
|
+
end
|
30
|
+
EOS
|
31
|
+
end
|
32
|
+
return syms
|
33
|
+
end
|
34
|
+
|
35
|
+
def arch(sym)
|
36
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
37
|
+
def arch
|
38
|
+
:#{sym}
|
39
|
+
end
|
40
|
+
EOS
|
41
|
+
return sym
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Impulse
|
48
|
+
class Stream
|
49
|
+
include StreamMacros
|
50
|
+
|
51
|
+
width 32
|
52
|
+
depth 1
|
53
|
+
|
54
|
+
def name
|
55
|
+
"stream_#{self.class.methodize}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Process
|
60
|
+
def initialize(*args)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class App
|
65
|
+
include AppMacros
|
66
|
+
|
67
|
+
arch :generic
|
68
|
+
has_stream :input
|
69
|
+
has_stream :output
|
70
|
+
has_process :producer
|
71
|
+
has_process :consumer
|
72
|
+
|
73
|
+
def name
|
74
|
+
self.class.methodize
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/impulse.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'parse_tree'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
class Array
|
6
|
+
# [:a, :b, :c] ~= [:a, :b]
|
7
|
+
def =~ other
|
8
|
+
s = length.min
|
9
|
+
flatten.slice(0, s) === other.flatten.slice(0, s)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RubyToImpulse < SexpProcessor
|
14
|
+
def initialize(*args)
|
15
|
+
super()
|
16
|
+
self.auto_shift_type = true
|
17
|
+
self.strict = true
|
18
|
+
self.expected = String
|
19
|
+
self.require_empty = true
|
20
|
+
self.default_method = :fallback
|
21
|
+
process(ParseTree.translate(*args))
|
22
|
+
end
|
23
|
+
|
24
|
+
def fallback(exp)
|
25
|
+
puts "*** Implement ***"
|
26
|
+
pp exp
|
27
|
+
puts "*** Implement (flat) ***"
|
28
|
+
pp exp.flatten
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
data/lib/stream.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "facets"
|
3
|
+
|
4
|
+
module Impulse
|
5
|
+
class Stream
|
6
|
+
def self.width(new_width)
|
7
|
+
width = new_width.to_i
|
8
|
+
if width.to_i <= 0
|
9
|
+
raise(ArgumentError, %Q{usage: `width 32': given `#{new_width}'})
|
10
|
+
end
|
11
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
12
|
+
def width; #{width.to_i}; end
|
13
|
+
EOS
|
14
|
+
return new_width
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.depth(new_depth)
|
18
|
+
depth = new_depth.to_i
|
19
|
+
if depth.to_i <= 0
|
20
|
+
raise(ArgumentError, %Q{usage: `depth N': given `#{new_depth}'})
|
21
|
+
end
|
22
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
23
|
+
def depth; #{depth.to_i}; end
|
24
|
+
EOS
|
25
|
+
return new_depth
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.size(dimensions)
|
29
|
+
width, depth = dimensions.to_s.split("x", 2)
|
30
|
+
if width.to_i <= 0 || depth.to_i <= 0
|
31
|
+
raise(ArgumentError, %Q{usage: `size "12x34"': given `size "#{dimensions}"'})
|
32
|
+
end
|
33
|
+
self.width width
|
34
|
+
self.depth depth
|
35
|
+
dimensions
|
36
|
+
end
|
37
|
+
|
38
|
+
def name
|
39
|
+
"stream_#{self.class.methodize}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Defaults
|
43
|
+
width 32
|
44
|
+
depth 1
|
45
|
+
|
46
|
+
def create
|
47
|
+
end
|
48
|
+
|
49
|
+
def open
|
50
|
+
end
|
51
|
+
|
52
|
+
def read
|
53
|
+
end
|
54
|
+
|
55
|
+
def write
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method :<<, :write
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synthemesc-impulse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Eckstein
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,13 +32,23 @@ extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README.rdoc
|
34
34
|
files:
|
35
|
+
- .document
|
35
36
|
- .gitignore
|
36
37
|
- LICENSE
|
37
38
|
- README.rdoc
|
38
39
|
- Rakefile
|
39
40
|
- VERSION
|
41
|
+
- ext/.gitignore
|
42
|
+
- ext/extconf.rb
|
43
|
+
- ext/impulse_ext.c
|
44
|
+
- ext/impulse_ext.h
|
45
|
+
- ext/stream.c
|
46
|
+
- impulse.gemspec
|
47
|
+
- lib/app.rb
|
40
48
|
- lib/impulse.rb
|
41
49
|
- lib/project.rb
|
50
|
+
- lib/ruby_to_impulse.rb
|
51
|
+
- lib/stream.rb
|
42
52
|
- lib/template.rb
|
43
53
|
has_rdoc: false
|
44
54
|
homepage: http://github.com/synthemesc/impulse
|