fam 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fam +12 -2
  3. data/lib/fam.rb +23 -1
  4. data/lib/fam/syntax/lexer.rb +4 -5
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80a521187255f27791f45b197a66fa69160a5d37cb2d6599a59d7001fd2b86ff
4
- data.tar.gz: 25f69d87e3148bc616964bcc15287c5b6fd6406548251a730a5b48abaddef081
3
+ metadata.gz: 48e083defa9264bec1a8aa528283008c7ac5041b88da8ef8eb0afb02c3748d13
4
+ data.tar.gz: f96c773b8fb78d623213df185831f1598e463f5a8ba899b1bda2fc6411062a1d
5
5
  SHA512:
6
- metadata.gz: 570f5e1160997bdcd2f8e9aa15d81068cef6b5bc94ec2483715baa3d25b5af90840375d2ef546a793aad728ce8e89a93224a70fc71ebf5af657759160de5bb78
7
- data.tar.gz: 7675fc3184c4210a21f47cc2a35991a40faccbd1bd9f1953ab2d8a8ca3da258511b305d45b73306b1c9a3a0223d5a1353439bd64a0c82d99222eff798d699e61
6
+ metadata.gz: 23a04cb33765547dd9abca66c77135f05b3ee312aaa355c85d5814d6424fdbdd677f8765b480bf3520fb48d247a703297ff3f4513f79c30d4d47c8439fcd4b55
7
+ data.tar.gz: 6e6556694a26ba109824cc1f7deecd942841688d178995ff680eb0cbeb6ca002c19136069cd5f550f7bdd0f3e42bf1496975daefbe4d4cb4d98b9fe2ecc435d3
data/bin/fam CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'fam'
4
4
 
5
- $VERBOSE = false
5
+ $VERBOSE = true
6
6
  $CLOCK = $VERBOSE ? 20 : Float::INFINITY
7
7
 
8
8
  file_names = ARGV.select { |file| file.include? '.fam'}
9
- lexed = FAM::Syntax::Lexer.lex file_names[-1]
9
+ lexed = FAM::Syntax::Lexer.lex File.read file_names[-1]
10
10
  puts lexed if $VERBOSE
11
11
  puts if $VERBOSE
12
12
 
@@ -21,3 +21,13 @@ puts if $VERBOSE
21
21
  CPU.run AST do |pc|
22
22
  puts "Program counter: #{pc}" if $VERBOSE
23
23
  end
24
+
25
+
26
+ #==== Shortened built in method: ====#
27
+
28
+ #file_names = ARGV.select { |file| file.include? '.fam'}
29
+ #FAM.run File.read(file_names[-1]), :allocate => '100B' do |ram, pc, registers|
30
+ # puts "RAM:\n#{ram}"
31
+ # puts "PC: #{pc}"
32
+ # puts "REG: #{registers}"
33
+ #end
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 => 1 }
8
+ VERSIONS = { :major => 0, :minor => 0, :tiny => 2 }
9
9
 
10
10
  def self.version *args
11
11
  VERSIONS.flatten.select.with_index { |val, i| i.odd? }.join '.'
@@ -14,3 +14,25 @@ end
14
14
 
15
15
  Dir["#{File.dirname __FILE__}/fam/*.rb"].each { |f| require f }
16
16
  Dir["#{File.dirname __FILE__}/fam/**/*.rb"].each { |f| require f }
17
+
18
+ module FAM
19
+ def self.run string, allocate: '200B', clock: 6, verbose: false, &block
20
+ $VERBOSE = verbose
21
+ $CLOCK = clock
22
+
23
+ lexed = Syntax::Lexer.lex string
24
+ puts lexed if $VERBOSE
25
+ puts if $VERBOSE
26
+ parsed = Syntax::Parser.parse lexed.tokens
27
+ tree = parsed.ast
28
+ pp tree if $VERBOSE
29
+ ram = Machine::RAM.new allocate
30
+ cpu = Machine::CPU.new ram
31
+ puts if $VERBOSE
32
+ cpu.run tree do |pc|
33
+ puts "Program counter: #{pc}" if $VERBOSE
34
+ yield cpu.ram, pc, cpu.registers if block_given?
35
+ end
36
+ cpu
37
+ end
38
+ end
@@ -4,20 +4,19 @@ module FAM::Syntax
4
4
  class Lexer
5
5
  attr_reader :tokens
6
6
 
7
- def initialize io_file
8
- @file_name = io_file
7
+ def initialize string
8
+ @raw = string
9
9
  @tokens = TokenStream.new
10
10
  end
11
11
 
12
- def self.lex io_file
13
- obj = self.new io_file
12
+ def self.lex string
13
+ obj = self.new string
14
14
  obj.lexer
15
15
  obj
16
16
  end
17
17
 
18
18
  def lexer
19
19
  puts "Lexing..." if $VERBOSE
20
- @raw = File.read @file_name
21
20
  @raw << EOF unless @raw[-1] == EOF
22
21
 
23
22
  loc = {:line => 1, :col => 1}
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.1
4
+ version: 0.0.2
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-13 00:00:00.000000000 Z
11
+ date: 2018-03-14 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
@@ -31,7 +31,7 @@ files:
31
31
  - lib/fam/syntax/tokens.rb
32
32
  homepage: https://github.com/Demonstrandum/FAM
33
33
  licenses:
34
- - GPL-3.0
34
+ - GPL-2.0
35
35
  metadata: {}
36
36
  post_install_message:
37
37
  rdoc_options: []