Add lexer and parser sources

This commit is contained in:
2025-06-14 23:57:48 +02:00
parent d5e2d53e9b
commit f524311f06
25 changed files with 3475 additions and 427 deletions

View File

@ -3,74 +3,39 @@
# obtain one at https://mozilla.org/MPL/2.0/.
require 'pathname'
require 'open3'
require 'rake/clean'
require_relative 'tools/support'
# Dependencies.
GCC_VERSION = "15.1.0"
# Paths.
HOST_GCC = TMP + 'host/gcc'
TMP = Pathname.new('./build')
HOST_INSTALL = TMP + 'host/install'
CLOBBER.include TMP
CLEAN.include(TMP + 'boot')
directory(TMP + 'tools')
directory HOST_GCC
directory HOST_INSTALL
task default: [TMP + 'elna'] do
sh (TMP + 'elna').to_path, '--parse', 'source.elna'
task default: ['source/main.elna', TMP + 'boot/elna'] do |t|
sources, compiler = t.prerequisites.partition { |f| f.end_with? '.elna' }
sh *compiler, '--parse', *sources
end
namespace :boot do
desc 'Download and configure the bootstrap compiler'
task configure: [TMP + 'tools', HOST_GCC, HOST_INSTALL] do
url = URI.parse "https://gcc.gnu.org/pub/gcc/releases/gcc-#{GCC_VERSION}/gcc-#{GCC_VERSION}.tar.xz"
options = find_build_target GCC_VERSION
source_directory = TMP + "tools/gcc-#{GCC_VERSION}"
frontend_link = source_directory + 'gcc'
rule(/boot\/.+\.o$/ => ->(file) {
Pathname.new('source') +
Pathname.new(file).relative_path_from(TMP + 'boot').sub_ext('.elna')
}) do |t|
Pathname.new(t.name).dirname.mkpath
compiler = HOST_INSTALL + 'bin/gelna'
download_and_pipe url, source_directory.dirname, ['tar', '-Jxv']
sh 'contrib/download_prerequisites', chdir: source_directory.to_path
File.symlink Pathname.new('.').relative_path_from(frontend_link), (frontend_link + 'elna')
configure_options = [
"--prefix=#{HOST_INSTALL.realpath}",
"--with-sysroot=#{options.sysroot.realpath}",
'--enable-languages=c,c++,elna',
'--disable-bootstrap',
'--disable-multilib',
"--target=#{options.build}",
"--build=#{options.build}",
"--host=#{options.build}"
]
flags = '-O0 -g -fPIC -I/opt/homebrew/Cellar/flex/2.6.4_2/include'
env = {
'CC' => options.gcc,
'CXX' => options.gxx,
'CFLAGS' => flags,
'CXXFLAGS' => flags,
}
configure = source_directory.relative_path_from(HOST_GCC) + 'configure'
sh env, configure.to_path, *configure_options, chdir: HOST_GCC.to_path
end
desc 'Make and install the bootstrap compiler'
task :make do
cwd = HOST_GCC.to_path
sh 'make', '-j', Etc.nprocessors.to_s, chdir: cwd
sh 'make', 'install', chdir: cwd
end
sh compiler.to_path, '-c', '-o', t.name, *t.prerequisites
end
desc 'Build the bootstrap compiler'
task boot: %w[boot:configure boot:make]
file TMP + 'boot/elna' => FileList['source/**/*.elna'].reject { |file|
file != file.downcase
}.map { |file|
TMP + 'boot' +
Pathname.new(file).relative_path_from('source').sub_ext('.o')
} do |t|
compiler = HOST_INSTALL + 'bin/gcc'
file (TMP + 'elna').to_path => ['source.elna']
file (TMP + 'elna').to_path => [(HOST_INSTALL + 'bin/gelna').to_path] do |task|
sh (HOST_INSTALL + 'bin/gelna').to_path, '-o', task.name, task.prerequisites.first
sh compiler.to_path, '-o', t.name, *t.prerequisites
end