Numworks Epsilon  1.4.1
Graphing Calculator Operating System
script_store.h
Go to the documentation of this file.
1 #ifndef CODE_SCRIPT_STORE_H
2 #define CODE_SCRIPT_STORE_H
3 
4 #include <ion.h>
5 #include "script.h"
6 #include "script_template.h"
7 #include <python/port/port.h>
8 extern "C" {
9 #include "py/parse.h"
10 }
11 
12 namespace Code {
13 
15 public:
16  static constexpr char k_scriptExtension[] = ".py";
17  static constexpr char k_defaultScriptName[] = "script.py";
18  static constexpr int k_maxNumberOfScripts = 8;
19 
20  ScriptStore();
21  Script scriptAtIndex(int index) {
22  return Script(Ion::Storage::sharedStorage()->recordWithExtensionAtIndex(k_scriptExtension, index));
23  }
24  Script scriptNamed(const char * name) {
25  return Script(Ion::Storage::sharedStorage()->recordNamed(name));
26  }
29  }
32  }
33  void deleteAllScripts();
34  bool isFull();
35 
36  /* Provide scripts content information */
37  typedef void (* ScanCallback)(void * context, const char * p, int n);
38  void scanScriptsForFunctionsAndVariables(void * context, ScanCallback storeFunction,ScanCallback storeVariable);
39 
40  /* MicroPython::ScriptProvider */
41  const char * contentOfScript(const char * name) override;
42 
44 private:
45  /* If the storage available space has a smaller size than
46  * k_fullFreeSpaceSizeLimit, we consider the script store as full.
47  * To be able to add a new empty record, the available space should at least
48  * stores a Script with default name "script99.py" (12 char), the importation
49  * status (1 char), the default content "from math import *\n" (20 char) and
50  * 10 char of free space. */
51  static constexpr int k_fullFreeSpaceSizeLimit = sizeof(Ion::Storage::record_size_t)+12+1+20+10;
52  static constexpr size_t k_fileInput2ParseNodeStructKind = 1;
53  static constexpr size_t k_functionDefinitionParseNodeStructKind = 3;
54  static constexpr size_t k_expressionStatementParseNodeStructKind = 5;
55  const char * structID(mp_parse_node_struct_t *structNode);
56 };
57 
58 }
59 
60 #endif
Ion::Storage::Record::ErrorStatus addScriptFromTemplate(const ScriptTemplate *scriptTemplate)
static const ScriptTemplate * Empty()
static constexpr int k_maxNumberOfScripts
Definition: script_store.h:18
int numberOfRecordsWithExtension(const char *extension)
Definition: storage.cpp:84
static Storage * sharedStorage()
Definition: storage.cpp:22
Script scriptNamed(const char *name)
Definition: script_store.h:24
Definition: app.cpp:7
const char * contentOfScript(const char *name) override
Script scriptAtIndex(int index)
Definition: script_store.h:21
void scanScriptsForFunctionsAndVariables(void *context, ScanCallback storeFunction, ScanCallback storeVariable)
void(* ScanCallback)(void *context, const char *p, int n)
Definition: script_store.h:37
Ion::Storage::Record::ErrorStatus addNewScript()
Definition: script_store.h:30
uint16_t record_size_t
Definition: storage.h:65
static constexpr char k_defaultScriptName[]
Definition: script_store.h:17
static constexpr char k_scriptExtension[]
Definition: script_store.h:16