From b7ec37325a2478493b9b717854b88291e0afb7a1 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Thu, 3 Oct 2019 18:12:23 -0700 Subject: [PATCH 2/2] Remove trailing whitespaces in sources. 2019-10-03 Henner Zeller * src/*.[hc]: remove trailing whitespace. --- src/ios-dev.h | 2 +- src/ios.c | 70 +++++++++++++++++------------------ src/ios.h | 16 ++++---- src/pk-cmd.c | 32 ++++++++-------- src/pk-def.c | 4 +- src/pk-file.c | 8 ++-- src/pk-misc.c | 2 +- src/pk-print.c | 2 +- src/pk-set.c | 4 +- src/pk-vm.c | 10 ++--- src/pkl-anal.c | 6 +-- src/pkl-asm.c | 64 ++++++++++++++++---------------- src/pkl-asm.h | 6 +-- src/pkl-ast.c | 96 ++++++++++++++++++++++++------------------------ src/pkl-ast.h | 18 ++++----- src/pkl-env.c | 8 ++-- src/pkl-fold.c | 6 +-- src/pkl-gen.c | 72 ++++++++++++++++++------------------ src/pkl-lex.l | 8 ++-- src/pkl-parser.c | 2 +- src/pkl-pass.c | 8 ++-- src/pkl-pass.h | 4 +- src/pkl-promo.c | 46 +++++++++++------------ src/pkl-tab.y | 32 ++++++++-------- src/pkl-trans.c | 40 ++++++++++---------- src/pkl-trans.h | 2 +- src/pkl-typify.c | 76 +++++++++++++++++++------------------- src/pkl.c | 42 ++++++++++----------- src/poke.c | 10 ++--- src/pvm-alloc.h | 2 +- src/pvm-env.c | 2 +- src/pvm-val.c | 52 +++++++++++++------------- src/pvm-val.h | 6 +-- 33 files changed, 379 insertions(+), 379 deletions(-) diff --git a/src/ios-dev.h b/src/ios-dev.h index bfc6c50..7f8579d 100644 --- a/src/ios-dev.h +++ b/src/ios-dev.h @@ -79,6 +79,6 @@ struct ios_dev_if /* Write a byte to the given device at the current position. Return the character written as an int, or IOD_EOF on error. */ - + int (*put_c) (void *dev, int c); }; diff --git a/src/ios.c b/src/ios.c index c99a35e..7c1f467 100644 --- a/src/ios.c +++ b/src/ios.c @@ -106,7 +106,7 @@ ios_open (const char *handler) goto error; io->dev_if = *dev_if; - + /* Open the device using the interface found above. */ io->dev = io->dev_if->open (handler); if (io->dev == NULL) @@ -133,7 +133,7 @@ void ios_close (ios io) { struct ios *tmp; - + /* XXX: if not saved, ask before closing. */ /* Close the device operated by the IO space. @@ -152,7 +152,7 @@ ios_close (ios io) tmp->next = io->next; } free (io); - + /* Set the new current IO. */ cur_io = io_list; } @@ -204,7 +204,7 @@ ios ios_get (int n) { ios io; - + if (n < 0) return NULL; @@ -246,18 +246,18 @@ ios_read_int (ios io, ios_off offset, int flags, c = io->dev_if->get_c (io->dev); if (c == IOD_EOF) return IOS_EIOFF; - + *value = c; break; } case 16: { int16_t c1, c2; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; @@ -272,23 +272,23 @@ ios_read_int (ios io, ios_off offset, int flags, case 32: { int32_t c1, c2, c3, c4; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; - + c3 = io->dev_if->get_c (io->dev); if (c3 == IOD_EOF) return IOS_EIOFF; - + c4 = io->dev_if->get_c (io->dev); if (c4 == IOD_EOF) return IOS_EIOFF; - + if (endian == IOS_ENDIAN_LSB) *value = (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; else @@ -299,19 +299,19 @@ ios_read_int (ios io, ios_off offset, int flags, case 64: { int64_t c1, c2, c3, c4, c5, c6, c7, c8; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; - + c3 = io->dev_if->get_c (io->dev); if (c3 == IOD_EOF) return IOS_EIOFF; - + c4 = io->dev_if->get_c (io->dev); if (c4 == IOD_EOF) return IOS_EIOFF; @@ -331,7 +331,7 @@ ios_read_int (ios io, ios_off offset, int flags, c8 = io->dev_if->get_c (io->dev); if (c8 == IOD_EOF) return IOS_EIOFF; - + if (endian == IOS_ENDIAN_LSB) *value = (c8 << 56) | (c7 << 48) | (c6 << 40) | (c5 << 32) | (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; else @@ -372,18 +372,18 @@ ios_read_uint (ios io, ios_off offset, int flags, c = io->dev_if->get_c (io->dev); if (c == IOD_EOF) return IOS_EIOFF; - + *value = c; break; } case 16: { int16_t c1, c2; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; @@ -398,23 +398,23 @@ ios_read_uint (ios io, ios_off offset, int flags, case 32: { int32_t c1, c2, c3, c4; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; - + c3 = io->dev_if->get_c (io->dev); if (c3 == IOD_EOF) return IOS_EIOFF; - + c4 = io->dev_if->get_c (io->dev); if (c4 == IOD_EOF) return IOS_EIOFF; - + if (endian == IOS_ENDIAN_LSB) *value = (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; else @@ -425,19 +425,19 @@ ios_read_uint (ios io, ios_off offset, int flags, case 64: { int64_t c1, c2, c3, c4, c5, c6, c7, c8; - + c1 = io->dev_if->get_c (io->dev); if (c1 == IOD_EOF) return IOS_EIOFF; - + c2 = io->dev_if->get_c (io->dev); if (c2 == IOD_EOF) return IOS_EIOFF; - + c3 = io->dev_if->get_c (io->dev); if (c3 == IOD_EOF) return IOS_EIOFF; - + c4 = io->dev_if->get_c (io->dev); if (c4 == IOD_EOF) return IOS_EIOFF; @@ -457,7 +457,7 @@ ios_read_uint (ios io, ios_off offset, int flags, c8 = io->dev_if->get_c (io->dev); if (c8 == IOD_EOF) return IOS_EIOFF; - + if (endian == IOS_ENDIAN_LSB) *value = (c8 << 56) | (c7 << 48) | (c6 << 40) | (c5 << 32) | (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; else @@ -499,7 +499,7 @@ ios_read_string (ios io, ios_off offset, int flags, char **value) str[i] = (char) c; } while (str[i++] != '\0'); - + *value = str; return IOS_OK; } @@ -522,7 +522,7 @@ ios_write_int (ios io, ios_off offset, int flags, case 32: { int32_t c1, c2, c3, c4; - + c1 = (value >> 24) & 0xff; c2 = (value >> 16) & 0xff; c3 = (value >> 8) & 0xff; @@ -543,7 +543,7 @@ ios_write_int (ios io, ios_off offset, int flags, if (io->dev_if->put_c (io->dev, c4) == IOD_EOF) return IOS_EIOFF; - + break; } case 64: @@ -628,7 +628,7 @@ ios_write_uint (ios io, ios_off offset, int flags, case 32: { int32_t c1, c2, c3, c4; - + c1 = (value >> 24) & 0xff; c2 = (value >> 16) & 0xff; c3 = (value >> 8) & 0xff; @@ -649,7 +649,7 @@ ios_write_uint (ios io, ios_off offset, int flags, if (io->dev_if->put_c (io->dev, c4) == IOD_EOF) return IOS_EIOFF; - + break; } case 64: diff --git a/src/ios.h b/src/ios.h index 3e68ad5..f5fdccf 100644 --- a/src/ios.h +++ b/src/ios.h @@ -35,17 +35,17 @@ void ios_shutdown (void); "IO spaces" "IO devices" Space of IO objects <=======> Space of bytes - - +------+ + + +------+ +----->| File | +-------+ | +------+ - | IO | | + | IO | | | space |<-----+ +---------+ | | +----->| Process | +-------+ | +---------+ - + : : - + | +-------------+ +----->| File system | +-------------+ @@ -97,10 +97,10 @@ typedef int64_t ios_off; there are no spaces open: space1 -> space2 -> ... -> spaceN - + ^ | - + current The functions declared below are used to manage this @@ -183,7 +183,7 @@ void ios_map (ios_map_fn cb, void *data); that reflects the state of the requested operation. The following values are supported, as well as the more generic IOS_OK and IOS_ERROR, */ - + #define IOS_EIOFF -2 /* The provided offset is invalid. This happens for example when the offset translates into a byte offset that exceeds the capacity of the diff --git a/src/pk-cmd.c b/src/pk-cmd.c index 680d5f6..8c560d8 100644 --- a/src/pk-cmd.c +++ b/src/pk-cmd.c @@ -276,7 +276,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) if (prefix != NULL) printf ("%s ", prefix); printf (_("%s: command not found.\n"), cmd_name); - return 0; + return 0; } /* Process user flags. */ @@ -312,7 +312,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) goto usage; return pk_cmd_exec_1 (p, *cmd->subtrie, cmd_name); } - + /* Parse arguments. */ argc = 0; a = cmd->arg_fmt; @@ -333,13 +333,13 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) { if (*a == '?') a++; - + /* Try the different options, in order, until one succeeds or the next argument or the end of the input is found. */ while (*a != ',' && *a != '\0') { char *beg = p; - + switch (*a) { case 'e': @@ -365,7 +365,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) messages, so don't bother the user with the usage message. */ besilent = 1; - + break; } case 'i': @@ -382,7 +382,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) match = 1; } } - + break; case 'a': /* Parse an address. */ @@ -396,7 +396,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) match = 1; } } - + break; case 't': /* Parse a #N tag. */ @@ -412,7 +412,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) match = 1; } } - + break; case 's': { @@ -420,7 +420,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) char *end, *str; size_t size; - + end = skip_blanks (p); while (*end != '\0' && *end != ',') end++; @@ -501,16 +501,16 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) /* This should NOT happen. */ assert (0); } - + if (match) break; - + /* Rewind input and try next option. */ p = beg; a++; } } - + /* Boo, could not find valid input for this argument. */ if (!match) goto usage; @@ -565,7 +565,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char *prefix) || argv[i].type == PK_CMD_ARG_STMT) pvm_destroy_program (argv[i].val.prog); } - + return ret; usage: @@ -597,7 +597,7 @@ pk_cmd_exec (char *str) /* If the first non-blank character in STR is a dot ('.'), then this is a poke command. Dispatch it with pk_cmd_exec_1. Otherwise, compile a Poke declaration or a statement and execute it. */ - + char *cmd = skip_blanks (str); if (*cmd == '.') @@ -647,7 +647,7 @@ pk_cmd_exec (char *str) fputc ('\n', stdout); } } - + return 1; error: @@ -689,7 +689,7 @@ pk_cmd_exec_script (const char *filename) int c = fgetc (fd); assert (i < MAX_LINE); - + if (c == EOF) { line[i] = '\0'; diff --git a/src/pk-def.c b/src/pk-def.c index d487736..9330d0a 100644 --- a/src/pk-def.c +++ b/src/pk-def.c @@ -50,7 +50,7 @@ print_var_decl (pkl_ast_node decl, void *data) val = pvm_env_lookup (runtime_env, back, over); assert (val != PVM_NULL); - + /* Print the name and the current value of the variable. */ fputs (PKL_AST_IDENTIFIER_POINTER (decl_name), stdout); fputs ("\t\t", stdout); @@ -82,7 +82,7 @@ print_fun_decl (pkl_ast_node decl, void *data) if (PKL_AST_CODE (func) != PKL_AST_FUNC) return; - + assert (pkl_env_lookup (compiler_env, PKL_AST_IDENTIFIER_POINTER (decl_name), &back, &over) != NULL); diff --git a/src/pk-file.c b/src/pk-file.c index 3f6de5f..8a0667e 100644 --- a/src/pk-file.c +++ b/src/pk-file.c @@ -62,17 +62,17 @@ pk_cmd_file (int argc, struct pk_cmd_arg argv[], uint64_t uflags) printf (_("%s: file cannot be read\n"), arg_str); return 0; } - + strcpy (filename, "file://"); strcat (filename, arg_str); - + if (ios_search (filename) != NULL) { printf (_("File %s already opened. Use `file #N' to switch.\n"), filename); return 0; } - + ios_open (filename); free (filename); } @@ -121,7 +121,7 @@ pk_cmd_close (int argc, struct pk_cmd_arg argv[], uint64_t uflags) ios_handler (ios_cur ())); } } - + return 1; } diff --git a/src/pk-misc.c b/src/pk-misc.c index c0281cd..85a1b13 100644 --- a/src/pk-misc.c +++ b/src/pk-misc.c @@ -34,7 +34,7 @@ pk_cmd_exit (int argc, struct pk_cmd_arg argv[], uint64_t uflags) code = 0; else code = (int) PK_CMD_ARG_INT (argv[0]); - + if (poke_interactive_p) { /* XXX: if unsaved changes, ask and save. */ diff --git a/src/pk-print.c b/src/pk-print.c index afc76bf..da47c34 100644 --- a/src/pk-print.c +++ b/src/pk-print.c @@ -67,7 +67,7 @@ pk_cmd_print (int argc, struct pk_cmd_arg argv[], uint64_t uflags) if (uflags & PK_PRINT_F_MAP) pflags |= PVM_PRINT_F_MAPS; - + pvm_ret = pvm_run (poke_vm, prog, &val); if (pvm_ret != PVM_EXIT_OK) goto rterror; diff --git a/src/pk-set.c b/src/pk-set.c index 0364763..7dbfd02 100644 --- a/src/pk-set.c +++ b/src/pk-set.c @@ -41,7 +41,7 @@ pk_cmd_set_obase (int argc, struct pk_cmd_arg argv[], uint64_t uflags) fputs ("error: obase should be one of 2, 8, 10 or 16.\n", stdout); return 0; } - + poke_obase = base; return 1; } @@ -78,7 +78,7 @@ pk_cmd_set_endian (int argc, struct pk_cmd_arg argv[], uint64_t uflags) else { enum ios_endian endian; - + if (STREQ (arg, "little")) endian = IOS_ENDIAN_LSB; else if (STREQ (arg, "big")) diff --git a/src/pk-vm.c b/src/pk-vm.c index 67569e4..11a4550 100644 --- a/src/pk-vm.c +++ b/src/pk-vm.c @@ -32,7 +32,7 @@ pk_cmd_vm_disas_exp (int argc, struct pk_cmd_arg argv[], uint64_t uflags) /* disassemble expression EXP. */ pvm_program prog; - + assert (argc == 1); assert (PK_CMD_ARG_TYPE (argv[0]) == PK_CMD_ARG_EXP); @@ -60,10 +60,10 @@ pk_cmd_vm_disas_fun (int argc, struct pk_cmd_arg argv[], uint64_t uflags) pkl_env compiler_env = pkl_get_env (poke_compiler); pvm_env runtime_env = pvm_get_env (poke_vm); - + assert (argc == 1); assert (PK_CMD_ARG_TYPE (argv[0]) == PK_CMD_ARG_STR); - + fname = PK_CMD_ARG_STR (argv[0]); decl = pkl_env_lookup (compiler_env, fname, @@ -90,7 +90,7 @@ pk_cmd_vm_disas_fun (int argc, struct pk_cmd_arg argv[], uint64_t uflags) JITTER_OBJDUMP, NULL); else pvm_print_program (stdout, prog); - + return 1; } @@ -152,7 +152,7 @@ pk_cmd_vm_disas_writ (int argc, struct pk_cmd_arg argv[], uint64_t uflags) } program = PVM_VAL_CLS_PROGRAM (writer); - + if (uflags & PK_VM_DIS_F_NAT) pvm_disassemble_program (program, true, JITTER_OBJDUMP, NULL); diff --git a/src/pkl-anal.c b/src/pkl-anal.c index 68e7561..fce4784 100644 --- a/src/pkl-anal.c +++ b/src/pkl-anal.c @@ -64,7 +64,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_struct) pkl_ast_node t; for (t = elems; t; t = PKL_AST_CHAIN (t)) - { + { pkl_ast_node ename = PKL_AST_STRUCT_FIELD_NAME (t); pkl_ast_node u; @@ -110,7 +110,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_type_struct) { pkl_ast_node tname = PKL_AST_STRUCT_FIELD_TYPE_NAME (u); pkl_ast_node uname = PKL_AST_STRUCT_FIELD_TYPE_NAME (t); - + if (uname && tname && STREQ (PKL_AST_IDENTIFIER_POINTER (uname), @@ -192,7 +192,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_funcall) /* If arguments are named, check that there are not arguments named twice. */ if (some_named) - { + { for (funcall_arg = PKL_AST_FUNCALL_ARGS (funcall); funcall_arg; funcall_arg = PKL_AST_CHAIN (funcall_arg)) diff --git a/src/pkl-asm.c b/src/pkl-asm.c index dbbea21..8fb2332 100644 --- a/src/pkl-asm.c +++ b/src/pkl-asm.c @@ -43,7 +43,7 @@ pkl_asm_dotimes (pasm, exp); { ... level-1 ... - + pkl_asm_if (pasm, exp); { ... level-2 ... @@ -62,7 +62,7 @@ PARENT is the parent level, i.e. the level containing this one. This is NULL at the top-level. - + The meaning of the LABEL* and NODE* fields depend on the particular kind of environment. See the details in the implementation of the functions below. */ @@ -254,7 +254,7 @@ pkl_asm_insn_atoa (pkl_asm pasm, /* Both array types are unbounded, hence they are identical => no need to do anything. */ return; - + /* No checks are due in this case, but the value itself should be typed as an unbound array. */ pkl_asm_insn (pasm, PKL_INSN_PUSH, PVM_NULL); /* ARR NULL */ @@ -322,10 +322,10 @@ pkl_asm_insn_nton (pkl_asm pasm, { size_t from_type_size = PKL_AST_TYPE_I_SIZE (from_type); int from_type_sign = PKL_AST_TYPE_I_SIGNED (from_type); - + size_t to_type_size = PKL_AST_TYPE_I_SIZE (to_type); int to_type_sign = PKL_AST_TYPE_I_SIGNED (to_type); - + if (from_type_size == to_type_size && from_type_sign == to_type_sign) { @@ -396,7 +396,7 @@ static void pkl_asm_insn_write (pkl_asm pasm) { RAS_MACRO_WRITE; -} +} /* Macro-instruction: PEEK type, endian, nenc ( -- VAL ) @@ -535,7 +535,7 @@ pkl_asm_insn_poked (pkl_asm pasm, pkl_ast_node type) Macro-instruction: ADD type ( VAL VAL -- VAL VAL VAL ) - + Macro-instruction: SUB type ( VAL VAL -- VAL VAL VAL ) @@ -547,7 +547,7 @@ pkl_asm_insn_poked (pkl_asm pasm, pkl_ast_node type) Macro-instruction: MOD type ( VAL VAL -- VAL VAL VAL ) - + Macro-instruction: BNOT type ( VAL -- VAL VAL VAL ) @@ -637,7 +637,7 @@ pkl_asm_insn_intop (pkl_asm pasm, pkl_asm_insn (pasm, div_table[tl][signed_p]); else pkl_asm_insn (pasm, mod_table[tl][signed_p]); - + break; case PKL_INSN_BNOT: pkl_asm_insn (pasm, bnot_table[tl][signed_p]); @@ -667,10 +667,10 @@ pkl_asm_insn_intop (pkl_asm pasm, Macro-instruction: NE type ( VAL VAL -- INT ) - + Macro-instruction: LT type ( VAL VAL -- INT ) - + Macro-instruction: GT type ( VAL VAL -- INT ) @@ -690,7 +690,7 @@ pkl_asm_insn_cmp (pkl_asm pasm, pkl_ast_node type) { enum pkl_asm_insn oinsn; - + /* Decide what instruction to assembly. */ if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_STRING) { @@ -710,18 +710,18 @@ pkl_asm_insn_cmp (pkl_asm pasm, { static int eq_table[2][2] = {{ PKL_INSN_EQIU, PKL_INSN_EQI }, { PKL_INSN_EQLU, PKL_INSN_EQL }}; - + static int ne_table[2][2] = {{ PKL_INSN_NEIU, PKL_INSN_NEI }, { PKL_INSN_NELU, PKL_INSN_NEL }}; static int lt_table[2][2] = {{ PKL_INSN_LTIU, PKL_INSN_LTI }, { PKL_INSN_LTLU, PKL_INSN_LTL }}; - + static int gt_table[2][2] = {{ PKL_INSN_GTIU, PKL_INSN_GTI }, { PKL_INSN_GTLU, PKL_INSN_GTL }}; - + static int ge_table[2][2] = {{ PKL_INSN_GEIU, PKL_INSN_GEI }, { PKL_INSN_GELU, PKL_INSN_GEL }}; - + static int le_table[2][2] = {{ PKL_INSN_LEIU, PKL_INSN_LEI }, { PKL_INSN_LELU, PKL_INSN_LEL }}; @@ -772,7 +772,7 @@ pkl_asm_insn_gcd (pkl_asm pasm, pkl_ast_node type) { RAS_MACRO_GCD (type); } - + /* Macro-instruction: ADDO base_type ( OFF OFF -- OFF OFF OFF ) @@ -931,7 +931,7 @@ pkl_asm_new (pkl_ast ast, pkl_compiler compiler, pasm->pointers = pvm_alloc (sizeof (void*) * PKL_AST_MAX_POINTERS); memset (pasm->pointers, 0, PKL_AST_MAX_POINTERS); pasm->next_pointer = 0; - + if (prologue) { /* Standard prologue. */ @@ -972,7 +972,7 @@ pkl_asm_finish (pkl_asm pasm, int epilogue, void **pointers) /* Successful program finalization. */ pkl_asm_insn (pasm, PKL_INSN_POPE); pkl_asm_insn (pasm, PKL_INSN_PUSH, pvm_make_int (PVM_EXIT_OK, 32)); - pkl_asm_insn (pasm, PKL_INSN_EXIT); + pkl_asm_insn (pasm, PKL_INSN_EXIT); pvm_append_label (pasm->program, pasm->error_label); @@ -993,17 +993,17 @@ pkl_asm_finish (pkl_asm pasm, int epilogue, void **pointers) /* Set the exit status to ERROR and exit the PVM. */ pkl_asm_insn (pasm, PKL_INSN_PUSH, pvm_make_int (PVM_EXIT_ERROR, 32)); - pkl_asm_insn (pasm, PKL_INSN_EXIT); + pkl_asm_insn (pasm, PKL_INSN_EXIT); pkl_asm_note (pasm, "#end epilogue"); - } + } if (pointers != NULL) *pointers = pasm->pointers; /* Free the first level. */ pkl_asm_poplevel (pasm); - + /* Free the assembler instance and return the assembled program to the user. */ free (pasm); @@ -1029,7 +1029,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...) #define PKL_DEF_INSN(SYM, ARGS, NAME) ARGS, # include "pkl-insn.def" #undef PKL_DEF_INSN - }; + }; va_list valist; @@ -1066,7 +1066,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...) for (p = insn_args[insn]; *p != '\0'; ++p) { char arg_class = *p; - + switch (arg_class) { case 'v': @@ -1412,7 +1412,7 @@ pkl_asm_endif (pkl_asm pasm) { assert (pasm->level->current_env == PKL_ASM_ENV_CONDITIONAL); pvm_append_label (pasm->program, pasm->level->label2); - + /* Cleanup and pop the current level. */ pkl_ast_node_free (pasm->level->node1); pkl_asm_poplevel (pasm); @@ -1459,14 +1459,14 @@ pkl_asm_catch (pkl_asm pasm) /* XXX pkl_asm_note (pasm, "POP-REGISTERS"); */ pkl_asm_insn (pasm, PKL_INSN_BA, pasm->level->label2); pvm_append_label (pasm->program, pasm->level->label1); - + /* At this point the exception number is at the top of the stack. If the catch block received an argument, push a new environment and set it as a local. Otherwise, just discard it. */ - + if (pasm->level->node1) { - pkl_asm_insn (pasm, PKL_INSN_PUSHF); + pkl_asm_insn (pasm, PKL_INSN_PUSHF); pkl_asm_insn (pasm, PKL_INSN_REGVAR); } else @@ -1501,7 +1501,7 @@ pkl_asm_endtry (pkl_asm pasm) label2: POP the condition expression break_label: - + Thus, loops use two labels. */ void @@ -1533,7 +1533,7 @@ pkl_asm_endloop (pkl_asm pasm) pkl_asm_insn (pasm, PKL_INSN_DROP); pvm_append_label (pasm->program, pasm->level->break_label); - + /* Cleanup and pop the current level. */ pkl_asm_poplevel (pasm); } @@ -1552,7 +1552,7 @@ pkl_asm_endloop (pkl_asm pasm) REGVAR ; CONTAINER SEL ; CONTAINER NELEMS PUSH 0UL ; CONTAINER NELEMS 0 - SWAP ; CONTAINER 0 NELEMS + SWAP ; CONTAINER 0 NELEMS PUSH NULL ; CONTAINER 0 NELEMS NULL label2: DROP ; CONTAINER I NELEMS @@ -1690,7 +1690,7 @@ pkl_asm_call (pkl_asm pasm, const char *funcname) { pkl_env compiler_env = pkl_get_env (pasm->compiler); int back, over; - + assert (pkl_env_lookup (compiler_env, funcname, &back, &over) != NULL); diff --git a/src/pkl-asm.h b/src/pkl-asm.h index 4b0c455..5e1e687 100644 --- a/src/pkl-asm.h +++ b/src/pkl-asm.h @@ -116,13 +116,13 @@ void pkl_asm_endif (pkl_asm pasm); /* While loops. * * pkl_asm_while (pasm); - * + * * ... condition ... * * pkl_asm_loop (pasm); * * ... loop body ... - * + * * pkl_asm_end_loop (pasm); */ @@ -157,7 +157,7 @@ void pkl_asm_for_endloop (pkl_asm pasm); /* Try-catch blocks. * * pkl_asm_try (pasm); - * + * * ... stmt ... * * pkl_asm_catch (pasm); diff --git a/src/pkl-ast.c b/src/pkl-ast.c index 7595ed4..30aa804 100644 --- a/src/pkl-ast.c +++ b/src/pkl-ast.c @@ -41,7 +41,7 @@ pkl_ast_default_endian (void) /* Allocate and return a new AST node, with the given CODE. The rest of the node is initialized to zero. */ - + static pkl_ast_node pkl_ast_make_node (pkl_ast ast, enum pkl_ast_code code) @@ -80,7 +80,7 @@ pkl_ast_chainon (pkl_ast_node ast1, pkl_ast_node ast2) /* Build and return an AST node for an integer constant. */ -pkl_ast_node +pkl_ast_node pkl_ast_make_integer (pkl_ast ast, uint64_t value) { @@ -88,13 +88,13 @@ pkl_ast_make_integer (pkl_ast ast, PKL_AST_INTEGER_VALUE (new) = value; PKL_AST_LITERAL_P (new) = 1; - + return new; } /* Build and return an AST node for a string constant. */ -pkl_ast_node +pkl_ast_node pkl_ast_make_string (pkl_ast ast, const char *str) { @@ -125,7 +125,7 @@ pkl_ast_make_identifier (pkl_ast ast, /* Build and return an AST node for an enumerator. */ -pkl_ast_node +pkl_ast_node pkl_ast_make_enumerator (pkl_ast ast, pkl_ast_node identifier, pkl_ast_node value) @@ -160,7 +160,7 @@ pkl_ast_make_cond_exp (pkl_ast ast, PKL_AST_LITERAL_P (cond_exp) = PKL_AST_LITERAL_P (thenexp) && PKL_AST_LITERAL_P (elseexp); - + return cond_exp; } @@ -219,7 +219,7 @@ pkl_ast_make_unary_exp (pkl_ast ast, PKL_AST_EXP_NUMOPS (exp) = 1; PKL_AST_EXP_OPERAND (exp, 0) = ASTREF (op); PKL_AST_LITERAL_P (exp) = PKL_AST_LITERAL_P (op); - + return exp; } @@ -311,7 +311,7 @@ pkl_ast_make_struct_ref (pkl_ast ast, PKL_AST_STRUCT_REF_STRUCT (sref) = ASTREF (sct); PKL_AST_STRUCT_REF_IDENTIFIER (sref) = ASTREF (identifier); - + return sref; } @@ -515,10 +515,10 @@ pkl_ast_node pkl_ast_dup_type (pkl_ast_node type) { pkl_ast_node t, new = pkl_ast_make_type (PKL_AST_AST (type)); - + PKL_AST_TYPE_CODE (new) = PKL_AST_TYPE_CODE (type); PKL_AST_TYPE_COMPLETE (new) = PKL_AST_TYPE_COMPLETE (type); - + switch (PKL_AST_TYPE_CODE (type)) { case PKL_TYPE_ANY: @@ -647,7 +647,7 @@ pkl_ast_type_equal (pkl_ast_node a, pkl_ast_node b) return 0; } } - + return pkl_ast_type_equal (PKL_AST_TYPE_A_ETYPE (a), PKL_AST_TYPE_A_ETYPE (b)); break; @@ -680,7 +680,7 @@ pkl_ast_type_equal (pkl_ast_node a, pkl_ast_node b) if (PKL_AST_FUNC_TYPE_ARG_VARARG (fa) != PKL_AST_FUNC_TYPE_ARG_VARARG (fb)) return 0; - + if (!pkl_ast_type_equal (PKL_AST_FUNC_TYPE_ARG_TYPE (fa), PKL_AST_FUNC_TYPE_ARG_TYPE (fb))) return 0; @@ -834,7 +834,7 @@ int pkl_ast_type_is_complete (pkl_ast_node type) { int complete = PKL_AST_TYPE_COMPLETE_UNKNOWN; - + switch (PKL_AST_TYPE_CODE (type)) { /* Integral, offset and struct types are always complete. */ @@ -920,7 +920,7 @@ pkl_print_type (FILE *out, pkl_ast_node type, int use_given_name) case PKL_TYPE_ARRAY: { pkl_ast_node bound = PKL_AST_TYPE_A_BOUND (type); - + pkl_print_type (out, PKL_AST_TYPE_A_ETYPE (type), use_given_name); fputc ('[', out); @@ -968,7 +968,7 @@ pkl_print_type (FILE *out, pkl_ast_node type, int use_given_name) if (PKL_AST_TYPE_F_NARG (type) > 0) { fputc ('(', out); - + for (t = PKL_AST_TYPE_F_ARGS (type); t; t = PKL_AST_CHAIN (t)) { @@ -986,7 +986,7 @@ pkl_print_type (FILE *out, pkl_ast_node type, int use_given_name) fputc ('?', out); } } - + fputc (')', out); } @@ -1013,7 +1013,7 @@ pkl_print_type (FILE *out, pkl_ast_node type, int use_given_name) fprintf (out, "%" PRIu64, PKL_AST_INTEGER_VALUE (unit)); else assert (0); - + fputc ('>', out); break; } @@ -1168,7 +1168,7 @@ pkl_ast_make_offset (pkl_ast ast, pkl_ast_node offset = pkl_ast_make_node (ast, PKL_AST_OFFSET); assert (unit); - + if (magnitude != NULL) PKL_AST_OFFSET_MAGNITUDE (offset) = ASTREF (magnitude); PKL_AST_OFFSET_UNIT (offset) = ASTREF (unit); @@ -1414,7 +1414,7 @@ pkl_ast_make_loop_stmt (pkl_ast ast, pkl_ast_node condition, PKL_AST_LOOP_STMT_ITERATOR (loop_stmt) = ASTREF (iterator); if (container) PKL_AST_LOOP_STMT_CONTAINER (loop_stmt) = ASTREF (container); - + PKL_AST_LOOP_STMT_BODY (loop_stmt) = ASTREF (body); return loop_stmt; @@ -1565,7 +1565,7 @@ pkl_ast_node_free (pkl_ast_node ast) { pkl_ast_node t, n; size_t i; - + if (ast == NULL) return; @@ -1586,7 +1586,7 @@ pkl_ast_node_free (pkl_ast_node ast) n = PKL_AST_CHAIN (t); pkl_ast_node_free (t); } - + break; case PKL_AST_EXP: @@ -1595,18 +1595,18 @@ pkl_ast_node_free (pkl_ast_node ast) pkl_ast_node_free (PKL_AST_EXP_OPERAND (ast, i)); break; - + case PKL_AST_COND_EXP: pkl_ast_node_free (PKL_AST_COND_EXP_COND (ast)); pkl_ast_node_free (PKL_AST_COND_EXP_THENEXP (ast)); pkl_ast_node_free (PKL_AST_COND_EXP_ELSEEXP (ast)); break; - + case PKL_AST_ENUM: pkl_ast_node_free (PKL_AST_ENUM_TAG (ast)); - + for (t = PKL_AST_ENUM_VALUES (ast); t; t = n) { n = PKL_AST_CHAIN (t); @@ -1614,13 +1614,13 @@ pkl_ast_node_free (pkl_ast_node ast) } break; - + case PKL_AST_ENUMERATOR: pkl_ast_node_free (PKL_AST_ENUMERATOR_IDENTIFIER (ast)); pkl_ast_node_free (PKL_AST_ENUMERATOR_VALUE (ast)); break; - + case PKL_AST_TYPE: free (PKL_AST_TYPE_NAME (ast)); @@ -1665,7 +1665,7 @@ pkl_ast_node_free (pkl_ast_node ast) default: break; } - + break; case PKL_AST_STRUCT_FIELD_TYPE: @@ -1681,7 +1681,7 @@ pkl_ast_node_free (pkl_ast_node ast) pkl_ast_node_free (PKL_AST_FUNC_TYPE_ARG_TYPE (ast)); pkl_ast_node_free (PKL_AST_FUNC_TYPE_ARG_NAME (ast)); break; - + case PKL_AST_INDEXER: pkl_ast_node_free (PKL_AST_INDEXER_ENTITY (ast)); @@ -1714,23 +1714,23 @@ pkl_ast_node_free (pkl_ast_node ast) pkl_ast_node_free (PKL_AST_FUNC_ARG_IDENTIFIER (ast)); pkl_ast_node_free (PKL_AST_FUNC_ARG_INITIAL (ast)); break; - + case PKL_AST_STRING: free (PKL_AST_STRING_POINTER (ast)); break; - + case PKL_AST_IDENTIFIER: free (PKL_AST_IDENTIFIER_POINTER (ast)); break; - + case PKL_AST_STRUCT_REF: pkl_ast_node_free (PKL_AST_STRUCT_REF_STRUCT (ast)); pkl_ast_node_free (PKL_AST_STRUCT_REF_IDENTIFIER (ast)); break; - + case PKL_AST_STRUCT_FIELD: pkl_ast_node_free (PKL_AST_STRUCT_FIELD_NAME (ast)); @@ -1745,7 +1745,7 @@ pkl_ast_node_free (pkl_ast_node ast) pkl_ast_node_free (t); } break; - + case PKL_AST_ARRAY_INITIALIZER: pkl_ast_node_free (PKL_AST_ARRAY_INITIALIZER_INDEX (ast)); @@ -1759,7 +1759,7 @@ pkl_ast_node_free (pkl_ast_node ast) n = PKL_AST_CHAIN (t); pkl_ast_node_free (t); } - + break; case PKL_AST_DECL: @@ -1786,7 +1786,7 @@ pkl_ast_node_free (pkl_ast_node ast) pkl_ast_node_free (PKL_AST_ISA_TYPE (ast)); pkl_ast_node_free (PKL_AST_ISA_EXP (ast)); break; - + case PKL_AST_MAP: pkl_ast_node_free (PKL_AST_MAP_TYPE (ast)); @@ -1807,7 +1807,7 @@ pkl_ast_node_free (pkl_ast_node ast) n = PKL_AST_CHAIN (t); pkl_ast_node_free (t); } - + break; case PKL_AST_FUNCALL_ARG: @@ -1897,7 +1897,7 @@ pkl_ast_node_free (pkl_ast_node ast) case PKL_AST_BREAK_STMT: break; - + case PKL_AST_RAISE_STMT: pkl_ast_node_free (PKL_AST_RAISE_STMT_EXP (ast)); @@ -1909,7 +1909,7 @@ pkl_ast_node_free (pkl_ast_node ast) case PKL_AST_INTEGER: /* Fallthrough. */ break; - + default: assert (0); } @@ -1939,7 +1939,7 @@ pkl_ast_free (pkl_ast ast) { if (ast == NULL) return; - + pkl_ast_node_free (ast->ast); free (ast->buffer); free (ast->filename); @@ -2204,7 +2204,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) { pkl_ast_node child; size_t i; - + if (ast == NULL) { IPRINTF ("NULL::\n"); @@ -2223,7 +2223,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) PKL_AST_LOC (ast).last_column); \ } \ while (0) - + switch (PKL_AST_CODE (ast)) { case PKL_AST_PROGRAM: @@ -2314,7 +2314,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) IPRINTF ("elems:\n"); PRINT_AST_SUBAST_CHAIN (STRUCT_FIELDS); break; - + case PKL_AST_ARRAY_INITIALIZER: IPRINTF ("ARRAY_INITIALIZER::\n"); @@ -2410,7 +2410,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) case PKL_AST_STRUCT_FIELD_TYPE: IPRINTF ("STRUCT_FIELD_TYPE::\n"); - PRINT_COMMON_FIELDS; + PRINT_COMMON_FIELDS; PRINT_AST_SUBAST (name, STRUCT_FIELD_TYPE_NAME); PRINT_AST_SUBAST (type, STRUCT_FIELD_TYPE_TYPE); PRINT_AST_SUBAST (exp, STRUCT_FIELD_TYPE_CONSTRAINT); @@ -2425,7 +2425,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) PRINT_AST_SUBAST (type, FUNC_TYPE_ARG_NAME); PRINT_AST_IMM (optional, FUNC_TYPE_ARG_OPTIONAL, "%d"); break; - + case PKL_AST_TRIMMER: IPRINTF ("TRIMMER::\n"); PRINT_AST_SUBAST (from, TRIMMER_FROM); @@ -2460,7 +2460,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) PRINT_AST_SUBAST (identifier, FUNC_ARG_IDENTIFIER); PRINT_AST_IMM (vararg, FUNC_ARG_VARARG, "%d"); break; - + case PKL_AST_STRUCT_REF: IPRINTF ("STRUCT_REF::\n"); @@ -2551,7 +2551,7 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) PRINT_AST_IMM (back, VAR_BACK, "%d"); PRINT_AST_IMM (over, VAR_OVER, "%d"); break; - + case PKL_AST_COMP_STMT: IPRINTF ("COMP_STMT::\n"); @@ -2644,10 +2644,10 @@ pkl_ast_print_1 (FILE *fd, pkl_ast_node ast, int indent) case PKL_AST_NULL_STMT: IPRINTF ("NULL_STMT::\n"); - + PRINT_COMMON_FIELDS; break; - + default: IPRINTF ("UNKNOWN:: code=%d\n", PKL_AST_CODE (ast)); break; diff --git a/src/pkl-ast.h b/src/pkl-ast.h index 1f0558e..3aa323b 100644 --- a/src/pkl-ast.h +++ b/src/pkl-ast.h @@ -282,7 +282,7 @@ pkl_ast_node pkl_ast_make_program (pkl_ast ast, pkl_ast_node declarations); /* PKL_AST_IDENTIFIER nodes represent identifiers in PKL programs. - + POINTER must point to a NULL-terminated string. LENGTH contains the size in bytes of the identifier @@ -432,7 +432,7 @@ pkl_ast_node pkl_ast_make_struct_field (pkl_ast ast, The supported operators are specified in pkl-ops.def. The supported attributes are defined in pkl-attrs.def. - + In PKL_AST_OP_ATTR exprssions, ATTR contains the code for the invoked attribute. @@ -628,7 +628,7 @@ pkl_ast_node pkl_ast_make_func_arg (pkl_ast ast, pkl_ast_node init); /* PKL_AST_TRIMMER nodes represent a trim of an array, or a string. - + ENTITY is either an array or a string, which is the subject of the trim. @@ -705,7 +705,7 @@ pkl_ast_node pkl_ast_make_struct_ref (pkl_ast ast, element has no name. TYPE is a PKL_AST_TYPE node. - + CONSTRAINT is a constraint associated with the struct field. It is an expression that should evaluate to a boolean. @@ -764,7 +764,7 @@ pkl_ast_node pkl_ast_make_func_type_arg (pkl_ast ast, pkl_ast_node type, pkl_ast_node name); /* PKL_AST_TYPE nodes represent type expressions. - + If NAME is not NULL, then this specific type instance has a given name, which is encoded in a PKL_AST_IDENTIFIER node. @@ -841,7 +841,7 @@ struct pkl_ast_type union pkl_ast_node *name; enum pkl_ast_type_code code; int complete; - + union { struct @@ -883,7 +883,7 @@ struct pkl_ast_type union pkl_ast_node *args; union pkl_ast_node *first_opt_arg; } fun; - + } val; }; @@ -993,7 +993,7 @@ pkl_ast_node pkl_ast_id_to_offset_unit (pkl_ast ast, pkl_ast_node id); /* PKL_AST_CAST nodes represent casts at the language level. - + TYPE is the target type in the case. EXP is the expression whole value should be casted to the targe type. */ @@ -1361,7 +1361,7 @@ pkl_ast_node pkl_ast_make_exp_stmt (pkl_ast ast, pkl_ast_node exp); TYPE, if specified, is the argument to the catch clause. The type of the argument must be a signed 32-bit type, which is the type used to denote exception types. - + EXP, if specified, is an expression evaluating to a 32-bit integer. Exceptions having any other type won't be catched by the `catch' clause of the statement. diff --git a/src/pkl-env.c b/src/pkl-env.c index 0e4072f..7a315e5 100644 --- a/src/pkl-env.c +++ b/src/pkl-env.c @@ -43,7 +43,7 @@ struct pkl_env int num_types; int num_vars; - + struct pkl_env *up; }; @@ -109,7 +109,7 @@ register_decl (pkl_hash hash_table, pkl_ast_node decl) { int hash; - + if (get_registered (hash_table, name) != NULL) /* Already registered. */ return 0; @@ -239,7 +239,7 @@ pkl_env_map_decls (pkl_env env, for (i = 0; i < HASH_TABLE_SIZE; ++i) { pkl_ast_node t = env->hash_table[i]; - + for (; t; t = PKL_AST_CHAIN2 (t)) { if ((what == PKL_AST_DECL_KIND_ANY @@ -274,6 +274,6 @@ pkl_env_dup_toplevel (pkl_env env) new->num_types = env->num_types; new->num_vars = env->num_vars; - + return new; } diff --git a/src/pkl-fold.c b/src/pkl-fold.c index 2a16f18..684723f 100644 --- a/src/pkl-fold.c +++ b/src/pkl-fold.c @@ -39,7 +39,7 @@ The letter-codes after EMUL_ specify the number and kind of arguments that the operations receive and return. The type of the returned value comes last. - + So, for example, EMUL_III declares an int64 OP int64 -> int64 operation, whereas EMUL_SSI declares a string OP string -> int64 operation. */ @@ -553,7 +553,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_fold_div) && PKL_AST_INTEGER_VALUE (magnitude) == 0) goto divbyzero; } - + OP_BINARY_III (div); OP_BINARY_OOI (divo); @@ -584,7 +584,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_fold_mod) && PKL_AST_INTEGER_VALUE (magnitude) == 0) goto divbyzero; } - + OP_BINARY_III (mod); OP_BINARY_OOO (modo); diff --git a/src/pkl-gen.c b/src/pkl-gen.c index 9a15ec8..d42d6ba 100644 --- a/src/pkl-gen.c +++ b/src/pkl-gen.c @@ -46,7 +46,7 @@ PKL_GEN_PAYLOAD->ASM[++(PKL_GEN_PAYLOAD->cur_##ASM)] = (new_pasm); \ } \ while (0) - + #define PKL_GEN_PUSH_ASM(new_pasm) PKL_GEN_PUSH_AN_ASM(pasm,new_pasm) #define PKL_GEN_PUSH_ASM2(new_pasm) PKL_GEN_PUSH_AN_ASM(pasm2,new_pasm) @@ -100,7 +100,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_program) && PKL_AST_PROGRAM_ELEMS (PKL_PASS_NODE) && PKL_AST_CODE (PKL_AST_PROGRAM_ELEMS (PKL_PASS_NODE)) == PKL_AST_EXP_STMT)) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, PVM_NULL); - + PKL_GEN_PAYLOAD->program = pkl_asm_finish (PKL_GEN_ASM, 1 /* prologue */, &PKL_GEN_PAYLOAD->pointers); @@ -127,21 +127,21 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_decl) pvm_val mapper_closure; pvm_val writer_closure; pvm_val constructor_closure; - + pkl_ast_node type_struct = initial; pkl_ast_node type_struct_fields = PKL_AST_TYPE_S_ELEMS (type_struct); pkl_ast_node field; - + /* Compile the struct closures and complete them using the current environment. */ - + PKL_GEN_PAYLOAD->in_writer = 1; RAS_FUNCTION_STRUCT_WRITER (writer_closure); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, writer_closure); /* CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC); /* CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DROP); /* _ */ PKL_GEN_PAYLOAD->in_writer = 0; - + PKL_GEN_PAYLOAD->in_mapper = 1; RAS_FUNCTION_STRUCT_MAPPER (mapper_closure); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, mapper_closure); /* CLS */ @@ -169,9 +169,9 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_decl) { pvm_val mapper_closure; pvm_val writer_closure; - + pkl_ast_node array_type = initial; - + /* Compile the arrays closures and complete them using the current environment. */ @@ -181,7 +181,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_decl) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC); /* CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DROP); /* _ */ PKL_GEN_PAYLOAD->in_writer = 0; - + PKL_GEN_PAYLOAD->in_mapper = 1; RAS_FUNCTION_ARRAY_MAPPER (mapper_closure); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, mapper_closure); /* CLS */ @@ -334,7 +334,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_comp_stmt) if (PKL_AST_COMP_STMT_BUILTIN (comp_stmt) == PKL_AST_BUILTIN_NONE) /* Push a frame into the environment. */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSHF); - + } PKL_PHASE_END_HANDLER @@ -407,7 +407,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_ass_stmt) case PKL_AST_STRUCT_REF: { jitter_label label = pkl_asm_fresh_label (PKL_GEN_ASM); - + valmapper = PVM_NULL; /* XXX PKL_AST_TYPE_S_VALMAPPER (lvalue_type) */ /* We need to get the value (array element, or struct field) @@ -428,7 +428,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_ass_stmt) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSHR, 0); /* LVALUE IDX VAL EXP */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_SWAP); /* LVALUE IDX EXP VAL */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_MGETM); /* LVALUE IDX EXP VAL MCLS */ - pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_BN, label); /* LVALUE IDX EXP VAL MCLS */ + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_BN, label); /* LVALUE IDX EXP VAL MCLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DROP); /* LVALUE IDX EXP VAL */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_MGETO); /* LVALUE IDX EXP VAL OFFSET */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NROT); /* LVALUE IDX OFFSET EXP VAL */ @@ -460,7 +460,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_ass_stmt) default: break; } - + /* All right, now assign the resulting rvalue to the lvalue. */ switch (PKL_AST_CODE (lvalue)) { @@ -604,7 +604,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_loop_stmt) else if (iterator && container) { pkl_ast_node container_type = PKL_AST_TYPE (container); - + /* This is a FOR-IN[-WHERE] loop. */ pkl_asm_for (PKL_GEN_ASM, PKL_AST_TYPE_CODE (container_type), @@ -671,7 +671,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_return_stmt) if (PKL_AST_TYPE_CODE (PKL_AST_TYPE_F_RTYPE (function_type)) == PKL_TYPE_VOID) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, PVM_NULL); - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_RETURN); } PKL_PHASE_END_HANDLER @@ -715,7 +715,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_print_stmt) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, pvm_make_string (prefix)); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PRINTS); } - + for (arg = print_stmt_args; arg; arg = PKL_AST_CHAIN (arg)) { /* Print the argument, and the optional suffix. */ @@ -785,7 +785,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_try_catch_stmt) PKL_PASS_SUBPASS (catch_exp); else pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, pvm_make_int (0, 32)); - + pkl_asm_try (PKL_GEN_ASM, catch_arg); { PKL_PASS_SUBPASS (code); @@ -826,7 +826,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_funcall) int vararg = PKL_AST_TYPE_F_VARARG (function_type); int i, aindex = 0, vararg_actual = 0, optionals_specified = 0; pkl_ast_node aa; - + /* Push the actuals to the stack. */ for (aa = PKL_AST_FUNCALL_ARGS (funcall); aa; aa = PKL_AST_CHAIN (aa)) { @@ -854,7 +854,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_funcall) else PKL_PASS_SUBPASS (aa); } - + if (vararg) { if (aindex == 0) @@ -862,12 +862,12 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_funcall) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, PVM_NULL); /* Array offset. */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, pvm_make_any_type ()); } - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, pvm_make_ulong (aindex, 64)); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DUP); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_MKA); } - + /* Complete non-specified actuals for formals having default values. For these, we should push nulls. But beware the vararg! */ { @@ -942,7 +942,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_func) { PKL_GEN_PAYLOAD->in_array_bounder = 1; PKL_PASS_SUBPASS (rtype); - PKL_GEN_PAYLOAD->in_array_bounder = 0; + PKL_GEN_PAYLOAD->in_array_bounder = 0; } } } @@ -998,7 +998,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_func_arg) pkl_asm_insn (pasm, PKL_INSN_ATOA, NULL /* from_type */, func_arg_type); } - + pkl_asm_label (PKL_GEN_ASM, after_conv_label); /* Pop the actual argument from the stack and put it in the current @@ -1036,7 +1036,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_func) pvm_make_int (PVM_E_NO_RETURN, 32)); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_RAISE); } - + /* Pop the function's argument environment, if any, and return. */ if (PKL_AST_FUNC_ARGS (function)) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_POPF, 1); @@ -1077,7 +1077,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_integer) else val = pvm_make_uint (value, size); } - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, val); } PKL_PHASE_END_HANDLER @@ -1356,7 +1356,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_map) pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_RAISE); pkl_asm_label (PKL_GEN_ASM, label); } - + PKL_PASS_BREAK; } PKL_PHASE_END_HANDLER @@ -1761,7 +1761,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_type_array) RAS_FUNCTION_ARRAY_MAPPER (mapper_closure); PKL_GEN_PAYLOAD->in_mapper = 0; PKL_GEN_PAYLOAD->in_valmapper = 1; - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, mapper_closure); /* VAL OFF CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC); /* VAL OFF CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP); /* VAL CLS */ @@ -1842,7 +1842,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_type_array) else { pvm_val writer_closure; - + /* Compile a writer function to a closure. */ RAS_FUNCTION_ARRAY_WRITER (writer_closure); @@ -1864,7 +1864,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_type_array) if (PKL_AST_TYPE_CODE (etype) == PKL_TYPE_ARRAY) PKL_PASS_SUBPASS (etype); - + RAS_FUNCTION_ARRAY_BOUNDER (bounder_closure); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, bounder_closure); /* CLS */ pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC); /* CLS */ @@ -2084,7 +2084,7 @@ PKL_PHASE_END_HANDLER PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_type_struct) { /* We are generating a PVM struct type. */ - + pkl_ast_node struct_type = PKL_PASS_NODE; pkl_ast_node type_name = PKL_AST_TYPE_NAME (struct_type); @@ -2095,7 +2095,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_type_struct) pvm_make_string (PKL_AST_IDENTIFIER_POINTER (type_name))); else pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, PVM_NULL); - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_MKTYSCT); } PKL_PHASE_END_HANDLER @@ -2130,12 +2130,12 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_struct_field_type) PKL_PASS_SUBPASS (PKL_AST_STRUCT_FIELD_TYPE_NAME (PKL_PASS_NODE)); PKL_PASS_SUBPASS (PKL_AST_STRUCT_FIELD_TYPE_TYPE (PKL_PASS_NODE)); } - + PKL_PASS_BREAK; } PKL_PHASE_END_HANDLER -/* +/* * Expression handlers. * * | OPERAND1 @@ -2216,7 +2216,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_mul) pkl_asm_insn (pasm, PKL_INSN_NIP2); break; case PKL_TYPE_OFFSET: - { + { pkl_ast_node op1 = PKL_AST_EXP_OPERAND (node, 0); pkl_ast_node op2 = PKL_AST_EXP_OPERAND (node, 1); pkl_ast_node op1_type = PKL_AST_TYPE (op1); @@ -2329,7 +2329,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_intexp) assert (0); break; } - + switch (PKL_AST_TYPE_CODE (type)) { case PKL_TYPE_INTEGRAL: @@ -2496,7 +2496,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_attr) case PKL_TYPE_STRUCT: { jitter_label label = pkl_asm_fresh_label (PKL_GEN_ASM); - + pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_MGETO); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP); pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_BNN, label); diff --git a/src/pkl-lex.l b/src/pkl-lex.l index 31d0dc1..91b612e 100644 --- a/src/pkl-lex.l +++ b/src/pkl-lex.l @@ -139,7 +139,7 @@ D [0-9] {NEWLINE} { /* Ignore newlines. */ } {BLANK} { /* Ignore whitespace. */ } -"/*" { BEGIN(C_COMMENT); } +"/*" { BEGIN(C_COMMENT); } "*/" { BEGIN(INITIAL); } . { } \n { } @@ -295,7 +295,7 @@ D [0-9] } base = pkl_lex_get_base (yytext, &offset); - + /* Note that strtol can't fail in this context. */ value = strtoll (yytext + offset, &end, base); @@ -337,7 +337,7 @@ D [0-9] yylval->ast = pkl_ast_make_integer (yyextra->ast, value); PKL_AST_TYPE (yylval->ast) = ASTREF (type); - return INTEGER; + return INTEGER; } {CHAR} { @@ -379,7 +379,7 @@ D [0-9] yylval->ast = pkl_ast_make_integer (yyextra->ast, value); PKL_AST_TYPE (yylval->ast) = ASTREF (type); - return CHAR; + return CHAR; } {STRING} { diff --git a/src/pkl-parser.c b/src/pkl-parser.c index 0a811a0..8581c81 100644 --- a/src/pkl-parser.c +++ b/src/pkl-parser.c @@ -36,7 +36,7 @@ pkl_parser_init (void) parser = xmalloc (sizeof (struct pkl_parser)); memset (parser, 0, sizeof (struct pkl_parser)); - + pkl_tab_lex_init (&(parser->scanner)); pkl_tab_set_extra (parser, parser->scanner); diff --git a/src/pkl-pass.c b/src/pkl-pass.c index 2789347..1ca25a4 100644 --- a/src/pkl-pass.c +++ b/src/pkl-pass.c @@ -142,7 +142,7 @@ pkl_call_node_handlers (jmp_buf toplevel, if (node_code == PKL_AST_EXP) { int opcode = PKL_AST_EXP_CODE (node); - + switch (opcode) { #define PKL_DEF_OP(ocode, str) \ @@ -183,7 +183,7 @@ pkl_call_node_handlers (jmp_buf toplevel, Refresh the code. */ node_code = PKL_AST_CODE (node); } - + /* Call the phase handlers defined for node codes, in the given order. */ if (order == PKL_PASS_PRE_ORDER) @@ -319,7 +319,7 @@ pkl_do_pass_1 (jmp_buf toplevel, PKL_PASS (PKL_AST_TRIMMER_FROM (node)); if (PKL_AST_TRIMMER_TO (node)) PKL_PASS (PKL_AST_TRIMMER_TO (node)); - + break; case PKL_AST_INDEXER: PKL_PASS (PKL_AST_INDEXER_ENTITY (node)); @@ -365,7 +365,7 @@ pkl_do_pass_1 (jmp_buf toplevel, case PKL_AST_SCONS: PKL_PASS (PKL_AST_SCONS_TYPE (node)); PKL_PASS (PKL_AST_SCONS_VALUE (node)); - + break; case PKL_AST_TYPE: { diff --git a/src/pkl-pass.h b/src/pkl-pass.h index 74cf793..07adbfa 100644 --- a/src/pkl-pass.h +++ b/src/pkl-pass.h @@ -178,7 +178,7 @@ typedef struct pkl_phase *pkl_phase; starting at NODE. The subpass shares the same payloads than the current pass. If the execution of the subpass returns an error then the expansion of this macro calls PKL_PASS_ERROR. - + PKL_PASS_EXIT can be used in order to interrupt the execution of the compiler pass, making `pkl_do_pass' to return a non-error code. @@ -284,7 +284,7 @@ pkl_phase_parent_in (pkl_ast_node parent, /* Traverse the given AST, applying the provided phases (or transformations) in sequence to each AST node. - + PHASES is a NULL-terminated array of pointers to node handlers. PAYLOADS is an array of pointers to payloads, which will be passed diff --git a/src/pkl-promo.c b/src/pkl-promo.c index e304a48..48dc217 100644 --- a/src/pkl-promo.c +++ b/src/pkl-promo.c @@ -40,7 +40,7 @@ promote_integral (pkl_ast ast, int *restart) { pkl_ast_node type = PKL_AST_TYPE (*a); - + *restart = 0; if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_INTEGRAL) { @@ -50,7 +50,7 @@ promote_integral (pkl_ast ast, pkl_ast_node desired_type = pkl_ast_make_integral_type (ast, size, sign); pkl_ast_loc loc = PKL_AST_LOC (*a); - + *a = pkl_ast_make_cast (ast, desired_type, ASTDEREF (*a)); PKL_AST_TYPE (*a) = ASTREF (desired_type); PKL_AST_LOC (*a) = loc; @@ -61,7 +61,7 @@ promote_integral (pkl_ast ast, return 1; } - + return 0; } @@ -76,7 +76,7 @@ promote_offset (pkl_ast ast, int *restart) { pkl_ast_node a_type = PKL_AST_TYPE (*a); - + *restart = 0; if (PKL_AST_TYPE_CODE (a_type) == PKL_TYPE_OFFSET) { @@ -116,7 +116,7 @@ promote_offset (pkl_ast ast, return 1; } - + return 0; } @@ -139,7 +139,7 @@ promote_array (pkl_ast ast, pkl_ast_node from_bound = PKL_AST_TYPE_A_BOUND (from_type); *restart = 0; - + /* Note that at this point it is assured (by typify1) that the array element types of both arrays are equivalent. XXX but not really, because the bounds in contained arrays may be different!! We @@ -164,7 +164,7 @@ promote_array (pkl_ast ast, performed even if there is not an actual check. */ { pkl_ast_loc loc = PKL_AST_LOC (*a); - + *a = pkl_ast_make_cast (ast, type, ASTDEREF (*a)); PKL_AST_TYPE (*a) = ASTREF (type); PKL_AST_LOC (*a) = loc; @@ -172,7 +172,7 @@ promote_array (pkl_ast ast, *restart = 1; return 1; } - + return 0; } @@ -199,7 +199,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_div) pkl_ast_node op1_type = PKL_AST_TYPE (op1); pkl_ast_node op2 = PKL_AST_EXP_OPERAND (exp, 1); pkl_ast_node op2_type = PKL_AST_TYPE (op2); - + /* Note we discriminate on the first operand type in order to distinguish between configurations. */ switch (PKL_AST_TYPE_CODE (op1_type)) @@ -290,7 +290,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_add_sub_mod) size_t size = PKL_AST_TYPE_I_SIZE (type); int sign = PKL_AST_TYPE_I_SIGNED (type); - + if (!promote_integral (PKL_PASS_AST, size, sign, &PKL_AST_EXP_OPERAND (exp, 0), &restart1)) goto error; @@ -433,7 +433,7 @@ PKL_PHASE_END_HANDLER INTEGRAL x INTEGRAL -> BOOL STRING x STRING -> BOOL OFFSET x OFFSET -> BOOL - + In the I x I -> I configuration, the types of the operands are promoted in a way both operands end having the same type, following the language's promotion rules. @@ -454,7 +454,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_rela) if (PKL_AST_TYPE_CODE (op1_type) != PKL_AST_TYPE_CODE (op2_type)) goto error; - + switch (PKL_AST_TYPE_CODE (op1_type)) { case PKL_TYPE_INTEGRAL: @@ -540,7 +540,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_bshift) { size_t size = PKL_AST_TYPE_I_SIZE (type); int sign = PKL_AST_TYPE_I_SIGNED (type); - + if (!promote_integral (PKL_PASS_AST, size, sign, &PKL_AST_EXP_OPERAND (exp, 0), &restart1) || !promote_integral (PKL_PASS_AST, 32, 0, @@ -577,7 +577,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_binary) { size_t size = PKL_AST_TYPE_I_SIZE (type); int sign = PKL_AST_TYPE_I_SIGNED (type); - + if (!promote_integral (PKL_PASS_AST, size, sign, &PKL_AST_EXP_OPERAND (exp, 0), &restart1) || !promote_integral (PKL_PASS_AST, size, sign, @@ -688,7 +688,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_type_array) pkl_ast_node array_type = PKL_PASS_NODE; pkl_ast_node bound = PKL_AST_TYPE_A_BOUND (array_type); pkl_ast_node bound_type; - + if (bound == NULL) /* This array type hasn't a number of elements. Be done. */ PKL_PASS_DONE; @@ -831,7 +831,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_ass_stmt) if (PKL_AST_TYPE_CODE (lvalue_type) != PKL_TYPE_ARRAY && pkl_ast_type_equal (lvalue_type, exp_type)) PKL_PASS_DONE; - + /* A promotion is needed. */ switch (PKL_AST_TYPE_CODE (lvalue_type)) { @@ -874,7 +874,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_ass_stmt) PKL_PASS_ERROR; break; } - + PKL_PASS_RESTART = restart; PKL_PASS_DONE; @@ -1009,7 +1009,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_return_stmt) if (PKL_AST_TYPE_CODE (expected_type) != PKL_TYPE_VOID) { int restart = 0; - + switch (PKL_AST_TYPE_CODE (expected_type)) { case PKL_TYPE_ANY: @@ -1172,7 +1172,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_func_arg) PKL_PASS_DONE; - error: + error: pkl_ice (PKL_PASS_AST, PKL_AST_LOC (initial), "couldn't promote argument initializer"); PKL_PASS_ERROR; @@ -1216,7 +1216,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_struct_field_type) { pkl_ast_node constraint_type = PKL_AST_TYPE (elem_constraint); int restart = 0; - + switch (PKL_AST_TYPE_CODE (constraint_type)) { case PKL_TYPE_INTEGRAL: @@ -1234,7 +1234,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_struct_field_type) "non-promoteable struct field constraint at promo time"); PKL_PASS_ERROR; break; - } + } PKL_PASS_RESTART = restart; } @@ -1243,7 +1243,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_struct_field_type) { pkl_ast_node label_type = PKL_AST_TYPE (elem_label); int restart = 0; - + switch (PKL_AST_TYPE_CODE (label_type)) { case PKL_TYPE_OFFSET: @@ -1268,7 +1268,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_struct_field_type) "non-promoteable struct field label at promo time"); PKL_PASS_ERROR; break; - } + } PKL_PASS_RESTART = PKL_PASS_RESTART || restart; } diff --git a/src/pkl-tab.y b/src/pkl-tab.y index 99c406e..1a02f64 100644 --- a/src/pkl-tab.y +++ b/src/pkl-tab.y @@ -52,9 +52,9 @@ #endif #define scanner (pkl_parser->scanner) - + /* YYLLOC_DEFAULT -> default code for computing locations. */ - + #define PKL_AST_CHILDREN_STEP 12 /* Convert a YYLTYPE value into an AST location and return it. */ @@ -81,14 +81,14 @@ pkl_register_arg (struct pkl_parser *parser, pkl_ast_node arg) pkl_ast_node dummy = pkl_ast_make_integer (parser->ast, 0); PKL_AST_TYPE (dummy) = ASTREF (PKL_AST_FUNC_ARG_TYPE (arg)); - + arg_decl = pkl_ast_make_decl (parser->ast, PKL_AST_DECL_KIND_VAR, arg_identifier, dummy, NULL /* source */); PKL_AST_LOC (arg_decl) = PKL_AST_LOC (arg); - + if (!pkl_env_register (parser->env, PKL_AST_IDENTIFIER_POINTER (arg_identifier), arg_decl)) @@ -157,7 +157,7 @@ pkl_register_dummies (struct pkl_parser *parser, int n) char *name; pkl_ast_node id; pkl_ast_node decl; - + asprintf (&name, "@*UNUSABLE_OFF_%d*@", i); id = pkl_ast_make_identifier (parser->ast, name); decl = pkl_ast_make_decl (parser->ast, @@ -688,7 +688,7 @@ primary: $$ = $1; PKL_AST_LOC ($$) = @$; PKL_AST_LOC (PKL_AST_TYPE ($$)) = @$; - } + } | '(' expression ')' { $$ = $2; @@ -886,7 +886,7 @@ function_arg: PKL_AST_LOC (type) = @1; PKL_AST_LOC (array_type) = @1; - + $$ = pkl_ast_make_func_arg (pkl_parser->ast, array_type, $1, @@ -981,7 +981,7 @@ offset_type_specifier: ; array_type_specifier: - simple_type_specifier '[' ']' + simple_type_specifier '[' ']' { $$ = pkl_ast_make_array_type (pkl_parser->ast, $1, NULL /* bound */); @@ -1040,7 +1040,7 @@ function_type_arg: PKL_AST_LOC (type) = @1; PKL_AST_LOC (array_type) = @1; - + $$ = pkl_ast_make_func_type_arg (pkl_parser->ast, array_type, NULL /* name */); PKL_AST_LOC ($$) = @$; @@ -1112,7 +1112,7 @@ struct_field_type: $2, dummy, NULL /* source */); PKL_AST_LOC (decl) = @$; - + if (!pkl_env_register (pkl_parser->env, PKL_AST_IDENTIFIER_POINTER ($2), decl)) @@ -1212,7 +1212,7 @@ declaration: PKL_AST_DECL_INITIAL ($3) = ASTREF ($5); $$ = $3; - + /* If the reference counting of the declaration is bigger than 1, this means there are recursive calls in the function body. Reset the refcount @@ -1290,7 +1290,7 @@ comp_stmt: { $$ = pkl_ast_make_comp_stmt (pkl_parser->ast, $3); PKL_AST_LOC ($$) = @$; - + /* Pop the frame pushed by the `pushlevel' above. */ pkl_parser->env = pkl_env_pop_frame (pkl_parser->env); } @@ -1299,7 +1299,7 @@ comp_stmt: $$ = pkl_ast_make_builtin (pkl_parser->ast, PKL_AST_BUILTIN_RAND); PKL_AST_LOC ($$) = @$; - + /* Pop the frame pushed by the `pushlevel' above. */ pkl_parser->env = pkl_env_pop_frame (pkl_parser->env); } @@ -1417,14 +1417,14 @@ stmt: pkl_ast_node dummy = pkl_ast_make_integer (pkl_parser->ast, 0); PKL_AST_LOC (dummy) = @3; - + $$ = pkl_ast_make_decl (pkl_parser->ast, PKL_AST_DECL_KIND_VAR, $3, dummy, pkl_parser->filename); PKL_AST_LOC ($$) = @3; - + if (!pkl_env_register (pkl_parser->env, PKL_AST_IDENTIFIER_POINTER ($3), $$)) @@ -1548,7 +1548,7 @@ print_stmt_arg_list: pkl_ast_node arg = pkl_ast_make_print_stmt_arg (pkl_parser->ast, $3); PKL_AST_LOC (arg) = @3; - + $$ = pkl_ast_chainon ($1, arg); } ; diff --git a/src/pkl-trans.c b/src/pkl-trans.c index 2b3e26d..4b6415e 100644 --- a/src/pkl-trans.c +++ b/src/pkl-trans.c @@ -76,7 +76,7 @@ static int pkl_trans_in_functions (pkl_ast_node functions[], pkl_trans_in_functions (PKL_TRANS_PAYLOAD->functions, \ PKL_TRANS_PAYLOAD->next_function, \ (function)) - + #define PKL_TRANS_PUSH_FUNCTION(function) \ do \ { \ @@ -232,14 +232,14 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_array) PKL_AST_LOC (initializer_index_type) = PKL_AST_LOC (tmp); - + initializer_index_node = pkl_ast_make_integer (PKL_PASS_AST, index); PKL_AST_TYPE (initializer_index_node) = ASTREF (initializer_index_type); PKL_AST_LOC (initializer_index_node) = PKL_AST_LOC (tmp); - + PKL_AST_ARRAY_INITIALIZER_INDEX (tmp) = ASTREF (initializer_index_node); @@ -268,7 +268,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_array) PKL_AST_INTEGER_VALUE (initializer_index_node) = effective_index; } - + index += elems_appended; nelem += elems_appended; } @@ -282,7 +282,7 @@ PKL_PHASE_END_HANDLER a type expressing its unit. This handler takes care of the first case, replacing the identifier with a suitable unit factor. If the identifier is invalid, then an error is raised. - + Also, if the magnitude of the offset wasn't specified then it defaults to 1. */ @@ -421,7 +421,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_var) pkl_ast_node funcall = pkl_ast_make_funcall (PKL_PASS_AST, ASTDEREF (var), NULL /* args */); - + PKL_AST_LOC (funcall) = PKL_AST_LOC (var); PKL_PASS_NODE = funcall; PKL_PASS_RESTART = 1; @@ -490,7 +490,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string) new_string_pointer[i] = p[0]; } new_string_pointer[i] = '\0'; - + free (string_pointer); PKL_AST_STRING_POINTER (string) = new_string_pointer; } @@ -727,11 +727,11 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt) case 'u': { unsigned int bits; - + if (p[2] >= '0' && p[2] <= '9') { int base_idx; - + if (p[3] >= '0' && p[3] <= '9') { bits = (p[2] - '0') * 10 + (p[3] - '0'); @@ -742,13 +742,13 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt) bits = p[2] - '0'; base_idx = 3; } - + if (bits > 64) { msg = _("Base with more than 64 bits"); goto invalid_tag; } - + switch (p[base_idx]) { case 'b': PKL_AST_PRINT_STMT_ARG_BASE (arg) = 2; break; @@ -767,12 +767,12 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt) msg = _("invalid base"); goto invalid_tag; } - + atype = pkl_ast_make_integral_type (PKL_PASS_AST, bits, p[1] == 'i'); PKL_AST_LOC (atype) = PKL_AST_LOC (print_fmt); types = pkl_ast_chainon (types, atype); - + if (base_idx == 4) p += 5; else @@ -788,7 +788,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt) default: msg = _("invalid format specifier"); goto invalid_tag; - } + } /* Add the optional suffix to the argument. */ if (*p != '%') @@ -862,7 +862,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans2_ps_exp) { pkl_ast_node exp = PKL_PASS_NODE; int o, literal_p = 1; - + for (o = 0; o < PKL_AST_EXP_NUMOPS (exp); ++o) { pkl_ast_node op = PKL_AST_EXP_OPERAND (exp, o); @@ -899,7 +899,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans2_ps_array) { pkl_ast_node array_initializer_exp = PKL_AST_ARRAY_INITIALIZER_EXP (t); - + literal_p &= PKL_AST_LITERAL_P (array_initializer_exp); if (!literal_p) break; @@ -934,7 +934,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans2_ps_struct) { pkl_ast_node t; int literal_p = 1; - + for (t = PKL_AST_STRUCT_FIELDS (PKL_PASS_NODE); t; t = PKL_AST_CHAIN (t)) { @@ -1039,14 +1039,14 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans3_ps_op_sizeof) PKL_PASS_ERROR; } - { + { /* Calculate the size of the complete type in bytes and put it in an integer node. */ pkl_ast_node magnitude = pkl_ast_sizeof_type (PKL_PASS_AST, op); PKL_AST_LOC (magnitude) = PKL_AST_LOC (node); PKL_AST_LOC (PKL_AST_TYPE (magnitude)) = PKL_AST_LOC (node); - + /* Build an offset with that magnitude, and unit bits. */ unit_type = pkl_ast_make_integral_type (PKL_PASS_AST, 64, 0); PKL_AST_LOC (unit_type) = PKL_AST_LOC (node); @@ -1054,7 +1054,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans3_ps_op_sizeof) unit = pkl_ast_make_integer (PKL_PASS_AST, PKL_AST_OFFSET_UNIT_BITS); PKL_AST_LOC (unit) = PKL_AST_LOC (node); PKL_AST_TYPE (unit) = ASTREF (unit_type); - + offset = pkl_ast_make_offset (PKL_PASS_AST, magnitude, unit); PKL_AST_LOC (offset) = PKL_AST_LOC (node); diff --git a/src/pkl-trans.h b/src/pkl-trans.h index 1b5bbad..b4e5854 100644 --- a/src/pkl-trans.h +++ b/src/pkl-trans.h @@ -26,7 +26,7 @@ /* The following struct defines the payload of the trans phases. ERRORS is the number of errors detected while running the phase. - + ADD_FRAMES is the number of frames to add to lexical addresses. This is used in transl. diff --git a/src/pkl-typify.c b/src/pkl-typify.c index eff4918..7b22edc 100644 --- a/src/pkl-typify.c +++ b/src/pkl-typify.c @@ -147,7 +147,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_first_operand) { pkl_ast_node exp = PKL_PASS_NODE; pkl_ast_node type = PKL_AST_TYPE (PKL_AST_EXP_OPERAND (exp, 0)); - + PKL_AST_TYPE (exp) = ASTREF (type); } PKL_PHASE_END_HANDLER @@ -165,7 +165,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_isa) pkl_ast_node bool_type = pkl_ast_make_integral_type (PKL_PASS_AST, 32, 1); PKL_AST_LOC (bool_type) = PKL_AST_LOC (isa); - + if (PKL_AST_TYPE_CODE (isa_type) == PKL_TYPE_ANY) { /* EXP isa any is always true. Replace the subtree with a @@ -497,7 +497,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_mul) int t1_code = PKL_AST_TYPE_CODE (t1); int t2_code = PKL_AST_TYPE_CODE (t2); - + pkl_ast_node type; if (t1_code == PKL_TYPE_OFFSET || t2_code == PKL_TYPE_OFFSET) @@ -547,7 +547,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_mul) switch (PKL_AST_TYPE_CODE (t1)) { CASE_STR - CASE_INTEGRAL + CASE_INTEGRAL default: goto error; break; @@ -630,7 +630,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_op_sizeof) 64, 0); pkl_ast_node unit = pkl_ast_make_integer (PKL_PASS_AST, PKL_AST_OFFSET_UNIT_BITS); - + pkl_ast_node type = pkl_ast_make_offset_type (PKL_PASS_AST, itype, unit); @@ -658,7 +658,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_offset) if (PKL_AST_CODE (unit) == PKL_AST_TYPE) { pkl_ast_node new_unit; - + if (PKL_AST_TYPE_COMPLETE (unit) != PKL_AST_TYPE_COMPLETE_YES) { pkl_error (PKL_PASS_AST, PKL_AST_LOC (unit), @@ -677,7 +677,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_offset) unit = new_unit; PKL_AST_OFFSET_UNIT (offset) = ASTREF (unit); } - + type = pkl_ast_make_offset_type (PKL_PASS_AST, magnitude_type, unit); PKL_AST_LOC (type) = PKL_AST_LOC (offset); @@ -692,7 +692,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_array) { pkl_ast_node array = PKL_PASS_NODE; pkl_ast_node initializers = PKL_AST_ARRAY_INITIALIZERS (array); - + pkl_ast_node tmp, type = NULL; /* Check that the types of all the array elements are the same, and @@ -709,7 +709,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_array) "array initializers should be of the same type"); PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; - } + } } /* Build the type of the array. The arrays built from array @@ -729,7 +729,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_array) PKL_AST_LOC (type) = PKL_AST_LOC (PKL_PASS_NODE); PKL_AST_TYPE (array) = ASTREF (type); } - + PKL_PASS_RESTART = 1; } PKL_PHASE_END_HANDLER @@ -801,7 +801,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_indexer) pkl_error (PKL_PASS_AST, PKL_AST_LOC (container), "operator to [] must be an arry or a string"); PKL_TYPIFY_PAYLOAD->errors++; - PKL_PASS_ERROR; + PKL_PASS_ERROR; } if (PKL_AST_TYPE_CODE (index_type) != PKL_TYPE_INTEGRAL) @@ -932,7 +932,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_funcall) break; mandatory_args += 1; } - + if (PKL_AST_FUNCALL_NARG (funcall) < mandatory_args) { pkl_error (PKL_PASS_AST, PKL_AST_LOC (funcall_function), @@ -952,14 +952,14 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_funcall) { if (!aa) break; - + if (PKL_AST_FUNC_TYPE_ARG_VARARG (fa)) { vararg = 1; PKL_AST_FUNCALL_ARG_FIRST_VARARG (aa) = 1; } } - + /* XXX if named arguments are used, the vararg cannot be specified, so it will always be empty and this warning applies. */ if (!vararg @@ -987,7 +987,7 @@ with prototype %s", { pkl_ast_node ordered_arg_list = NULL; size_t nfa; - + /* Make sure that the function type gets named arguments, and that every named actual argument corresponds to a formal argument. */ @@ -998,13 +998,13 @@ with prototype %s", pkl_ast_node aa_name = PKL_AST_FUNCALL_ARG_NAME (aa); int found_arg = 0; - + if (!aa_name) /* The funcall doesn't use named arguments; bail out. Note this will always happen while processing the first actual argument, as per a check in anal1. */ - goto after_named; + goto after_named; for (fa = PKL_AST_TYPE_F_ARGS (funcall_function_type); fa; @@ -1037,7 +1037,7 @@ with prototype %s", PKL_PASS_ERROR; } } - + /* Reorder the actual arguments to match the arguments specified in the function type. For not mentioned optional formal arguments, add a NULL. */ @@ -1048,7 +1048,7 @@ with prototype %s", pkl_ast_node aa_name, fa_name; pkl_ast_node new_aa; size_t naa; - + fa_name = PKL_AST_FUNC_TYPE_ARG_NAME (fa); for (naa = 0, aa = PKL_AST_FUNCALL_ARGS (funcall); aa; @@ -1132,14 +1132,14 @@ with prototype %s", { char *passed_type = pkl_type_str (aa_type, 1); char *expected_type = pkl_type_str (fa_type, 1); - + pkl_error (PKL_PASS_AST, PKL_AST_LOC (aa), "function argument %d has the wrong type\n\ expected %s, got %s", narg + 1, expected_type, passed_type); free (expected_type); free (passed_type); - + PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; } @@ -1201,15 +1201,15 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_ass_stmt) { char *expected_type = pkl_type_str (lvalue_type, 1); char *found_type = pkl_type_str (exp_type, 1); - + pkl_error (PKL_PASS_AST, PKL_AST_LOC (ass_stmt), "r-value in assignment has the wrong type\n\ expected %s got %s", expected_type, found_type); - + free (found_type); free (expected_type); - + PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; } @@ -1268,7 +1268,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_struct_ref) { pkl_ast_node struct_field_type_name = PKL_AST_STRUCT_FIELD_TYPE_NAME (t); - + if (struct_field_type_name && STREQ (PKL_AST_IDENTIFIER_POINTER (struct_field_type_name), PKL_AST_IDENTIFIER_POINTER (field_name))) @@ -1406,7 +1406,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_scons) { pkl_ast_node type_elem_name = PKL_AST_STRUCT_FIELD_TYPE_NAME (type_elem); - + if (type_elem_name && STREQ (PKL_AST_IDENTIFIER_POINTER (type_elem_name), PKL_AST_IDENTIFIER_POINTER (elem_name))) @@ -1420,7 +1420,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_scons) { char *expected_type = pkl_type_str (type_elem_type, 1); char *found_type = pkl_type_str (elem_type, 1); - + pkl_error (PKL_PASS_AST, PKL_AST_LOC (elem_exp), "invalid initializer for `%s' in constructor\n\ expected %s, got %s", @@ -1446,7 +1446,7 @@ expected %s, got %s", PKL_PASS_ERROR; } } - + PKL_AST_TYPE (scons) = ASTREF (scons_type); } PKL_PHASE_END_HANDLER @@ -1485,7 +1485,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_pr_loop_stmt) pkl_ast_node iterator = PKL_AST_LOOP_STMT_ITERATOR (loop_stmt); pkl_ast_node container = PKL_AST_LOOP_STMT_CONTAINER (loop_stmt); pkl_ast_node body = PKL_AST_LOOP_STMT_BODY (loop_stmt); - + if (container) { PKL_PASS_SUBPASS (container); @@ -1536,9 +1536,9 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_pr_loop_stmt) PKL_PASS_SUBPASS (condition); if (PKL_TYPIFY_PAYLOAD->errors > 0) PKL_PASS_ERROR; - + condition_type = PKL_AST_TYPE (condition); - + if (PKL_AST_TYPE_CODE (condition_type) != PKL_TYPE_INTEGRAL || PKL_AST_TYPE_I_SIZE (condition_type) != 32 || PKL_AST_TYPE_I_SIGNED (condition_type) != 1) @@ -1592,7 +1592,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_print_stmt) { char *found_type = pkl_type_str (arg_type, 1); char *expected_type = pkl_type_str (type, 1); - + pkl_error (PKL_PASS_AST, PKL_AST_LOC (arg), "printf argument is of an invalid type\n\ expected %s, got %s", @@ -1665,7 +1665,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_try_catch_stmt) if (try_catch_stmt_arg) { pkl_ast_node arg_type = PKL_AST_FUNC_ARG_TYPE (try_catch_stmt_arg); - + if (PKL_AST_TYPE_CODE (arg_type) != PKL_TYPE_INTEGRAL || PKL_AST_TYPE_I_SIZE (arg_type) != 32 || PKL_AST_TYPE_I_SIGNED (arg_type) != 1) @@ -1753,7 +1753,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_attr) case PKL_AST_ATTR_UNIT: /* 'unit is defined for offset values. */ if (PKL_AST_TYPE_CODE (operand_type) != PKL_TYPE_OFFSET) - goto invalid_attribute; + goto invalid_attribute; /* The type of 'unit is uint<64> */ exp_type = pkl_ast_make_integral_type (PKL_PASS_AST, 64, 0); @@ -1902,7 +1902,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_struct_field_type) PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; } - + ASTREF (offset_type); pkl_ast_node_free (offset_type); } } @@ -1939,7 +1939,7 @@ expected %s, got %s", expected_type_str, returned_type_str); free (expected_type_str); free (returned_type_str); - + PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; } @@ -1964,14 +1964,14 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_func_arg) { char *arg_type_str = pkl_type_str (arg_type, 1); char *initial_type_str = pkl_type_str (initial_type, 1); - + pkl_error (PKL_PASS_AST, PKL_AST_LOC (initial), "argument initializer is of the wrong type\n\ expected %s, got %s", arg_type_str, initial_type_str); free (arg_type_str); free (initial_type_str); - + PKL_TYPIFY_PAYLOAD->errors++; PKL_PASS_ERROR; } diff --git a/src/pkl.c b/src/pkl.c index bd0ddf9..0197531 100644 --- a/src/pkl.c +++ b/src/pkl.c @@ -90,7 +90,7 @@ pkl_new () compiler->bootstrapped = 1; /* XXX: disable compiler built-ins from this point on. */ } - + return compiler; } @@ -107,7 +107,7 @@ rest_of_compilation (pkl_compiler compiler, void **pointers) { struct pkl_gen_payload gen_payload; - + struct pkl_anal_payload anal1_payload = { 0 }; struct pkl_anal_payload anal2_payload = { 0 }; struct pkl_anal_payload analf_payload = { 0 }; @@ -117,7 +117,7 @@ rest_of_compilation (pkl_compiler compiler, struct pkl_trans_payload trans2_payload; struct pkl_trans_payload trans3_payload; struct pkl_trans_payload trans4_payload; - + struct pkl_typify_payload typify1_payload = { 0 }; struct pkl_typify_payload typify2_payload = { 0 }; @@ -130,7 +130,7 @@ rest_of_compilation (pkl_compiler compiler, void *lex_payloads[] = { &transl_payload }; - + struct pkl_phase *frontend_phases[] = { &pkl_phase_trans1, &pkl_phase_anal1, @@ -143,7 +143,7 @@ rest_of_compilation (pkl_compiler compiler, &pkl_phase_anal2, NULL, }; - + void *frontend_payloads[] = { &trans1_payload, &anal1_payload, @@ -194,10 +194,10 @@ rest_of_compilation (pkl_compiler compiler, /* XXX */ /* pkl_ast_print (stdout, ast->ast); */ - + if (!pkl_do_pass (ast, frontend_phases, frontend_payloads, PKL_PASS_F_TYPES)) goto error; - + if (trans1_payload.errors > 0 || trans2_payload.errors > 0 || trans3_payload.errors > 0 @@ -219,10 +219,10 @@ rest_of_compilation (pkl_compiler compiler, /* XXX */ /* pkl_ast_print (stdout, ast->ast); */ - + if (!pkl_do_pass (ast, backend_phases, backend_payloads, 0)) goto error; - + if (analf_payload.errors > 0) goto error; @@ -252,7 +252,7 @@ pkl_compile_buffer (pkl_compiler compiler, compiler->compiling = PKL_COMPILING_PROGRAM; env = pkl_env_dup_toplevel (compiler->env); - + /* Parse the input program into an AST. */ ret = pkl_parse_buffer (&env, &ast, PKL_PARSE_PROGRAM, @@ -263,7 +263,7 @@ pkl_compile_buffer (pkl_compiler compiler, else if (ret == 2) /* Memory exhaustion. */ printf (_("out of memory\n")); - + program = rest_of_compilation (compiler, ast, &pointers); if (program == NULL) goto error; @@ -310,7 +310,7 @@ pkl_compile_statement (pkl_compiler compiler, compiler->compiling = PKL_COMPILING_STATEMENT; env = pkl_env_dup_toplevel (compiler->env); - + /* Parse the input program into an AST. */ ret = pkl_parse_buffer (&env, &ast, PKL_PARSE_STATEMENT, @@ -321,7 +321,7 @@ pkl_compile_statement (pkl_compiler compiler, else if (ret == 2) /* Memory exhaustion. */ printf (_("out of memory\n")); - + program = rest_of_compilation (compiler, ast, &pointers); if (program == NULL) goto error; @@ -362,7 +362,7 @@ pkl_compile_expression (pkl_compiler compiler, compiler->compiling = PKL_COMPILING_EXPRESSION; env = pkl_env_dup_toplevel (compiler->env); - + /* Parse the input program into an AST. */ ret = pkl_parse_buffer (&env, &ast, PKL_PARSE_EXPRESSION, @@ -373,7 +373,7 @@ pkl_compile_expression (pkl_compiler compiler, else if (ret == 2) /* Memory exhaustion. */ printf (_("out of memory\n")); - + program = rest_of_compilation (compiler, ast, &pointers); if (program == NULL) goto error; @@ -431,7 +431,7 @@ pkl_compile_file (pkl_compiler compiler, const char *fname) goto error; pvm_specialize_program (program); - /* XXX */ + /* XXX */ /* pvm_print_program (stdout, program); */ fclose (fd); @@ -489,7 +489,7 @@ pkl_error (pkl_ast ast, { if (ast->filename) fprintf (stderr, "%s:", ast->filename); - + if (PKL_AST_LOC_VALID (loc)) { if (poke_quiet_p) @@ -513,7 +513,7 @@ pkl_error (pkl_ast ast, if (poke_quiet_p) return; - + /* XXX: cleanup this pile of shit, and make fancy output optional. */ if (PKL_AST_LOC_VALID (loc)) @@ -533,7 +533,7 @@ pkl_error (pkl_ast ast, } else cur_column++; - + if (cur_line >= loc.first_line && cur_line <= loc.last_line) { @@ -563,7 +563,7 @@ pkl_error (pkl_ast ast, } else cur_column++; - + if (cur_line >= loc.first_line && cur_line <= loc.last_line) { @@ -636,7 +636,7 @@ pkl_ice (pkl_ast ast, stderr); return; } - + out = fdopen (des, "w"); if (out == NULL) { diff --git a/src/poke.c b/src/poke.c index 40770b4..9d1aa3b 100644 --- a/src/poke.c +++ b/src/poke.c @@ -172,7 +172,7 @@ pk_print_version () /* It is important to separate the year from the rest of the message, as done here, to avoid having to retranslate the message when a new - year comes around. */ + year comes around. */ printf (_("\ Copyright (C) %s Jose E. Marchesi.\n\ License GPLv3+: GNU GPL version 3 or later .\n\ @@ -302,7 +302,7 @@ initialize () { /* This is used by the `progname' gnulib module. */ set_program_name ("poke"); - + /* i18n */ setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -310,7 +310,7 @@ initialize () /* Determine whether the tool has been invoked interactively. */ poke_interactive_p = isatty (fileno (stdin)); - + /* Determine the directory containing poke's scripts and other architecture-independent data. */ poke_datadir = getenv ("POKEDATADIR"); @@ -366,7 +366,7 @@ initialize_user () if (ret == 1) exit (EXIT_FAILURE); } - + free (pokerc); } } @@ -399,6 +399,6 @@ main (int argc, char *argv[]) /* Cleanup. */ finalize (); - + return poke_exit_code; } diff --git a/src/pvm-alloc.h b/src/pvm-alloc.h index 69dcbea..ab2cb5f 100644 --- a/src/pvm-alloc.h +++ b/src/pvm-alloc.h @@ -34,7 +34,7 @@ void pvm_alloc_finalize (void); /* Register/unregister NELEM pointers at POINTER as roots for the garbage-collector. */ - + void pvm_alloc_add_gc_roots (void *pointer, size_t nelems); void pvm_alloc_remove_gc_roots (void *pointer, size_t nelems); diff --git a/src/pvm-env.c b/src/pvm-env.c index e15b91b..ffd5e5f 100644 --- a/src/pvm-env.c +++ b/src/pvm-env.c @@ -54,7 +54,7 @@ pvm_env_new () for (i = 0; i < MAX_VARS; ++i) env->vars[i] = PVM_NULL; - + return env; } diff --git a/src/pvm-val.c b/src/pvm-val.c index ccb7cba..48a0521 100644 --- a/src/pvm-val.c +++ b/src/pvm-val.c @@ -46,7 +46,7 @@ static inline pvm_val pvm_make_long_ulong (int64_t value, int size, int tag) { uint64_t *ll = pvm_alloc (sizeof (uint64_t) * 2); - + ll[0] = value; ll[1] = (size - 1) & 0x3f; return ((uint64_t) (uintptr_t) ll) | tag; @@ -104,7 +104,7 @@ pvm_make_array (pvm_val nelem, pvm_val type) arr->elems[i].offset = PVM_NULL; arr->elems[i].value = PVM_NULL; } - + PVM_VAL_BOX_ARR (box) = arr; return PVM_BOX (box); } @@ -143,10 +143,10 @@ pvm_ref_struct (pvm_val sct, pvm_val name) struct pvm_struct_field *fields; assert (PVM_IS_SCT (sct) && PVM_IS_STR (name)); - + nfields = PVM_VAL_ULONG (PVM_VAL_SCT_NFIELDS (sct)); fields = PVM_VAL_SCT (sct)->fields; - + for (i = 0; i < nfields; ++i) { if (fields[i].name != PVM_NULL @@ -154,7 +154,7 @@ pvm_ref_struct (pvm_val sct, pvm_val name) PVM_VAL_STR (name))) return fields[i].value; } - + return PVM_NULL; } @@ -165,10 +165,10 @@ pvm_set_struct (pvm_val sct, pvm_val name, pvm_val val) struct pvm_struct_field *fields; assert (PVM_IS_SCT (sct) && PVM_IS_STR (name)); - + nfields = PVM_VAL_ULONG (PVM_VAL_SCT_NFIELDS (sct)); fields = PVM_VAL_SCT (sct)->fields; - + for (i = 0; i < nfields; ++i) { if (fields[i].name != PVM_NULL @@ -181,7 +181,7 @@ pvm_set_struct (pvm_val sct, pvm_val name, pvm_val val) return 1; } } - + return 0; } @@ -412,7 +412,7 @@ pvm_sizeof (pvm_val val) else if (PVM_IS_TYP (val)) { size_t size; - + /* XXX */ assert (0); switch (PVM_VAL_TYP_CODE (val)) @@ -426,7 +426,7 @@ pvm_sizeof (pvm_val val) return size; } - + assert (0); return 0; } @@ -482,7 +482,7 @@ void pvm_print_val (FILE *out, pvm_val val, int base, int flags) { const char *long64_fmt, *long_fmt; - const char *ulong64_fmt, *ulong_fmt; + const char *ulong64_fmt, *ulong_fmt; const char *int32_fmt, *int16_fmt, *int8_fmt, *int4_fmt, *int_fmt; const char *uint32_fmt, *uint16_fmt, *uint8_fmt, *uint4_fmt, *uint_fmt; @@ -494,7 +494,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) long64_fmt = "0o%" PRIo64 "L"; long_fmt = "(int<%d>) 0o%" PRIo64; ulong64_fmt = "0o%" PRIo64 "UL"; - ulong_fmt = "(uint<%d>) 0o%" PRIo64; + ulong_fmt = "(uint<%d>) 0o%" PRIo64; int32_fmt = "0o%" PRIo32; int16_fmt = "0o%" PRIo32 "H"; int8_fmt = "0o%" PRIo32 "B"; @@ -510,7 +510,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) long64_fmt = "%" PRIi64 "L"; long_fmt = "(int<%d>) %" PRIi64; ulong64_fmt = "%" PRIu64 "UL"; - ulong_fmt = "(uint<%d>) %" PRIu64; + ulong_fmt = "(uint<%d>) %" PRIu64; int32_fmt = "%" PRIi32; int16_fmt = "%" PRIi32 "H"; int8_fmt = "%" PRIi32 "B"; @@ -526,7 +526,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) long64_fmt = "0x%" PRIx64 "L"; long_fmt = "(int<%d>) %" PRIx64; ulong64_fmt = "0x%" PRIx64 "UL"; - ulong_fmt = "(uint<%d>) %" PRIx64; + ulong_fmt = "(uint<%d>) %" PRIx64; int32_fmt = "0x%" PRIx32; int16_fmt = "0x%" PRIx32 "H"; int8_fmt = "0x%" PRIx32 "B"; @@ -618,7 +618,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) { int size = PVM_VAL_ULONG_SIZE (val); uint64_t ulongval = PVM_VAL_ULONG (val); - + if (base == 2) pvm_print_binary (out, ulongval, size, 0); else @@ -701,7 +701,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) } assert (j == printable_size); str_printable[j] = '\0'; - + fprintf (out, "\"%s\"", str_printable); free (str_printable); } @@ -709,7 +709,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) { size_t nelem, idx; pvm_val array_offset = PVM_VAL_ARR_OFFSET (val); - + nelem = PVM_VAL_ULONG (PVM_VAL_ARR_NELEM (val)); fprintf (out, "["); @@ -717,7 +717,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) { pvm_val elem_offset = PVM_VAL_ARR_ELEM_OFFSET (val, idx); pvm_val elem_value = PVM_VAL_ARR_ELEM_VALUE (val, idx); - + if (idx != 0) fprintf (out, ","); pvm_print_val (out, elem_value, base, flags); @@ -734,7 +734,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) { fputc ('@', out); pvm_print_val (out, array_offset, base, flags); - } + } } else if (PVM_IS_SCT (val)) { @@ -749,7 +749,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) else fputs ("struct", out); fputs (" ", out); - + fprintf (out, "{"); for (idx = 0; idx < nelem; ++idx) { @@ -762,12 +762,12 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) if (name != PVM_NULL) fprintf (out, "%s=", PVM_VAL_STR (name)); pvm_print_val (out, value, base, flags); - + if (flags & PVM_PRINT_F_MAPS && offset != PVM_NULL) { fputc ('@', out); pvm_print_val (out, offset, base, flags); - } + } } fprintf (out, "}"); } @@ -779,7 +779,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) { if (!(PVM_VAL_UINT (PVM_VAL_TYP_I_SIGNED (val)))) fprintf (out, "u"); - + switch (PVM_VAL_ULONG (PVM_VAL_TYP_I_SIZE (val))) { case 8: fprintf (out, "int8"); break; @@ -864,7 +864,7 @@ pvm_print_val (FILE *out, pvm_val val, int base, int flags) if (i != 0) fprintf (out, " "); - + pvm_print_val (out, etype, base, flags); if (ename != PVM_NULL) fprintf (out, " %s", PVM_VAL_STR (ename)); @@ -927,7 +927,7 @@ pvm_val pvm_typeof (pvm_val val) { pvm_val type; - + if (PVM_IS_INT (val)) type = pvm_make_integral_type (pvm_make_ulong (PVM_VAL_INT_SIZE (val), 64), pvm_make_uint (1, 32)); @@ -963,7 +963,7 @@ pvm_type_equal (pvm_val type1, pvm_val type2) if (type_code_1 != type_code_2) return 0; - + switch (type_code_1) { case PVM_TYPE_INTEGRAL: diff --git a/src/pvm-val.h b/src/pvm-val.h index d49774f..74c3547 100644 --- a/src/pvm-val.h +++ b/src/pvm-val.h @@ -105,8 +105,8 @@ pvm_val pvm_make_uint (uint32_t value, int size); val --- [0] vvvv vvvv vvvv vvvv vvvv vvvv vvvv vvvv - bits - ---- + bits + ---- [1] xxxx xxxx xxxx xxxx xxxx xxxx xxbb bbbb BITS+1 is the size of the integral value in bits, from 0 to 63. @@ -534,7 +534,7 @@ pvm_val pvm_make_offset (pvm_val magnitude, pvm_val unit); else if (PVM_IS_SCT ((V))) \ PVM_VAL_SCT_OFFSET ((V)) = (O); \ } while (0) - + #define PVM_VAL_MAPPER(V) \ (PVM_IS_ARR ((V)) ? PVM_VAL_ARR_MAPPER ((V)) \ : PVM_IS_SCT ((V)) ? PVM_VAL_SCT_MAPPER ((V)) \ -- 2.20.1