savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
155 stars 12 forks source link

Override constants with compile-time CLI args #161

Open jemc opened 2 years ago

jemc commented 2 years ago

We want to allow overriding a :const value at compile-time (without editing source code), by specifying a compile-time CLI argument for it.

For example, consider the following program:

:module MyApp
  :const version: "unknown"

:actor Main
  :new (env Env)
    env.out.print("MyApp version: " + MyApp.version)

When compiled as normal, it would print the source-code-defined value ("unknown"):

> savi && ./main

MyApp version: unknown

But when compiled with a compile-time constant value override defined, it would print the overridden value:

> savi --define MyApp.version="v3.5.21 (git a46fde0d)" && ./main

MyApp version: v3.5.21 (git a46fde0d)
jemc commented 2 years ago

It should be possible to override a string constant, a boolean constant, or a numeric constant.

If the constant has some other (unsupported) type, or if the CLI arg fails to parse as the expected type, a compilation error will result, requesting the user to fix the CLI invocation with a supported kind of value defined.