gloo 0.5.4 → 0.7.2
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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/gloo/app/args.rb +48 -6
- data/lib/gloo/app/engine.rb +60 -38
- data/lib/gloo/app/help.rb +137 -16
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +23 -0
- data/lib/gloo/app/mode.rb +2 -0
- data/lib/gloo/app/settings.rb +98 -47
- data/lib/gloo/convert/converter.rb +35 -0
- data/lib/gloo/convert/string_to_datetime.rb +1 -1
- data/lib/gloo/convert/string_to_decimal.rb +1 -1
- data/lib/gloo/convert/string_to_integer.rb +1 -1
- data/lib/gloo/core/dictionary.rb +99 -22
- data/lib/gloo/core/error.rb +19 -8
- data/lib/gloo/core/event_manager.rb +4 -0
- data/lib/gloo/core/factory.rb +11 -0
- data/lib/gloo/core/gloo_system.rb +1 -1
- data/lib/gloo/core/heap.rb +11 -3
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +6 -0
- data/lib/gloo/core/literal.rb +5 -0
- data/lib/gloo/core/obj.rb +22 -0
- data/lib/gloo/core/op.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -0
- data/lib/gloo/core/pn.rb +38 -0
- data/lib/gloo/core/tokens.rb +66 -22
- data/lib/gloo/core/verb.rb +12 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +15 -5
- data/lib/gloo/exec/exec_env.rb +74 -0
- data/lib/gloo/exec/runner.rb +4 -2
- data/lib/gloo/{core → exec}/script.rb +21 -9
- data/lib/gloo/exec/stack.rb +78 -0
- data/lib/gloo/expr/expression.rb +26 -4
- data/lib/gloo/expr/l_boolean.rb +6 -0
- data/lib/gloo/expr/l_decimal.rb +5 -0
- data/lib/gloo/expr/l_integer.rb +7 -0
- data/lib/gloo/expr/l_string.rb +7 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/help/app/application.txt +22 -0
- data/lib/gloo/help/app/configuration.txt +7 -0
- data/lib/gloo/help/app/default_help.txt +14 -0
- data/lib/gloo/help/app/logging.txt +16 -0
- data/lib/gloo/help/core/color.txt +31 -0
- data/lib/gloo/help/core/error.txt +33 -0
- data/lib/gloo/help/core/events.txt +21 -0
- data/lib/gloo/help/core/gloo_system.txt +54 -0
- data/lib/gloo/help/core/here.txt +30 -0
- data/lib/gloo/help/core/it.txt +23 -0
- data/lib/gloo/help/core/ops.txt +16 -0
- data/lib/gloo/help/core/pathname.txt +29 -0
- data/lib/gloo/help/objs/basic/alias.txt +36 -0
- data/lib/gloo/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo/help/objs/basic/container.txt +33 -0
- data/lib/gloo/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo/help/objs/basic/integer.txt +27 -0
- data/lib/gloo/help/objs/basic/script.txt +29 -0
- data/lib/gloo/help/objs/basic/string.txt +28 -0
- data/lib/gloo/help/objs/basic/text.txt +27 -0
- data/lib/gloo/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo/help/objs/cli/banner.txt +49 -0
- data/lib/gloo/help/objs/cli/bar.txt +34 -0
- data/lib/gloo/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo/help/objs/cli/menu.txt +44 -0
- data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo/help/objs/cli/select.txt +34 -0
- data/lib/gloo/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo/help/objs/data/markdown.txt +25 -0
- data/lib/gloo/help/objs/data/table.txt +46 -0
- data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
- data/lib/gloo/help/objs/dt/date.txt +23 -0
- data/lib/gloo/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo/help/objs/dt/time.txt +23 -0
- data/lib/gloo/help/objs/ror/erb.txt +37 -0
- data/lib/gloo/help/objs/ror/eval.txt +24 -0
- data/lib/gloo/help/objs/snd/play.txt +23 -0
- data/lib/gloo/help/objs/snd/say.txt +28 -0
- data/lib/gloo/help/objs/system/file.txt +41 -0
- data/lib/gloo/help/objs/system/system.txt +32 -0
- data/lib/gloo/help/objs/web/http_get.txt +35 -0
- data/lib/gloo/help/objs/web/http_post.txt +32 -0
- data/lib/gloo/help/objs/web/json.txt +34 -0
- data/lib/gloo/help/objs/web/slack.txt +33 -0
- data/lib/gloo/help/objs/web/teams.txt +30 -0
- data/lib/gloo/help/objs/web/uri.txt +37 -0
- data/lib/gloo/help/verbs/alert.txt +33 -0
- data/lib/gloo/help/verbs/beep.txt +25 -0
- data/lib/gloo/help/verbs/cls.txt +24 -0
- data/lib/gloo/help/verbs/context.txt +43 -0
- data/lib/gloo/help/verbs/create.txt +33 -0
- data/lib/gloo/help/verbs/execute.txt +27 -0
- data/lib/gloo/help/verbs/help.txt +34 -0
- data/lib/gloo/help/verbs/if.txt +37 -0
- data/lib/gloo/help/verbs/list.txt +34 -0
- data/lib/gloo/help/verbs/load.txt +38 -0
- data/lib/gloo/help/verbs/move.txt +42 -0
- data/lib/gloo/help/verbs/put.txt +38 -0
- data/lib/gloo/help/verbs/quit.txt +25 -0
- data/lib/gloo/help/verbs/run.txt +41 -0
- data/lib/gloo/help/verbs/save.txt +26 -0
- data/lib/gloo/help/verbs/show.txt +30 -0
- data/lib/gloo/help/verbs/tell.txt +34 -0
- data/lib/gloo/help/verbs/unless.txt +38 -0
- data/lib/gloo/help/verbs/version.txt +32 -0
- data/lib/gloo/help/verbs/wait.txt +29 -0
- data/lib/gloo/objs/basic/alias.rb +0 -33
- data/lib/gloo/objs/basic/boolean.rb +6 -27
- data/lib/gloo/objs/basic/container.rb +0 -33
- data/lib/gloo/objs/basic/decimal.rb +8 -28
- data/lib/gloo/objs/basic/integer.rb +5 -26
- data/lib/gloo/objs/basic/script.rb +1 -27
- data/lib/gloo/objs/basic/string.rb +6 -26
- data/lib/gloo/objs/basic/text.rb +0 -25
- data/lib/gloo/objs/basic/untyped.rb +0 -26
- data/lib/gloo/objs/cli/banner.rb +0 -29
- data/lib/gloo/objs/cli/bar.rb +0 -29
- data/lib/gloo/objs/cli/colorize.rb +4 -34
- data/lib/gloo/objs/cli/confirm.rb +6 -36
- data/lib/gloo/objs/cli/menu.rb +6 -36
- data/lib/gloo/objs/cli/menu_item.rb +0 -33
- data/lib/gloo/objs/cli/pastel.rb +4 -27
- data/lib/gloo/objs/cli/prompt.rb +4 -28
- data/lib/gloo/objs/cli/select.rb +4 -31
- data/lib/gloo/objs/ctrl/each.rb +33 -33
- data/lib/gloo/objs/ctrl/repeat.rb +8 -29
- data/lib/gloo/objs/data/markdown.rb +0 -25
- data/lib/gloo/objs/data/table.rb +4 -32
- data/lib/gloo/objs/dev/git.rb +12 -30
- data/lib/gloo/objs/dt/date.rb +3 -25
- data/lib/gloo/objs/dt/datetime.rb +4 -26
- data/lib/gloo/objs/dt/time.rb +3 -25
- data/lib/gloo/objs/ror/erb.rb +11 -45
- data/lib/gloo/objs/ror/eval.rb +11 -38
- data/lib/gloo/objs/snd/play.rb +2 -25
- data/lib/gloo/objs/snd/say.rb +9 -31
- data/lib/gloo/objs/system/file_handle.rb +0 -38
- data/lib/gloo/objs/system/system.rb +16 -46
- data/lib/gloo/objs/web/http_get.rb +57 -83
- data/lib/gloo/objs/web/http_post.rb +8 -31
- data/lib/gloo/objs/web/json.rb +11 -31
- data/lib/gloo/objs/web/slack.rb +7 -34
- data/lib/gloo/objs/web/teams.rb +13 -48
- data/lib/gloo/objs/web/uri.rb +0 -29
- data/lib/gloo/persist/file_loader.rb +8 -0
- data/lib/gloo/persist/file_saver.rb +6 -0
- data/lib/gloo/persist/file_storage.rb +2 -0
- data/lib/gloo/persist/line_splitter.rb +2 -0
- data/lib/gloo/persist/persist_man.rb +6 -0
- data/lib/gloo/verbs/alert.rb +30 -44
- data/lib/gloo/verbs/beep.rb +0 -30
- data/lib/gloo/verbs/cls.rb +0 -30
- data/lib/gloo/verbs/context.rb +9 -39
- data/lib/gloo/verbs/create.rb +17 -32
- data/lib/gloo/verbs/execute.rb +52 -0
- data/lib/gloo/verbs/help.rb +151 -115
- data/lib/gloo/verbs/if.rb +46 -44
- data/lib/gloo/verbs/list.rb +36 -54
- data/lib/gloo/verbs/load.rb +8 -37
- data/lib/gloo/verbs/move.rb +12 -51
- data/lib/gloo/verbs/put.rb +28 -52
- data/lib/gloo/verbs/quit.rb +0 -31
- data/lib/gloo/verbs/run.rb +23 -39
- data/lib/gloo/verbs/save.rb +0 -33
- data/lib/gloo/verbs/show.rb +6 -31
- data/lib/gloo/verbs/tell.rb +31 -31
- data/lib/gloo/verbs/unless.rb +47 -46
- data/lib/gloo/verbs/version.rb +0 -30
- data/lib/gloo/verbs/wait.rb +0 -31
- metadata +79 -3
data/lib/gloo/core/tokens.rb
CHANGED
@@ -11,78 +11,85 @@ module Gloo
|
|
11
11
|
|
12
12
|
attr_reader :cmd, :tokens
|
13
13
|
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
# Constructor
|
16
|
+
# ---------------------------------------------------------------------
|
17
|
+
|
18
|
+
#
|
14
19
|
# Set up the tokens.
|
20
|
+
# The command string is parsed into tokens during creation.
|
21
|
+
#
|
15
22
|
def initialize( cmd_string )
|
16
23
|
@cmd = cmd_string
|
17
24
|
@tokens = []
|
18
25
|
tokenize @cmd
|
19
26
|
end
|
20
27
|
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
i = str.index( '"' )
|
25
|
-
j = str.index( '"', i + 1 )
|
26
|
-
j ||= str.length
|
27
|
-
|
28
|
-
tokenize( str[ 0..i - 1 ] ) if i > 1
|
29
|
-
@tokens << str[ i..j ]
|
30
|
-
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
31
|
-
elsif str.index( "'" )
|
32
|
-
i = str.index( "'" )
|
33
|
-
j = str.index( "'", i + 1 )
|
34
|
-
j ||= str.length
|
35
|
-
|
36
|
-
tokenize( str[ 0..i - 1 ] ) if i > 1
|
37
|
-
@tokens << str[ i..j ]
|
38
|
-
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
39
|
-
else
|
40
|
-
str.strip.split( ' ' ).each { |t| @tokens << t }
|
41
|
-
end
|
42
|
-
end
|
28
|
+
# ---------------------------------------------------------------------
|
29
|
+
# Public functions
|
30
|
+
# ---------------------------------------------------------------------
|
43
31
|
|
32
|
+
#
|
44
33
|
# Get the number of tokens
|
34
|
+
#
|
45
35
|
def token_count
|
46
36
|
return @tokens.size
|
47
37
|
end
|
48
38
|
|
39
|
+
#
|
49
40
|
# Get the verb (the first word)
|
41
|
+
#
|
50
42
|
def verb
|
51
43
|
return first
|
52
44
|
end
|
53
45
|
|
46
|
+
#
|
54
47
|
# Get all tokens except the first.
|
48
|
+
#
|
55
49
|
def params
|
56
50
|
return @tokens[ 1..-1 ]
|
57
51
|
end
|
58
52
|
|
53
|
+
#
|
59
54
|
# Get the first token.
|
55
|
+
#
|
60
56
|
def first
|
61
57
|
return @tokens.first if @tokens
|
62
58
|
end
|
63
59
|
|
60
|
+
#
|
64
61
|
# Get the last token.
|
62
|
+
#
|
65
63
|
def last
|
66
64
|
return @tokens.last if @tokens
|
67
65
|
end
|
68
66
|
|
67
|
+
#
|
69
68
|
# Get the second token.
|
69
|
+
#
|
70
70
|
def second
|
71
71
|
return @tokens[ 1 ] if @tokens&.size&.positive?
|
72
72
|
end
|
73
73
|
|
74
|
+
#
|
75
|
+
# Get the token at the the requested index.
|
76
|
+
#
|
74
77
|
def at( index )
|
75
78
|
return @tokens[ index ] if @tokens && @tokens.size >= index
|
76
79
|
end
|
77
80
|
|
81
|
+
#
|
78
82
|
# Get the index of the given token.
|
83
|
+
#
|
79
84
|
def index_of( token )
|
80
85
|
return nil unless @tokens
|
81
86
|
|
82
87
|
return @tokens.find_index { |o| o.casecmp( token ).zero? }
|
83
88
|
end
|
84
89
|
|
90
|
+
#
|
85
91
|
# Get the list of tokens after the given token
|
92
|
+
#
|
86
93
|
def tokens_after( token )
|
87
94
|
i = index_of token
|
88
95
|
return @tokens[ i + 1..-1 ] if i && @tokens && @tokens.size > ( i + 1 )
|
@@ -90,7 +97,9 @@ module Gloo
|
|
90
97
|
return nil
|
91
98
|
end
|
92
99
|
|
100
|
+
#
|
93
101
|
# Get the expression after the given token
|
102
|
+
#
|
94
103
|
def expr_after( token )
|
95
104
|
str = ''
|
96
105
|
tokens_after( token ).each do |t|
|
@@ -100,7 +109,9 @@ module Gloo
|
|
100
109
|
return str
|
101
110
|
end
|
102
111
|
|
112
|
+
#
|
103
113
|
# Get the item after a given token.
|
114
|
+
#
|
104
115
|
def after_token( token )
|
105
116
|
i = index_of token
|
106
117
|
return @tokens[ i + 1 ] if i && @tokens && @tokens.size > ( i + 1 )
|
@@ -108,7 +119,9 @@ module Gloo
|
|
108
119
|
return nil
|
109
120
|
end
|
110
121
|
|
122
|
+
#
|
111
123
|
# Get the item after a given token.
|
124
|
+
#
|
112
125
|
def before_token( token )
|
113
126
|
i = index_of token
|
114
127
|
return @tokens[ 0..i - 1 ] if i && @tokens && @tokens.size >= i
|
@@ -116,6 +129,37 @@ module Gloo
|
|
116
129
|
return nil
|
117
130
|
end
|
118
131
|
|
132
|
+
# ---------------------------------------------------------------------
|
133
|
+
# Private functions
|
134
|
+
# ---------------------------------------------------------------------
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
#
|
139
|
+
# Create a list of token from the given string.
|
140
|
+
#
|
141
|
+
def tokenize( str )
|
142
|
+
if str.index( '"' )
|
143
|
+
i = str.index( '"' )
|
144
|
+
j = str.index( '"', i + 1 )
|
145
|
+
j ||= str.length
|
146
|
+
|
147
|
+
tokenize( str[ 0..i - 1 ] ) if i > 1
|
148
|
+
@tokens << str[ i..j ]
|
149
|
+
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
150
|
+
elsif str.index( "'" )
|
151
|
+
i = str.index( "'" )
|
152
|
+
j = str.index( "'", i + 1 )
|
153
|
+
j ||= str.length
|
154
|
+
|
155
|
+
tokenize( str[ 0..i - 1 ] ) if i > 1
|
156
|
+
@tokens << str[ i..j ]
|
157
|
+
tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
|
158
|
+
else
|
159
|
+
str.strip.split( ' ' ).each { |t| @tokens << t }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
119
163
|
end
|
120
164
|
end
|
121
165
|
end
|
data/lib/gloo/core/verb.rb
CHANGED
@@ -13,13 +13,17 @@ module Gloo
|
|
13
13
|
|
14
14
|
attr_reader :tokens, :params
|
15
15
|
|
16
|
+
#
|
16
17
|
# Set up the verb.
|
18
|
+
#
|
17
19
|
def initialize( tokens, params = [] )
|
18
20
|
@tokens = tokens
|
19
21
|
@params = params
|
20
22
|
end
|
21
23
|
|
24
|
+
#
|
22
25
|
# Register verbs when they are loaded.
|
26
|
+
#
|
23
27
|
def self.inherited( subclass )
|
24
28
|
Dictionary.instance.register_verb( subclass )
|
25
29
|
end
|
@@ -58,6 +62,14 @@ module Gloo
|
|
58
62
|
return self.class.keyword
|
59
63
|
end
|
60
64
|
|
65
|
+
#
|
66
|
+
# Generic function to get display value.
|
67
|
+
# Can be used for debugging, etc.
|
68
|
+
#
|
69
|
+
def display_value
|
70
|
+
return self.class.keyword
|
71
|
+
end
|
72
|
+
|
61
73
|
# ---------------------------------------------------------------------
|
62
74
|
# Help
|
63
75
|
# ---------------------------------------------------------------------
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An action is a message sent to an object with optional parameters.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Exec
|
9
|
+
class Action
|
10
|
+
|
11
|
+
attr_accessor :msg, :to, :params
|
12
|
+
|
13
|
+
#
|
14
|
+
# Set up the action.
|
15
|
+
#
|
16
|
+
def initialize( msg, to, params = nil )
|
17
|
+
@msg = msg
|
18
|
+
@to = to
|
19
|
+
@params = params
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# The action is valid if the object can receive
|
24
|
+
# the message specified.
|
25
|
+
#
|
26
|
+
def valid?
|
27
|
+
return @to.can_receive_message?( @msg )
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Execute the action.
|
32
|
+
# Dispatch the message to the object.
|
33
|
+
#
|
34
|
+
def dispatch
|
35
|
+
@to.send_message @msg, @params
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Generic function to get display value.
|
40
|
+
# Can be used for debugging, etc.
|
41
|
+
#
|
42
|
+
def display_value
|
43
|
+
return "#{@msg} -> #{@to.pn}"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/gloo/exec/dispatch.rb
CHANGED
@@ -16,13 +16,23 @@ module Gloo
|
|
16
16
|
# Dispatch the given message to the given object.
|
17
17
|
#
|
18
18
|
def self.message( msg, to_obj, params = nil )
|
19
|
-
$log.debug "
|
19
|
+
$log.debug "Dispatch message #{msg} to #{to_obj.name}"
|
20
|
+
a = Gloo::Exec::Action.new msg, to_obj, params
|
21
|
+
Gloo::Exec::Dispatch.action a
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
#
|
25
|
+
# Dispatch an action.
|
26
|
+
#
|
27
|
+
def self.action( action )
|
28
|
+
unless action.valid?
|
29
|
+
$log.warn "Object #{action.to.name} does not respond to #{action.msg}"
|
25
30
|
end
|
31
|
+
|
32
|
+
$engine.exec_env.push_action action
|
33
|
+
$log.debug "Sending message #{action.msg} to #{action.to.name}"
|
34
|
+
action.dispatch
|
35
|
+
$engine.exec_env.pop_action
|
26
36
|
end
|
27
37
|
|
28
38
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The execution environment.
|
5
|
+
# The current state of running scripts and messaging.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Gloo
|
9
|
+
module Exec
|
10
|
+
class ExecEnv
|
11
|
+
|
12
|
+
attr_accessor :verbs, :actions, :scripts, :here
|
13
|
+
|
14
|
+
VERB_STACK = 'verbs'.freeze
|
15
|
+
ACTION_STACK = 'actions'.freeze
|
16
|
+
SCRIPT_STACK = 'scripts'.freeze
|
17
|
+
HERE_STACK = 'here'.freeze
|
18
|
+
|
19
|
+
#
|
20
|
+
# Set up the execution environment.
|
21
|
+
#
|
22
|
+
def initialize
|
23
|
+
$log.debug 'exec env intialized...'
|
24
|
+
|
25
|
+
@verbs = Gloo::Exec::Stack.new VERB_STACK
|
26
|
+
@actions = Gloo::Exec::Stack.new ACTION_STACK
|
27
|
+
@scripts = Gloo::Exec::Stack.new SCRIPT_STACK
|
28
|
+
@here = Gloo::Exec::Stack.new HERE_STACK
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Get the here object.
|
33
|
+
#
|
34
|
+
def here_obj
|
35
|
+
return nil if @here.stack.empty?
|
36
|
+
|
37
|
+
return @here.stack.last
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Push a script onto the stack.
|
42
|
+
#
|
43
|
+
def push_script( script )
|
44
|
+
@scripts.push script
|
45
|
+
@here.push script.obj
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Pop a script off the stack.
|
50
|
+
#
|
51
|
+
def pop_script
|
52
|
+
@scripts.pop
|
53
|
+
@here.pop
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Push an action onto the stack.
|
58
|
+
#
|
59
|
+
def push_action( action )
|
60
|
+
@actions.push action
|
61
|
+
# @here.push action.to
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Pop an action off the stack.
|
66
|
+
#
|
67
|
+
def pop_action
|
68
|
+
@actions.pop
|
69
|
+
# @here.pop
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/gloo/exec/runner.rb
CHANGED
@@ -16,9 +16,11 @@ module Gloo
|
|
16
16
|
# is done running.
|
17
17
|
#
|
18
18
|
def self.go( verb )
|
19
|
-
$log.debug "
|
19
|
+
$log.debug "running verb #{verb.type_display}"
|
20
20
|
$engine.heap.error.start_tracking
|
21
|
+
$engine.exec_env.verbs.push verb
|
21
22
|
verb&.run
|
23
|
+
$engine.exec_env.verbs.pop
|
22
24
|
$engine.heap.error.clear_if_no_errors
|
23
25
|
end
|
24
26
|
|
@@ -27,7 +29,7 @@ module Gloo
|
|
27
29
|
# Resolve the path_name and then send the run message.
|
28
30
|
#
|
29
31
|
def self.run( path_name )
|
30
|
-
$log.debug "
|
32
|
+
$log.debug "running script at #{path_name}"
|
31
33
|
pn = Gloo::Core::Pn.new path_name
|
32
34
|
o = pn.resolve
|
33
35
|
|
@@ -5,31 +5,43 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
module Gloo
|
8
|
-
module
|
8
|
+
module Exec
|
9
9
|
class Script
|
10
10
|
|
11
|
+
attr_accessor :obj
|
12
|
+
|
13
|
+
#
|
11
14
|
# Set up the script.
|
15
|
+
#
|
12
16
|
def initialize( obj )
|
13
17
|
@obj = obj
|
14
18
|
end
|
15
19
|
|
20
|
+
#
|
16
21
|
# Run the script.
|
22
|
+
# The script might be a single string or an array
|
23
|
+
# of lines.
|
24
|
+
#
|
17
25
|
def run
|
26
|
+
$engine.exec_env.push_script self
|
27
|
+
|
18
28
|
if @obj.value.is_a? String
|
19
|
-
|
29
|
+
$engine.parser.run @obj.value
|
20
30
|
elsif @obj.value.is_a? Array
|
21
31
|
@obj.value.each do |line|
|
22
|
-
|
32
|
+
$engine.parser.run line
|
23
33
|
end
|
24
34
|
end
|
25
|
-
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
i = $engine.parser.parse_immediate line
|
30
|
-
return unless i
|
36
|
+
$engine.exec_env.pop_script
|
37
|
+
end
|
31
38
|
|
32
|
-
|
39
|
+
#
|
40
|
+
# Generic function to get display value.
|
41
|
+
# Can be used for debugging, etc.
|
42
|
+
#
|
43
|
+
def display_value
|
44
|
+
return @obj.pn
|
33
45
|
end
|
34
46
|
|
35
47
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A stack of items, a call stack.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Exec
|
9
|
+
class Stack
|
10
|
+
|
11
|
+
attr_accessor :stack
|
12
|
+
|
13
|
+
#
|
14
|
+
# Set up the stack.
|
15
|
+
#
|
16
|
+
def initialize( name )
|
17
|
+
@name = name
|
18
|
+
clear_stack
|
19
|
+
$log.debug "#{name} stack intialized..."
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Push an item onto the stack.
|
24
|
+
#
|
25
|
+
def push( obj )
|
26
|
+
$log.debug "#{@name}:push #{obj.display_value}"
|
27
|
+
@stack.push obj
|
28
|
+
self.update_out_file if $settings.debug
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Pop an item from the stack.
|
33
|
+
#
|
34
|
+
def pop
|
35
|
+
o = @stack.pop
|
36
|
+
$log.debug "#{@name}:pop #{o.display_value}"
|
37
|
+
self.update_out_file if $settings.debug
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Get the current size of the call stack.
|
42
|
+
#
|
43
|
+
def size
|
44
|
+
return @stack.size
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Get stack data for output.
|
49
|
+
#
|
50
|
+
def out_data
|
51
|
+
return @stack.map( &:display_value ).join( "\n" )
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Get the file we'll write debug information for the stack.
|
56
|
+
#
|
57
|
+
def out_file
|
58
|
+
return File.join( $settings.debug_path, @name )
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Update the stack trace file.
|
63
|
+
#
|
64
|
+
def update_out_file
|
65
|
+
File.write( self.out_file, self.out_data )
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Clear the stack and the output file.
|
70
|
+
#
|
71
|
+
def clear_stack
|
72
|
+
@stack = []
|
73
|
+
self.update_out_file
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|