1 | sclass Operation { |
2 | S function; |
3 | int[] registers; |
4 | int outRegister = -1; |
5 | |
6 | *(S *function, int... regs) { |
7 | registers = subArray(regs, 0, l(regs)-1); |
8 | outRegister = last(regs); |
9 | } |
10 | } |
11 | |
12 | sclass Machine { |
13 | O[] registers = new O[10]; |
14 | new TreeMap<S, O> functions; |
15 | |
16 | void function(S name, O implementation) { |
17 | functions.put(name, implementation); |
18 | } |
19 | |
20 | void set(int register, O value) { |
21 | if (register >= l(registers)) |
22 | registers = resizeArray(registers, register+1); |
23 | registers[register] = value; |
24 | } |
25 | |
26 | O get(int register) { |
27 | ret _get(registers, register); |
28 | } |
29 | |
30 | void run(Operation op) { |
31 | O f = functions.get(op.function); |
32 | if (f == null) fail("Unknown operation: " + op.function); |
33 | int n = l(op.registers); |
34 | O[] arguments = new O[n]; |
35 | for i to n: arguments[i] = get(op.registers[i]); |
36 | O result = callF(f, arguments); |
37 | if (op.outRegister >= 0) |
38 | set(op.outRegister, result); |
39 | } |
40 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006737 |
Snippet name: | AI Assembler [Include] - Machine + Operation |
Eternal ID of this version: | #1006737/2 |
Text MD5: | 01c260a54f53b2bb3fc27535b7cbf2ec |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-03 04:32:16 |
Source code size: | 979 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 532 / 491 |
Version history: | 1 change(s) |
Referenced in: | [show references] |