Cleanup after remastering

This commit is contained in:
louis 2014-02-11 11:33:43 +01:00
parent c41a598661
commit ed074dc6d6
72 changed files with 0 additions and 2227 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1 +0,0 @@


View file

@ -1 +0,0 @@


View file

@ -1 +0,0 @@


View file

@ -1 +0,0 @@


View file

@ -1 +0,0 @@


View file

@ -1 +0,0 @@


Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,30 +0,0 @@
E:\projets\rpn\Debug\cl.command.1.tlog
E:\projets\rpn\Debug\CL.read.1.tlog
E:\projets\rpn\Debug\CL.write.1.tlog
E:\projets\rpn\Debug\link.3260.read.1.tlog
E:\projets\rpn\Debug\link.3260.write.1.tlog
E:\projets\rpn\Debug\link.3260-cvtres.read.1.tlog
E:\projets\rpn\Debug\link.3260-cvtres.write.1.tlog
E:\projets\rpn\Debug\link.command.1.tlog
E:\projets\rpn\Debug\link.read.1.tlog
E:\projets\rpn\Debug\link.write.1.tlog
E:\projets\rpn\Debug\link-cvtres.read.1.tlog
E:\projets\rpn\Debug\link-cvtres.write.1.tlog
E:\projets\rpn\Debug\mt.command.1.tlog
E:\projets\rpn\Debug\mt.read.1.tlog
E:\projets\rpn\Debug\mt.write.1.tlog
E:\projets\rpn\Debug\rc.command.1.tlog
E:\projets\rpn\Debug\rc.read.1.tlog
E:\projets\rpn\Debug\rc.write.1.tlog
E:\PROJETS\RPN\DEBUG\RPN.EXE
E:\PROJETS\RPN\DEBUG\RPN.EXE.EMBED.MANIFEST
E:\PROJETS\RPN\DEBUG\RPN.EXE.EMBED.MANIFEST.RES
E:\PROJETS\RPN\DEBUG\RPN.EXE.INTERMEDIATE.MANIFEST
E:\PROJETS\RPN\DEBUG\RPN.ILK
E:\PROJETS\RPN\DEBUG\RPN.OBJ
E:\PROJETS\RPN\DEBUG\RPN.PDB
E:\projets\rpn\Debug\rpn.vcxprojResolveAssemblyReference.cache
E:\projets\rpn\Debug\rpn.write.1.tlog
E:\projets\rpn\Debug\rpn_manifest.rc
E:\projets\rpn\Debug\vc100.idb
E:\PROJETS\RPN\DEBUG\VC100.PDB

Binary file not shown.

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

Binary file not shown.

View file

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

Binary file not shown.

View file

@ -1,2 +0,0 @@
#v4.0:v100:false
Debug|Win32|E:\projets\rpn\|

View file

@ -1,30 +0,0 @@
Build started 11/01/2014 18:53:53.
1>Project "E:\projets\rpn\rpn.vcxproj" on node 2 (rebuild target(s)).
1>_PrepareForClean:
Deleting file "Debug\rpn.lastbuildstate".
InitializeBuildStatus:
Creating "Debug\rpn.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt rpn.cpp
rpn.cpp
ManifestResourceCompile:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /nologo /fo"Debug\rpn.exe.embed.manifest.res" Debug\rpn_manifest.rc
Link:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"E:\projets\rpn\Debug\rpn.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Debug\rpn.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\projets\rpn\Debug\rpn.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:\projets\rpn\Debug\rpn.lib" /MACHINE:X86 Debug\rpn.exe.embed.manifest.res
Debug\rpn.obj
Manifest:
Deleting file "Debug\rpn.exe.embed.manifest".
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /out:"Debug\rpn.exe.embed.manifest" /manifest Debug\rpn.exe.intermediate.manifest
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /nologo /fo"Debug\rpn.exe.embed.manifest.res" Debug\rpn_manifest.rc
LinkEmbedManifest:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"E:\projets\rpn\Debug\rpn.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Debug\rpn.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\projets\rpn\Debug\rpn.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:\projets\rpn\Debug\rpn.lib" /MACHINE:X86 Debug\rpn.exe.embed.manifest.res
Debug\rpn.obj
rpn.vcxproj -> E:\projets\rpn\Debug\rpn.exe
FinalizeBuildStatus:
Deleting file "Debug\rpn.unsuccessfulbuild".
Touching "Debug\rpn.lastbuildstate".
1>Done Building Project "E:\projets\rpn\rpn.vcxproj" (rebuild target(s)).
Build succeeded.
Time Elapsed 00:00:01.07

Binary file not shown.

Binary file not shown.

View file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,40 +0,0 @@
========================================================================
CONSOLE APPLICATION : rpn Project Overview
========================================================================
AppWizard has created this rpn application for you.
This file contains a summary of what you will find in each of the files that
make up your rpn application.
rpn.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
rpn.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
rpn.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named rpn.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,16 +0,0 @@
E:\projets\rpn\Release\cl.command.1.tlog
E:\projets\rpn\Release\CL.read.1.tlog
E:\projets\rpn\Release\CL.write.1.tlog
E:\projets\rpn\Release\link.command.1.tlog
E:\projets\rpn\Release\link.read.1.tlog
E:\projets\rpn\Release\link.write.1.tlog
E:\projets\rpn\Release\mt.command.1.tlog
E:\projets\rpn\Release\mt.read.1.tlog
E:\projets\rpn\Release\mt.write.1.tlog
E:\PROJETS\RPN\RELEASE\RPN.EXE
E:\PROJETS\RPN\RELEASE\RPN.EXE.INTERMEDIATE.MANIFEST
E:\PROJETS\RPN\RELEASE\RPN.OBJ
E:\PROJETS\RPN\RELEASE\RPN.PDB
E:\projets\rpn\Release\rpn.vcxprojResolveAssemblyReference.cache
E:\projets\rpn\Release\rpn.write.1.tlog
E:\PROJETS\RPN\RELEASE\VC100.PDB

Binary file not shown.

View file

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View file

@ -1,2 +0,0 @@
#v4.0:v100:false
Release|Win32|E:\projets\rpn\|

View file

@ -1,24 +0,0 @@
Build started 11/01/2014 18:53:51.
1>Project "E:\projets\rpn\rpn.vcxproj" on node 2 (rebuild target(s)).
1>_PrepareForClean:
Deleting file "Release\rpn.lastbuildstate".
InitializeBuildStatus:
Creating "Release\rpn.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt rpn.cpp
rpn.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"E:\projets\rpn\Release\rpn.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Release\rpn.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\projets\rpn\Release\rpn.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:\projets\rpn\Release\rpn.lib" /MACHINE:X86 Release\rpn.obj
Generating code
Finished generating code
rpn.vcxproj -> E:\projets\rpn\Release\rpn.exe
Manifest:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"E:\projets\rpn\Release\rpn.exe;#1" /manifest Release\rpn.exe.intermediate.manifest
FinalizeBuildStatus:
Deleting file "Release\rpn.unsuccessfulbuild".
Touching "Release\rpn.lastbuildstate".
1>Done Building Project "E:\projets\rpn\rpn.vcxproj" (rebuild target(s)).
Build succeeded.
Time Elapsed 00:00:01.65

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,82 +0,0 @@
/*
* TODO en plus des commands hp28s
*/
general:
entry:
- parse en entier la ligne de commande puis si pas de pb de syntaxe entrer
- entrée sur plusieurs lignes
- entrée d'une variable sans '' = rcl
- rpn <"commande entière">
commands:
print
system
alias
alt-R + recherche ?
date / time
/*
* FONCTIONNALITES en plus de celles marquées '*' dans la liste HP-28s commands
*/
verbose augmenter / diminuer la verbosité
vars lister les variables
erase effacer toute la stack
/*
* HP-28s commands
*
* STACK
* DROP*, SWAP*, ROLL, DUP*, OVER, DUP2*, DROP2*, ROT*, LIST->, ROLLD, PICK*, DUPN, DROPN, DEPTH*, ->LIST
*
* STORE
* STO*, RCL*, PURGE*, STO+, STO-, STO*, STO/, SNEG, SINV, SCONJ
*
* MEMORY
* MEM, MENU, ORDER, PATH, HOME, CRDIR, VARS, CLUSR
*
* ALGEBRA
* NEG*(+), COLCT, EXPAN, SIZE, FORM, OBSUB, EXSUB, TAYLR, ISOL, QUAD, SHOW, OBGET, EXGET
*
* STAT
* ∑DAT, ∑PAR, ∑+, ∑-, N∑, CL∑, STO∑, RCL∑, TOT, MEAN, SDEV, VAR, MAX∑, MIN∑, COL∑, CORR, COV, LR,
* PREDEV, UTPC, UTPF, UTPN, UTPT, COMB, PERM
*
* PRINT
* PR1, PRST, PRVAR, PRLCD, CR, TRAC, PRSTC, PRUSR, PRMD
*
* CONTRL
* SST, HALT, ABORT, KILL, WAIT, KEY, BEPP, CLLCD, DISP, CLMF, ERRN, ERRM
*
* BRANCH
* IF*, IFERR, THEN*, ELSE*, END*, START*, FOR*, NEXT*, STEP*, IFT, IFTE, DO, UNTIL, END, WHILE, REPEAT, END
*
* TEST
* !=*, >*, >=*, <*, <=*, SF, CF, FS?, FC?, FS?C, FC?C, AND, OR, XOR, NOT, SAME, ==*, STOF, RCLF, TYPE
*
* CATALOG
* NEXT, PREV, SCAN, USE, FETCH, QUIT
*
* UNITS
* CONVERT
*
* CURSOR
* INS, DEL, ← → ↑ ↓, STD, FIX, SCI, ENG, DEG, RAD, CMD, UNDO, LAST, ML, RDX, PRMD
*
* TRIG
* PI*(+), SIN*, ASIN*, COS*, ACOS*, TAN*, ATAN*, P→R, R→P, R→C, C→R, ARG, →HMS, HMS→, HMS+, HMS-, *D→R, *R→D
*
* LOGS
* LOG*, ALOG*, LN*, EXP*, LNP1, EXPM, SINH*, ASINH*, COSH*, ACOSH*, TANH*, ATANH*
*
* SOLV
* STEQ, RCEQ, ISOL, QUAD, SHOW, ROOT,
*
* PLOT
* PPAR, STEQ, RCEQ, PMIN, PMAX, INDEP, DRAW, RES, AXES, CENTR, *W, *H, STO∑, RCL∑, COL∑, SCL∑, DRW∑, CLLCD, DIGTIZ
*
* CUSTOM
* MENU, CUSTOM
*
* integration, differentiation, flags, reserved variables, system operations
*/

Binary file not shown.

View file

@ -1,46 +0,0 @@
void plus()
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
putf(getf() + getf());
}
void minus()
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() - first);
}
void mul()
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
putf(getf() * getf());
}
void div()
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
// arithmetic faults are managed by c++
floating_t first = getf();
putf(getf() / first);
}
void neg()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
putf(-getf());
}

View file

@ -1,165 +0,0 @@
//
int rpn_if(branch& myobj)
{
// myobj.arg1 = 'if' condition evaluation value
MIN_ARGUMENTS_RET(1, -1);
ARG_IS_OF_TYPE_RET(0, cmd_number, -1);
myobj.arg1 = ((getf() != 0) ? 1 : 0);
return -1;
}
int rpn_then(branch& myobj)
{
// myobj.arg1 = index of then + 1
// myobj.arg2 = index of else + 1 or end + 1
// myobj.arg3 = index of if
// if condition is true -> arg1 (= jump to then + 1)
// else -> arg2 (= jump to else + 1 or end + 1)
branch* if_cmd = (branch*)seq_obj(myobj.arg3);
if (if_cmd->arg1 == 1)
return myobj.arg1;
else
return myobj.arg2;
}
int rpn_else(branch& myobj)
{
// myobj.arg1 = index of else + 1
// myobj.arg2 = index of end + 1
// myobj.arg3 = index of if
// if condition was false -> arg1 (= jump to else + 1)
// if condition was true -> arg2 (= jump to end + 1)
branch* if_cmd = (branch*)seq_obj(myobj.arg3);
if (if_cmd->arg1 == 1)
return myobj.arg2;
else
return myobj.arg1;
}
void rpn_end(void)
{
// nothing
}
int rpn_start(branch& myobj)
{
MIN_ARGUMENTS_RET(2, 1);
ARG_IS_OF_TYPE_RET(0, cmd_number, -1);
ARG_IS_OF_TYPE_RET(1, cmd_number, -1);
// farg1 = first value of start command
// farg2 = last value of start command
myobj.farg2 = getf();
myobj.farg1 = getf();
return -1;
}
int rpn_for(branch& myobj)
{
MIN_ARGUMENTS_RET(2, 1);
ARG_IS_OF_TYPE_RET(0, cmd_number, -1);
ARG_IS_OF_TYPE_RET(1, cmd_number, -1);
symbol* sym = ((symbol*)seq_obj(myobj.arg1));
// farg1 = first value of for command
// farg2 = last value of for command
// arg1 = index of symbol to increase
myobj.farg2 = getf();
myobj.farg1 = getf();
// store symbol with first value
_heap->add(sym->_name, &number(myobj.farg1), sizeof(number), cmd_number);
return myobj.arg1 + 1;
}
int rpn_next(branch& myobj)
{
// arg1 = index of start or for command in program
// farg1 = current count
branch* start_or_for = (branch*)seq_obj(myobj.arg1);
if (! myobj.arg_bool)
{
myobj.arg_bool = true;
myobj.farg1 = start_or_for->farg1;
}
// increment then test
myobj.farg1++;
// for command: increment symbol too
if (start_or_for->arg1 != -1)
{
void* obj;
unsigned int size;
int type;
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
// check symbol variable is a number, then increase
if (_heap->get(var->_name, obj, size, type) && (type == cmd_number))
((number*)obj)->_value = myobj.farg1;
}
//test value
if (myobj.farg1 > start_or_for->farg2)
{
// end of loop
myobj.arg_bool = false;// init again next time
return -1;
}
else
{
// for command: next instruction will be after symbol variable
if (start_or_for->arg1 != -1)
return start_or_for->arg1 + 1;
// start command: next instruction will be after start command
else
return myobj.arg1 + 1;
}
}
int rpn_step(branch& myobj)
{
// arg1 = index of start or for command in program
// farg1 = current count
floating_t step = getf();
branch* start_or_for = (branch*)seq_obj(myobj.arg1);
if (! myobj.arg_bool)
{
myobj.arg_bool = true;
myobj.farg1 = start_or_for->farg1;
}
// increment then test
myobj.farg1 += step;
// for command: increment symbol too
if (start_or_for->arg1 != -1)
{
void* obj;
unsigned int size;
int type;
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
// check symbol variable is a number, then increase
if (_heap->get(var->_name, obj, size, type) && (type == cmd_number))
((number*)obj)->_value = myobj.farg1;
}
//test value
if (((step>0) && (myobj.farg1 > start_or_for->farg2))
|| ((step<0) && (myobj.farg1 < start_or_for->farg2)))
{
// end of loop
myobj.arg_bool = false;// init again next time
return -1;
}
else
{
// for command: next instruction will be after symbol variable
if (start_or_for->arg1 != -1)
return start_or_for->arg1 + 1;
// start command: next instruction will be after start command
else
return myobj.arg1 + 1;
}
}

View file

@ -1,90 +0,0 @@
program::keyword_t program::_keywords[] =
{
//GENERAL
{ cmd_keyword, "", NULL, "\nGENERAL"},
{ cmd_keyword, "nop", &program::nop, "no operation"},
{ cmd_keyword, "?", &program::help, "" },
{ cmd_keyword, "h", &program::help, "" },
{ cmd_keyword, "help", &program::help, "(or h or ?) this help message" },
{ cmd_keyword, "q", &program::good_bye, "" },
{ cmd_keyword, "quit", &program::good_bye, "(or q or exit) quit software" },
{ cmd_keyword, "exit", &program::good_bye, "" },
{ cmd_keyword, "verbose", &program::verbose, "set verbosity, from 0 (not verbose) to > 0" },
{ cmd_keyword, "test", &program::test, "" }, //not seen by user
//ALGEBRA
{ cmd_undef, "", NULL, "\nALGEBRA"},
{ cmd_keyword, "+", &program::plus, "binary operator +" },
{ cmd_keyword, "-", &program::minus, "binary operator -" },
{ cmd_keyword, "neg", &program::neg , "unary operator - (negation)" },
{ cmd_keyword, "*", &program::mul, "binary operator *" },
{ cmd_keyword, "/", &program::div, "binary operator /" },
//TEST
{ cmd_undef, "", NULL, "\nTEST"},
{ cmd_keyword, ">", &program::sup, "binary operator >" },
{ cmd_keyword, ">=", &program::sup_eq, "binary operator >=" },
{ cmd_keyword, "<", &program::inf, "binary operator <" },
{ cmd_keyword, "<=", &program::inf_eq, "binary operator <=" },
{ cmd_keyword, "!=", &program::diff, "binary operator != (different)" },
{ cmd_keyword, "==", &program::eq , "binary operator == (equal)" },
//STACK
{ cmd_undef, "", NULL, "\nSTACK"},
{ cmd_keyword, "swap", &program::swap, "swap 2 first stack entries" },
{ cmd_keyword, "drop", &program::drop, "drop first stack entry" },
{ cmd_keyword, "drop2", &program::drop2, "drop 2 first stack entries" },
{ cmd_keyword, "erase", &program::erase, "drop all stack entries" },
{ cmd_keyword, "rot", &program::rot, "rotate 3 first stack entries" },
{ cmd_keyword, "dup", &program::dup, "duplicate first stack entry" },
{ cmd_keyword, "dup2", &program::dup2, "duplicate 2 first stack entries" },
{ cmd_keyword, "pick", &program::pick, "push a copy of the given stack level onto the stack" },
{ cmd_keyword, "depth", &program::depth, "give stack depth" },
//BRANCH
{ cmd_undef, "", NULL, "\nBRANCH"},
{ cmd_branch, "if", (program_fn_t)&program::rpn_if, "<test-instructions>" },
{ cmd_branch, "then", (program_fn_t)&program::rpn_then, "<true-instructions>" },
{ cmd_branch, "else", (program_fn_t)&program::rpn_else, "<false-instructions>" },
{ cmd_keyword, "end", &program::rpn_end, "(end of if structure)" },
{ cmd_branch, "start", (program_fn_t)&program::rpn_start, "repeat instructions several times" },
{ cmd_branch, "for", (program_fn_t)&program::rpn_for, "repeat instructions several times with variable" },
{ cmd_branch, "next", (program_fn_t)&program::rpn_next, "ex: 1 10 start <instructions> next" },
{ cmd_branch, "step", (program_fn_t)&program::rpn_step, "ex: 1 100 start <instructions> 4 step" },
//STORE
{ cmd_undef, "", NULL, "\nSTORE"},
{ cmd_keyword, "sto", &program::sto, "store a variable. ex: 1 'name' sto" },
{ cmd_keyword, "rcl", &program::rcl, "recall a variable. ex: 'name' rcl" },
{ cmd_keyword, "purge", &program::purge, "delete a variable. ex: 'name' purge" },
{ cmd_keyword, "vars", &program::vars, "list all variables" },
//TRIG
{ cmd_undef, "", NULL, "\nTRIG"},
{ cmd_keyword, "pi", &program::pi, "PI constant" },
{ cmd_keyword, "sin", &program::rpn_sin, "sinus" },
{ cmd_keyword, "asin", &program::rpn_asin, "arg sinus" },
{ cmd_keyword, "cos", &program::rpn_cos , "cosinus" },
{ cmd_keyword, "acos", &program::rpn_acos, "arg cosinus" },
{ cmd_keyword, "tan", &program::rpn_tan, "tangent" },
{ cmd_keyword, "atan", &program::rpn_atan, "arg tangent" },
{ cmd_keyword, "d->r", &program::d2r, "convert degrees to radians" },
{ cmd_keyword, "r->d", &program::r2d, "convert radians to degrees" },
//LOGS
{ cmd_undef, "", NULL, "\nLOGS"},
{ cmd_keyword, "e", &program::rpn_e, "exp(0) constant" },
{ cmd_keyword, "log", &program::rpn_log, "logarithm base 10" },
{ cmd_keyword, "alog", &program::rpn_alog, "exponential base 10" },
{ cmd_keyword, "ln", &program::rpn_ln, "logarithm base e" },
{ cmd_keyword, "exp", &program::rpn_exp, "exponential" },
{ cmd_keyword, "sinh", &program::rpn_sinh, "hyperbolic sine" },
{ cmd_keyword, "asinh", &program::rpn_asinh, "inverse hyperbolic sine" },
{ cmd_keyword, "cosh", &program::rpn_sinh, "hyperbolic cosine" },
{ cmd_keyword, "acosh", &program::rpn_acosh, "inverse hyperbolic cosine" },
{ cmd_keyword, "tanh", &program::rpn_tanh, "hyperbolic tangent" },
{ cmd_keyword, "atanh", &program::rpn_atanh, "inverse hyperbolic tangent" },
// end
{ cmd_max, "", NULL, "" },
};

View file

@ -1,89 +0,0 @@
void program::test()
{
const string test_filename = "test.txt";
ifstream test_file(test_filename);
if (test_file.is_open())
{
const string stack_size("-> stack size should be ");
const string stack_value("-> stack should be ");
string test_title;
string entry;
ret_value ret;
stack stk;
heap hp;
bool indicate_passed = false;
bool failed = false;
int count_tests = 0;
while (!test_file.eof())
{
getline(test_file, entry);
if (entry.substr(0,2)=="##")
{
if (indicate_passed)
cout << "passed " << count_tests << " tests"<< endl;
cout << entry << " .. ";
indicate_passed = true;
count_tests = 0;
}
else if (entry.substr(0,1)=="#")
{
test_title = entry;
count_tests++;
}
else if (entry.find(stack_size, 0) == 0)
{
istringstream isub;
int size;
isub.str(entry.substr(stack_size.size()));
isub>>size;
if (stk.size() != size)
{
cout<<endl<<endl<<test_title<<endl<<entry<<endl<<"FAIL, ";
cout<<"real stack size is "<<stk.size()<<endl;
failed = true;
indicate_passed = false;
}
}
else if (entry.find(stack_value, 0) == 0)
{
string stack_should_be = entry.substr(stack_value.size());
string stack_is;
string tmp;
for (int i = (int)stk.size() - 1; i >= 0; i--)
{
stringstream os;
if (i < (int)(stk.size() - 1))
stack_is += ", ";
((object*)stk.seq_obj(i))->show(os);
getline(os, tmp);
stack_is += tmp;
}
if (stack_is != stack_should_be)
{
cout<<endl<<endl<<test_title<<endl<<entry<<endl<<"FAIL, ";
cout<<"real stack is "<<stack_is<<endl;
failed = true;
indicate_passed = false;
}
}
else if (entry.size() > 0)
{
program prog;
ret = program::parse(entry, prog);
if (ret == ret_ok)
{
// run it
(void)prog.run(stk, hp);
}
}
}
if (indicate_passed)
cout << "passed " << count_tests << " tests"<< endl;
if (! failed)
cout << "test file '"<<test_filename<<"' has passed" << endl;
}
else
cerr << "test file '"<<test_filename<<"' not found" << endl;
}

View file

@ -1,29 +0,0 @@
//
void nop()
{
// nop
}
void good_bye()
{
ERR_CONTEXT(ret_good_bye);
}
void verbose()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
g_verbose = (int)getf();
}
void help()
{
for(int i=0; i<sizeof(_keywords)/sizeof(_keywords[0]); i++)
if (_keywords[i].comment.size() != 0)
cout<<_keywords[i].name<<"\t"<<_keywords[i].comment<<endl;
cout<<endl;
cout<<"Current verbosity is "<<g_verbose<<endl<<endl;
cout<<endl;
}
void test();

View file

@ -1,95 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
//
void rpn_e(void)
{
putf(M_E);
}
void rpn_log()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = log10(((number*)_stack->get_obj(0))->_value);
}
void rpn_alog()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = pow(((number*)_stack->get_obj(0))->_value, 10);
}
void rpn_ln()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = log(((number*)_stack->get_obj(0))->_value);
}
void rpn_exp()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = exp(((number*)_stack->get_obj(0))->_value);
}
void rpn_sinh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = sinh(((number*)_stack->get_obj(0))->_value);
}
void rpn_asinh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
floating_t value = ((number*)_stack->get_obj(0))->_value;
if(value>0)
value = log(value + sqrt(value * value + 1));
else
value = -log(-value + sqrt(value * value + 1));
((number*)_stack->get_obj(0))->_value = value;
}
void rpn_cosh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = cosh(((number*)_stack->get_obj(0))->_value);
}
void rpn_acosh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
floating_t value = ((number*)_stack->get_obj(0))->_value;
if(value>0)
value = log(value + sqrt(value * value - 1));
else
value = -log(-value + sqrt(value * value - 1));
((number*)_stack->get_obj(0))->_value = value;
}
void rpn_tanh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = tanh(((number*)_stack->get_obj(0))->_value);
}
void rpn_atanh()
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
floating_t value = ((number*)_stack->get_obj(0))->_value;
value = (log(1 + value) - log(1 - value)) / 2;
((number*)_stack->get_obj(0))->_value = value;
}

View file

@ -1,81 +0,0 @@
//
void swap(void)
{
MIN_ARGUMENTS(2);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->pop_back();
_stack->pop_back();
_stack->push_obj_from_local(0);
_stack->push_obj_from_local(1);
}
void drop(void)
{
MIN_ARGUMENTS(1);
_stack->pop_back();
}
void drop2(void)
{
MIN_ARGUMENTS(2);
_stack->pop_back();
_stack->pop_back();
}
void erase(void)
{
while(_stack->size()>0)
_stack->pop_back();
}
void dup(void)
{
MIN_ARGUMENTS(1);
_stack->copy_obj_to_local(0, 0);
_stack->push_obj_from_local(0);
}
void dup2(void)
{
MIN_ARGUMENTS(2);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->push_obj_from_local(1);
_stack->push_obj_from_local(0);
}
void pick(void)
{
MIN_ARGUMENTS(1);
unsigned int to_pick = (unsigned int)getf();
// treat stack depth errors
if ((to_pick == 0) || (to_pick > _stack->size()))
{
ERR_CONTEXT(ret_missing_operand);
return;
}
_stack->copy_obj_to_local(to_pick - 1, 0);
_stack->push_obj_from_local(0);
}
void rot(void)
{
MIN_ARGUMENTS(3);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->copy_obj_to_local(2, 2);
_stack->pop_back();
_stack->pop_back();
_stack->pop_back();
_stack->push_obj_from_local(1);
_stack->push_obj_from_local(0);
_stack->push_obj_from_local(2);
}
void depth(void)
{
number num((floating_t)_stack->size());
_stack->push_back(&num, sizeof(number), cmd_number);
}

View file

@ -1,66 +0,0 @@
//
void sto(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_symbol);
string name = getn();
_heap->add(name, _stack->get_obj(0), _stack->get_len(0), _stack->get_type(0));
_stack->pop_back();
}
void rcl(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_symbol);
void* obj;
unsigned int size;
int type;
if (_heap->get(getn(), obj, size, type))
_stack->push_back(obj, size, type);
else
ERR_CONTEXT(ret_unknown_variable);
}
// carefull : this is not a langage command
void auto_rcl(symbol* symb)
{
if (symb->_auto_eval)
{
void* obj;
unsigned int size;
int type;
if (_heap->get(symb->_name, obj, size, type))
_stack->push_back(obj, size, type);
else
_stack->push_back(symb, sizeof(symbol), cmd_symbol);
}
else
_stack->push_back(symb, sizeof(symbol), cmd_symbol);
}
void purge(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_symbol);
if (!_heap->erase(getn()))
ERR_CONTEXT(ret_unknown_variable);
}
void vars(void)
{
object* obj;
unsigned int size;
int type;
string name;
for (int i=0; i<(int)_heap->size(); i++)
{
(void)_heap->get_by_index(i, name, (void*&)obj, size, type);
cout<<"var "<<i+1<<": name '"<<name<<"', type "<<cmd_type_string[type]<<", value ";
obj->show();
cout<<endl;
}
}

View file

@ -1,85 +0,0 @@
void sup(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() > first);
}
void sup_eq(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() >= first);
}
void inf(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() < first);
}
void inf_eq(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() <= first);
}
void diff(void)
{
MIN_ARGUMENTS(2);
ARG_IS_OF_TYPE(0, cmd_number);
ARG_IS_OF_TYPE(1, cmd_number);
floating_t first = getf();
putf(getf() != first);
}
void eq(void)
{
MIN_ARGUMENTS(2);
int type = _stack->get_type(0);
if (_stack->get_type(1) == type)
{
switch(type)
{
case cmd_number:
{
floating_t first = getf();
putf(getf() == first);
}
break;
case cmd_symbol:
{
string first = getn();
putf(getn() == first);
}
break;
default:
_stack->pop_back();
_stack->pop_back();
putf(0);
break;
}
}
else
{
_stack->pop_back();
_stack->pop_back();
putf(0);
}
}

View file

@ -1,64 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
//
void pi(void)
{
putf(M_PI);
}
void d2r(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value *= M_PI / 360;
}
void r2d(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value *= 360 / M_PI;
}
void rpn_sin(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = sin(((number*)_stack->get_obj(0))->_value);
}
void rpn_asin(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = asin(((number*)_stack->get_obj(0))->_value);
}
void rpn_cos(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = cos(((number*)_stack->get_obj(0))->_value);
}
void rpn_acos(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = acos(((number*)_stack->get_obj(0))->_value);
}
void rpn_tan(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = tan(((number*)_stack->get_obj(0))->_value);
}
void rpn_atan(void)
{
MIN_ARGUMENTS(1);
ARG_IS_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = atan(((number*)_stack->get_obj(0))->_value);
}

694
rpn.cpp
View file

@ -1,694 +0,0 @@
/*
* rpn.cpp
*
* Copyright 2013 <louis@rubet.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <stdlib.h>
#ifdef WIN32
#include <tchar.h>
#else
#define _TCHAR char
#define _tmain main
#endif
#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
#include <fstream>
using namespace std;
#include "stack.h"
static const char CURSOR[] = "> ";
static const char SHOW_STACK_SEPARATOR[] = ":\t";
static int g_verbose = 0;
typedef enum {
ret_ok,
ret_unknown_err,
ret_missing_operand,
ret_bad_operand_type,
ret_unknown_variable,
ret_internal,
ret_deadly,
ret_good_bye,
ret_not_impl,
ret_nop,
ret_syntax,
ret_max
} ret_value;
const char* ret_value_string[ret_max] = {
"ok", "unknown command", "missing operand", "bad operand type", "unknown variable", "internal error, aborting",
"deadly", "goodbye", "not implemented", "no operation", "syntax"
};
typedef enum {
cmd_undef,
cmd_number,/* floating value to put in stack */
cmd_symbol,/* symbol value to put in stack */
cmd_keyword,/* langage keyword */
cmd_branch,/* langage branch keyword */
cmd_max
} cmd_type_t;
const char* cmd_type_string[cmd_max] = {
"undef", "number", "symbol", "keyword", "keyword"
};
//
typedef long double floating_t;
class program;
class object;
class branch;
typedef void (program::*program_fn_t)(void);
typedef union
{
program_fn_t _fn;
} operand;
typedef int (program::*branch_fn_t)(branch&);
//
class object
{
public:
cmd_type_t _type;// object type
object(cmd_type_t type = cmd_undef):_type(type) { }
virtual void show(ostream& stream = cout) { }
};
class number : public object
{
public:
number(floating_t value) : object(cmd_number) { _value = value; }
virtual void show(ostream& stream = cout) { stream << _value; }
floating_t _value;
};
class symbol : public object
{
public:
symbol(string& name, cmd_type_t type = cmd_symbol) : object(type), _name(name),_auto_eval(false) { }
virtual void show(ostream& stream = cout)
{
stream << "'" << _name << "'";
}
string _name;
bool _auto_eval;
};
class keyword : public symbol
{
public:
keyword(program_fn_t fn, string& name, cmd_type_t type = cmd_keyword) : symbol(name, type) { _fn = fn; }
program_fn_t _fn;
virtual void show(ostream& stream = cout)
{
stream << _name;
}
};
class branch : public keyword
{
public:
branch(branch_fn_t fn, string& name) : keyword(NULL, name, cmd_branch), arg1(-1), arg2(-1), arg3(-1), arg_bool(false)
{
_type = cmd_branch;
_fn = fn;
}
// branch function
branch_fn_t _fn;
// args used by cmd_branch cmds
int arg1, arg2, arg3;
floating_t farg1, farg2;
bool arg_bool;
};
class program : public stack
{
public:
program() { }
// run this program
ret_value run(stack& stk, heap& hp)
{
bool go_out = false;
ret_value ret = ret_ok;
cmd_type_t type;
_stack = &stk;
_heap = &hp;
_err = ret_ok;
_err_context = "";
// branches for 'if'
ret = preprocess();
if (ret != ret_ok)
return ret;
// iterate commands
for(int i = 0; (go_out==false) && (i<(int)size());)
{
type = (cmd_type_t)seq_type(i);
//
if (g_verbose >= 1)
{
cout << "(" << i << ") ";
((object*)seq_obj(i))->show();
cout << endl;
}
// not a command, but a stack entry, manage it
if (type == cmd_number)
{
stk.push_back(seq_obj(i), seq_len(i), type);
i++;
}
// could be an auto-evaluated symbol
else if (type == cmd_symbol)
{
auto_rcl((symbol*)seq_obj(i));
i++;
}
// a keyword
else if (type == cmd_keyword)
{
keyword* k = (keyword*)seq_obj(i);
// call matching function
(this->*(k->_fn))();
switch(_err)
{
// no pb -> go on
case ret_ok:
break;
// explicit go out software
case ret_good_bye:
go_out = true;
ret = ret_good_bye;
break;
default:
// error: abort prog
go_out = true;
// error: show it
if (show_error(_err, _err_context) == ret_deadly)
{
// pb showing error -> go out software
ret = ret_good_bye;
}
break;
}
i++;
}
// a branch keyword
else if (type == cmd_branch)
{
// call matching function
branch* b = (branch*)seq_obj(i);
int tmp = (this->*(b->_fn))(*b);
if (tmp == -1)
i++;
else
i = tmp;
}
}
return ret;
}
ret_value preprocess(void)
{
struct if_layout_t
{
if_layout_t():index_then(-1),index_else(-1),index_end(-1) { }
int index_if;
int index_then;
int index_else;
int index_end;
};
// for if-then-else-end
vector<if_layout_t> vlayout;
int layout_index=-1;// TODO remplaçable par vlayout.size()-1
//for start-end-step
vector<int> vstartindex;
// analyse if-then-else-end branches
// analyse start-{next, step} branches
for(int i=0; i<(int)size(); i++)
{
int type = seq_type(i);
if (type == cmd_keyword)
{
keyword* k = (keyword*)seq_obj(i);
if(k->_name.compare("end") == 0)
{
int next = i + 1;
if (next >= (int)size())
next = -1;
if (layout_index<0)
{
// error: show it
show_syntax_error("missing if before end");
return ret_syntax;
}
if (vlayout[layout_index].index_end != -1)
{
// error: show it
show_syntax_error("duplicate end");
return ret_syntax;
}
((branch*)seq_obj(i))->arg1 = next;//fill branch1
if (vlayout[layout_index].index_else != -1)
//fill 'end' branch of 'else'
((branch*)seq_obj(vlayout[layout_index].index_else))->arg2 = i;
else
//fill 'end' branch of 'then'
((branch*)seq_obj(vlayout[layout_index].index_then))->arg2 = i;
layout_index--;
}
}
else if (type == cmd_branch)
{
branch* k = (branch*)seq_obj(i);
if (k->_name.compare("if") == 0)
{
if_layout_t layout;
layout.index_if = i;
vlayout.push_back(layout);
layout_index++;
}
else if(k->_name.compare("then") == 0)
{
int next = i + 1;
if (next >= (int)size())
next = -1;
// nothing after 'then' -> error
if (next == -1)
{
// error: show it
show_syntax_error("missing end after then");
return ret_syntax;
}
if (layout_index<0)
{
// error: show it
show_syntax_error("missing if before then");
return ret_syntax;
}
if (vlayout[layout_index].index_then != -1)
{
// error: show it
show_syntax_error("duplicate then");
return ret_syntax;
}
vlayout[layout_index].index_then = i;
k->arg1 = next;
k->arg3 = vlayout[layout_index].index_if;
}
else if(k->_name.compare("else") == 0)
{
int next = i + 1;
if (next >= (int)size())
next = -1;
// nothing after 'else' -> error
if (next == -1)
{
// error: show it
show_syntax_error("missing end after else");
return ret_syntax;
}
if (layout_index<0)
{
// error: show it
show_syntax_error("missing if before else");
return ret_syntax;
}
if (vlayout[layout_index].index_then == -1)
{
// error: show it
show_syntax_error("missing then before else");
return ret_syntax;
}
if (vlayout[layout_index].index_else != -1)
{
// error: show it
show_syntax_error("duplicate else");
return ret_syntax;
}
vlayout[layout_index].index_else = i;
k->arg1 = next;// fill branch1 (if was false) of 'else'
k->arg3 = vlayout[layout_index].index_if;
((branch*)seq_obj(vlayout[layout_index].index_then))->arg2 = next;// fill branch2 (if was false) of 'then'
}
else if(k->_name.compare("start") == 0)
{
vstartindex.push_back(i);
}
else if(k->_name.compare("for") == 0)
{
vstartindex.push_back(i);
k->arg1 = i + 1;// arg1 points on symbol variable
}
else if(k->_name.compare("next") == 0)
{
if (vstartindex.size() == 0)
{
// error: show it
show_syntax_error("missing start or for before next");
return ret_syntax;
}
k->arg1 = vstartindex[vstartindex.size() - 1];// fill 'next' branch1 = 'start' index
vstartindex.pop_back();
}
else if(k->_name.compare("step") == 0)
{
if (vstartindex.size() == 0)
{
// error: show it
show_syntax_error("missing start or for before step");
return ret_syntax;
}
k->arg1 = vstartindex[vstartindex.size() - 1];// fill 'step' branch1 = 'start' index
vstartindex.pop_back();
}
}
}
if (layout_index >= 0)
{
// error: show it
show_syntax_error("missing end");
return ret_syntax;
}
if (vstartindex.size() > 0)
{
// error: show it
show_syntax_error("missing next or step after for or start");
return ret_syntax;
}
return ret_ok;
}
static ret_value show_error(ret_value err, string& context)
{
cerr<<context<<": "<<ret_value_string[err]<<endl;
switch(err)
{
case ret_internal:
case ret_deadly:
return ret_deadly;
default:
return ret_ok;
}
}
static ret_value show_error(ret_value err, char* context)
{
string context_string(context);
return show_error(err, context_string);
}
static void show_syntax_error(char* context)
{
cerr<<"syntax error: "<<context<<endl;
}
// keywords declaration
struct keyword_t
{
cmd_type_t type;
string name;
program_fn_t fn;
string comment;
};
static keyword_t program::_keywords[100];
ret_value get_fn(const string& fn_name, program_fn_t& fn, cmd_type_t& type)
{
for(int i=0; (i<sizeof(_keywords)/sizeof(_keywords[0])) && (_keywords[i].type != cmd_max); i++)
{
if ((_keywords[i].name.size()>0) && (fn_name == _keywords[i].name))
{
fn = _keywords[i].fn;
type = _keywords[i].type;
return ret_ok;
}
}
return ret_unknown_err;
}
// interactive entry and decoding
static ret_value entry(program& prog)
{
ret_value ret;
string entry;
// show cursor
cout<<CURSOR;
// get user line
getline(cin, entry);
if (cin.good())
// parse it
ret = parse(entry, prog);
else
ret = ret_internal;
return ret;
}
static ret_value parse(const string& entry, program& prog)
{
ret_value ret = ret_ok;
istringstream stream(entry);
do
{
floating_t num;
istringstream isub;
string sub;
stream >> sub;
isub.str(sub);
// check whether it is a number
isub >> num;
if ( (!isub.fail()) && (!isub.bad()) )
{
// found a number
prog.push_back(&number(num), sizeof(number), cmd_number);
if (isub.good())
{
// plus another command without space
program_fn_t fn;
cmd_type_t type;
isub >> sub;
if (prog.get_fn(sub, fn, type) != ret_ok)
program::show_error(ret_unknown_err, sub);
else
{
if (type == cmd_keyword)
prog.push_back(&keyword(fn, sub), sizeof(keyword), cmd_keyword);
else if (type == cmd_branch)
prog.push_back(&branch((branch_fn_t)fn, sub), sizeof(branch), cmd_branch);
}
}
}
else
{
if (sub.size()>0)
{
// not a number ?
// could be a symbol
if (sub.substr(0,1) == "'")
{
// syntax should be 'symbol'
if (sub.substr(sub.size()-1, 1) == "'")
prog.push_back(&symbol(sub.substr(1, sub.size()-2)), sizeof(symbol), cmd_symbol);
// or 'symbol without ending ' only if last entry
else
{
char c;
do
{
stream.get(c);
if (stream.eof())
break;
sub += c;
}
while(c != '\'');
if (stream.eof())
prog.push_back(&symbol(sub.substr(1, sub.size()-1)), sizeof(symbol), cmd_symbol);
else
prog.push_back(&symbol(sub.substr(1, sub.size()-2)), sizeof(symbol), cmd_symbol);
}
}
else
{
program_fn_t fn;
cmd_type_t type;
// could be a command
if (prog.get_fn(sub, fn, type) == ret_ok)
{
if (type == cmd_keyword)
prog.push_back(&keyword(fn, sub), sizeof(keyword), cmd_keyword);
else if (type == cmd_branch)
prog.push_back(&branch((branch_fn_t)fn, sub), sizeof(branch), cmd_branch);
}
else
{
// no, so it is counted as an auto-evaluated symbol
symbol sym(sub);
sym._auto_eval = true;
prog.push_back(&sym, sizeof(symbol), cmd_symbol);
}
}
}
}
}
while (!stream.eof());
// particular : check 'for' command is followed by a symbol, with auto-evaluated syntax (i.e. without ')
//TODO
/*
for(int i = 0; i < (int)prog.size(); i++)
{
if ((prog.seq_type(i) == cmd_branch) && ())
}
*/
return ret;
}
static void show_stack(stack& st)
{
if (st.size() == 1)
{
((object*)st.back())->show();
cout<<endl;
}
else
{
for (int i = st.size()-1; i>=0; i--)
{
cout<<i+1<<SHOW_STACK_SEPARATOR;
((object*)st[i])->show();
cout<<endl;
}
}
}
private:
ret_value _err;
string _err_context;
stack* _stack;
heap* _heap;
// helpers for keywords implementation
floating_t getf()
{
/* warning, caller must check object type before */
floating_t a = ((number*)_stack->back())->_value;
_stack->pop_back();
return a;
}
void putf(floating_t value)
{
/* warning, caller must check object type before */
_stack->push_back(&number(value), sizeof(number), cmd_number);
}
string getn()
{
/* warning, caller must check object type before */
string a = ((symbol*)_stack->back())->_name;
_stack->pop_back();
return a;
}
void putn(string& a)
{
/* warning, caller must check object type before */
_stack->push_back(&symbol(a), sizeof(symbol), cmd_symbol);
}
int stack_size()
{
return _stack->size();
}
private:
// carefull : some of these macros modify program flow
#define ERR_CONTEXT(err) do { _err = (err); _err_context = __FUNCTION__; } while(0)
#define MIN_ARGUMENTS(num) do { if (stack_size()<(num)) { ERR_CONTEXT(ret_missing_operand); return; } } while(0)
#define MIN_ARGUMENTS_RET(num, ret) do { if (stack_size()<(num)) { ERR_CONTEXT(ret_missing_operand); return (ret); } } while(0)
#define ARG_IS_OF_TYPE(num, type) do { if (_stack->get_type(num) != (type)) { ERR_CONTEXT(ret_bad_operand_type); return; } } while(0)
#define ARG_IS_OF_TYPE_RET(num, type, ret) do { if (_stack->get_type(num) != (type)) { ERR_CONTEXT(ret_bad_operand_type); return (ret); } } while(0)
// keywords implementation
#include "rpn-general.h"
#include "rpn-algebra.h"
#include "rpn-test.h"
#include "rpn-stack.h"
#include "rpn-branch.h"
#include "rpn-store.h"
#include "rpn-trig.h"
#include "rpn-logs.h"
};
//keywords declaration
#include "rpn-cmd.h"
#include "rpn-general-core.h"
//
int _tmain(int argc, _TCHAR* argv[])
{
heap hp;
stack st;
//
cout << setprecision(16);
//
for (;;)
{
program prog;
if (program::entry(prog) == ret_good_bye)
break;
else
{
if (prog.run(st, hp) == ret_good_bye)
break;
else
program::show_stack(st);
}
}
return 0;
}

BIN
rpn.sdf

Binary file not shown.

20
rpn.sln
View file

@ -1,20 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rpn", "rpn.vcxproj", "{FF16FBC4-7CF1-486F-AF41-FEA72547475F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FF16FBC4-7CF1-486F-AF41-FEA72547475F}.Debug|Win32.ActiveCfg = Debug|Win32
{FF16FBC4-7CF1-486F-AF41-FEA72547475F}.Debug|Win32.Build.0 = Debug|Win32
{FF16FBC4-7CF1-486F-AF41-FEA72547475F}.Release|Win32.ActiveCfg = Release|Win32
{FF16FBC4-7CF1-486F-AF41-FEA72547475F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
rpn.suo

Binary file not shown.

View file

@ -1,100 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FF16FBC4-7CF1-486F-AF41-FEA72547475F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>rpn</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="HP-28S-Quick-Reference.pdf" />
<None Include="ReadMe.txt" />
<None Include="test.txt" />
<None Include="TODO.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="rpn-algebra.h" />
<ClInclude Include="rpn-branch.h" />
<ClInclude Include="rpn-cmd.h" />
<ClInclude Include="rpn-general-core.h" />
<ClInclude Include="rpn-general.h" />
<ClInclude Include="rpn-logs.h" />
<ClInclude Include="rpn-stack.h" />
<ClInclude Include="rpn-store.h" />
<ClInclude Include="rpn-test.h" />
<ClInclude Include="rpn-trig.h" />
<ClInclude Include="stack.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="rpn.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -1,66 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
<None Include="HP-28S-Quick-Reference.pdf" />
<None Include="TODO.txt" />
<None Include="test.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-algebra.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-branch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-cmd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-general.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-general-core.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-logs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-stack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-store.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-test.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rpn-trig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stack.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="rpn.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

264
stack.h
View file

@ -1,264 +0,0 @@
#ifndef __stack_h__
#define __stack_h__
#include <assert.h>
#include <vector>
#include <map>
using namespace std;
#define ALLOC_BLOB (128*1024)
#define LOCAL_COPY_PLACES 3
#define LOCAL_COPY_SIZE 128
//
class stack
{
private:
struct local_copy
{
unsigned int length;
int type;
int blob;
};
public:
stack()
{
_base = (char*)malloc(ALLOC_BLOB);
_total_size = ALLOC_BLOB;
_current = _base;
_count = 0;
}
virtual ~stack() { free(_base); }
void push_back(void* obj, unsigned int size, int type = 0)
{
if (_current + size > _base + _total_size)
{
//TODO gérer les pbs de mémoire
_total_size += ALLOC_BLOB;
_base = (char*)realloc(_base, _total_size);
}
memcpy(_current, obj, size);
_vlen.push_back(size);
_vpointer.push_back(_current);
_vtype.push_back(type);
_count++;
_current += size;
}
void pop_back()
{
if (_count > 0)
{
_current = _vpointer[_count - 1];
_vlen.pop_back();
_vpointer.pop_back();
_vtype.pop_back();
_count--;
}
}
unsigned int size()
{
return _count;
}
// stack access (index is counted from back)
void* get_obj(unsigned int index)
{
if (index<_count)
return _vpointer[_count-index-1];
else
return NULL;
}
void* operator[](unsigned int index)
{
return get_obj(index);
}
void* back()
{
if (_count>0)
return _vpointer[_count-1];
else
return NULL;
}
unsigned int get_len(unsigned int index)
{
if (index<_count)
return _vlen[_count-index-1];
else
return 0;
}
int get_type(unsigned int index)
{
if (index<_count)
return _vtype[_count-index-1];
else
return 0;
}
// sequential access (index is counted from front)
void* seq_obj(unsigned int index)
{
if (index<_count)
return _vpointer[index];
else
return NULL;
}
unsigned int seq_len(unsigned int index)
{
if (index<_count)
return _vlen[index];
else
return 0;
}
int seq_type(unsigned int index)
{
if (index<_count)
return _vtype[index];
else
return 0;
}
// local objects copy
void copy_obj_to_local(unsigned int index, unsigned int to_place)
{
assert(to_place < LOCAL_COPY_PLACES);
struct local_copy* local = (struct local_copy*)_places[to_place];
local->length = get_len(index);
local->type= get_type(index);
memcpy(&local->blob, get_obj(index), local->length);
}
void push_obj_from_local(unsigned int from_place)
{
assert(from_place < LOCAL_COPY_PLACES);
struct local_copy* local = (struct local_copy*)_places[from_place];
push_back(&local->blob, local->length, local->type);
}
private:
char* _base;
char* _current;
vector<unsigned int> _vlen;// size of each entry in bytes
vector<char*> _vpointer;//pointer on each entry
vector<int> _vtype;//type of each entry
unsigned int _count;// =_vlen.size()=_vpointer.size()=_vtype.size()
unsigned int _total_size;//total allocated size in bytes
char _places[LOCAL_COPY_PLACES][LOCAL_COPY_SIZE];
};
//
class heap
{
private:
struct local_var
{
unsigned int length;
int type;
int blob;
};
public:
heap() { }
virtual ~heap()
{
for(map<string, struct local_var*>::iterator i=_map.begin(); i!=_map.end(); i++)
free(i->second);
}
void add(const string name, void* obj, unsigned int size, int type = 0)
{
struct local_var* blob = _map[name];
if (blob == NULL)
{
//TODO gérer les pbs de mémoire
blob = (struct local_var*)malloc(size + sizeof(local_var));
_map[name] = blob;
}
else if (size != blob->length)
{
//TODO gérer les pbs de mémoire
blob = (struct local_var*)realloc(blob, size + sizeof(local_var));
_map[name] = blob;
}
blob->length = size;
blob->type= type;
memcpy(&blob->blob, obj, size);
}
bool get(const string name, void*& obj, unsigned int& size, int& type)
{
map<string, struct local_var*>::iterator i = _map.find(name);
if (i != _map.end())
{
if (i->second != NULL)
{
obj = &i->second->blob;
size = i->second->length;
type = i->second->type;
}
return true;
}
else
return false;
}
bool exist(const string name)
{
return (_map.find(name) != _map.end());
}
bool get_by_index(int num, string& name, void*& obj, unsigned int& size, int& type)
{
if (num>=0 && num<(int)_map.size())
{
struct local_var* blob;
map<string, struct local_var*>::iterator i=_map.begin();
//TODO moche moche moche
for(int j=0;j<num;j++)
i++;
blob = (struct local_var*)i->second;
assert(blob != NULL);
name = i->first;
obj = &blob->blob;
size = blob->length;
type = blob->type;
return true;
}
else
return false;
}
bool erase(const string name)
{
map<string, struct local_var*>::iterator i = _map.find(name);
if (i != _map.end())
{
free(i->second);
_map.erase(i->first);
return true;
}
return false;
}
unsigned int size() { return _map.size(); }
private:
map<string, struct local_var*> _map;
};
#endif // __stack_h__

View file

@ -1,8 +0,0 @@
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>