Alpha Runtime provides a way to execute programs written in the assemlber language "α-Notation".
The α-Notation is originally a pseudo assembler language that I got introduced to in the module "Systemnahme Informatik (SS 2021)" at Uni Bonn. It is a simplified assembler for educational purposes.
Here's the starter template for Node.js and ES6 JS. Make sure to check out the JSDoc documentation for more detailed information!
importexecutefrom'./alpha-runtime/Executor'importparsefrom'./alpha-runtime/Parser'constcode=String(readFileSync('./alpha-runtime/tests/programs/add42.alpha','utf8'));constprogram=parse(code);construntimeState=execute(program);// do something with the resulting runtimeStateYou can create a own Runtime object with custom callback functions and pass this runtime into the execute function.
construntime=newRuntime(program,{onMemoryWrite: (writeAddress: String,newValue: number,wasInitialized: boolean)=>console.log('memory write'),onStackChange: (value: number,type: OnStackChangeEventType)=>console.log('stack change'),onCallStackChange?: (value: number,type: OnStackChangeEventType)=>console.log('call stack change'),onInstructionPointerChange?: (value: number)=>console.log('instruction pointer change'),onProgramEnd?: ()=>console.log('end of program')});construntimeState=execute(program,runtime);Make sure to build everything via webpack
npminpmrunbuild<scriptsrc='./alpha-runtime/dist/index.js'></script><script>letcode="ρ(1) := 10;\nρ(2) := 32;\nρ(result) := ρ(1) + ρ(2);"letprogram=parse(code);letruntimeState=execute(program);</script>parse()takes a string and convertes it into an AST. This is done via a PEGJS grammar that combines lexer and parser.execute()operates on a program and a runtime and keeps executing the next statement until the program halts.Runtimeconsists of 4 parts:stackandcallstack, which both use the customStackclassmemorywhich uses the customMemoryclasscodeManagerwhich uses theCodeManagerclass
You can learn more about these in the JSDoc of the individual classes.
This has been done before with Java and JavaFX, see LowerAlpha. This project aims to be more robust, reliable and user friendly than LowerAlpha.