fam 0.1.0 → 0.1.1
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 +4 -4
- data/DOC.md +109 -0
- data/README.md +100 -1
- data/lib/fam.rb +2 -2
- data/lib/fam/syntax/tokens.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4dfcc52fdeefad0727862860ec59ad2ff5d4609d82d998383e0f46e25bef721
|
4
|
+
data.tar.gz: ce91c0ca5e16a70c65c68054f4993ac5a9e2fee57d3c928a7d6f441b06cb1678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a001bae8abf643e6c14d53e9346609d89ebfae9c6b8acd5361bbae4b6c33002c8aae60c7bd647cf82938ddb138257f7b3ec4722202b111d3770c807bf2b1a7d
|
7
|
+
data.tar.gz: 1442bf6cb3a042383ce68ee66cb681f6efce1a6db6b56601f5966c098420c1531f8562131361624f2d21ac8d93c30574686de52ae2d121c05a1b841260601d53
|
data/DOC.md
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Documentation
|
2
|
+
> Documentation, quite incomplete
|
3
|
+
|
4
|
+
## Basic Syntax
|
5
|
+
The syntax is extremely simplistic.
|
6
|
+
|
7
|
+
The language consists mostly of labels, opcodes and operands.
|
8
|
+
|
9
|
+
### Identifiers
|
10
|
+
Identifiers are just names for things, such as variables, labels, etc.
|
11
|
+
|
12
|
+
They may consist of any number of underscores (`_`) anywhere in the name and any number of Latin alphabet letters. Numbers may only exist in identifiers only if preceded by one or more letters or underscores.
|
13
|
+
|
14
|
+
Identifiers have the following regular expression:
|
15
|
+
|
16
|
+
`[A-Za-z_]([A-Za-z0-9_]+)?`
|
17
|
+
|
18
|
+
### Labels
|
19
|
+
A label is defined by an identifier (a name) immediately followed by a colon, e.g.
|
20
|
+
```nasm
|
21
|
+
LABEL_NAME:
|
22
|
+
!! Code goes here.
|
23
|
+
!! ...
|
24
|
+
```
|
25
|
+
A label if not jumped to by a `GOTO`, will be entered automatically, when that happens the special `_BACK` ident will be set to that label.
|
26
|
+
|
27
|
+
Labels are defined as: `[a-zA-Z_]([a-zA-Z0-9_]+)?:`
|
28
|
+
|
29
|
+
### Comments
|
30
|
+
Single-line comments must start with an `!` (although it looks neater using a double exclamation-mark: `!!`), and are ended, naturally, by a new line.
|
31
|
+
|
32
|
+
e.g.
|
33
|
+
```nasm
|
34
|
+
SUB 4 : &ACC !! Hi, I'm a comment
|
35
|
+
MOD 265 : &ACC
|
36
|
+
```
|
37
|
+
|
38
|
+
Multi-line comments start by a `{{` and are ended by a `}}`.
|
39
|
+
|
40
|
+
e.g.
|
41
|
+
```nasm
|
42
|
+
DATA x : -0xff
|
43
|
+
{{ I can be one line }}
|
44
|
+
|
45
|
+
{{
|
46
|
+
Here, multiple lines
|
47
|
+
are commented out.
|
48
|
+
}}
|
49
|
+
```
|
50
|
+
|
51
|
+
### Numerics
|
52
|
+
Numerics must always start with either a number, or a sign (`+`/`-`). Hexadecimal and duodecimal (binary) support also exists; this is achieved by prepending a `0x` (hexadecimal) or `0b` (binary) prefix to the number.
|
53
|
+
|
54
|
+
Normal base-10 numbers can have an `e` (scientific notation for 10 to the power of some number).
|
55
|
+
|
56
|
+
Numbers can be defined through the regular expression:
|
57
|
+
```
|
58
|
+
(\-|\+)??((?=0x|0b)([0-9A-Za-z]+)|([0-9]+((e(\-|\+)?[0-9]+)?)))
|
59
|
+
```
|
60
|
+
|
61
|
+
Some examples of numbers:
|
62
|
+
```
|
63
|
+
!! Scientific notation
|
64
|
+
12e1 !! becomes 120
|
65
|
+
12e+1 !! becomes 120
|
66
|
+
-23e+3 !! becomes -23000
|
67
|
+
5000e-3 !! becomes 5
|
68
|
+
|
69
|
+
!! Hexadecimal
|
70
|
+
0xff4a !! becomes 65354
|
71
|
+
-0xff4a !! becomes -65354
|
72
|
+
|
73
|
+
!! Binary
|
74
|
+
0b010110 !! becomes 184615184
|
75
|
+
-0b101 !! becomes -5
|
76
|
+
```
|
77
|
+
|
78
|
+
### Registers
|
79
|
+
Registers in the language, are names for the registers in the CPU. Registers must start with an `&` followed by any combination of lower and uppercase Latin letters, and digits.
|
80
|
+
|
81
|
+
Regular expression: `&[a-zA-Z0-9]+`
|
82
|
+
|
83
|
+
### Addresses
|
84
|
+
Addresses address locations in memory, these address numbers range from `0` to your chosen allocated amount, minus one.
|
85
|
+
|
86
|
+
Regular expression: `@[0-9]+`
|
87
|
+
|
88
|
+
### Opcodes
|
89
|
+
#### `:HALT`
|
90
|
+
#### `:ALIAS`
|
91
|
+
**Not implemented.**
|
92
|
+
#### `:DATA`
|
93
|
+
#### `:STORE`
|
94
|
+
#### `:LOAD`
|
95
|
+
#### `:GOTO`
|
96
|
+
#### `:DATA`
|
97
|
+
#### `:EQUAL`
|
98
|
+
#### `:MORE`
|
99
|
+
#### `:LESS`
|
100
|
+
#### `:ADD`
|
101
|
+
#### `:SUB`
|
102
|
+
#### `:MUL`
|
103
|
+
#### `:DIV`
|
104
|
+
#### `:MOD`
|
105
|
+
#### `:SLEEP`
|
106
|
+
**Not implemented.**
|
107
|
+
#### `:IN`
|
108
|
+
#### `:OUT`
|
109
|
+
#### `:ASCII`
|
data/README.md
CHANGED
@@ -1,2 +1,101 @@
|
|
1
1
|
# FAM
|
2
|
-
A very
|
2
|
+
> A very **<u>F</u>ake** **<u>A</u>ssembly**(_-ish_ language) **<u>M</u>achine**, parser and _interpreter_.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
```shell
|
6
|
+
gem install fam
|
7
|
+
```
|
8
|
+
## Documentation
|
9
|
+
See this repository's `DOC.md` file.
|
10
|
+
|
11
|
+
## Examples
|
12
|
+
Examples can be found in scarce supply, in the `example` folder in this repository.
|
13
|
+
|
14
|
+
Some examples:
|
15
|
+
```nasm
|
16
|
+
STORE 55 : @0
|
17
|
+
DATA dyn : 0b01101 !! Dynamic memory allocation,
|
18
|
+
LOAD -0xf : &DAT !! finds available memory location.
|
19
|
+
LOAD &DAT : &ACC
|
20
|
+
|
21
|
+
LOOP:
|
22
|
+
ADD 1 : &ACC
|
23
|
+
OUT &ACC
|
24
|
+
STORE &ACC : dyn
|
25
|
+
|
26
|
+
EQUAL &ACC : 30
|
27
|
+
| GOTO END
|
28
|
+
| GOTO LOOP
|
29
|
+
|
30
|
+
END: HALT 0
|
31
|
+
```
|
32
|
+
```nasm
|
33
|
+
GOTO INCR
|
34
|
+
OUT &ACC
|
35
|
+
HALT 0
|
36
|
+
|
37
|
+
INCR:
|
38
|
+
ADD 1 : &ACC
|
39
|
+
GOTO _BACK
|
40
|
+
|
41
|
+
{{ _BACK works by jumping to just after the last GOTO
|
42
|
+
statement, or jumping to the last label that was passed
|
43
|
+
without GOTOing to it. }}
|
44
|
+
```
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
Current terminal usage is very simplistic.
|
48
|
+
Simply, write `fam` and the file name _ensuring_ the file name ends in `.fam`.
|
49
|
+
|
50
|
+
e.g.
|
51
|
+
```shell
|
52
|
+
fam some_file.fam
|
53
|
+
```
|
54
|
+
by default, the program is extremely verbose.
|
55
|
+
To make any changes it is recommended you write a Ruby script to deal with it yourself.
|
56
|
+
|
57
|
+
e.g.
|
58
|
+
```ruby
|
59
|
+
program = <<EOF
|
60
|
+
IN &DAT
|
61
|
+
ADD 10 : &DAT
|
62
|
+
OUT &DAT
|
63
|
+
|
64
|
+
HALT 0
|
65
|
+
EOF
|
66
|
+
|
67
|
+
# PROGRAM STRING, ALLOC, CLOCK, VERBOSE?
|
68
|
+
# All except the `program string' are optional,
|
69
|
+
# block is not required either.
|
70
|
+
FAM.run program, '200B', 6, true do |ram, pc, regs|
|
71
|
+
puts "RAM:\n#{ram.to_a}"
|
72
|
+
puts "REGISTERS:"
|
73
|
+
regs.each { |name, value| puts "#{name} => #{value}" }
|
74
|
+
|
75
|
+
puts "PROGRAM COUNTER: #{pc}"
|
76
|
+
end
|
77
|
+
```
|
78
|
+
in a more verbose manner:
|
79
|
+
```ruby
|
80
|
+
require 'fam'
|
81
|
+
|
82
|
+
$VERBOSE = true
|
83
|
+
$CLOCK = $VERBOSE ? 20 : Float::INFINITY
|
84
|
+
|
85
|
+
file_names = ARGV.select { |file| file.include? '.fam'}
|
86
|
+
lexed = FAM::Syntax::Lexer.lex File.read file_names[-1]
|
87
|
+
|
88
|
+
parsed = FAM::Syntax::Parser.parse lexed.tokens
|
89
|
+
AST = parsed.ast
|
90
|
+
|
91
|
+
MEM = FAM::Machine::RAM.new '100B' # Alloc 100 bytes
|
92
|
+
CPU = FAM::Machine::CPU.new MEM
|
93
|
+
|
94
|
+
CPU.run AST do |pc|
|
95
|
+
# Do something every `clock-cycle'
|
96
|
+
puts "Program counter: #{pc}"
|
97
|
+
end
|
98
|
+
```
|
99
|
+
A `#step(syntax_tree)` method is also available for the CPU class.
|
100
|
+
|
101
|
+
for auto-generated documentation, see: [rubydoc.info/gems/fam/](http://www.rubydoc.info/gems/fam/FAM/Machine/CPU)
|
data/lib/fam.rb
CHANGED
@@ -5,10 +5,10 @@ class Object
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module FAM
|
8
|
-
VERSIONS = { :major => 0, :minor => 1, :tiny =>
|
8
|
+
VERSIONS = { :major => 0, :minor => 1, :tiny => 1 }
|
9
9
|
|
10
10
|
def self.version *args
|
11
|
-
VERSIONS.
|
11
|
+
VERSIONS.values.join '.'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/lib/fam/syntax/tokens.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Demonstrandum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-27 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
|
@@ -41,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 2.
|
44
|
+
version: 2.5.1
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
51
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.7.
|
52
|
+
rubygems_version: 2.7.3
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Fake Assembly(ish) Machine
|