about summary refs log blame commit diff stats
path: root/tools/test_treeshake_translate
blob: 1aa6f068f0280d3e949e1c8040ce514c0789a5f6 (plain) (tree)




























                                                        
#!/bin/sh
# Translate SubX programs using a minified translator.
# Based on ntranslate.

set -e

./build

cat $*          |apps/braces.treeshake.bin   > a.braces

cat a.braces    |apps/calls.treeshake.bin    > a.calls

cat a.calls     |apps/sigils.treeshake.bin   > a.sigils

cat a.sigils    |apps/tests.treeshake.bin    > a.tests

cat a.tests     |apps/assort.treeshake.bin   > a.assort

cat a.assort    |apps/dquotes.treeshake.bin  > a.dquotes

cat a.dquotes   |apps/assort.treeshake.bin   > a.assort2

cat a.assort2   |apps/pack.treeshake.bin     > a.pack

cat a.pack      |apps/survey.treeshake.bin   > a.survey

cat a.survey    |apps/hex.treeshake.bin      > a.elf

chmod +x a.elf
ss="p">)); Real_hardware_types.push_back(parse_type("address:console")); Real_hardware_types.push_back(parse_type("address:resources")); } type_tree* parse_type(string s) { reagent x("x:"+s); type_tree* result = x.type; x.type = NULL; // don't deallocate on return return result; } void teardown_real_hardware_types() { for (int i = 0; i < SIZE(Real_hardware_types); ++i) delete Real_hardware_types.at(i); Real_hardware_types.clear(); } :(before "End Checks") Transform.push_back(check_for_misuse_of_real_hardware); :(code) void check_for_misuse_of_real_hardware(const recipe_ordinal r) { const recipe& caller = get(Recipe, r); if (caller.name == "main") return; if (starts_with(caller.name, "scenario_")) return; trace(101, "transform") << "--- check if recipe " << caller.name << " has any dependency-injection mistakes" << end(); for (int index = 0; index < SIZE(caller.steps); ++index) { const instruction& inst = caller.steps.at(index); if (is_primitive(inst.operation)) continue; for (int i = 0; i < SIZE(inst.ingredients); ++i) { const reagent& ing = inst.ingredients.at(i); if (!is_literal(ing) || ing.name != "0") continue; const recipe& callee = get(Recipe, inst.operation); if (!callee.has_header) continue; if (i >= SIZE(callee.ingredients)) continue; const reagent& expected_ing = callee.ingredients.at(i); for (int j = 0; j < SIZE(Real_hardware_types); ++j) { if (*Real_hardware_types.at(j) == *expected_ing.type) raise << maybe(caller.name) << "'" << to_original_string(inst) << "': only 'main' can pass 0 into a " << to_string(expected_ing.type) << '\n' << end(); } } } } void test_warn_on_using_real_screen_directly_in_non_main_recipe() { Hide_errors = true; transform( "def foo [\n" " print 0, 34\n" "]\n" ); CHECK_TRACE_CONTENTS( "error: foo: 'print 0, 34': only 'main' can pass 0 into a (address screen)\n" ); }