Skip to content

Commit 1931b17

Browse files
Owl Hotfixes and proxy defaults fix (#107)
* fix: proxy defaults for modules without properties * fix for token run size * fix for end of string tokization again * Update parser.h typo fix * code review --------- Co-authored-by: Falko Schindler <[email protected]>
1 parent 73f6c64 commit 1931b17

File tree

9 files changed

+43
-7
lines changed

9 files changed

+43
-7
lines changed

gen_parser.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
echo "This generator is does not include changes from PR #107 and should not be used."
4+
exit 1
5+
36
echo "Generating parser..."
47
if [[ "language.owl" -nt main/parser.h ]]
58
then

main/modules/bluetooth.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "bluetooth.h"
22
#include "uart.h"
33

4+
const std::map<std::string, Variable_ptr> &Bluetooth::get_defaults() {
5+
static std::map<std::string, Variable_ptr> defaults = {};
6+
return defaults;
7+
}
8+
49
Bluetooth::Bluetooth(const std::string name, const std::string device_name, MessageHandler message_handler)
510
: Module(bluetooth, name), device_name(device_name) {
611
ZZ::BleCommand::init(device_name, [message_handler](const std::string_view &message) {
@@ -11,6 +16,7 @@ Bluetooth::Bluetooth(const std::string name, const std::string device_name, Mess
1116
echo("error in bluetooth message handler: %s", e.what());
1217
}
1318
});
19+
this->properties = Bluetooth::get_defaults();
1420
}
1521

1622
void Bluetooth::call(const std::string method_name, const std::vector<ConstExpression_ptr> arguments) {

main/modules/bluetooth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ class Bluetooth : public Module {
1616
Bluetooth(const std::string name, const std::string device_name, MessageHandler message_handler);
1717

1818
void call(const std::string method_name, const std::vector<ConstExpression_ptr> arguments) override;
19+
static const std::map<std::string, Variable_ptr> &get_defaults();
1920
};

main/modules/module.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ const std::map<std::string, Variable_ptr> &Module::get_module_defaults(const std
465465
return Analog::get_defaults();
466466
} else if (type_name == "LinearMotor") {
467467
return LinearMotor::get_defaults();
468+
} else if (type_name == "Serial") {
469+
return Serial::get_defaults();
470+
} else if (type_name == "Bluetooth") {
471+
return Bluetooth::get_defaults();
472+
} else if (type_name == "MotorAxis") {
473+
return MotorAxis::get_defaults();
474+
} else {
475+
throw std::runtime_error("module type \"" + type_name + "\" not found in defaults list");
468476
}
469-
throw std::runtime_error("module type \"" + type_name + "\" not found in defaults list");
470477
}

main/modules/motor_axis.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
#include "utils/uart.h"
33
#include <stdexcept>
44

5+
const std::map<std::string, Variable_ptr> &MotorAxis::get_defaults() {
6+
static std::map<std::string, Variable_ptr> defaults = {};
7+
return defaults;
8+
}
9+
510
MotorAxis::MotorAxis(const std::string name, const Motor_ptr motor, const Input_ptr input1, const Input_ptr input2)
611
: Module(motor_axis, name), motor(motor), input1(input1), input2(input2) {
12+
this->properties = MotorAxis::get_defaults();
713
}
814

915
bool MotorAxis::can_move(const float speed) const {

main/modules/motor_axis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ class MotorAxis : public Module {
1515
MotorAxis(const std::string name, const Motor_ptr motor, const Input_ptr input1, const Input_ptr input2);
1616
void step() override;
1717
void call(const std::string method_name, const std::vector<ConstExpression_ptr> arguments) override;
18+
static const std::map<std::string, Variable_ptr> &get_defaults();
1819
};

main/modules/serial.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
#define TX_BUF_SIZE 2048
99
#define UART_PATTERN_QUEUE_SIZE 100
1010

11+
const std::map<std::string, Variable_ptr> &Serial::get_defaults() {
12+
static const std::map<std::string, Variable_ptr> defaults = {};
13+
return defaults;
14+
}
15+
1116
Serial::Serial(const std::string name,
1217
const gpio_num_t rx_pin, const gpio_num_t tx_pin, const long baud_rate, const uart_port_t uart_num)
1318
: Module(serial, name), rx_pin(rx_pin), tx_pin(tx_pin), baud_rate(baud_rate), uart_num(uart_num) {
19+
this->properties = Serial::get_defaults();
20+
1421
if (uart_is_driver_installed(uart_num)) {
1522
throw std::runtime_error("serial interface is already in use");
1623
}

main/modules/serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ class Serial : public Module {
3232
void clear() const;
3333
std::string get_output() const override;
3434
void call(const std::string method_name, const std::vector<ConstExpression_ptr> arguments) override;
35+
static const std::map<std::string, Variable_ptr> &get_defaults();
3536
};

main/parser.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ struct parsed_statements owl_tree_get_parsed_statements(struct owl_tree *tree) {
17011701
check_for_error(tree);
17021702
return parsed_statements_get(owl_tree_root_ref(tree));
17031703
}
1704+
#define HOTFIX_TOKENIZER_ADVANCE_SIZE 256
17041705
#define ESCAPE_CHAR(c, info) ((c) == 'b' ? '\b' : (c) == 'f' ? '\f' : (c) == 'n' ? '\n' : (c) == 'r' ? '\r' : (c) == 't' ? '\t' : (c))
17051706
#define IGNORE_TOKEN_WRITE(...)
17061707
#define IGNORE_TOKEN_READ(...) (0)
@@ -1766,9 +1767,9 @@ struct owl_token_run {
17661767
struct owl_token_run *prev;
17671768
uint16_t number_of_tokens;
17681769
uint16_t lengths_size;
1769-
uint8_t lengths[4096 * 2];
1770-
uint32_t tokens[4096];
1771-
uint32_t states[4096];
1770+
uint8_t lengths[HOTFIX_TOKENIZER_ADVANCE_SIZE * 2];
1771+
uint32_t tokens[HOTFIX_TOKENIZER_ADVANCE_SIZE];
1772+
uint32_t states[HOTFIX_TOKENIZER_ADVANCE_SIZE];
17721773
};
17731774
struct owl_default_tokenizer {
17741775
const char *text;
@@ -1843,14 +1844,17 @@ static size_t decode_token_length(struct owl_token_run *run, uint16_t *length_of
18431844
return length;
18441845
}
18451846
static bool OWL_DONT_INLINE owl_default_tokenizer_advance(struct owl_default_tokenizer *tokenizer, struct owl_token_run **previous_run) {
1847+
if (tokenizer->text[tokenizer->offset] == '\0') {
1848+
return false;
1849+
}
18461850
struct owl_token_run *run = malloc(sizeof(struct owl_token_run));
18471851
if (!run) return false;
18481852
uint16_t number_of_tokens = 0;
18491853
uint16_t lengths_size = 0;
18501854
const char *text = tokenizer->text;
18511855
size_t whitespace = tokenizer->whitespace;
18521856
size_t offset = tokenizer->offset;
1853-
while (number_of_tokens < 4096) {
1857+
while (number_of_tokens < HOTFIX_TOKENIZER_ADVANCE_SIZE) {
18541858
char c = text[offset];
18551859
if (c == '\0') break;
18561860
size_t whitespace_length = read_whitespace(text + offset, tokenizer->info);
@@ -1975,7 +1979,7 @@ static bool OWL_DONT_INLINE owl_default_tokenizer_advance(struct owl_default_tok
19751979
free(run);
19761980
return false;
19771981
}
1978-
if (end_token && number_of_tokens + 1 >= 4096) break;
1982+
if (end_token && number_of_tokens + 1 >= HOTFIX_TOKENIZER_ADVANCE_SIZE) break;
19791983
if (!encode_token_length(run, &lengths_size, token_length, whitespace)) break;
19801984
if (token == 43) {
19811985
write_identifier_token(offset, token_length, tokenizer->info);
@@ -2020,7 +2024,7 @@ static bool OWL_DONT_INLINE owl_default_tokenizer_advance(struct owl_default_tok
20202024
number_of_tokens++;
20212025
offset += token_length;
20222026
if (end_token) {
2023-
assert(number_of_tokens < 4096);
2027+
assert(number_of_tokens < HOTFIX_TOKENIZER_ADVANCE_SIZE);
20242028
run->tokens[number_of_tokens] = 4294967295U;
20252029
number_of_tokens++;
20262030
}

0 commit comments

Comments
 (0)