Giter Club home page Giter Club logo

Comments (5)

jserv avatar jserv commented on July 23, 2024 1

should these macros be defined in another file e.g. stdbool.c rather than c.c?

No, maintaining our copy of <stdbool.h> is not necessary. By leveraging the shecc-specific identifier (__SHECC__), we can easily define the bool-related macros directly in src/defs.h, thereby ensuring our implementation adheres to C99 standards.

from shecc.

ChAoSUnItY avatar ChAoSUnItY commented on July 23, 2024

should these macros be defined in another file e.g. stdbool.c rather than c.c?

from shecc.

ChAoSUnItY avatar ChAoSUnItY commented on July 23, 2024

After further investigation by utilize bool back on declarations, e.g. return type / parameter type in functions (see bb677b4), I found that the issue that caused stage 2 compilation failure is the global variable initialization with bool type, specifically this one. By replacing int with bool, the stage 2 compilation would fail.

I think this is not frontend but codegen's fault?

from shecc.

vacantron avatar vacantron commented on July 23, 2024

This problem is probably caused by the unmatched size of the datatype when allocating variable in either

shecc/src/reg-alloc.c

Lines 259 to 265 in cb49429

else if (strcmp(global_insn->rd->type_name, "int") &&
strcmp(global_insn->rd->type_name, "char")) {
type_t *type = find_type(global_insn->rd->type_name, 0);
GLOBAL_FUNC.stack_size += type->size;
} else
/* 'char' is aligned to one byte for the convenience */
GLOBAL_FUNC.stack_size += 4;

or

shecc/src/reg-alloc.c

Lines 347 to 352 in cb49429

case OP_allocat:
if ((!strcmp(insn->rd->type_name, "void") ||
!strcmp(insn->rd->type_name, "int") ||
!strcmp(insn->rd->type_name, "char")) &&
insn->rd->array_size == 0)
break;

We need to check the type bool also.

BTW, can we simply replace the macro in lib/c.c

shecc/lib/c.c

Line 12 in cb49429

#define bool _Bool

with

- type = add_named_type("_Bool");
+ type = add_named_type("bool");

at src/parser.c ?

type = add_named_type("_Bool");

The current preprocessor only support number or string if it is not a function-like macro.

from shecc.

ChAoSUnItY avatar ChAoSUnItY commented on July 23, 2024

Current macro supports identifier macro but only "_Bool" will be supported at this moment

shecc/src/parser.c

Lines 391 to 394 in cb49429

} else if (lex_peek(T_identifier, value)) {
lex_expect(T_identifier);
add_alias(alias, value);
} else if (lex_accept(T_open_bracket)) { /* function-like macro */

shecc/src/lexer.c

Lines 524 to 530 in cb49429

if (is_numeric(alias)) {
t = T_numeric;
} else if (!strcmp(alias, "_Bool")) {
t = T_identifier;
} else {
t = T_string;
}

And I will rework on frontend tokenizing process recently to hopefully eliminate some unintentional limitations, e.g. single token aliasing in macro.

from shecc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.