fOOrth 0.6.4 → 0.6.5
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/integration/compile_lib_tests.rb +41 -0
- data/irbt.rb +0 -2
- data/lib/fOOrth/compiler.rb +4 -8
- data/lib/fOOrth/compiler/cast.rb +39 -0
- data/lib/fOOrth/compiler/context/map_name.rb +12 -31
- data/lib/fOOrth/compiler/process.rb +5 -3
- data/lib/fOOrth/core/class.rb +1 -1
- data/lib/fOOrth/debug.rb +0 -2
- data/lib/fOOrth/debug/display_abort.rb +0 -6
- data/lib/fOOrth/library.rb +1 -0
- data/lib/fOOrth/library/array_library.rb +1 -47
- data/lib/fOOrth/library/command_library.rb +35 -60
- data/lib/fOOrth/library/compile_library.rb +27 -7
- data/lib/fOOrth/library/formatting/bullets.rb +121 -0
- data/lib/fOOrth/library/formatting/columns.rb +144 -0
- data/lib/fOOrth/library/hash_library.rb +2 -1
- data/lib/fOOrth/library/introspection/class.rb +84 -0
- data/lib/fOOrth/library/introspection/context.rb +36 -0
- data/lib/fOOrth/library/introspection/object.rb +69 -0
- data/lib/fOOrth/library/introspection/string.rb +28 -0
- data/lib/fOOrth/library/introspection/symbol_map.rb +19 -0
- data/lib/fOOrth/library/introspection/vm.rb +70 -0
- data/lib/fOOrth/library/introspection/word_specs.rb +18 -0
- data/lib/fOOrth/library/introspection_library.rb +78 -0
- data/lib/fOOrth/library/stack_library.rb +2 -4
- data/lib/fOOrth/library/stdio_library.rb +68 -0
- data/lib/fOOrth/library/stubs.rb +11 -7
- data/lib/fOOrth/library/vm_library.rb +1 -5
- data/lib/fOOrth/version.rb +1 -1
- data/tests/core_tests.rb +1 -1
- metadata +13 -4
- data/lib/fOOrth/debug/context_dump.rb +0 -31
- data/lib/fOOrth/debug/vm_dump.rb +0 -27
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/context.rb - Context support for introspection.
|
4
|
+
module XfOOrth
|
5
|
+
|
6
|
+
#Get information about this compiler context.
|
7
|
+
class Context
|
8
|
+
|
9
|
+
#Get introspection info.
|
10
|
+
def get_info
|
11
|
+
results = [["Level", depth]]
|
12
|
+
|
13
|
+
@data.each do |key, value|
|
14
|
+
results << ["", ""]
|
15
|
+
|
16
|
+
if value.is_a?(AbstractWordSpec)
|
17
|
+
results << ["Name", SymbolMap.unmap(key)]
|
18
|
+
results << ["Mapping", key]
|
19
|
+
results.concat(value.get_info)
|
20
|
+
else
|
21
|
+
results << ["Name", key]
|
22
|
+
results << ["Value", value]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
if (prev = self.previous)
|
28
|
+
results << ["", ""]
|
29
|
+
results.concat(prev.get_info)
|
30
|
+
end
|
31
|
+
|
32
|
+
results
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/object.rb - Object support for introspection.
|
4
|
+
class Object
|
5
|
+
|
6
|
+
#Map the symbol to a specification or nil if there is no mapping.
|
7
|
+
def map_foorth_exclusive_info(symbol, shallow=nil)
|
8
|
+
if (foorth_has_exclusive? && (spec = foorth_exclusive[symbol]))
|
9
|
+
[spec, [["Object", foorth_name], ["Scope", "Exclusive"]]]
|
10
|
+
elsif !shallow
|
11
|
+
self.class.map_foorth_shared_info(symbol)
|
12
|
+
else
|
13
|
+
[nil, nil]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#Get introspection info.
|
18
|
+
def get_info
|
19
|
+
results = [["Type", foorth_name]]
|
20
|
+
|
21
|
+
unless (vars = instance_variables).empty?
|
22
|
+
results.concat([["", ""], ["Data", "Instance"], ["", ""]])
|
23
|
+
|
24
|
+
vars.sort.each do |name|
|
25
|
+
var_name = XfOOrth::SymbolMap.unmap(name[1..-1].to_sym) || name
|
26
|
+
results << [var_name, instance_variable_get(name)]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if foorth_has_exclusive?
|
31
|
+
results.concat([["", ""], ["Methods", "Exclusive"]])
|
32
|
+
|
33
|
+
foorth_exclusive.extract_method_names(:all).sort.each do |name|
|
34
|
+
symbol, info = XfOOrth::SymbolMap.map_info(name)
|
35
|
+
results.concat([["", ""], ["Name", name], info])
|
36
|
+
spec, info = map_foorth_exclusive_info(symbol, :shallow)
|
37
|
+
results.concat(info).concat(spec.get_info)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
results
|
42
|
+
end
|
43
|
+
|
44
|
+
#Investigate a method of this object.
|
45
|
+
def foorth_method_info(name)
|
46
|
+
symbol, results = XfOOrth::SymbolMap.map_info(name)
|
47
|
+
found = false
|
48
|
+
|
49
|
+
if symbol
|
50
|
+
spec, info = map_foorth_exclusive_info(symbol)
|
51
|
+
|
52
|
+
if spec && !spec.has_tag?(:stub)
|
53
|
+
(results << ["", ""]).concat(info).concat(spec.get_info)
|
54
|
+
found = true
|
55
|
+
end
|
56
|
+
|
57
|
+
results << ["Scope", "not found."] unless found
|
58
|
+
end
|
59
|
+
|
60
|
+
results
|
61
|
+
end
|
62
|
+
|
63
|
+
#Get the lineage of this object.
|
64
|
+
def lineage
|
65
|
+
foorth_name + " < " + self.class.lineage
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/string.rb - String support for introspection.
|
4
|
+
class String
|
5
|
+
|
6
|
+
#Scan all classes for information about a method.
|
7
|
+
def foorth_method_scan
|
8
|
+
symbol, results = XfOOrth::SymbolMap.map_info(self)
|
9
|
+
found = false
|
10
|
+
|
11
|
+
symbol && $FOORTH_GLOBALS.values
|
12
|
+
.select {|entry| entry.has_tag?(:class)}
|
13
|
+
.collect {|spec| spec.new_class}
|
14
|
+
.sort {|a,b| a.foorth_name <=> b.foorth_name}
|
15
|
+
.each do |klass|
|
16
|
+
spec, info = klass.map_foorth_shared_info(symbol, :shallow)
|
17
|
+
found |= spec && (results << ["", ""]).concat(info).concat(spec.get_info)
|
18
|
+
|
19
|
+
spec, info = klass.map_foorth_exclusive_info(symbol, :shallow)
|
20
|
+
found |= spec && (results << ["", ""]).concat(info).concat(spec.get_info)
|
21
|
+
end
|
22
|
+
|
23
|
+
results << ["Scope", "not found in any class."] if symbol && !found
|
24
|
+
|
25
|
+
results
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/symbol_map.rb - Mapping support for introspection.
|
4
|
+
module XfOOrth
|
5
|
+
|
6
|
+
#* library/introspection/symbol_map.rb - Mapping support for introspection.
|
7
|
+
module SymbolMap
|
8
|
+
|
9
|
+
#Get mapping info for a method name.
|
10
|
+
def self.map_info(name)
|
11
|
+
symbol = map(name)
|
12
|
+
target = symbol ? symbol.to_s : "not found."
|
13
|
+
[symbol, [["Name", name], ["Mapping", target]]]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/vm.rb - Virtual Machine support for introspection.
|
4
|
+
module XfOOrth
|
5
|
+
|
6
|
+
#* library/introspection/vm.rb - Virtual Machine support for introspection.
|
7
|
+
class VirtualMachine
|
8
|
+
|
9
|
+
#Get introspection info.
|
10
|
+
def get_info
|
11
|
+
results = [["Name", foorth_name],
|
12
|
+
["Ruby", self.to_s],
|
13
|
+
["Stack", @data_stack.inspect],
|
14
|
+
["Nesting", @context.depth],
|
15
|
+
["Quotes", @quotes],
|
16
|
+
["Debug", @debug],
|
17
|
+
["Show", @show_stack],
|
18
|
+
["Start", @start_time]]
|
19
|
+
|
20
|
+
if (source = @parser && @parser.source)
|
21
|
+
results << ["Source", source.source_name]
|
22
|
+
results << ["Buffer", source.read_buffer.inspect]
|
23
|
+
end
|
24
|
+
|
25
|
+
names = instance_variables.map do |sym|
|
26
|
+
if (name = XfOOrth::SymbolMap.unmap(sym.to_s[1..-1].to_sym))
|
27
|
+
[name, sym]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
names.compact!
|
32
|
+
|
33
|
+
unless names.empty?
|
34
|
+
results.concat([["", ""], ["Data", "Instance"], ["", ""]])
|
35
|
+
|
36
|
+
names.each do |name, sym|
|
37
|
+
results << [name, instance_variable_get(sym)]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
unless @data.empty?
|
42
|
+
results.concat([["", ""], ["Data", "Thread"], ["", ""]])
|
43
|
+
|
44
|
+
@data
|
45
|
+
.keys
|
46
|
+
.map{|symbol| [SymbolMap.unmap(symbol), symbol]}
|
47
|
+
.sort{|a,b| a[0] <=> b[0]}
|
48
|
+
.map{|name, symbol| [name, @data[symbol]]}
|
49
|
+
.each do |name, value|
|
50
|
+
results << [name, value.inspect]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if foorth_has_exclusive?
|
55
|
+
results.concat([["", ""], ["Methods", "Exclusive"]])
|
56
|
+
|
57
|
+
foorth_exclusive.extract_method_names(:all).sort.each do |name|
|
58
|
+
symbol, info = SymbolMap.map_info(name)
|
59
|
+
results.concat([["", ""], ["Name", name], info])
|
60
|
+
spec, info = map_foorth_exclusive_info(symbol, :shallow)
|
61
|
+
results.concat(info).concat(spec.get_info)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
results
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/introspection/word_specs.rb - WordSpec support for introspection.
|
4
|
+
module XfOOrth
|
5
|
+
|
6
|
+
#Get information about this word spec.
|
7
|
+
class AbstractWordSpec
|
8
|
+
|
9
|
+
#Get introspection info.
|
10
|
+
def get_info
|
11
|
+
[["Spec" , self.class.foorth_name],
|
12
|
+
["Tags" , tags.join(' ')],
|
13
|
+
["Builds", builds],
|
14
|
+
["Does" , does.inspect]]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'introspection/symbol_map'
|
4
|
+
require_relative 'introspection/class'
|
5
|
+
require_relative 'introspection/object'
|
6
|
+
require_relative 'introspection/string'
|
7
|
+
require_relative 'introspection/word_specs'
|
8
|
+
require_relative 'introspection/context'
|
9
|
+
require_relative 'introspection/vm'
|
10
|
+
|
11
|
+
#* library/introspection_library.rb - The fOOrth introspection library.
|
12
|
+
module XfOOrth
|
13
|
+
|
14
|
+
#Dump the context.
|
15
|
+
VirtualMachine.create_shared_method(')context', VmSpec, [],
|
16
|
+
&lambda {|vm| vm.context.get_info.foorth_bullets(vm) })
|
17
|
+
|
18
|
+
#Dump the context right NOW!.
|
19
|
+
VirtualMachine.create_shared_method(')context!', VmSpec, [:immediate],
|
20
|
+
&lambda {|vm| vm.context.get_info.foorth_bullets(vm) })
|
21
|
+
|
22
|
+
#Dump the virtual machine.
|
23
|
+
VirtualMachine.create_shared_method('.dump', TosSpec, [],
|
24
|
+
&lambda {|vm| get_info.foorth_bullets(vm) })
|
25
|
+
|
26
|
+
#Dump the virtual machine.
|
27
|
+
VirtualMachine.create_shared_method(')vm', VmSpec, [],
|
28
|
+
&lambda {|vm| get_info.foorth_bullets(vm) })
|
29
|
+
|
30
|
+
#Dump the virtual machine right NOW!
|
31
|
+
VirtualMachine.create_shared_method(')vm!', VmSpec, [:immediate],
|
32
|
+
&lambda {|vm| get_info.foorth_bullets(vm) })
|
33
|
+
|
34
|
+
#Map a symbol entry
|
35
|
+
VirtualMachine.create_shared_method(')map"', VmSpec, [], &lambda {|vm|
|
36
|
+
str = vm.pop.to_s
|
37
|
+
puts "#{str} => #{(SymbolMap.map(str).to_s)}"
|
38
|
+
})
|
39
|
+
|
40
|
+
#Unmap a symbol entry
|
41
|
+
VirtualMachine.create_shared_method(')unmap"', VmSpec, [], &lambda {|vm|
|
42
|
+
str = vm.pop.to_s
|
43
|
+
puts "#{str} <= #{(SymbolMap.unmap(str.to_sym).to_s)}"
|
44
|
+
})
|
45
|
+
|
46
|
+
#Get information on a method.
|
47
|
+
Object.create_shared_method('.method_info', TosSpec, [],
|
48
|
+
&lambda{|vm| vm.push(foorth_method_info(vm.pop)) })
|
49
|
+
|
50
|
+
#Get information on a method.
|
51
|
+
Object.create_shared_method(')method_info"', NosSpec, [],
|
52
|
+
&lambda{|vm| foorth_method_info(vm.pop).foorth_bullets(vm) })
|
53
|
+
|
54
|
+
#Scan all classes for information about a method.
|
55
|
+
String.create_shared_method('.method_scan', TosSpec, [],
|
56
|
+
&lambda{|vm| vm.push(foorth_method_scan) })
|
57
|
+
|
58
|
+
#Scan all classes for information about a method.
|
59
|
+
String.create_shared_method(')method_scan"', TosSpec, [],
|
60
|
+
&lambda{|vm| foorth_method_scan.foorth_bullets(vm) })
|
61
|
+
|
62
|
+
#Get this class's lineage in a string.
|
63
|
+
Object.create_shared_method('.lineage', TosSpec, [],
|
64
|
+
&lambda{|vm| vm.push(lineage.freeze) })
|
65
|
+
|
66
|
+
#Print this class's lineage.
|
67
|
+
Object.create_shared_method(')lineage', TosSpec, [],
|
68
|
+
&lambda{|vm| puts lineage })
|
69
|
+
|
70
|
+
#Scan an object for stuff.
|
71
|
+
Object.create_shared_method('.scan', TosSpec, [],
|
72
|
+
&lambda{|vm| vm.push(get_info) })
|
73
|
+
|
74
|
+
#Scan an object for stuff.
|
75
|
+
Object.create_shared_method(')scan', TosSpec, [],
|
76
|
+
&lambda{|vm| get_info.foorth_bullets(vm) })
|
77
|
+
|
78
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
#* library/queue_library.rb - The Queue support fOOrth library.
|
3
|
+
#* library/stack_library.rb - The Stack support fOOrth library.
|
6
4
|
module XfOOrth
|
7
5
|
|
8
|
-
#Connect the
|
6
|
+
#Connect the Stack class to the fOOrth class system.
|
9
7
|
stack = Object.create_foorth_subclass('Stack').new_class
|
10
8
|
|
11
9
|
#Uses the default implementation of the .new method.
|
@@ -1,5 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
#Load up some pretty printing support.
|
4
|
+
require_relative 'formatting/columns'
|
5
|
+
require_relative 'formatting/bullets'
|
6
|
+
|
3
7
|
#* library/stdio_library.rb - The standard I/O fOOrth library.
|
4
8
|
module XfOOrth
|
5
9
|
|
@@ -53,4 +57,68 @@ module XfOOrth
|
|
53
57
|
# "prompt" [] .accept [string]; gets a string from the console.
|
54
58
|
String.create_shared_method('.accept', TosSpec, [],
|
55
59
|
&lambda{|vm| vm.push(MiniReadline.readline(self, true))})
|
60
|
+
|
61
|
+
symbol = :lines_per_page
|
62
|
+
SymbolMap.add_entry('$lines_per_page', symbol)
|
63
|
+
$lines_per_page = [25]
|
64
|
+
$FOORTH_GLOBALS[symbol] = GlobalVarSpec.new('$lines_per_page', symbol, [])
|
65
|
+
|
66
|
+
symbol = :chars_per_line
|
67
|
+
$chars_per_line = [80]
|
68
|
+
SymbolMap.add_entry('$chars_per_line', :chars_per_line)
|
69
|
+
$FOORTH_GLOBALS[symbol] = GlobalVarSpec.new('$chars_per_line', symbol, [])
|
70
|
+
|
71
|
+
#Show the page length.
|
72
|
+
VirtualMachine.create_shared_method(')pl', MacroSpec,
|
73
|
+
[:macro, 'puts "Page Length = #{$lines_per_page[0]}"; '])
|
74
|
+
|
75
|
+
#Set the page length.
|
76
|
+
VirtualMachine.create_shared_method(')set_pl', MacroSpec,
|
77
|
+
[:macro, 'puts "New Page Length = #{$lines_per_page[0] = vm.pop}"; '])
|
78
|
+
|
79
|
+
#Show the page width.
|
80
|
+
VirtualMachine.create_shared_method(')pw', MacroSpec,
|
81
|
+
[:macro, 'puts "Page Width = #{$chars_per_line[0]}"; '])
|
82
|
+
|
83
|
+
#Set the page width.
|
84
|
+
VirtualMachine.create_shared_method(')set_pw', MacroSpec,
|
85
|
+
[:macro, 'puts "New Page Width = #{$chars_per_line[0] = vm.pop}"; '])
|
86
|
+
|
87
|
+
# [ l 2 3 ... n ] .pp []; pretty print the array!
|
88
|
+
Array.create_shared_method('.pp', TosSpec, [], &lambda {|vm|
|
89
|
+
puts_foorth_columnized($lines_per_page[0], $chars_per_line[0])
|
90
|
+
})
|
91
|
+
|
92
|
+
# [ l 2 3 ... n ] .format_columns []; format to strings with columns.
|
93
|
+
Array.create_shared_method('.format_columns', TosSpec, [], &lambda {|vm|
|
94
|
+
vm.push(foorth_columnize($lines_per_page[0], $chars_per_line[0])
|
95
|
+
.map {|page| page << ""}
|
96
|
+
.flatten[0...-1])
|
97
|
+
})
|
98
|
+
|
99
|
+
# [ l 2 3 ... n ] .print_columns []; pretty print columns.
|
100
|
+
Array.create_shared_method('.print_columns', TosSpec, [], &lambda {|vm|
|
101
|
+
puts_foorth_columnized($lines_per_page[0], $chars_per_line[0])
|
102
|
+
})
|
103
|
+
|
104
|
+
#[["1" "stuff"] ["two" stuff] .format_bullets; format to strings with bullets.
|
105
|
+
Array.create_shared_method('.format_bullets', TosSpec, [], &lambda {|vm|
|
106
|
+
vm.push(foorth_bulletize($chars_per_line[0]))
|
107
|
+
})
|
108
|
+
|
109
|
+
#[["1" "stuff"] ["two" stuff] .print_bullets; pretty print bullet points.
|
110
|
+
Array.create_shared_method('.print_bullets', TosSpec, [], &lambda {|vm|
|
111
|
+
puts_foorth_bullets($chars_per_line[0])
|
112
|
+
})
|
113
|
+
|
114
|
+
#{ "1" "stuff" -> "two" "stuff" -> } .format_bullets; format to strings with bullets.
|
115
|
+
Hash.create_shared_method('.format_bullets', TosSpec, [], &lambda {|vm|
|
116
|
+
vm.push(foorth_bulletize($chars_per_line[0]))
|
117
|
+
})
|
118
|
+
|
119
|
+
#{ "1" "stuff" -> "two" "stuff" -> } .print_bullets; pretty print bullet points.
|
120
|
+
Hash.create_shared_method('.print_bullets', TosSpec, [], &lambda {|vm|
|
121
|
+
puts_foorth_bullets($chars_per_line[0])
|
122
|
+
})
|
123
|
+
|
56
124
|
end
|
data/lib/fOOrth/library/stubs.rb
CHANGED
@@ -69,12 +69,16 @@ module XfOOrth
|
|
69
69
|
Object.create_shared_method(',asm', TosSpec, [:stub])
|
70
70
|
Object.create_shared_method(',asm"', TosSpec, [:stub])
|
71
71
|
|
72
|
+
#Command stubs
|
73
|
+
Object.create_shared_method(')method_scan"', TosSpec, [:stub])
|
74
|
+
|
72
75
|
#Define some "crossover" symbols.
|
73
|
-
SymbolMap.add_entry('.is_class?',
|
74
|
-
SymbolMap.add_entry('.to_s',
|
75
|
-
SymbolMap.add_entry('.strlen',
|
76
|
-
SymbolMap.add_entry('.strmax',
|
77
|
-
SymbolMap.add_entry('.strmax2',
|
78
|
-
SymbolMap.add_entry('.
|
79
|
-
SymbolMap.add_entry('.
|
76
|
+
SymbolMap.add_entry('.is_class?', :foorth_is_class?)
|
77
|
+
SymbolMap.add_entry('.to_s', :to_foorth_s)
|
78
|
+
SymbolMap.add_entry('.strlen', :foorth_strlen)
|
79
|
+
SymbolMap.add_entry('.strmax', :foorth_strmax)
|
80
|
+
SymbolMap.add_entry('.strmax2', :foorth_strmax2)
|
81
|
+
SymbolMap.add_entry('.print_columns', :foorth_columns)
|
82
|
+
SymbolMap.add_entry('.print_bullets', :foorth_bullets)
|
83
|
+
SymbolMap.add_entry('.load', :foorth_load_file)
|
80
84
|
end
|