Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lerno

Pages: 1 ... 8 9 [10] 11 12 ... 17
136
Ideas / Re: Add defer
« on: November 03, 2018, 03:51:29 AM »
A limited form of defer exists as a GCC extension __cleanup__:

http://echorand.me/site/notes/articles/c_cleanup/cleanup_attribute_c.html

137
Ideas / Relax variable initialization rules
« on: November 02, 2018, 06:42:01 PM »
According to the docs, this is not allowed:

Code: [Select]
i32 foo = 1;

i32[8] array = {
    [foo] = 1,    // error: initializer element is not a compile-time constant
}

However, there is no real reason why we could not support this:

Code: [Select]
func void foo(arg i32)
{
   i32[arg + 1] array = {
     [arg] = 1;
   }
}

As this is could be syntactic sugar for the following code:

Code: [Select]
func void foo(i i32)
{
   i32[i + 1] array = {}
   array[i] = 1;
}

It makes array usage more flexible and uniform. (Even though few might use this functionality)

138
General Discussion / Other reference languages
« on: November 01, 2018, 10:42:47 PM »
Alef and Limbo (both precursors to Go) are useful to have a look at.

139
Implementation Details / ASM validation
« on: November 01, 2018, 09:12:16 PM »
It looks like ASM validation is only partial (and based on Clang) should more detailed parsing/checking be done?

140
Implementation Details / Re: Why do we need Clang and LLVM?
« on: November 01, 2018, 02:52:43 PM »
Code in clang's lexer:

Code: [Select]
    Char = getCharAndSize(CurPtr, SizeTmp);
    if (Char == '=') {
      Kind = tok::percentequal;
      CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
    } else if (LangOpts.Digraphs && Char == '>') {
      Kind = tok::r_brace;                             // '%>' -> '}'
      CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
    } else if (LangOpts.Digraphs && Char == ':') {
      CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
      Char = getCharAndSize(CurPtr, SizeTmp);
      if (Char == '%' && getCharAndSize(CurPtr+SizeTmp, SizeTmp2) == ':') {
        Kind = tok::hashhash;                          // '%:%:' -> '##'
        CurPtr = ConsumeChar(ConsumeChar(CurPtr, SizeTmp, Result),
                             SizeTmp2, Result);
      } else {                                         // '%:' -> '#'
        // We parsed a # character.  If this occurs at the start of the line,
        // it's actually the start of a preprocessing directive.  Callback to
        // the preprocessor to handle it.
        // TODO: -fpreprocessed mode??
        if (TokAtPhysicalStartOfLine && !LexingRawMode && !Is_PragmaLexer)
          goto HandleDirective;

        Kind = tok::hash;
      }
    } else {
      Kind = tok::percent;
    }

:o Indentation is not a sufficient way to make C's if-statements readable.

Makes you want to do something like this:

if-stmt
 : "if" expr "->" stmt
 | "if" expr "{" stmt_list "}" else-clause
 ;

else-clause
 : <empty>
 : "else" "{" smt_list "}"
 : "elseif" expr "{" smt_list "}" else-clause 
 ;


141
Implementation Details / Re: Why do we need Clang and LLVM?
« on: November 01, 2018, 02:29:36 PM »
Interestingly, about 90% of the complexity of Preprocessor work comes from resolving modules and macros from modules correctly. So this is why macro resolution should come AFTER parsing and not as a pre-processor :D

142
Implementation Details / Re: Why do we need Clang and LLVM?
« on: November 01, 2018, 02:09:03 AM »
Status update:

1. Relevant parts of Clang lifted out, verified to work stand alone.
2. Now working on cutting away the huge amounts of unnecessary code needed for various versions of C, C++ and different extensions that don't make any sense for C2.

143
Ideas / Re: Switch statement
« on: November 01, 2018, 01:51:14 AM »
If there are first class strings, then switch on strings are is an awesome feature (likely implemented using a hash)

144
General Discussion / Re: State of progress?
« on: October 31, 2018, 10:03:20 AM »
Right now I'm working on actually pulling the Clang lexer into a flat directory (c2c/Clang) to see how many things are necessary. Needless to say, trying to pull it out brings with it CRAZY AMOUNTS OF CODE. I'm then going to try to cut away what we don't use. If we get some subset of less than 50 files, we could actually move those into C2 and then refactor it down to the bare essentials, swapping things out as we go along.

I'm going to give it a few more hours and see where it leads.

145
General Discussion / Re: Overview of syntax
« on: October 31, 2018, 09:58:58 AM »
Definitely, I'm not suggesting anything other than { } for C2. (Unless we find some reason that changing { } would make things much much more readable.

146
General Discussion / Re: Contribute / get into the code
« on: October 31, 2018, 09:57:11 AM »
Got it!

147
Ideas / Anonymous structs (actually, tuples)
« on: October 30, 2018, 03:35:19 PM »
We could have tuples through anonymous structs with destructuring.

Code: [Select]
func struct { i32, f64 } foo() {
   return struct { 1, 4 };
   // also ok: return { 1, 4 };
}

i32 a, f64 f = foo(); // <- we need to consider parsing here, this collides with the C comma operator.

struct { i32, f64 } x = foo();

What's missing here is some way to only keep one part. If we had named arguments, that could work though!

Code: [Select]
func struct { i32 loop, f64 time } foo();

i32 x = foo().loop;

The rewrite to C is fairly straightforward here, since we're just using structs.

148
Ideas / Re: Syntax of const pointers
« on: October 30, 2018, 03:19:04 PM »
Upvote for implementing 4.

149
Ideas / Re: Weird ideas #2: variable sized structures
« on: October 30, 2018, 03:06:38 PM »
I think this is a good (tiny) extension to the syntax.

Three syntax ideas:
Code: [Select]
// 1
struct Foo {
  i32 element_count;
  Foobar...;
}

// 2
struct Foo {
  i32 element_count;
  Foobar[...];
}

// 3
struct Foo {
  i32 element_count;
  Foobar[+];
}

// 4
struct Foo {
  i32 element_count;
  Foobar[*];
}

sizeof(Foo) would then be based on Foo having zero elements of Foobar.

150
Implementation Details / Re: Why do we need Clang and LLVM?
« on: October 29, 2018, 09:36:23 PM »
Now that I have a better overview of the code I feel it's even more urgent that the Lexer is swapped for a custom one:

  • The lexer parses a lot of stuff that C2 shouldn't, this makes the code rather unclear at places.
  • The lexer has a firm idea about how to lex certain tokens, like "@" which might complicate parsing.
  • We have full C pre-processing. I don't think this is a good thing.
  • Keywords need to be defined in the Clang source :-[
  • Code requires reading up on a lot of Clang code to see how things work, rather than just the c2compiler code.

Pages: 1 ... 8 9 [10] 11 12 ... 17