rpl 0.12.0 → 0.13.0

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.
@@ -10,28 +10,28 @@ module RplLang
10
10
 
11
11
  category = 'Program'
12
12
 
13
- @dictionary.add_word( ['eval'],
14
- category,
15
- '( a -- … ) interpret',
16
- proc do
17
- args = stack_extract( [:any] )
13
+ @dictionary.add_word!( ['eval'],
14
+ category,
15
+ '( a -- … ) interpret',
16
+ proc do
17
+ args = stack_extract( [:any] )
18
18
 
19
- if [RplList, RplNumeric, RplBoolean].include?( args[0].class )
20
- @stack << args[0] # these types evaluate to themselves
21
- else
22
- run( args[0].value.to_s )
23
- end
24
- end )
19
+ if [RplList, RplNumeric, RplBoolean].include?( args[0].class )
20
+ @stack << args[0] # these types evaluate to themselves
21
+ else
22
+ run!( args[0].value.to_s )
23
+ end
24
+ end )
25
25
 
26
- @dictionary.add_word( ['↴', 'lsto'],
27
- category,
28
- '( content name -- ) store to local variable',
29
- proc do
30
- args = stack_extract( [[RplName], :any] )
26
+ @dictionary.add_word!( ['↴', 'lsto'],
27
+ category,
28
+ '( content name -- ) store to local variable',
29
+ proc do
30
+ args = stack_extract( [[RplName], :any] )
31
31
 
32
- @dictionary.add_local_var( args[0].value,
33
- args[1] )
34
- end )
32
+ @dictionary.add_local_var!( args[0].value,
33
+ args[1] )
34
+ end )
35
35
  end
36
36
  end
37
37
  end
@@ -12,73 +12,73 @@ module RplLang
12
12
 
13
13
  category = 'REPL'
14
14
 
15
- @dictionary.add_word( ['words'],
16
- category,
17
- '() print the categorized list of all words',
18
- proc do
19
- @dictionary.words
20
- .to_a
21
- .group_by { |word| word.last[:category] }
22
- .each do |cat, words|
23
- puts cat
24
- puts " #{words.map(&:first).join(', ')}"
25
- end
26
- end )
27
-
28
- @dictionary.add_word( ['history'],
29
- category,
30
- '() print the REPL\'s history',
31
- proc {} )
32
-
33
- @dictionary.add_word( ['edit'],
34
- category,
35
- '( x -- y ) put first stack object in prompt for modification',
36
- proc {} )
37
-
38
- @dictionary.add_word( ['extedit'],
39
- category,
40
- '( x -- y ) open object in $EDITOR',
41
- proc do
42
- args = stack_extract( [:any] )
43
-
44
- value = args[0].to_s
45
- tempfile = Tempfile.new('rpl')
46
-
47
- begin
48
- tempfile.write( value )
49
- tempfile.rewind
50
-
51
- `$EDITOR #{tempfile.path}`
52
-
53
- edited_value = tempfile.read
54
- ensure
55
- tempfile.close
56
- tempfile.unlink
57
- end
58
-
59
- @stack << Types.new_object( args[0].class, edited_value )
60
- end )
15
+ @dictionary.add_word!( ['words'],
16
+ category,
17
+ '() print the categorized list of all words',
18
+ proc do
19
+ @dictionary.words
20
+ .to_a
21
+ .group_by { |word| word.last[:category] }
22
+ .each do |cat, words|
23
+ puts cat
24
+ puts " #{words.map(&:first).join(', ')}"
25
+ end
26
+ end )
27
+
28
+ @dictionary.add_word!( ['history'],
29
+ category,
30
+ '() print the REPL\'s history',
31
+ proc {} )
32
+
33
+ @dictionary.add_word!( ['edit'],
34
+ category,
35
+ '( x -- y ) put first stack object in prompt for modification',
36
+ proc {} )
37
+
38
+ @dictionary.add_word!( ['extedit'],
39
+ category,
40
+ '( x -- y ) open object in $EDITOR',
41
+ proc do
42
+ args = stack_extract( [:any] )
43
+
44
+ value = args[0].to_s
45
+ tempfile = Tempfile.new('rpl')
46
+
47
+ begin
48
+ tempfile.write( value )
49
+ tempfile.rewind
50
+
51
+ `$EDITOR #{tempfile.path}`
52
+
53
+ edited_value = tempfile.read
54
+ ensure
55
+ tempfile.close
56
+ tempfile.unlink
57
+ end
58
+
59
+ @stack << Types.new_object( args[0].class, edited_value )
60
+ end )
61
61
 
62
62
  category = 'DEBUG'
63
- @dictionary.add_word( ['.s'],
64
- category,
65
- '() print internal state of stack',
66
- proc { pp @stack } )
67
-
68
- @dictionary.add_word( ['.d'],
69
- category,
70
- '() print internal state of dictionary',
71
- proc { pp @dictionary } )
72
-
73
- @dictionary.add_word( ['.v'],
74
- category,
75
- '() print internal state of variables',
76
- proc { pp @dictionary.vars } )
77
-
78
- @dictionary.add_word( ['.lv'],
79
- category,
80
- '() print internal state of local variables layers',
81
- proc { pp @dictionary.local_vars_layers } )
63
+ @dictionary.add_word!( ['.s'],
64
+ category,
65
+ '() print internal state of stack',
66
+ proc { pp @stack } )
67
+
68
+ @dictionary.add_word!( ['.d'],
69
+ category,
70
+ '() print internal state of dictionary',
71
+ proc { pp @dictionary } )
72
+
73
+ @dictionary.add_word!( ['.v'],
74
+ category,
75
+ '() print internal state of variables',
76
+ proc { pp @dictionary.vars } )
77
+
78
+ @dictionary.add_word!( ['.lv'],
79
+ category,
80
+ '() print internal state of local variables layers',
81
+ proc { pp @dictionary.local_vars_layers } )
82
82
  end
83
83
  end
84
84
  end
@@ -10,139 +10,139 @@ module RplLang
10
10
 
11
11
  category = 'Stack'
12
12
 
13
- @dictionary.add_word( ['swap'],
14
- category,
15
- '( a b -- b a ) swap 2 first stack elements',
16
- proc do
17
- args = stack_extract( %i[any any] )
18
-
19
- @stack << args[0] << args[1]
20
- end )
21
-
22
- @dictionary.add_word( ['drop'],
23
- category,
24
- '( a -- ) drop first stack element',
25
- Types.new_object( RplProgram, '« 1 dropn »' ) )
26
-
27
- @dictionary.add_word( ['drop2'],
28
- category,
29
- '( a b -- ) drop first two stack elements',
30
- Types.new_object( RplProgram, '« 2 dropn »' ) )
31
-
32
- @dictionary.add_word( ['dropn'],
33
- category,
34
- '( a b … n -- ) drop first n stack elements',
35
- proc do
36
- args = stack_extract( [[RplNumeric]] )
37
-
38
- _args = stack_extract( %i[any] * args[0].value )
39
- end )
40
-
41
- @dictionary.add_word( ['del'],
42
- category,
43
- '( a b … -- ) drop all stack elements',
44
- proc do
45
- @stack = []
46
- end)
47
-
48
- @dictionary.add_word( ['rot'],
49
- category,
50
- '( a b c -- b c a ) rotate 3 first stack elements',
51
- proc do
52
- args = stack_extract( %i[any any any] )
53
-
54
- @stack << args[1] << args[0] << args[2]
55
- end )
56
-
57
- @dictionary.add_word( ['dup'],
58
- category,
59
- '( a -- a a ) duplicate first stack element',
60
- Types.new_object( RplProgram, '« 1 dupn »' ) )
61
-
62
- @dictionary.add_word( ['dup2'],
63
- category,
64
- '( a b -- a b a b ) duplicate first two stack elements',
65
- Types.new_object( RplProgram, '« 2 dupn »' ) )
66
-
67
- @dictionary.add_word( ['dupn'],
68
- category,
69
- '( a b … n -- a b … a b … ) duplicate first n stack elements',
70
- proc do
71
- args = stack_extract( [[RplNumeric]] )
72
- n = args[0].value.to_i
73
- args = stack_extract( %i[any] * args[0].value )
74
-
75
- args.reverse!
76
-
77
- 2.times do
78
- n.times.each do |i|
79
- @stack << Marshal.load(Marshal.dump( args[i] ))
80
- end
81
- end
82
- end )
83
-
84
- @dictionary.add_word( ['pick'],
85
- category,
86
- '( … b … n -- … b … b ) push a copy of the given stack level onto the stack',
87
- proc do
88
- args = stack_extract( [[RplNumeric]] )
89
- n = args[0].value.to_i
90
- args = stack_extract( %i[any] * args[0].value )
91
-
92
- args.reverse!
93
-
94
- n.times.each do |i|
95
- @stack << args[ i ]
96
- end
97
-
98
- @stack << args[0]
99
- end )
100
-
101
- @dictionary.add_word( ['depth'],
102
- category,
103
- '( … -- … n ) push stack depth onto the stack',
104
- proc do
105
- @stack << Types.new_object( RplNumeric, stack.size )
106
- end )
107
-
108
- @dictionary.add_word( ['roll'],
109
- category,
110
- '( … a -- a … ) move a stack element to the top of the stack',
111
- proc do
112
- args = stack_extract( [[RplNumeric]] )
113
- n = args[0].value
114
- args = stack_extract( %i[any] * args[0].value )
115
-
116
- args.reverse!
117
-
118
- (1..(n - 1)).each do |i|
119
- @stack << args[ i ]
120
- end
121
-
122
- @stack << args[0]
123
- end )
124
-
125
- @dictionary.add_word( ['rolld'],
126
- category,
127
- '( a … -- … a ) move the element on top of the stack to a higher stack position',
128
- proc do
129
- args = stack_extract( [[RplNumeric]] )
130
- n = args[0].value
131
- args = stack_extract( %i[any] * args[0].value )
132
-
133
- args.reverse!
134
-
135
- @stack << args[n - 1]
136
-
137
- (0..(n - 2)).each do |i|
138
- @stack << args[ i ]
139
- end
140
- end )
141
-
142
- @dictionary.add_word( ['over'],
143
- category,
144
- '( a b -- a b a ) push a copy of the element in stack level 2 onto the stack',
145
- Types.new_object( RplProgram, '« 2 pick »' ) )
13
+ @dictionary.add_word!( ['swap'],
14
+ category,
15
+ '( a b -- b a ) swap 2 first stack elements',
16
+ proc do
17
+ args = stack_extract( %i[any any] )
18
+
19
+ @stack << args[0] << args[1]
20
+ end )
21
+
22
+ @dictionary.add_word!( ['drop'],
23
+ category,
24
+ '( a -- ) drop first stack element',
25
+ Types.new_object( RplProgram, '« 1 dropn »' ) )
26
+
27
+ @dictionary.add_word!( ['drop2'],
28
+ category,
29
+ '( a b -- ) drop first two stack elements',
30
+ Types.new_object( RplProgram, '« 2 dropn »' ) )
31
+
32
+ @dictionary.add_word!( ['dropn'],
33
+ category,
34
+ '( a b … n -- ) drop first n stack elements',
35
+ proc do
36
+ args = stack_extract( [[RplNumeric]] )
37
+
38
+ _args = stack_extract( %i[any] * args[0].value )
39
+ end )
40
+
41
+ @dictionary.add_word!( ['del'],
42
+ category,
43
+ '( a b … -- ) drop all stack elements',
44
+ proc do
45
+ @stack = []
46
+ end)
47
+
48
+ @dictionary.add_word!( ['rot'],
49
+ category,
50
+ '( a b c -- b c a ) rotate 3 first stack elements',
51
+ proc do
52
+ args = stack_extract( %i[any any any] )
53
+
54
+ @stack << args[1] << args[0] << args[2]
55
+ end )
56
+
57
+ @dictionary.add_word!( ['dup'],
58
+ category,
59
+ '( a -- a a ) duplicate first stack element',
60
+ Types.new_object( RplProgram, '« 1 dupn »' ) )
61
+
62
+ @dictionary.add_word!( ['dup2'],
63
+ category,
64
+ '( a b -- a b a b ) duplicate first two stack elements',
65
+ Types.new_object( RplProgram, '« 2 dupn »' ) )
66
+
67
+ @dictionary.add_word!( ['dupn'],
68
+ category,
69
+ '( a b … n -- a b … a b … ) duplicate first n stack elements',
70
+ proc do
71
+ args = stack_extract( [[RplNumeric]] )
72
+ n = args[0].value.to_i
73
+ args = stack_extract( %i[any] * args[0].value )
74
+
75
+ args.reverse!
76
+
77
+ 2.times do
78
+ n.times.each do |i|
79
+ @stack << Marshal.load(Marshal.dump( args[i] ))
80
+ end
81
+ end
82
+ end )
83
+
84
+ @dictionary.add_word!( ['pick'],
85
+ category,
86
+ '( … b … n -- … b … b ) push a copy of the given stack level onto the stack',
87
+ proc do
88
+ args = stack_extract( [[RplNumeric]] )
89
+ n = args[0].value.to_i
90
+ args = stack_extract( %i[any] * args[0].value )
91
+
92
+ args.reverse!
93
+
94
+ n.times.each do |i|
95
+ @stack << args[ i ]
96
+ end
97
+
98
+ @stack << args[0]
99
+ end )
100
+
101
+ @dictionary.add_word!( ['depth'],
102
+ category,
103
+ '( … -- … n ) push stack depth onto the stack',
104
+ proc do
105
+ @stack << Types.new_object( RplNumeric, stack.size )
106
+ end )
107
+
108
+ @dictionary.add_word!( ['roll'],
109
+ category,
110
+ '( … a -- a … ) move a stack element to the top of the stack',
111
+ proc do
112
+ args = stack_extract( [[RplNumeric]] )
113
+ n = args[0].value
114
+ args = stack_extract( %i[any] * args[0].value )
115
+
116
+ args.reverse!
117
+
118
+ (1..(n - 1)).each do |i|
119
+ @stack << args[ i ]
120
+ end
121
+
122
+ @stack << args[0]
123
+ end )
124
+
125
+ @dictionary.add_word!( ['rolld'],
126
+ category,
127
+ '( a … -- … a ) move the element on top of the stack to a higher stack position',
128
+ proc do
129
+ args = stack_extract( [[RplNumeric]] )
130
+ n = args[0].value
131
+ args = stack_extract( %i[any] * args[0].value )
132
+
133
+ args.reverse!
134
+
135
+ @stack << args[n - 1]
136
+
137
+ (0..(n - 2)).each do |i|
138
+ @stack << args[ i ]
139
+ end
140
+ end )
141
+
142
+ @dictionary.add_word!( ['over'],
143
+ category,
144
+ '( a b -- a b a ) push a copy of the element in stack level 2 onto the stack',
145
+ Types.new_object( RplProgram, '« 2 pick »' ) )
146
146
  end
147
147
  end
148
148
  end
@@ -10,80 +10,80 @@ module RplLang
10
10
 
11
11
  category = 'Store'
12
12
 
13
- @dictionary.add_word( ['▶', 'sto'],
14
- category,
15
- '( content name -- ) store to variable',
16
- proc do
17
- args = stack_extract( [[RplName], :any] )
18
-
19
- @dictionary.add_var( args[0].value,
20
- args[1] )
21
- end )
22
-
23
- @dictionary.add_word( ['rcl'],
24
- category,
25
- '( name -- … ) push content of variable name onto stack',
26
- proc do
27
- args = stack_extract( [[RplName]] )
28
-
29
- content = @dictionary.lookup( args[0].value )
30
-
31
- @stack << content unless content.nil?
32
- end )
33
-
34
- @dictionary.add_word( ['purge'],
35
- category,
36
- '( name -- ) delete variable',
37
- proc do
38
- args = stack_extract( [[RplName]] )
39
-
40
- @dictionary.remove_var( args[0].value )
41
- end )
42
-
43
- @dictionary.add_word( ['vars'],
44
- category,
45
- '( -- […] ) list variables',
46
- proc do
47
- @stack << Types.new_object( RplList, (@dictionary.vars.keys + @dictionary.local_vars_layers.reduce([]) { |memo, layer| memo + layer.keys })
48
- .map { |name| Types.new_object( RplName, name ) } )
49
- end )
50
-
51
- @dictionary.add_word( ['clusr'],
52
- category,
53
- '( -- ) delete all variables',
54
- proc do
55
- @dictionary.remove_all_vars
56
- end )
57
-
58
- @dictionary.add_word( ['sto+'],
59
- category,
60
- '( a n -- ) add content to variable\'s value',
61
- Types.new_object( RplProgram, '« swap over rcl + swap sto »' ) )
62
-
63
- @dictionary.add_word( ['sto-'],
64
- category,
65
- '( a n -- ) subtract content to variable\'s value',
66
- Types.new_object( RplProgram, '« swap over rcl swap - swap sto »' ) )
67
-
68
- @dictionary.add_word( ['sto×', 'sto*'],
69
- category,
70
- '( a n -- ) multiply content of variable\'s value',
71
- Types.new_object( RplProgram, '« swap over rcl * swap sto »' ) )
72
-
73
- @dictionary.add_word( ['sto÷', 'sto/'],
74
- category,
75
- '( a n -- ) divide content of variable\'s value',
76
- Types.new_object( RplProgram, '« swap over rcl swap / swap sto »' ) )
77
-
78
- @dictionary.add_word( ['sneg'],
79
- category,
80
- '( a n -- ) negate content of variable\'s value',
81
- Types.new_object( RplProgram, '« dup rcl chs swap sto »' ) )
82
-
83
- @dictionary.add_word( ['sinv'],
84
- category,
85
- '( a n -- ) invert content of variable\'s value',
86
- Types.new_object( RplProgram, '« dup rcl inv swap sto »' ) )
13
+ @dictionary.add_word!( ['▶', 'sto'],
14
+ category,
15
+ '( content name -- ) store to variable',
16
+ proc do
17
+ args = stack_extract( [[RplName], :any] )
18
+
19
+ @dictionary.add_var!( args[0].value,
20
+ args[1] )
21
+ end )
22
+
23
+ @dictionary.add_word!( ['rcl'],
24
+ category,
25
+ '( name -- … ) push content of variable name onto stack',
26
+ proc do
27
+ args = stack_extract( [[RplName]] )
28
+
29
+ content = @dictionary.lookup( args[0].value )
30
+
31
+ @stack << content unless content.nil?
32
+ end )
33
+
34
+ @dictionary.add_word!( ['purge'],
35
+ category,
36
+ '( name -- ) delete variable',
37
+ proc do
38
+ args = stack_extract( [[RplName]] )
39
+
40
+ @dictionary.remove_var!( args[0].value )
41
+ end )
42
+
43
+ @dictionary.add_word!( ['vars'],
44
+ category,
45
+ '( -- […] ) list variables',
46
+ proc do
47
+ @stack << Types.new_object( RplList, (@dictionary.vars.keys + @dictionary.local_vars_layers.reduce([]) { |memo, layer| memo + layer.keys })
48
+ .map { |name| Types.new_object( RplName, name ) } )
49
+ end )
50
+
51
+ @dictionary.add_word!( ['clusr'],
52
+ category,
53
+ '( -- ) delete all variables',
54
+ proc do
55
+ @dictionary.remove_all_vars!
56
+ end )
57
+
58
+ @dictionary.add_word!( ['sto+'],
59
+ category,
60
+ '( a n -- ) add content to variable\'s value',
61
+ Types.new_object( RplProgram, '« swap over rcl + swap sto »' ) )
62
+
63
+ @dictionary.add_word!( ['sto-'],
64
+ category,
65
+ '( a n -- ) subtract content to variable\'s value',
66
+ Types.new_object( RplProgram, '« swap over rcl swap - swap sto »' ) )
67
+
68
+ @dictionary.add_word!( ['sto×', 'sto*'],
69
+ category,
70
+ '( a n -- ) multiply content of variable\'s value',
71
+ Types.new_object( RplProgram, '« swap over rcl * swap sto »' ) )
72
+
73
+ @dictionary.add_word!( ['sto÷', 'sto/'],
74
+ category,
75
+ '( a n -- ) divide content of variable\'s value',
76
+ Types.new_object( RplProgram, '« swap over rcl swap / swap sto »' ) )
77
+
78
+ @dictionary.add_word!( ['sneg'],
79
+ category,
80
+ '( a n -- ) negate content of variable\'s value',
81
+ Types.new_object( RplProgram, '« dup rcl chs swap sto »' ) )
82
+
83
+ @dictionary.add_word!( ['sinv'],
84
+ category,
85
+ '( a n -- ) invert content of variable\'s value',
86
+ Types.new_object( RplProgram, '« dup rcl inv swap sto »' ) )
87
87
  end
88
88
  end
89
89
  end