os

An operating system
git clone https://erai.gay/code/os/
Log | Files | Refs | README | LICENSE

commit 7dbbe8ac0fb1c48750e5766fe27de673613347c8
parent 1b18d17bbfb609a4b4d0013142e05b3caa48820a
Author: erai <erai@omiltem.net>
Date:   Wed,  9 Apr 2025 16:05:12 -0400

get lexer tag names

Diffstat:
Mcc0.c | 617++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Mlexer.om | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlexlib.om | 19+++++++++++++++----
3 files changed, 598 insertions(+), 106 deletions(-)

diff --git a/cc0.c b/cc0.c @@ -96,6 +96,7 @@ u zfunc_to_ir(); u zgather_include(); u zget(); u zget_link_table(); +u zget_tag_name(); u zget_tag_table(); u zgettok(); u zhex2int(); @@ -155,6 +156,7 @@ u zlexer_compile(); u zlexer_compile_alternative(); u zlexer_compile_any(); u zlexer_compile_charset(); +u zlexer_compile_get_tag_name(); u zlexer_compile_pattern(); u zlexer_compile_primary(); u zlexer_compile_rule(); @@ -4621,6 +4623,17 @@ u zdolex(u va, u vname) { u v33 = 0; u v34 = 0; u v35 = 0; + u v36 = 0; + u v37 = 0; + u v38 = 0; + u v39 = 0; + u v40 = 0; + u v41 = 0; + u v42 = 0; + u v43 = 0; + u v44 = 0; + u v45 = 0; + u v46 = 0; v5 = (u)zsetup_lex; v6 = va; v7 = ((u(*)())v5)(v6); @@ -4646,27 +4659,45 @@ b8: v20 = (u)zgettok; v22 = ((u(*)())v20)(v21); vtok = v22; if (vtok != -1UL) goto b13; - return 0UL; + if (!*(u*)(vl + 40UL)) goto b29; + v43 = 0UL; +b30: if (!v43) goto b27; + v44 = (u)zdie; + v45 = (u)"problem"; + v46 = ((u(*)())v44)(v45); + v46; +b25: return 0UL; +b27: goto b25; +b29: v43 = 1UL; + goto b30; b13: if (vtok != 59UL) goto b16; goto b8; b16: if (vtok != 60UL) goto b19; goto b8; -b19: v23 = (u)zfputd; +b19: v23 = (u)zfputs; v24 = 0UL; - v25 = vtok; - v26 = ((u(*)())v23)(v24, v25); - v26; - v27 = (u)zfputb; - v28 = 0UL; - v29 = *(u*)(vl + 48UL) + *(u*)(vl + 56UL) * 1UL; - v30 = *(u*)(vl + 64UL) - *(u*)(vl + 56UL); - v31 = ((u(*)())v27)(v28, v29, v30); - v31; - v32 = (u)zfputc; - v33 = 0UL; - v34 = 10UL; - v35 = ((u(*)())v32)(v33, v34); - v35; + v26 = (u)zget_tag_name; + v27 = vtok; + v28 = ((u(*)())v26)(v27); + v25 = v28; + v29 = ((u(*)())v23)(v24, v25); + v29; + v30 = (u)zfputs; + v31 = 0UL; + v32 = (u)"\011'"; + v33 = ((u(*)())v30)(v31, v32); + v33; + v34 = (u)zfputb; + v35 = 0UL; + v36 = *(u*)(vl + 56UL) + *(u*)(vl + 64UL) * 1UL; + v37 = *(u*)(vl + 72UL) - *(u*)(vl + 64UL); + v38 = ((u(*)())v34)(v35, v36, v37); + v38; + v39 = (u)zfputs; + v40 = 0UL; + v41 = (u)"'\012"; + v42 = ((u(*)())v39)(v40, v41); + v42; goto b8; b5: goto b3; } @@ -19788,6 +19819,129 @@ u zget_link_table() { "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"; } +u zget_tag_name(u vtag) { + if (vtag != 1UL) goto b2; + return (u)"LEFT_BRACE"; +b2: if (vtag != 2UL) goto b4; + return (u)"RIGHT_BRACE"; +b4: if (vtag != 3UL) goto b6; + return (u)"LEFT_SQUARE"; +b6: if (vtag != 4UL) goto b8; + return (u)"RIGHT_SQUARE"; +b8: if (vtag != 5UL) goto b10; + return (u)"LEFT_PAREN"; +b10: if (vtag != 6UL) goto b12; + return (u)"RIGHT_PAREN"; +b12: if (vtag != 7UL) goto b14; + return (u)"DOT"; +b14: if (vtag != 8UL) goto b16; + return (u)"ASSIGN"; +b16: if (vtag != 9UL) goto b18; + return (u)"SEMI"; +b18: if (vtag != 10UL) goto b20; + return (u)"COLON"; +b20: if (vtag != 11UL) goto b22; + return (u)"QMARK"; +b22: if (vtag != 12UL) goto b24; + return (u)"STAR"; +b24: if (vtag != 13UL) goto b26; + return (u)"AMP"; +b26: if (vtag != 14UL) goto b28; + return (u)"COMMA"; +b28: if (vtag != 15UL) goto b30; + return (u)"BANG"; +b30: if (vtag != 16UL) goto b32; + return (u)"PLUS"; +b32: if (vtag != 17UL) goto b34; + return (u)"MINUS"; +b34: if (vtag != 18UL) goto b36; + return (u)"NOT"; +b36: if (vtag != 19UL) goto b38; + return (u)"SLASH"; +b38: if (vtag != 20UL) goto b40; + return (u)"MOD"; +b40: if (vtag != 21UL) goto b42; + return (u)"PIPE"; +b42: if (vtag != 22UL) goto b44; + return (u)"XOR"; +b44: if (vtag != 23UL) goto b46; + return (u)"AND_THEN"; +b46: if (vtag != 24UL) goto b48; + return (u)"OR_ELSE"; +b48: if (vtag != 25UL) goto b50; + return (u)"LE"; +b50: if (vtag != 26UL) goto b52; + return (u)"GE"; +b52: if (vtag != 27UL) goto b54; + return (u)"LT"; +b54: if (vtag != 28UL) goto b56; + return (u)"GT"; +b56: if (vtag != 29UL) goto b58; + return (u)"EQ"; +b58: if (vtag != 30UL) goto b60; + return (u)"NE"; +b60: if (vtag != 31UL) goto b62; + return (u)"LEFT_SHIFT"; +b62: if (vtag != 32UL) goto b64; + return (u)"RIGHT_SHIFT"; +b64: if (vtag != 33UL) goto b66; + return (u)"RETURN"; +b66: if (vtag != 34UL) goto b68; + return (u)"BREAK"; +b68: if (vtag != 35UL) goto b70; + return (u)"SIZEOF"; +b70: if (vtag != 36UL) goto b72; + return (u)"IF"; +b72: if (vtag != 37UL) goto b74; + return (u)"ELSE"; +b74: if (vtag != 38UL) goto b76; + return (u)"LOOP"; +b76: if (vtag != 39UL) goto b78; + return (u)"CONTINUE"; +b78: if (vtag != 40UL) goto b80; + return (u)"GOTO"; +b80: if (vtag != 41UL) goto b82; + return (u)"VAR"; +b82: if (vtag != 42UL) goto b84; + return (u)"ENUM"; +b84: if (vtag != 43UL) goto b86; + return (u)"STRUCT"; +b86: if (vtag != 44UL) goto b88; + return (u)"UNION"; +b88: if (vtag != 45UL) goto b90; + return (u)"BYTE"; +b90: if (vtag != 46UL) goto b92; + return (u)"INT"; +b92: if (vtag != 47UL) goto b94; + return (u)"VOID"; +b94: if (vtag != 48UL) goto b96; + return (u)"FUNC"; +b96: if (vtag != 49UL) goto b98; + return (u)"AS"; +b98: if (vtag != 50UL) goto b100; + return (u)"NIL"; +b100: if (vtag != 51UL) goto b102; + return (u)"LEX"; +b102: if (vtag != 52UL) goto b104; + return (u)"LALR"; +b104: if (vtag != 53UL) goto b106; + return (u)"IDENT"; +b106: if (vtag != 54UL) goto b108; + return (u)"HEXIDECIMAL"; +b108: if (vtag != 55UL) goto b110; + return (u)"DECIMAL"; +b110: if (vtag != 56UL) goto b112; + return (u)"STRING"; +b112: if (vtag != 57UL) goto b114; + return (u)"CHAR"; +b114: if (vtag != 58UL) goto b116; + return (u)"CHARSET"; +b116: if (vtag != 59UL) goto b118; + return (u)"SPACE"; +b118: if (vtag != 60UL) goto b120; + return (u)"COMMENT"; +b120: return 0UL; +} u zget_tag_table() { return (u)"\000\000\000\000\000\000\000\000;\000\000\000\000\000\000\000\017\000\000\000\000\000\000\000\036\000\000\000\000\000\000\000\000\000\000\000\000\000\000\0008\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\024\000\000\000\000\000\000\000\015\000\000\000\000\000\000\000\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\0009\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\005\000\000\000\000\000\000\000\006\000\000\000\000\000\000\000\014\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\016\000\000\000\000\000\000\000\021\000\000\000\000\000\000\000\007\000\000\000\000\000\000\000\023\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000<\000\000\000\000\000\000\0007\000\000\000\000\000\000\0007\000\000\000\000\000\000" @@ -19836,89 +19990,92 @@ u zgettok(u vl) { u v32 = 0; u v33 = 0; u v34 = 0; - vptr = *(u*)(vl + 64UL); - vlineno = *(u*)(vl + 112UL); - vcolno = *(u*)(vl + 120UL); - *(u*)(vl + 56UL) = vptr; - *(u*)(vl + 96UL) = vlineno; - *(u*)(vl + 104UL) = vcolno; - *(u*)(vl + 88UL) = -1UL; - *(u*)(vl + 112UL) = vlineno; - *(u*)(vl + 120UL) = vcolno; + vptr = *(u*)(vl + 72UL); + vlineno = *(u*)(vl + 120UL); + vcolno = *(u*)(vl + 128UL); + *(u*)(vl + 64UL) = vptr; + *(u*)(vl + 104UL) = vlineno; + *(u*)(vl + 112UL) = vcolno; + *(u*)(vl + 96UL) = -1UL; + *(u*)(vl + 120UL) = vlineno; + *(u*)(vl + 128UL) = vcolno; vstate = 0UL; -b1: if (vptr != *(u*)(vl + 72UL)) goto b5; - if (!*(u*)(vl + 40UL)) goto b8; -b2: return *(u*)(vl + 88UL); -b8: if ((s)(*(u*)(vl + 72UL) - *(u*)(vl + 56UL)) < (s)(*(u*)(vl + 80UL) >> 1UL)) goto b11; - *(u*)(vl + 80UL) = *(u*)(vl + 80UL) * 2UL + 256UL; +b1: if (vptr != *(u*)(vl + 80UL)) goto b5; + if (!*(u*)(vl + 48UL)) goto b8; + if (*(u*)(vl + 64UL) != *(u*)(vl + 80UL)) goto b11; + *(u*)(vl + 40UL) = 1UL; +b9:b2: return *(u*)(vl + 96UL); +b11: goto b9; +b8: if ((s)(*(u*)(vl + 80UL) - *(u*)(vl + 64UL)) < (s)(*(u*)(vl + 88UL) >> 1UL)) goto b14; + *(u*)(vl + 88UL) = *(u*)(vl + 88UL) * 2UL + 256UL; v9 = (u)zalloc; v10 = *(u*)(vl + 0UL); - v11 = *(u*)(vl + 80UL); + v11 = *(u*)(vl + 88UL); v12 = ((u(*)())v9)(v10, v11); vtmp = v12; v13 = (u)zmemcpy; v14 = vtmp; - v15 = *(u*)(vl + 48UL) + *(u*)(vl + 56UL) * 1UL; - v16 = *(u*)(vl + 72UL) - *(u*)(vl + 56UL); + v15 = *(u*)(vl + 56UL) + *(u*)(vl + 64UL) * 1UL; + v16 = *(u*)(vl + 80UL) - *(u*)(vl + 64UL); v17 = ((u(*)())v13)(v14, v15, v16); v17; v18 = (u)zfree; v19 = *(u*)(vl + 0UL); - v20 = *(u*)(vl + 48UL); + v20 = *(u*)(vl + 56UL); v21 = ((u(*)())v18)(v19, v20); v21; - *(u*)(vl + 48UL) = vtmp; - vptr = vptr - *(u*)(vl + 56UL); - *(u*)(vl + 64UL) = *(u*)(vl + 64UL) - *(u*)(vl + 56UL); - *(u*)(vl + 72UL) = *(u*)(vl + 72UL) - *(u*)(vl + 56UL); - *(u*)(vl + 56UL) = 0UL; -b9: v27 = (u)zread; + *(u*)(vl + 56UL) = vtmp; + vptr = vptr - *(u*)(vl + 64UL); + *(u*)(vl + 72UL) = *(u*)(vl + 72UL) - *(u*)(vl + 64UL); + *(u*)(vl + 80UL) = *(u*)(vl + 80UL) - *(u*)(vl + 64UL); + *(u*)(vl + 64UL) = 0UL; +b12: v27 = (u)zread; v28 = *(u*)(vl + 32UL); - v29 = *(u*)(vl + 48UL) + *(u*)(vl + 72UL) * 1UL; - v30 = *(u*)(vl + 80UL) - *(u*)(vl + 72UL); + v29 = *(u*)(vl + 56UL) + *(u*)(vl + 80UL) * 1UL; + v30 = *(u*)(vl + 88UL) - *(u*)(vl + 80UL); v31 = ((u(*)())v27)(v28, v29, v30); vret = v31; - if ((s)vret >= (s)0UL) goto b21; + if ((s)vret >= (s)0UL) goto b24; v32 = (u)zdie; v33 = (u)"read failed"; v34 = ((u(*)())v32)(v33); v34; -b19: if (vret != 0UL) goto b25; - *(u*)(vl + 40UL) = 1UL; +b22: if (vret != 0UL) goto b28; + *(u*)(vl + 48UL) = 1UL; goto b2; -b25: *(u*)(vl + 72UL) = *(u*)(vl + 72UL) + vret; -b3: vch = (u)*(b*)(*(u*)(vl + 48UL) + vptr * 1UL); +b28: *(u*)(vl + 80UL) = *(u*)(vl + 80UL) + vret; +b3: vch = (u)*(b*)(*(u*)(vl + 56UL) + vptr * 1UL); vptr = vptr + 1UL; - if (vch != 10UL) goto b28; + if (vch != 10UL) goto b31; vlineno = vlineno + 1UL; vcolno = 1UL; -b26: vstate = *(u*)(*(u*)(vl + 24UL) + (vstate * 256UL + vch) * 8UL); - if (vstate != -1UL) goto b31; +b29: vstate = *(u*)(*(u*)(vl + 24UL) + (vstate * 256UL + vch) * 8UL); + if (vstate != -1UL) goto b34; goto b2; -b31: vtag = *(u*)(*(u*)(vl + 16UL) + vstate * 8UL); - if (!vtag) goto b34; - *(u*)(vl + 88UL) = vtag; - *(u*)(vl + 64UL) = vptr; - *(u*)(vl + 112UL) = vlineno; - *(u*)(vl + 120UL) = vcolno; -b32: goto b1; -b34: goto b32; -b28: vcolno = vcolno + 1UL; - goto b26; -b21: goto b19; -b11: if ((s)*(u*)(vl + 72UL) < (s)(*(u*)(vl + 80UL) >> 1UL)) goto b16; +b34: vtag = *(u*)(*(u*)(vl + 16UL) + vstate * 8UL); + if (!vtag) goto b37; + *(u*)(vl + 96UL) = vtag; + *(u*)(vl + 72UL) = vptr; + *(u*)(vl + 120UL) = vlineno; + *(u*)(vl + 128UL) = vcolno; +b35: goto b1; +b37: goto b35; +b31: vcolno = vcolno + 1UL; + goto b29; +b24: goto b22; +b14: if ((s)*(u*)(vl + 80UL) < (s)(*(u*)(vl + 88UL) >> 1UL)) goto b19; v22 = (u)zmemcpy; - v23 = *(u*)(vl + 48UL); - v24 = *(u*)(vl + 48UL) + *(u*)(vl + 56UL) * 1UL; - v25 = *(u*)(vl + 72UL) - *(u*)(vl + 56UL); + v23 = *(u*)(vl + 56UL); + v24 = *(u*)(vl + 56UL) + *(u*)(vl + 64UL) * 1UL; + v25 = *(u*)(vl + 80UL) - *(u*)(vl + 64UL); v26 = ((u(*)())v22)(v23, v24, v25); v26; - vptr = vptr - *(u*)(vl + 56UL); - *(u*)(vl + 64UL) = *(u*)(vl + 64UL) - *(u*)(vl + 56UL); - *(u*)(vl + 72UL) = *(u*)(vl + 72UL) - *(u*)(vl + 56UL); - *(u*)(vl + 56UL) = 0UL; - goto b9; -b16: goto b9; + vptr = vptr - *(u*)(vl + 64UL); + *(u*)(vl + 72UL) = *(u*)(vl + 72UL) - *(u*)(vl + 64UL); + *(u*)(vl + 80UL) = *(u*)(vl + 80UL) - *(u*)(vl + 64UL); + *(u*)(vl + 64UL) = 0UL; + goto b12; +b19: goto b12; b5: goto b3; } u zhex2int(u vs, u vlen, u vok) { @@ -26408,36 +26565,45 @@ u zlexer_compile(u vc, u vpn, u verr) { u v21 = 0; u v22 = 0; u v23 = 0; + u v24 = 0; + u v25 = 0; + u v26 = 0; + u v27 = 0; + v6 = (u)zlexer_compile_get_tag_name; + v7 = vc; + v8 = vpn; + v9 = ((u(*)())v6)(v7, v8); + v9; vpn = *(u*)(vpn + 16UL); -b1: if (!vpn) goto b7; - v6 = 0UL; -b8: if (!v6) goto b5; - v16 = (u)zlexer_explode; - v17 = vc; - v18 = va; - v19 = ((u(*)())v16)(v17, v18); - vd = v19; - v20 = (u)zlexer_codegen; +b2: if (!vpn) goto b8; + v10 = 0UL; +b9: if (!v10) goto b6; + v20 = (u)zlexer_explode; v21 = vc; - v22 = vd; + v22 = va; v23 = ((u(*)())v20)(v21, v22); - v23; + vd = v23; + v24 = (u)zlexer_codegen; + v25 = vc; + v26 = vd; + v27 = ((u(*)())v24)(v25, v26); + v27; return 0UL; -b5: v7 = (u)zlexer_compile_rule; - v8 = vc; - v9 = vpn; - v10 = ((u(*)())v7)(v8, v9); - vb = v10; - v11 = (u)znfa_alt; +b6: v11 = (u)zlexer_compile_rule; v12 = vc; - v13 = va; - v14 = vb; - v15 = ((u(*)())v11)(v12, v13, v14); - va = v15; + v13 = vpn; + v14 = ((u(*)())v11)(v12, v13); + vb = v14; + v15 = (u)znfa_alt; + v16 = vc; + v17 = va; + v18 = vb; + v19 = ((u(*)())v15)(v16, v17, v18); + va = v19; vpn = *(u*)(vpn + 8UL); - goto b1; -b7: v6 = 1UL; - goto b8; + goto b2; +b8: v10 = 1UL; + goto b9; } u zlexer_compile_alternative(u vc, u vpn) { u vpart = 0; @@ -26668,6 +26834,251 @@ b9: *(b*)(vscratch + vj * 1UL) = 1UL; goto b5; b4: goto b2; } +u zlexer_compile_get_tag_name(u vc, u vpn) { + u varg1_type = 0; + u vargs_type = 0; + u vret_type = 0; + u vfunc_type = 0; + u vic = 0; + u vo = 0; + u va = 0; + u vb = 0; + u vthis = 0; + u vnext = 0; + u vident = 0; + u vi = 0; + u vname = 0; + u v15 = 0; + u v16 = 0; + u v17 = 0; + u v18 = 0; + u v19 = 0; + u v20 = 0; + u v21 = 0; + u v22 = 0; + u v23 = 0; + u v24 = 0; + u v25 = 0; + u v26 = 0; + u v27 = 0; + u v28 = 0; + u v29 = 0; + u v30 = 0; + u v31 = 0; + u v32 = 0; + u v33 = 0; + u v34 = 0; + u v35 = 0; + u v36 = 0; + u v37 = 0; + u v38 = 0; + u v39 = 0; + u v40 = 0; + u v41 = 0; + u v42 = 0; + u v43 = 0; + u v44 = 0; + u v45 = 0; + u v46 = 0; + u v47 = 0; + u v48 = 0; + u v49 = 0; + u v50 = 0; + u v51 = 0; + u v52 = 0; + u v53 = 0; + u v54 = 0; + u v55 = 0; + u v56 = 0; + u v57 = 0; + u v58 = 0; + u v59 = 0; + u v60 = 0; + u v61 = 0; + u v62 = 0; + u v63 = 0; + u v64 = 0; + u v65 = 0; + u v66 = 0; + u v67 = 0; + u v68 = 0; + u v69 = 0; + u v70 = 0; + u v71 = 0; + u v72 = 0; + u v73 = 0; + u v74 = 0; + u v75 = 0; + u v76 = 0; + u v77 = 0; + u v78 = 0; + u v79 = 0; + u v80 = 0; + u v81 = 0; + u v82 = 0; + u v83 = 0; + u v84 = 0; + u v85 = 0; + u v86 = 0; + u v87 = 0; + u v88 = 0; + u v89 = 0; + u v90 = 0; + u v91 = 0; + u v92 = 0; + u v93 = 0; + u v94 = 0; + u v95 = 0; + u v96 = 0; + u v97 = 0; + u v98 = 0; + u v99 = 0; + u v100 = 0; + u v101 = 0; + u v102 = 0; + u v103 = 0; + u v104 = 0; + u v105 = 0; + u v106 = 0; + u v107 = 0; + u v108 = 0; + u v109 = 0; + u v110 = 0; + u v111 = 0; + u v112 = 0; + v15 = (u)zmktype0; + v16 = vc; + v17 = 2UL; + v18 = ((u(*)())v15)(v16, v17); + varg1_type = v18; + v19 = (u)zmktype1; + v20 = vc; + v21 = 5UL; + v22 = varg1_type; + v23 = ((u(*)())v19)(v20, v21, v22); + vargs_type = v23; + v24 = (u)zmktype0; + v25 = vc; + v26 = 3UL; + v27 = ((u(*)())v24)(v25, v26); + vret_type = v27; + v28 = (u)zmktype1; + v29 = vc; + v30 = 4UL; + v31 = vret_type; + v32 = ((u(*)())v28)(v29, v30, v31); + vret_type = v32; + v33 = (u)zmktype2; + v34 = vc; + v35 = 6UL; + v36 = vret_type; + v37 = vargs_type; + v38 = ((u(*)())v33)(v34, v35, v36, v37); + vfunc_type = v38; + v39 = (u)zmkirfunc; + v40 = vc; + v41 = (u)"get_tag_name"; + v42 = ((u(*)())v39)(v40, v41); + vic = v42; + v43 = (u)ziraddarg; + v44 = vic; + v45 = (u)"tag"; + v46 = varg1_type; + v47 = ((u(*)())v43)(v44, v45, v46); + v47; + vi = 1UL; + vpn = *(u*)(vpn + 16UL); +b8: if (!vpn) goto b14; + v48 = 0UL; +b15: if (!v48) goto b12; + v100 = (u)zmkirconst; + v101 = vic; + v102 = 0UL; + v103 = ((u(*)())v100)(v101, v102); + vo = v103; + v104 = (u)zirreturn; + v105 = vic; + v106 = vo; + v107 = ((u(*)())v104)(v105, v106); + v107; + v108 = (u)zdefine_ir_func; + v109 = vc; + v110 = vic; + v111 = vfunc_type; + v112 = ((u(*)())v108)(v109, v110, v111); + v112; + return 0UL; +b12: vident = *(u*)(vpn + 16UL); + v49 = (u)zmkirblock; + v50 = vic; + v51 = ((u(*)())v49)(v50); + vthis = v51; + v52 = (u)zmkirblock; + v53 = vic; + v54 = ((u(*)())v52)(v53); + vnext = v54; + v55 = (u)zalloc; + v56 = *(u*)(vc + 0UL); + v57 = *(u*)(vident + 32UL) + 1UL; + v58 = ((u(*)())v55)(v56, v57); + vname = v58; + v59 = (u)zmemcpy; + v60 = vname; + v61 = *(u*)(vident + 24UL); + v62 = *(u*)(vident + 32UL); + v63 = ((u(*)())v59)(v60, v61, v62); + v63; + *(b*)(vname + *(u*)(vident + 32UL) * 1UL) = 0UL; + v64 = (u)zmkirop; + v65 = vic; + v66 = 0UL; + v67 = 0UL; + v68 = 0UL; + v69 = ((u(*)())v64)(v65, v66, v67, v68); + va = v69; + *(u*)(va + 24UL) = 0UL; + v70 = (u)zmkirconst; + v71 = vic; + v72 = vi; + v73 = ((u(*)())v70)(v71, v72); + vb = v73; + v74 = (u)zmkirop; + v75 = vic; + v76 = 21UL; + v77 = va; + v78 = vb; + v79 = ((u(*)())v74)(v75, v76, v77, v78); + vo = v79; + v80 = (u)zirbranch; + v81 = vic; + v82 = vo; + v83 = vnext; + v84 = vthis; + v85 = ((u(*)())v80)(v81, v82, v83, v84); + v85; + v86 = (u)zmkirstr; + v87 = vic; + v88 = vname; + v89 = *(u*)(vident + 32UL); + v90 = ((u(*)())v86)(v87, v88, v89); + vo = v90; + v91 = (u)zirreturn; + v92 = vic; + v93 = vo; + v94 = ((u(*)())v91)(v92, v93); + v94; + v95 = (u)zirjump; + v96 = vic; + v97 = vnext; + v98 = vnext; + v99 = ((u(*)())v95)(v96, v97, v98); + v99; + vpn = *(u*)(vpn + 8UL); + vi = vi + 1UL; + goto b8; +b14: v48 = 1UL; + goto b15; +} u zlexer_compile_pattern(u vc, u vpn) { u valt = 0; u va = 0; @@ -29139,14 +29550,15 @@ b3: goto b1; u zopen_lex(u vl, u vfd) { *(u*)(vl + 32UL) = vfd; *(u*)(vl + 40UL) = 0UL; - *(u*)(vl + 56UL) = 0UL; + *(u*)(vl + 48UL) = 0UL; *(u*)(vl + 64UL) = 0UL; *(u*)(vl + 72UL) = 0UL; - *(u*)(vl + 88UL) = -1UL; - *(u*)(vl + 96UL) = 1UL; + *(u*)(vl + 80UL) = 0UL; + *(u*)(vl + 96UL) = -1UL; *(u*)(vl + 104UL) = 1UL; *(u*)(vl + 112UL) = 1UL; *(u*)(vl + 120UL) = 1UL; + *(u*)(vl + 128UL) = 1UL; return 0UL; } u zopen_lines_out(u vc, u vfilename) { @@ -39283,7 +39695,7 @@ u zsetup_lex(u va) { u v10 = 0; v3 = (u)zalloc; v4 = va; - v5 = 128UL; + v5 = 136UL; v6 = ((u(*)())v3)(v4, v5); vl = v6; *(u*)(vl + 0UL) = va; @@ -39298,16 +39710,17 @@ b4: if (*(u*)(*(u*)(vl + 16UL) + vi * 8UL) != -1UL) goto b8; *(u*)(vl + 8UL) = vi; *(u*)(vl + 32UL) = 0UL; *(u*)(vl + 40UL) = 1UL; - *(u*)(vl + 48UL) = 0UL; + *(u*)(vl + 48UL) = 1UL; *(u*)(vl + 56UL) = 0UL; *(u*)(vl + 64UL) = 0UL; *(u*)(vl + 72UL) = 0UL; *(u*)(vl + 80UL) = 0UL; - *(u*)(vl + 88UL) = -1UL; - *(u*)(vl + 96UL) = 1UL; + *(u*)(vl + 88UL) = 0UL; + *(u*)(vl + 96UL) = -1UL; *(u*)(vl + 104UL) = 1UL; *(u*)(vl + 112UL) = 1UL; *(u*)(vl + 120UL) = 1UL; + *(u*)(vl + 128UL) = 1UL; return vl; b8: vi = vi + 1UL; goto b4; diff --git a/lexer.om b/lexer.om @@ -195,6 +195,8 @@ func lexer_compile(c: *compiler, pn: *peg_node, err: *file) { var b: *nfa; var d: *dfa; + lexer_compile_get_tag_name(c, pn); + pn = pn.child; loop { if !pn { @@ -1181,3 +1183,69 @@ func lexer_output(c: *compiler, cg: *dfa_codegen) { irreturn(ic, o); define_ir_func(c, ic, func_type); } + +func lexer_compile_get_tag_name(c: *compiler, pn: *peg_node) { + var arg1_type: *type; + var args_type: *type; + var ret_type: *type; + var func_type: *type; + var ic: *irfunc; + var o: *irop; + var a: *irop; + var b: *irop; + var this: *irblock; + var next: *irblock; + var ident: *peg_node; + var i: int; + var name: *byte; + + arg1_type = mktype0(c, TY_INT); + args_type = mktype1(c, TY_ARG, arg1_type); + + ret_type = mktype0(c, TY_BYTE); + ret_type = mktype1(c, TY_PTR, ret_type); + + // func(int):*byte; + func_type = mktype2(c, TY_FUNC, ret_type, args_type); + + ic = mkirfunc(c, "get_tag_name"); + + iraddarg(ic, "tag", arg1_type); + + i = 1; + + pn = pn.child; + loop { + if !pn { + break; + } + + ident = pn.child; + + this = mkirblock(ic); + next = mkirblock(ic); + + name = alloc(c.a, ident.len + 1); + memcpy(name, ident.str, ident.len); + name[ident.len] = 0 as byte; + + // `if tag == ,i { return ,tag; } + a = mkirop(ic, IOP_VAR, nil, nil); + a.n = 0; + b = mkirconst(ic, i); + o = mkirop(ic, IOP_EQ, a, b); + irbranch(ic, o, next, this); + o = mkirstr(ic, name, ident.len); + irreturn(ic, o); + + irjump(ic, next, next); + + pn = pn.next; + i = i + 1; + } + + o = mkirconst(ic, 0); + irreturn(ic, o); + + define_ir_func(c, ic, func_type); +} diff --git a/lexlib.om b/lexlib.om @@ -1,5 +1,6 @@ func get_tag_table(): *int; func get_link_table(): *int; +func get_tag_name(tag: int): *byte; struct lex { a: *alloc; @@ -10,6 +11,7 @@ struct lex { fd: int; eof: int; + goteof: int; buf: *byte; start: int; @@ -41,6 +43,7 @@ func setup_lex(a: *alloc): *lex { l.num_states = i; l.fd = 0; l.eof = 1; + l.goteof = 1; l.buf = nil; l.start = 0; l.end = 0; @@ -57,6 +60,7 @@ func setup_lex(a: *alloc): *lex { func open_lex(l: *lex, fd: int) { l.fd = fd; l.eof = 0; + l.goteof = 0; l.start = 0; l.end = 0; @@ -96,7 +100,10 @@ func gettok(l: *lex): int { state = 0; loop { if ptr == l.fill { - if l.eof { + if l.goteof { + if l.start == l.fill { + l.eof = 1; + } break; } @@ -124,7 +131,7 @@ func gettok(l: *lex): int { } if ret == 0 { - l.eof = 1; + l.goteof = 1; break; } @@ -179,8 +186,12 @@ func dolex(a: *alloc, name: *byte) { if tok == COMMENT { continue; } - fputd(nil, tok); + fputs(nil, get_tag_name(tok)); + fputs(nil, "\t'"); fputb(nil, &l.buf[l.start], l.end - l.start); - fputc(nil, '\n'); + fputs(nil, "'\n"); + } + if !l.eof { + die("problem"); } }