From 2da35fec177ef94525f668d0517f64b69cf9e0ea Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 26 Aug 2024 21:25:23 +0200 Subject: [PATCH] remove requirement to end subroutine with an EOL, so oneliners are now possible main { sub start() { cx16.r0++ cx16.r1++ } } --- compiler/test/ast/TestProg8Parser.kt | 10 ++++++++++ docs/source/todo.rst | 2 +- parser/antlr/Prog8ANTLR.g4 | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/compiler/test/ast/TestProg8Parser.kt b/compiler/test/ast/TestProg8Parser.kt index b090e12e6..495724ef7 100644 --- a/compiler/test/ast/TestProg8Parser.kt +++ b/compiler/test/ast/TestProg8Parser.kt @@ -1046,4 +1046,14 @@ main { (assigns[3].value as NumericLiteral).number shouldBe 3000001.141592654 } + test("oneliner") { + val src=""" + main { sub start() { cx16.r0++ cx16.r1++ } } + other { asmsub thing() { %asm {{ inx }} } } + """; + val result = compileText(VMTarget(), false, src, writeAssembly = false)!! + val st = result.compilerAst.entrypoint.statements + st.size shouldBe 2 + } + }) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index c57d4036d..9b549da37 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -11,7 +11,6 @@ Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ Compiler: -- Relax newline / bracket in parser so that you can put open and close brackets on the same line or on the next line if you so wish. For example be able to write a true one liner? - Can we support signed % (remainder) somehow? - IR: implement missing operators in AssignmentGen (array shifts etc) - expand the kata encoding to somehow translate normal katana to half-widths? (see comment in KatakanaEncoding) @@ -72,6 +71,7 @@ Optimizations: STRUCTS? -------- +- declare struct *type*, or directly declare the variable itself? Problem with the latter is: you cannot easily define multiple variables of the same struct type. - can contain only numeric types (byte,word,float) - no nested structs, no reference types (strings, arrays) inside structs - only as a reference type (uword pointer). This removes a lot of the problems related to introducing a variable length value type. - arrays of struct is just an array of uword pointers. Can even be @split? diff --git a/parser/antlr/Prog8ANTLR.g4 b/parser/antlr/Prog8ANTLR.g4 index d73362d42..6ba39f703 100644 --- a/parser/antlr/Prog8ANTLR.g4 +++ b/parser/antlr/Prog8ANTLR.g4 @@ -256,7 +256,7 @@ inlineir: '%ir' EOL? INLINEASMBLOCK; inline: 'inline'; subroutine : - 'sub' identifier '(' sub_params? ')' sub_return_part? EOL? (statement_block EOL) + 'sub' identifier '(' sub_params? ')' sub_return_part? EOL? (statement_block EOL?) ; sub_return_part : '->' datatype ; @@ -271,7 +271,7 @@ statement_block : sub_params : vardecl (',' EOL? vardecl)* ; asmsubroutine : - inline? 'asmsub' asmsub_decl EOL? (statement_block EOL) + inline? 'asmsub' asmsub_decl EOL? (statement_block EOL?) ; romsubroutine :