1 // Copyright (C) 2008-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef _CCSCRIPT_H_
18 #define _CCSCRIPT_H_
19
20 #ifndef UCOMMON_UCOMMON_H_
21 #include <ucommon/ucommon.h>
22 #endif
23
25
32 {
33 public:
37
42
51 union {
54 };
60
65
72 {
78
87 {
88 private:
90
91 public:
93
94 static bool find(
Script *img,
header *scr,
const char *
id);
95 static void createVar(
Script *img,
header *scr,
const char *
id);
96 static void createSym(
Script *img,
header *scr,
const char *
id);
97 static void createAny(
Script *img,
header *scr,
const char *
id);
98 static void createGlobal(
Script *img,
const char *
id);
99
100 void put(FILE *fp,
const char *
header);
101 };
102
111 {
112 private:
113 __DELETE_DEFAULTS(
symbol);
114
115 public:
120 };
121
128 {
129 private:
130 __DELETE_DEFAULTS(
event);
131
132 public:
135 };
136
141
151 {
152 private:
153 __DELETE_DEFAULTS(
header);
154
155 public:
169 {Next = scr;}
170 };
171
180 {
181 private:
182 __DELETE_DEFAULTS(
checks);
183
184 public:
185 static bool isValue(const char *text);
186 static bool isText(const char *text);
187
226 };
227
242
254 {
255 public:
256 typedef char num_t[16];
257
260
266 bool step(void);
267
276 bool attach(
Script *image,
const char *entry = NULL);
277
281 void detach(void);
282
288 void initialize(void);
289
294 bool error(
const char *text);
295
300 unsigned getResource(void);
301
306 const char *getFilename(void);
307
308 protected:
309 symbol *find(
const char *
id);
310 void skip(void);
311 void push(void);
312 bool trylabel(const char *id);
313 bool tryexit(void);
314 void pullScope(void);
315 void pullBase(void);
316 void pullLoop(void);
317 bool pop(void);
319
327 bool scriptEvent(const char *name);
328
334 event *scriptMethod(const char *name);
335
340
341 char *getTemp(void);
342 bool setConst(const char *id, const char *value);
343 symbol *createSymbol(
const char *
id);
344 symbol *getVar(
const char *
id,
const char *value = NULL);
345 const char *getValue(void);
346 const char *getContent(void);
347 const char *getContent(const char *text);
348 const char *getKeyword(const char *id);
349 method_t getLooping(void);
350 bool isConditional(unsigned index);
351 void setRef(
header *scope,
const char *
id,
char *data,
unsigned size);
353 void startScript(
header *scr);
354
355 virtual unsigned getTypesize(const char *type_id);
356 virtual const char *getTypeinit(const char *type_id);
357 virtual const char *getFormat(
symbol *sym,
const char *
id,
char *temp);
358 virtual bool getCondition(const char *test, const char *value);
359 const char *getIndex(void);
360
361 private:
363
364 bool getExpression(unsigned index);
365
366 char *errmsg;
367 char *temps[3];
368 unsigned tempindex;
369 };
370
378 {
379 private:
381
382 __DELETE_DEFAULTS(
error);
383
385
386 public:
390 };
391
400 {
401 private:
403
404 public:
405 bool scrPush(void);
406 bool scrApply(void);
407 bool scrExpr(void);
408 bool scrVar(void);
409 bool scrSet(void);
410 bool scrAdd(void);
411 bool scrClear(void);
412 bool scrConst(void);
413 bool scrPause(void);
414 bool scrNop(void);
415 bool scrPack(void);
416 bool scrExpand(void);
417 bool scrExit(void);
418 bool scrReturn(void);
419 bool scrError(void);
420 bool scrRestart(void);
421 bool scrGosub(void);
422 bool scrGoto(void);
423 bool scrDo(void);
424 bool scrLoop(void);
425 bool scrUntil(void);
426 bool scrWhile(void);
427 bool scrBreak(void);
428 bool scrContinue(void);
429 bool scrForeach(void);
430 bool scrPrevious(void);
431 bool scrRepeat(void);
432 bool scrIndex(void);
433 bool scrCase(void);
434 bool scrEndcase(void);
435 bool scrOtherwise(void);
436 bool scrIf(void);
437 bool scrElif(void);
438 bool scrElse(void);
439 bool scrEndif(void);
440 bool scrDefine(void);
441 bool scrInvoke(void);
442 bool scrWhen(void);
443 bool scrRef(void);
444 bool scrIgnore(void);
445 };
446
448
468
475
484
488 static void init(void);
489
490 static unsigned offset(const char *list, unsigned index);
491 static void copy(const char *list, char *item, unsigned size);
492 static unsigned count(const char *list);
493 static const char *get(const char *list, unsigned offset);
494 static char *get(char *list, unsigned offset);
496 static bool isEvent(
header *scr,
const char *
id);
497
500
502 method_t pull(void);
503 method_t looping(void);
504
506 {return errors;}
507
509 {return errlist.begin();}
510
512 {return filename;}
513
515 {return global != NULL;}
516
518 {return lines;}
519
520 private:
526
528
530
531 void errlog(
unsigned line,
const char *fmt, ...);
532
533 unsigned long instance;
534 unsigned errors;
535 unsigned loop;
536 unsigned lines;
537 bool thencheck;
540 OrderedIndex errlist;
541 object_pointer<Script> shared;
542 const char *filename;
543 unsigned serial;
545 };
546
547 } // namespace ucommon
548
549 #endif
550
header * scr
executing script for stack
static size_t paging
default heap paging
LinkedObject * getListing(void)
line_t * ignore
ignored events
LinkedObject * scheduler
scheduler list
A class to collect compile-time errors.
static unsigned stepping
default stepping increment
static unsigned indexing
default symbol indexing
event event_t
Convenience typedef to allow use of event name.
const char * name
name of command
NAMESPACE_UCOMMON A structure to introduce new core commands to the runtime engine.
char * data
content of symbol
line_t * line
executing line at stack level
const char * name
name of symbol
const char * getFilename(void)
unsigned short index
index marker for loops
Basic compiled statement.
static unsigned stacking
stack frames in script runtime
Contains instance of a runtime symbol.
object_pointer< Script > image
Contains defined variables found by scope when strict is used.
header * scope
scope of symbol definition
static unsigned decimals
default decimal places
header * scope
effective symbol scope
struct keyword * next
linked list set by assign()
A container class for compile-time check methods.
Compiled script container.
check_t check
compile-time check routine
An instance of the runtime interpreter.
method_t method
runtime method or NULL if c-t only
unsigned short base
base stack of "@section"
An event block for a script.
Runtime methods collection class.
event_t * event
so we don't redo our event
unsigned size
size of data buffer or 0 if const
Runtime stack for each interpreter instance.
static unsigned sizing
default symbol size
unsigned short resmask
effective dsp resource mask