rpl 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +115 -0
- data/lib/rpl/types/program.rb +27 -0
- data/lib/rpl/types/string.rb +27 -0
- data/lib/rpl/types.rb +8 -0
- data/lib/rpl/{core → words}/branch.rb +14 -16
- data/lib/rpl/{core → words}/filesystem.rb +10 -11
- data/lib/rpl/{core → words}/general.rb +36 -7
- 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 +22 -37
- 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/list.rb +0 -33
- data/lib/rpl/core/string.rb +0 -114
data/lib/rpl/types.rb
ADDED
@@ -1,38 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RplLang
|
4
|
-
module
|
4
|
+
module Words
|
5
5
|
module Branch
|
6
|
+
include Types
|
7
|
+
|
6
8
|
def populate_dictionary
|
7
9
|
super
|
8
10
|
|
9
11
|
@dictionary.add_word( ['ift'],
|
10
12
|
'Branch',
|
11
13
|
'( t pt -- … ) eval pt or not based on the value of boolean t',
|
12
|
-
|
13
|
-
run( '« nop » ifte' )
|
14
|
-
end )
|
14
|
+
RplProgram.new( '« « nop » ifte »' ) )
|
15
15
|
|
16
16
|
@dictionary.add_word( ['ifte'],
|
17
17
|
'Branch',
|
18
18
|
'( t pt pf -- … ) eval pt or pf based on the value of boolean t',
|
19
19
|
proc do
|
20
|
-
args = stack_extract( [:any, :any,
|
20
|
+
args = stack_extract( [:any, :any, [RplBoolean]] )
|
21
21
|
|
22
|
-
run( args[ args[2]
|
22
|
+
run( args[ args[2].value ? 1 : 0 ].value )
|
23
23
|
end )
|
24
24
|
|
25
25
|
@dictionary.add_word( ['times'],
|
26
26
|
'Branch',
|
27
27
|
'( p n -- … ) eval p n times while pushing counter on stack before',
|
28
28
|
proc do
|
29
|
-
args = stack_extract( [
|
29
|
+
args = stack_extract( [[RplNumeric], :any] )
|
30
30
|
|
31
|
-
args[0]
|
32
|
-
|
33
|
-
@stack << counter
|
31
|
+
args[0].value.to_i.times do |counter|
|
32
|
+
@stack << RplNumeric.new( counter )
|
34
33
|
|
35
|
-
run( args[1]
|
34
|
+
run( args[1].value )
|
36
35
|
end
|
37
36
|
end )
|
38
37
|
|
@@ -40,13 +39,12 @@ module RplLang
|
|
40
39
|
'Branch',
|
41
40
|
'( p n1 n2 -- … ) eval p looping from n1 to n2 while pushing counter on stack before',
|
42
41
|
proc do
|
43
|
-
args = stack_extract( [
|
42
|
+
args = stack_extract( [[RplNumeric], [RplNumeric], :any] )
|
44
43
|
|
45
|
-
((args[1]
|
46
|
-
|
47
|
-
@stack << counter
|
44
|
+
((args[1].value.to_i)..(args[0].value.to_i)).each do |counter|
|
45
|
+
@stack << RplNumeric.new( counter )
|
48
46
|
|
49
|
-
run( args[2]
|
47
|
+
run( args[2].value )
|
50
48
|
end
|
51
49
|
end )
|
52
50
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RplLang
|
4
|
-
module
|
4
|
+
module Words
|
5
5
|
module FileSystem
|
6
|
+
include Types
|
7
|
+
|
6
8
|
def populate_dictionary
|
7
9
|
super
|
8
10
|
|
@@ -10,29 +12,26 @@ module RplLang
|
|
10
12
|
'Filesystem',
|
11
13
|
'( filename -- content ) read file and put content on stack as string',
|
12
14
|
proc do
|
13
|
-
args = stack_extract( [
|
15
|
+
args = stack_extract( [[RplString]] )
|
14
16
|
|
15
|
-
path = File.absolute_path( args[0]
|
17
|
+
path = File.absolute_path( args[0].value )
|
16
18
|
|
17
|
-
@stack << {
|
18
|
-
value: File.read( path ) }
|
19
|
+
@stack << RplString.new( "\"#{File.read( path )}\"" )
|
19
20
|
end )
|
20
21
|
|
21
22
|
@dictionary.add_word( ['feval'],
|
22
23
|
'Filesystem',
|
23
24
|
'( filename -- … ) read and run file',
|
24
|
-
|
25
|
-
run( 'fread eval' )
|
26
|
-
end )
|
25
|
+
RplProgram.new( '« fread eval »' ) )
|
27
26
|
|
28
27
|
@dictionary.add_word( ['fwrite'],
|
29
28
|
'Filesystem',
|
30
29
|
'( content filename -- ) write content into filename',
|
31
30
|
proc do
|
32
|
-
args = stack_extract( [
|
31
|
+
args = stack_extract( [[RplString], :any] )
|
33
32
|
|
34
|
-
File.write( File.absolute_path( args[0]
|
35
|
-
args[1]
|
33
|
+
File.write( File.absolute_path( args[0].value ),
|
34
|
+
args[1].value )
|
36
35
|
end )
|
37
36
|
end
|
38
37
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RplLang
|
4
|
-
module
|
4
|
+
module Words
|
5
5
|
module General
|
6
|
+
include Types
|
7
|
+
|
6
8
|
def populate_dictionary
|
7
9
|
super
|
8
10
|
|
@@ -15,12 +17,24 @@ module RplLang
|
|
15
17
|
'General',
|
16
18
|
'( w -- s ) pop help string of the given word',
|
17
19
|
proc do
|
18
|
-
args = stack_extract( [
|
20
|
+
args = stack_extract( [[RplName]] )
|
21
|
+
|
22
|
+
word = @dictionary.words[ args[0].value ]
|
19
23
|
|
20
|
-
|
24
|
+
@stack << RplString.new( "\"#{args[0].value}: #{word.nil? ? 'not a core word' : word[:help]}\"" )
|
25
|
+
end )
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
@dictionary.add_word( ['words'],
|
28
|
+
'REPL',
|
29
|
+
'DEBUG',
|
30
|
+
proc do
|
31
|
+
@dictionary.words
|
32
|
+
.to_a
|
33
|
+
.group_by { |word| word.last[:category] }
|
34
|
+
.each do |cat, words|
|
35
|
+
puts cat
|
36
|
+
puts " #{words.map { |word| word.first }.join(', ')}"
|
37
|
+
end
|
24
38
|
end )
|
25
39
|
|
26
40
|
@dictionary.add_word( ['quit'],
|
@@ -32,14 +46,14 @@ module RplLang
|
|
32
46
|
'General',
|
33
47
|
'( -- n ) Pop the interpreter\'s version number',
|
34
48
|
proc do
|
35
|
-
@stack += parse( @version.to_s )
|
49
|
+
@stack += Parser.parse( @version.to_s )
|
36
50
|
end )
|
37
51
|
|
38
52
|
@dictionary.add_word( ['uname'],
|
39
53
|
'General',
|
40
54
|
'( -- s ) Pop the interpreter\'s complete indentification string',
|
41
55
|
proc do
|
42
|
-
@stack += parse( "\"Rpl Interpreter version #{@version}\"" )
|
56
|
+
@stack += Parser.parse( "\"Rpl Interpreter version #{@version}\"" )
|
43
57
|
end )
|
44
58
|
|
45
59
|
@dictionary.add_word( ['history'],
|
@@ -51,6 +65,21 @@ module RplLang
|
|
51
65
|
'REPL',
|
52
66
|
'DEBUG',
|
53
67
|
proc { pp @stack } )
|
68
|
+
|
69
|
+
@dictionary.add_word( ['.d'],
|
70
|
+
'REPL',
|
71
|
+
'DEBUG',
|
72
|
+
proc { pp @dictionary } )
|
73
|
+
|
74
|
+
@dictionary.add_word( ['.v'],
|
75
|
+
'REPL',
|
76
|
+
'DEBUG',
|
77
|
+
proc { pp @dictionary.vars } )
|
78
|
+
|
79
|
+
@dictionary.add_word( ['.lv'],
|
80
|
+
'REPL',
|
81
|
+
'DEBUG',
|
82
|
+
proc { pp @dictionary.local_vars_layers } )
|
54
83
|
end
|
55
84
|
end
|
56
85
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RplLang
|
4
|
-
module
|
4
|
+
module Words
|
5
5
|
module Logarithm
|
6
|
+
include Types
|
7
|
+
|
6
8
|
def populate_dictionary
|
7
9
|
super
|
8
10
|
|
@@ -10,9 +12,7 @@ module RplLang
|
|
10
12
|
'Logs on reals and complexes',
|
11
13
|
'( … -- ℇ ) push ℇ',
|
12
14
|
proc do
|
13
|
-
@stack <<
|
14
|
-
base: 10,
|
15
|
-
value: BigMath.E( @precision ) }
|
15
|
+
@stack << RplNumeric.new( BigMath.E( RplNumeric.precision ) )
|
16
16
|
end )
|
17
17
|
|
18
18
|
# @dictionary.add_word( ['ln'],
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RplLang
|
4
|
-
module
|
4
|
+
module Words
|
5
5
|
module Mode
|
6
|
+
include Types
|
7
|
+
|
6
8
|
def populate_dictionary
|
7
9
|
super
|
8
10
|
|
@@ -10,15 +12,15 @@ module RplLang
|
|
10
12
|
'Mode',
|
11
13
|
'( a -- ) set precision to a',
|
12
14
|
proc do
|
13
|
-
args = stack_extract( [
|
15
|
+
args = stack_extract( [[RplNumeric]] )
|
14
16
|
|
15
|
-
|
17
|
+
RplNumeric.precision = args[0].value
|
16
18
|
end )
|
17
19
|
@dictionary.add_word( ['default'],
|
18
20
|
'Mode',
|
19
21
|
'( -- ) set default precision',
|
20
22
|
proc do
|
21
|
-
|
23
|
+
RplNumeric.default_precision
|
22
24
|
end )
|
23
25
|
@dictionary.add_word( ['type'],
|
24
26
|
'Mode',
|
@@ -26,8 +28,7 @@ module RplLang
|
|
26
28
|
proc do
|
27
29
|
args = stack_extract( [:any] )
|
28
30
|
|
29
|
-
@stack << {
|
30
|
-
value: args[0][:type].to_s }
|
31
|
+
@stack << RplString.new( "\"#{args[0].class.to_s[10..-1]}\"" )
|
31
32
|
end )
|
32
33
|
|
33
34
|
# @dictionary.add_word( ['std'],
|