aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile2
-rw-r--r--boot/evaluator.cc9
-rw-r--r--rakelib/compiler.rake12
-rw-r--r--testsuite/compilable/compile_time_array_length.elna7
-rw-r--r--testsuite/compilable/const_negation.elna9
-rw-r--r--testsuite/compilable/const_var_chain.elna8
-rw-r--r--testsuite/runnable/case_constant_label.elna7
-rw-r--r--testsuite/runnable/compile_time_array_access.elna8
-rw-r--r--testsuite/runnable/inferred_variable.elna4
-rw-r--r--tools/tree-sitter/grammar.js8
10 files changed, 23 insertions, 51 deletions
diff --git a/Rakefile b/Rakefile
index 5adb525..a2f1850 100644
--- a/Rakefile
+++ b/Rakefile
@@ -7,7 +7,7 @@ require 'rake/clean'
CLOBBER.include 'build'
-task default: ['source/main.elna', 'build/gcc/elna'] do |t|
+task default: ['source/main.elna', 'build/gcc/bin/elna'] do |t|
sources, compiler = t.prerequisites.partition { |f| f.end_with? '.elna' }
sh(*compiler, '--parse', *sources)
diff --git a/boot/evaluator.cc b/boot/evaluator.cc
index a96d8ab..4eed818 100644
--- a/boot/evaluator.cc
+++ b/boot/evaluator.cc
@@ -299,14 +299,7 @@ namespace elna::boot
{
return constant->value;
}
- const std::shared_ptr<variable_info> variable = symbol->is_variable();
-
- if (variable == nullptr
- || resolve_aliases(variable->symbol).get<constant_type>() == nullptr)
- {
- return std::nullopt;
- }
- return variable->value;
+ return std::nullopt;
}
std::optional<constant_value> evaluator::evaluate_array_access(array_access_expression& subject)
diff --git a/rakelib/compiler.rake b/rakelib/compiler.rake
index 4731e1d..5cd19d5 100644
--- a/rakelib/compiler.rake
+++ b/rakelib/compiler.rake
@@ -9,11 +9,11 @@ require 'rake/clean'
CLEAN.include 'build/gcc'
Rake.application.add_loader('d', Rake::MakefileLoader.new)
-FileList['build/gcc/**/*.d'].each { |file| import file }
+FileList['build/gcc/obj/**/*.d'].each { |file| import file }
-rule(%r{gcc/.+\.o$} => lambda { |file|
+rule(%r{gcc/obj/.+\.o$} => lambda { |file|
source = Pathname.new('source') +
- Pathname.new(file).relative_path_from('build/gcc').sub_ext('.elna')
+ Pathname.new(file).relative_path_from('build/gcc/obj').sub_ext('.elna')
[source, 'build/host/install/bin/gelna']
}) do |t|
@@ -23,9 +23,11 @@ rule(%r{gcc/.+\.o$} => lambda { |file|
end
sources = FileList['source/**/*.elna'].select { |file| file == file.downcase }
-file 'build/gcc/elna' => sources.map { |file|
- Pathname.new('build/gcc') +
+file 'build/gcc/bin/elna' => sources.map { |file|
+ Pathname.new('build/gcc/obj') +
Pathname.new(file).relative_path_from('source').sub_ext('.o')
} do |t|
+ Pathname.new(t.name).dirname.mkpath
+
sh 'build/host/install/bin/gcc', '-o', t.name, *t.prerequisites
end
diff --git a/testsuite/compilable/compile_time_array_length.elna b/testsuite/compilable/compile_time_array_length.elna
deleted file mode 100644
index 9e2c896..0000000
--- a/testsuite/compilable/compile_time_array_length.elna
+++ /dev/null
@@ -1,7 +0,0 @@
-module
-
-var
- source: const [3]Int := [1, 2, 3]
- target: Word := source.length
-
-end.
diff --git a/testsuite/compilable/const_negation.elna b/testsuite/compilable/const_negation.elna
deleted file mode 100644
index 1dd45f4..0000000
--- a/testsuite/compilable/const_negation.elna
+++ /dev/null
@@ -1,9 +0,0 @@
-program()
-var
- x: const Int := -5
- y: const Int := -x
-
-begin
- assert(x = -5);
- assert(y = 5);
-end.
diff --git a/testsuite/compilable/const_var_chain.elna b/testsuite/compilable/const_var_chain.elna
deleted file mode 100644
index 438b79a..0000000
--- a/testsuite/compilable/const_var_chain.elna
+++ /dev/null
@@ -1,8 +0,0 @@
-program()
-var
- x: const Int := 42
- y: Int := x
-
-begin
- assert(y = 42)
-end.
diff --git a/testsuite/runnable/case_constant_label.elna b/testsuite/runnable/case_constant_label.elna
index 1b01736..3f7a483 100644
--- a/testsuite/runnable/case_constant_label.elna
+++ b/testsuite/runnable/case_constant_label.elna
@@ -1,14 +1,15 @@
program()
+const
+ BASE = 2
+ LIMIT = BASE
var
- base: const Int := 2
- limit: const Int := base
x: Int := 2
matched: Bool := false
begin
case x of
1: assert(false)
- | limit: matched := true
+ | LIMIT: matched := true
end;
assert(matched)
end.
diff --git a/testsuite/runnable/compile_time_array_access.elna b/testsuite/runnable/compile_time_array_access.elna
index 5ce10a0..146fd27 100644
--- a/testsuite/runnable/compile_time_array_access.elna
+++ b/testsuite/runnable/compile_time_array_access.elna
@@ -1,8 +1,8 @@
program()
-var
- array: const [3]Int := [1, 2, 3]
- i: const Int := array[2]
+const
+ ARRAY = [1, 2, 3]
+ I = ARRAY[2]
begin
- assert(i = 2)
+ assert(I = 2)
end.
diff --git a/testsuite/runnable/inferred_variable.elna b/testsuite/runnable/inferred_variable.elna
index 48d7414..edc3399 100644
--- a/testsuite/runnable/inferred_variable.elna
+++ b/testsuite/runnable/inferred_variable.elna
@@ -2,8 +2,8 @@ program()
var
x := 42
c: const := 10
- y := c
- arr := [c, 2]
+ y := 10
+ arr := [10, 2]
begin
x := x + 1;
diff --git a/tools/tree-sitter/grammar.js b/tools/tree-sitter/grammar.js
index ca0e7d5..4aab2fa 100644
--- a/tools/tree-sitter/grammar.js
+++ b/tools/tree-sitter/grammar.js
@@ -98,7 +98,7 @@ module.exports = grammar({
type_section: $ => seq(
'type',
- repeat1(seq($.type_declaration, optional(';'))),
+ repeat(seq($.type_declaration, optional(';'))),
),
type_declaration: $ => seq(
@@ -109,7 +109,7 @@ module.exports = grammar({
const_section: $ => seq(
'const',
- repeat1(seq($.const_declaration, optional(';'))),
+ repeat(seq($.const_declaration, optional(';'))),
),
const_declaration: $ => seq(
@@ -140,12 +140,12 @@ module.exports = grammar({
var_section: $ => seq(
'var',
- repeat1(seq($.variable_declaration, optional(';'))),
+ repeat(seq($.variable_declaration, optional(';'))),
),
threadvar_section: $ => seq(
'threadvar',
- repeat1(seq($.variable_declaration, optional(';'))),
+ repeat(seq($.variable_declaration, optional(';'))),
),
variable_declaration: $ => seq(