Commit Graph

52 Commits (ipv6)

Author SHA1 Message Date
Nicolas Hake 60829ae5e4 Aul: Don't let exceptions escape from constant resolver
Letting the constant resolver throw exceptions prevented us from doing
checking on later initializers anyway, so instead we'll send them to the
error handler. As a special bonus this makes it so we don't crash when
a global variable initializer has errors. Fixes #1850, #1855.
2016-11-30 13:37:33 +01:00
Nicolas Hake eda6cc9c7f Aul: Gracefully handle errors in codegen (#1840)
By continuing to generate bytecode even after an error is found, we're
able to find more syntax errors and will also be able to keep the value
stack at the expected height.
2016-11-13 11:07:21 +01:00
Nicolas Hake e2fd7095c1 Merge branch 'ast'
# Conflicts:
#	src/C4Include.h
#	src/script/C4AulCompiler.cpp
#	src/script/C4AulParse.cpp
#	src/script/C4AulParse.h
#	src/script/C4ScriptHost.cpp
#	src/script/C4ScriptHost.h
#	tests/CMakeLists.txt
2016-10-20 17:33:02 +02:00
Nicolas Hake 266feeda4d Aul: Add AST generation tests
Just making sure the parser creates the AST the way we expect before we
hand off the code to the codegen.
2016-10-20 17:20:55 +02:00
Nicolas Hake 5f3dbdd417 Reject function expressions inside proplists inside functions
These aren't supported by the codegen on account of not working in
savegames.
2016-10-19 14:20:45 +02:00
Nicolas Hake 9caaf1e298 Aul: Split out error handling into a separate class for easier testing
By using an extern error handler in the script engine, we can mock that
handler and make sure something that should fail actually does, instead
of having to parse log messages.
2016-10-19 14:20:41 +02:00
Nicolas Hake ab1e6bd5a4 Allow proplist-local funcs to access vars of their owner's prototype
Thanks to JCaesar for providing this test case.
2016-10-19 13:45:35 +02:00
Nicolas Hake 46f342dd0c Tests: Split test helper functions into Expr/Code/Script evaluators
RunExpr will evaluate and return the value of a single expression.
RunCode will evaluate a full function body.
RunScript will compile a complete standalone script and return the
return value of its Main() function.
2016-10-19 13:45:11 +02:00
Nicolas Hake 49a98e54a5 Add test for 57a35bf fix
So it turns out that the fix stops the engine from crashing, but it
still doesn't seem to generate valid code - Aul emits an internal error
at runtime.
2016-06-05 13:36:32 +02:00
Nicolas Hake 092a23c2f7 Aul: Parse scripts into an AST, then generate bytecode from that
This commit contains a fairly substantial rewrite of the C4Script code
generator. Instead of generating bytecode while parsing the script,
we're now parsing the script into a syntax tree, and have any further
processing happen on that instead of the raw source.

At this time, the code generator emits the same bytecode as the old
parser; there are several optimization opportunities that arise from the
new possibility to emit code out of order from its specification by the
author.

Compared to the old compiler, this one is still rather deficient when
dealing with incorrect code; it's also not emitting several warnings
that used to be diagnosed.
2016-05-12 19:43:48 +02:00
Nicolas Hake f2bf34ff3e Add missing semicolons to CreateEffect tests 2016-05-09 12:33:56 +02:00
Günther Brammer b00b8554ab Merge branch script 2016-04-28 03:25:44 +02:00
Günther Brammer d8e8d25ab4 Aul tests: CreateEffect 2016-04-28 02:59:11 +02:00
Günther Brammer 5fbac346d3 Incompatible type warnings work for parameters with type declarations 2016-04-24 19:40:27 +02:00
Nicolas Hake 607eb8e246 Aul tests: Test conditionals 2016-04-24 14:01:23 +02:00
Nicolas Hake 2eba2e72f3 Aul tests: Test parameter passing 2016-04-24 14:01:23 +02:00
Nicolas Hake 79b6d993df Aul tests: Test nested loops, loop control statements 2016-04-24 14:01:23 +02:00
Nicolas Hake d21f75829d Aul tests: stop GMock from complaining about uninteresting log calls 2016-04-24 14:01:23 +02:00
Nicolas Hake f7c29c93e8 Tests: Add index of current test to script name for better errors 2016-04-07 20:52:30 +02:00
Günther Brammer 5bb3d7cb77 Use a null C4ScriptHost to parse DirectExec code
This mostly makes Parse_Expression use the case for functions in proplists
instead of the other for local variable lookup.
2016-02-02 02:57:48 +01:00
Günther Brammer 6f98fb2e66 Remove C4AulScript class
It isn't needed to hold engine functions anymore, because those are just
put into C4PropLists.
2016-02-02 02:57:47 +01:00
Günther Brammer c444f85bae Add more C4Script tests
This time exercising some code I managed to break by adding more
optimizations.
2016-02-02 02:57:45 +01:00
Günther Brammer 1e8dafd75d Fix Translate AulTest when compiling without string deduplication 2016-02-02 02:57:45 +01:00
Günther Brammer 08f1037866 Add some more C4Script tests 2016-01-25 00:43:24 +01:00
Günther Brammer 9dadfba5af Move GlobalNamed.SetNameList call after Link() into Link()
It isn't clear whether that call is necessary since the C4AulScriptEngine
constructor already does this, but it is clear that duplicating the call
all over is a bad idea.
2016-01-25 00:00:58 +01:00
Günther Brammer 8425169dd6 Rename C4Script.h to C4GameScript.h 2016-01-24 12:27:23 +01:00
Günther Brammer 20c22582ec Move DirectExec from C4AulScript to C4AulExec
In the long term, there is no reason DirectExec should be concerned with
C4AulScript/C4ScriptHost. In the meantime, the lookup code from Fneval can
be moved into the function.

This allows eval in scenario script to access scenario script locals, but
that seems harmless.
2016-01-24 12:27:23 +01:00
Günther Brammer 93bf8f4779 Script: Allow "new Foo {}" in constant expressions 2016-01-24 12:27:23 +01:00
Günther Brammer 507b63a55a Functions store their containing proplist instead of the C4AulScript
The C4AulScript containing the source of the function was already mostly
used to get the relevant proplist or available from context. This will
allow more than one proplist plus the global one per scripthost to contain
functions.
2016-01-24 12:27:23 +01:00
Günther Brammer e790d2c327 Remove duplicated stubs for the scriptengine from mape 2016-01-24 02:09:14 +01:00
Günther Brammer 5a570b96f1 Remove now unnecessary stubs from C4ScriptStandaloneStubs 2016-01-24 02:09:14 +01:00
Günther Brammer b7ecc49a02 Remove a bit of dead code from C4Value 2016-01-24 02:09:13 +01:00
Günther Brammer d81c93b7d4 Add a few C4Script tests 2016-01-24 02:09:13 +01:00
Nicolas Hake 4fddda20f9 C4Script: Accept array parameter for Min, Max
Min/Max with array parameter will return the smallest/largest value of
all elements of the array. If any array element is not an integer, nor
convertible to integer, the function will fail.
2016-01-23 13:49:10 +01:00
Nicolas Hake b7cffa5e82 Aul tests: Assert that Translate() warns when a translation is missing
I'm not a huge fan of testing for warnings by hijacking the logging
routines, but right now there's no way to exfiltrate warnings from Aul
any other way, so it'll have to do.

Overriding the logging functions from C4SimpleLog.cpp has the nice
additional advantage that expected runtime errors no longer get written
to stdout - this is okay because we're already checking that an
exception is thrown.
2016-01-23 13:49:09 +01:00
Nicolas Hake 53fe0fa1cc Aul Tests: Move Translate() test stub to predefined functions test
As small as the Translate() test is, it is exercising a predefined
function and not just the Aul engine itself.
2016-01-23 13:49:08 +01:00
Nicolas Hake 24839204ce Tests: Add tests for Min, Max 2016-01-23 13:49:07 +01:00
Nicolas Hake b128f3a0a4 Tests: Split math tests out of base aul test file 2016-01-23 13:49:06 +01:00
Nicolas Hake 8136edb45a Pull tests into main CMake project 2016-01-23 13:49:05 +01:00
Nicolas Hake 7d186516a8 Tests: Move pthread dependency to gtest
The test binaries don't directly use pthread (but gtest does), so the
dependency should be added to gtest instead of the binary itself.
2015-12-13 14:33:02 +01:00
Nicolas Hake a9f93378fa Add some edge case tests for Aul arithmetic
These tests include testing for #1389 "Strange numbers on 64 bit".
2015-12-08 13:17:42 +01:00
Nicolas Hake 184b36d08a Add helper function to create test binaries 2015-12-08 13:17:38 +01:00
Nicolas Hake 2b83c1c778 Tests: Add C4ScriptStandaloneStubs.cpp to test project 2015-12-08 13:17:37 +01:00
Nicolas Hake 3f5efe65ad Tests: Link winmm 2015-02-08 15:05:14 +01:00
Nicolas Hake 849f8fe98d GTest: Also accept fused sources 2015-02-08 15:05:12 +01:00
Nicolas Hake 1a1cecadd4 Update license texts
Some files, most notably ObjC and test cases, hadn't been updated to use
the new license header. Fix this.
2015-02-08 15:05:11 +01:00
Oliver Schneider 3c3621072c cmake: properly removed gtest from the all target 2013-01-30 13:06:22 +01:00
Oliver Schneider c43a682785 tests: Compile gtest from source, add a few new tests
GTest does not ship precompiled binaries anymore. They are now compiled
using the CMakelists.txt from gtest.

Add basic unit tests for C4Value, DirectExec and C4StringTable.
2013-01-29 01:07:22 +01:00
Nicolas Hake d5669964b8 tests: Fix on linux-gcc 2011-10-16 14:17:43 +02:00
Nicolas Hake 6efa0ac05e win32: Correctly read back unicode strings from registry 2011-07-27 17:30:56 +02:00