undar-lang/emit/uxn/emit.c

836 lines
19 KiB
C

#include "../../emit.h"
#include <stdio.h>
#include <stdlib.h>
#define UXN_OP_2 (1 << 5)
#define UXN_OP_R (1 << 6)
#define UXN_OP_K (1 << 7)
enum uxn_opcode {
/* Stack I */ /* Logic */ /* Memory I */ /* Arithmetic*/
BRK = 0x00, EQU = 0x08, LDZ = 0x10, ADD = 0x18,
INC = 0x01, NEQ = 0x09, STZ = 0x11, SUB = 0x19,
POP = 0x02, GTH = 0x0A, LDR = 0x12, MUL = 0x1A,
NIP = 0x03, LTH = 0x0B, STR = 0x13, DIV = 0x1B,
/* Stack II */ /* Stash */ /* Memory II */ /* Bitwise */
SWP = 0x04, JMP = 0x0C, LDA = 0x14, AND = 0x1C,
ROT = 0x05, JCN = 0x0D, STA = 0x15, ORA = 0x1D,
DUP = 0x06, JSR = 0x0E, DEI = 0x16, EOR = 0x1E,
OVR = 0x07, STH = 0x0F, DEO = 0x17, SFT = 0x1F,
LIT = 0x80, JCI = 0x20, JMI = 0x40, JSI = 0x60,
};
unsigned char __lib_undar[] = {
0x40, 0x73, 0x65, 0x78, 0x74, 0x0a, 0x20, 0x20, 0x23, 0x38, 0x30, 0x20,
0x41, 0x4e, 0x44, 0x6b, 0x20, 0x45, 0x51, 0x55, 0x20, 0x23, 0x66, 0x66,
0x20, 0x4d, 0x55, 0x4c, 0x20, 0x53, 0x57, 0x50, 0x20, 0x4a, 0x4d, 0x50,
0x32, 0x72, 0x0a, 0x0a, 0x40, 0x61, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x5f,
0x20, 0x28, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x2a, 0x20, 0x2d, 0x2d, 0x20,
0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2a, 0x20, 0x29, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x4f, 0x56, 0x52, 0x32, 0x72, 0x20, 0x4c, 0x49, 0x54, 0x32,
0x72, 0x20, 0x30, 0x30, 0x30, 0x34, 0x20, 0x53, 0x55, 0x42, 0x32, 0x72,
0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x49, 0x4e, 0x43, 0x32,
0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20,
0x20, 0x20, 0x20, 0x3b, 0x6d, 0x65, 0x6d, 0x5f, 0x6c, 0x65, 0x6e, 0x67,
0x74, 0x68, 0x5f, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x53, 0x54, 0x48,
0x32, 0x6b, 0x72, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x3b, 0x6d, 0x65, 0x6d, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68,
0x5f, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x6b, 0x20, 0x53, 0x54, 0x48, 0x32,
0x6b, 0x72, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32,
0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x53,
0x57, 0x50, 0x32, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x3b, 0x6d, 0x65, 0x6d, 0x5f, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b,
0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20,
0x21, 0x26, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x0a, 0x20, 0x20, 0x26, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x50, 0x4f,
0x50, 0x32, 0x72, 0x20, 0x4a, 0x4d, 0x50, 0x32, 0x72, 0x0a, 0x0a, 0x40,
0x61, 0x6d, 0x63, 0x70, 0x79, 0x5f, 0x20, 0x28, 0x20, 0x6c, 0x65, 0x6e,
0x67, 0x74, 0x68, 0x2a, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x2a, 0x20, 0x2d,
0x2d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2a, 0x20, 0x29, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x4f, 0x56, 0x52, 0x32, 0x72, 0x20, 0x4c, 0x49,
0x54, 0x32, 0x72, 0x20, 0x30, 0x30, 0x30, 0x38, 0x20, 0x53, 0x55, 0x42,
0x32, 0x72, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30,
0x30, 0x30, 0x36, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x53, 0x54, 0x41,
0x32, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72,
0x20, 0x23, 0x30, 0x30, 0x30, 0x34, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20,
0x53, 0x54, 0x41, 0x32, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54, 0x48,
0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x34, 0x20, 0x41, 0x44,
0x44, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x61, 0x61, 0x6c, 0x6c,
0x6f, 0x63, 0x5f, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54, 0x48, 0x32,
0x6b, 0x72, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32,
0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x23, 0x30,
0x30, 0x30, 0x30, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x53,
0x54, 0x41, 0x32, 0x0a, 0x0a, 0x20, 0x20, 0x26, 0x62, 0x65, 0x67, 0x69,
0x6e, 0x2e, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54, 0x48, 0x32,
0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x53, 0x54, 0x48, 0x32,
0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x34, 0x20, 0x41, 0x44, 0x44,
0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x4c, 0x54, 0x48, 0x32, 0x20,
0x23, 0x30, 0x30, 0x20, 0x45, 0x51, 0x55, 0x20, 0x3f, 0x26, 0x62, 0x72,
0x65, 0x61, 0x6b, 0x2e, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54,
0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x36, 0x20, 0x41,
0x44, 0x44, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x53, 0x54, 0x48,
0x32, 0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x41, 0x44, 0x44,
0x32, 0x20, 0x4c, 0x44, 0x41, 0x20, 0x73, 0x65, 0x78, 0x74, 0x0a, 0x20,
0x20, 0x20, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x49, 0x4e,
0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32,
0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32,
0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x53, 0x54, 0x41, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x50, 0x4f, 0x50, 0x0a, 0x0a, 0x20, 0x20, 0x26, 0x63, 0x6f,
0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x31, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32,
0x6b, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x6b, 0x20, 0x52, 0x4f, 0x54, 0x32,
0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x50, 0x4f,
0x50, 0x32, 0x20, 0x21, 0x26, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2e, 0x31,
0x0a, 0x0a, 0x20, 0x20, 0x26, 0x62, 0x72, 0x65, 0x61, 0x6b, 0x2e, 0x31,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20,
0x49, 0x4e, 0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x4c, 0x44,
0x41, 0x32, 0x20, 0x21, 0x26, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x0a, 0x20,
0x20, 0x26, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x50, 0x4f, 0x50, 0x32, 0x72, 0x20, 0x4a, 0x4d, 0x50, 0x32, 0x72,
0x0a, 0x0a, 0x40, 0x6e, 0x61, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x73, 0x74,
0x72, 0x5f, 0x20, 0x28, 0x20, 0x6e, 0x2a, 0x20, 0x2d, 0x2d, 0x20, 0x72,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x2a, 0x20, 0x29, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x4f, 0x56, 0x52, 0x32, 0x72, 0x20, 0x4c, 0x49, 0x54, 0x32, 0x72,
0x20, 0x30, 0x30, 0x30, 0x61, 0x20, 0x53, 0x55, 0x42, 0x32, 0x72, 0x20,
0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x38,
0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x20,
0x20, 0x20, 0x20, 0x23, 0x30, 0x30, 0x30, 0x35, 0x20, 0x53, 0x54, 0x48,
0x32, 0x6b, 0x72, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x0a, 0x20, 0x20,
0x26, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2e, 0x31, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30,
0x38, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20,
0x23, 0x30, 0x30, 0x30, 0x61, 0x20, 0x4f, 0x56, 0x52, 0x32, 0x20, 0x4f,
0x56, 0x52, 0x32, 0x20, 0x44, 0x49, 0x56, 0x32, 0x20, 0x4d, 0x55, 0x4c,
0x32, 0x20, 0x53, 0x55, 0x42, 0x32, 0x20, 0x23, 0x30, 0x30, 0x33, 0x30,
0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72,
0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x53,
0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x6b, 0x20,
0x23, 0x30, 0x30, 0x30, 0x31, 0x20, 0x53, 0x55, 0x42, 0x32, 0x20, 0x53,
0x57, 0x50, 0x32, 0x20, 0x53, 0x54, 0x41, 0x32, 0x6b, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x50, 0x4f, 0x50, 0x32, 0x20, 0x41, 0x44, 0x44, 0x32, 0x20,
0x53, 0x54, 0x41, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x50, 0x4f, 0x50, 0x20,
0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x38,
0x20, 0x41, 0x44, 0x44, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x6b, 0x20,
0x23, 0x30, 0x30, 0x30, 0x61, 0x20, 0x44, 0x49, 0x56, 0x32, 0x20, 0x53,
0x57, 0x50, 0x32, 0x20, 0x53, 0x54, 0x41, 0x32, 0x0a, 0x0a, 0x20, 0x20,
0x26, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x31, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x20, 0x53, 0x54,
0x48, 0x32, 0x6b, 0x72, 0x20, 0x23, 0x30, 0x30, 0x30, 0x38, 0x20, 0x41,
0x44, 0x44, 0x32, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x4c, 0x54, 0x48,
0x32, 0x20, 0x3f, 0x26, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x2e, 0x31, 0x0a,
0x0a, 0x20, 0x20, 0x26, 0x62, 0x72, 0x65, 0x61, 0x6b, 0x2e, 0x31, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x23, 0x30, 0x30, 0x30, 0x35, 0x20, 0x53, 0x54,
0x48, 0x32, 0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x53, 0x55,
0x42, 0x32, 0x20, 0x53, 0x54, 0x48, 0x32, 0x6b, 0x72, 0x20, 0x49, 0x4e,
0x43, 0x32, 0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x53, 0x54, 0x48, 0x32,
0x6b, 0x72, 0x20, 0x4c, 0x44, 0x41, 0x32, 0x20, 0x41, 0x44, 0x44, 0x32,
0x20, 0x61, 0x6d, 0x63, 0x70, 0x79, 0x5f, 0x0a, 0x20, 0x20, 0x20, 0x20,
0x21, 0x26, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x0a, 0x20, 0x20, 0x26, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x50, 0x4f,
0x50, 0x32, 0x72, 0x20, 0x4a, 0x4d, 0x50, 0x32, 0x72, 0x0a, 0x0a, 0x40,
0x73, 0x74, 0x72, 0x2f, 0x3c, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x3e, 0x20,
0x28, 0x20, 0x73, 0x74, 0x72, 0x2a, 0x20, 0x2d, 0x2d, 0x20, 0x29, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x4c, 0x44, 0x41, 0x6b, 0x20, 0x44, 0x55, 0x50,
0x20, 0x3f, 0x7b, 0x20, 0x50, 0x4f, 0x50, 0x20, 0x50, 0x4f, 0x50, 0x32,
0x20, 0x4a, 0x4d, 0x50, 0x32, 0x72, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x23, 0x31, 0x38, 0x20, 0x44, 0x45, 0x4f, 0x0a, 0x20, 0x20, 0x20,
0x20, 0x49, 0x4e, 0x43, 0x32, 0x20, 0x21, 0x2f, 0x3c, 0x70, 0x72, 0x69,
0x6e, 0x74, 0x3e, 0x0a, 0x0a, 0x40, 0x6d, 0x65, 0x6d, 0x5f, 0x6c, 0x65,
0x6e, 0x67, 0x74, 0x68, 0x5f, 0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x0a,
0x40, 0x6d, 0x65, 0x6d, 0x5f
};
unsigned int __lib_undar_len = 1433;
void
uxn_emit_error(const char *str, i32 length, i32 line)
{
printf("Error at line: %d > %.*s\n ", line, length, str);
exit(1);
}
void
uxn_mem(u32 a)
{
USED(a);
}
void
uxn_prolog()
{
printf("|100\n");
}
void
uxn_epilogue()
{
printf("BRK\n\n");
for (u32 i = 0; i < __lib_undar_len; i++) {
putchar(__lib_undar[i]);
}
}
void
uxn_emit_add()
{
printf("ADD2 ");
}
void
uxn_emit_sub()
{
printf("SUB2 ");
}
void
uxn_emit_mul()
{
printf("MUL2 ");
}
void
uxn_emit_div()
{
printf("DIV2 ");
}
void
uxn_emit_lt()
{
printf("LTH2 ");
}
void
uxn_emit_le()
{
printf("ROT SWP LTH ?{ LTH #00 EQU JMPr } GTH JMPr ");
}
void
uxn_emit_gt()
{
printf("GTH2 ");
}
void
uxn_emit_ge()
{
printf("ROT SWP GTH ?{ GTH #00 EQU JMPr } LTH JMPr ");
}
void
uxn_emit_ne()
{
printf("NEQ2 ");
}
void
uxn_emit_eq()
{
printf("EQU2 ");
}
void
uxn_emit_false()
{
printf("#0000 ");
}
void
uxn_emit_true()
{
printf("#0001 ");
}
void
uxn_emit_nil()
{
printf("#0000 ");
}
void
uxn_emit_neg()
{
printf("#0000 SUB2 ");
}
void
uxn_emit_not()
{
printf("#0000 EQU2 ");
}
void
uxn_emit_void()
{
}
i32
uxn_emit_bool_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_byte_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $1 } ", length, str);
else
printf("!{ @%.*s $1 } ", length, str);
return 1;
}
i32
uxn_emit_int_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_nat_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_real_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_str_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_u8_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $1 } ", length, str);
else
printf("!{ @%.*s $1 } ", length, str);
return 1;
}
i32
uxn_emit_i8_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $1 } ", length, str);
else
printf("!{ @%.*s $1 } ", length, str);
return 1;
}
i32
uxn_emit_i16_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_u16_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $2 } ", length, str);
else
printf("!{ @%.*s $2 } ", length, str);
return 2;
}
i32
uxn_emit_i32_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $4 } ", length, str);
else
printf("!{ @%.*s $4 } ", length, str);
return 4;
}
i32
uxn_emit_u32_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $4 } ", length, str);
else
printf("!{ @%.*s $4 } ", length, str);
return 4;
}
i32
uxn_emit_f32_type(const char *str, i32 length, bool local)
{
if(local)
printf("!{ &%.*s $4 } ", length, str);
else
printf("!{ @%.*s $4 } ", length, str);
return 4;
}
void
uxn_emit_int(const char *str, i32 length)
{
i32 i = (i32)strtol(str, nil, 10);
printf("#%04x ", i);
USED(length);
}
void
uxn_emit_nat(const char *str, i32 length)
{
u32 i = (u32)strtol(str, nil, 10);
printf("#%04x ", i);
USED(length);
}
void
uxn_emit_real(const char *str, i32 length)
{
USED(str);
USED(length);
/// TODO: implement this
}
void
uxn_emit_byte(const char *str, i32 length)
{
u8 i = (u8)strtol(str, nil, 10);
printf("#%04x ", i);
USED(length);
}
void
uxn_emit_str(const char *str, i32 length)
{
/* set a pointer to the string literal and then jump over it */
printf(";{ #0002 ADD2 } !{ ");
for(i32 i = 1; i < length - 1; i++) printf("%02x ", str[i]);
printf("00 } ");
}
void
uxn_emit_constant(const char *str, i32 length, bool local)
{
if(local)
printf(",/%.*s STR2 ", length, str);
else
printf(";%.*s STA2 ", length, str);
}
void
uxn_emit_array()
{
}
void
uxn_emit_function()
{
}
void
uxn_emit_plex()
{
}
void
uxn_emit_method()
{
}
void
uxn_emit_trait()
{
}
void
uxn_emit_const()
{
}
void
uxn_emit_putchar()
{
printf("#18 DEO ");
}
void
uxn_emit_getchar()
{
printf("#12 DEI ");
}
void
uxn_emit_open_paren()
{
}
void
uxn_emit_close_paren()
{
}
void
uxn_emit_variable(Symbol *sym, bool local)
{
if(local)
printf(",/%.*s LDR2 ", sym->name_length, sym->name);
else
printf(";%.*s LDA2 ", sym->name_length, sym->name);
}
void
uxn_emit_write()
{
}
void
uxn_emit_read()
{
}
void
uxn_emit_open()
{
}
void
uxn_emit_close()
{
}
void
uxn_emit_stat()
{
}
void
uxn_emit_end_statement()
{
printf("\n");
}
void
uxn_emit_set_value()
{
}
void
uxn_emit_plex_def()
{
}
void
uxn_emit_cast_int_to_nat()
{
printf("int_to_nat_ ");
}
void
uxn_emit_cast_int_to_real()
{
printf("int_to_real_ ");
}
void
uxn_emit_cast_int_to_str()
{
printf("int_to_str_ ");
}
void
uxn_emit_cast_nat_to_int()
{
printf("nat_to_int_ ");
}
void
uxn_emit_cast_nat_to_real()
{
printf("nat_to_real_ ");
}
void
uxn_emit_cast_nat_to_str()
{
printf("nat_to_str_ ");
}
void
uxn_emit_cast_real_to_int()
{
printf("real_to_int_ ");
}
void
uxn_emit_cast_real_to_nat()
{
printf("real_to_nat_ ");
}
void
uxn_emit_cast_real_to_str()
{
printf("real_to_str_ ");
}
void
uxn_emit_strbuf_init()
{
}
void
uxn_emit_strbuf_append()
{
}
void
uxn_emit_strbuf_to_str()
{
}
void
uxn_emit_arena_fn_call()
{
}
void
uxn_emit_arena_fn_return_plex()
{
}
void
uxn_emit_arena_fn_return_array()
{
}
void
uxn_emit_arena_fn_return_strbuf()
{
}
void
uxn_emit_cast_str_to_int()
{
}
void
uxn_emit_cast_str_to_nat()
{
}
void
uxn_emit_cast_str_to_real()
{
}
void
uxn_emit_sll()
{
printf("#40 SFT SFT ");
}
void
uxn_emit_srl()
{
printf("SFT ");
}
void
uxn_emit_xor()
{
printf("EOR2 ");
}
void
uxn_emit_mod()
{
printf("DIV2k MUL2 SUB2 ");
}
void
uxn_emit_or()
{
printf("ORA2 ");
}
void
uxn_emit_and()
{
printf("AND2 ");
}
void
uxn_emit_print()
{
printf("str/<print> ");
}
void
uxn_emit_if()
{
printf("#03 JCN !{ ");
}
void
uxn_emit_patch_if(i32 local_ifs)
{
printf("!&if_end.%d } ", local_ifs);
}
void
uxn_emit_patch_if_done(i32 local_ifs)
{
printf("&if_end.%d ", local_ifs);
}
void
uxn_emit_while(i32 local_whiles)
{
printf("&while.%d ", local_whiles);
}
void
uxn_emit_while_postfix()
{
printf("#03 JCN !{ ");
}
void
uxn_emit_patch_while(i32 local_whiles)
{
printf("!&while.%d } ", local_whiles);
}
Emitter uxn_emitter()
{
return (Emitter){
0,
0,
0,
0,
uxn_emit_error,
uxn_prolog,
uxn_epilogue,
uxn_emit_add,
uxn_emit_sub,
uxn_emit_mul,
uxn_emit_div,
uxn_emit_lt,
uxn_emit_le,
uxn_emit_gt,
uxn_emit_ge,
uxn_emit_ne,
uxn_emit_eq,
uxn_emit_false,
uxn_emit_true,
uxn_emit_nil,
uxn_emit_void,
uxn_emit_int,
uxn_emit_nat,
uxn_emit_real,
uxn_emit_byte,
uxn_emit_str,
uxn_emit_bool_type,
uxn_emit_byte_type,
uxn_emit_int_type,
uxn_emit_nat_type,
uxn_emit_real_type,
uxn_emit_str_type,
uxn_emit_u8_type,
uxn_emit_i8_type,
uxn_emit_i16_type,
uxn_emit_u16_type,
uxn_emit_i32_type,
uxn_emit_u32_type,
uxn_emit_f32_type,
uxn_emit_array,
uxn_emit_function,
uxn_emit_plex,
uxn_emit_method,
uxn_emit_trait,
uxn_emit_const,
uxn_emit_print,
uxn_emit_putchar,
uxn_emit_getchar,
uxn_emit_neg,
uxn_emit_not,
uxn_emit_open_paren,
uxn_emit_close_paren,
uxn_emit_constant,
uxn_emit_variable,
uxn_emit_write,
uxn_emit_read,
uxn_emit_open,
uxn_emit_close,
uxn_emit_stat,
uxn_emit_end_statement,
uxn_emit_set_value,
uxn_emit_plex_def,
uxn_emit_cast_int_to_nat,
uxn_emit_cast_int_to_real,
uxn_emit_cast_int_to_str,
uxn_emit_cast_nat_to_int,
uxn_emit_cast_nat_to_real,
uxn_emit_cast_nat_to_str,
uxn_emit_cast_real_to_int,
uxn_emit_cast_real_to_nat,
uxn_emit_cast_real_to_str,
uxn_emit_strbuf_init,
uxn_emit_strbuf_append,
uxn_emit_strbuf_to_str,
uxn_emit_arena_fn_call,
uxn_emit_arena_fn_return_plex,
uxn_emit_arena_fn_return_array,
uxn_emit_arena_fn_return_strbuf,
uxn_emit_cast_str_to_int,
uxn_emit_cast_str_to_nat,
uxn_emit_cast_str_to_real,
uxn_emit_sll,
uxn_emit_srl,
uxn_emit_xor,
uxn_emit_mod,
uxn_emit_and,
uxn_emit_or,
uxn_emit_if,
uxn_emit_patch_if,
uxn_emit_patch_if_done,
uxn_emit_while,
uxn_emit_while_postfix,
uxn_emit_patch_while,
};
}