File: gcode_vm.h

package info (click to toggle)
camv-rnd 1.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,824 kB
  • sloc: ansic: 35,928; sh: 686; makefile: 476; yacc: 110; awk: 3
file content (100 lines) | stat: -rw-r--r-- 3,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 *                            COPYRIGHT
 *
 *  camv-rnd - electronics-related CAM viewer
 *  Copyright (C) 2019,2024 Tibor 'Igor2' Palinkas
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *  Contact:
 *    Project page: http://repo.hu/projects/camv-rnd
 *    lead developer: http://repo.hu/projects/camv-rnd/contact.html
 *    mailing list: camv-rnd (at) list.repo.hu (send "subscribe")
 */

#ifndef GCODE_VM_H
#define GCODE_VM_H

#include <genvector/vtd0.h>

typedef enum {
	PUSH_NUM = 1000,
	ADD, SUB, MUL, DIV,
	ASSIGN, PARAM, DO
} gcode_i_t;

typedef struct gcode_inst_s gcode_inst_t;

struct gcode_inst_s {
	int inst; /* a letter or a T_ or gcode_i_t */
	double payload;
	long lineno; /* in the file */
	unsigned do_pop:1;
	gcode_inst_t *next;
};

typedef enum {
	GCP_DELAY_OFF = 0,  /* start collecting instructions on the first (main program) list */
	GCP_DELAY_ON,       /* start collecting instructions on the 2nd (temporary list) */
	GCP_DELAY_APPLY     /* append 2nd list to the main and empty it */
} gcode_delay_t;

typedef struct gcode_prg_s gcode_prg_t;
struct gcode_prg_s {
	struct {
		unsigned laser:1;
	} cfg;

	/*** shared ***/
	void (*error)(gcode_prg_t *ctx, int runtime, const char *msg); /* provided by the caller */
	void (*set_lineno)(gcode_prg_t *ctx, int lineno); /* optional: provided by the caller */
	long ip;
	int lineno;

	/*** lexer states ***/
	int (*get_char)(gcode_prg_t *ctx);   /* provided by the caller */
	int in_eof, pushback, subseq_error;
	long line, col, used, alloced;
	char *buff;

	/*** compiler states ***/
	gcode_inst_t *first, *last; /* main program */
	gcode_inst_t *first2, *last2; /* temporary storage for assignments */
	gcode_delay_t delay;
	long ip2;

	/*** execution states ***/
	int (*execute_code)(gcode_prg_t *ctx, int code, double param); /* provided by the caller; returns 0 on success; code is DO for executing the line */
	double params[5400];
	vtd0_t stack;
	unsigned laser_on:1;

	/*** caller's ***/
	void *user_data;
	void *exec_data;
};


void gcode_delayed(gcode_prg_t *ctx, gcode_delay_t delay);
gcode_inst_t *gcode_append(gcode_prg_t *ctx, gcode_i_t inst, double payload);
void gcode_set_lineno(gcode_prg_t *ctx, int lineno);

void gcode_dump_inst(const char *prefix, gcode_inst_t *inst);
void gcode_dump_prg(const char *prefix, gcode_prg_t *prg);

int gcodeparse(gcode_prg_t *ctx);
int gcode_execute(gcode_prg_t *ctx);

#endif