Free Hero Mesh

Check-in [c343f9952a]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement the {edit} macro.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c343f9952a9f273c4ba3f22f09f88356865b8da9
User & Date: user on 2021-05-24 05:06:10
Other Links: manifest | tags
Context
2021-05-26
05:03
Implement the \d escape for embedding data in strings. The ability to use this data is not implemented yet. check-in: a9cc459c7a user: user tags: trunk
2021-05-24
05:06
Implement the {edit} macro. check-in: c343f9952a user: user tags: trunk
2021-05-23
23:23
Implement portable compilation mode, to compile it for "portable app" use. check-in: ec088682c3 user: user tags: trunk
Changes

Modified class.c from [674cdbf650] to [3ce0307661].

140
141
142
143
144
145
146

147
148
149
150
151
152
153
#define MAC_BIT 0xFFCA
#define MAC_MAKE 0xFFCB
#define MAC_VERSION 0xFFE0
#define MAC_DEFINE 0xFFE1
#define MAC_INCLUDE 0xFFE2
#define MAC_CALL 0xFFE3
#define MAC_APPEND 0xFFE4

#define MAC_UNDEFINED 0xFFFF

static TokenList*add_macro(void) {
  TokenList*o=malloc(sizeof(TokenList));
  if(!o) fatal("Allocation failed\n");
  o->t=tokent;
  o->v=tokenv;







>







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#define MAC_BIT 0xFFCA
#define MAC_MAKE 0xFFCB
#define MAC_VERSION 0xFFE0
#define MAC_DEFINE 0xFFE1
#define MAC_INCLUDE 0xFFE2
#define MAC_CALL 0xFFE3
#define MAC_APPEND 0xFFE4
#define MAC_EDIT 0xFFE5
#define MAC_UNDEFINED 0xFFFF

static TokenList*add_macro(void) {
  TokenList*o=malloc(sizeof(TokenList));
  if(!o) fatal("Allocation failed\n");
  o->t=tokent;
  o->v=tokenv;
617
618
619
620
621
622
623

624
625
626
627
628
629
630

static void begin_macro(TokenList*mac) {
  MacroStack*ms=malloc(sizeof(MacroStack));
  TokenList**ap=0;
  int a=0;
  int b=0;
  int c=0;

  ref_macro(mac);
  if(!ms) fatal("Allocation failed\n");
  ms->tok=mac;
  ms->n=0;
  ms->args=0;
  for(;;) {
    nxttok1();







>







618
619
620
621
622
623
624
625
626
627
628
629
630
631
632

static void begin_macro(TokenList*mac) {
  MacroStack*ms=malloc(sizeof(MacroStack));
  TokenList**ap=0;
  int a=0;
  int b=0;
  int c=0;
  if(StackProtection()) fatal("Stack overflow\n");
  ref_macro(mac);
  if(!ms) fatal("Allocation failed\n");
  ms->tok=mac;
  ms->n=0;
  ms->args=0;
  for(;;) {
    nxttok1();
993
994
995
996
997
998
999





























1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
            macros=calloc(MAX_MACRO,sizeof(TokenList*));
            if(!macros) fatal("Allocation failed\n");
          }
          nxttok();
          if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
          define_macro(look_hash_mac(),0);
          goto again;





























        case MAC_UNDEFINED:
          ParseError("Undefined macro: {%s}\n",tokenstr);
          break;
        default:
          ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id);
      }
      if(main_options['M']) printf("M-\n");
    }
  }
}

static int pool_string(const char*s) {
  int i;
  for(i=0;i<num_strings;i++) if(!strcmp(s,stringpool[i])) return i;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|







995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
            macros=calloc(MAX_MACRO,sizeof(TokenList*));
            if(!macros) fatal("Allocation failed\n");
          }
          nxttok();
          if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
          define_macro(look_hash_mac(),0);
          goto again;
        case MAC_EDIT:
          if(!macros) ParseError("Cannot edit nonexistent macro\n");
          nxttok();
          if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
          n=glohash[look_hash_mac()].id;
          if(n<0xC000 || n>MAX_MACRO+0xC000-1 || !macros[n-0xC000]) ParseError("Undefined macro: {%s}\n",tokenstr);
          nxttok();
          n-=0xC000;
          if(macros[n]->t&(TF_MACRO|TF_EOF)) ParseError("Invalid edit token\n");
          free(macros[n]->str);
          macros[n]->t=tokent;
          macros[n]->v=tokenv;
          macros[n]->str=0;
          if(*tokenstr) {
            macros[n]->str=strdup(tokenstr);
            if(!macros[n]->str) fatal("Allocation failed\n");
          }
          if(main_options['M']) {
            int i;
            printf("M= @%4d %04X %08X \"",linenum,tokent,tokenv);
            for(i=0;tokenstr[i];i++) {
              if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255);
              else putchar(tokenstr[i]);
            }
            printf("\"\n");
          }
          nxttok();
          if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n");
          goto again;
        case MAC_UNDEFINED:
          ParseError("Undefined macro: {%s}\n",tokenstr);
          break;
        default:
          ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id);
      }
      if(main_options['M']) printf("M- %5d %04X %08X\n",linenum,tokent,tokenv);
    }
  }
}

static int pool_string(const char*s) {
  int i;
  for(i=0;i<num_strings;i++) if(!strcmp(s,stringpool[i])) return i;
2096
2097
2098
2099
2100
2101
2102

2103
2104
2105
2106
2107
2108
2109
  strcpy(tokenstr,"bit"); glohash[look_hash_mac()].id=MAC_BIT;
  strcpy(tokenstr,"make"); glohash[look_hash_mac()].id=MAC_MAKE;
  strcpy(tokenstr,"version"); glohash[look_hash_mac()].id=MAC_VERSION;
  strcpy(tokenstr,"define"); glohash[look_hash_mac()].id=MAC_DEFINE;
  strcpy(tokenstr,"include"); glohash[look_hash_mac()].id=MAC_INCLUDE;
  strcpy(tokenstr,"call"); glohash[look_hash_mac()].id=MAC_CALL;
  strcpy(tokenstr,"append"); glohash[look_hash_mac()].id=MAC_APPEND;

  if(main_options['L']) {
    for(;;) {
      nxttok();
      printf("** %5d %04X %08X \"",linenum,tokent,tokenv);
      for(i=0;tokenstr[i];i++) {
        if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255);
        else putchar(tokenstr[i]);







>







2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
  strcpy(tokenstr,"bit"); glohash[look_hash_mac()].id=MAC_BIT;
  strcpy(tokenstr,"make"); glohash[look_hash_mac()].id=MAC_MAKE;
  strcpy(tokenstr,"version"); glohash[look_hash_mac()].id=MAC_VERSION;
  strcpy(tokenstr,"define"); glohash[look_hash_mac()].id=MAC_DEFINE;
  strcpy(tokenstr,"include"); glohash[look_hash_mac()].id=MAC_INCLUDE;
  strcpy(tokenstr,"call"); glohash[look_hash_mac()].id=MAC_CALL;
  strcpy(tokenstr,"append"); glohash[look_hash_mac()].id=MAC_APPEND;
  strcpy(tokenstr,"edit"); glohash[look_hash_mac()].id=MAC_EDIT;
  if(main_options['L']) {
    for(;;) {
      nxttok();
      printf("** %5d %04X %08X \"",linenum,tokent,tokenv);
      for(i=0;tokenstr[i];i++) {
        if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255);
        else putchar(tokenstr[i]);

Modified class.doc from [529040a567] to [e830fb8c52].

166
167
168
169
170
171
172






173
174
175
176
177
178
179
{define <string> <tokens...>}
  Define a macro. The inner tokens are not expanded yet; they will be
  expanded during each use. A macro argument token with a single backslash
  expands to the argument in that position, while a macro argument tokens
  with multiple tokens becomes the token with one less backslash. It is
  permitted to redefine existing macros as well as new ones.







{include <string>}
  Include text from another file into this one. You cannot use {include}
  inside of another macro or in a macro argument.

{make <mode> <arg>}
  Make a synthetic token; see the below section about synthetic tokens for
  details. The second argument can be a number, or a direction or key name







>
>
>
>
>
>







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{define <string> <tokens...>}
  Define a macro. The inner tokens are not expanded yet; they will be
  expanded during each use. A macro argument token with a single backslash
  expands to the argument in that position, while a macro argument tokens
  with multiple tokens becomes the token with one less backslash. It is
  permitted to redefine existing macros as well as new ones.

{edit <string> <token>}
  Edit a macro. This changes the first token of the definition of the macro
  (which must not be another macro) to the specified token (which also must
  not be another macro). The token is expanded, and must be a single token
  once it is expanded; that is what it will be replaced with.

{include <string>}
  Include text from another file into this one. You cannot use {include}
  inside of another macro or in a macro argument.

{make <mode> <arg>}
  Make a synthetic token; see the below section about synthetic tokens for
  details. The second argument can be a number, or a direction or key name