Skip to contentSkip to conversation

dtc: Add support for named integer constants

PATCH In review Stephen Warren 7 participants 16 messages Dec 12, 2011 – Jan 21, 2012 13 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dtc: Add support for named integer constants

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

My earlier posting was blocked by a lack of consensus on the direction of macro/expression support in dtc. I haven't seen any move to resolve this since. Can we please move forward with simple expression support; it seems to be the most immediately useful aspect of any macro/ expression support. The alternative is to either continue to suffer with unreadable integer constants, or perhaps pre-process before passing the .dts file to dtc, thus making any macro support in dtc moot.

 dtc-lexer.l           |   13 +++++++++
 dtc-parser.y          |   73 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/Makefile.tests  |    3 +-
 tests/identifiers.c   |   44 +++++++++++++++++++++++++++++
 tests/identifiers.dts |   12 ++++++++
 tests/run_tests.sh    |    4 +++
 6 files changed, 148 insertions(+), 1 deletions(-)
 create mode 100644 tests/identifiers.c
 create mode 100644 tests/identifiers.dts
dtc-lexer.l +13 -0
index e866ea5..60a0677 100644
@@ -28,6 +28,7 @@
 PROPNODECHAR	[a-zA-Z0-9,._+*#?@-]
 PATHCHAR	({PROPNODECHAR}|[/])
 LABEL		[a-zA-Z_][a-zA-Z0-9_]*
+IDENTIFIER	[a-zA-Z_][a-zA-Z0-9_]*
 STRING		\"([^\\"]|\\.)*\"
 WS		[[:space:]]
 COMMENT		"/*"([^*]|\*+[^*/])*\*+"/"
@@ -96,6 +97,12 @@ static int pop_input_file(void);
 			return DT_MEMRESERVE;
 		}
 
+<*>"/define/"	{
+			DPRINT("Keyword: /define/\n");
+			BEGIN_DEFAULT();
+			return DT_DEFINE;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
@@ -103,6 +110,12 @@ static int pop_input_file(void);
 			return DT_LABEL;
 		}
 
+<V1>{IDENTIFIER} {
+			DPRINT("identifier: %s\n", yytext);
+			yylval.identifier = xstrdup(yytext);
+			return DT_IDENTIFIER;
+		}
+
 <V1>[0-9]+|0[xX][0-9a-fA-F]+      {
 			yylval.literal = xstrdup(yytext);
 			DPRINT("Literal: '%s'\n", yylval.literal);
dtc-parser.y +73 -0

122 lines not on this page · raw message

tests/Makefile.tests +2 -1
index c564e72..25d2e3c 100644
@@ -15,7 +15,8 @@ LIB_TESTS_L = get_mem_rsv \
 	extra-terminating-null \
 	dtbs_equal_ordered \
 	dtb_reverse dtbs_equal_unordered \
-	add_subnode_with_nops path_offset_aliases
+	add_subnode_with_nops path_offset_aliases \
+	identifiers
 LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
 
 LIBTREE_TESTS_L = truncated_property
tests/identifiers.c new file +44 -0

44 lines not on this page · raw message

tests/identifiers.dts new file +12 -0
new file mode 100644
index 0000000..e8d8e23
@@ -0,0 +1,12 @@
+/dts-v1/;
+
+/define/ VAR1 0xdeadbeef;
+/define/ VAR2 VAR1;
+
+/ {
+	var1 = <VAR1>;
+	var2 = <VAR2>;
+};
+
+/define/ OTHER 0xdeadbeef;
+
tests/run_tests.sh +4 -0
index 72dda32..e0da087 100755
@@ -343,6 +343,10 @@ dtc_tests () {
     run_dtc_test -I dtb -O dts -o stdin_odts_test_tree1.dtb.test.dts - < test_tree1.dtb
     run_wrap_test cmp stdin_odts_test_tree1.dtb.test.dts odts_test_tree1.dtb.test.dts
 
+    # Test identifiers
+    run_dtc_test -I dts -O dtb -o identifiers.dtb identifiers.dts
+    run_test identifiers identifiers.dtb
+
     # Check for graceful failure in some error conditions
     run_sh_test dtc-fatal.sh -I dts -O dtb nosuchfile.dts
     run_sh_test dtc-fatal.sh -I dtb -O dtb nosuchfile.dtb
Signature · 1 line
1.7.0.4
#2 lore raw
In reply to a message not in the archive

Hi Stephen,

Quoted 8 lines · Stephen Warren

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

Quoted 7 lines

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

Yes I agree, it is very useful.

I get conflicts with this - does it need a rebase?

Regards,
Simon

#4 lore raw
In reply to a message not in the archive

Simon Glass wrote at Monday, December 12, 2011 1:19 PM:

Quoted 17 lines · Stephen Warren
Quoted 8 lines

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

Quoted 7 lines

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

Quoted 3 lines

Yes I agree, it is very useful.

I get conflicts with this - does it need a rebase?

Yes, I should have mentioned this patch is still based on the same commit it was 3 months ago, and HEAD has moved forward since. If it's deemed conceptually acceptable, I'll rebase it to HEAD.

(For reference, it's based on ed8fee1 "Add missing tests to .gitignore".)

Signature · 1 line
nvpublic
#6 lore raw
In reply to a message not in the archive

Hi Stephen,

Quoted 22 lines · Stephen Warren

Simon Glass wrote at Monday, December 12, 2011 1:19 PM:

Quoted 17 lines · Stephen Warren
Quoted 8 lines

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

Quoted 7 lines

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

Quoted 3 lines

Yes I agree, it is very useful.

I get conflicts with this - does it need a rebase?

Quoted 9 lines

Yes, I should have mentioned this patch is still based on the same commit it was 3 months ago, and HEAD has moved forward since. If it's deemed conceptually acceptable, I'll rebase it to HEAD.

(For reference, it's based on ed8fee1 "Add missing tests to .gitignore".)

--
nvpublic

I haven't seen any other comments. Is this going in? Constants would be useful.

Regards,
Simon

#8 lore raw
In reply to a message not in the archive

Simon Glass wrote at Tuesday, January 03, 2012 5:46 PM:

Quoted 23 lines · Stephen Warren
Quoted 22 lines

Simon Glass wrote at Monday, December 12, 2011 1:19 PM:

Quoted 20 lines · Stephen Warren
Quoted 8 lines

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

Quoted 7 lines

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

Yes I agree, it is very useful.

I get conflicts with this - does it need a rebase?

Quoted 7 lines
Quoted 5 lines

Yes, I should have mentioned this patch is still based on the same commit it was 3 months ago, and HEAD has moved forward since. If it's deemed conceptually acceptable, I'll rebase it to HEAD.

(For reference, it's based on ed8fee1 "Add missing tests to .gitignore".)

I haven't seen any other comments. Is this going in? Constants would be useful.

I took a quick look at rebasing this on HEAD today. There are some non- trivial conflicts with Anton's recent patch to support variable-sized elements in arrays. In particular, my patch relied on the cellval token, allowing it to reference a symbol or a literal, but Anton's patch has removed that token from the grammar.

So, I'm still willing to rebase my patch, but given the non-trivial nature of doing so, I'd like prior confirmation from Jon and David that the syntax is acceptable, and so my work won't be in vain.

For reference, here's the test .dts file from my patch:

+/dts-v1/;
+
+/define/ VAR1 0xdeadbeef;
+/define/ VAR2 VAR1;
+
+/ {
+ var1 = <VAR1>;
+ var2 = <VAR2>;
+};
+
+/define/ OTHER 0xdeadbeef;

Signature · 1 line
nvpublic
#10 lore raw
In reply to a message not in the archive

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Will either of you be attending Linaro Connect or ELC 2012 in February by any chance? We could get together and talk this through in person if you are...

Thanks for any kind of discussion!

Stephen Warren wrote at Thursday, January 05, 2012 2:27 PM:

Quoted 55 lines

Simon Glass wrote at Tuesday, January 03, 2012 5:46 PM:

Quoted 23 lines · Stephen Warren
Quoted 22 lines

Simon Glass wrote at Monday, December 12, 2011 1:19 PM:

Quoted 20 lines · Stephen Warren
Quoted 8 lines

You may define constants as follows:

/define/ TWO 2;
/define/ FOUR 4;
/define/ OTHER FOUR;

And properties may use these values as follows:

Quoted 7 lines

foo = <1 TWO 3 FOUR 5>;

---
I posted this back in early September. I'd like to ask again that this feature be merged into dtc; there are many situations where it'd allow .dts files to be simplified.

Yes I agree, it is very useful.

I get conflicts with this - does it need a rebase?

Quoted 7 lines
Quoted 5 lines

Yes, I should have mentioned this patch is still based on the same commit it was 3 months ago, and HEAD has moved forward since. If it's deemed conceptually acceptable, I'll rebase it to HEAD.

(For reference, it's based on ed8fee1 "Add missing tests to .gitignore".)

I haven't seen any other comments. Is this going in? Constants would be useful.

I took a quick look at rebasing this on HEAD today. There are some non- trivial conflicts with Anton's recent patch to support variable-sized elements in arrays. In particular, my patch relied on the cellval token, allowing it to reference a symbol or a literal, but Anton's patch has removed that token from the grammar.

So, I'm still willing to rebase my patch, but given the non-trivial nature of doing so, I'd like prior confirmation from Jon and David that the syntax is acceptable, and so my work won't be in vain.

For reference, here's the test .dts file from my patch:

(quoted diff) +11 -0
+/dts-v1/;
+
+/define/ VAR1 0xdeadbeef;
+/define/ VAR2 VAR1;
+
+/ {
+	var1 = <VAR1>;
+	var2 = <VAR2>;
+};
+
+/define/ OTHER 0xdeadbeef;
Signature · 1 line
nvpublic
#12 lore raw
In reply to a message not in the archive
Quoted 5 lines · Stephen Warren

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without at least having an outline of what a future macro/function syntax would look like. The latter is almost certain to permit the former as a subcase, and I'd really rather not end up with two different syntaxes for constants.

Unfortunately, much as I'd like to get all these extended features into dtc, it's not my main job, so I don't have a lot of time to ponder the possibilities.

Quoted 3 lines

Will either of you be attending Linaro Connect or ELC 2012 in February by any chance? We could get together and talk this through in person if you are...

Not for me, I'm afraid.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#14 lore raw
In reply to a message not in the archive
Quoted 10 lines · Stephen Warren
Quoted 5 lines

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without at least having an outline of what a future macro/function syntax would look like.

Which is where I thought it was left earlier...? :-) And it's not just what the macro/function syntax will look like, but also how these will play into a more generalized expression handling mechanism. Defining something one-off now that doesn't fit well into a long term plan is less than ideal.

Yes, I know that is tantamount to requiring the whole, larger picture be solved first. But Dave is right -- at least an outline of the direction. Seriously, the lexical problems can form some of the nastiest gotchas if we're not careful from the onset.

Quoted 3 lines

The latter is almost certain to permit the former as a subcase, and I'd really rather not end up with two different syntaxes for constants.

Exactly.

Quoted 2 lines

Unfortunately, much as I'd like to get all these extended features into dtc,

Agreed....

Quoted 5 lines
Quoted 3 lines

Will either of you be attending Linaro Connect or ELC 2012 in February by any chance? We could get together and talk this through in person if you are...

Not for me, I'm afraid.

Only if they are in Austin. :-) Which is to say "Sorry, no."

jdl

#16 lore raw
In reply to a message not in the archive

Jon Loeliger wrote at Wednesday, January 11, 2012 7:38 AM:

Quoted 17 lines
Quoted 10 lines · Stephen Warren
Quoted 5 lines

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without at least having an outline of what a future macro/function syntax would look like.

Which is where I thought it was left earlier...? :-) And it's not just what the macro/function syntax will look like, but also how these will play into a more generalized expression handling mechanism. Defining something one-off now that doesn't fit well into a long term plan is less than ideal.

Quoted 4 lines

Yes, I know that is tantamount to requiring the whole, larger picture be solved first. But Dave is right -- at least an outline of the direction. Seriously, the lexical problems can form some of the nastiest gotchas if we're not careful from the onset.

So that all makes sense.

My question is: How can we get consensus on what we want that complete future syntax to be? IIRC, Jon has a branch that implements a proposal, and David at least posted a different proposal if not actual code that implemented it. We're not missing proposals, but rather a mechanism to decide between them?

For what it's worth, I'd tend towards a simple expression-based syntax where property values can be calculated with C-style expressions. Basic math stuff like ( ) + - * / & | ~ << >> and some basic string handling operations (str(int) and concatenation). I think that'd cover the vast majority of use-cases wouldn't it? For more advanced stuff like loops to synthesize multiple nodes, it seems like writing a custom script to generate the .dts file and then passing the result to dtc would be more modular, and not require us to create a whole new Turing-complete language in dtc?

Signature · 1 line
nvpublic
#26 lore raw
In reply to a message not in the archive

Even if everyone can't make it, how about a BoF session at ELC 2012? I haven't had any time to contribute recently, but am tremendously interested in moving this forward.

Quoted 3 lines

-----Original Message-----
From: devicetree-discuss-bounces+dvomlehn=cisco.com-uLR06cmDAlY/[email protected]

[mailto:devicetree-discuss-bounces+dvomlehn=cisco.com-uLR06cmDAlY/[email protected]]

Quoted 57 lines

On Behalf Of Jon Loeliger
Sent: Wednesday, January 11, 2012 6:38 AM
To: David Gibson
Cc: Devicetree Discuss
Subject: Re: [PATCH v2 REPOST] dtc: Add support for named integer constants

Quoted 5 lines · Stephen Warren
Quoted 4 lines

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax

with

Quoted 3 lines
Quoted 1 line

expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without

at

Quoted 2 lines

least having an outline of what a future macro/function syntax would look like.

Which is where I thought it was left earlier...? :-) And it's not just what the macro/function syntax will look like, but also how these will play into a more generalized expression handling mechanism. Defining something one-off now that doesn't fit well into a long term plan is less than ideal.

Yes, I know that is tantamount to requiring the whole, larger picture be solved first. But Dave is right -- at least an outline of the direction. Seriously, the lexical problems can form some of the nastiest gotchas if we're not careful from the onset.

Quoted 3 lines

The latter is almost certain to permit the former as a subcase, and I'd really rather not end up with two different syntaxes for constants.

Exactly.

Quoted 2 lines

Unfortunately, much as I'd like to get all these extended features into dtc,

Agreed....

Quoted 1 line
Quoted 1 line

Will either of you be attending Linaro Connect or ELC 2012 in

February

Quoted 1 line
Quoted 1 line

by any chance? We could get together and talk this through in

person if

Quoted 3 lines
Quoted 1 line

you are...

Not for me, I'm afraid.

Only if they are in Austin. :-) Which is to say "Sorry, no."

jdl
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#18 lore raw
In reply to a message not in the archive

I find it ironic that the very first device tree implementation, dating back to 1989, was built around a Turing complete language.

Quoted 41 lines · Stephen Warren

Jon Loeliger wrote at Wednesday, January 11, 2012 7:38 AM:

Quoted 17 lines
Quoted 10 lines · Stephen Warren
Quoted 5 lines

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without at least having an outline of what a future macro/function syntax would look like.

Which is where I thought it was left earlier...? :-) And it's not just what the macro/function syntax will look like, but also how these will play into a more generalized expression handling mechanism. Defining something one-off now that doesn't fit well into a long term plan is less than ideal.

Quoted 4 lines

Yes, I know that is tantamount to requiring the whole, larger picture be solved first. But Dave is right -- at least an outline of the direction. Seriously, the lexical problems can form some of the nastiest gotchas if we're not careful from the onset.

So that all makes sense.

My question is: How can we get consensus on what we want that complete future syntax to be? IIRC, Jon has a branch that implements a proposal, and David at least posted a different proposal if not actual code that implemented it. We're not missing proposals, but rather a mechanism to decide between them?

For what it's worth, I'd tend towards a simple expression-based syntax where property values can be calculated with C-style expressions. Basic math stuff like ( ) + - * /& | ~<< >> and some basic string handling operations (str(int) and concatenation). I think that'd cover the vast majority of use-cases wouldn't it? For more advanced stuff like loops to synthesize multiple nodes, it seems like writing a custom script to generate the .dts file and then passing the result to dtc would be more modular, and not require us to create a whole new Turing-complete language in dtc?

#20 lore raw
In reply to a message not in the archive
Quoted 2 lines

I find it ironic that the very first device tree implementation, dating back to 1989, was built around a Turing complete language.

...and that my uncle wrote one of the very first
books about that language. :-)

jdl

#28 lore raw
In reply to a message not in the archive
Quoted 4 lines · David VomLehn (dvomlehn)

Even if everyone can't make it, how about a BoF session at ELC 2012? I haven't had any time to contribute recently, but am tremendously interested in moving this forward.

+1

We've been wanting this support for long time.

Signature · 2 lines
Regards,
Shawn
#21 lore raw
In reply to a message not in the archive
Quoted 23 lines · Stephen Warren

Jon Loeliger wrote at Wednesday, January 11, 2012 7:38 AM:

Quoted 17 lines
Quoted 10 lines · Stephen Warren
Quoted 5 lines

John, David,

What can we do to reach consensus on expanding dtc to handle named constants, or in general any future direction to extend the syntax with expressions etc.?

Hrm, so, I'm not at all keen to add a named constant syntax without at least having an outline of what a future macro/function syntax would look like.

Which is where I thought it was left earlier...? :-) And it's not just what the macro/function syntax will look like, but also how these will play into a more generalized expression handling mechanism. Defining something one-off now that doesn't fit well into a long term plan is less than ideal.

Quoted 4 lines

Yes, I know that is tantamount to requiring the whole, larger picture be solved first. But Dave is right -- at least an outline of the direction. Seriously, the lexical problems can form some of the nastiest gotchas if we're not careful from the onset.

Quoted 4 lines

So that all makes sense.

My question is: How can we get consensus on what we want that complete future syntax to be?

Um.. try to make a detailed proposal (synthesised from earlier ones) that enough people are happy with (Jon and myself for starters).

Quoted 4 lines

IIRC, Jon has a branch that implements a proposal,
and David at least posted a different proposal if not actual code that implemented it. We're not missing proposals, but rather a mechanism to decide between them?

Well.. that's not entirely true. The proposed expression syntax was essentially identical between Jon's proposal and mine (though the implementation of it is quite different). Jon's proposal includes loops and "functions", mine started with just expressions. I had in mind some sort of macro language to allow making use of those expressions. I'm not sure quite what that would look like (or even if it would be implemented withing dtc, or use an external helper like cpp). So there's really only one proposal that covers the full space, it's just I don't like it that much.

Quoted 4 lines

For what it's worth, I'd tend towards a simple expression-based syntax where property values can be calculated with C-style expressions. Basic math stuff like ( ) + - * / & | ~ << >> and some basic string handling operations (str(int) and concatenation).

Ok. Well, I should de-bitrot and re-propose my integer expression patch, which covered most of that. I also intended basic string operations as you suggest, though I can't remember if I made a start on that.

I think applying that would be reasonably safe as it is. If we go with Jon's proposal or something like it in the end, we'll need to reimplement most of the expression evaluation (to do delayed instead of parse-time evaluation). But I'm much less worried about having to rework code - even substantially - than I am about user-visible syntax regressions.

Quoted 2 lines

I think that'd cover the vast
majority of use-cases wouldn't it?

Not quite. Expressions are interesting of themselves, but not all that useful. It's functions or macros plus expressions which gets us close to where we want to be. So expressions gives a little as it is, a lot more for people already running their dts through cpp. To really make progress, we still want a proposal for a standard function or macro syntax for dtc. And, obviously, a decision whether to go with functions or macros. I like macros, because I think they give a lot of flexibility with minimal conceptual complexity. Jon's proposal is based on functions. I didn't like his proposal very much as a whole, but I should take another look and see what I think of the function syntax in isolation.

Quoted 5 lines

For more advanced stuff like loops
to synthesize multiple nodes, it seems like writing a custom script to generate the .dts file and then passing the result to dtc would be more modular, and not require us to create a whole new Turing-complete language in dtc?

Perhaps. One of the reasons that I'm so doggedly conservative and picky about new dtc syntax is that small languages have a tendency to grow to Turing completeness, whether you intend it originally or not. I'm ok with that happening, but I'd really like to make sure that when and if it happens, we arrive at a decent Turing complete language, not a horrible one.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#23 lore raw
In reply to a message not in the archive
Quoted 6 lines
Quoted 5 lines

For what it's worth, I'd tend towards a simple expression-based syntax where property values can be calculated with C-style expressions. Basic math stuff like ( ) + - * / & | ~ << >> and some basic string handling operations (str(int) and concatenation).

Quoted 8 lines

...

I think applying that would be reasonably safe as it is. If we go with Jon's proposal or something like it in the end, we'll need to reimplement most of the expression evaluation (to do delayed instead of parse-time evaluation). But I'm much less worried about having to rework code - even substantially - than I am about user-visible syntax regressions.

Even with that piece, there are substanial lexical and parsing issues that complicate things. Bare numbers, or expressions, next to each other without syntactic glue can cause parsing fits. :-)

Quoted 6 lines
Quoted 2 lines

I think that'd cover the vast
majority of use-cases wouldn't it?

Not quite. Expressions are interesting of themselves, but not all that useful. It's functions or macros plus expressions which gets us close to where we want to be. So expressions gives a little as it is,

That's the difficult and slippery slope here. Being able to write

    (FOO << (12 + 2))
is nice, but it would be nicer and more useful to represent
    (FOO << ((i) + 2))

where (i) was actually parameterized or iterated in some way.

Quoted 8 lines

a lot more for people already running their dts through cpp. To really make progress, we still want a proposal for a standard function or macro syntax for dtc. And, obviously, a decision whether to go with functions or macros. I like macros, because I think they give a lot of flexibility with minimal conceptual complexity. Jon's proposal is based on functions. I didn't like his proposal very much as a whole, but I should take another look and see what I think of the function syntax in isolation.

It might also be instructive to isolate my expression parsing for its lexical and syntactic changes and work towards introducing those, perhaps in isolation, as a first step.

The key there WRT your interest, Stephen, is that it can capture the use of apparent variables or #define'd-equivalent symbols within the expression handling. (David's version did not.)

Quoted 6 lines
Quoted 4 lines

For more advanced stuff like loops to synthesize multiple nodes, it seems like writing a custom script to generate the .dts file and then passing the result to dtc would be more modular, and not require us to create a whole new Turing-complete language in dtc?

Perhaps.

OK. Let's explore that approach. We'll write a, say, Python collection of code-objects for each, what?, device. Place them all in a large library. Your "device tree source" effectively now becomes a "main" that starts instantiating librarified devices, adding a litle glue to emit some one-off property or two.

That could work. But is it now OK that the construction of the device tree source file is tied to Python? Do we make the kernel builds now reliant upon Python too? Or Perl? But wasn't that shot down *again*? Hans wants shell. Lotte likes Lua. Suki plays with Python. Willi is happy again. Adolf builds his DTS with Perl. No one uses Tcl. Everyone just checks-in their *generated* DTS results anyway. It'll be a war without tears.

Or how do you see this working?

Quoted 3 lines

.. One of the reasons that I'm so doggedly conservative and picky about new dtc syntax is that small languages have a tendency to grow to Turing completeness, whether you intend it originally or not.

Isn't that someone's observation...? Behind every flat-file there is a Turing-complete language trying to get out.

Quoted 3 lines

I'm ok with that happening, but I'd really like to make sure that when and if it happens, we arrive at a decent Turing complete language, not a horrible one.

Name two decent ones. :-) C and ..., and .... See? There isn't another!

Never mind.

jdl

#25 lore raw
In reply to a message not in the archive
Quoted 15 lines · Jon Loeliger
Quoted 6 lines
Quoted 5 lines

For what it's worth, I'd tend towards a simple expression-based syntax where property values can be calculated with C-style expressions. Basic math stuff like ( ) + - * / & | ~ << >> and some basic string handling operations (str(int) and concatenation).

Quoted 8 lines

...

I think applying that would be reasonably safe as it is. If we go with Jon's proposal or something like it in the end, we'll need to reimplement most of the expression evaluation (to do delayed instead of parse-time evaluation). But I'm much less worried about having to rework code - even substantially - than I am about user-visible syntax regressions.

Quoted 3 lines

Even with that piece, there are substanial lexical and parsing issues that complicate things. Bare numbers, or expressions, next to each other without syntactic glue can cause parsing fits. :-)

Well, my patch requires that expressions in cell lists have parens around them. I think that's the only sane choice, otherwise there's no reasonable way to distinguish between the 1 cell construct <(500-300)> and the 2 cell construct <500 (-300)>.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I think that'd cover the vast
majority of use-cases wouldn't it?

Not quite. Expressions are interesting of themselves, but not all that useful. It's functions or macros plus expressions which gets us close to where we want to be. So expressions gives a little as it is,

Quoted 5 lines

That's the difficult and slippery slope here. Being able to write

    (FOO << (12 + 2))
is nice, but it would be nicer and more useful to represent
    (FOO << ((i) + 2))

where (i) was actually parameterized or iterated in some way.

Right, exactly my point.

Quoted 9 lines
Quoted 8 lines

a lot more for people already running their dts through cpp. To really make progress, we still want a proposal for a standard function or macro syntax for dtc. And, obviously, a decision whether to go with functions or macros. I like macros, because I think they give a lot of flexibility with minimal conceptual complexity. Jon's proposal is based on functions. I didn't like his proposal very much as a whole, but I should take another look and see what I think of the function syntax in isolation.

Quoted 3 lines

It might also be instructive to isolate my expression parsing for its lexical and syntactic changes and work towards introducing those, perhaps in isolation, as a first step.

Right. I think my expression code and your expression code were essentially identical syntactically (possibly modulo a slightly different set of implemented operators).

Quoted 3 lines

The key there WRT your interest, Stephen, is that it can capture the use of apparent variables or #define'd-equivalent symbols within the expression handling. (David's version did not.)

True, but constant definitions (as opposed to function definitions) would be trivial to add to my code.

Quoted 40 lines
Quoted 6 lines
Quoted 4 lines

For more advanced stuff like loops to synthesize multiple nodes, it seems like writing a custom script to generate the .dts file and then passing the result to dtc would be more modular, and not require us to create a whole new Turing-complete language in dtc?

Perhaps.

OK. Let's explore that approach. We'll write a, say, Python collection of code-objects for each, what?, device. Place them all in a large library. Your "device tree source" effectively now becomes a "main" that starts instantiating librarified devices, adding a litle glue to emit some one-off property or two.

That could work. But is it now OK that the construction of the device tree source file is tied to Python? Do we make the kernel builds now reliant upon Python too? Or Perl? But wasn't that shot down *again*? Hans wants shell. Lotte likes Lua. Suki plays with Python. Willi is happy again. Adolf builds his DTS with Perl. No one uses Tcl. Everyone just checks-in their *generated* DTS results anyway. It'll be a war without tears.

Or how do you see this working?

Quoted 3 lines

.. One of the reasons that I'm so doggedly conservative and picky about new dtc syntax is that small languages have a tendency to grow to Turing completeness, whether you intend it originally or not.

Isn't that someone's observation...? Behind every flat-file there is a Turing-complete language trying to get out.

Quoted 3 lines

I'm ok with that happening, but I'd really like to make sure that when and if it happens, we arrive at a decent Turing complete language, not a horrible one.

Name two decent ones. :-) C and ..., and .... See? There isn't another!

Never mind.

jdl

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson