Skip to content

Commit 07856fc

Browse files
committed
G6
1 parent 6a9c90b commit 07856fc

File tree

8 files changed

+135
-75
lines changed

8 files changed

+135
-75
lines changed

CONTRIBUTING.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Contributing to GGcode
2+
3+
Thank you for your interest in contributing to GGcode! Your help makes this project better for everyone.
4+
5+
## 📝 How to Contribute
6+
7+
- **Bug Reports & Feature Requests:**
8+
- Please use [GitHub Issues](https://github.com/1T17/GGcode/issues) to report bugs or suggest features.
9+
- Include as much detail as possible (steps to reproduce, expected/actual behavior, screenshots, etc).
10+
11+
- **Pull Requests:**
12+
1. Fork the repository and create your branch from `main`.
13+
2. Write clear, concise commit messages.
14+
3. Add tests for new features or bug fixes if possible.
15+
4. Ensure all tests pass (`make test` or `npm test` if applicable).
16+
5. Open a pull request and describe your changes.
17+
18+
## 🧑‍💻 Code Style
19+
20+
- **C code:**
21+
- Use 4 spaces for indentation.
22+
- Follow existing naming conventions.
23+
- Add comments for complex logic.
24+
- **JavaScript/Node.js:**
25+
- Use 2 spaces for indentation.
26+
- Prefer `const`/`let` over `var`.
27+
- Use semicolons and single quotes.
28+
- **General:**
29+
- Keep functions small and focused.
30+
- Write descriptive variable and function names.
31+
- Document public functions with comments.
32+
33+
## 🧪 Testing
34+
35+
- Run all tests before submitting a pull request.
36+
- Add new tests for new features or bug fixes.
37+
- Test both the C and Node.js sides if your change affects both.
38+
39+
## ✍️ Contributing GGcode Scripts & Algorithms
40+
41+
We welcome contributions of new GGcode scripts, toolpath algorithms, and parametric machining logic! Here’s how to make your script contributions clear, reusable, and high-quality:
42+
43+
### Script Style & Best Practices
44+
- **Use clear variable names** (e.g., `radius`, `feed_rate`, `passes`).
45+
- **Add comments** to explain the purpose of each section and any tricky logic.
46+
- **Group related logic** into functions when possible.
47+
- **Use `note {}` blocks** for runtime comments and debug output.
48+
- **Prefer parametric/variable-driven code** over hardcoded values.
49+
- **Document required input variables** at the top of your script.
50+
- **Include a sample output or screenshot** if possible (in your pull request).
51+
52+
### Example GGcode Script Contribution
53+
```ggcode
54+
// Spiral pocketing example
55+
let center_x = 0
56+
let center_y = 0
57+
let start_radius = 5
58+
let end_radius = 20
59+
let step = 1
60+
let feed = 300
61+
62+
note {Spiral pocketing from R[start_radius] to R[end_radius]}
63+
64+
for r = start_radius..end_radius step step {
65+
G1 X[center_x + r] Y[center_y] F[feed]
66+
}
67+
```
68+
69+
### Algorithm Contributions
70+
- **Describe the algorithm** in your pull request (what problem it solves, how it works).
71+
- **Add comments** in the code for each major step.
72+
- **If porting from another language or paper, cite the source.**
73+
- **Add tests or example GGcode files** in the `GGCODE/` directory.
74+
- **If your algorithm is complex, consider adding a markdown file explaining it in `/docs` or as a comment block.**
75+
76+
### Where to Put Your Scripts
77+
- Place example or reusable scripts in the `GGCODE/` directory.
78+
- Add a short comment at the top with your name/handle and a description.
79+
80+
---
81+
82+
## 📦 Project Structure
83+
84+
See the [README.md](./README.md#project-structure) for an overview of the project layout.
85+
86+
## 📧 Contact
87+
88+
For questions, reach out to [[email protected]](mailto:[email protected]).
89+
90+
---
91+
92+
Thank you for helping make GGcode better!

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
---
1111

12+
13+
1214
## ✨ Features
1315

1416
**🪶 Lightweight & Embeddable**
@@ -121,6 +123,38 @@ To compile and run a `.ggcode` file:
121123

122124
If no file is specified, GGcode will automatically compile **all `.ggcode` files** in the current directory.
123125

126+
---
127+
## 🚦 Quick Start
128+
129+
```sh
130+
# Build the compiler and Node.js backend
131+
make all
132+
make node
133+
134+
# Start the web UI (from the node directory)
135+
cd node
136+
node ggcode.js
137+
138+
# Open in your browser:
139+
http://localhost:3000
140+
```
141+
142+
---
143+
144+
## 📁 Project Structure
145+
146+
```
147+
GGcode/
148+
├── src/ # C source code for the compiler and runtime
149+
├── node/ # Node.js backend and web frontend
150+
├── tests/ # Unit and integration tests
151+
├── bin/ # Compiled binaries and test runners
152+
├── GGCODE/ # Example and test .ggcode files
153+
├── README.md # This file
154+
├── Makefile # Build automation
155+
└── ...
156+
```
157+
124158
---
125159

126160
## 🧾 Supported Syntax

node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "",
55
"main": "test.js",
66
"scripts": {
7+
"start": "node ggcode.js",
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},
910
"keywords": [],

node/views/index.ejs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,9 @@
273273
<div class="control-left">
274274

275275

276-
277-
<div class="separator"></div>
278276
<div class="button-group">
279277
<span class="group-label">GG-code</span>
280278

281-
282-
283279
<button type="submit" class="primary" title="Compile GGcode">
284280
<svg width="14" height="14" viewBox="0 0 12 12" fill="currentColor">
285281
<path d="M2.5 1.5L8.5 6L2.5 10.5V1.5Z"/>

src/bindings/nodejs.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ extern int statement_count;
1717

1818
// In your function later:
1919

20-
2120
const char* compile_ggcode_from_string(const char* source_code) {
2221

2322
int debug = get_debug();
24-
2523
// Initialize runtime state
2624
init_runtime();
2725
Runtime* runtime = get_runtime();
@@ -35,56 +33,30 @@ if (!source_code || source_code[0] == '\0') {
3533

3634
// reset_runtime_state();
3735
init_output_buffer();
38-
39-
40-
4136
ASTNode* root = parse_script_from_string(source_code);
42-
43-
4437
emit_gcode(root, -1); // Use runtime state for debug
4538

4639
// === Insert G-code header with % and ID ===
4740

4841
char ggcode_file_name[64];
4942
snprintf(ggcode_file_name, sizeof(ggcode_file_name), "nodejs.ggcode");
50-
5143
emit_gcode_preamble(debug, ggcode_file_name);
5244

53-
54-
55-
56-
5745
// const char* buffer = get_output_buffer();
58-
59-
6046
// printf("DEBUG RAW OUTPUT: '%s'\n", buffer); // See what's really there
6147

62-
63-
6448
const char* output = strdup(get_output_buffer());
6549

66-
67-
6850
if (!root || has_errors()) {
6951
report_error("[NodeJS] Compilation failed or errors detected");
7052
print_errors();
7153
clear_errors();
7254
return strdup("; ERROR\n");
7355
}
7456

75-
76-
7757
reset_runtime_state();
78-
79-
8058
free_ast(root);
81-
82-
83-
84-
8559
free_output_buffer();
86-
87-
8860
return output;
8961
}
9062

src/main.c

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <unistd.h>
66
#include <string.h>
77
#include <libgen.h>
8+
#include <errno.h>
89

910
#ifdef _WIN32
1011
#include <tchar.h>
@@ -34,35 +35,16 @@
3435
#include "utils/file_utils.h"
3536
#include "utils/report.h"
3637
#include "error/error.h"
37-
#define FATAL_ERROR(msg, ...) fatal_error(NULL, 0, 0, msg, ##__VA_ARGS__)
38-
3938
#include "utils/time_utils.h"
40-
#include <errno.h>
41-
42-
43-
44-
45-
4639

4740

48-
49-
50-
51-
// int statement_count = 0;
52-
41+
#define FATAL_ERROR(msg, ...) fatal_error(NULL, 0, 0, msg, ##__VA_ARGS__)
5342

5443
// Declare the runtime variable lookup functions from evaluator.c
55-
56-
57-
5844
const char* GGCODE_INPUT_FILENAME = NULL;
59-
60-
6145
void compile_file(const char* input_path, const char* output_path, int debug);
6246

6347

64-
65-
6648
void make_g_gcode_filename(const char *src, char *dst, size_t dst_size) {
6749
size_t len = strlen(src);
6850
if (len > 7 && strcmp(src + len - 7, ".ggcode") == 0) {
@@ -72,19 +54,13 @@ void make_g_gcode_filename(const char *src, char *dst, size_t dst_size) {
7254
}
7355
}
7456

75-
76-
7757
// Helper to check if a string ends with .ggcode
7858
int ends_with_ggcode(const char *filename) {
7959
size_t len = strlen(filename);
8060
return len > 7 && strcmp(filename + len - 7, ".ggcode") == 0;
8161
}
8262

8363

84-
85-
86-
87-
8864
void compile_file(const char* input_path, const char* output_path, int debug) {
8965
// Initialize runtime state
9066
init_runtime();
@@ -133,25 +109,20 @@ void compile_file(const char* input_path, const char* output_path, int debug) {
133109
Timer parse_timer;
134110
start_timer(&parse_timer);
135111

136-
137-
ASTNode* root = parse_script_from_string(source);
138-
139-
112+
ASTNode* root = parse_script_from_string(source);
140113
double parse_time = end_timer(&parse_timer);
141114

142115
// Emit timing
143116
Timer emit_timer;
144117
start_timer(&emit_timer);
145118

146-
reset_line_number();
147-
119+
// reset_line_number();
148120
emit_gcode(root, -1); // Use runtime state for debug
149121
double emit_time = end_timer(&emit_timer);
150122

151123
// ➤ Insert G-code header at the beginning AFTER emit
152124
emit_gcode_preamble(debug, filename);
153125

154-
155126
// Measure memory usage (Linux/macOS/Windows)
156127
long memory_kb = 0;
157128

@@ -167,7 +138,6 @@ long memory_kb = 0;
167138
}
168139
#endif
169140

170-
171141
// Output
172142
if (get_output_to_file()) {
173143
FILE* out = fopen(output_path, "w");

src/runtime/evaluator.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,16 @@
1414
#define M_E 2.71828182845904523536
1515
#endif
1616

17-
18-
19-
2017
void enter_scope(void);
2118
void exit_scope(void);
2219

23-
24-
25-
26-
2720
// --- Value types ---
2821
typedef enum {
2922
VAL_NUMBER,
3023
VAL_ARRAY
3124
} ValueType;
3225

33-
34-
26+
// --- Value ---
3527
typedef struct Value {
3628
ValueType type;
3729
union {

src/runtime/runtime_state.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
// Forward declarations
1111
struct Value;
1212

13+
// --- Variable ---
1314
typedef struct {
1415
char *name;
1516
int scope_level;
1617
struct Value *val;
1718
} Variable;
1819

20+
// --- Function ---
1921
typedef struct {
2022
char *name;
2123
ASTNode *node; // AST_FUNCTION node
2224
} FunctionEntry;
2325

26+
// --- Runtime State ---
2427
typedef struct Runtime {
2528
int statement_count;
2629
char RUNTIME_TIME[64];

0 commit comments

Comments
 (0)