fam 0.0.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48e083defa9264bec1a8aa528283008c7ac5041b88da8ef8eb0afb02c3748d13
4
- data.tar.gz: f96c773b8fb78d623213df185831f1598e463f5a8ba899b1bda2fc6411062a1d
3
+ metadata.gz: e38f107dfcb9efdeb43affd220b7ef40b662ddf35f21b070753fecc6bf953d25
4
+ data.tar.gz: 596acf48da4a1c333ad15b1ab8b4032f75ed02d8709d69dfca4a5f679807277f
5
5
  SHA512:
6
- metadata.gz: 23a04cb33765547dd9abca66c77135f05b3ee312aaa355c85d5814d6424fdbdd677f8765b480bf3520fb48d247a703297ff3f4513f79c30d4d47c8439fcd4b55
7
- data.tar.gz: 6e6556694a26ba109824cc1f7deecd942841688d178995ff680eb0cbeb6ca002c19136069cd5f550f7bdd0f3e42bf1496975daefbe4d4cb4d98b9fe2ecc435d3
6
+ metadata.gz: dfcc9df73fe1d1dbd3c4d5871392da853801db10bef0fd4972a0ea2a48224c36c7f16d755509df56bfcc38b15b9b12060af80798d6d945220cd7544180ab3165
7
+ data.tar.gz: 820eedd878734ceaca7bdc7e994f7649c18c09f2c62f5e6fc1365e9a50bf0605fc05675f1a0122eeb82d4876efaa83173a595ef8550588cfa5f2de2b5d6041ac
data/lib/fam.rb CHANGED
@@ -5,7 +5,7 @@ class Object
5
5
  end
6
6
 
7
7
  module FAM
8
- VERSIONS = { :major => 0, :minor => 0, :tiny => 2 }
8
+ VERSIONS = { :major => 0, :minor => 1, :tiny => 0 }
9
9
 
10
10
  def self.version *args
11
11
  VERSIONS.flatten.select.with_index { |val, i| i.odd? }.join '.'
@@ -5,6 +5,8 @@ module FAM::Machine
5
5
  class CPU
6
6
  include FAM::Syntax
7
7
  attr_reader :ram, :registers, :memory_aliases, :labels
8
+ attr_reader :inputting, :outputting, :halted
9
+ attr_reader :output
8
10
 
9
11
  def initialize ram
10
12
  @ram = ram
@@ -18,6 +20,10 @@ module FAM::Machine
18
20
  @labels = Hash.new
19
21
  @last_jump = nil
20
22
  @back_index = 0
23
+ @tree_index = -1
24
+ @halted = false
25
+ @outputting = @inputting = false
26
+ @output = String.new
21
27
  end
22
28
 
23
29
  def self.quick_run ram, parsed, &block
@@ -34,7 +40,6 @@ module FAM::Machine
34
40
  @block = block if block_given?
35
41
  @parsed = parsed
36
42
 
37
- @tree_index = -1
38
43
  while @tree_index < parsed.tree.size
39
44
  @tree_index += 1
40
45
 
@@ -48,7 +53,21 @@ module FAM::Machine
48
53
  end
49
54
  end
50
55
 
56
+ def step parsed
57
+ @parsed = parsed
58
+ return {:state => 'done'} if @tree_index >= parsed.tree.size || @halted
59
+ @tree_index += 1
60
+ node = parsed[@tree_index]
61
+ status = execute node
62
+ if status == :STOP
63
+ @halted = true
64
+ return {:state => 'done'}
65
+ end
66
+ {:state => 'running', :input => @inputting, :output => @outputting}
67
+ end
68
+
51
69
  def execute node
70
+ @outputting = @inputting = false
52
71
  @registers[:PC] = @tree_index
53
72
  @block.call @registers[:PC] unless @block.nil?
54
73
  case node
@@ -98,8 +117,9 @@ module FAM::Machine
98
117
  when AST::InNode
99
118
  @registers[node.register.register.to_sym] = cpu_input
100
119
  when AST::OutNode, AST::AsciiNode
120
+ @outputting = true
101
121
  value = get_value node, node.value
102
- cpu_output value, (node.base_name == 'OutNode' ? :PLAIN : :ASCII)
122
+ @output = cpu_output(value, (node.base_name == 'OutNode' ? :PLAIN : :ASCII))
103
123
  when AST::SubNode, AST::AddNode, AST::MulNode, AST::DivNode, AST::ModNode
104
124
  value = get_value node, node.value
105
125
  ExpectedNode 'REGISTER', node.to unless node.to.base_name == 'RegisterNode'
@@ -143,7 +163,8 @@ module FAM::Machine
143
163
  end
144
164
 
145
165
  def cpu_output out, ascii=:PLAIN # Ment to be changed
146
- puts "OUTPUT: #{ascii != :PLAIN ? out.chr : out }"
166
+ show = ascii == :PLAIN ? out.to_s : out.chr
167
+ puts "OUTPUT: #{show}"
147
168
  end
148
169
 
149
170
  private def get_value super_value, value_node
@@ -161,12 +182,12 @@ module FAM::Machine
161
182
  end
162
183
  end
163
184
 
164
- private def UnexpectedNode node, sub_node
185
+ def UnexpectedNode node, sub_node
165
186
  print "\n" * (@ram.to_s.count("\n") + 1) if $VERBOSE
166
187
  abort ("Unexpected Node, you've given `#{sub_node.base_name}` AST::to Node: `#{node.base_name}`?").red.bold
167
188
  end
168
189
 
169
- private def ExpectedNode expect, got
190
+ def ExpectedNode expect, got
170
191
  print "\n" * (@ram.to_s.count("\n") + 1) if $VERBOSE
171
192
  abort ("Expected: `#{expect}`, but insted got: `#{got}`").red.bold
172
193
  end
@@ -17,7 +17,7 @@ module FAM::Machine
17
17
  when Numeric
18
18
  alloc = size
19
19
  when String
20
- suffix = size.upcase[/[A-Z]+/]
20
+ suffix = size.upcase[/[A-Z]+/] || ''
21
21
  suffix = 'kB' if suffix == 'KB'
22
22
  unless suffix.empty?
23
23
  alloc = size[/[0-9]+/].to_i * SIZES[suffix.to_sym]
@@ -39,6 +39,10 @@ module FAM::Machine
39
39
  @array[i] = value
40
40
  end
41
41
 
42
+ def to_a
43
+ @array
44
+ end
45
+
42
46
  def to_s
43
47
  result = String.new
44
48
  width = %x{ tput cols }.to_i
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demonstrandum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-14 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very watered down language ment to look like an assembly language.
14
14
  email: knutsen@jetspace.co