synthemesc-impulse 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -3,6 +3,9 @@ Please see your CoDeveloper license for more information. The license below
3
3
  is only applicable to the Impulse Ruby gem. Please do not contact Impulse
4
4
  Accelerated Technologies with questions regarding support for this gem.
5
5
 
6
+ Project#to_makefile is derived from the icProj2make.pl script included with
7
+ the CoDeveloper distribution. See lib/project.rb for additional license details.
8
+
6
9
  ----------------------------------------------------------------------------
7
10
 
8
11
  Impulse Ruby gem Copyright (c) 2009 Joshua Eckstein.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/impulse.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{impulse}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Joshua Eckstein"]
9
- s.date = %q{2009-06-23}
10
- s.email = %q{josh@agentcomputer.com}
9
+ s.date = %q{2009-07-11}
10
+ s.email = %q{josh@eksdyne.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
13
13
  "README.rdoc"
@@ -19,19 +19,24 @@ Gem::Specification.new do |s|
19
19
  "README.rdoc",
20
20
  "Rakefile",
21
21
  "VERSION",
22
- "ext/.gitignore",
23
- "ext/extconf.rb",
24
- "ext/impulse_ext.c",
25
- "ext/impulse_ext.h",
26
- "ext/stream.c",
27
22
  "impulse.gemspec",
28
23
  "lib/app.rb",
24
+ "lib/ext/.gitignore",
25
+ "lib/ext/arch.c",
26
+ "lib/ext/extconf.rb",
27
+ "lib/ext/fixnum.c",
28
+ "lib/ext/impulse_ext.c",
29
+ "lib/ext/impulse_ext.h",
30
+ "lib/ext/log.c",
31
+ "lib/ext/stream.c",
29
32
  "lib/impulse.rb",
30
33
  "lib/project.rb",
31
34
  "lib/ruby_to_impulse.rb",
32
35
  "lib/stream.rb",
33
- "lib/template.rb"
36
+ "lib/template.rb",
37
+ "test/ext_test.rb"
34
38
  ]
39
+ s.has_rdoc = true
35
40
  s.homepage = %q{http://github.com/synthemesc/impulse}
36
41
  s.rdoc_options = ["--charset=UTF-8"]
37
42
  s.require_paths = ["lib"]
@@ -40,6 +45,9 @@ Gem::Specification.new do |s|
40
45
  s.summary = %q{Ruby tools for the Impulse platform}
41
46
 
42
47
  s.add_dependency "facets"
48
+ s.test_files = [
49
+ "test/ext_test.rb"
50
+ ]
43
51
 
44
52
  if s.respond_to? :specification_version then
45
53
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,5 @@
1
+ *.o
2
+ *.so
3
+ *.bundle
4
+ Makefile
5
+ mkmf.log
data/lib/ext/arch.c ADDED
@@ -0,0 +1,57 @@
1
+ #include <ruby.h>
2
+ #include <string.h>
3
+
4
+ #include "impulse_ext.h"
5
+
6
+ static VALUE
7
+ co_architecture_rb_alloc(self)
8
+ VALUE self;
9
+ {
10
+ co_architecture arch;
11
+ return Data_Wrap_Struct(self, 0, 0, arch); /* No mark/free */
12
+ }
13
+
14
+ /* No-op for now */
15
+ void t_configure(void *arg)
16
+ {
17
+ rb_need_block();
18
+ rb_cvar_set(cLog, id_cLog_initialized, (cosim_logwindow_init() != 0 ? Qtrue : Qfalse)
19
+ #ifdef RB_CVAR_SET_4ARGS
20
+ , 0
21
+ #endif
22
+ );
23
+ rb_yield(rb_block_proc());
24
+ return;
25
+ }
26
+
27
+ /* co_initialize is required to do anything. Ref'd in t_architecture_init */
28
+ co_architecture co_initialize(void *args)
29
+ {
30
+ return(co_architecture_create("rb_arch","generic_vhdl",t_configure,(void *)args));
31
+ }
32
+
33
+ /* Set up the co_architecture object and initialize */
34
+ static VALUE
35
+ t_architecture_init(self)
36
+ VALUE self; /* the object */
37
+ {
38
+ DATA_PTR(self) = (co_architecture) co_initialize((void *)self);
39
+ return (self);
40
+ }
41
+
42
+ static VALUE
43
+ t_architecture_execute(self)
44
+ VALUE self; /* the object */
45
+ {
46
+ co_execute(DATA_PTR(self));
47
+ return (Qtrue);
48
+ }
49
+
50
+ void Init_arch()
51
+ {
52
+ cArchitecture = rb_define_class_under(mImpulse, "Architecture", rb_cObject);
53
+
54
+ rb_define_alloc_func(cArchitecture, co_architecture_rb_alloc);
55
+ rb_define_method(cArchitecture, "initialize", t_architecture_init, 0);
56
+ rb_define_method(cArchitecture, "execute", t_architecture_execute, 0);
57
+ }
@@ -0,0 +1,21 @@
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
+ if (have_header("co.h") ||
9
+ find_header("co.h", inc_path)) &&
10
+ (have_header("cosim_log.h") ||
11
+ find_header("cosim_log.h", inc_path)) &&
12
+ (have_library("ImpulseC", "co_stream_open") ||
13
+ find_library("ImpulseC", "co_stream_open", lib_path)) then
14
+ create_makefile("impulse_ext")
15
+ else
16
+ STDERR.puts <<-EOS
17
+ Couldn't find the ImpulseC headers or library. Are you sure you have
18
+ them installed either in $IMPULSEC_HOME ('#{ENV["IMPULSEC_HOME"]}') or
19
+ the standard system locations (e.g., /usr/include, /usr/lib, etc.)?
20
+ EOS
21
+ end
data/lib/ext/fixnum.c ADDED
@@ -0,0 +1,73 @@
1
+ #include <ruby.h>
2
+ #include "impulse_ext.h"
3
+
4
+ static ID id_beg, id_end;
5
+
6
+ /* co_bit_extract is duck-equivalent to Ruby's slice methods.
7
+ * Keep in mind we don't implement fix_bit_extract_u because
8
+ * it's not exactly Ruby idiom-esque to make a distinction.
9
+ * Maybe some other time.
10
+ */
11
+
12
+ static VALUE
13
+ fix_bit_extract(self, index)
14
+ VALUE self;
15
+ VALUE index;
16
+ {
17
+ VALUE b, e;
18
+
19
+ /* Check that it's a range */
20
+ if (!rb_obj_is_kind_of(index, rb_cRange))
21
+ return(rb_super());
22
+
23
+ b = rb_ivar_get(index, id_beg);
24
+ e = rb_ivar_get(index, id_end);
25
+
26
+ if (FIXNUM_P(b) && FIXNUM_P(e))
27
+ {
28
+ return INT2FIX(co_bit_extract((int32) FIX2INT(self),
29
+ (uint8) FIX2UINT(b),
30
+ (uint8) FIX2UINT(e) - FIX2UINT(b)));
31
+ }
32
+ else
33
+ return(rb_super());
34
+ }
35
+
36
+ static VALUE
37
+ fix_bit_insert(self, index, from)
38
+ VALUE self;
39
+ VALUE index;
40
+ VALUE from;
41
+ {
42
+ VALUE b, e;
43
+
44
+ if (!rb_obj_is_kind_of(index, rb_cRange))
45
+ {
46
+ rb_raise(rb_eTypeError, "Range required");
47
+ return (INT2FIX(0));
48
+ }
49
+
50
+ b = rb_ivar_get(index, id_beg);
51
+ e = rb_ivar_get(index, id_end);
52
+
53
+ /* If it's not a range of numbers, well, it's 0 */
54
+ if (!FIXNUM_P(b) || !FIXNUM_P(e))
55
+ return(INT2FIX(0));
56
+
57
+ self = INT2FIX(co_bit_insert((int32) FIX2INT(self),
58
+ (uint8) FIX2UINT(b),
59
+ (uint8) FIX2INT(e) - FIX2INT(b),
60
+ (int32) FIX2INT(from)));
61
+
62
+ return (self);
63
+ }
64
+
65
+ void
66
+ Init_fixnum_ext()
67
+ {
68
+ rb_define_method(rb_cFixnum, "[]", fix_bit_extract, 1);
69
+ rb_define_method(rb_cFixnum, "[]=", fix_bit_insert, 2);
70
+
71
+ id_beg = rb_intern("begin");
72
+ id_end = rb_intern("end");
73
+ }
@@ -0,0 +1,39 @@
1
+ #include <ruby.h>
2
+ #include "impulse_ext.h"
3
+
4
+ static VALUE
5
+ t_impulse_simulation(self)
6
+ VALUE self; /* the object */
7
+ {
8
+ IF_SIM(return (Qtrue));
9
+ return (Qfalse);
10
+ }
11
+
12
+ void Init_impulse_ext()
13
+ {
14
+ /* Impulse module */
15
+ mImpulse = rb_define_module("Impulse");
16
+
17
+ /* Base classes, probably placeholders for now */
18
+ cArchitecture = rb_define_class_under(mImpulse, "Architecture", rb_cObject);
19
+ cLog = rb_define_class_under(mImpulse, "Log", rb_cObject);
20
+ cMemory = rb_define_class_under(mImpulse, "Memory", rb_cObject);
21
+ cProcess = rb_define_class_under(mImpulse, "Process", rb_cObject);
22
+ cRegister = rb_define_class_under(mImpulse, "Register", rb_cObject);
23
+ cSignal = rb_define_class_under(mImpulse, "Signal", rb_cObject);
24
+
25
+ rb_define_method(cArchitecture, "sim?", t_impulse_simulation, 0);
26
+ rb_define_method(cLog, "sim?", t_impulse_simulation, 0);
27
+ rb_define_method(cMemory, "sim?", t_impulse_simulation, 0);
28
+ rb_define_method(cProcess, "sim?", t_impulse_simulation, 0);
29
+ rb_define_method(cRegister, "sim?", t_impulse_simulation, 0);
30
+ rb_define_method(cSignal, "sim?", t_impulse_simulation, 0);
31
+
32
+ /* Impulse::Stream */
33
+ Init_stream();
34
+ Init_arch();
35
+ Init_fixnum_ext();
36
+ Init_log();
37
+
38
+ return;
39
+ }
@@ -1,6 +1,10 @@
1
1
  #ifndef IMPULSE_EXT_H
2
2
  #define IMPULSE_EXT_H
3
3
 
4
+ #ifdef WIN32
5
+ #include <windows.h>
6
+ #endif
7
+
4
8
  #include <ruby.h>
5
9
 
6
10
  #include "co.h"
@@ -10,7 +14,7 @@
10
14
  VALUE mImpulse;
11
15
 
12
16
  /* Classes */
13
- VALUE cArch;
17
+ VALUE cArchitecture;
14
18
  VALUE cLog;
15
19
  VALUE cMemory;
16
20
  VALUE cProcess;
@@ -18,8 +22,13 @@ VALUE cRegister;
18
22
  VALUE cSignal;
19
23
  VALUE cStream;
20
24
 
25
+ ID id_cLog_initialized;
26
+
21
27
  /* Init prototypes */
22
28
  void Init_impulse_ext();
23
29
  void Init_stream();
30
+ void Init_architecture();
31
+ void Init_fixnum_ext();
32
+ void Init_log();
24
33
 
25
- #endif
34
+ #endif
data/lib/ext/log.c ADDED
@@ -0,0 +1,87 @@
1
+ #include <ruby.h>
2
+ #include <string.h>
3
+
4
+ #include "impulse_ext.h"
5
+
6
+ static ID id_name;
7
+
8
+ /*
9
+ * Marks a co_log object for the Ruby garbage collector.
10
+ * Currently a no-op.
11
+ */
12
+ static void
13
+ cosim_logwindow_rb_mark(log)
14
+ cosim_logwindow log;
15
+ {
16
+ return;
17
+ }
18
+
19
+ /*
20
+ * Frees the actual cosim_logwindow object.
21
+ * Currently a no-op.
22
+ */
23
+ static void
24
+ cosim_logwindow_rb_free(log)
25
+ cosim_logwindow log;
26
+ {
27
+ return;
28
+ }
29
+
30
+ static VALUE
31
+ cosim_logwindow_rb_alloc(self)
32
+ VALUE self;
33
+ {
34
+ cosim_logwindow log;
35
+ return Data_Wrap_Struct(self, cosim_logwindow_rb_mark, cosim_logwindow_rb_free, log);
36
+ }
37
+
38
+ static VALUE
39
+ t_log_init(self, name)
40
+ VALUE self; /* the object */
41
+ VALUE name; /* unique name */
42
+ {
43
+ DATA_PTR(self) = cosim_logwindow_create(RSTRING(name)->ptr);
44
+ rb_ivar_set(self, id_name, name);
45
+ return (self);
46
+ }
47
+
48
+ static VALUE
49
+ t_log_puts(self, message)
50
+ VALUE self; /* the object */
51
+ VALUE message; /* log message */
52
+ {
53
+ if (!RTEST(rb_cvar_get(cLog, id_cLog_initialized)))
54
+ {
55
+ rb_warn("Can't do anything with the simulation log until you create an Architecture.");
56
+ return (Qnil);
57
+ }
58
+
59
+ /* TODO: Some actual type checking here would be nice. */
60
+ if (cosim_logwindow_write(DATA_PTR(self), RSTRING(message)->ptr) != 0)
61
+ return (self);
62
+ else
63
+ {
64
+ rb_raise(rb_eArgError, "Couldn't write to %s.", RSTRING(rb_ivar_get(self, id_name))->ptr);
65
+ return (self);
66
+ }
67
+ }
68
+
69
+ /*
70
+ static VALUE
71
+ t_log_printf(self, ...)
72
+ */
73
+
74
+ void Init_log()
75
+ {
76
+ cLog = rb_define_class_under(mImpulse, "Log", rb_cObject);
77
+ rb_cvar_set(cLog, id_cLog_initialized, Qfalse
78
+ #ifdef RB_CVAR_SET_4ARGS
79
+ , 0
80
+ #endif
81
+ );
82
+
83
+ rb_define_alloc_func(cLog, cosim_logwindow_rb_alloc);
84
+ rb_define_method(cLog, "initialize", t_log_init, 1);
85
+ rb_define_method(cLog, "puts", t_log_puts, 1);
86
+ rb_define_method(cLog, "<<", t_log_puts, 1);
87
+ }
@@ -3,6 +3,8 @@
3
3
 
4
4
  #include "impulse_ext.h"
5
5
 
6
+ static ID id_name, id_mode, id_width, id_depth;
7
+
6
8
  /*
7
9
  * Marks a co_stream object for the Ruby garbage collector.
8
10
  * Currently a no-op.
@@ -45,10 +47,12 @@ t_stream_init(self, name, mode, width, depth)
45
47
 
46
48
  /* 'r' is read only mode */
47
49
  if (!strncmp(RSTRING(mode)->ptr, "r", 1)) {
50
+ /* TODO: Check for errors/success here */
48
51
  co_stream_open(DATA_PTR(self), O_RDONLY, INT_TYPE(FIX2INT(width)));
49
52
 
50
53
  /* 'w' is write only mode */
51
54
  } else if (!strncmp(RSTRING(mode)->ptr, "w", 1)) {
55
+ /* TODO: Check for errors/success here */
52
56
  co_stream_open(DATA_PTR(self), O_WRONLY, INT_TYPE(FIX2INT(width)));
53
57
 
54
58
  /* there is no other mode these can have. */
@@ -57,13 +61,26 @@ t_stream_init(self, name, mode, width, depth)
57
61
  return Qnil;
58
62
  }
59
63
 
64
+ rb_ivar_set(self, id_name, name);
65
+ rb_ivar_set(self, id_mode, mode);
66
+ rb_ivar_set(self, id_width, width);
67
+ rb_ivar_set(self, id_depth, depth);
68
+
60
69
  return (self);
61
70
  }
62
71
 
72
+ static VALUE
73
+ t_stream_eos(self)
74
+ VALUE self;
75
+ {
76
+ return (co_stream_eos(DATA_PTR(self)) != 0 ? Qtrue : Qfalse);
77
+ }
78
+
63
79
  void Init_stream()
64
80
  {
65
81
  cStream = rb_define_class_under(mImpulse, "Stream", rb_cObject);
66
82
 
67
83
  rb_define_alloc_func(cStream, co_stream_rb_alloc);
68
84
  rb_define_method(cStream, "initialize", t_stream_init, 4);
69
- }
85
+ rb_define_method(cStream, "eos?", t_stream_eos, 0);
86
+ }
data/lib/impulse.rb CHANGED
@@ -1,3 +1,5 @@
1
- require "project"
2
- require "template"
3
- require "app"
1
+ root = File.dirname(__FILE__)
2
+ require File.join(root, "project")
3
+ require File.join(root, "template")
4
+ #require File.join(root, "app")
5
+ require File.join(root, "ext", "impulse_ext")
data/lib/project.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "rubygems"
2
- require "facets"
2
+ gem "facets"
3
3
 
4
4
  module Impulse
5
5
  # A CoDeveloper project is a simple plaintext file with an <em>.icProj</em>
@@ -22,7 +22,7 @@ module Impulse
22
22
  @options = Hash.new
23
23
 
24
24
  skipped_lines_header = false
25
- File.open(project_file).each_with_index do |line, line_number|
25
+ File.open(project_file.to_s).each_with_index do |line, line_number|
26
26
  next unless line.match ValidOptionLine
27
27
  print("Skipping lines: ") unless skipped_lines_header
28
28
  skipped_lines_header = true
@@ -98,5 +98,20 @@ module Impulse
98
98
  end
99
99
  end
100
100
  end
101
+
102
+ #--
103
+ # From the original icProj2Make.pl file:
104
+ #
105
+ # Copyright(c) 2006-2009 Impulse Accelerated Technologies, Inc.
106
+ # All rights reserved.
107
+ # www.ImpulseAccelerated.com
108
+ #
109
+ # This source file may be used and distributed without restriction provided
110
+ # that this copyright notice is not removed from the file and that any
111
+ # derivative work contains this copyright notice.
112
+ #++
113
+ def to_makefile
114
+ raise(ArgumentError, "Generated Makefiles require the IMPULSEC_HOME environment variable.") unless ENV["IMPULSEC_HOME"]
115
+ end
101
116
  end
102
117
  end
data/test/ext_test.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), "..", "lib", "ext", "impulse_ext")
2
+
3
+ require "test/unit"
4
+ require "rubygems"
5
+ gem "thoughtbot-shoulda"
6
+ require "shoulda"
7
+
8
+ class ExtTest < Test::Unit::TestCase
9
+ context "The C extension" do
10
+ should "set up classes" do
11
+ assert_kind_of(Module, Impulse)
12
+ assert_kind_of(Class, Impulse::Stream)
13
+ assert_kind_of(Class, Impulse::Architecture)
14
+ assert_kind_of(Class, Impulse::Log)
15
+ assert_kind_of(Class, Impulse::Memory)
16
+ assert_kind_of(Class, Impulse::Process)
17
+ assert_kind_of(Class, Impulse::Register)
18
+ assert_kind_of(Class, Impulse::Signal)
19
+ end
20
+ end
21
+ 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.3
4
+ version: 0.0.4
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-23 00:00:00 -07:00
12
+ date: 2009-07-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: "0"
24
24
  version:
25
25
  description:
26
- email: josh@agentcomputer.com
26
+ email: josh@eksdyne.com
27
27
  executables: []
28
28
 
29
29
  extensions: []
@@ -38,19 +38,23 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
- - ext/.gitignore
42
- - ext/extconf.rb
43
- - ext/impulse_ext.c
44
- - ext/impulse_ext.h
45
- - ext/stream.c
46
41
  - impulse.gemspec
47
42
  - lib/app.rb
43
+ - lib/ext/.gitignore
44
+ - lib/ext/arch.c
45
+ - lib/ext/extconf.rb
46
+ - lib/ext/fixnum.c
47
+ - lib/ext/impulse_ext.c
48
+ - lib/ext/impulse_ext.h
49
+ - lib/ext/log.c
50
+ - lib/ext/stream.c
48
51
  - lib/impulse.rb
49
52
  - lib/project.rb
50
53
  - lib/ruby_to_impulse.rb
51
54
  - lib/stream.rb
52
55
  - lib/template.rb
53
- has_rdoc: false
56
+ - test/ext_test.rb
57
+ has_rdoc: true
54
58
  homepage: http://github.com/synthemesc/impulse
55
59
  post_install_message:
56
60
  rdoc_options:
@@ -76,5 +80,5 @@ rubygems_version: 1.2.0
76
80
  signing_key:
77
81
  specification_version: 3
78
82
  summary: Ruby tools for the Impulse platform
79
- test_files: []
80
-
83
+ test_files:
84
+ - test/ext_test.rb
data/ext/.gitignore DELETED
@@ -1 +0,0 @@
1
- mkmf.log
data/ext/extconf.rb DELETED
@@ -1,12 +0,0 @@
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 DELETED
@@ -1,21 +0,0 @@
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
- }