ucisc 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: af46f976c69b0844dc290a6d7addb29f29b03077009152eaaca5a3ae4f800ef3
4
+ data.tar.gz: 1ab1c92750ff4f8de30e416b9cc53a8321e1dfb510fdf1e9f5ea6287fbd6c954
5
+ SHA512:
6
+ metadata.gz: 2b04fde677c94ba3b1c97fe0ed6a255212c8f77a24e4652d7daa0eb8fa7438ce308b9efb2d3940054ca593ca5cf56fdbfe4da5c2a55841b5f76f8e3f3bdefe2f
7
+ data.tar.gz: 875fcca7db2a73fa62eb16611b5d262ecd0eecc816a3ee4141c81ad338f09eece592afab49bc0bd7d1e976eb3fbc8dfae7a4522da7ef263f647a5d6946239fe4
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.byebug_history
10
+ *.swp
11
+ *~
12
+
13
+ # video system create screen.png, ignore it
14
+ screen.png
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at robert at grokthiscommunity.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in micro_cisc.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem "byebug"
9
+
10
+ # Devices
11
+ gem "tty-screen"
12
+
13
+ # Gems for the graphics, going as lightweight, few dependencies as possible
14
+ gem "gtk2"
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ucisc (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ atk (3.4.1)
10
+ glib2 (= 3.4.1)
11
+ byebug (11.0.1)
12
+ cairo (1.16.5)
13
+ native-package-installer (>= 1.0.3)
14
+ pkg-config (>= 1.2.2)
15
+ cairo-gobject (3.4.1)
16
+ cairo (>= 1.16.2)
17
+ glib2 (= 3.4.1)
18
+ gdk_pixbuf2 (3.4.1)
19
+ gio2 (= 3.4.1)
20
+ gio2 (3.4.1)
21
+ gobject-introspection (= 3.4.1)
22
+ glib2 (3.4.1)
23
+ native-package-installer (>= 1.0.3)
24
+ pkg-config (>= 1.3.5)
25
+ gobject-introspection (3.4.1)
26
+ glib2 (= 3.4.1)
27
+ gtk2 (3.4.1)
28
+ atk (= 3.4.1)
29
+ gdk_pixbuf2 (= 3.4.1)
30
+ pango (= 3.4.1)
31
+ minitest (5.14.0)
32
+ native-package-installer (1.0.9)
33
+ pango (3.4.1)
34
+ cairo-gobject (= 3.4.1)
35
+ gobject-introspection (= 3.4.1)
36
+ pkg-config (1.4.1)
37
+ rake (12.3.3)
38
+ tty-screen (0.8.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ byebug
45
+ gtk2
46
+ minitest (~> 5.0)
47
+ rake (~> 12.0)
48
+ tty-screen
49
+ ucisc!
50
+
51
+ BUNDLED WITH
52
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Robert Butler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,217 @@
1
+ # MicroCisc
2
+
3
+ Sketch Emulator/VM implementation for https://github.com/grokthis/ucisc
4
+
5
+ ## Installation
6
+
7
+ Prerequisites: Bundler 2
8
+
9
+ ```
10
+ $ git clone https://github.com/grokthis/ucisc-ruby
11
+ $ cd ucisc-ruby
12
+ $ bundle install
13
+ ```
14
+
15
+ Eventually, once the gem stabilizes a bit, I will host it on
16
+ rubygems. I don't want to do that until the code stabilizes a
17
+ bit and a release cadence doesn't get in the way. In the mean
18
+ time, you can install the gem locally by doing:
19
+
20
+ ```
21
+ bundle exec rake install
22
+ ```
23
+
24
+ This will let you simply run `ucisc` as a command assuming your
25
+ path is setup to load gem binaries.
26
+
27
+ This gem is only ever intended to be a prototype compiler and
28
+ VM. It's useful to get uCISC code running anywhere ruby can run
29
+ but ultimately the goal is to get it self bootstrapping. It will
30
+ always need a VM of sorts as the instruction set is fundamentally
31
+ different from x86, ARM or others, but I intend to write a better
32
+ performing VM in SubX or Mu. That said, this project will likely
33
+ be around a while.
34
+
35
+ ## Usage
36
+
37
+ The `ucisc` command combines the compilation and VM execution.
38
+
39
+ ```
40
+ # Run the factorial example
41
+ $ exe/ucisc examples/fib.ucisc
42
+ ```
43
+
44
+ You will get 3 outputs:
45
+ 1. Line numbered output with instructions encoded (label values are all 0)
46
+ 2. Final instruction output with address numbers and final label substitutions
47
+ 3. Instruction by instruction execution details, including the result "value"
48
+
49
+ This code:
50
+
51
+ ```
52
+ ...
53
+ 13: Entry:
54
+ 14: # Initialize the stack register to 0x0000, decrement on push will change to 0xFFFF
55
+ 15: 0/load 0xFFFF to sp/ 4.val 0.imm 1.reg
56
+ 16:
57
+ 17: (1.mem fib 4.val 8.imm)
58
+ ...
59
+ ```
60
+ Gets translated into these instructions:
61
+
62
+ ```
63
+ 13: Entry
64
+ 15: 0x7600 0/load 0xFFFF to sp/ 4.val 0.imm 1.reg
65
+ 17: 0x6443 0 0.reg 3.imm 1.mem 1.push # (1.mem fib 4.val 8.imm)
66
+ 17: 0x6648 0 4.val 8.imm 1.mem 1.push # (1.mem fib 4.val 8.imm)
67
+ 17: 0x6000 0 0.reg fib.disp 0.reg # (1.mem fib 4.val 8.imm)
68
+ ...
69
+ ```
70
+
71
+ Note: as you can see in the example above, the function call
72
+ gets added to each generated push and call command it generates.
73
+
74
+ This is the preliminary compile step and you can see the line
75
+ number, compiled instruction in hex and the original line.
76
+ Comment lines and blank lines are ignored. Any labels evaluate
77
+ to 0x0000 at this stage. See line 22 above for example.
78
+
79
+ After line numbers, the second pass produces the binary output
80
+ after subtituting the label offset calculations. You get
81
+ something like this:
82
+
83
+ ```
84
+ 0: 0x763F 0/load 0xFFFF to sp/ 4.val -1.imm 5.reg
85
+ 2: 0x6443 0 0.reg 6.imm 1.mem 1.inc 3.eff # (1.mem fib 4.val 8.imm)
86
+ 4: 0x6648 0 4.val 8.imm 1.mem 1.inc 3.eff # (1.mem fib 4.val 8.imm)
87
+ 6: 0x6002 0 0.reg fib.disp 0.reg 0.inc 3.eff # (1.mem fib 4.val 8.imm)
88
+ ...
89
+ ```
90
+
91
+ The line numbers are now the hex memory address of the
92
+ instruction followed by the final hex instruction code and the
93
+ original statement that produced it.
94
+
95
+ The vm will then execute the code. Any instruction that sets
96
+ the PC address to 0x0000 will cause the VM to break execution
97
+ and give you a prompt.
98
+
99
+ ```
100
+ Running program with 60 bytes
101
+ Starting program... (enter to continue)
102
+ 0000 0x0 4.val 0x0 1.reg 3.eff 0.push # value: 0, stored > _
103
+ ```
104
+ You can see the compiled program is 60 bytes total including any
105
+ data and instructions encoded. The program is loaded and ready to
106
+ execute at this point. The last line shows the instruction that is
107
+ about to be executed. Press [enter] to continue and run the
108
+ program to completion.
109
+
110
+ ```
111
+ Breaking on jump to 0x0000...
112
+ Finished 929 instructions in 0.001835s
113
+ 0000 0x0 4.val 0x0 1.reg 3.eff 0.push # value: 0, stored > _
114
+ ```
115
+ When the program jumps to address 0x0000, the program pauses. In
116
+ this case, 929 instructions were executed in 0.001835s. Performance
117
+ will depend on your ruby version, computer performance and program.
118
+ I've seen up to 6x the performance of the 8-bit computers of the
119
+ early 80's when running on modern CPU's, so that gives you an idea
120
+ of what types of algorithms you can run.
121
+
122
+ At the prompt, you can do the following:
123
+
124
+ * Type "exit" - exits the VM
125
+ * Type "break" - opens the ruby debugger. You can inspect the
126
+ memory and registers from here if desired.
127
+ * "next", "n" - Turn debug mode on and step to the next instruction.
128
+ * "continue", "c" - Turn debug mode off and continue execution
129
+ * Simply hit "enter" and the execution will continue. If in debug
130
+ mode, it will execute the instruction and move to the next. If
131
+ not debugging it will continue running until the next jump 0x0000.
132
+
133
+ When in the ruby debugger, you can do the following to look at
134
+ the stack value:
135
+
136
+ ```
137
+ # Load a value from memory; returns 16-bit word
138
+ # Returns nil if the address is out of memory bounds
139
+ load(address)
140
+
141
+ # Look at the contents of a register; number is 1-3
142
+ # Returns 16-bit register value
143
+ register(number)
144
+
145
+ # PC contents
146
+ pc
147
+
148
+ # Flags register
149
+ flags
150
+
151
+ # Values are show in decimal, conver to hex with:
152
+ pc.to_s(16).upcase
153
+
154
+ # To continue execution (any byebug commands are available)
155
+ # https://github.com/deivid-rodriguez/byebug
156
+ continue
157
+
158
+ # Combine as needed
159
+ # Look at the stack: load the address in r1
160
+ load(register(1)).to_s(16).upcase
161
+ ```
162
+
163
+ ## Debugging
164
+
165
+ You can debug your code by doing the following:
166
+
167
+ ```
168
+ # Debug the factorial example
169
+ $ exe/ucisc examples/factorial.ucisc -d
170
+ ```
171
+
172
+ Instead of simply executing all the code, the debugger will
173
+ pause after each instruction:
174
+
175
+ ```
176
+ 0000 0x0 4.val 0x0 1.reg 3.eff 0.push # value: 0, stored >
177
+ 0001 0x0 0.reg 0x3 1.mem 3.eff 1.push # value: 4, stored >
178
+ 0002 0x0 4.val 0x8 1.mem 3.eff 1.push # value: 8, stored >
179
+ 0003 0x0 0.reg 0x2 0.reg 3.eff 0.push # value: 5, stored >
180
+ 0005 0x202 1.mem 1.mem 0.inc 1.sign 3.eff # arg1: 8, arg2: 8, result 8, not stored >
181
+ 0006 0x0 0.reg 0x2 0.reg 1.eff 0.push # value: 8, stored >
182
+ 0008 0x0 4.val 0x1 2.reg 3.eff 0.push # value: 1, stored >
183
+ 0009 0x20c 2.reg 1.mem 0.inc 1.sign 3.eff # arg1: 1, arg2: 8, result 7, not stored >
184
+ 000a 0x0 0.reg 0x2 0.reg 1.eff 0.push # value: 12, stored >
185
+ 000c 0x0 1.mem 0x0 1.mem 3.eff 1.push # value: 8, stored > _
186
+ ```
187
+
188
+ Notice the prompt after each instruction. The same break, exit
189
+ or "enter" options are available as described above. The output
190
+ at each line is the uCISC equivalent of what was executed.
191
+ After the comment, the value result and whether or not the value
192
+ was stored is indicated. ALU instructions also include both args
193
+ in the comment.
194
+
195
+ Note the 4-digit hex address to the left. That is the address
196
+ of the instruction that was executed and will match the compiled
197
+ output (assuming your code doesn't overwrite itself or load code
198
+ to other memory locations).
199
+
200
+ ## Development
201
+
202
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
203
+
204
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
205
+
206
+ ## Contributing
207
+
208
+ Bug reports and pull requests are welcome on GitHub at https://github.com/grokthis/micro_cisc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/grokthis/micro_cisc/blob/master/CODE_OF_CONDUCT.md).
209
+
210
+
211
+ ## License
212
+
213
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
214
+
215
+ ## Code of Conduct
216
+
217
+ Everyone interacting in the MicroCisc project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/grokthis/micro_cisc/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "micro_cisc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here