Skip to content

v0.1.28

Choose a tag to compare

@gmpassos gmpassos released this 24 Jun 19:42
· 391 commits to master since this release
d56a74d

0.1.28

  • Kotlin language support (parse, run, and translate), reaching parity with the
    existing Java feature set:
    • New lib/src/languages/kotlin/ module: ApolloParserKotlin,
      KotlinGrammarDefinition/KotlinGrammarLexer, ApolloCodeGeneratorKotlin
      and ApolloRunnerKotlin, all built on the shared AST (no AST changes).
    • Grammar covers top-level and class fun declarations, val/var
      declarations (with type inference), Int/Double/Boolean/String/
      Unit/Any/List/Map types, if/else, for (x in ...), while,
      expressions/operators, listOf/mapOf literals, and "$x" / "${expr}"
      string templates. println is normalized to the VM's print.
    • Registered in ApolloVM (getParser/createRunner/createCodeGenerator);
      .kt files already mapped to kotlin.
    • Tests in test/apollovm_kotlin_test.dart cover parse+run and
      Kotlin→Dart/Java/Kotlin translation round-trips.
  • JavaScript (modern ES) language support — fully bidirectional:
    • Parser (ApolloParserJavaScript, JavaScriptGrammarDefinition, JavaScriptGrammarLexer): parses .js/javascript source into the shared ApolloVM AST. Covers classes (fields + methods, static, constructor), top-level function declarations, let/const/var, for/for...of/while, if/else if/else, list literals, ++/--, compound assignment, strict equality (===/!==), and single/double-quoted strings plus back-tick template literals with ${ … } interpolation. Untyped sites map to dynamic; method/function return types are inferred as void (no value-return) or dynamic.
    • Code generator (ApolloCodeGeneratorJavaScript): emits idiomatic modern JS from any loaded AST (Dart, Java, or JS) — let/const, template literals for string interpolation, for...of, top-level functions, untyped params/fields, ===/!==, and Math.trunc(a / b) for integer division.
    • Runner (ApolloRunnerJavaScript): executes JS-parsed ASTs in the VM (subject to the VM's existing limitation that arithmetic requires concrete/inferable types — dynamic-typed arithmetic is unsupported, as for Dart dynamic).
    • Registered javascript/js in ApolloVM.getParser, createRunner, and createCodeGenerator.
    • CLI: apollovm run/translate now work on .js files (the .js extension already mapped to javascript); added a test/hello_world.js fixture and updated the CLI banner to "Dart, Java and JavaScript".
    • Tests: added javascript_basic_* definitions (parse + execute + round-trip + cross-translation to Dart/Java) and a JavaScript generation block to the Dart class-function test.
    • Follow-ups: destructuring, spread, async/await, true constructor semantics with this.x parameters, and full ESM are not yet supported.
  • CLI bug fix: apollovm translate printed Instance of 'Future<StringBuffer>' instead of the translated source — writeAllSources() was stringified without await. Fixed for all languages.
  • Runtime fix — for-each / for...of over any iterable: ASTStatementForEach only accepted an ASTValueArray, so iterating a list bound to a dynamic/Object variable (which resolves to a plain ASTValueStatic) threw at runtime. It now iterates any resolved Iterable (and Map values), and wraps each element into a concretely-typed ASTValue (via ASTValue.fromValue) so per-element operations (e.g. arithmetic, string concatenation) work. Affects all languages; enables JavaScript for...of over arrays.
  • Runtime fix — arithmetic/comparison on dynamically-typed operands: binary operators (+ - * / % == != > < …) dispatched on the operand's static ASTValue.type and only handled concrete primitives, so two dynamic/var/Object operands (e.g. untyped JavaScript parameters) threw Can't perform '+' operation with types: dynamic + dynamic even when the runtime values were real numbers/strings. ASTExpressionOperation.run now resolves each "boxed"/untyped operand to its concrete ASTValue (via ASTValue.fromValue) before dispatching. Affects all languages; enables executing parsed JavaScript arithmetic.
  • JavaScript / is now floating-point division (ASTExpressionOperator.divideAsDouble), matching JS semantics (7 / 2 === 3.5) instead of integer division.
  • JavaScript arrow functions: a named arrow assignment (const add = (a, b) => a + b;, const square = n => n * n;, const greet = () => { … };) is parsed and desugared to a named function declaration — callable by name (add(1, 2)), at top level or as a local statement, with expression or block bodies. Translates to a regular function/method on output. Anonymous arrows passed as callbacks (true closures) are a follow-up.
  • Code generation fix — logical negation of a complex operand: !(a > b) was emitted as !a > b (which re-parses as (!a) > b). The negated operand is now parenthesized when complex. Affects all languages.
  • Tests: broad JavaScript coverage added — parse + execute + translate (to Dart/Java where applicable) + re-execute the generated code: javascript_basic_vars, branches, while_loop, for_loop, comparisons, division, negation, this_method, plus the earlier class_function, control_flow, for_of, arithmetic, and arrow-function definitions.
  • Docs/examples: added per-language runnable examples under example/ — apollovm_example_java.dart, apollovm_example_kotlin.dart and apollovm_example_javascript.dart (each load + run + translate to Dart, with verified output) — and fixed the existing apollovm_example.dart to await writeAllSources() (was printing Instance of 'Future<StringBuffer>'). README updated with a Kotlin section and the CLI banner now reads "Dart, Java, Kotlin and JavaScript".