wasm 0.0.1 → 0.0.2

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.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/assets/mruby/include/mrbconf.h +143 -0
  3. data/assets/mruby/include/mruby.h +1284 -0
  4. data/assets/mruby/include/mruby/array.h +279 -0
  5. data/assets/mruby/include/mruby/boxing_nan.h +102 -0
  6. data/assets/mruby/include/mruby/boxing_no.h +56 -0
  7. data/assets/mruby/include/mruby/boxing_word.h +136 -0
  8. data/assets/mruby/include/mruby/class.h +94 -0
  9. data/assets/mruby/include/mruby/common.h +72 -0
  10. data/assets/mruby/include/mruby/compile.h +194 -0
  11. data/assets/mruby/include/mruby/data.h +75 -0
  12. data/assets/mruby/include/mruby/debug.h +66 -0
  13. data/assets/mruby/include/mruby/dump.h +196 -0
  14. data/assets/mruby/include/mruby/error.h +75 -0
  15. data/assets/mruby/include/mruby/gc.h +91 -0
  16. data/assets/mruby/include/mruby/hash.h +182 -0
  17. data/assets/mruby/include/mruby/irep.h +62 -0
  18. data/assets/mruby/include/mruby/istruct.h +47 -0
  19. data/assets/mruby/include/mruby/khash.h +274 -0
  20. data/assets/mruby/include/mruby/numeric.h +161 -0
  21. data/assets/mruby/include/mruby/object.h +45 -0
  22. data/assets/mruby/include/mruby/opcode.h +161 -0
  23. data/assets/mruby/include/mruby/proc.h +131 -0
  24. data/assets/mruby/include/mruby/range.h +49 -0
  25. data/assets/mruby/include/mruby/re.h +16 -0
  26. data/assets/mruby/include/mruby/string.h +440 -0
  27. data/assets/mruby/include/mruby/throw.h +55 -0
  28. data/assets/mruby/include/mruby/value.h +309 -0
  29. data/assets/mruby/include/mruby/variable.h +138 -0
  30. data/assets/mruby/include/mruby/version.h +110 -0
  31. data/assets/mruby/libmruby.a +0 -0
  32. data/assets/mruby_init.c +16 -0
  33. data/assets/template.html +17 -0
  34. data/bin/ruby-wasm +150 -0
  35. data/build_config.rb +13 -0
  36. data/lib/wasm.rb +0 -5
  37. data/lib/wasm/version.rb +4 -2
  38. metadata +46 -65
  39. data/.gitignore +0 -9
  40. data/.travis.yml +0 -5
  41. data/Gemfile +0 -4
  42. data/LICENSE.txt +0 -21
  43. data/README.md +0 -40
  44. data/Rakefile +0 -10
  45. data/bin/console +0 -14
  46. data/bin/setup +0 -8
  47. data/wasm.gemspec +0 -26
@@ -0,0 +1,110 @@
1
+ /*
2
+ ** mruby/version.h - mruby version definition
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_VERSION_H
8
+ #define MRUBY_VERSION_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * mruby version definition macros
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ /*
18
+ * A passed in expression.
19
+ */
20
+ #define MRB_STRINGIZE0(expr) #expr
21
+
22
+ /*
23
+ * Passes in an expression to MRB_STRINGIZE0.
24
+ */
25
+ #define MRB_STRINGIZE(expr) MRB_STRINGIZE0(expr)
26
+
27
+ /*
28
+ * The version of Ruby used by mruby.
29
+ */
30
+ #define MRUBY_RUBY_VERSION "1.9"
31
+
32
+ /*
33
+ * Ruby engine.
34
+ */
35
+ #define MRUBY_RUBY_ENGINE "mruby"
36
+
37
+ /*
38
+ * Major release version number.
39
+ */
40
+ #define MRUBY_RELEASE_MAJOR 1
41
+
42
+ /*
43
+ * Minor release version number.
44
+ */
45
+ #define MRUBY_RELEASE_MINOR 4
46
+
47
+ /*
48
+ * Tiny release version number.
49
+ */
50
+ #define MRUBY_RELEASE_TEENY 1
51
+
52
+ /*
53
+ * The mruby version.
54
+ */
55
+ #define MRUBY_VERSION MRB_STRINGIZE(MRUBY_RELEASE_MAJOR) "." MRB_STRINGIZE(MRUBY_RELEASE_MINOR) "." MRB_STRINGIZE(MRUBY_RELEASE_TEENY)
56
+
57
+ /*
58
+ * Release number.
59
+ */
60
+ #define MRUBY_RELEASE_NO (MRUBY_RELEASE_MAJOR * 100 * 100 + MRUBY_RELEASE_MINOR * 100 + MRUBY_RELEASE_TEENY)
61
+
62
+ /*
63
+ * Release year.
64
+ */
65
+ #define MRUBY_RELEASE_YEAR 2018
66
+
67
+ /*
68
+ * Release month.
69
+ */
70
+ #define MRUBY_RELEASE_MONTH 4
71
+
72
+ /*
73
+ * Release day.
74
+ */
75
+ #define MRUBY_RELEASE_DAY 27
76
+
77
+ /*
78
+ * Release date as a string.
79
+ */
80
+ #define MRUBY_RELEASE_DATE MRB_STRINGIZE(MRUBY_RELEASE_YEAR) "-" MRB_STRINGIZE(MRUBY_RELEASE_MONTH) "-" MRB_STRINGIZE(MRUBY_RELEASE_DAY)
81
+
82
+ /*
83
+ * The year mruby was first created.
84
+ */
85
+ #define MRUBY_BIRTH_YEAR 2010
86
+
87
+ /*
88
+ * MRuby's authors.
89
+ */
90
+ #define MRUBY_AUTHOR "mruby developers"
91
+
92
+ /*
93
+ * mruby's version, and release date.
94
+ */
95
+ #define MRUBY_DESCRIPTION \
96
+ "mruby " MRUBY_VERSION \
97
+ " (" MRUBY_RELEASE_DATE ") " \
98
+
99
+ /*
100
+ * mruby's copyright information.
101
+ */
102
+ #define MRUBY_COPYRIGHT \
103
+ "mruby - Copyright (c) " \
104
+ MRB_STRINGIZE(MRUBY_BIRTH_YEAR)"-" \
105
+ MRB_STRINGIZE(MRUBY_RELEASE_YEAR)" " \
106
+ MRUBY_AUTHOR \
107
+
108
+ MRB_END_DECL
109
+
110
+ #endif /* MRUBY_VERSION_H */
Binary file
@@ -0,0 +1,16 @@
1
+ #include <mruby.h>
2
+ #include <mruby/irep.h>
3
+
4
+ int main() {
5
+ mrb_state *mrb = mrb_open();
6
+
7
+ if (!mrb) { /* handle error */ }
8
+
9
+ mrb_load_irep(mrb, ruby_app);
10
+
11
+ // If an exception, print error
12
+ if (mrb->exc) mrb_print_error(mrb);
13
+
14
+ mrb_close(mrb);
15
+ return 0;
16
+ }
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" dir="ltr">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Ruby on WebAssembly</title>
6
+ <style>
7
+ body {
8
+ font-family: system-ui;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <h1>Ruby on WebAssembly</h1>
14
+ <p>Open the web console to see output and errors.</p>
15
+ </body>
16
+ <script src="app.js"></script>
17
+ </html>
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+ require 'wasm/version'
3
+
4
+ # The installed gem directory
5
+ @gem_dir = "#{Gem::Specification.find_by_name('wasm').gem_dir}"
6
+
7
+ # Compilation optimizations flag
8
+ @optimize = false
9
+
10
+ # Extending `String` to include some fancy colors
11
+ class String
12
+ def colorize(c); "\e[#{c}m#{self}\e[0m" end
13
+ def bold; colorize('1') end
14
+ def success; colorize('1;32') end
15
+ def error; colorize('1;31') end
16
+ end
17
+
18
+ # Build a Ruby file
19
+ def build(rb_file)
20
+
21
+ # Clean up the build directory
22
+ FileUtils.rm_f 'build/app.c'
23
+ FileUtils.rm_f 'build/app.js'
24
+ FileUtils.rm_f 'build/app.wasm'
25
+ FileUtils.rm_f 'build/app.html'
26
+
27
+ # Check if source file provided is good
28
+ if !rb_file
29
+ puts 'Please provide a Ruby file to build'
30
+ exit
31
+ elsif !File.exists? rb_file
32
+ puts "Can't find file: #{rb_file}"
33
+ exit
34
+ end
35
+
36
+ # Create the build directory
37
+ FileUtils.mkdir_p 'build'
38
+
39
+ # Create MRuby bytecode from Ruby source file
40
+ `mrbc -Bruby_app -obuild/app.c #{rb_file}`
41
+
42
+ # Add MRuby init code to app bytecode
43
+ open('build/app.c', 'a') do |f|
44
+ f << "\n\n" << File.read("#{@gem_dir}/assets/mruby_init.c")
45
+ end
46
+
47
+ # Compile using Emscripten
48
+ `emcc -s WASM=1 #{ if @optimize then '-Os' end } -I #{@gem_dir + '/assets/mruby/include'} build/app.c #{@gem_dir + '/assets/mruby/libmruby.a'} -o build/app.js #{ if @optimize then '--closure 1' end }`
49
+
50
+ # Copy HTML template from gem assets to build directory
51
+ FileUtils.cp "#{@gem_dir}/assets/template.html", 'build/app.html'
52
+
53
+ # Clean up
54
+ FileUtils.rm_f 'build/app.c'
55
+
56
+ end
57
+
58
+ # Serve a build WebAssembly binary
59
+ def serve(open_browser)
60
+
61
+ if !File.exists? 'build/app.html'
62
+ puts 'No WebAssembly app built!'
63
+ exit
64
+ end
65
+
66
+ if open_browser
67
+ open_cmd = 'open'
68
+
69
+ case RUBY_PLATFORM
70
+ when /linux/
71
+ open_cmd = "xdg-#{open_cmd}"
72
+ when /mingw/
73
+ open_cmd = 'start'
74
+ end
75
+
76
+ Thread.new do
77
+ sleep 2
78
+ `#{open_cmd} http://localhost:8000/app.html`
79
+ end
80
+ end
81
+
82
+ `ruby -run -ehttpd ./build -p8000`
83
+ end
84
+
85
+ # Check for problems
86
+ def doctor
87
+
88
+ errors = false
89
+
90
+ puts "\nChecking for Emscripten tools"
91
+
92
+ # Check for `emcc`
93
+ print ' emcc...'
94
+ if `which emcc`.empty?
95
+ puts 'not found'.error
96
+ errors = true
97
+ else
98
+ puts 'found'.success
99
+ end
100
+
101
+ # Check for `emar`
102
+ print ' emar...'
103
+ if `which emar`.empty?
104
+ puts 'not found'.error
105
+ errors = true
106
+ else
107
+ puts 'found'.success
108
+ end
109
+
110
+ if errors
111
+ puts "\nErrors were found!\n\n"
112
+ puts "Did you run \`./emsdk_env.sh\` ?", "For help, check out the \"Getting Started\" guide on webassembly.org\n\n"
113
+ else
114
+ puts "\n👍 Everything looks good!\n\n"
115
+ end
116
+
117
+ end
118
+
119
+ # Check Command-line Arguments #################################################
120
+
121
+ usage = 'Ruby on WebAssembly'.bold + "\n
122
+ Usage: ruby-wasm <command> <options>
123
+ [-v|--version]
124
+
125
+ Summary of commands and options:
126
+ build <file.rb> Build a Ruby source file
127
+ --optimize Compile with all optimizations
128
+ serve Serve the build WebAssembly binary
129
+ -o|--open Open the default web browser after serving
130
+ doctor Check for problems with your WebAssembly toolchain
131
+ -v|--version Prints the installed version\n\n"
132
+
133
+ case ARGV[0]
134
+ when 'build'
135
+ if ARGV.delete '--optimize' then @optimize = true end
136
+ build ARGV[1]
137
+ when 'serve'
138
+ case ARGV[1]
139
+ when '-o', '--open'
140
+ serve(true)
141
+ else
142
+ serve(false)
143
+ end
144
+ when 'doctor'
145
+ doctor
146
+ when '-v', '--version'
147
+ puts WASM::VERSION
148
+ else
149
+ puts usage
150
+ end
@@ -0,0 +1,13 @@
1
+ MRuby::Build.new do |conf|
2
+ toolchain :gcc
3
+ conf.gembox 'default'
4
+ end
5
+
6
+ MRuby::CrossBuild.new('emscripten') do |conf|
7
+ toolchain :clang
8
+ conf.gembox 'default'
9
+ conf.cc.command = 'emcc'
10
+ conf.cc.flags = %W(-Os)
11
+ conf.linker.command = 'emcc'
12
+ conf.archiver.command = 'emar'
13
+ end
@@ -1,5 +0,0 @@
1
- require "wasm/version"
2
-
3
- module Wasm
4
- # Your code goes here...
5
- end
@@ -1,3 +1,5 @@
1
- module Wasm
2
- VERSION = "0.0.1"
1
+ # version.rb
2
+
3
+ module WASM
4
+ VERSION = '0.0.2'
3
5
  end
metadata CHANGED
@@ -1,76 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - Vikrant Chaudhary
7
+ - Tom Black
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.13'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.0'
55
- description:
56
- email:
57
- - nasa42@gmail.com
58
- executables: []
11
+ date: 2018-04-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Helping you get started with Ruby and WebAssembly
14
+ email: tom@blacktm.com
15
+ executables:
16
+ - ruby-wasm
59
17
  extensions: []
60
18
  extra_rdoc_files: []
61
19
  files:
62
- - ".gitignore"
63
- - ".travis.yml"
64
- - Gemfile
65
- - LICENSE.txt
66
- - README.md
67
- - Rakefile
68
- - bin/console
69
- - bin/setup
20
+ - assets/mruby/include/mrbconf.h
21
+ - assets/mruby/include/mruby.h
22
+ - assets/mruby/include/mruby/array.h
23
+ - assets/mruby/include/mruby/boxing_nan.h
24
+ - assets/mruby/include/mruby/boxing_no.h
25
+ - assets/mruby/include/mruby/boxing_word.h
26
+ - assets/mruby/include/mruby/class.h
27
+ - assets/mruby/include/mruby/common.h
28
+ - assets/mruby/include/mruby/compile.h
29
+ - assets/mruby/include/mruby/data.h
30
+ - assets/mruby/include/mruby/debug.h
31
+ - assets/mruby/include/mruby/dump.h
32
+ - assets/mruby/include/mruby/error.h
33
+ - assets/mruby/include/mruby/gc.h
34
+ - assets/mruby/include/mruby/hash.h
35
+ - assets/mruby/include/mruby/irep.h
36
+ - assets/mruby/include/mruby/istruct.h
37
+ - assets/mruby/include/mruby/khash.h
38
+ - assets/mruby/include/mruby/numeric.h
39
+ - assets/mruby/include/mruby/object.h
40
+ - assets/mruby/include/mruby/opcode.h
41
+ - assets/mruby/include/mruby/proc.h
42
+ - assets/mruby/include/mruby/range.h
43
+ - assets/mruby/include/mruby/re.h
44
+ - assets/mruby/include/mruby/string.h
45
+ - assets/mruby/include/mruby/throw.h
46
+ - assets/mruby/include/mruby/value.h
47
+ - assets/mruby/include/mruby/variable.h
48
+ - assets/mruby/include/mruby/version.h
49
+ - assets/mruby/libmruby.a
50
+ - assets/mruby_init.c
51
+ - assets/template.html
52
+ - bin/ruby-wasm
53
+ - build_config.rb
70
54
  - lib/wasm.rb
71
55
  - lib/wasm/version.rb
72
- - wasm.gemspec
73
- homepage: https://github.com/nasa42
56
+ homepage: https://github.com/blacktm/ruby-wasm
74
57
  licenses:
75
58
  - MIT
76
59
  metadata: {}
@@ -90,10 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
73
  version: '0'
91
74
  requirements: []
92
75
  rubyforge_project:
93
- rubygems_version: 2.5.1
76
+ rubygems_version: 2.7.6
94
77
  signing_key:
95
78
  specification_version: 4
96
- summary: Reserving for planned future use. But if my plans get stagnant (which from
97
- past experiences, has a probability of 92%), please contact me if you'd like to
98
- take this gem name.
79
+ summary: Ruby on WebAssembly
99
80
  test_files: []