diff options
author | Eugene Sandulenko | 2016-06-16 15:00:46 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-08-03 23:40:36 +0200 |
commit | 4b56951d3038836c32d8a1a0db3da856a720f1fc (patch) | |
tree | 4d10a17f4b5fd820b6251226a8a4a882e3f1f60c | |
parent | d90a8605d238786d53e645743d96b8c584ca3fb6 (diff) | |
download | scummvm-rg350-4b56951d3038836c32d8a1a0db3da856a720f1fc.tar.gz scummvm-rg350-4b56951d3038836c32d8a1a0db3da856a720f1fc.tar.bz2 scummvm-rg350-4b56951d3038836c32d8a1a0db3da856a720f1fc.zip |
DIRECTOR: Started work on converting Lingo into compiler
-rw-r--r-- | engines/director/lingo/lingo-funcs.cpp | 18 | ||||
-rw-r--r-- | engines/director/lingo/lingo-gr.cpp | 12 | ||||
-rw-r--r-- | engines/director/lingo/lingo-gr.y | 12 | ||||
-rw-r--r-- | engines/director/lingo/lingo-lex.cpp | 2 | ||||
-rw-r--r-- | engines/director/lingo/lingo-lex.l | 2 | ||||
-rw-r--r-- | engines/director/lingo/lingo.cpp | 12 | ||||
-rw-r--r-- | engines/director/lingo/lingo.h | 20 | ||||
-rw-r--r-- | engines/director/score.h | 7 |
8 files changed, 66 insertions, 19 deletions
diff --git a/engines/director/lingo/lingo-funcs.cpp b/engines/director/lingo/lingo-funcs.cpp index 6f4b1b22e9..5422b3ca9b 100644 --- a/engines/director/lingo/lingo-funcs.cpp +++ b/engines/director/lingo/lingo-funcs.cpp @@ -154,4 +154,22 @@ int Lingo::func_mci(Common::String *s) { return 0; } +void Lingo::func_constpush() { +} + +void Lingo::func_add() { +} + +void Lingo::func_sub() { +} + +void Lingo::func_mul() { +} + +void Lingo::func_div() { +} + +void Lingo::func_negate() { +} + } diff --git a/engines/director/lingo/lingo-gr.cpp b/engines/director/lingo/lingo-gr.cpp index 343817c2b1..c34a25f839 100644 --- a/engines/director/lingo/lingo-gr.cpp +++ b/engines/director/lingo/lingo-gr.cpp @@ -1374,7 +1374,7 @@ yyreduce: case 6: #line 74 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = (yyvsp[(1) - (1)].i); ;} + { (yyval.i) = g_lingo->code2(g_lingo->func_constpush, (inst)(yyvsp[(1) - (1)].i)); ;} break; case 7: @@ -1384,22 +1384,22 @@ yyreduce: case 8: #line 76 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = (yyvsp[(1) - (3)].i) + (yyvsp[(3) - (3)].i); ;} + { g_lingo->code1(g_lingo->func_add); ;} break; case 9: #line 77 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = (yyvsp[(1) - (3)].i) - (yyvsp[(3) - (3)].i); ;} + { g_lingo->code1(g_lingo->func_sub); ;} break; case 10: #line 78 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = (yyvsp[(1) - (3)].i) * (yyvsp[(3) - (3)].i); ;} + { g_lingo->code1(g_lingo->func_mul); ;} break; case 11: #line 79 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = (yyvsp[(1) - (3)].i) / (yyvsp[(3) - (3)].i); ;} + { g_lingo->code1(g_lingo->func_div); ;} break; case 12: @@ -1409,7 +1409,7 @@ yyreduce: case 13: #line 81 "engines/director/lingo/lingo-gr.y" - { (yyval.i) = -(yyvsp[(2) - (2)].i); ;} + { (yyval.i) = (yyvsp[(2) - (2)].i); g_lingo->code1(g_lingo->func_negate); ;} break; case 14: diff --git a/engines/director/lingo/lingo-gr.y b/engines/director/lingo/lingo-gr.y index f6968b8b4d..14d80d31fd 100644 --- a/engines/director/lingo/lingo-gr.y +++ b/engines/director/lingo/lingo-gr.y @@ -71,14 +71,14 @@ statement: expr { warning("%d", $1); } | func { warning("%d", $1); } ; -expr: INT { $$ = $1; } +expr: INT { $$ = g_lingo->code2(g_lingo->func_constpush, (inst)$1); } | VAR { $$ = vars[*$1]; delete $1; } - | expr '+' expr { $$ = $1 + $3; } - | expr '-' expr { $$ = $1 - $3; } - | expr '*' expr { $$ = $1 * $3; } - | expr '/' expr { $$ = $1 / $3; } + | expr '+' expr { g_lingo->code1(g_lingo->func_add); } + | expr '-' expr { g_lingo->code1(g_lingo->func_sub); } + | expr '*' expr { g_lingo->code1(g_lingo->func_mul); } + | expr '/' expr { g_lingo->code1(g_lingo->func_div); } | '+' expr %prec UNARY { $$ = $2; } - | '-' expr %prec UNARY { $$ = -$2; } + | '-' expr %prec UNARY { $$ = $2; g_lingo->code1(g_lingo->func_negate); } | '(' expr ')' { $$ = $2; } | ; diff --git a/engines/director/lingo/lingo-lex.cpp b/engines/director/lingo/lingo-lex.cpp index 534a13cd12..b639d53749 100644 --- a/engines/director/lingo/lingo-lex.cpp +++ b/engines/director/lingo/lingo-lex.cpp @@ -1841,7 +1841,7 @@ void yyfree (void * ptr ) namespace Director { -int Lingo::parse(char *code) { +int Lingo::parse(const char *code) { YY_BUFFER_STATE bp; yy_delete_buffer(YY_CURRENT_BUFFER); diff --git a/engines/director/lingo/lingo-lex.l b/engines/director/lingo/lingo-lex.l index 6d97d17990..a206f961c6 100644 --- a/engines/director/lingo/lingo-lex.l +++ b/engines/director/lingo/lingo-lex.l @@ -61,7 +61,7 @@ to { return OP_TO; } namespace Director { -int Lingo::parse(char *code) { +int Lingo::parse(const char *code) { YY_BUFFER_STATE bp; yy_delete_buffer(YY_CURRENT_BUFFER); diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 3d166acba0..e338c3d646 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -71,6 +71,8 @@ Lingo::Lingo(DirectorEngine *vm) : _vm(vm) { for (const EventHandlerType *t = &eventHanlerDescs[0]; t->handler != kEventNone; ++t) _eventHandlerTypes[t->handler] = t->name; + + _currentScript = 0; } Lingo::~Lingo() { @@ -78,6 +80,15 @@ Lingo::~Lingo() { void Lingo::addCode(Common::String code, ScriptType type, uint16 id) { debug(0, "Add code %s for type %d with id %d", code.c_str(), type, id); + + if (_scripts[type].contains(id)) { + free(_scripts[type][id]); + } + + _currentScript = new Common::Array<inst>(); + _scripts[type][id] = _currentScript; + + parse(code.c_str()); } void Lingo::processEvent(LEvent event, int entityId) { @@ -87,5 +98,4 @@ void Lingo::processEvent(LEvent event, int entityId) { debug(0, "processEvent(%s) for %d", _eventHandlerTypes[event], entityId); } - } // End of namespace Director diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index 9fb024f30c..c819779a31 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -70,6 +70,9 @@ enum LEvent { kEventStart }; +typedef void (*inst)(void); +#define STOP (inst)0 + class Lingo { public: Lingo(DirectorEngine *vm); @@ -79,13 +82,28 @@ public: void processEvent(LEvent event, int entityId); - int parse(char *code); + int parse(const char *code); + + int code1(inst code) { _currentScript->push_back(code); return _currentScript->size(); } + int code2(inst code_1, inst code_2) { code1(code_1); return code1(code_2); } + int code3(inst code_1, inst code_2, inst code_3) { code1(code_1); code1(code_2); return code1(code_3); } +public: + static void func_add(); + static void func_sub(); + static void func_mul(); + static void func_div(); + static void func_negate(); + static void func_constpush(); int func_mci(Common::String *s); private: Common::HashMap<uint32, const char *> _eventHandlerTypes; Common::HashMap<Common::String, Audio::AudioStream *> _audioAliases; + + Common::HashMap<int32, Common::Array<inst> *> _scripts[kMaxScriptType]; + Common::Array<inst> *_currentScript; + DirectorEngine *_vm; }; diff --git a/engines/director/score.h b/engines/director/score.h index ea2402823d..cd4985fc12 100644 --- a/engines/director/score.h +++ b/engines/director/score.h @@ -102,9 +102,10 @@ enum InkType { }; enum ScriptType { - kMovieScript, - kSpriteScript, - kFrameScript + kMovieScript = 0, + kSpriteScript = 1, + kFrameScript = 2, + kMaxScriptType = 2 }; enum TransitionType { |