gloo 0.5.4 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20f45224b6b8b6007e5f99d8552be6ba63b8f2295c0ad348442a24cf7fe22d03
4
- data.tar.gz: be35cae08d277dc082f450ac3d3bab101e1a4b027ac74288a3a828e5f3608430
3
+ metadata.gz: d78e3893a4d68e8c47bfa5eadaf88b540eb1370eba87883cdb4280bc2b707af3
4
+ data.tar.gz: a4eca4c6ab8df0554b17b5ccedd2efb62357be12c03abe3e3301a993a0599847
5
5
  SHA512:
6
- metadata.gz: 992d33279fa29545b34c0b5218dd92a8ef51db57863ead34aaf16161aeae53731586eff1d9b62a361f09572949309a6158a096c88122aa85afd79f5cef688d33
7
- data.tar.gz: 52f91ea8a7966e1a00f21abf8fa6de471540e63ea6199ed07def348b18e98b610ecf9acb0ac2008ca746116dadedd168015fdcf3bec91de74bae4a65c498ed42
6
+ metadata.gz: 649c9ae168c9933cf139cb6526697b6960f37570edc027840e9a40c51f5e3995d87f575812af918f2463965caa878825c6c554011f969063407ee8cf96fd73d7
7
+ data.tar.gz: 7c2ba8c60a18b36425b8cc436b3fcf40fa6e3a3da437559669e56efc73e3ca891731405bb5e53a672be5fc7ceeff2b22b4db2062dfb03e766264e53d4417d959
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
  *.gem
10
10
  *.log
11
+ test/gloo/debug/*
@@ -15,6 +15,7 @@ module Gloo
15
15
  attr_reader :args, :mode, :running
16
16
  attr_reader :dictionary, :parser, :heap, :factory
17
17
  attr_accessor :last_cmd, :persist_man, :event_manager
18
+ attr_accessor :exec_env
18
19
 
19
20
  # Set up the engine with basic elements.
20
21
  def initialize( params = [] )
@@ -41,6 +42,8 @@ module Gloo
41
42
  @persist_man = Gloo::Persist::PersistMan.new
42
43
  @event_manager = Gloo::Core::EventManager.new
43
44
 
45
+ @exec_env = Gloo::Exec::ExecEnv.new
46
+
44
47
  run_mode
45
48
  end
46
49
 
@@ -8,7 +8,7 @@ module Gloo
8
8
  module App
9
9
  class Info
10
10
 
11
- VERSION = '0.5.4'.freeze
11
+ VERSION = '0.6.0'.freeze
12
12
  APP_NAME = 'Gloo'.freeze
13
13
 
14
14
  # Get the application display title.
@@ -14,8 +14,11 @@ module Gloo
14
14
 
15
15
  attr_reader :user_root, :log_path, :config_path, :project_path
16
16
  attr_reader :start_with, :list_indent, :tmp_path
17
+ attr_reader :debug_path, :debug
17
18
 
19
+ #
18
20
  # Load setting from the yml file.
21
+ #
19
22
  def initialize( mode )
20
23
  @mode = mode
21
24
  init_root
@@ -23,6 +26,9 @@ module Gloo
23
26
  init_user_settings
24
27
  end
25
28
 
29
+ #
30
+ # Initialize gloo's root path.
31
+ #
26
32
  def init_root
27
33
  if in_test_mode?
28
34
  path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
@@ -34,19 +40,25 @@ module Gloo
34
40
  end
35
41
  end
36
42
 
43
+ #
37
44
  # Are we in test mode?
45
+ #
38
46
  def in_test_mode?
39
47
  return @mode == 'TEST'
40
48
  end
41
49
 
50
+ #
42
51
  # Get the project path for the current mode.
52
+ #
43
53
  def project_path_for_mode( settings )
44
54
  return File.join( @user_root, 'projects' ) if in_test_mode?
45
55
 
46
56
  return settings[ 'gloo' ][ 'project_path' ]
47
57
  end
48
58
 
59
+ #
49
60
  # Get the app's required directories.
61
+ #
50
62
  def init_path_settings
51
63
  Dir.mkdir( @user_root ) unless File.exist?( @user_root )
52
64
 
@@ -58,31 +70,44 @@ module Gloo
58
70
 
59
71
  @tmp_path = File.join( @user_root, 'tmp' )
60
72
  Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
73
+
74
+ @debug_path = File.join( @user_root, 'debug' )
75
+ Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
61
76
  end
62
77
 
78
+ #
63
79
  # Initialize the user settings for the currently
64
80
  # running environment.
81
+ #
65
82
  def init_user_settings
66
83
  settings = get_settings
67
84
 
68
85
  @project_path = project_path_for_mode settings
69
86
  @start_with = settings[ 'gloo' ][ 'start_with' ]
70
87
  @list_indent = settings[ 'gloo' ][ 'list_indent' ]
88
+
89
+ @debug = settings[ 'gloo' ][ 'debug' ]
71
90
  end
72
91
 
92
+ #
73
93
  # Get the app's required directories.
94
+ #
74
95
  def get_settings
75
96
  f = File.join( @config_path, 'gloo.yml' )
76
97
  create_settings( f ) unless File.exist?( f )
77
98
  return YAML.load_file f
78
99
  end
79
100
 
101
+ #
80
102
  # Create settings file.
103
+ #
81
104
  def create_settings( file )
82
105
  IO.write( file, get_default_settings )
83
106
  end
84
107
 
108
+ #
85
109
  # Get the value for default settings.
110
+ #
86
111
  def get_default_settings
87
112
  projects = File.join( @user_root, 'projects' )
88
113
  str = <<~TEXT
@@ -90,6 +115,7 @@ module Gloo
90
115
  project_path: #{projects}
91
116
  start_with:
92
117
  list_indent: 1
118
+ debug: false
93
119
  TEXT
94
120
  return str
95
121
  end
@@ -100,32 +126,50 @@ module Gloo
100
126
  #
101
127
  def show
102
128
  puts "\nApplication Settings:".blue
103
- puts ' User Root Path is here: '.yellow + @user_root.white
104
- puts ' Projects directory: '.yellow + @project_path.white
105
- puts ' Tmp directory: '.yellow + @tmp_path.white
106
129
  puts ' Startup with: '.yellow + @start_with.white
107
130
  puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
108
- puts ''
109
131
  puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
110
132
  puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
111
133
  puts ''
134
+ self.show_paths
135
+ puts ''
136
+ end
137
+
138
+ #
139
+ # Show path settings
140
+ #
141
+ def show_paths
142
+ puts ' User Root Path is here: '.yellow + @user_root.white
143
+ puts ' Projects Path: '.yellow + @project_path.white
144
+ puts ' Tmp Path: '.yellow + @tmp_path.white
145
+ puts ' Debug Path: '.yellow + @debug_path.white
112
146
  end
113
147
 
114
- # Get the number of lines on screen.
148
+ #
149
+ # Get the number of vertical lines on screen.
150
+ #
115
151
  def self.lines
116
152
  TTY::Screen.rows
117
153
  end
118
154
 
155
+ #
156
+ # Get the number of horizontal columns on screen.
157
+ #
119
158
  def self.cols
120
159
  TTY::Screen.cols
121
160
  end
122
161
 
162
+ #
123
163
  # Get the default page size.
164
+ # This is the number of lines of text we can show.
165
+ #
124
166
  def self.page_size
125
167
  Settings.lines - 3
126
168
  end
127
169
 
170
+ #
128
171
  # How many lines should we use for a preview?
172
+ #
129
173
  def self.preview_lines
130
174
  return 7
131
175
  end
@@ -0,0 +1,36 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Here helper class,
5
+ # used to resolve relative referencing.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Here
11
+
12
+ HERE = '^'.freeze
13
+
14
+ #
15
+ # Does the pathname start with here reference?
16
+ #
17
+ def self.includes_here_ref?( elements )
18
+ return elements.first.start_with?( HERE )
19
+ end
20
+
21
+ #
22
+ # Expand here reference if present.
23
+ #
24
+ def self.expand_here( pn )
25
+ target = $engine.exec_env.here_obj
26
+
27
+ here = pn.elements.first
28
+ remainder = pn.elements[ 1..-1 ].join( '.' )
29
+
30
+ here.length.times { target = target.parent }
31
+ pn.set_to "#{target.pn}.#{remainder}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -73,6 +73,14 @@ module Gloo
73
73
  return str
74
74
  end
75
75
 
76
+ #
77
+ # Generic function to get display value.
78
+ # Can be used for debugging, etc.
79
+ #
80
+ def display_value
81
+ return self.pn
82
+ end
83
+
76
84
  # ---------------------------------------------------------------------
77
85
  # Value
78
86
  # ---------------------------------------------------------------------
@@ -138,6 +138,8 @@ module Gloo
138
138
  return $engine.heap.error if self.error?
139
139
  return Gloo::Core::GlooSystem.new( self ) if self.gloo_sys?
140
140
 
141
+ Here.expand_here( self ) if Here.includes_here_ref?( @elements )
142
+
141
143
  parent = self.get_parent
142
144
  return nil unless parent
143
145
 
@@ -58,6 +58,14 @@ module Gloo
58
58
  return self.class.keyword
59
59
  end
60
60
 
61
+ #
62
+ # Generic function to get display value.
63
+ # Can be used for debugging, etc.
64
+ #
65
+ def display_value
66
+ return self.class.keyword
67
+ end
68
+
61
69
  # ---------------------------------------------------------------------
62
70
  # Help
63
71
  # ---------------------------------------------------------------------
@@ -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
@@ -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 "----- Sending message #{msg} to #{to_obj.name}"
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
- if to_obj.can_receive_message? msg
22
- to_obj.send_message msg, params
23
- else
24
- $log.warn "Object #{to_obj.name} does not respond to #{msg}"
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,62 @@
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 stack.
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
+ def push_script( script )
41
+ @scripts.push script
42
+ @here.push script.obj
43
+ end
44
+
45
+ def pop_script
46
+ @scripts.pop
47
+ @here.pop
48
+ end
49
+
50
+ def push_action( action )
51
+ @actions.push action
52
+ # @here.push action.to
53
+ end
54
+
55
+ def pop_action
56
+ @actions.pop
57
+ # @here.pop
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -16,9 +16,11 @@ module Gloo
16
16
  # is done running.
17
17
  #
18
18
  def self.go( verb )
19
- $log.debug "**** Running verb #{verb.type_display}"
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 "**** Running script at #{path_name}"
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 Core
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
- run_line @obj.value
29
+ $engine.parser.run @obj.value
20
30
  elsif @obj.value.is_a? Array
21
31
  @obj.value.each do |line|
22
- run_line line
32
+ $engine.parser.run line
23
33
  end
24
34
  end
25
- end
26
35
 
27
- # Run a single line of the script.
28
- def run_line( line )
29
- i = $engine.parser.parse_immediate line
30
- return unless i
36
+ $engine.exec_env.pop_script
37
+ end
31
38
 
32
- i.run
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
@@ -90,7 +90,7 @@ module Gloo
90
90
  # Send the object the unload message.
91
91
  #
92
92
  def msg_run
93
- s = Gloo::Core::Script.new self
93
+ s = Gloo::Exec::Script.new self
94
94
  s.run
95
95
  end
96
96
 
@@ -171,7 +171,7 @@ module Gloo
171
171
  obj = find_child DEFAULT
172
172
  return unless obj
173
173
 
174
- s = Gloo::Core::Script.new obj
174
+ s = Gloo::Exec::Script.new obj
175
175
  s.run
176
176
  end
177
177
 
@@ -193,7 +193,7 @@ module Gloo
193
193
  script = obj.do_script
194
194
  return unless script
195
195
 
196
- s = Gloo::Core::Script.new script
196
+ s = Gloo::Exec::Script.new script
197
197
  s.run
198
198
  end
199
199
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -220,6 +220,7 @@ files:
220
220
  - lib/gloo/core/factory.rb
221
221
  - lib/gloo/core/gloo_system.rb
222
222
  - lib/gloo/core/heap.rb
223
+ - lib/gloo/core/here.rb
223
224
  - lib/gloo/core/it.rb
224
225
  - lib/gloo/core/literal.rb
225
226
  - lib/gloo/core/obj.rb
@@ -227,11 +228,14 @@ files:
227
228
  - lib/gloo/core/op.rb
228
229
  - lib/gloo/core/parser.rb
229
230
  - lib/gloo/core/pn.rb
230
- - lib/gloo/core/script.rb
231
231
  - lib/gloo/core/tokens.rb
232
232
  - lib/gloo/core/verb.rb
233
+ - lib/gloo/exec/action.rb
233
234
  - lib/gloo/exec/dispatch.rb
235
+ - lib/gloo/exec/exec_env.rb
234
236
  - lib/gloo/exec/runner.rb
237
+ - lib/gloo/exec/script.rb
238
+ - lib/gloo/exec/stack.rb
235
239
  - lib/gloo/expr/expression.rb
236
240
  - lib/gloo/expr/l_boolean.rb
237
241
  - lib/gloo/expr/l_decimal.rb