From 7146084c7730274c7739db5e1ede7e5ee910b237 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 22 Dec 2021 18:33:20 +0100 Subject: Add print to ir compilation --- src/ir.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ir.h b/src/ir.h index a42cd48..845bf63 100644 --- a/src/ir.h +++ b/src/ir.h @@ -127,6 +127,17 @@ compile_arithmetic(ProgramIr *program, Procedure *proc, Op op, } } +void +compile_print(ProgramIr *program, Procedure *proc, + size_t line, size_t col, Object *args) { + Instruction inst = (Instruction){OP_PRINT, NULL, line, col}; + while (args != NULL) { + compile_object(program, proc, args->head); + args = args->tail; + array_push(proc->instructions, inst); + } +} + void compile_proc_call(ProgramIr *program, Procedure *proc, Object *obj) { size_t line = obj->line; @@ -148,6 +159,9 @@ compile_proc_call(ProgramIr *program, Procedure *proc, Object *obj) { case BUILTIN_MOD: { compile_arithmetic(program, proc, OP_MOD, line, col, obj->tail); } break; + case BUILTIN_PRINT: { + compile_print(program, proc, line, col, obj->tail); + } break; default: { assert(false && "builtin not implemented"); } break; -- cgit v1.2.1