ascode 0.2.2 → 0.2.3
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/README.md +3 -3
- data/lib/ascode/functions.md +3 -0
- data/lib/ascode/interpreter.rb +23 -8
- data/lib/ascode.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be5ffda76c2c8c88b0a89678a05730f7497fc8752208b3a41dc2523d81e62e46
|
4
|
+
data.tar.gz: a510b069ecb83cf610dd696c3d3b55abf761062f4296329b1ef012a67cfa21af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f18a849a4413d3182427a88f98da6736712443915a199e320ac857b79e2bb436807b977920a21cad5d527673382d8f79dc3f99df789955017a25d38e59b87214
|
7
|
+
data.tar.gz: 6a10e1ef202258ebb4414e922e4a97e69d286b8524c7c46cc34000650ecb78d4a7e611079aa09ae6c7224e38fdb8d34fd0ba0b67b786a53314adf1a1b78e7e72
|
data/README.md
CHANGED
@@ -27,9 +27,9 @@ At this moment, the only way to play with `ascode` is `irb`.
|
|
27
27
|
$ irb
|
28
28
|
irb(main):001:0> require 'ascode'
|
29
29
|
=> true
|
30
|
-
irb(main):002:0> Ascode.run
|
31
|
-
|
32
|
-
|
30
|
+
irb(main):002:0> Ascode.run '5*ê[Even~Odd]'
|
31
|
+
10
|
32
|
+
Even
|
33
33
|
```
|
34
34
|
|
35
35
|
### Features
|
data/lib/ascode/functions.md
CHANGED
@@ -3,6 +3,9 @@ Character|Name|`pop`s|`push`es|Description
|
|
3
3
|
`>`|`output`|`a`||`a` -> `stdout`
|
4
4
|
`<`|`input`||`a`|`stdin` -> `a`
|
5
5
|
`^`|`pop`|`a`||
|
6
|
+
`[`|`condition_begin`|`a`|| If `a` = `0`, `nil` or `false`, jump to `~`, or to `]` if `~` is not present
|
7
|
+
`~`|`condition_else`|||
|
8
|
+
`]`|`condition_end`|||
|
6
9
|
`+`|`plus`|`a`, `b`|`c`|`c` = `a` + `b`
|
7
10
|
`-`|`minus`|`a`, `b`|`c`|`c` = `a` - `b`
|
8
11
|
`/`|`divide`|`a`, `b`|`c`|`c` = `a` / `b`
|
data/lib/ascode/interpreter.rb
CHANGED
@@ -4,6 +4,8 @@ module Ascode
|
|
4
4
|
class Interpreter
|
5
5
|
def initialize(ast)
|
6
6
|
@ast = ast
|
7
|
+
@conditions = []
|
8
|
+
@cond_positions = []
|
7
9
|
|
8
10
|
@stack = []
|
9
11
|
end
|
@@ -11,13 +13,12 @@ module Ascode
|
|
11
13
|
def run
|
12
14
|
@ast.each do |action|
|
13
15
|
name = action[:action]
|
14
|
-
what = action[:what]
|
15
16
|
|
16
|
-
if
|
17
|
-
|
18
|
-
else
|
19
|
-
send(name)
|
17
|
+
if !@conditions.empty? && !%w[condition_else condition_end].include?(name)
|
18
|
+
next if @conditions[0] != @cond_positions[0]
|
20
19
|
end
|
20
|
+
|
21
|
+
name == 'push' ? push(action[:what]) : send(name)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -25,11 +26,11 @@ module Ascode
|
|
25
26
|
@stack.push what
|
26
27
|
end
|
27
28
|
|
28
|
-
def pop
|
29
|
+
def pop(ask = true)
|
29
30
|
value = @stack.pop
|
30
31
|
if value
|
31
32
|
value
|
32
|
-
|
33
|
+
elsif ask
|
33
34
|
input
|
34
35
|
@stack.pop
|
35
36
|
end
|
@@ -40,7 +41,21 @@ module Ascode
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def output
|
43
|
-
puts pop
|
44
|
+
puts pop(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
def condition_begin
|
48
|
+
condition = pop
|
49
|
+
@conditions.push(!(condition.nil? || !condition || condition.zero?))
|
50
|
+
@cond_positions.push true
|
51
|
+
end
|
52
|
+
|
53
|
+
def condition_else
|
54
|
+
@cond_positions[0] = false
|
55
|
+
end
|
56
|
+
|
57
|
+
def condition_end
|
58
|
+
@conditions.pop
|
44
59
|
end
|
45
60
|
|
46
61
|
def plus
|
data/lib/ascode.rb
CHANGED