ascode 0.7.3 → 0.7.4

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: 2e4dad30f3c635d048e0a0c55998dced7d3b19ef3493207935f729ff17a977ca
4
- data.tar.gz: e6165cc228e8e8d520c1915ffe05cf478546dd9b75a55768e51e240a618177dd
3
+ metadata.gz: 75b9614d0f7afda646d8b000aa8ce1280ec964142644005940a83783534ff2a3
4
+ data.tar.gz: 590186bd0ea7102961238075d3f7518ee2afd3bdf1eecb0f70c86eb76ccc2792
5
5
  SHA512:
6
- metadata.gz: 055abbb6b5491616412ceb47abeb9734dc271f37c4cc11a1aed43477053f3e1c8c6a51a97cb1804568baeee096e824090eead4c6f327d014927766f6c24f44d2
7
- data.tar.gz: 8e4582ac30a1d020e0a7875d2911f7b4959802b8b5e51f1a26180c27ec1529de7c9d35e18c6342344241759f2e3d2581d08bda9525ffb0cf889f09671369e8a7
6
+ metadata.gz: 8e3d1e1482766751d880e650cb8ec65488340e502baf631cde0a6832429ee40b44b50b925d94270a65764cc0caeee2773f0e569d723d32082b374596d150d87c
7
+ data.tar.gz: 5ab43c64aa85ef777703e3b5b19843d431b65e60707f892137ee1dc6628895cefb35d1ef6bfd31bdaa12ff402acee78c5e59009a98899bbf498fa709f912655b
data/README.md CHANGED
@@ -18,8 +18,8 @@ gem install ascode
18
18
 
19
19
  ###### Run
20
20
 
21
- > Function reference is available in [`lib/ascode/functions.md
22
- `](https://github.com/sudoio/ascode/blob/master/lib/ascode/functions.md).
21
+ > Function reference is available in [`docs/functions.md
22
+ `](https://github.com/sudoio/ascode/blob/master/docs/functions.md).
23
23
 
24
24
  ```bash
25
25
  ascode 'your code here'
data/ascode.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ascode"
3
+ s.authors = ["Artem Varaksa"]
4
+
5
+ s.version = "0.7.4"
6
+ s.date = Time.now.strftime("%Y-%m-%d")
7
+
8
+ s.summary = "[β] Esoteric golfing language"
9
+ s.description =
10
+ "Esoteric golfing language. In active development, so behavior may be changed without prior notice."
11
+
12
+ s.bindir = "bin"
13
+ s.executables << "ascode"
14
+ s.files = Dir["**/*"]
15
+
16
+ s.homepage = "https://github.com/sudoio/ascode"
17
+ s.license = "MIT"
18
+ s.metadata = {
19
+ "bug_tracker_uri" => "https://github.com/sudoio/ascode/issues",
20
+ "source_code_uri" => "https://github.com/sudoio/ascode"
21
+ }
22
+ end
data/docs/functions.md ADDED
@@ -0,0 +1,46 @@
1
+ # Functions
2
+
3
+ - [`IO`](#io)
4
+ - [`Environment`](#environment)
5
+ - [`Conditions`](#conditions)
6
+ - [`Math`](#math)
7
+
8
+ ##### IO
9
+
10
+ Function|`pop`s|`push`es|Description
11
+ ---|---|---|---
12
+ `I`| |`a`|`stdin` -> `a`
13
+ `O`|`a`| |`a` -> `stdout`
14
+ `N`| | |`\n` -> `stdout`
15
+
16
+ ##### Environment
17
+
18
+ Function|`pop`s|`push`es|Description
19
+ ---|---|---|---
20
+ `P`|`a`| |
21
+ `C`|`a`| |`a` -> `Register`
22
+ `V`| |`a`|`Register` -> `a`
23
+ `S`|`a`, `b`|`a`, `b`|Swaps first two elements in the stack
24
+ `D`|`a`|`a`, `a`|Duplicates first element in the stack
25
+
26
+ ##### Conditions
27
+
28
+ > `a` = `pop`
29
+ > Condition is false if `a` is `0` or `false`
30
+
31
+ Syntax: `[` **ascode for true** `:` **ascode for false** `]`
32
+
33
+ ##### Math
34
+
35
+ Function|`pop`s|`push`es|Description
36
+ ---|---|---|---
37
+ `+`|`a`, `b`|`c`|`c` = `a` + `b`
38
+ `-`|`a`, `b`|`c`|`c` = `a` - `b`
39
+ `/`|`a`, `b`|`c`|`c` = `a` / `b`
40
+ `*`|`a`, `b`|`c`|`c` = `a` * `b`
41
+ `>`|`a`, `b`|`c`|`c` = `1` if `a` > `b`, `0` otherwise
42
+ `<`|`a`, `b`|`c`|`c` = `1` if `a` < `b`, `0` otherwise
43
+ `=`|`a`, `b`|`c`|`c` = `1` if `a` = `b`, `0` otherwise
44
+ `e`|`a`|`b`|`b` = `1` if `a` is even, `0` otherwise
45
+ `!`|`a`|`b`|`b` = `1` if `a` = `0`, otherwise `0`
46
+ `s`|`a`|`b`|`b` = `-1` * `a`
@@ -11,9 +11,9 @@ module Ascode
11
11
  @env.ast = ast
12
12
 
13
13
  @map = {
14
- "io" => IO,
15
- "math" => Math,
16
- "condition" => Condition
14
+ io: IO,
15
+ math: Math,
16
+ condition: Condition
17
17
  }
18
18
  end
19
19
 
@@ -32,7 +32,7 @@ module Ascode
32
32
  end
33
33
 
34
34
  def call(type, name)
35
- if type == "env"
35
+ if type == :env
36
36
  @env.send name
37
37
  else
38
38
  @map[type].send name, @env
@@ -1,50 +1,58 @@
1
1
  module Ascode
2
2
  module Parser
3
3
  class Function
4
- attr_reader :csv_data
5
-
6
- def initialize
7
- @csv_data = []
8
-
9
- filename = File.join(File.dirname(__FILE__), "../functions.md")
10
- File.open(filename, "r") do |file|
11
- read_csv file
12
- end
13
-
14
- @csv_data.delete_if do |e|
15
- e[:short].nil? || e[:short].to_s.length > 1
16
- end
17
- end
18
-
19
4
  def parse(char)
20
- function = @csv_data.to_enum.find do |value|
21
- value[:short] == char
5
+ CODE.find do |type|
6
+ type[1].find_index do |function|
7
+ @ast = ast type[0], function[1] if function[0] == char
8
+ end
22
9
  end
23
10
 
24
- return unless function
11
+ return unless @ast
12
+ @ast
13
+ end
25
14
 
15
+ def ast(type, name)
26
16
  {
27
- type: function[:type],
28
- action: function[:long]
17
+ type: type,
18
+ action: name
29
19
  }
30
20
  end
31
21
 
32
- def read_csv(file)
33
- until (line = file.gets).nil?
34
- src = line.strip.split("|")
35
-
36
- @csv_data.push(
37
- short: clear_quotes(src[0]),
38
- type: clear_quotes(src[1]),
39
- long: clear_quotes(src[2])
40
- )
41
- end
42
- end
43
-
44
- def clear_quotes(str)
45
- return str unless str
46
- str.delete("`")
47
- end
22
+ CODE = {
23
+ io: [
24
+ %w[I input],
25
+ %w[O output],
26
+ %w[N new_line]
27
+ ],
28
+
29
+ env: [
30
+ %w[P pop],
31
+ %w[C reg_copy],
32
+ %w[V reg_paste],
33
+ %w[S swap],
34
+ %w[D duplicate]
35
+ ],
36
+
37
+ condition: [
38
+ %w([ begin),
39
+ %w[: else],
40
+ %w(] end)
41
+ ],
42
+
43
+ math: [
44
+ %w[+ plus],
45
+ %w[- minus],
46
+ %w[* multiply],
47
+ %w[/ divide],
48
+ %w[> bigger_than],
49
+ %w[< less_than],
50
+ %w[= equal],
51
+ %w[e even],
52
+ %w[! invert],
53
+ %w[s change_sign]
54
+ ]
55
+ }.freeze
48
56
  end
49
57
  end
50
58
  end
@@ -26,7 +26,7 @@ module Ascode
26
26
  character char, index
27
27
  end
28
28
 
29
- @ast.push(type: "io", action: "output") if @implicit_output
29
+ @ast.push(type: :io, action: "output") if @implicit_output
30
30
 
31
31
  @ast
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Varaksa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Esoteric golfing language. In active development, so behavior may be
14
14
  changed without prior notice.
@@ -20,10 +20,11 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - LICENSE.md
22
22
  - README.md
23
+ - ascode.gemspec
23
24
  - bin/ascode
25
+ - docs/functions.md
24
26
  - lib/ascode.rb
25
27
  - lib/ascode/converter.rb
26
- - lib/ascode/functions.md
27
28
  - lib/ascode/interpreter/condition.rb
28
29
  - lib/ascode/interpreter/environment.rb
29
30
  - lib/ascode/interpreter/io.rb
@@ -1,40 +0,0 @@
1
- #### IO
2
-
3
- Character|Type|Name|`pop`s|`push`es|Description
4
- ---|---|---|---|---|---
5
- `I`|`io`|`input`||`a`|`stdin` -> `a`
6
- `O`|`io`|`output`|`a`||`a` -> `stdout`
7
- `N`|`io`|`new_line`|||`\n` -> `stdout`
8
-
9
- #### Environment
10
-
11
- Character|Type|Name|`pop`s|`push`es|Description
12
- ---|---|---|---|---|---
13
- `P`|`env`|`pop`|`a`||
14
- `C`|`env`|`reg_copy`|`a`||`a` -> `Register`
15
- `V`|`env`|`reg_paste`||`a`|`Register` -> `a`
16
- `S`|`env`|`swap`|`a`, `b`|`a`, `b`|Swaps first two elements in the stack
17
- `D`|`env`|`duplicate`|`a`|`a`, `a`|Duplicates first element in the stack
18
-
19
- #### Condition
20
-
21
- Character|Type|Name|`pop`s|`push`es|Description
22
- ---|---|---|---|---|---
23
- `[`|`condition`|`begin`|`a`|| Condition is false if `a` = `0` or `false`
24
- `:`|`condition`|`else`|||
25
- `]`|`condition`|`end`|||
26
-
27
- #### Math
28
-
29
- Character|Type|Name|`pop`s|`push`es|Description
30
- ---|---|---|---|---|---
31
- `+`|`math`|`plus`|`a`, `b`|`c`|`c` = `a` + `b`
32
- `-`|`math`|`minus`|`a`, `b`|`c`|`c` = `a` - `b`
33
- `/`|`math`|`divide`|`a`, `b`|`c`|`c` = `a` / `b`
34
- `*`|`math`|`multiply`|`a`, `b`|`c`|`c` = `a` * `b`
35
- `>`|`math`|`bigger_than`|`a`, `b`|`c`|`c` = `1` if `a` > `b`, `0` otherwise
36
- `<`|`math`|`less_than`|`a`, `b`|`c`|`c` = `1` if `a` < `b`, `0` otherwise
37
- `=`|`math`|`equal`|`a`, `b`|`c`|`c` = `1` if `a` = `b`, `0` otherwise
38
- `e`|`math`|`even`|`a`|`b`|`b` = `1` if `a` is even, `0` otherwise
39
- `!`|`math`|`invert`|`a`|`b`|`b` = `1` if `a` = `0`, otherwise `0`
40
- `s`|`math`|`change_sign`|`a`|`b`|`b` = `-1` * `a`