rpl 0.5.0 → 0.7.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/bin/rpl +11 -9
- data/lib/rpl/interpreter.rb +25 -204
- data/lib/rpl/parser.rb +87 -0
- data/lib/rpl/types/boolean.rb +32 -0
- data/lib/rpl/types/list.rb +34 -0
- data/lib/rpl/types/name.rb +36 -0
- data/lib/rpl/types/numeric.rb +113 -0
- data/lib/rpl/types/program.rb +27 -0
- data/lib/rpl/types/string.rb +27 -0
- data/lib/rpl/types.rb +19 -0
- data/lib/rpl/{core → words}/branch.rb +14 -16
- data/lib/rpl/{core → words}/filesystem.rb +10 -11
- data/lib/rpl/words/general.rb +112 -0
- data/lib/rpl/{core → words}/logarithm.rb +4 -4
- data/lib/rpl/{core → words}/mode.rb +7 -6
- data/lib/rpl/{core → words}/operations.rb +139 -133
- data/lib/rpl/{core → words}/program.rb +5 -3
- data/lib/rpl/{core → words}/stack.rb +22 -28
- data/lib/rpl/{core → words}/store.rb +18 -45
- data/lib/rpl/words/string-list.rb +133 -0
- data/lib/rpl/{core → words}/test.rb +19 -29
- data/lib/rpl/{core → words}/time-date.rb +6 -8
- data/lib/rpl/{core → words}/trig.rb +20 -36
- data/lib/rpl/words.rb +15 -0
- data/lib/rpl.rb +17 -29
- metadata +24 -16
- data/lib/rpl/core/general.rb +0 -57
- data/lib/rpl/core/list.rb +0 -33
- data/lib/rpl/core/string.rb +0 -114
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gwenhael Le Moine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02
|
11
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A language inspired by HP's RPL and https://github.com/louisrubet/rpn/
|
14
14
|
email: gwenhael@le-moine.org
|
@@ -19,22 +19,30 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/rpl
|
21
21
|
- lib/rpl.rb
|
22
|
-
- lib/rpl/core/branch.rb
|
23
|
-
- lib/rpl/core/filesystem.rb
|
24
|
-
- lib/rpl/core/general.rb
|
25
|
-
- lib/rpl/core/list.rb
|
26
|
-
- lib/rpl/core/logarithm.rb
|
27
|
-
- lib/rpl/core/mode.rb
|
28
|
-
- lib/rpl/core/operations.rb
|
29
|
-
- lib/rpl/core/program.rb
|
30
|
-
- lib/rpl/core/stack.rb
|
31
|
-
- lib/rpl/core/store.rb
|
32
|
-
- lib/rpl/core/string.rb
|
33
|
-
- lib/rpl/core/test.rb
|
34
|
-
- lib/rpl/core/time-date.rb
|
35
|
-
- lib/rpl/core/trig.rb
|
36
22
|
- lib/rpl/dictionary.rb
|
37
23
|
- lib/rpl/interpreter.rb
|
24
|
+
- lib/rpl/parser.rb
|
25
|
+
- lib/rpl/types.rb
|
26
|
+
- lib/rpl/types/boolean.rb
|
27
|
+
- lib/rpl/types/list.rb
|
28
|
+
- lib/rpl/types/name.rb
|
29
|
+
- lib/rpl/types/numeric.rb
|
30
|
+
- lib/rpl/types/program.rb
|
31
|
+
- lib/rpl/types/string.rb
|
32
|
+
- lib/rpl/words.rb
|
33
|
+
- lib/rpl/words/branch.rb
|
34
|
+
- lib/rpl/words/filesystem.rb
|
35
|
+
- lib/rpl/words/general.rb
|
36
|
+
- lib/rpl/words/logarithm.rb
|
37
|
+
- lib/rpl/words/mode.rb
|
38
|
+
- lib/rpl/words/operations.rb
|
39
|
+
- lib/rpl/words/program.rb
|
40
|
+
- lib/rpl/words/stack.rb
|
41
|
+
- lib/rpl/words/store.rb
|
42
|
+
- lib/rpl/words/string-list.rb
|
43
|
+
- lib/rpl/words/test.rb
|
44
|
+
- lib/rpl/words/time-date.rb
|
45
|
+
- lib/rpl/words/trig.rb
|
38
46
|
homepage: https://github.com/gwenhael-le-moine/rpl.rb
|
39
47
|
licenses:
|
40
48
|
- GPL-3.0
|
data/lib/rpl/core/general.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RplLang
|
4
|
-
module Core
|
5
|
-
module General
|
6
|
-
def populate_dictionary
|
7
|
-
super
|
8
|
-
|
9
|
-
@dictionary.add_word( ['nop'],
|
10
|
-
'General',
|
11
|
-
'( -- ) no operation',
|
12
|
-
proc {} )
|
13
|
-
|
14
|
-
@dictionary.add_word( ['help'],
|
15
|
-
'General',
|
16
|
-
'( w -- s ) pop help string of the given word',
|
17
|
-
proc do
|
18
|
-
args = stack_extract( [%i[name]] )
|
19
|
-
|
20
|
-
word = @dictionary.words[ args[0][:value] ]
|
21
|
-
|
22
|
-
@stack << { type: :string,
|
23
|
-
value: "#{args[0][:value]}: #{word.nil? ? 'not a core word' : word[:help]}" }
|
24
|
-
end )
|
25
|
-
|
26
|
-
@dictionary.add_word( ['quit'],
|
27
|
-
'General',
|
28
|
-
'( -- ) Stop and quit interpreter',
|
29
|
-
proc {} )
|
30
|
-
|
31
|
-
@dictionary.add_word( ['version'],
|
32
|
-
'General',
|
33
|
-
'( -- n ) Pop the interpreter\'s version number',
|
34
|
-
proc do
|
35
|
-
@stack += parse( @version.to_s )
|
36
|
-
end )
|
37
|
-
|
38
|
-
@dictionary.add_word( ['uname'],
|
39
|
-
'General',
|
40
|
-
'( -- s ) Pop the interpreter\'s complete indentification string',
|
41
|
-
proc do
|
42
|
-
@stack += parse( "\"Rpl Interpreter version #{@version}\"" )
|
43
|
-
end )
|
44
|
-
|
45
|
-
@dictionary.add_word( ['history'],
|
46
|
-
'REPL',
|
47
|
-
'',
|
48
|
-
proc {} )
|
49
|
-
|
50
|
-
@dictionary.add_word( ['.s'],
|
51
|
-
'REPL',
|
52
|
-
'DEBUG',
|
53
|
-
proc { pp @stack } )
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/lib/rpl/core/list.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RplLang
|
4
|
-
module Core
|
5
|
-
module List
|
6
|
-
def populate_dictionary
|
7
|
-
super
|
8
|
-
|
9
|
-
@dictionary.add_word( ['→list', '->list'],
|
10
|
-
'Lists',
|
11
|
-
'( … x -- […] ) pack x stacks levels into a list',
|
12
|
-
proc do
|
13
|
-
args = stack_extract( [%i[numeric]] )
|
14
|
-
args = stack_extract( %i[any] * args[0][:value] )
|
15
|
-
|
16
|
-
@stack << { type: :list,
|
17
|
-
value: args.reverse }
|
18
|
-
end )
|
19
|
-
|
20
|
-
@dictionary.add_word( ['list→', 'list->'],
|
21
|
-
'Lists',
|
22
|
-
'( […] -- … ) unpack list on stack',
|
23
|
-
proc do
|
24
|
-
args = stack_extract( [%i[list]] )
|
25
|
-
|
26
|
-
args[0][:value].each do |elt|
|
27
|
-
@stack << elt
|
28
|
-
end
|
29
|
-
end )
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/rpl/core/string.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RplLang
|
4
|
-
module Core
|
5
|
-
module String
|
6
|
-
def populate_dictionary
|
7
|
-
super
|
8
|
-
|
9
|
-
@dictionary.add_word( ['→str', '->str'],
|
10
|
-
'String',
|
11
|
-
'( a -- s ) convert element to string',
|
12
|
-
proc do
|
13
|
-
args = stack_extract( [:any] )
|
14
|
-
|
15
|
-
@stack << { type: :string,
|
16
|
-
value: stringify( args[0] ) }
|
17
|
-
end )
|
18
|
-
|
19
|
-
@dictionary.add_word( ['str→', 'str->'],
|
20
|
-
'String',
|
21
|
-
'( s -- a ) convert string to element',
|
22
|
-
proc do
|
23
|
-
args = stack_extract( [%i[string]] )
|
24
|
-
|
25
|
-
@stack += parse( args[0][:value] )
|
26
|
-
end )
|
27
|
-
|
28
|
-
@dictionary.add_word( ['chr'],
|
29
|
-
'String',
|
30
|
-
'( n -- c ) convert ASCII character code in stack level 1 into a string',
|
31
|
-
proc do
|
32
|
-
args = stack_extract( [%i[numeric]] )
|
33
|
-
|
34
|
-
@stack << { type: :string,
|
35
|
-
value: args[0][:value].to_i.chr }
|
36
|
-
end )
|
37
|
-
|
38
|
-
@dictionary.add_word( ['num'],
|
39
|
-
'String',
|
40
|
-
'( s -- n ) return ASCII code of the first character of the string in stack level 1 as a real number',
|
41
|
-
proc do
|
42
|
-
args = stack_extract( [%i[string]] )
|
43
|
-
|
44
|
-
@stack << { type: :numeric,
|
45
|
-
base: 10,
|
46
|
-
value: args[0][:value].ord }
|
47
|
-
end )
|
48
|
-
|
49
|
-
@dictionary.add_word( ['size'],
|
50
|
-
'String',
|
51
|
-
'( s -- n ) return the length of the string',
|
52
|
-
proc do
|
53
|
-
args = stack_extract( [%i[string]] )
|
54
|
-
|
55
|
-
@stack << { type: :numeric,
|
56
|
-
base: 10,
|
57
|
-
value: args[0][:value].length }
|
58
|
-
end )
|
59
|
-
|
60
|
-
@dictionary.add_word( ['pos'],
|
61
|
-
'String',
|
62
|
-
'( s s -- n ) search for the string in level 1 within the string in level 2',
|
63
|
-
proc do
|
64
|
-
args = stack_extract( [%i[string], %i[string]] )
|
65
|
-
|
66
|
-
@stack << { type: :numeric,
|
67
|
-
base: 10,
|
68
|
-
value: args[1][:value].index( args[0][:value] ) }
|
69
|
-
end )
|
70
|
-
|
71
|
-
@dictionary.add_word( ['sub'],
|
72
|
-
'String',
|
73
|
-
'( s n n -- s ) return a substring of the string in level 3',
|
74
|
-
proc do
|
75
|
-
args = stack_extract( [%i[numeric], %i[numeric], %i[string]] )
|
76
|
-
|
77
|
-
@stack << { type: :string,
|
78
|
-
value: args[2][:value][ (args[1][:value] - 1)..(args[0][:value] - 1) ] }
|
79
|
-
end )
|
80
|
-
|
81
|
-
@dictionary.add_word( ['rev'],
|
82
|
-
'String',
|
83
|
-
'( s -- s ) reverse string',
|
84
|
-
proc do
|
85
|
-
args = stack_extract( [%i[string list]] )
|
86
|
-
|
87
|
-
result = args[0]
|
88
|
-
|
89
|
-
case args[0][:type]
|
90
|
-
when :string
|
91
|
-
result = { type: :string,
|
92
|
-
value: args[0][:value].reverse }
|
93
|
-
when :list
|
94
|
-
result[:value].reverse!
|
95
|
-
end
|
96
|
-
|
97
|
-
@stack << result
|
98
|
-
end )
|
99
|
-
|
100
|
-
@dictionary.add_word( ['split'],
|
101
|
-
'String',
|
102
|
-
'( s c -- … ) split string s on character c',
|
103
|
-
proc do
|
104
|
-
args = stack_extract( [%i[string], %i[string]] )
|
105
|
-
|
106
|
-
args[1][:value].split( args[0][:value] ).each do |elt|
|
107
|
-
@stack << { type: :string,
|
108
|
-
value: elt }
|
109
|
-
end
|
110
|
-
end )
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|